Flutter Engine
 
Loading...
Searching...
No Matches
impeller::SkylineRectanglePacker Class Referencefinal
Inheritance diagram for impeller::SkylineRectanglePacker:
impeller::RectanglePacker

Public Member Functions

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

Additional Inherited Members

- Static Public Member Functions inherited from impeller::RectanglePacker
static std::shared_ptr< RectanglePackerFactory (int width, int height)
 Return an empty packer with area specified by width and height.
 
- Protected Member Functions inherited from impeller::RectanglePacker
 RectanglePacker (int width, int height)
 
int width () const
 
int height () const
 

Detailed Description

Definition at line 19 of file rectangle_packer.cc.

Constructor & Destructor Documentation

◆ SkylineRectanglePacker()

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

Definition at line 21 of file rectangle_packer.cc.

21: RectanglePacker(w, h) { Reset(); }
RectanglePacker(int width, int height)
void Reset() final
Empty out all previously added rectangles.

References Reset().

◆ ~SkylineRectanglePacker()

impeller::SkylineRectanglePacker::~SkylineRectanglePacker ( )
inlinefinal

Definition at line 23 of file rectangle_packer.cc.

23{}

Member Function Documentation

◆ AddRect()

bool impeller::SkylineRectanglePacker::AddRect ( int  width,
int  height,
IPoint16 loc 
)
finalvirtual

Attempt to add a rect without moving already placed rectangles.

Parameters
[in]widthThe width of the rectangle to add.
[in]heightThe height of the rectangle to add.
[out]locIf 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 62 of file rectangle_packer.cc.

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

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

◆ PercentFull()

Scalar impeller::SkylineRectanglePacker::PercentFull ( ) const
inlinefinalvirtual

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 33 of file rectangle_packer.cc.

33 {
34 return area_so_far_ / (static_cast<float>(width()) * height());
35 }

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

◆ Reset()

void impeller::SkylineRectanglePacker::Reset ( )
inlinefinalvirtual

Empty out all previously added rectangles.

Implements impeller::RectanglePacker.

Definition at line 25 of file rectangle_packer.cc.

25 {
26 area_so_far_ = 0;
27 skyline_.clear();
28 skyline_.push_back(SkylineSegment{0, 0, width()});
29 }

References impeller::RectanglePacker::width().

Referenced by SkylineRectanglePacker().


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