| Flutter Impeller |

Classes | Public Member Functions | List of all members
impeller::SkylineRectanglePacker Class Referencefinal
Inheritance diagram for impeller::SkylineRectanglePacker:

## Public Member Functions
| SkylineRectanglePacker (int w, int h)
| ~SkylineRectanglePacker () final
void | reset () final
| Empty out all previously added rectangles. More...
bool | addRect (int w, int h, IPoint16 *loc) final
| Attempt to add a rect without moving already placed rectangles. More...
float | percentFull () const final
| Returns how much area has been filled with rectangles. More...
Public Member Functions inherited from impeller::RectanglePacker
virtual | ~RectanglePacker ()

## Additional Inherited Members
Static Public Member Functions inherited from impeller::RectanglePacker
static RectanglePacker * | Factory (int width, int height)
| Return an empty packer with area specified by width and height. More...
Protected Member Functions inherited from impeller::RectanglePacker
| RectanglePacker (int width, int height)
int | width () const
int | height () const

## Detailed Description

Definition at line 16 of file rectangle_packer.cc.

## Constructor & Destructor Documentation

## ◆ SkylineRectanglePacker()

impeller::SkylineRectanglePacker::SkylineRectanglePacker | ( | int | w,
|  | int | h
| ) |  |
| inline

Definition at line 18 of file rectangle_packer.cc.

18 : RectanglePacker(w, h) {
19 this->reset();
20 }

References reset().

## ◆ ~SkylineRectanglePacker()

impeller::SkylineRectanglePacker::~SkylineRectanglePacker | ( |  | ) |
| inline final

Definition at line 22 of file rectangle_packer.cc.

22 {}

## Member Function Documentation

## ◆ addRect()

bool impeller::SkylineRectanglePacker::addRect | ( | int | width,
|  | int | height,
|  | IPoint16 * | loc
| ) |  |
| final virtual

Attempt to add a rect without moving already placed rectangles.

Parameters

  [in] | width | The width of the rectangle to add.
  [in] | height | The height of the rectangle to add.
  [out] | loc | If successful, will be set to the position of the upper-left corner of the rectangle.

Returns
  Return true on success; false on failure.

Implements impeller::RectanglePacker.

Definition at line 57 of file rectangle_packer.cc.

57 {
58 if ((unsigned)width > (unsigned)this->width() ||
59 (unsigned)height > (unsigned)this->height()) {
60 return false;
61 }
62
63 // find position for new rectangle
64 int bestWidth = this->width() + 1;
65 int bestX = 0;
66 int bestY = this->height() + 1;
67 int bestIndex = -1;
68 for (int i = 0; i < (int)skyline_.size(); ++i) {
69 int y;
70 if (this->rectangleFits(i, width, height, &y)) {
71 // minimize y position first, then width of skyline
72 if (y < bestY || (y == bestY && skyline_[i].width_ < bestWidth)) {
73 bestIndex = i;
74 bestWidth = skyline_[i].width_;
75 bestX = skyline_[i].x_;
76 bestY = y;
77 }
78 }
79 }
80
81 // add rectangle to skyline
82 if (-1 != bestIndex) {
83 this->addSkylineLevel(bestIndex, bestX, bestY, width, height);
84 loc->x_ = bestX;
85 loc->y_ = bestY;
86
87 area_so_far_ += width * height;
88 return true;
89 }
90
91 loc->x_ = 0;
92 loc->y_ = 0;
93 return false;
94 }

References impeller::RectanglePacker::height(), impeller::RectanglePacker::width(), impeller::IPoint16::x_, and impeller::IPoint16::y_.

## ◆ percentFull()

float impeller::SkylineRectanglePacker::percentFull | ( |  | ) | const
| inline final virtual

Returns how much area has been filled with rectangles.

Returns
  Percentage as a decimal between 0.0 and 1.0

Implements impeller::RectanglePacker.

Definition at line 32 of file rectangle_packer.cc.

32 {
33 return area_so_far_ / ((float)this->width() * this->height());
34 }

References impeller::RectanglePacker::height(), and impeller::RectanglePacker::width().

## ◆ reset()

void impeller::SkylineRectanglePacker::reset | ( |  | ) |
| inline final virtual

Empty out all previously added rectangles.

Implements impeller::RectanglePacker.

Definition at line 24 of file rectangle_packer.cc.

24 {
25 area_so_far_ = 0;
26 skyline_.clear();
27 skyline_.push_back(SkylineSegment{0, 0, this->width()});
28 }

References impeller::RectanglePacker::width().

Referenced by SkylineRectanglePacker().

The documentation for this class was generated from the following file:

- impeller/typographer/rectangle_packer.cc

impeller::RectanglePacker::width
int width() const
Definition: rectangle_packer.h:63
impeller::SkylineRectanglePacker::reset
void reset() final
Empty out all previously added rectangles.
Definition: rectangle_packer.cc:24
impeller::RectanglePacker::height
int height() const
Definition: rectangle_packer.h:64
impeller::RectanglePacker::RectanglePacker
RectanglePacker(int width, int height)
Definition: rectangle_packer.h:58