| 21 | // *********************************************************************** |
| 22 | |
| 23 | void Packing::RowPackRects(ResizableArray<Rect>& rects, i32 width, i32 height) { |
| 24 | for (i64 i = 0; i < rects.count; i++) { |
| 25 | rects[i].ordering = (int)i; |
| 26 | } |
| 27 | |
| 28 | Sort(rects.pData, rects.count, SortByHeight()); |
| 29 | |
| 30 | i32 xPos = 0; |
| 31 | i32 yPos = 0; |
| 32 | |
| 33 | i32 largestHThisRow = 0; |
| 34 | |
| 35 | // Pack from left to right on a row |
| 36 | i32 maxX = 0; |
| 37 | i32 maxY = 0; |
| 38 | i32 totalArea = 0; |
| 39 | |
| 40 | for (Rect& rect : rects) { |
| 41 | if ((xPos + rect.w) > width) { |
| 42 | yPos += largestHThisRow; |
| 43 | xPos = 0; |
| 44 | largestHThisRow = 0; |
| 45 | } |
| 46 | |
| 47 | if ((yPos + rect.h) > height) |
| 48 | break; |
| 49 | |
| 50 | rect.x = xPos; |
| 51 | rect.y = yPos; |
| 52 | |
| 53 | xPos += rect.w; |
| 54 | |
| 55 | if (rect.h > largestHThisRow) |
| 56 | largestHThisRow = rect.h; |
| 57 | |
| 58 | rect.wasPacked = true; |
| 59 | } |
| 60 | |
| 61 | Sort(rects.pData, rects.count, SortToOriginalOrder()); |
| 62 | } |
| 63 | |
| 64 | // *********************************************************************** |
| 65 |
nothing calls this directly
no test coverage detected