Skip to content

Commit

Permalink
Vector3: simplify getSide()
Browse files Browse the repository at this point in the history
  • Loading branch information
dktapps committed Aug 3, 2023
1 parent 2c0be33 commit cf12e7a
Showing 1 changed file with 3 additions and 16 deletions.
19 changes: 3 additions & 16 deletions src/Vector3.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,9 @@ public function abs() : Vector3{
* @return Vector3
*/
public function getSide(int $side, int $step = 1){
switch($side){
case Facing::DOWN:
return new Vector3($this->x, $this->y - $step, $this->z);
case Facing::UP:
return new Vector3($this->x, $this->y + $step, $this->z);
case Facing::NORTH:
return new Vector3($this->x, $this->y, $this->z - $step);
case Facing::SOUTH:
return new Vector3($this->x, $this->y, $this->z + $step);
case Facing::WEST:
return new Vector3($this->x - $step, $this->y, $this->z);
case Facing::EAST:
return new Vector3($this->x + $step, $this->y, $this->z);
default:
return $this;
}
[$offsetX, $offsetY, $offsetZ] = Facing::OFFSET[$side] ?? [0, 0, 0];

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

/**
Expand Down

0 comments on commit cf12e7a

Please sign in to comment.