diff --git a/src/cram.c b/src/cram.c index 2944eca..9f3de63 100644 --- a/src/cram.c +++ b/src/cram.c @@ -298,7 +298,7 @@ void Cram_Internal_PruneRects(RectPackContext* context) for (i = 0; i < context->freeRectangleCount; i += 1) { - for (j = 0; j < context->newFreeRectangleCount;) + for (j = context->newFreeRectangleCount - 1; j >= 0; j -= 1) { if (Cram_Internal_Contains(&context->freeRectangles[i], &context->newFreeRectangles[j])) { @@ -306,10 +306,6 @@ void Cram_Internal_PruneRects(RectPackContext* context) context->newFreeRectangles[j] = context->newFreeRectangles[context->newFreeRectangleCount - 1]; context->newFreeRectangleCount -= 1; } - else - { - j += 1; - } } } @@ -418,7 +414,7 @@ void Cram_Internal_PlaceRect(RectPackContext *context, Rect *rect) Rect *freeRect; int32_t i; - for (i = 0; i < context->freeRectangleCount;) + for (i = context->freeRectangleCount - 1; i >= 0; i -= 1) { freeRect = &context->freeRectangles[i]; @@ -428,10 +424,6 @@ void Cram_Internal_PlaceRect(RectPackContext *context, Rect *rect) context->freeRectangles[i] = context->freeRectangles[context->freeRectangleCount - 1]; context->freeRectangleCount -= 1; } - else - { - i += 1; - } } Cram_Internal_PruneRects(context);