| @@ 34-45 (lines=12) @@ | ||
| 31 | * |
|
| 32 | * @return int |
|
| 33 | */ |
|
| 34 | public function compare($boxA, $boxB) |
|
| 35 | { |
|
| 36 | $choice = $boxA->getItems()->count() - $boxB->getItems()->count(); |
|
| 37 | if ($choice === 0) { |
|
| 38 | $choice = $boxB->getBox()->getInnerVolume() - $boxA->getBox()->getInnerVolume(); |
|
| 39 | } |
|
| 40 | if ($choice === 0) { |
|
| 41 | $choice = $boxA->getWeight() - $boxB->getWeight(); |
|
| 42 | } |
|
| 43 | ||
| 44 | return $choice; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * Reversed version of compare. |
|
| @@ 55-66 (lines=12) @@ | ||
| 52 | * |
|
| 53 | * @return int |
|
| 54 | */ |
|
| 55 | public function reverseCompare($boxA, $boxB) |
|
| 56 | { |
|
| 57 | $choice = $boxB->getItems()->count() - $boxA->getItems()->count(); |
|
| 58 | if ($choice === 0) { |
|
| 59 | $choice = $boxA->getBox()->getInnerVolume() - $boxB->getBox()->getInnerVolume(); |
|
| 60 | } |
|
| 61 | if ($choice === 0) { |
|
| 62 | $choice = $boxB->getWeight() - $boxA->getWeight(); |
|
| 63 | } |
|
| 64 | ||
| 65 | return $choice; |
|
| 66 | } |
|
| 67 | ||
| 68 | /** |
|
| 69 | * Calculate the average (mean) weight of the boxes. |
|
| @@ 148-159 (lines=12) @@ | ||
| 145 | * |
|
| 146 | * @return int |
|
| 147 | */ |
|
| 148 | private function sortMoreSpaceFirst(PackedBox $boxA, PackedBox $boxB) |
|
| 149 | { |
|
| 150 | $choice = $boxB->getItems()->count() - $boxA->getItems()->count(); |
|
| 151 | if ($choice === 0) { |
|
| 152 | $choice = $boxA->getInnerVolume() - $boxB->getInnerVolume(); |
|
| 153 | } |
|
| 154 | if ($choice === 0) { |
|
| 155 | $choice = $boxB->getWeight() - $boxA->getWeight(); |
|
| 156 | } |
|
| 157 | ||
| 158 | return $choice; |
|
| 159 | } |
|
| 160 | } |
|
| 161 | ||