-
-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport packing enhancements from 3.1.0
- Loading branch information
Showing
25 changed files
with
968 additions
and
598 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ build: | |
coverage: | ||
file: 'build/behat.clover' | ||
format: 'clover' | ||
- php-scrutinizer-run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
group: travis_latest | ||
language: php | ||
sudo: false | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
/** | ||
* Box packing (3D bin packing, knapsack problem). | ||
* | ||
* @author Doug Wright | ||
*/ | ||
|
||
namespace DVDoug\BoxPacker; | ||
|
||
use Psr\Log\LoggerAwareInterface; | ||
use Psr\Log\LoggerAwareTrait; | ||
use Psr\Log\NullLogger; | ||
|
||
/** | ||
* Applies load stability to generated result. | ||
* | ||
* @author Doug Wright | ||
*/ | ||
class LayerStabiliser implements LoggerAwareInterface | ||
{ | ||
use LoggerAwareTrait; | ||
|
||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->logger = new NullLogger(); | ||
} | ||
|
||
/** | ||
* @param PackedLayer[] $packedLayers | ||
* | ||
* @return PackedLayer[] | ||
*/ | ||
public function stabilise(array $packedLayers) | ||
{ | ||
// first re-order according to footprint | ||
$stabilisedLayers = []; | ||
usort($packedLayers, [$this, 'compare']); | ||
|
||
// then for each item in the layer, re-calculate each item's z position | ||
$currentZ = 0; | ||
foreach ($packedLayers as $oldZLayer) { | ||
$oldZStart = $oldZLayer->getStartDepth(); | ||
$newZLayer = new PackedLayer(); | ||
foreach ($oldZLayer->getItems() as $oldZItem) { | ||
$newZ = $oldZItem->getZ() - $oldZStart + $currentZ; | ||
$newZItem = new PackedItem($oldZItem->getItem(), $oldZItem->getX(), $oldZItem->getY(), $newZ, $oldZItem->getWidth(), $oldZItem->getLength(), $oldZItem->getDepth()); | ||
$newZLayer->insert($newZItem); | ||
} | ||
|
||
$stabilisedLayers[] = $newZLayer; | ||
$currentZ += $newZLayer->getDepth(); | ||
} | ||
|
||
return $stabilisedLayers; | ||
} | ||
|
||
/** | ||
* @param PackedLayer $layerA | ||
* @param PackedLayer $layerB | ||
* | ||
* @return int | ||
*/ | ||
private function compare(PackedLayer $layerA, PackedLayer $layerB) | ||
{ | ||
return ($layerB->getFootprint() - $layerA->getFootprint()) ?: ($layerB->getDepth() - $layerA->getDepth()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.