1 | <?php |
||
11 | class Box |
||
12 | { |
||
13 | /** @var int */ |
||
14 | protected $x; |
||
15 | /** @var int */ |
||
16 | protected $y; |
||
17 | /** @var int */ |
||
18 | protected $width; |
||
19 | /** @var int */ |
||
20 | protected $height; |
||
21 | /** @var int */ |
||
22 | protected $top; |
||
23 | /** @var int */ |
||
24 | protected $bottom; |
||
25 | /** @var int */ |
||
26 | protected $left; |
||
27 | /** @var int */ |
||
28 | protected $right; |
||
29 | |||
30 | 2 | public function __construct($x, $y, $width, $height) |
|
39 | |||
40 | 1 | public static function constructFromImagine(PointInterface $point, BoxInterface $box) |
|
44 | |||
45 | 2 | protected function update() |
|
52 | |||
53 | /** |
||
54 | * Detect box collision |
||
55 | * This algorithm only works with Axis-Aligned boxes! |
||
56 | * @param Box $box The other rectangle to test collision with |
||
57 | * @return boolean True is the boxes collide, false otherwise |
||
58 | */ |
||
59 | 4 | function intersects(Box $box) |
|
67 | |||
68 | /** |
||
69 | * @return int |
||
70 | */ |
||
71 | 2 | public function getBottom() |
|
75 | |||
76 | /** |
||
77 | * @return int |
||
78 | */ |
||
79 | public function getHeight() |
||
83 | |||
84 | /** |
||
85 | * @return int |
||
86 | */ |
||
87 | 4 | public function getLeft() |
|
91 | |||
92 | /** |
||
93 | * @return int |
||
94 | */ |
||
95 | 4 | public function getRight() |
|
99 | |||
100 | /** |
||
101 | * @return int |
||
102 | */ |
||
103 | 2 | public function getTop() |
|
107 | |||
108 | /** |
||
109 | * @return int |
||
110 | */ |
||
111 | public function getWidth() |
||
115 | |||
116 | /** |
||
117 | * @return int |
||
118 | */ |
||
119 | public function getX() |
||
123 | |||
124 | /** |
||
125 | * @return int |
||
126 | */ |
||
127 | public function getY() |
||
131 | } |
||
132 | |||
133 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.