From 6e6fd0cba8fb71d4e80b880c92f448e24a05941d Mon Sep 17 00:00:00 2001 From: Holmes Futrell Date: Mon, 18 Mar 2019 16:44:43 -0700 Subject: [PATCH] fix a crash in the demos. --- BezierKit/Library/BezierCurve.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/BezierKit/Library/BezierCurve.swift b/BezierKit/Library/BezierCurve.swift index 0fe6a724..c399f878 100644 --- a/BezierKit/Library/BezierCurve.swift +++ b/BezierKit/Library/BezierCurve.swift @@ -461,12 +461,27 @@ extension BezierCurve { } alen = alen + slen } - + + func cleanupCurves(_ curves: inout [BezierCurve]) { + // ensures the curves are contiguous + for i in 0.. 0 { + curves[i].startingPoint = curves[i-1].endingPoint + } + if i < curves.count-1 { + curves[i].endingPoint = 0.5 * ( curves[i].endingPoint + curves[i+1].startingPoint ) + } + } + } + + cleanupCurves(&fcurves) + cleanupCurves(&bcurves) + // reverse the "return" outline bcurves = bcurves.map({(s: BezierCurve) in return s.reversed() }).reversed() - + // form the endcaps as lines let fs = fcurves[0].points[0] let fe = fcurves[len-1].points[fcurves[len-1].points.count-1]