curves

package
v0.0.0-...-0518d83 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CLine = CType(iota)
	CBezier
	CCirArc
	CCatmull
)
View Source
const BEZIER_QUANTIZATION = 0.5
View Source
const BEZIER_QUANTIZATIONSQ = BEZIER_QUANTIZATION * BEZIER_QUANTIZATION

Variables

This section is empty.

Functions

func IsFlatEnough

func IsFlatEnough(controlPoints []vector.Vector2f) bool

/ <summary> / Make sure the 2nd order derivative (approximated using finite elements) is within tolerable bounds. / NOTE: The 2nd order derivative of a 2d curve represents its curvature, so intuitively this function / checks (as the name suggests) whether our approximation is _locally_ "flat". More curvy parts / need to have a denser approximation to be more "flat". / </summary> / <param name="controlPoints">The control points to check for flatness.</param> / <returns>Whether the control points are flat enough.</returns>

Types

type Bezier

type Bezier struct {
	Points []vector.Vector2f

	ApproxLength float32
	// contains filtered or unexported fields
}

func NewBezier

func NewBezier(points []vector.Vector2f) *Bezier

Creates a bezier curve with approximated length

func NewBezierNA

func NewBezierNA(points []vector.Vector2f) *Bezier

Creates a bezier curve with non-approximated length. To calculate that length, call (*Bezier).CalculateLength()

func SolveBSpline

func SolveBSpline(points1 []vector.Vector2f) []*Bezier

SolveBSpline calculates the spline that goes through all given control points. points[1] and points[len(points)-2] are terminal tangents Returns an array of bezier curves in NA (non-approximated) version for performance considerations.

func (*Bezier) CalculateLength

func (bz *Bezier) CalculateLength()

Calculates the approximate length of the curve to 2 decimal points of accuracy in most cases

func (*Bezier) GetEndAngle

func (bz *Bezier) GetEndAngle() float32

func (*Bezier) GetLength

func (bz *Bezier) GetLength() float32

func (*Bezier) GetStartAngle

func (bz *Bezier) GetStartAngle() float32

type BezierApproximator

type BezierApproximator struct {
	// contains filtered or unexported fields
}

func NewBezierApproximator

func NewBezierApproximator(controlPoints []vector.Vector2f) *BezierApproximator

func (*BezierApproximator) Approximate

func (approximator *BezierApproximator) Approximate(controlPoints []vector.Vector2f, output *[]vector.Vector2f)

/ <summary> / This uses <a href="https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm">De Casteljau's algorithm</a> to obtain an optimal / piecewise-linear approximation of the bezier curve with the same amount of points as there are control points. / </summary> / <param name="controlPoints">The control points describing the bezier curve to be approximated.</param> / <param name="output">The points representing the resulting piecewise-linear approximation.</param>

func (*BezierApproximator) CreateBezier

func (approximator *BezierApproximator) CreateBezier() []vector.Vector2f

/ <summary> / Creates a piecewise-linear approximation of a bezier curve, by adaptively repeatedly subdividing / the control points until their approximation error vanishes below a given threshold. / </summary> / <param name="controlPoints">The control points describing the curve.</param> / <returns>A list of vectors representing the piecewise-linear approximation.</returns>

func (*BezierApproximator) Subdivide

func (approximator *BezierApproximator) Subdivide(controlPoints, l, r []vector.Vector2f)

/ <summary> / Subdivides n control points representing a bezier curve into 2 sets of n control points, each / describing a bezier curve equivalent to a half of the original curve. Effectively this splits / the original curve into 2 curves which result in the original curve when pieced back together. / </summary> / <param name="controlPoints">The control points to split.</param> / <param name="l">Output: The control points corresponding to the left half of the curve.</param> / <param name="r">Output: The control points corresponding to the right half of the curve.</param>

type CType

type CType int

type Catmull

type Catmull struct {
	ApproxLength float32
	// contains filtered or unexported fields
}

func NewCatmull

func NewCatmull(points []vector.Vector2f) Catmull

func (Catmull) GetEndAngle

func (cm Catmull) GetEndAngle() float32

func (Catmull) GetLength

func (cm Catmull) GetLength() float32

func (Catmull) GetStartAngle

func (cm Catmull) GetStartAngle() float32

func (Catmull) PointAt

func (cm Catmull) PointAt(t float32) vector.Vector2f

type CirArc

type CirArc struct {
	Unstable bool
	// contains filtered or unexported fields
}

func NewCirArc

func NewCirArc(a, b, c vector.Vector2f) *CirArc

func (*CirArc) GetEndAngle

func (arc *CirArc) GetEndAngle() float32

func (*CirArc) GetLength

func (arc *CirArc) GetLength() float32

func (*CirArc) GetStartAngle

func (arc *CirArc) GetStartAngle() float32

func (*CirArc) PointAt

func (arc *CirArc) PointAt(t float32) vector.Vector2f

type Curve

type Curve interface {
	PointAt(t float32) vector.Vector2f
	GetStartAngle() float32
	GetEndAngle() float32
	GetLength() float32
}

type CurveDef

type CurveDef struct {
	CurveType CType
	Points    []vector.Vector2f
}

type ItemStack

type ItemStack struct {
	// contains filtered or unexported fields
}

ItemStack the stack of Items

func NewStack

func NewStack() *ItemStack

New creates a new ItemStack

func (*ItemStack) Count

func (s *ItemStack) Count() int

func (*ItemStack) Pop

func (s *ItemStack) Pop() []vector.Vector2f

Pop removes an Item from the top of the stack

func (*ItemStack) Push

func (s *ItemStack) Push(t []vector.Vector2f)

Push adds an Item to the top of the stack

type Linear

type Linear struct {
	Point1, Point2 vector.Vector2f
}

func ApproximateBezier

func ApproximateBezier(points []vector.Vector2f) []Linear

func ApproximateCatmullRom

func ApproximateCatmullRom(points []vector.Vector2f, detail int) []Linear

func ApproximateCircularArc

func ApproximateCircularArc(pt1, pt2, pt3 vector.Vector2f, detail float32) []Linear

func NewLinear

func NewLinear(pt1, pt2 vector.Vector2f) Linear

func (Linear) GetEndAngle

func (ln Linear) GetEndAngle() float32

func (Linear) GetLength

func (ln Linear) GetLength() float32

func (Linear) GetStartAngle

func (ln Linear) GetStartAngle() float32

func (Linear) PointAt

func (ln Linear) PointAt(t float32) vector.Vector2f

type MonotoneCubic

type MonotoneCubic struct {
	Points []vector.Vector2f
	// contains filtered or unexported fields
}

func NewMonotoneCubic

func NewMonotoneCubic(points []vector.Vector2f) *MonotoneCubic

func (*MonotoneCubic) GetEndAngle

func (bz *MonotoneCubic) GetEndAngle() float32

func (*MonotoneCubic) GetLength

func (bz *MonotoneCubic) GetLength() float32

func (*MonotoneCubic) GetStartAngle

func (bz *MonotoneCubic) GetStartAngle() float32

func (*MonotoneCubic) PointAt

func (bz *MonotoneCubic) PointAt(t float32) vector.Vector2f

type MultiCurve

type MultiCurve struct {
	// contains filtered or unexported fields
}

func NewMultiCurve

func NewMultiCurve(curveDefs []CurveDef) *MultiCurve

func NewMultiCurveT

func NewMultiCurveT(curveDefs []CurveDef, desiredLength float64) *MultiCurve

func (*MultiCurve) GetEndAngle

func (mCurve *MultiCurve) GetEndAngle() float32

func (*MultiCurve) GetEndAngleAt

func (mCurve *MultiCurve) GetEndAngleAt(t float32) float32

func (*MultiCurve) GetLength

func (mCurve *MultiCurve) GetLength() float32

func (*MultiCurve) GetLines

func (mCurve *MultiCurve) GetLines() []Linear

func (*MultiCurve) GetStartAngle

func (mCurve *MultiCurve) GetStartAngle() float32

func (*MultiCurve) GetStartAngleAt

func (mCurve *MultiCurve) GetStartAngleAt(t float32) float32

func (*MultiCurve) PointAt

func (mCurve *MultiCurve) PointAt(t float32) vector.Vector2f

type Spline

type Spline struct {
	// contains filtered or unexported fields
}

func NewBSpline

func NewBSpline(points []vector.Vector2f) *Spline

NewBSpline creates a spline that goes through all given control points. points[1] and points[len(points)-2] are terminal tangents.

func NewBSplineW

func NewBSplineW(points []vector.Vector2f, weights []float32) *Spline

NewBSplineW creates a spline that goes through all given control points with forced weights(lengths), useful when control points have to be passed at certain times. points[1] and points[len(points)-2] are terminal tangents.

func NewSpline

func NewSpline(curves []Curve) *Spline

NewSpline creates a spline with weights determined by sub-curves lengths

func NewSplineW

func NewSplineW(curves []Curve, weights []float32) *Spline

NewSplineW creates a spline with forced weights(lengths), useful when sub-curves have to be finished at certain times. Length of weights has to be the same as curves, otherwise function will panic.

func (*Spline) GetCurves

func (spline *Spline) GetCurves() []Curve

func (*Spline) GetEndAngle

func (spline *Spline) GetEndAngle() float32

func (*Spline) GetEndAngleAt

func (spline *Spline) GetEndAngleAt(t float32) float32

func (*Spline) GetLength

func (spline *Spline) GetLength() float32

func (*Spline) GetStartAngle

func (spline *Spline) GetStartAngle() float32

func (*Spline) GetStartAngleAt

func (spline *Spline) GetStartAngleAt(t float32) float32

func (*Spline) PointAt

func (spline *Spline) PointAt(t float32) vector.Vector2f

Jump to

Keyboard shortcuts

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