26
26
use function abs ;
27
27
use const PHP_INT_MAX ;
28
28
29
- final class AxisAlignedBB{
29
+ final readonly class AxisAlignedBB{
30
30
31
31
public float $ minX ;
32
32
public float $ minY ;
@@ -93,21 +93,14 @@ public function addCoord(float $x, float $y, float $z) : AxisAlignedBB{
93
93
* @return $this
94
94
*/
95
95
public function expand (float $ x , float $ y , float $ z ){
96
- $ this ->minX -= $ x ;
97
- $ this ->minY -= $ y ;
98
- $ this ->minZ -= $ z ;
99
- $ this ->maxX += $ x ;
100
- $ this ->maxY += $ y ;
101
- $ this ->maxZ += $ z ;
102
-
103
- return $ this ;
104
- }
105
-
106
- /**
107
- * Returns an expanded clone of this AxisAlignedBB.
108
- */
109
- public function expandedCopy (float $ x , float $ y , float $ z ) : AxisAlignedBB {
110
- return (clone $ this )->expand ($ x , $ y , $ z );
96
+ return new AxisAlignedBB (
97
+ $ this ->minX - $ x ,
98
+ $ this ->minY - $ y ,
99
+ $ this ->minZ - $ z ,
100
+ $ this ->maxX + $ x ,
101
+ $ this ->maxY + $ y ,
102
+ $ this ->maxZ + $ z
103
+ );
111
104
}
112
105
113
106
/**
@@ -116,21 +109,14 @@ public function expandedCopy(float $x, float $y, float $z) : AxisAlignedBB{
116
109
* @return $this
117
110
*/
118
111
public function offset (float $ x , float $ y , float $ z ) : AxisAlignedBB {
119
- $ this ->minX += $ x ;
120
- $ this ->minY += $ y ;
121
- $ this ->minZ += $ z ;
122
- $ this ->maxX += $ x ;
123
- $ this ->maxY += $ y ;
124
- $ this ->maxZ += $ z ;
125
-
126
- return $ this ;
127
- }
128
-
129
- /**
130
- * Returns an offset clone of this AxisAlignedBB.
131
- */
132
- public function offsetCopy (float $ x , float $ y , float $ z ) : AxisAlignedBB {
133
- return (clone $ this )->offset ($ x , $ y , $ z );
112
+ return new AxisAlignedBB (
113
+ $ this ->minX + $ x ,
114
+ $ this ->minY + $ y ,
115
+ $ this ->minZ + $ z ,
116
+ $ this ->maxX + $ x ,
117
+ $ this ->maxY + $ y ,
118
+ $ this ->maxZ + $ z
119
+ );
134
120
}
135
121
136
122
/**
@@ -144,34 +130,20 @@ public function offsetTowards(Facing $face, float $distance) : AxisAlignedBB{
144
130
return $ this ->offset ($ offsetX * $ distance , $ offsetY * $ distance , $ offsetZ * $ distance );
145
131
}
146
132
147
- /**
148
- * Returns an offset clone of this AxisAlignedBB.
149
- */
150
- public function offsetTowardsCopy (Facing $ face , float $ distance ) : AxisAlignedBB {
151
- return (clone $ this )->offsetTowards ($ face , $ distance );
152
- }
153
-
154
133
/**
155
134
* Insets the bounds of this AxisAlignedBB by the specified X, Y and Z.
156
135
*
157
136
* @return $this
158
137
*/
159
138
public function contract (float $ x , float $ y , float $ z ) : AxisAlignedBB {
160
- $ this ->minX += $ x ;
161
- $ this ->minY += $ y ;
162
- $ this ->minZ += $ z ;
163
- $ this ->maxX -= $ x ;
164
- $ this ->maxY -= $ y ;
165
- $ this ->maxZ -= $ z ;
166
-
167
- return $ this ;
168
- }
169
-
170
- /**
171
- * Returns a contracted clone of this AxisAlignedBB.
172
- */
173
- public function contractedCopy (float $ x , float $ y , float $ z ) : AxisAlignedBB {
174
- return (clone $ this )->contract ($ x , $ y , $ z );
139
+ return new AxisAlignedBB (
140
+ $ this ->minX + $ x ,
141
+ $ this ->minY + $ y ,
142
+ $ this ->minZ + $ z ,
143
+ $ this ->maxX - $ x ,
144
+ $ this ->maxY - $ y ,
145
+ $ this ->maxZ - $ z
146
+ );
175
147
}
176
148
177
149
/**
@@ -182,24 +154,14 @@ public function contractedCopy(float $x, float $y, float $z) : AxisAlignedBB{
182
154
* @return $this
183
155
*/
184
156
public function extend (Facing $ face , float $ distance ) : AxisAlignedBB {
185
- match ($ face ){
186
- Facing::DOWN => $ this ->minY -= $ distance ,
187
- Facing::UP => $ this ->maxY += $ distance ,
188
- Facing::NORTH => $ this ->minZ -= $ distance ,
189
- Facing::SOUTH => $ this ->maxZ += $ distance ,
190
- Facing::WEST => $ this ->minX -= $ distance ,
191
- Facing::EAST => $ this ->maxX += $ distance ,
157
+ return match ($ face ){
158
+ Facing::DOWN => new AxisAlignedBB ( $ this ->minX , $ this -> minY - $ distance, $ this -> minZ , $ this -> maxX , $ this -> maxY , $ this -> maxZ ) ,
159
+ Facing::UP => new AxisAlignedBB ( $ this ->minX , $ this -> minY , $ this -> minZ , $ this -> maxX + $ distance, $ this -> maxY , $ this -> maxZ ) ,
160
+ Facing::NORTH => new AxisAlignedBB ( $ this ->minX , $ this -> minY , $ this -> minZ - $ distance, $ this -> maxX , $ this -> maxY , $ this -> maxZ ) ,
161
+ Facing::SOUTH => new AxisAlignedBB ( $ this ->minX , $ this -> minY , $ this -> minZ , $ this -> maxX , $ this -> maxY , $ this -> maxZ + $ distance) ,
162
+ Facing::WEST => new AxisAlignedBB ( $ this ->minX - $ distance, $ this -> minY , $ this -> minZ , $ this -> maxX , $ this -> maxY , $ this -> maxZ ) ,
163
+ Facing::EAST => new AxisAlignedBB ( $ this ->minX , $ this -> minY , $ this -> minZ , $ this -> maxX + $ distance , $ this -> maxY , $ this -> maxZ )
192
164
};
193
-
194
- return $ this ;
195
- }
196
-
197
- /**
198
- * Returns an extended clone of this bounding box.
199
- * @see AxisAlignedBB::extend()
200
- */
201
- public function extendedCopy (Facing $ face , float $ distance ) : AxisAlignedBB {
202
- return (clone $ this )->extend ($ face , $ distance );
203
165
}
204
166
205
167
/**
@@ -214,14 +176,6 @@ public function trim(Facing $face, float $distance) : AxisAlignedBB{
214
176
return $ this ->extend ($ face , -$ distance );
215
177
}
216
178
217
- /**
218
- * Returns a trimmed clone of this bounding box.
219
- * @see AxisAlignedBB::trim()
220
- */
221
- public function trimmedCopy (Facing $ face , float $ distance ) : AxisAlignedBB {
222
- return $ this ->extendedCopy ($ face , -$ distance );
223
- }
224
-
225
179
/**
226
180
* Increases the dimension of the AABB along the given axis.
227
181
*
@@ -230,26 +184,11 @@ public function trimmedCopy(Facing $face, float $distance) : AxisAlignedBB{
230
184
* @return $this
231
185
*/
232
186
public function stretch (Axis $ axis , float $ distance ) : AxisAlignedBB {
233
- if ($ axis === Axis::Y){
234
- $ this ->minY -= $ distance ;
235
- $ this ->maxY += $ distance ;
236
- }elseif ($ axis === Axis::Z){
237
- $ this ->minZ -= $ distance ;
238
- $ this ->maxZ += $ distance ;
239
- }elseif ($ axis === Axis::X){
240
- $ this ->minX -= $ distance ;
241
- $ this ->maxX += $ distance ;
242
- }
243
-
244
- return $ this ;
245
- }
246
-
247
- /**
248
- * Returns a stretched copy of this bounding box.
249
- * @see AxisAlignedBB::stretch()
250
- */
251
- public function stretchedCopy (Axis $ axis , float $ distance ) : AxisAlignedBB {
252
- return (clone $ this )->stretch ($ axis , $ distance );
187
+ return match ($ axis ){
188
+ Axis::Y => new AxisAlignedBB ($ this ->minX , $ this ->minY - $ distance , $ this ->minZ , $ this ->maxX , $ this ->maxY + $ distance , $ this ->maxZ ),
189
+ Axis::Z => new AxisAlignedBB ($ this ->minX , $ this ->minY , $ this ->minZ - $ distance , $ this ->maxX , $ this ->maxY , $ this ->maxZ + $ distance ),
190
+ Axis::X => new AxisAlignedBB ($ this ->minX - $ distance , $ this ->minY , $ this ->minZ , $ this ->maxX + $ distance , $ this ->maxY , $ this ->maxZ )
191
+ };
253
192
}
254
193
255
194
/**
@@ -262,14 +201,6 @@ public function squash(Axis $axis, float $distance) : AxisAlignedBB{
262
201
return $ this ->stretch ($ axis , -$ distance );
263
202
}
264
203
265
- /**
266
- * Returns a squashed copy of this bounding box.
267
- * @see AxisAlignedBB::squash()
268
- */
269
- public function squashedCopy (Axis $ axis , float $ distance ) : AxisAlignedBB {
270
- return $ this ->stretchedCopy ($ axis , -$ distance );
271
- }
272
-
273
204
public function calculateXOffset (AxisAlignedBB $ bb , float $ x ) : float {
274
205
if ($ bb ->maxY <= $ this ->minY or $ bb ->minY >= $ this ->maxY ){
275
206
return $ x ;
0 commit comments