Documentation ¶
Index ¶
- Constants
- func BinomialCoefficient(n, k int64) int64
- func IsFlatEnough(controlPoints []vector.Vector2f) bool
- type Bezier
- type BezierApproximator
- type CType
- type Catmull
- type CirArc
- type Curve
- type CurveDef
- type ItemStack
- type Linear
- type MonotoneCubic
- type MultiCurve
- func (mCurve *MultiCurve) GetEndAngle() float32
- func (mCurve *MultiCurve) GetEndAngleAt(t float32) float32
- func (mCurve *MultiCurve) GetLength() float32
- func (mCurve *MultiCurve) GetLines() []Linear
- func (mCurve *MultiCurve) GetStartAngle() float32
- func (mCurve *MultiCurve) GetStartAngleAt(t float32) float32
- func (mCurve *MultiCurve) PointAt(t float32) vector.Vector2f
- type Spline
- func (spline *Spline) GetCurves() []Curve
- func (spline *Spline) GetEndAngle() float32
- func (spline *Spline) GetEndAngleAt(t float32) float32
- func (spline *Spline) GetLength() float32
- func (spline *Spline) GetStartAngle() float32
- func (spline *Spline) GetStartAngleAt(t float32) float32
- func (spline *Spline) PointAt(t float32) vector.Vector2f
Constants ¶
const ( CLine = CType(iota) CBezier CCirArc CCatmull )
const BEZIER_QUANTIZATION = 0.5
const BEZIER_QUANTIZATIONSQ = BEZIER_QUANTIZATION * BEZIER_QUANTIZATION
Variables ¶
This section is empty.
Functions ¶
func BinomialCoefficient ¶
https://en.wikipedia.org/wiki/Binomial_coefficient#Multiplicative_formula
func IsFlatEnough ¶
/ <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 NewBezierNA ¶
Creates a bezier curve with non-approximated length. To calculate that length, call (*Bezier).CalculateLength()
func SolveBSpline ¶
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 (*Bezier) GetStartAngle ¶
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 Catmull ¶
type Catmull struct { ApproxLength float32 // contains filtered or unexported fields }
func NewCatmull ¶
func (Catmull) GetEndAngle ¶
func (Catmull) GetStartAngle ¶
type CirArc ¶
type CirArc struct { Unstable bool // contains filtered or unexported fields }
func (*CirArc) GetEndAngle ¶
func (*CirArc) GetStartAngle ¶
type ItemStack ¶
type ItemStack struct {
// contains filtered or unexported fields
}
ItemStack the stack of Items
type Linear ¶
func ApproximateBezier ¶
func ApproximateCatmullRom ¶
func ApproximateCircularArc ¶
func (Linear) GetEndAngle ¶
func (Linear) GetStartAngle ¶
type MonotoneCubic ¶
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
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
type Spline ¶
type Spline struct {
// contains filtered or unexported fields
}
func NewBSpline ¶
NewBSpline creates a spline that goes through all given control points. points[1] and points[len(points)-2] are terminal tangents.
func NewBSplineW ¶
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 NewSplineW ¶
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.