@@ -709,7 +709,11 @@ func approxCubeTo(quads *[]QuadSegment, splits int, maxDistSq float32, from, ctr
709
709
// and use the midpoint between the two curves Q1 and Q2 as control point:
710
710
//
711
711
// C = (3ctrl0 - pen + 3ctrl1 - to)/4
712
- c := ctrl0 .Mul (3 ).Sub (from ).Add (ctrl1 .Mul (3 )).Sub (to ).Mul (1.0 / 4.0 )
712
+ // using, q0 := 3ctrl0 - pen, q1 := 3ctrl1 - to
713
+ // C = (q0 + q1)/4
714
+ q0 := ctrl0 .Mul (3 ).Sub (from )
715
+ q1 := ctrl1 .Mul (3 ).Sub (to )
716
+ c := q0 .Add (q1 ).Mul (1.0 / 4.0 )
713
717
const maxSplits = 32
714
718
if splits >= maxSplits {
715
719
* quads = append (* quads , QuadSegment {From : from , Ctrl : c , To : to })
@@ -718,10 +722,12 @@ func approxCubeTo(quads *[]QuadSegment, splits int, maxDistSq float32, from, ctr
718
722
// The maximum distance between the cubic P and its approximation Q given t
719
723
// can be shown to be
720
724
//
721
- // d = sqrt(3)/36*|to - 3ctrl1 + 3ctrl0 - pen|
725
+ // d = sqrt(3)/36 * |to - 3ctrl1 + 3ctrl0 - pen|
726
+ // reusing, q0 := 3ctrl0 - pen, q1 := 3ctrl1 - to
727
+ // d = sqrt(3)/36 * |-q1 + q0|
722
728
//
723
729
// To save a square root, compare d² with the squared tolerance.
724
- v := to .Sub (ctrl1 . Mul ( 3 )). Add ( ctrl0 . Mul ( 3 )). Sub ( from )
730
+ v := q0 .Sub (q1 )
725
731
d2 := (v .X * v .X + v .Y * v .Y ) * 3 / (36 * 36 )
726
732
if d2 <= maxDistSq {
727
733
* quads = append (* quads , QuadSegment {From : from , Ctrl : c , To : to })
0 commit comments