Simplified Vector3::getOppositeSide() (#377)

* Simplified Vector3::getOppositeSide()

* Throw exception on bad input values

* @throws doc
This commit is contained in:
Dylan K. Taylor 2017-03-05 11:30:12 +00:00 committed by SOFe
parent e33eb0ddb6
commit c569fd86b1

View File

@ -157,23 +157,20 @@ class Vector3{
} }
} }
public static function getOppositeSide($side){ /**
switch((int) $side){ * Returns the Vector3 side number opposite the specified one
case Vector3::SIDE_DOWN: *
return Vector3::SIDE_UP; * @param int $side 0-5 one of the Vector3::SIDE_* constants
case Vector3::SIDE_UP: * @return int
return Vector3::SIDE_DOWN; *
case Vector3::SIDE_NORTH: * @throws \InvalidArgumentException if an invalid side is supplied
return Vector3::SIDE_SOUTH; */
case Vector3::SIDE_SOUTH: public static function getOppositeSide(int $side) : int{
return Vector3::SIDE_NORTH; if($side >= 0 and $side <= 5){
case Vector3::SIDE_WEST: return $side ^ 0x01;
return Vector3::SIDE_EAST;
case Vector3::SIDE_EAST:
return Vector3::SIDE_WEST;
default:
return -1;
} }
throw new \InvalidArgumentException("Invalid side $side given to getOppositeSide");
} }
public function distance(Vector3 $pos){ public function distance(Vector3 $pos){