Remove Curve. _getEdgeSum() again, and inline code in Path.isClockwise()

This commit is contained in:
Jürg Lehni 2013-10-18 19:51:54 +02:00
parent 1fc9f882ca
commit b91c8f93f8
2 changed files with 12 additions and 20 deletions

View file

@ -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

View file

@ -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;
},