math/fixed: add I and P helper functions.
The P function is especially common in e.g. Freetype code that works with both the integer-pixel (X,Y) coordinates used by the stdlib image package and sub-pixel (X,Y) coordinates used by its raster package. Change-Id: I68be8ca71ceb24f40277ecc39a0896323f6671f5 Reviewed-on: https://go-review.googlesource.com/13652 Reviewed-by: Rob Pike <r@golang.org>
This commit is contained in:
parent
b137518d47
commit
d9c0088098
|
@ -11,6 +11,13 @@ import (
|
||||||
|
|
||||||
// TODO: implement fmt.Formatter for %f and %g.
|
// 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.
|
// Int26_6 is a signed 26.6 fixed-point number.
|
||||||
//
|
//
|
||||||
// The integer part ranges from -33554432 to 33554431, inclusive. The
|
// 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).
|
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.
|
// Point26_6 is a 26.6 fixed-point coordinate pair.
|
||||||
type Point26_6 struct {
|
type Point26_6 struct {
|
||||||
X, Y Int26_6
|
X, Y Int26_6
|
||||||
|
|
Loading…
Reference in New Issue
Block a user