Skip to content

Commit

Permalink
Break out the cases a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdoug committed Apr 15, 2020
1 parent 978b22d commit e78ea21
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/LayerPacker.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,25 @@ public function packLayer(ItemList &$items, PackedItemList $packedItemList, arra
$items = ItemList::fromArray(array_merge($skippedItems, iterator_to_array($items)), true);
$skippedItems = [];
}
} elseif (count($layer->getItems()) === 0) { // zero items on layer
continue;
}

if (count($layer->getItems()) === 0) { // zero items on layer
$this->logger->debug("doesn't fit on layer even when empty, skipping for good");
continue;
} elseif ($items->count() > 0) { // skip for now, move on to the next item
}

if ($items->count() > 0) { // skip for now, move on to the next item
$this->logger->debug("doesn't fit, skipping for now");
$skippedItems[] = $itemToPack;
// abandon here if next item is the same, no point trying to keep going. Last time is not skipped, need that to trigger appropriate reset logic
while ($items->count() > 2 && static::isSameDimensions($itemToPack, $items->top())) {
while ($items->count() > 1 && static::isSameDimensions($itemToPack, $items->top())) {
$skippedItems[] = $items->extract();
}
} elseif ($x > 0) {
continue;
}

if ($x > 0) {
$this->logger->debug('No more fit in width wise, resetting for new row');
$lengthLeft -= $rowLength;
$y += $rowLength;
Expand All @@ -134,14 +142,14 @@ public function packLayer(ItemList &$items, PackedItemList $packedItemList, arra
$skippedItems = [];
$prevItem = null;
continue;
} else {
$this->logger->debug('no items fit, so starting next vertical layer');
$skippedItems[] = $itemToPack;
}

$items = ItemList::fromArray(array_merge($skippedItems, iterator_to_array($items)), true);
$this->logger->debug('no items fit, so starting next vertical layer');
$skippedItems[] = $itemToPack;

return $layer;
}
$items = ItemList::fromArray(array_merge($skippedItems, iterator_to_array($items)), true);

return $layer;
}

return $layer;
Expand All @@ -162,12 +170,13 @@ private function packVerticallyInsideItemFootprint(PackedLayer $layer, PackedIte
$packedItemList->insert($packedItem);
$stackableDepth -= $stackedItem->getDepth();
$stackedZ += $stackedItem->getDepth();
} else {
$stackSkippedItems[] = $itemToTryStacking;
// abandon here if next item is the same, no point trying to keep going
while ($items->count() > 0 && static::isSameDimensions($itemToTryStacking, $items->top())) {
$stackSkippedItems[] = $items->extract();
}
continue;
}

$stackSkippedItems[] = $itemToTryStacking;
// abandon here if next item is the same, no point trying to keep going
while ($items->count() > 0 && static::isSameDimensions($itemToTryStacking, $items->top())) {
$stackSkippedItems[] = $items->extract();
}
}
if ($stackSkippedItems) {
Expand Down

0 comments on commit e78ea21

Please sign in to comment.