From af355dc82c87b55cdf4c7ddec88dec7fc0ef5f4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 3 Sep 2015 09:01:07 +0200 Subject: [PATCH] Fix false positives in Curve#isLinear() and Segment#isLinear(). --- src/path/Curve.js | 8 +++++--- src/path/Segment.js | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index e873723a..90977dfe 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -666,9 +666,11 @@ statics: { // See Segment#isLinear(): var p1x = v[0], p1y = v[1], p2x = v[6], p2y = v[7], - l = new Point(p2x - p1x, p2y - p1y); - return l.isCollinear(new Point(v[2] - p1x, v[3] - p1y)) - && l.isCollinear(new Point(v[4] - p2x, v[5] - p2y)); + l = new Point(p2x - p1x, p2y - p1y), + h1 = new Point(v[2] - p1x, v[3] - p1y), + h2 = new Point(v[4] - p2x, v[5] - p2y); + return l.isZero() ? h1.isZero() && h2.isZero() + : l.isCollinear(h2) && l.isCollinear(h2); }, isFlatEnough: function(v, tolerance) { diff --git a/src/path/Segment.js b/src/path/Segment.js index 27af6723..21b16871 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -571,9 +571,11 @@ var Segment = Base.extend(/** @lends Segment# */{ // these methods that are implemented in both places. isLinear: function(seg1, seg2) { - var l = seg2._point.subtract(seg1._point); - return l.isCollinear(seg1._handleOut) - && l.isCollinear(seg2._handleIn); + var l = seg2._point.subtract(seg1._point), + h1 = seg1._handleOut, + h2 = seg2._handleIn; + return l.isZero() ? h1.isZero() && h2.isZero() + : l.isCollinear(h2) && l.isCollinear(h2); }, isCollinear: function(seg1, seg2, seg3, seg4) {