heavyfishdesign: github.com/dustismo/heavyfishdesign/bezier Index | Files

package bezier

import "github.com/dustismo/heavyfishdesign/bezier"


Package Files

bezier.go utils.go


const MaxInt = int(^uint(0) >> 1)
const MinInt = -MaxInt - 1

func Approx Uses

func Approx(a, b float64) bool

approximately using precision = 0.000001

func Approximately Uses

func Approximately(a, b, precision float64) bool

func Between Uses

func Between(v, m1, m2 float64) bool

func BoundingBox Uses

func BoundingBox(curve CubicCurve) (topLeft Point, bottomRight Point)

the smallest box that the curve fits into

func BoundingBoxOverlaps Uses

func BoundingBoxOverlaps(box1TopLeft, box1BottomRight, box2TopLeft, box2BottomRight Point) bool

func Crt Uses

func Crt(v float64) float64

cube root function yielding real roots

func CurveOverlaps Uses

func CurveOverlaps(c1, c2 CubicCurve) bool

checks the Bounding Boxes of the two curves and tests whether they overlap

func Distance Uses

func Distance(p1 Point, p2 Point) float64

Distance finds the straightline distance between the two points

func Float64ArrayContains Uses

func Float64ArrayContains(a []float64, x float64) bool

func Float64ArrayDeDup Uses

func Float64ArrayDeDup(a []float64) []float64

removes any duplicates from the array order may or may not be maintained

func Float64ArrayInsertIfAbsent Uses

func Float64ArrayInsertIfAbsent(a []float64, x float64) []float64

inserts the requested item if it does not already exist

func IntersectsLine Uses

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 Uses

func IntersectsProjectedLine(curve CubicCurve, p1 Point, p2 Point) []float64

func IntersectsSelf Uses

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 IsClockwise Uses

func IsClockwise(curve CubicCurve) bool

returns true if this curve is clockwise

func Roots Uses

func Roots(points []Point, lineP1 Point, lineP2 Point) []float64

func SplitCurve Uses

func SplitCurve(curve CubicCurve, t float64) (CubicCurve, CubicCurve)

func StringArrayDeDup Uses

func StringArrayDeDup(a []string) []string

removes any duplicates maintaining ordering

type CubicCurve Uses

type CubicCurve struct {
    Start        Point
    StartControl Point
    End          Point
    EndControl   Point

func Offset Uses

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 Uses

func Scale(curve CubicCurve, d float64) (CubicCurve, error)

func ScaleByFunc Uses

func ScaleByFunc(curve CubicCurve, distanceFn distanceFunc) (CubicCurve, error)

scales by the passed in distance function

func SplitCurveSection Uses

func SplitCurveSection(curve CubicCurve, tStart float64, tEnd float64) CubicCurve

splits the curve into a section

type Point Uses

type Point struct {
    X   float64
    Y   float64

func Align Uses

func Align(points []Point, lineP1 Point, lineP2 Point) []Point

func DeCasteljau Uses

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 Uses

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 Uses

func FindPoint(curve CubicCurve, t float64) Point

finds the given t value on the curve. Where t is between 0 and 1

func NewPoint Uses

func NewPoint(x, y float64) Point

func OffsetPoint Uses

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 Uses

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.

func (Point) String Uses

func (p Point) String() string

type ValuePair Uses

type ValuePair struct {
    Left  float64
    Right float64

func IntersectsCurve Uses

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 Uses

func ValuePairDedup(a []ValuePair) []ValuePair

dedups the ValuePair array, based on the String() method (currently truncated to 5 digits)

func (ValuePair) String Uses

func (c ValuePair) String() string

Package bezier imports 3 packages (graph) and is imported by 1 packages. Updated 2020-04-15. Refresh now. Tools for package owners.