18 if ((
unsigned)
width > (
unsigned)this->
width() ||
19 (
unsigned)height > (
unsigned)this->
height()) {
24 int bestWidth = this->
width() + 1;
26 int bestY = this->
height() + 1;
28 for (
int i = 0;
i < fSkyline.
size(); ++
i) {
32 if (
y < bestY || (
y == bestY && fSkyline[
i].fWidth < bestWidth)) {
34 bestWidth = fSkyline[
i].fWidth;
35 bestX = fSkyline[
i].fX;
42 if (-1 != bestIndex) {
43 this->addSkylineLevel(bestIndex, bestX, bestY,
width,
height);
56bool RectanizerSkyline::rectangleFits(
int skylineIndex,
int width,
int height,
int* ypos)
const {
57 int x = fSkyline[skylineIndex].fX;
62 int widthLeft =
width;
64 int y = fSkyline[skylineIndex].fY;
65 while (widthLeft > 0) {
70 widthLeft -= fSkyline[
i].fWidth;
79void RectanizerSkyline::addSkylineLevel(
int skylineIndex,
int x,
int y,
int width,
int height) {
80 SkylineSegment newSegment;
83 newSegment.fWidth =
width;
84 fSkyline.
insert(skylineIndex, 1, &newSegment);
86 SkASSERT(newSegment.fX + newSegment.fWidth <= this->width());
87 SkASSERT(newSegment.fY <= this->height());
90 for (
int i = skylineIndex+1;
i < fSkyline.
size(); ++
i) {
94 if (fSkyline[
i].fX < fSkyline[
i-1].fX + fSkyline[
i-1].fWidth) {
95 int shrink = fSkyline[
i-1].fX + fSkyline[
i-1].fWidth - fSkyline[
i].fX;
97 fSkyline[
i].fX += shrink;
98 fSkyline[
i].fWidth -= shrink;
100 if (fSkyline[
i].fWidth <= 0) {
114 for (
int i = 0;
i < fSkyline.
size()-1; ++
i) {
115 if (fSkyline[
i].fY == fSkyline[
i+1].fY) {
116 fSkyline[
i].fWidth += fSkyline[
i+1].fWidth;
void remove(int index, int count=1)
bool addRect(int w, int h, SkIPoint16 *loc) final
static Rectanizer * Factory(int width, int height)
static float max(float r, float g, float b)
int16_t fY
y-axis value used by SkIPoint16
int16_t fX
x-axis value used by SkIPoint16