Total Complexity | 8 |
Total Lines | 110 |
Duplicated Lines | 0 % |
Coverage | 90.48% |
Changes | 0 |
1 | <?php |
||
18 | class OrientatedItem |
||
19 | { |
||
20 | /** |
||
21 | * @var Item |
||
22 | */ |
||
23 | protected $item; |
||
24 | |||
25 | /** |
||
26 | * @var int |
||
27 | */ |
||
28 | protected $width; |
||
29 | |||
30 | /** |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $length; |
||
34 | |||
35 | /** |
||
36 | * @var int |
||
37 | */ |
||
38 | protected $depth; |
||
39 | |||
40 | /** @var float */ |
||
41 | protected $tippingPoint; |
||
42 | |||
43 | /** |
||
44 | * Constructor. |
||
45 | * |
||
46 | * @param Item $item |
||
47 | * @param int $width |
||
48 | * @param int $length |
||
49 | * @param int $depth |
||
50 | */ |
||
51 | 21 | public function __construct(Item $item, int $width, int $length, int $depth) |
|
52 | { |
||
53 | 21 | $this->item = $item; |
|
54 | 21 | $this->width = $width; |
|
55 | 21 | $this->length = $length; |
|
56 | 21 | $this->depth = $depth; |
|
57 | 21 | $this->tippingPoint = atan(min($this->length, $this->width) / $this->depth); |
|
58 | 21 | } |
|
59 | |||
60 | /** |
||
61 | * Item. |
||
62 | * |
||
63 | * @return Item |
||
64 | */ |
||
65 | 21 | public function getItem(): Item |
|
66 | { |
||
67 | 21 | return $this->item; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * Item width in mm in it's packed orientation. |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | 21 | public function getWidth(): int |
|
76 | { |
||
77 | 21 | return $this->width; |
|
78 | } |
||
79 | |||
80 | /** |
||
81 | * Item length in mm in it's packed orientation. |
||
82 | * |
||
83 | * @return int |
||
84 | */ |
||
85 | 21 | public function getLength(): int |
|
86 | { |
||
87 | 21 | return $this->length; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * Item depth in mm in it's packed orientation. |
||
92 | * |
||
93 | * @return int |
||
94 | */ |
||
95 | 21 | public function getDepth(): int |
|
96 | { |
||
97 | 21 | return $this->depth; |
|
98 | } |
||
99 | |||
100 | /** |
||
101 | * Calculate the surface footprint of the current orientation. |
||
102 | * |
||
103 | * @return int |
||
104 | */ |
||
105 | 13 | public function getSurfaceFootprint(): int |
|
106 | { |
||
107 | 13 | return $this->width * $this->length; |
|
108 | } |
||
109 | |||
110 | /** |
||
111 | * @return float |
||
112 | */ |
||
113 | public function getTippingPoint(): float |
||
116 | } |
||
117 | |||
118 | /** |
||
119 | * Is this item stable (low centre of gravity), calculated as if the tipping point is >15 degrees. |
||
120 | * |
||
121 | * N.B. Assumes equal weight distribution. |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | 21 | public function isStable(): bool |
|
128 | } |
||
129 | } |
||
130 |