MCPcopy
hub / github.com/tdewolff/canvas / cubicBezierNormal

Function cubicBezierNormal

path_util.go:593–621  ·  view source on GitHub ↗

return the normal at the right-side of the curve (when increasing t)

(p0, p1, p2, p3 Point, t, d float64)

Source from the content-addressed store, hash-verified

591
592// return the normal at the right-side of the curve (when increasing t)
593func cubicBezierNormal(p0, p1, p2, p3 Point, t, d float64) Point {
594 // TODO: remove and use cubicBezierDeriv + Rot90CW?
595 if t == 0.0 {
596 n := p1.Sub(p0)
597 if n.X == 0 && n.Y == 0 {
598 n = p2.Sub(p0)
599 }
600 if n.X == 0 && n.Y == 0 {
601 n = p3.Sub(p0)
602 }
603 if n.X == 0 && n.Y == 0 {
604 return Point{}
605 }
606 return n.Rot90CW().Norm(d)
607 } else if t == 1.0 {
608 n := p3.Sub(p2)
609 if n.X == 0 && n.Y == 0 {
610 n = p3.Sub(p1)
611 }
612 if n.X == 0 && n.Y == 0 {
613 n = p3.Sub(p0)
614 }
615 if n.X == 0 && n.Y == 0 {
616 return Point{}
617 }
618 return n.Rot90CW().Norm(d)
619 }
620 panic("not implemented") // not needed
621}
622
623// cubicBezierLength calculates the length of the Bézier, taking care of inflection points. It uses Gauss-Legendre (n=5) and has an error of ~1% or less (empirical).
624func cubicBezierLength(p0, p1, p2, p3 Point) float64 {

Callers 4

addCubicBezierLineFunction · 0.85
strokeCubicBezierFunction · 0.85
TestCubicBezierNormalFunction · 0.85
offsetMethod · 0.85

Calls 3

SubMethod · 0.80
NormMethod · 0.80
Rot90CWMethod · 0.80

Tested by 1

TestCubicBezierNormalFunction · 0.68