math

package
v1.5.54 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllOrientations = Orientations{
	Orientation{Right: East(), Down: North()},
	Orientation{Right: East(), Down: South()},
	Orientation{Right: North(), Down: East()},
	Orientation{Right: North(), Down: West()},
	Orientation{Right: South(), Down: East()},
	Orientation{Right: South(), Down: West()},
	Orientation{Right: West(), Down: North()},
	Orientation{Right: West(), Down: South()},
}

Functions

func Div

func Div(a, b int) int

func Div64 added in v1.2.321

func Div64(a, b int64) int64

func Mod

func Mod(a, b int) int

func Mod64 added in v1.2.321

func Mod64(a, b int64) int64

func Rint

func Rint(f float64) int

Types

type Delta

type Delta struct {
	DX, DY int
}

Delta represents a move between two pixel positions.

func East

func East() Delta

func North

func North() Delta

func South

func South() Delta

func West

func West() Delta

func (Delta) Add

func (d Delta) Add(d2 Delta) Delta

func (Delta) Div

func (d Delta) Div(m int) Delta

func (Delta) Dot

func (d Delta) Dot(d2 Delta) int

func (Delta) IsZero

func (d Delta) IsZero() bool

func (Delta) Length

func (d Delta) Length() float64

func (Delta) Length2

func (d Delta) Length2() int64

func (Delta) LengthFixed

func (d Delta) LengthFixed() Fixed

func (Delta) MarshalText added in v1.2.217

func (d Delta) MarshalText() ([]byte, error)

func (Delta) Mod added in v1.1.280

func (d Delta) Mod(m int) Delta

func (Delta) Mul

func (d Delta) Mul(n int) Delta

func (Delta) Mul2

func (d Delta) Mul2(mx, my int) Delta

func (Delta) MulFixed

func (d Delta) MulFixed(f Fixed) Delta

func (Delta) MulFracFixed

func (d Delta) MulFracFixed(num, denom Fixed) Delta

func (Delta) Norm0

func (d Delta) Norm0() int

func (Delta) Norm1

func (d Delta) Norm1() int

func (Delta) String added in v1.2.356

func (d Delta) String() string

func (Delta) Sub

func (d Delta) Sub(d2 Delta) Delta

func (*Delta) UnmarshalText added in v1.2.399

func (d *Delta) UnmarshalText(text []byte) error

func (Delta) WithLengthFixed

func (d Delta) WithLengthFixed(f Fixed) Delta

func (Delta) WithMaxLengthFixed

func (d Delta) WithMaxLengthFixed(f Fixed) Delta

type Fixed

type Fixed fixedUnderlying
const (
	FixedOne Fixed = 1 << fixedBits
)

func NewFixed

func NewFixed(i int) Fixed

func NewFixedFloat64

func NewFixedFloat64(f float64) Fixed

func NewFixedInt64

func NewFixedInt64(i fixedUnderlying) Fixed

func (Fixed) Div

func (f Fixed) Div(g Fixed) Fixed

func (Fixed) Float64

func (f Fixed) Float64() float64

func (Fixed) Mod added in v1.2.321

func (f Fixed) Mod(g Fixed) Fixed

func (Fixed) Mul

func (f Fixed) Mul(g Fixed) Fixed

func (Fixed) MulFrac

func (f Fixed) MulFrac(n, d Fixed) Fixed

func (Fixed) Rint

func (f Fixed) Rint() int

func (Fixed) Sqrt

func (f Fixed) Sqrt() Fixed

func (Fixed) String

func (f Fixed) String() string

type Orientation

type Orientation struct {
	Right Delta
	Down  Delta
}

Orientation represents a transformation matrix, written as a right and a down vector.

The zero value is not valid here.

func FlipD

func FlipD() Orientation

FlipD yields an orientation where X/Y are swapped.

func FlipX

func FlipX() Orientation

FlipX yields an orientation where X is flipped.

func FlipY

func FlipY() Orientation

FlipY yields an orientation where Y is flipped.

func Identity

func Identity() Orientation

Identity yields the default orientation.

func Left

func Left() Orientation

Left yields an orientation that turns left.

func ParseOrientation

func ParseOrientation(s string) (Orientation, error)

ParseOrientation parses an orientation from a string. It is given by the right and down directions in that order.

func Right() Orientation

Right yields an orientation that turns right.

func TurnAround

func TurnAround() Orientation

Left yields an orientation that turns left.

func (Orientation) Apply

func (o Orientation) Apply(d Delta) Delta

Apply rotates a delta by an orientation.

func (Orientation) ApplyToRect2

func (o Orientation) ApplyToRect2(pivot2 Pos, r Rect) Rect

ApplyToRect2 rotates a rectangle by the given orientation, mapping the pivot to itself. The pivot is given in doubled coordinates to support half-pixel pivots. Note: odd numbers are pixel centers, even numbers are pixel corners!

func (Orientation) Concat

func (o Orientation) Concat(o2 Orientation) Orientation

Concat returns the orientation o * o2 so that o.Concat(o2).Apply(d) == o.Apply(o2.Apply(d)).

func (Orientation) Determinant

func (o Orientation) Determinant() int

func (Orientation) Inverse

func (o Orientation) Inverse() Orientation

Inverse returns an orientation so that o.Concat(o.Invert()) == Identity().

func (Orientation) IsZero added in v1.4.160

func (o Orientation) IsZero() bool

IsZero returns whether o is the zero value. The zero value is not valid to use.

func (Orientation) MarshalText added in v1.2.399

func (o Orientation) MarshalText() ([]byte, error)

func (Orientation) String added in v1.2.356

func (o Orientation) String() string

func (*Orientation) UnmarshalText added in v1.2.399

func (o *Orientation) UnmarshalText(text []byte) error

type Orientations added in v1.2.356

type Orientations []Orientation

func ParseOrientations added in v1.2.4

func ParseOrientations(s string) (Orientations, error)

func (Orientations) MarshalText added in v1.2.399

func (o Orientations) MarshalText() ([]byte, error)

func (*Orientations) UnmarshalText added in v1.2.399

func (o *Orientations) UnmarshalText(text []byte) error

type Pos

type Pos struct {
	X, Y int
}

Pos represents a pixel position, where X points right and Y points down.

func (Pos) Add

func (p Pos) Add(d Delta) Pos

Add applies a delta to a position.

func (Pos) Delta

func (p Pos) Delta(p2 Pos) Delta

func (Pos) Div

func (p Pos) Div(m int) Pos

func (Pos) FromRectToRect

func (p Pos) FromRectToRect(a Rect, b Rect) Pos

func (Pos) MarshalText added in v1.2.399

func (p Pos) MarshalText() ([]byte, error)

func (Pos) Mul

func (p Pos) Mul(n int) Pos

func (Pos) String added in v1.2.356

func (p Pos) String() string

func (Pos) Sub

func (p Pos) Sub(d Delta) Pos

func (*Pos) UnmarshalJSON added in v1.2.399

func (p *Pos) UnmarshalJSON(text []byte) error

func (*Pos) UnmarshalText added in v1.2.399

func (p *Pos) UnmarshalText(text []byte) error

type Rect

type Rect struct {
	// Origin is the origin of the rectangle, typically the top left corner.
	Origin Pos
	// Size is the size of the rectangle, typically positive.
	Size Delta
}

Rect represents a rectangle.

func RectFromPoints

func RectFromPoints(a, b Pos) Rect

func (Rect) Add added in v1.0.140

func (r Rect) Add(d Delta) Rect

Add creates a new rectangle moved by the given delta.

func (Rect) Center

func (r Rect) Center() Pos

Center returns the coordinate in the middle of the rectangle.

func (Rect) Delta

func (r Rect) Delta(other Rect) Delta

Delta returns the vector between the closest points of two rectangles.

func (Rect) DeltaPos

func (r Rect) DeltaPos(other Pos) Delta

DeltaPos returns the vector between the closest points of a rectangle and a point.

func (Rect) Foot

func (r Rect) Foot() Pos

Foot returns the coordinate in the bottom middle of the rectangle.

func (Rect) GridPos added in v1.3.43

func (r Rect) GridPos(p Pos, nx int, ny int) (int, int)

GridPos converts coordinates of p within the rect into grid coords.

func (Rect) Grow added in v1.2.342

func (r Rect) Grow(d Delta) Rect

Grow creates a new rectangle grown by the given delta.

func (Rect) MarshalText added in v1.2.399

func (r Rect) MarshalText() ([]byte, error)

func (Rect) Normalized

func (r Rect) Normalized() Rect

Normalized returns a rectangle such that its size is nonnegative.

func (Rect) OppositeCorner

func (r Rect) OppositeCorner() Pos

OppositeCorner returns the coordinate of the opposite corner of the rectangle. Only correct on normalized rectangles.

func (Rect) String added in v1.2.356

func (r Rect) String() string

func (Rect) Union added in v1.4.33

func (r Rect) Union(other Rect) Rect

Union returns the smallest Rect containing both Rects.

func (*Rect) UnmarshalText added in v1.2.399

func (r *Rect) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

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