d2

package
v0.0.0-...-9c88ebf Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: BSD-3-Clause Imports: 6 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Prec = 4

Prec is the precision for the String method on F

Functions

func MinMax

func MinMax(pts ...Pt) (Pt, Pt)

MinMax takes any number of points and returns a min point with the lowest X and the lowest Y in the entire set and a max point with the highest X and highest Y in the set.

Types

type AssertV1

type AssertV1 struct{}

AssertV1 checks that the derivative is close the derivative approximation. A good base check that an algorithm isn't completely wrong.

func (AssertV1) AssertEqual

func (AssertV1) AssertEqual(actual interface{}, t cmpr.Tolerance) error

AssertEqual fulfils geomtest.AssertEqualizer.

type Chain

type Chain []TGen

Chain combines multiple TGens into one

func (Chain) Pair

func (c Chain) Pair() [2]*T

Pair calls pair on all the TGen in the chain and computes both the transform and it's inverse.

func (Chain) T

func (c Chain) T() *T

T does a forward multiplication through the chain returning the transform

func (Chain) TInv

func (c Chain) TInv() *T

TInv does a reverse multiplication through the chain returning the inverse of the transform.

type D2

type D2 struct {
	X, Y float64
}

D2 is an abstract two dimensional struct holding the methods shared by both Pt and V.

func (D2) Angle

func (d D2) Angle() angle.Rad

Angle returns the angle in radians

func (D2) Mag

func (d D2) Mag() float64

Mag returns the magnitude (distance to origin) of the vector

func (D2) Mag2

func (d D2) Mag2() float64

Mag2 Returns the sqaure of the magnitude of the vector.

func (D2) Polar

func (d D2) Polar() Polar

Polar converts D2 to a Polar

func (D2) Pt

func (d D2) Pt() Pt

Pt converts D2 to a Pt

func (D2) V

func (d D2) V() V

V converts D2 to a V

type Limit

type Limit byte

Limit is used to indicate if a parametric method is bounded to [0,1] or unbounded

const (
	// LimitUndefined indicates that the requested parametric method is not
	// defined.
	LimitUndefined Limit = iota
	// LimitBounded indicates that the behavior of a parametric funnction
	// outside the range [0,1] is not defined.
	LimitBounded
	// LimitUnbounded indicates that passing parametric values outside the range
	// [0,1] should behave predictibly.
	LimitUnbounded
)

type Limiter

type Limiter interface {
	L(t, c int) Limit
}

Limiter can describe the behavior of it's parametric methods that return a Pt

type Point

type Point interface {
	Pt() Pt
}

Point can return a Pt

type Polar

type Polar struct {
	M float64
	A angle.Rad
}

Polar is an abstract D2 using polar coordinates. It can be useful for defining Pt or V values.

func (Polar) D2

func (p Polar) D2() D2

D2 representation of the Polar

func (Polar) Pt

func (p Polar) Pt() Pt

Pt representation of the Polar

func (Polar) V

func (p Polar) V() V

V representation of the Polar

type Pt

type Pt D2

Pt represets a two dimensional point.

func Max

func Max(pts ...Pt) Pt

Max returns a Pt with the highest X and highest Y.

func Min

func Min(pts ...Pt) Pt

Min returns a Pt with the lowest X and the lowest Y.

func (Pt) Add

func (pt Pt) Add(v V) Pt

Add a V to a Pt

func (Pt) Angle

func (pt Pt) Angle() angle.Rad

Angle returns the angle of the point relative to the origin

func (Pt) AssertEqual

func (pt Pt) AssertEqual(actual interface{}, t cmpr.Tolerance) error

AssertEqual fulfils geomtest.AssertEqualizer

func (Pt) Distance

func (pt Pt) Distance(pt2 Pt) float64

Distance returns the distance between to points

func (Pt) Mag

func (pt Pt) Mag() float64

Mag returns the magnitude of the point relative to the origin

func (Pt) Mag2

func (pt Pt) Mag2() float64

Mag2 returns the square of the magnitude. For comparisions this can be more efficient as it avoids a sqrt call.

func (Pt) Multiply

func (pt Pt) Multiply(scale float64) Pt

Multiply performs a scalar multiplication on the Pt

func (Pt) Polar

func (pt Pt) Polar() Polar

Polar converts Pt to Polar

func (Pt) Pt

func (pt Pt) Pt() Pt

Pt is defined on Pt to fulfill Point

func (Pt) String

func (pt Pt) String() string

String fulfills Stringer, returns the vector as "(X, Y)"

func (Pt) Subtract

func (pt Pt) Subtract(pt2 Pt) V

Subtract returns the difference between two points as V

func (Pt) V

func (pt Pt) V() V

V converts Pt to V

type Pt1

type Pt1 interface {
	Pt1(t0 float64) Pt
}

Pt1 takes one parametric value and returns a Pt

type Pt1V1

type Pt1V1 interface {
	Pt1
	V1
}

Pt1V1 has one argument parametric methods for both Pt1 and V1, typically this represents a curve and it's derivative.

type Pt1c0

type Pt1c0 interface {
	Pt1c0() Pt1
}

Pt1c0 returns a Pt1, it may cache some computation to optimize future calls to Pt1

type Pt2

type Pt2 interface {
	Pt2(t0, t1 float64) Pt
}

Pt2 takes two parametric values and returns a Pt

type Pt2c1

type Pt2c1 interface {
	Pt2c1(t0 float64) Pt1
}

Pt2c1 curries one of two parametric values returning a Pt1

func GetPt2c1

func GetPt2c1(of Pt2) Pt2c1

GetPt2c1 returns a Pt2c1 from any Pt2 prefering Pt2c1 on the interface if it is defined

type Pt2c1Wrapper

type Pt2c1Wrapper struct {
	Pt2
}

Pt2c1Wrapper wraps any Pt2 to convert it to a Pt2c1

func (Pt2c1Wrapper) Pt2c1

func (pt2c1 Pt2c1Wrapper) Pt2c1(t0 float64) Pt1

Pt2c1 curries the first argument using a T0Wrapper

type Rotate

type Rotate angle.Rad

Rotate generates a rotation transform

func (Rotate) Pair

func (r Rotate) Pair() [2]*T

Pair returns the rotation transform and it's inverse

func (Rotate) T

func (r Rotate) T() *T

T returns the rotation transform

func (Rotate) TInv

func (r Rotate) TInv() *T

TInv returns the inverse of the rotation transform

type Scale

type Scale V

Scale generates a scale transform

func (Scale) Pair

func (s Scale) Pair() [2]*T

Pair returns the Scale transform and it's inverse

func (Scale) T

func (s Scale) T() *T

T returns the scale transform

func (Scale) TInv

func (s Scale) TInv() *T

TInv returns the inverse of the scale transform

type T

type T [3][3]float64

T represets a transform matrix

func IndentityTransform

func IndentityTransform() *T

IndentityTransform returns an Identity matrix

func TProd

func TProd(ts ...*T) *T

TProd returns the product of multiple transforms.

func (*T) AssertEqual

func (t *T) AssertEqual(actual interface{}, tol cmpr.Tolerance) error

AssertEqual fulfils geomtest.AssertEqualizer

func (*T) Pt

func (t *T) Pt(pt Pt) Pt

Pt applies the transform to a Pt.

func (*T) PtF

func (t *T) PtF(pt Pt) (Pt, float64)

PtF applies the transform to a Pt, returning the resulting Pt and scale.

func (*T) Slice

func (t *T) Slice(pts []Pt) []Pt

Slice applies the transform to a slice of Pts

func (*T) String

func (t *T) String() string

func (*T) T

func (t *T) T(t2 *T) *T

T returns the product of t with t2

func (*T) V

func (t *T) V(v V) V

V applies the transform to a V

func (*T) VF

func (t *T) VF(v V) (V, float64)

VF applies the transform and returns a V and the scale

type T0Wrapper

type T0Wrapper struct {
	T0 float64
	Pt2
}

T0Wrapper curries the t0 parametric value to a Pt2

func (T0Wrapper) Pt1

func (t0w T0Wrapper) Pt1(t1 float64) Pt

Pt1 passes the curried t0 and the method argument t1 into the underlying Pt2

type TGen

type TGen interface {
	T() *T
	TInv() *T
	Pair() [2]*T
}

TGen is a Transform generator. If both the T and it's inverse are needed, Pair may reduce some duplicate calculations.

type TransformSet

type TransformSet struct {
	Head, Middle, Tail []*T
}

TransformSet builds up a chain of transformaitions.

func NewTSet

func NewTSet() *TransformSet

NewTSet creates a TransformSet.

func (*TransformSet) Add

func (ts *TransformSet) Add(t *T) *TransformSet

Add t to the middle

func (*TransformSet) AddBoth

func (ts *TransformSet) AddBoth(t TGen) *TransformSet

AddBoth appends the transform and it's inverse to the head and tail.

func (*TransformSet) GetT

func (ts *TransformSet) GetT() *T

Get produces a transform produces a transform by applying the transforms in head, then middle then applying tail in reverse.

type Translate

type Translate V

Translate generates a translation transform

func (Translate) Pair

func (t Translate) Pair() [2]*T

Pair returns the translation transform and it's inverse.

func (Translate) T

func (t Translate) T() *T

T returns the translation transform

func (Translate) TInv

func (t Translate) TInv() *T

TInv returns the inverse of the translation transform.

type V

type V D2

V represents a Vector, the difference between two points.

func (V) Abs

func (v V) Abs() V

Abs of vector for both X and Y

func (V) Add

func (v V) Add(v2 V) V

Add two vectors

func (V) Angle

func (v V) Angle() angle.Rad

Angle of the vector

func (V) AssertEqual

func (v V) AssertEqual(actual interface{}, t cmpr.Tolerance) error

AssertEqual fulfils geomtest.AssertEqualizer

func (V) Cross

func (v V) Cross(v2 V) float64

Cross returns the cross product of the two vectors

func (V) Dot

func (v V) Dot(v2 V) float64

Dot returns the dot product of two vectors

func (V) Mag

func (v V) Mag() float64

Mag returns the magnitude of the vector

func (V) Mag2

func (v V) Mag2() float64

Mag2 returns the square magnitude of the vector. This can be useful for comparisons to avoid the additional cost of a Sqrt call.

func (V) Multiply

func (v V) Multiply(scale float64) V

Multiply returns the scalar product of a vector.

func (V) Polar

func (v V) Polar() Polar

Polar converts V to Polar

func (V) Product

func (v V) Product(v2 V) V

Product of two vectors

func (V) Pt

func (v V) Pt() Pt

Pt converts a V to Pt

func (V) String

func (v V) String() string

String fulfills Stringer, returns the vector as "V(X, Y)"

func (V) Subtract

func (v V) Subtract(v2 V) V

Subtract two vectors

func (V) V

func (v V) V() V

V fulfills the Vector interface

type V1

type V1 interface {
	V1(t0 float64) V
}

V1 takes one parametric value and returns a V

func GetV1

func GetV1(of Pt1) V1

GetV1 takes any Pt1 and returns the optimal V1.

type V1Wrapper

type V1Wrapper struct {
	P     Pt1
	Small float64
}

V1Wrapper takes any Pt1 and approximates V1

func (V1Wrapper) Pt1

func (v1 V1Wrapper) Pt1(t0 float64) Pt

Pt1 calls underlying Pt1 to fulfill Pt1V1 interface

func (V1Wrapper) V1

func (v1 V1Wrapper) V1(t0 float64) V

V1 approximates V1 from two points close together

type V1c0

type V1c0 interface {
	V1c0() V1
}

V1c0 returns a V1, it may cache some computation to optimize future callse to V1

type VLimiter

type VLimiter interface {
	VL(t, c int) Limit
}

VLimiter can describe the behavior of it's parametric methods that return a V

type Vector

type Vector interface {
	V() V
}

Vector can return a V

Directories

Path Synopsis
curve
Package generate helps generate random data from the types in the d2 package.
Package generate helps generate random data from the types in the d2 package.
box

Jump to

Keyboard shortcuts

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