diff --git a/PackedBox.php b/PackedBox.php index 326361ba..7d9688c5 100644 --- a/PackedBox.php +++ b/PackedBox.php @@ -27,10 +27,34 @@ class PackedBox { /** * Total weight of box - * @var float + * @var int */ protected $weight; + /** + * Remaining width inside box for another item + * @var int + */ + protected $remainingWidth; + + /** + * Remaining length inside box for another item + * @var int + */ + protected $remainingLength; + + /** + * Remaining depth inside box for another item + * @var int + */ + protected $remainingDepth; + + /** + * Remaining weight inside box for another item + * @var int + */ + protected $remainingWeight; + /** * Get box used * @return Box @@ -65,9 +89,56 @@ public function getWeight() { return $this->weight; } - public function __construct(Box $aBox, ItemList $aItemList) { + /** + * Get remaining width inside box for another item + * @return int + */ + public function getRemainingWidth() { + return $this->remainingWidth; + } + + /** + * Get remaining length inside box for another item + * @return int + */ + public function getRemainingLength() { + return $this->remainingLength; + } + + /** + * Get remaining depth inside box for another item + * @return int + */ + public function getRemainingDepth() { + return $this->remainingDepth; + } + + /** + * Get remaining weight inside box for another item + * @return int + */ + public function getRemainingWeight() { + return $this->remainingWeight; + } + + + + /** + * Constructor + * @param Box $aBox + * @param ItemList $aItemList + * @param int $aRemainingWidth + * @param int $aRemainingLength + * @param int $aRemainingDepth + * @param int $aRemainingWeight + */ + public function __construct(Box $aBox, ItemList $aItemList, $aRemainingWidth, $aRemainingLength, $aRemainingDepth, $aRemainingWeight) { $this->box = $aBox; $this->items = $aItemList; + $this->remainingWidth = $aRemainingWidth; + $this->remainingLength = $aRemainingLength; + $this->remainingDepth = $aRemainingDepth; + $this->remainingWeight = $aRemainingWeight; } } diff --git a/Packer.php b/Packer.php index 18e9599b..09048b72 100644 --- a/Packer.php +++ b/Packer.php @@ -125,12 +125,12 @@ public function doVolumePacking() { //Loop through boxes starting with smallest, see what happens while (!$boxesToEvaluate->isEmpty()) { $box = $boxesToEvaluate->extract(); - $packedItems = $this->packBox($box, clone $this->items); - if ($packedItems->count()) { - $packedBoxesIteration->insert(new PackedBox($box, $packedItems)); + $packedBox = $this->packIntoBox($box, clone $this->items); + if ($packedBox->getItems()->count()) { + $packedBoxesIteration->insert($packedBox); //Have we found a single box that contains everything? - if ($packedItems->count() === $this->items->count()) { + if ($packedBox->getItems()->count() === $this->items->count()) { break; } } @@ -234,9 +234,9 @@ public function redistributeWeight(PackedBoxList $aPackedBoxes) { * Pack as many items as possible into specific given box * @param Box $aBox * @param ItemList $aItems - * @return ItemList items packed into box + * @return PackedBox packed box */ - public function packBox(Box $aBox, ItemList $aItems) { + public function packIntoBox(Box $aBox, ItemList $aItems) { $this->logger->log(LogLevel::DEBUG, "evaluating box {$aBox->getReference()}"); $packedItems = new ItemList; @@ -300,6 +300,18 @@ public function packBox(Box $aBox, ItemList $aItems) { } } $this->logger->log(LogLevel::DEBUG, "done with this box"); - return $packedItems; + return new PackedBox($aBox, $packedItems, $remainingWidth, $remainingLength, $remainingDepth, $remainingWeight); + } + + /** + * Pack as many items as possible into specific given box + * @deprecated + * @param Box $aBox + * @param ItemList $aItems + * @return ItemList items packed into box + */ + public function packBox(Box $aBox, ItemList $aItems) { + $packedBox = $this->packIntoBox($aBox, $aItems); + return $packedBox->getItems(); } }