fract

package
v0.0.9-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2023 License: MIT Imports: 2 Imported by: 23

Documentation

Index

Constants

View Source
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

type Point struct {
	X Unit
	Y Unit
}

func UnitsToPoint

func UnitsToPoint(x, y Unit) Point

func (Point) AddPoint

func (self Point) AddPoint(pt Point) Point

func (Point) AddUnits

func (self Point) AddUnits(x, y Unit) Point

func (Point) ImagePoint

func (self Point) ImagePoint() image.Point

func (Point) In

func (self Point) In(rect Rect) bool

func (Point) String

func (self Point) String() string

func (Point) ToFloat32s

func (self Point) ToFloat32s() (x, y float32)

func (Point) ToFloat64s

func (self Point) ToFloat64s() (x, y float64)

func (Point) ToInts

func (self Point) ToInts() (int, int)

type Rect

type Rect struct {
	Min Point
	Max Point
}

func PointsToRect

func PointsToRect(min, max Point) Rect

func UnitsToRect

func UnitsToRect(minX, minY, maxX, maxY Unit) Rect

func (Rect) AddPoint

func (self Rect) AddPoint(pt Point) Rect

func (Rect) AddUnits

func (self Rect) AddUnits(x, y Unit) Rect

func (Rect) Contains

func (self Rect) Contains(pt Point) bool

func (Rect) Empty

func (self Rect) Empty() bool

func (Rect) Height

func (self Rect) Height() Unit

func (Rect) ImageRect

func (self Rect) ImageRect() image.Rectangle

func (Rect) IntHeight

func (self Rect) IntHeight() int

func (Rect) IntOrigin

func (self Rect) IntOrigin() (int, int)

func (Rect) IntWidth

func (self Rect) IntWidth() int

func (Rect) String

func (self Rect) String() string

func (Rect) ToFloat64s

func (self Rect) ToFloat64s() (minX, minY, maxX, maxY float64)

func (Rect) ToInts

func (self Rect) ToInts() (int, int, int, int)

func (Rect) Width

func (self Rect) Width() Unit

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

func FromFloat64(value float64) Unit

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

func FromFloat64Down(value float64) Unit

Converts a float64 to the closest Unit, rounding down in case of ties. Doesn't account for NaNs, infinites nor overflows.

func FromFloat64Up

func FromFloat64Up(value float64) Unit

Converts a float64 to the closest Unit, rounding up in case of ties. Doesn't account for NaNs, infinites nor overflows.

func FromInt

func FromInt(value int) Unit

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) Abs

func (self Unit) Abs() Unit

Returns the absolute value of the unit.

func (Unit) Away

func (self Unit) Away(reference int) Unit

func (Unit) Ceil

func (self Unit) Ceil() Unit

func (Unit) Div

func (self Unit) Div(divisor Unit) Unit

Divides the unit by the given divisor, rounding away from zero in case of ties.

func (Unit) Floor

func (self Unit) Floor() Unit

func (Unit) Fract

func (self Unit) Fract() Unit

Returns only the fractional part of the unit.

func (Unit) FractShift

func (self Unit) FractShift() Unit

Returns only the fractional part of the unit as a non-negative value relative to the unit's floor.

func (Unit) HalfAway

func (self Unit) HalfAway(reference int) Unit

func (Unit) HalfDown

func (self Unit) HalfDown() Unit

func (Unit) HalfToward

func (self Unit) HalfToward(reference int) Unit

func (Unit) HalfUp

func (self Unit) HalfUp() Unit

func (Unit) IsWhole

func (self Unit) IsWhole() bool

Returns whether the Unit is a whole number or if it has a fractional part.

func (Unit) Mul

func (self Unit) Mul(multiplier Unit) Unit

Multiplies the unit by the given value, rounding away from zero.

func (Unit) MulDown

func (self Unit) MulDown(multiplier Unit) Unit

Multiplies the unit by the given value, rounding down in case of ties.

func (Unit) MulInt

func (self Unit) MulInt(multiplier int) Unit

Multiplies the unit by the given int.

func (Unit) MulUp

func (self Unit) MulUp(multiplier Unit) Unit

Multiplies the unit by the given value, rounding up in case of ties.

func (Unit) QuantizeDown

func (self Unit) QuantizeDown(step Unit) Unit

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

func (self Unit) QuantizeUp(step Unit) Unit

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

func (self Unit) Rescale(from, to Unit) Unit

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

func (self Unit) ToFloat32() float32

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) ToFloat64

func (self Unit) ToFloat64() float64

The conversion is always exact.

func (Unit) ToInt

func (self Unit) ToInt() int

Defaults to Unit.ToIntHalfAway(0). For the fastest possible conversion to int, use Unit.ToIntFloor() instead.

func (Unit) ToIntAway

func (self Unit) ToIntAway(reference int) int

func (Unit) ToIntCeil

func (self Unit) ToIntCeil() int

func (Unit) ToIntFloor

func (self Unit) ToIntFloor() int

Fastest conversion from Unit to int.

func (Unit) ToIntHalfAway

func (self Unit) ToIntHalfAway(reference int) int

func (Unit) ToIntHalfDown

func (self Unit) ToIntHalfDown() int

func (Unit) ToIntHalfToward

func (self Unit) ToIntHalfToward(reference int) int

func (Unit) ToIntHalfUp

func (self Unit) ToIntHalfUp() int

func (Unit) ToIntToward

func (self Unit) ToIntToward(reference int) int

func (Unit) Toward

func (self Unit) Toward(reference int) Unit

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL