29 public const FLAG_AXIS_POSITIVE = 1;
32 case DOWN = Axis::Y->value << 1;
33 case UP = (Axis::Y->value << 1) | self::FLAG_AXIS_POSITIVE;
34 case NORTH = Axis::Z->value << 1;
35 case SOUTH = (Axis::Z->value << 1) | self::FLAG_AXIS_POSITIVE;
36 case WEST = Axis::X->value << 1;
37 case EAST = (Axis::X->value << 1) | self::FLAG_AXIS_POSITIVE;
48 public const HORIZONTAL = [
55 public const OFFSET = [
56 self::DOWN->value => [ 0, -1, 0],
57 self::UP->value => [ 0, +1, 0],
58 self::NORTH->value => [ 0, 0, -1],
59 self::SOUTH->value => [ 0, 0, +1],
60 self::WEST->value => [-1, 0, 0],
61 self::EAST->value => [+1, 0, 0]
64 private const CLOCKWISE = [
66 self::NORTH->value => self::EAST,
67 self::EAST->value => self::SOUTH,
68 self::SOUTH->value => self::WEST,
69 self::WEST->value => self::NORTH
72 self::UP->value => self::EAST,
73 self::EAST->value => self::DOWN,
74 self::DOWN->value => self::WEST,
75 self::WEST->value => self::UP
78 self::UP->value => self::NORTH,
79 self::NORTH->value => self::DOWN,
80 self::DOWN->value => self::SOUTH,
81 self::SOUTH->value => self::UP
89 return Axis::from($direction->value >> 1);
95 public static function isPositive(
Facing $direction) :
bool{
96 return ($direction->value & self::FLAG_AXIS_POSITIVE) === self::FLAG_AXIS_POSITIVE;
102 public static function opposite(
Facing $direction) :
Facing{
103 return self::from($direction->value ^ self::FLAG_AXIS_POSITIVE);
111 public static function rotate(
Facing $direction,
Axis $axis,
bool $clockwise) :
Facing{
112 if(!isset(self::CLOCKWISE[$axis->value][$direction->value])){
113 throw new \InvalidArgumentException(
"Cannot rotate facing \"" . self::toString($direction) .
"\" around axis \"" .
Axis::toString($axis) .
"\"");
116 $rotated = self::CLOCKWISE[$axis->value][$direction->value];
117 return $clockwise ? $rotated : self::opposite($rotated);
123 public static function rotateY(
Facing $direction,
bool $clockwise) :
Facing{
124 return self::rotate($direction, Axis::Y, $clockwise);
130 public static function rotateZ(
Facing $direction,
bool $clockwise) :
Facing{
131 return self::rotate($direction, Axis::Z, $clockwise);
137 public static function rotateX(
Facing $direction,
bool $clockwise) :
Facing{
138 return self::rotate($direction, Axis::X, $clockwise);
145 return strtolower($facing->name);