1 | <?php |
||
8 | class Box |
||
9 | { |
||
10 | /** @var float */ |
||
11 | protected $x; |
||
12 | |||
13 | /** @var float */ |
||
14 | protected $y; |
||
15 | |||
16 | /** @var float */ |
||
17 | protected $width; |
||
18 | |||
19 | /** @var float */ |
||
20 | protected $height; |
||
21 | |||
22 | /** @var float */ |
||
23 | protected $top; |
||
24 | |||
25 | /** @var float */ |
||
26 | protected $bottom; |
||
27 | |||
28 | /** @var float */ |
||
29 | protected $left; |
||
30 | |||
31 | /** @var float */ |
||
32 | protected $right; |
||
33 | |||
34 | /** |
||
35 | * Constructor |
||
36 | * @param float $x |
||
37 | * @param float $y |
||
38 | * @param float $width |
||
39 | * @param float $height |
||
40 | */ |
||
41 | 26 | public function __construct($x, $y, $width, $height) |
|
50 | |||
51 | /** |
||
52 | * Factory method. |
||
53 | * @param float $x |
||
54 | * @param float $y |
||
55 | * @param float $width |
||
56 | * @param float $height |
||
57 | * @return Box |
||
58 | */ |
||
59 | 5 | public static function create($x, $y, $width, $height) : Box |
|
63 | |||
64 | /** |
||
65 | * Update the left, right, top, and bottom coordinates. |
||
66 | */ |
||
67 | 26 | public function update() |
|
74 | |||
75 | /** |
||
76 | * Detect box collision |
||
77 | * This algorithm only works with Axis-Aligned boxes! |
||
78 | * @param Box $box The other rectangle to test collision with |
||
79 | * @param bool $strict If true, boxes "touching" each other are not intersecting, otherwise they are |
||
80 | * @return boolean True is the boxes collide, false otherwise |
||
81 | */ |
||
82 | public function intersects(Box $box, $strict = true) : bool |
||
99 | |||
100 | /** |
||
101 | * @param Box $box |
||
102 | * @return bool |
||
103 | */ |
||
104 | 2 | public function inside(Box $box) : bool |
|
112 | |||
113 | /** |
||
114 | * @param float $deltaX |
||
115 | * @param float $deltaY |
||
116 | * @return Box |
||
117 | */ |
||
118 | 1 | public function move($deltaX, $deltaY) : Box |
|
122 | |||
123 | /** |
||
124 | * @param int $increment |
||
125 | * @return Box |
||
126 | */ |
||
127 | 1 | public function resize($increment) : Box |
|
136 | |||
137 | /** |
||
138 | * @return float |
||
139 | */ |
||
140 | 12 | public function getBottom() : float |
|
144 | |||
145 | /** |
||
146 | * @return float |
||
147 | */ |
||
148 | 19 | public function getHeight() : float |
|
152 | |||
153 | /** |
||
154 | * @return float |
||
155 | */ |
||
156 | 16 | public function getLeft() : float |
|
160 | |||
161 | /** |
||
162 | * @return float |
||
163 | */ |
||
164 | 15 | public function getRight() : float |
|
168 | |||
169 | /** |
||
170 | * @return float |
||
171 | */ |
||
172 | 12 | public function getTop() : float |
|
176 | |||
177 | /** |
||
178 | * @return float |
||
179 | */ |
||
180 | 19 | public function getWidth() : float |
|
184 | |||
185 | /** |
||
186 | * @return float |
||
187 | */ |
||
188 | 21 | public function getX() : float |
|
192 | |||
193 | /** |
||
194 | * @return float |
||
195 | */ |
||
196 | 21 | public function getY() : float |
|
200 | |||
201 | /** |
||
202 | * @return Vector |
||
203 | */ |
||
204 | 1 | public function getPosition() : Vector |
|
208 | |||
209 | /** |
||
210 | * @return Vector |
||
211 | */ |
||
212 | 1 | public function getDimensions() : Vector |
|
216 | |||
217 | /** |
||
218 | * @return Vector |
||
219 | */ |
||
220 | 18 | public function getCenter() : Vector |
|
227 | |||
228 | /** |
||
229 | * @return string |
||
230 | */ |
||
231 | 1 | public function __toString() : string |
|
235 | |||
236 | 1 | public function serialize(): string |
|
245 | } |
||
246 |