github.com/df-mc/dragonfly@v0.9.13/server/block/cube/orientation.go (about) 1 package cube 2 3 import "math" 4 5 // Orientation represents the orientation of a sign 6 type Orientation int 7 8 // OrientationFromYaw returns an Orientation value that (roughly) matches the yaw passed. 9 func OrientationFromYaw(yaw float64) Orientation { 10 yaw = math.Mod(yaw, 360) 11 return Orientation(math.Round(yaw / 360 * 16)) 12 } 13 14 // Yaw returns the yaw value that matches the orientation. 15 func (o Orientation) Yaw() float64 { 16 return float64(o) / 16 * 360 17 } 18 19 // Opposite returns the opposite orientation value of the Orientation. 20 func (o Orientation) Opposite() Orientation { 21 return OrientationFromYaw(o.Yaw() + 180) 22 } 23 24 // RotateLeft rotates the orientation left by 90 degrees and returns it. 25 func (o Orientation) RotateLeft() Orientation { 26 return OrientationFromYaw(o.Yaw() - 90) 27 } 28 29 // RotateRight rotates the orientation right by 90 degrees and returns it. 30 func (o Orientation) RotateRight() Orientation { 31 return OrientationFromYaw(o.Yaw() + 90) 32 }