| Conditions | 3 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 26 | 56 | public function stabilise(array $packedLayers): array |
|
| 27 | { |
||
| 28 | // first re-order according to footprint |
||
| 29 | 56 | $stabilisedLayers = []; |
|
| 30 | 56 | usort($packedLayers, [$this, 'compare']); |
|
| 31 | |||
| 32 | // then for each item in the layer, re-calculate each item's z position |
||
| 33 | 56 | $currentZ = 0; |
|
| 34 | 56 | foreach ($packedLayers as $oldZLayer) { |
|
| 35 | 56 | $oldZStart = $oldZLayer->getStartDepth(); |
|
| 36 | 56 | $newZLayer = new PackedLayer(); |
|
| 37 | 56 | foreach ($oldZLayer->getItems() as $oldZItem) { |
|
| 38 | 56 | $newZ = $oldZItem->getZ() - $oldZStart + $currentZ; |
|
| 39 | 56 | $newZItem = new PackedItem($oldZItem->getItem(), $oldZItem->getX(), $oldZItem->getY(), $newZ, $oldZItem->getWidth(), $oldZItem->getLength(), $oldZItem->getDepth()); |
|
| 40 | 56 | $newZLayer->insert($newZItem); |
|
| 41 | } |
||
| 42 | |||
| 43 | 56 | $stabilisedLayers[] = $newZLayer; |
|
| 44 | 56 | $currentZ += $newZLayer->getDepth(); |
|
| 45 | } |
||
| 46 | |||
| 47 | 56 | return $stabilisedLayers; |
|
| 48 | } |
||
| 55 |