Skip to content

Commit

Permalink
Fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhaiven committed May 12, 2024
1 parent 89f49e0 commit 54d40bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
17 changes: 9 additions & 8 deletions src/AxisAlignedBB.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,17 +457,18 @@ public function calculateIntercept(Vector3 $pos1, Vector3 $pos2) : ?RayTraceResu
$face = -1;

foreach([
Facing::WEST => $v1,
Facing::EAST => $v2,
Facing::DOWN => $v3,
Facing::UP => $v4,
Facing::NORTH => $v5,
Facing::SOUTH => $v6
] as $f => $v){
[Facing::WEST, $v1],
[Facing::EAST, $v2],
[Facing::DOWN, $v3],
[Facing::UP, $v4],
[Facing::NORTH, $v5],
[Facing::SOUTH, $v6]
] as $value){
$v = $value[1];
if($v !== null and ($d = $pos1->distanceSquared($v)) < $distance){
$vector = $v;
$distance = $d;
$face = $f;
$face = $value[0];
}
}

Expand Down
14 changes: 10 additions & 4 deletions src/Facing.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public static function axis(Facing $direction) : Axis{
};
}

public function offset(): array{
/**
* @return non-empty-array<int>
*/
public function offset() : array{
return match ($this) {
self::DOWN => [ 0, -1, 0],
self::UP => [ 0, +1, 0],
Expand Down Expand Up @@ -90,19 +93,22 @@ public static function rotate(Facing $direction, Axis $axis, bool $clockwise) :
self::NORTH => self::EAST,
self::EAST => self::SOUTH,
self::SOUTH => self::WEST,
self::WEST => self::NORTH
self::WEST => self::NORTH,
default => throw new \InvalidArgumentException("Face " . strtolower($direction->name) . " not match with Axis " . strtolower($axis->name))
},
Axis::Z => match ($direction) {
self::UP => self::EAST,
self::EAST => self::DOWN,
self::DOWN => self::WEST,
self::WEST => self::UP
self::WEST => self::UP,
default => throw new \InvalidArgumentException("Face " . strtolower($direction->name) . " not match with Axis " . strtolower($axis->name))
},
Axis::X => match ($direction) {
self::UP => self::NORTH,
self::NORTH => self::DOWN,
self::DOWN => self::SOUTH,
self::SOUTH => self::UP
self::SOUTH => self::UP,
default => throw new \InvalidArgumentException("Face " . strtolower($direction->name) . " not match with Axis " . strtolower($axis->name))
}
};

Expand Down
12 changes: 6 additions & 6 deletions src/Vector3.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ public function east(int $step = 1){
*
* @param int $step Distance in each direction to shift the vector
*
* @return \Generator|Vector3[]
* @phpstan-return \Generator<int, Vector3, void, void>
* @return \Generator|array
* @phpstan-return \Generator<Facing, Vector3, void, void>
*/
public function sides(int $step = 1) : \Generator{
foreach(Facing::cases() as $facing){
yield $facing => $this->getSide($facing, $step);
yield [$facing, $this->getSide($facing, $step)];

Check failure on line 178 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Generator expects key type pocketmine\math\Facing, int given.

Check failure on line 178 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Generator expects value type pocketmine\math\Vector3, array<int, pocketmine\math\Facing::DOWN|pocketmine\math\Facing::EAST|pocketmine\math\Facing::NORTH|pocketmine\math\Facing::SOUTH|pocketmine\math\Facing::UP|pocketmine\math\Facing::WEST|pocketmine\math\Vector3> given.

Check failure on line 178 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Generator expects key type pocketmine\math\Facing, int given.

Check failure on line 178 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Generator expects value type pocketmine\math\Vector3, array<int, pocketmine\math\Facing::DOWN|pocketmine\math\Facing::EAST|pocketmine\math\Facing::NORTH|pocketmine\math\Facing::SOUTH|pocketmine\math\Facing::UP|pocketmine\math\Facing::WEST|pocketmine\math\Vector3> given.

Check failure on line 178 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Generator expects key type pocketmine\math\Facing, int given.

Check failure on line 178 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Generator expects value type pocketmine\math\Vector3, array<int, pocketmine\math\Facing::DOWN|pocketmine\math\Facing::EAST|pocketmine\math\Facing::NORTH|pocketmine\math\Facing::SOUTH|pocketmine\math\Facing::UP|pocketmine\math\Facing::WEST|pocketmine\math\Vector3> given.
}
}

Expand All @@ -191,13 +191,13 @@ public function sidesArray(bool $keys = false, int $step = 1) : array{
/**
* Yields vectors stepped out from this one in directions except those on the given axis.
*
* @return \Generator|Vector3[]
* @phpstan-return \Generator<int, Vector3, void, void>
* @return \Generator|array
* @phpstan-return \Generator<Facing, Vector3, void, void>
*/
public function sidesAroundAxis(Axis $axis, int $step = 1) : \Generator{
foreach(Facing::cases() as $facing){
if(Facing::axis($facing) !== $axis){
yield $facing => $this->getSide($facing, $step);
yield [$facing, $this->getSide($facing, $step)];

Check failure on line 200 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Generator expects key type pocketmine\math\Facing, int given.

Check failure on line 200 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Generator expects value type pocketmine\math\Vector3, array<int, pocketmine\math\Facing::DOWN|pocketmine\math\Facing::EAST|pocketmine\math\Facing::NORTH|pocketmine\math\Facing::SOUTH|pocketmine\math\Facing::UP|pocketmine\math\Facing::WEST|pocketmine\math\Vector3> given.

Check failure on line 200 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Generator expects key type pocketmine\math\Facing, int given.

Check failure on line 200 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Generator expects value type pocketmine\math\Vector3, array<int, pocketmine\math\Facing::DOWN|pocketmine\math\Facing::EAST|pocketmine\math\Facing::NORTH|pocketmine\math\Facing::SOUTH|pocketmine\math\Facing::UP|pocketmine\math\Facing::WEST|pocketmine\math\Vector3> given.

Check failure on line 200 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Generator expects key type pocketmine\math\Facing, int given.

Check failure on line 200 in src/Vector3.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Generator expects value type pocketmine\math\Vector3, array<int, pocketmine\math\Facing::DOWN|pocketmine\math\Facing::EAST|pocketmine\math\Facing::NORTH|pocketmine\math\Facing::SOUTH|pocketmine\math\Facing::UP|pocketmine\math\Facing::WEST|pocketmine\math\Vector3> given.
}
}
}
Expand Down

0 comments on commit 54d40bb

Please sign in to comment.