From cf12e7acfb07536f8f83f61a27a53410d0db7151 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 3 Aug 2023 13:39:42 +0100 Subject: [PATCH] Vector3: simplify getSide() --- src/Vector3.php | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/src/Vector3.php b/src/Vector3.php index 47d0343..18f4024 100644 --- a/src/Vector3.php +++ b/src/Vector3.php @@ -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); } /**