diff --git a/math/fixed/fixed.go b/math/fixed/fixed.go index 8e78e6c..60f83c8 100644 --- a/math/fixed/fixed.go +++ b/math/fixed/fixed.go @@ -11,6 +11,13 @@ import ( // TODO: implement fmt.Formatter for %f and %g. +// I returns the integer value i as an Int26_6. +// +// For example, the integer value 2 is the Int26_6 128. +func I(i int) Int26_6 { + return Int26_6(i << 6) +} + // Int26_6 is a signed 26.6 fixed-point number. // // The integer part ranges from -33554432 to 33554431, inclusive. The @@ -58,6 +65,13 @@ func (x Int52_12) String() string { return "-2251799813685248:0000" // The minimum value is -(1<<51). } +// P returns the integer values x and y as a Point26_6. +// +// For example, the integer value pair (2, -3) is the Point26_6 (128, -192). +func P(x, y int) Point26_6 { + return Point26_6{Int26_6(x << 6), Int26_6(y << 6)} +} + // Point26_6 is a 26.6 fixed-point coordinate pair. type Point26_6 struct { X, Y Int26_6