Skip to content

Commit 2839326

Browse files
committed
remove changes out of scope of this pr
1 parent 72b08b4 commit 2839326

File tree

4 files changed

+94
-73
lines changed

4 files changed

+94
-73
lines changed

src/AxisAlignedBB.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,14 @@ public function intersectsWith(AxisAlignedBB $bb, float $epsilon = 0.00001) : bo
370370
* Returns whether the specified vector is within the bounds of this AABB on all axes.
371371
*/
372372
public function isVectorInside(Vector3 $vector) : bool{
373-
if($vector->getX() <= $this->minX or $vector->getX() >= $this->maxX){
373+
if($vector->x <= $this->minX or $vector->x >= $this->maxX){
374374
return false;
375375
}
376-
if($vector->getY() <= $this->minY or $vector->getY() >= $this->maxY){
376+
if($vector->y <= $this->minY or $vector->y >= $this->maxY){
377377
return false;
378378
}
379379

380-
return $vector->getZ() > $this->minZ and $vector->getZ() < $this->maxZ;
380+
return $vector->z > $this->minZ and $vector->z < $this->maxZ;
381381
}
382382

383383
/**
@@ -409,21 +409,21 @@ public function getVolume() : float{
409409
* Returns whether the specified vector is within the Y and Z bounds of this AABB.
410410
*/
411411
public function isVectorInYZ(Vector3 $vector) : bool{
412-
return $vector->getY() >= $this->minY and $vector->getY() <= $this->maxY and $vector->getZ() >= $this->minZ and $vector->getZ() <= $this->maxZ;
412+
return $vector->y >= $this->minY and $vector->y <= $this->maxY and $vector->z >= $this->minZ and $vector->z <= $this->maxZ;
413413
}
414414

415415
/**
416416
* Returns whether the specified vector is within the X and Z bounds of this AABB.
417417
*/
418418
public function isVectorInXZ(Vector3 $vector) : bool{
419-
return $vector->getX() >= $this->minX and $vector->getX() <= $this->maxX and $vector->getZ() >= $this->minZ and $vector->getZ() <= $this->maxZ;
419+
return $vector->x >= $this->minX and $vector->x <= $this->maxX and $vector->z >= $this->minZ and $vector->z <= $this->maxZ;
420420
}
421421

422422
/**
423423
* Returns whether the specified vector is within the X and Y bounds of this AABB.
424424
*/
425425
public function isVectorInXY(Vector3 $vector) : bool{
426-
return $vector->getX() >= $this->minX and $vector->getX() <= $this->maxX and $vector->getY() >= $this->minY and $vector->getY() <= $this->maxY;
426+
return $vector->x >= $this->minX and $vector->x <= $this->maxX and $vector->y >= $this->minY and $vector->y <= $this->maxY;
427427
}
428428

429429
/**

src/Vector3.php

Lines changed: 76 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -36,54 +36,54 @@
3636
readonly class Vector3{
3737

3838
public function __construct(
39-
protected float|int $x,
40-
protected float|int $y,
41-
protected float|int $z
39+
public float|int $x,
40+
public float|int $y,
41+
public float|int $z
4242
){}
4343

4444
public static function zero() : Vector3{
4545
//TODO: make this reuse a single object, once Vector3 becomes immutable
4646
return new self(0, 0, 0);
4747
}
4848

49-
final public function getX() : float|int{
49+
public function getX() : float|int{
5050
return $this->x;
5151
}
5252

53-
final public function getY() : float|int{
53+
public function getY() : float|int{
5454
return $this->y;
5555
}
5656

57-
final public function getZ() : float|int{
57+
public function getZ() : float|int{
5858
return $this->z;
5959
}
6060

61-
final public function getFloorX() : int{
61+
public function getFloorX() : int{
6262
return (int) floor($this->x);
6363
}
6464

65-
final public function getFloorY() : int{
65+
public function getFloorY() : int{
6666
return (int) floor($this->y);
6767
}
6868

69-
final public function getFloorZ() : int{
69+
public function getFloorZ() : int{
7070
return (int) floor($this->z);
7171
}
7272

7373
public function add(float|int $x, float|int $y, float|int $z) : Vector3{
7474
return new Vector3($this->x + $x, $this->y + $y, $this->z + $z);
7575
}
7676

77-
final public function addVector(Vector3 $v) : Vector3{
78-
return $this->add($v->getX(), $v->getY(), $v->getZ());
77+
public function addVector(Vector3 $v) : Vector3{
78+
return $this->add($v->x, $v->y, $v->z);
7979
}
8080

81-
final public function subtract(float|int $x, float|int $y, float|int $z) : Vector3{
81+
public function subtract(float|int $x, float|int $y, float|int $z) : Vector3{
8282
return $this->add(-$x, -$y, -$z);
8383
}
8484

85-
final public function subtractVector(Vector3 $v) : Vector3{
86-
return $this->add(-$v->getX(), -$v->getY(), -$v->getZ());
85+
public function subtractVector(Vector3 $v) : Vector3{
86+
return $this->add(-$v->x, -$v->y, -$v->z);
8787
}
8888

8989
public function multiply(float $number) : Vector3{
@@ -115,33 +115,54 @@ public function abs() : Vector3{
115115
return new Vector3(abs($this->x), abs($this->y), abs($this->z));
116116
}
117117

118-
final public function getSide(int $side, int $step = 1) : Vector3{
118+
/**
119+
* @return Vector3
120+
*/
121+
public function getSide(int $side, int $step = 1){
119122
[$offsetX, $offsetY, $offsetZ] = Facing::OFFSET[$side] ?? [0, 0, 0];
120123

121124
return $this->add($offsetX * $step, $offsetY * $step, $offsetZ * $step);
122125
}
123126

124-
final public function down(int $step = 1) : Vector3{
127+
/**
128+
* @return Vector3
129+
*/
130+
public function down(int $step = 1){
125131
return $this->getSide(Facing::DOWN, $step);
126132
}
127133

128-
final public function up(int $step = 1) : Vector3{
134+
/**
135+
* @return Vector3
136+
*/
137+
public function up(int $step = 1){
129138
return $this->getSide(Facing::UP, $step);
130139
}
131140

132-
final public function north(int $step = 1) : Vector3{
141+
/**
142+
* @return Vector3
143+
*/
144+
public function north(int $step = 1){
133145
return $this->getSide(Facing::NORTH, $step);
134146
}
135147

136-
final public function south(int $step = 1) : Vector3{
148+
/**
149+
* @return Vector3
150+
*/
151+
public function south(int $step = 1){
137152
return $this->getSide(Facing::SOUTH, $step);
138153
}
139154

140-
final public function west(int $step = 1) : Vector3{
155+
/**
156+
* @return Vector3
157+
*/
158+
public function west(int $step = 1){
141159
return $this->getSide(Facing::WEST, $step);
142160
}
143161

144-
final public function east(int $step = 1) : Vector3{
162+
/**
163+
* @return Vector3
164+
*/
165+
public function east(int $step = 1){
145166
return $this->getSide(Facing::EAST, $step);
146167
}
147168

@@ -153,7 +174,7 @@ final public function east(int $step = 1) : Vector3{
153174
* @return \Generator|Vector3[]
154175
* @phpstan-return \Generator<int, Vector3, void, void>
155176
*/
156-
final public function sides(int $step = 1) : \Generator{
177+
public function sides(int $step = 1) : \Generator{
157178
foreach(Facing::ALL as $facing){
158179
yield $facing => $this->getSide($facing, $step);
159180
}
@@ -164,7 +185,7 @@ final public function sides(int $step = 1) : \Generator{
164185
*
165186
* @return Vector3[]
166187
*/
167-
final public function sidesArray(bool $keys = false, int $step = 1) : array{
188+
public function sidesArray(bool $keys = false, int $step = 1) : array{
168189
return iterator_to_array($this->sides($step), $keys);
169190
}
170191

@@ -176,7 +197,7 @@ final public function sidesArray(bool $keys = false, int $step = 1) : array{
176197
* @return \Generator|Vector3[]
177198
* @phpstan-return \Generator<int, Vector3, void, void>
178199
*/
179-
final public function sidesAroundAxis(int $axis, int $step = 1) : \Generator{
200+
public function sidesAroundAxis(int $axis, int $step = 1) : \Generator{
180201
foreach(Facing::ALL as $facing){
181202
if(Facing::axis($facing) !== $axis){
182203
yield $facing => $this->getSide($facing, $step);
@@ -187,11 +208,11 @@ final public function sidesAroundAxis(int $axis, int $step = 1) : \Generator{
187208
/**
188209
* Return a Vector3 instance
189210
*/
190-
final public function asVector3() : Vector3{
211+
public function asVector3() : Vector3{
191212
return new Vector3($this->x, $this->y, $this->z);
192213
}
193214

194-
final public function distance(Vector3 $pos) : float{
215+
public function distance(Vector3 $pos) : float{
195216
return sqrt($this->distanceSquared($pos));
196217
}
197218

@@ -204,19 +225,19 @@ public function distanceSquared(Vector3 $pos) : float{
204225

205226
public function maxPlainDistance(Vector3|Vector2|float $x, float $z = 0) : float{
206227
if($x instanceof Vector3){
207-
return $this->maxPlainDistance($x->getX(), $x->getZ());
228+
return $this->maxPlainDistance($x->x, $x->z);
208229
}elseif($x instanceof Vector2){
209230
return $this->maxPlainDistance($x->x, $x->y);
210231
}else{
211232
return max(abs($this->x - $x), abs($this->z - $z));
212233
}
213234
}
214235

215-
final public function length() : float{
236+
public function length() : float{
216237
return sqrt($this->lengthSquared());
217238
}
218239

219-
final public function lengthSquared() : float{
240+
public function lengthSquared() : float{
220241
return $this->x * $this->x + $this->y * $this->y + $this->z * $this->z;
221242
}
222243

@@ -230,27 +251,27 @@ public function normalize() : Vector3{
230251
}
231252

232253
public function dot(Vector3 $v) : float{
233-
return $this->x * $v->getX() + $this->y * $v->getY() + $this->z * $v->getZ();
254+
return $this->x * $v->x + $this->y * $v->y + $this->z * $v->z;
234255
}
235256

236257
public function cross(Vector3 $v) : Vector3{
237258
return new Vector3(
238-
$this->y * $v->getZ() - $this->z * $v->getY(),
239-
$this->z * $v->getX() - $this->x * $v->getZ(),
240-
$this->x * $v->getY() - $this->y * $v->getX()
259+
$this->y * $v->z - $this->z * $v->y,
260+
$this->z * $v->x - $this->x * $v->z,
261+
$this->x * $v->y - $this->y * $v->x
241262
);
242263
}
243264

244265
public function equals(Vector3 $v) : bool{
245-
return $this->x == $v->getX() and $this->y == $v->getY() and $this->z == $v->getZ();
266+
return $this->x == $v->x and $this->y == $v->y and $this->z == $v->z;
246267
}
247268

248269
/**
249270
* Returns a new vector with x value equal to the second parameter, along the line between this vector and the
250271
* passed in vector, or null if not possible.
251272
*/
252273
public function getIntermediateWithXValue(Vector3 $v, float $x) : ?Vector3{
253-
$xDiff = $v->getX() - $this->x;
274+
$xDiff = $v->x - $this->x;
254275
if(($xDiff * $xDiff) < 0.0000001){
255276
return null;
256277
}
@@ -260,7 +281,7 @@ public function getIntermediateWithXValue(Vector3 $v, float $x) : ?Vector3{
260281
if($f < 0 or $f > 1){
261282
return null;
262283
}else{
263-
return new Vector3($x, $this->y + ($v->getY() - $this->y) * $f, $this->z + ($v->getZ() - $this->z) * $f);
284+
return new Vector3($x, $this->y + ($v->y - $this->y) * $f, $this->z + ($v->z - $this->z) * $f);
264285
}
265286
}
266287

@@ -269,7 +290,7 @@ public function getIntermediateWithXValue(Vector3 $v, float $x) : ?Vector3{
269290
* passed in vector, or null if not possible.
270291
*/
271292
public function getIntermediateWithYValue(Vector3 $v, float $y) : ?Vector3{
272-
$yDiff = $v->getY() - $this->y;
293+
$yDiff = $v->y - $this->y;
273294
if(($yDiff * $yDiff) < 0.0000001){
274295
return null;
275296
}
@@ -279,7 +300,7 @@ public function getIntermediateWithYValue(Vector3 $v, float $y) : ?Vector3{
279300
if($f < 0 or $f > 1){
280301
return null;
281302
}else{
282-
return new Vector3($this->x + ($v->getX() - $this->x) * $f, $y, $this->z + ($v->getZ() - $this->z) * $f);
303+
return new Vector3($this->x + ($v->x - $this->x) * $f, $y, $this->z + ($v->z - $this->z) * $f);
283304
}
284305
}
285306

@@ -288,7 +309,7 @@ public function getIntermediateWithYValue(Vector3 $v, float $y) : ?Vector3{
288309
* passed in vector, or null if not possible.
289310
*/
290311
public function getIntermediateWithZValue(Vector3 $v, float $z) : ?Vector3{
291-
$zDiff = $v->getZ() - $this->z;
312+
$zDiff = $v->z - $this->z;
292313
if(($zDiff * $zDiff) < 0.0000001){
293314
return null;
294315
}
@@ -298,7 +319,7 @@ public function getIntermediateWithZValue(Vector3 $v, float $z) : ?Vector3{
298319
if($f < 0 or $f > 1){
299320
return null;
300321
}else{
301-
return new Vector3($this->x + ($v->getX() - $this->x) * $f, $this->y + ($v->getY() - $this->y) * $f, $z);
322+
return new Vector3($this->x + ($v->x - $this->x) * $f, $this->y + ($v->y - $this->y) * $f, $z);
302323
}
303324
}
304325

@@ -324,13 +345,13 @@ public function withComponents(float|int|null $x, float|int|null $y, float|int|n
324345
* @param Vector3 ...$vectors
325346
*/
326347
public static function maxComponents(Vector3 $vector, Vector3 ...$vectors) : Vector3{
327-
$x = $vector->getX();
328-
$y = $vector->getY();
329-
$z = $vector->getZ();
348+
$x = $vector->x;
349+
$y = $vector->y;
350+
$z = $vector->z;
330351
foreach($vectors as $position){
331-
$x = max($x, $position->getX());
332-
$y = max($y, $position->getY());
333-
$z = max($z, $position->getZ());
352+
$x = max($x, $position->x);
353+
$y = max($y, $position->y);
354+
$z = max($z, $position->z);
334355
}
335356
return new Vector3($x, $y, $z);
336357
}
@@ -341,23 +362,23 @@ public static function maxComponents(Vector3 $vector, Vector3 ...$vectors) : Vec
341362
* @param Vector3 ...$vectors
342363
*/
343364
public static function minComponents(Vector3 $vector, Vector3 ...$vectors) : Vector3{
344-
$x = $vector->getX();
345-
$y = $vector->getY();
346-
$z = $vector->getZ();
365+
$x = $vector->x;
366+
$y = $vector->y;
367+
$z = $vector->z;
347368
foreach($vectors as $position){
348-
$x = min($x, $position->getX());
349-
$y = min($y, $position->getY());
350-
$z = min($z, $position->getZ());
369+
$x = min($x, $position->x);
370+
$y = min($y, $position->y);
371+
$z = min($z, $position->z);
351372
}
352373
return new Vector3($x, $y, $z);
353374
}
354375

355376
public static function sum(Vector3 ...$vector3s) : Vector3{
356377
$x = $y = $z = 0;
357378
foreach($vector3s as $vector3){
358-
$x += $vector3->getX();
359-
$y += $vector3->getY();
360-
$z += $vector3->getZ();
379+
$x += $vector3->x;
380+
$y += $vector3->y;
381+
$z += $vector3->z;
361382
}
362383
return new Vector3($x, $y, $z);
363384
}

src/VoxelRayTrace.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@ public static function betweenPoints(Vector3 $start, Vector3 $end) : \Generator{
7474

7575
$radius = $start->distance($end);
7676

77-
$stepX = $directionVector->getX() <=> 0;
78-
$stepY = $directionVector->getY() <=> 0;
79-
$stepZ = $directionVector->getZ() <=> 0;
77+
$stepX = $directionVector->x <=> 0;
78+
$stepY = $directionVector->y <=> 0;
79+
$stepZ = $directionVector->z <=> 0;
8080

8181
//Initialize the step accumulation variables depending how far into the current block the start position is. If
8282
//the start position is on the corner of the block, these will be zero.
83-
$tMaxX = self::rayTraceDistanceToBoundary($start->getX(), $directionVector->getX());
84-
$tMaxY = self::rayTraceDistanceToBoundary($start->getY(), $directionVector->getY());
85-
$tMaxZ = self::rayTraceDistanceToBoundary($start->getZ(), $directionVector->getZ());
83+
$tMaxX = self::rayTraceDistanceToBoundary($start->x, $directionVector->x);
84+
$tMaxY = self::rayTraceDistanceToBoundary($start->y, $directionVector->y);
85+
$tMaxZ = self::rayTraceDistanceToBoundary($start->z, $directionVector->z);
8686

8787
//The change in t on each axis when taking a step on that axis (always positive).
88-
$tDeltaX = $directionVector->getX() == 0 ? 0 : $stepX / $directionVector->getX();
89-
$tDeltaY = $directionVector->getY() == 0 ? 0 : $stepY / $directionVector->getY();
90-
$tDeltaZ = $directionVector->getZ() == 0 ? 0 : $stepZ / $directionVector->getZ();
88+
$tDeltaX = $directionVector->x == 0 ? 0 : $stepX / $directionVector->x;
89+
$tDeltaY = $directionVector->y == 0 ? 0 : $stepY / $directionVector->y;
90+
$tDeltaZ = $directionVector->z == 0 ? 0 : $stepZ / $directionVector->z;
9191

9292
while(true){
9393
yield $currentBlock;

0 commit comments

Comments
 (0)