From 37dc9efea4f4b81982c6bf40de8528b3d9d0dc3a Mon Sep 17 00:00:00 2001 From: Hyung-Suk Kim Date: Fri, 5 Feb 2021 14:52:54 -0800 Subject: [PATCH 1/2] include t = 1 when searching for t value on cubic curve --- Lib/booleanOperations/flatten.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/booleanOperations/flatten.py b/Lib/booleanOperations/flatten.py index 8f1d7e1..9635dd2 100644 --- a/Lib/booleanOperations/flatten.py +++ b/Lib/booleanOperations/flatten.py @@ -961,9 +961,9 @@ def _tValueForPointOnCubicCurve(point, cubicCurve, isHorizontal=0): a, b, c, d = bezierTools.calcCubicParameters(pt1, pt2, pt3, pt4) solutions = bezierTools.solveCubic(a[isHorizontal], b[isHorizontal], c[isHorizontal], d[isHorizontal] - point[isHorizontal]) - solutions = [t for t in solutions if 0 <= t < 1] + solutions = [t for t in solutions if 0 <= t <= 1] if not solutions and not isHorizontal: - # can happen that a horizontal line doens intersect, try the vertical + # can happen that a horizontal line doesn't intersect, try the vertical return _tValueForPointOnCubicCurve(point, (pt1, pt2, pt3, pt4), isHorizontal=1) if len(solutions) > 1: intersectionLenghts = {} From 1e726c29355af54aa13140e6328874850ddb5b12 Mon Sep 17 00:00:00 2001 From: Hyung-Suk Kim Date: Fri, 5 Feb 2021 15:25:36 -0800 Subject: [PATCH 2/2] code/comment formatting --- Lib/booleanOperations/flatten.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/Lib/booleanOperations/flatten.py b/Lib/booleanOperations/flatten.py index 9635dd2..942bed6 100644 --- a/Lib/booleanOperations/flatten.py +++ b/Lib/booleanOperations/flatten.py @@ -953,18 +953,23 @@ class OutputPoint(InputPoint): def _tValueForPointOnCubicCurve(point, cubicCurve, isHorizontal=0): """ - Finds a t value on a curve from a point. - The points must be originaly be a point on the curve. - This will only back trace the t value, needed to split the curve in parts + Finds a t-value on a curve from a point. + The point must be originally be on the curve. + This will only backtrace the t value, needed to split the curve in parts """ pt1, pt2, pt3, pt4 = cubicCurve a, b, c, d = bezierTools.calcCubicParameters(pt1, pt2, pt3, pt4) - solutions = bezierTools.solveCubic(a[isHorizontal], b[isHorizontal], c[isHorizontal], - d[isHorizontal] - point[isHorizontal]) + solutions = bezierTools.solveCubic( + a[isHorizontal], + b[isHorizontal], + c[isHorizontal], + d[isHorizontal] - point[isHorizontal] + ) solutions = [t for t in solutions if 0 <= t <= 1] if not solutions and not isHorizontal: - # can happen that a horizontal line doesn't intersect, try the vertical - return _tValueForPointOnCubicCurve(point, (pt1, pt2, pt3, pt4), isHorizontal=1) + # If the horizontal line doesn't intersect, try the vertical + return _tValueForPointOnCubicCurve(point, (pt1, pt2, pt3, pt4), + isHorizontal=1) if len(solutions) > 1: intersectionLenghts = {} for t in solutions: