up3
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package cube
|
||||
|
||||
import "math"
|
||||
|
||||
// Orientation represents the rotation of a block divided into 16 options.
|
||||
type Orientation int
|
||||
|
||||
// OrientationFromYaw returns an Orientation value that (roughly) matches the
|
||||
// yaw passed.
|
||||
func OrientationFromYaw(yaw float64) Orientation {
|
||||
yaw = math.Mod(yaw, 360)
|
||||
return Orientation(math.Round(yaw / 360 * 16))
|
||||
}
|
||||
|
||||
// Yaw returns the yaw value that matches the orientation.
|
||||
func (o Orientation) Yaw() float64 {
|
||||
return float64(o) / 16 * 360
|
||||
}
|
||||
|
||||
// Opposite returns the opposite orientation value of the Orientation.
|
||||
func (o Orientation) Opposite() Orientation {
|
||||
return OrientationFromYaw(o.Yaw() + 180)
|
||||
}
|
||||
|
||||
// RotateLeft rotates the orientation left by 90 degrees and returns it.
|
||||
func (o Orientation) RotateLeft() Orientation {
|
||||
return OrientationFromYaw(o.Yaw() - 90)
|
||||
}
|
||||
|
||||
// RotateRight rotates the orientation right by 90 degrees and returns it.
|
||||
func (o Orientation) RotateRight() Orientation {
|
||||
return OrientationFromYaw(o.Yaw() + 90)
|
||||
}
|
||||
Reference in New Issue
Block a user