Documentation ¶
Index ¶
- Constants
- type Point
- func (self Point) AddPoint(pt Point) Point
- func (self Point) AddUnits(x, y Unit) Point
- func (self Point) ImagePoint() image.Point
- func (self Point) In(rect Rect) bool
- func (self Point) String() string
- func (self Point) ToFloat32s() (x, y float32)
- func (self Point) ToFloat64s() (x, y float64)
- func (self Point) ToInts() (int, int)
- type Rect
- func (self Rect) AddPoint(pt Point) Rect
- func (self Rect) AddUnits(x, y Unit) Rect
- func (self Rect) Contains(pt Point) bool
- func (self Rect) Empty() bool
- func (self Rect) Height() Unit
- func (self Rect) ImageRect() image.Rectangle
- func (self Rect) IntHeight() int
- func (self Rect) IntOrigin() (int, int)
- func (self Rect) IntWidth() int
- func (self Rect) String() string
- func (self Rect) ToFloat64s() (minX, minY, maxX, maxY float64)
- func (self Rect) ToInts() (int, int, int, int)
- func (self Rect) Width() Unit
- type Unit
- func (self Unit) Abs() Unit
- func (self Unit) Away(reference int) Unit
- func (self Unit) Ceil() Unit
- func (self Unit) Div(divisor Unit) Unit
- func (self Unit) Floor() Unit
- func (self Unit) Fract() Unit
- func (self Unit) FractShift() Unit
- func (self Unit) HalfAway(reference int) Unit
- func (self Unit) HalfDown() Unit
- func (self Unit) HalfToward(reference int) Unit
- func (self Unit) HalfUp() Unit
- func (self Unit) IsWhole() bool
- func (self Unit) Mul(multiplier Unit) Unit
- func (self Unit) MulDown(multiplier Unit) Unit
- func (self Unit) MulInt(multiplier int) Unit
- func (self Unit) MulUp(multiplier Unit) Unit
- func (self Unit) QuantizeDown(step Unit) Unit
- func (self Unit) QuantizeUp(step Unit) Unit
- func (self Unit) Rescale(from, to Unit) Unit
- func (self Unit) ToFloat32() float32
- func (self Unit) ToFloat64() float64
- func (self Unit) ToInt() int
- func (self Unit) ToIntAway(reference int) int
- func (self Unit) ToIntCeil() int
- func (self Unit) ToIntFloor() int
- func (self Unit) ToIntHalfAway(reference int) int
- func (self Unit) ToIntHalfDown() int
- func (self Unit) ToIntHalfToward(reference int) int
- func (self Unit) ToIntHalfUp() int
- func (self Unit) ToIntToward(reference int) int
- func (self Unit) Toward(reference int) Unit
Constants ¶
const ( MaxUnit Unit = +0x7FFFFFFF MinUnit Unit = -0x7FFFFFFF - 1 One Unit = 64 // fract.One.ToInt() == 1 MaxInt int = +33554431 MinInt int = -33554432 MaxFloat64 float64 = +33554431.984375 MinFloat64 float64 = -33554432 Delta float64 = 0.015625 // 1.0/64.0 HalfDelta float64 = 0.0078125 // 1.0/128.0 )
Minimum and maximum constants.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Point ¶
func UnitsToPoint ¶
func (Point) ImagePoint ¶
func (Point) ToFloat32s ¶
func (Point) ToFloat64s ¶
type Unit ¶
type Unit int32
Fixed point type to represent fractional values used for font rendering.
26 bits represent the integer part of the value, while the remaining 6 bits represent the decimal part. For an intuitive understanding, if you can understand that var ms Millis = 1000 is storing the equivalent to 1 second, with Unit, instead of 1/1000ths of a value, you are storing 1/64ths. So, var pixels Unit = 64 would mean 1 pixel, and 96 would be 1.5 pixels.
The internal representation is compatible with [fixed.Int26_6].
[fixed.Int26_6]: golang.org/x/image/math/fixed.Int26_6
func FromFloat64 ¶
Converts a float64 to the closest Unit, rounding away frmo zero in case of ties. Doesn't account for NaNs, infinites nor overflows. See also FromFloat64Up() and FromFloat64Down().
func FromFloat64Down ¶
Converts a float64 to the closest Unit, rounding down in case of ties. Doesn't account for NaNs, infinites nor overflows.
func FromFloat64Up ¶
Converts a float64 to the closest Unit, rounding up in case of ties. Doesn't account for NaNs, infinites nor overflows.
func FromInt ¶
Fast conversion from int to Unit. If the int value is not representable with a Unit, the result is undefined. If you want to account for overflows, check MinInt <= value <= MaxInt.
func (Unit) FractShift ¶
Returns only the fractional part of the unit as a non-negative value relative to the unit's floor.
func (Unit) HalfToward ¶
func (Unit) QuantizeDown ¶
Given a fractional step between 1 and 64, it quantizes the Unit to that fractional value, rounding down in case of ties.
func (Unit) QuantizeUp ¶
Given a fractional step between 1 and 64, it quantizes the Unit to that fractional value, rounding up in case of ties.
func (Unit) Rescale ¶
Rescales the value from the 'from' scale to the 'to' scale, rounding away from zero. In etxt, this is often used to rescale font metrics between different EM sizes (e.g. an advance of 512 on a font with EM of 1024 units corresponds to an advance of 384 with an EM size of 768, or 512.Rescale(1024, 768) = 384).
func (Unit) ToFloat32 ¶
The conversion is exact in the +/-16777216 Units range. Beyond that range, which corresponds to +/-2^18 (+/-262144) in the decimal numbering system), conversions become progressively less precise.
func (Unit) ToInt ¶
Defaults to Unit.ToIntHalfAway(0). For the fastest possible conversion to int, use Unit.ToIntFloor() instead.