Documentation ¶
Index ¶
- Constants
- func Approx(a, b float64) bool
- func Approximately(a, b, precision float64) bool
- func Between(v, m1, m2 float64) bool
- func BoundingBox(curve CubicCurve) (topLeft Point, bottomRight Point)
- func BoundingBoxOverlaps(box1TopLeft, box1BottomRight, box2TopLeft, box2BottomRight Point) bool
- func Crt(v float64) float64
- func CurveOverlaps(c1, c2 CubicCurve) bool
- func Distance(p1 Point, p2 Point) float64
- func Float64ArrayContains(a []float64, x float64) bool
- func Float64ArrayDeDup(a []float64) []float64
- func Float64ArrayInsertIfAbsent(a []float64, x float64) []float64
- func IntersectsLine(curve CubicCurve, p1 Point, p2 Point) []float64
- func IntersectsProjectedLine(curve CubicCurve, p1 Point, p2 Point) []float64
- func IntersectsSelf(curve CubicCurve, curveIntersectionThreshold float64) (intersect bool, t1 float64, t2 float64)
- func IsClockwise(curve CubicCurve) bool
- func Roots(points []Point, lineP1 Point, lineP2 Point) []float64
- func SplitCurve(curve CubicCurve, t float64) (CubicCurve, CubicCurve)
- func StringArrayDeDup(a []string) []string
- type CubicCurve
- type Point
- func Align(points []Point, lineP1 Point, lineP2 Point) []Point
- func DeCasteljau(curve CubicCurve, t float64) Point
- func Derivative(curve CubicCurve, t float64) Point
- func FindPoint(curve CubicCurve, t float64) Point
- func NewPoint(x, y float64) Point
- func OffsetPoint(curve CubicCurve, t, d float64) Point
- func Project(curve CubicCurve, point Point) (pt Point, distance float64, t float64)
- type ValuePair
Constants ¶
const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1
Variables ¶
This section is empty.
Functions ¶
func Approximately ¶
func BoundingBox ¶
func BoundingBox(curve CubicCurve) (topLeft Point, bottomRight Point)
the smallest box that the curve fits into
func BoundingBoxOverlaps ¶
func CurveOverlaps ¶
func CurveOverlaps(c1, c2 CubicCurve) bool
checks the Bounding Boxes of the two curves and tests whether they overlap
func Float64ArrayContains ¶
func Float64ArrayDeDup ¶
removes any duplicates from the array order may or may not be maintained
func Float64ArrayInsertIfAbsent ¶
inserts the requested item if it does not already exist
func IntersectsLine ¶
func IntersectsLine(curve CubicCurve, p1 Point, p2 Point) []float64
Finds the intersections between this curve an some line {p1: {x:... ,y:...}, p2: ... }. The intersections are an array of t values on this curve. Curves are first aligned (translation/rotation) such that the curve's first coordinate is (0,0), and the curve is rotated so that the intersecting line coincides with the x-axis. Doing so turns "intersection finding" into plain "root finding". As a root finding solution, the roots are computed symbolically for both quadratic and cubic curves, using the standard square root function which you might remember from high school, and the absolutely not standard Cardano's algorithm for solving the cubic root function.
func IntersectsProjectedLine ¶
func IntersectsProjectedLine(curve CubicCurve, p1 Point, p2 Point) []float64
func IntersectsSelf ¶
func IntersectsSelf(curve CubicCurve, curveIntersectionThreshold float64) (intersect bool, t1 float64, t2 float64)
this function checks for self-intersection. Intersections are yielded as an array of float/float strings, where the two floats are separated by the character / and both floats corresponding to t values on the curve at which the intersection is found.
Note this will only return a single intersection. Afaik a cubic curve could not intersect itself more than once, so this is likely a non-issue. (Anyone know different? Math is hard.)
func SplitCurve ¶
func SplitCurve(curve CubicCurve, t float64) (CubicCurve, CubicCurve)
func StringArrayDeDup ¶
removes any duplicates maintaining ordering
Types ¶
type CubicCurve ¶
func Offset ¶
func Offset(curve CubicCurve, d float64) []CubicCurve
This function creates a new curve, offset along the curve normals, at distance d. Note that deep magic lies here and the offset curve of a Bezier curve cannot ever be another Bezier curve. As such, this function "cheats" and yields an array of curves which, taken together, form a single continuous curve equivalent to what a theoretical offset curve would be.
func Scale ¶
func Scale(curve CubicCurve, d float64) (CubicCurve, error)
func ScaleByFunc ¶
func ScaleByFunc(curve CubicCurve, distanceFn distanceFunc) (CubicCurve, error)
scales by the passed in distance function
func SplitCurveSection ¶
func SplitCurveSection(curve CubicCurve, tStart float64, tEnd float64) CubicCurve
splits the curve into a section
type Point ¶
func DeCasteljau ¶
func DeCasteljau(curve CubicCurve, t float64) Point
decasteljaus algorithm to find point on a curve. This will find the point t on the curve (where t >=0 && t <= 1) that is, t is the percentage along the line of the curve.
func Derivative ¶
func Derivative(curve CubicCurve, t float64) Point
Calculates the curve tangent at the specified t value. Note that this yields a not-normalized vector {x: dx, y: dy}
func FindPoint ¶
func FindPoint(curve CubicCurve, t float64) Point
finds the given t value on the curve. Where t is between 0 and 1
func OffsetPoint ¶
func OffsetPoint(curve CubicCurve, t, d float64) Point
the point on the curve at t=..., offset along its normal by a distance d.
func Project ¶
func Project(curve CubicCurve, point Point) (pt Point, distance float64, t float64)
Finds the on-curve point closest to the specific off-curve point, using a two-pass projection test based on the curve's LUT. A distance comparison finds the closest match, after which a fine interval around that match is checked to see if a better projection can be found.
type ValuePair ¶
func IntersectsCurve ¶
func IntersectsCurve(c1, c2 CubicCurve, curveIntersectionThreshold float64) []ValuePair
Finds the intersection points between the two curves. The resulting pairs are the T values on left (i.e c1) and right (c2)
Note curveIntersectionThreshold defaults to 0.5 in the javascript impl
func ValuePairDedup ¶
dedups the ValuePair array, based on the String() method (currently truncated to 5 digits)