1 | <?php |
||
12 | class Box |
||
13 | { |
||
14 | /** @var int */ |
||
15 | protected $x; |
||
16 | /** @var int */ |
||
17 | protected $y; |
||
18 | /** @var int */ |
||
19 | protected $width; |
||
20 | /** @var int */ |
||
21 | protected $height; |
||
22 | /** @var int */ |
||
23 | protected $top; |
||
24 | /** @var int */ |
||
25 | protected $bottom; |
||
26 | /** @var int */ |
||
27 | protected $left; |
||
28 | /** @var int */ |
||
29 | protected $right; |
||
30 | |||
31 | 8 | public function __construct($x, $y, $width, $height) |
|
40 | |||
41 | 1 | public static function constructFromImagine(PointInterface $point, BoxInterface $box) |
|
45 | |||
46 | 8 | protected function update() |
|
53 | |||
54 | /** |
||
55 | * Detect box collision |
||
56 | * This algorithm only works with Axis-Aligned boxes! |
||
57 | * @param Box $box The other rectangle to test collision with |
||
58 | * @return boolean True is the boxes collide, false otherwise |
||
59 | */ |
||
60 | 8 | public function intersects(Box $box) |
|
68 | |||
69 | /** |
||
70 | * @param Box $box |
||
71 | * @return bool |
||
72 | */ |
||
73 | 4 | public function inside(Box $box) |
|
81 | |||
82 | /** |
||
83 | * @param int $deltaX |
||
84 | * @param int $deltaY |
||
85 | * @return \SixtyNine\Cloud\Model\Box |
||
86 | */ |
||
87 | 4 | public function move($deltaX, $deltaY) |
|
91 | |||
92 | /** |
||
93 | * @return int |
||
94 | */ |
||
95 | 6 | public function getBottom() |
|
99 | |||
100 | /** |
||
101 | * @return int |
||
102 | */ |
||
103 | 6 | public function getHeight() |
|
107 | |||
108 | /** |
||
109 | * @return int |
||
110 | */ |
||
111 | 8 | public function getLeft() |
|
115 | |||
116 | /** |
||
117 | * @return int |
||
118 | */ |
||
119 | 8 | public function getRight() |
|
123 | |||
124 | /** |
||
125 | * @return int |
||
126 | */ |
||
127 | 6 | public function getTop() |
|
131 | |||
132 | /** |
||
133 | * @return int |
||
134 | */ |
||
135 | 6 | public function getWidth() |
|
139 | |||
140 | /** |
||
141 | * @return int |
||
142 | */ |
||
143 | 4 | public function getX() |
|
147 | |||
148 | /** |
||
149 | * @return int |
||
150 | */ |
||
151 | 4 | public function getY() |
|
155 | |||
156 | /** |
||
157 | * @return Point |
||
158 | */ |
||
159 | 4 | public function getPosition() |
|
163 | |||
164 | /** |
||
165 | * @return \Imagine\Image\Box |
||
166 | */ |
||
167 | 3 | public function getDimensions() |
|
171 | |||
172 | function __toString() |
||
176 | } |
||
177 | |||
178 |
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.