MCPcopy Create free account
hub / github.com/DavidColson/Polybox / CanRectFit

Function CanRectFit

source/rect_packing.cpp:70–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68};
69
70i32 CanRectFit(ResizableArray<SkylineNode>& nodes, i32 atNode, i32 rectWidth, i32 rectHeight, i32 width, i32 height) {
71 // See if there's space for this rect at node "atNode"
72
73 i32 x = nodes[atNode].x;
74 i32 y = nodes[atNode].y;
75 if (x + rectWidth > width) // Check we're not going off the end of the image
76 return -1;
77
78
79 // We're going to loop over all the nodes from atNode to however many this new rect "covers"
80 // We want to find the highest rect underneath this rect to place it at.
81 i32 remainingSpace = rectWidth;
82 i32 i = atNode;
83 while (remainingSpace > 0) {
84 if (i == nodes.count)
85 return -1;
86
87 SkylineNode& node = nodes[i];
88
89 if (node.y > y)
90 y = node.y;
91
92 if (y + rectHeight > height)
93 return -1; // of the edge of the image
94 remainingSpace -= node.width;
95 i++;
96 }
97 return y;
98}
99
100// ***********************************************************************
101

Callers 1

SkylinePackRectsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected