Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
rectangle_packer.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
6#define FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
7
8#include "flutter/fml/logging.h"
9
10#include <cstdint>
11
12namespace impeller {
13
14struct IPoint16 {
15 int16_t x() const { return x_; }
16 int16_t y() const { return y_; }
17
18 int16_t x_;
19 int16_t y_;
20};
21
22//------------------------------------------------------------------------------
23/// @brief Packs rectangles into a specified area without rotating them.
24///
26 public:
27 //----------------------------------------------------------------------------
28 /// @brief Return an empty packer with area specified by width and height.
29 ///
30 static std::unique_ptr<RectanglePacker> Factory(int width, int height);
31
32 virtual ~RectanglePacker() {}
33
34 //----------------------------------------------------------------------------
35 /// @brief Attempt to add a rect without moving already placed rectangles.
36 ///
37 /// @param[in] width The width of the rectangle to add.
38 /// @param[in] height The height of the rectangle to add.
39 /// @param[out] loc If successful, will be set to the position of the
40 /// upper-left corner of the rectangle.
41 ///
42 /// @return Return true on success; false on failure.
43 ///
44 virtual bool addRect(int width, int height, IPoint16* loc) = 0;
45
46 //----------------------------------------------------------------------------
47 /// @brief Returns how much area has been filled with rectangles.
48 ///
49 /// @return Percentage as a decimal between 0.0 and 1.0
50 ///
51 virtual float percentFull() const = 0;
52
53 //----------------------------------------------------------------------------
54 /// @brief Empty out all previously added rectangles.
55 ///
56 virtual void reset() = 0;
57
58 protected:
59 RectanglePacker(int width, int height) : width_(width), height_(height) {
60 FML_DCHECK(width >= 0);
61 FML_DCHECK(height >= 0);
62 }
63
64 int width() const { return width_; }
65 int height() const { return height_; }
66
67 private:
68 const int width_;
69 const int height_;
70};
71
72} // namespace impeller
73
74#endif // FLUTTER_IMPELLER_TYPOGRAPHER_RECTANGLE_PACKER_H_
Packs rectangles into a specified area without rotating them.
virtual void reset()=0
Empty out all previously added rectangles.
static std::unique_ptr< RectanglePacker > Factory(int width, int height)
Return an empty packer with area specified by width and height.
RectanglePacker(int width, int height)
virtual bool addRect(int width, int height, IPoint16 *loc)=0
Attempt to add a rect without moving already placed rectangles.
virtual float percentFull() const =0
Returns how much area has been filled with rectangles.
#define FML_DCHECK(condition)
Definition logging.h:103
int16_t y() const
int16_t x() const