Skip to content

Commit

Permalink
AxisAlignedBB: modernize extend() code
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Aug 3, 2023
1 parent cf12e7a commit 44fd696
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/AxisAlignedBB.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,21 +185,15 @@ public function contractedCopy(float $x, float $y, float $z) : AxisAlignedBB{
* @throws \InvalidArgumentException
*/
public function extend(int $face, float $distance) : AxisAlignedBB{
if($face === Facing::DOWN){
$this->minY -= $distance;
}elseif($face === Facing::UP){
$this->maxY += $distance;
}elseif($face === Facing::NORTH){
$this->minZ -= $distance;
}elseif($face === Facing::SOUTH){
$this->maxZ += $distance;
}elseif($face === Facing::WEST){
$this->minX -= $distance;
}elseif($face === Facing::EAST){
$this->maxX += $distance;
}else{
throw new \InvalidArgumentException("Invalid face $face");
}
match($face){
Facing::DOWN => $this->minY -= $distance,
Facing::UP => $this->maxY += $distance,
Facing::NORTH => $this->minZ -= $distance,
Facing::SOUTH => $this->maxZ += $distance,
Facing::WEST => $this->minX -= $distance,
Facing::EAST => $this->maxX += $distance,
default => throw new \InvalidArgumentException("Invalid face $face"),
};

return $this;
}
Expand Down

0 comments on commit 44fd696

Please sign in to comment.