Skip to content

Commit b91c8f9

Browse files
committed
Remove Curve. _getEdgeSum() again, and inline code in Path.isClockwise()
1 parent 1fc9f88 commit b91c8f9

2 files changed

Lines changed: 12 additions & 20 deletions

File tree

src/path/Curve.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -642,10 +642,6 @@ statics: {
642642
return new Rectangle(min[0], min[1], max[0] - min[0], max[1] - min[1]);
643643
},
644644

645-
isClockwise: function(v) {
646-
return Curve._getEdgeSum(v) > 0;
647-
},
648-
649645
/**
650646
* Private helper for both Curve.getBounds() and Path.getBounds(), which
651647
* finds the 0-crossings of the derivative of a bezier curve polynomial, to
@@ -806,19 +802,6 @@ statics: {
806802
}
807803
}
808804
return winding;
809-
},
810-
811-
_getEdgeSum: function(v) {
812-
// Method derived from:
813-
// http://stackoverflow.com/questions/1165647
814-
// We treat the curve points and handles as the outline of a polygon of
815-
// which we determine the orientation using the method of calculating
816-
// the sum over the edges. This will work even with non-convex polygons,
817-
// telling you whether it's mostly clockwise
818-
var sum = 0;
819-
for (var j = 2; j < 8; j += 2)
820-
sum += (v[j - 2] - v[j]) * (v[j + 1] + v[j - 1]);
821-
return sum;
822805
}
823806
}}, Base.each(['getBounds', 'getStrokeBounds', 'getHandleBounds', 'getRoughBounds'],
824807
// Note: Although Curve.getBounds() exists, we are using Path.getBounds() to

src/path/Path.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2417,10 +2417,19 @@ statics: {
24172417
*/
24182418
isClockwise: function(segments) {
24192419
var sum = 0;
2420+
// Method derived from:
2421+
// http://stackoverflow.com/questions/1165647
2422+
// We treat the curve points and handles as the outline of a polygon of
2423+
// which we determine the orientation using the method of calculating
2424+
// the sum over the edges. This will work even with non-convex polygons,
2425+
// telling you whether it's mostly clockwise
24202426
// TODO: Check if this works correctly for all open paths.
2421-
for (var i = 0, l = segments.length; i < l; i++)
2422-
sum += Curve._getEdgeSum(Curve.getValues(segments[i],
2423-
segments[i + 1 < l ? i + 1 : 0]));
2427+
for (var i = 0, l = segments.length; i < l; i++) {
2428+
var v = Curve.getValues(
2429+
segments[i], segments[i + 1 < l ? i + 1 : 0]);
2430+
for (var j = 2; j < 8; j += 2)
2431+
sum += (v[j - 2] - v[j]) * (v[j + 1] + v[j - 1]);
2432+
}
24242433
return sum > 0;
24252434
},
24262435

0 commit comments

Comments
 (0)