From b91c8f93f8fb76864d016452255343d2a5319833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Fri, 18 Oct 2013 19:51:54 +0200 Subject: [PATCH] Remove Curve. _getEdgeSum() again, and inline code in Path.isClockwise() --- src/path/Curve.js | 17 ----------------- src/path/Path.js | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 19291bc9..441f54d8 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -642,10 +642,6 @@ statics: { return new Rectangle(min[0], min[1], max[0] - min[0], max[1] - min[1]); }, - isClockwise: function(v) { - return Curve._getEdgeSum(v) > 0; - }, - /** * Private helper for both Curve.getBounds() and Path.getBounds(), which * finds the 0-crossings of the derivative of a bezier curve polynomial, to @@ -806,19 +802,6 @@ statics: { } } return winding; - }, - - _getEdgeSum: function(v) { - // Method derived from: - // http://stackoverflow.com/questions/1165647 - // We treat the curve points and handles as the outline of a polygon of - // which we determine the orientation using the method of calculating - // the sum over the edges. This will work even with non-convex polygons, - // telling you whether it's mostly clockwise - var sum = 0; - for (var j = 2; j < 8; j += 2) - sum += (v[j - 2] - v[j]) * (v[j + 1] + v[j - 1]); - return sum; } }}, Base.each(['getBounds', 'getStrokeBounds', 'getHandleBounds', 'getRoughBounds'], // Note: Although Curve.getBounds() exists, we are using Path.getBounds() to diff --git a/src/path/Path.js b/src/path/Path.js index 8dd7eb61..4c4f1052 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -2417,10 +2417,19 @@ statics: { */ isClockwise: function(segments) { var sum = 0; + // Method derived from: + // http://stackoverflow.com/questions/1165647 + // We treat the curve points and handles as the outline of a polygon of + // which we determine the orientation using the method of calculating + // the sum over the edges. This will work even with non-convex polygons, + // telling you whether it's mostly clockwise // TODO: Check if this works correctly for all open paths. - for (var i = 0, l = segments.length; i < l; i++) - sum += Curve._getEdgeSum(Curve.getValues(segments[i], - segments[i + 1 < l ? i + 1 : 0])); + for (var i = 0, l = segments.length; i < l; i++) { + var v = Curve.getValues( + segments[i], segments[i + 1 < l ? i + 1 : 0]); + for (var j = 2; j < 8; j += 2) + sum += (v[j - 2] - v[j]) * (v[j + 1] + v[j - 1]); + } return sum > 0; },