Handle stationary points in #getWinding method.

This commit is contained in:
hkrish 2014-02-22 18:56:19 +01:00
parent b4d8315484
commit 49ddfafe4d
2 changed files with 13 additions and 6 deletions

View file

@ -251,7 +251,7 @@ PathItem.inject(new function() {
* Private method that returns the winding contribution of the given point * Private method that returns the winding contribution of the given point
* with respect to a given set of monotone curves. * with respect to a given set of monotone curves.
*/ */
function getWinding(point, curves, horizontal) { function getWinding(point, curves, horizontal, testContains) {
var TOLERANCE = /*#=*/ Numerical.TOLERANCE, var TOLERANCE = /*#=*/ Numerical.TOLERANCE,
x = point.x, x = point.x,
y = point.y, y = point.y,
@ -318,7 +318,10 @@ PathItem.inject(new function() {
if (abs(slope) < TOLERANCE && !Curve.isLinear(values) if (abs(slope) < TOLERANCE && !Curve.isLinear(values)
|| t < TOLERANCE && slope * Curve.evaluate( || t < TOLERANCE && slope * Curve.evaluate(
curve.previous.values, t, 1).y < 0) { curve.previous.values, t, 1).y < 0) {
// TODO: Handle stationary points here! if (testContains && x0 >= xBefore && x0 <= xAfter) {
++windLeft;
++windRight;
}
} else if (x0 <= xBefore) { } else if (x0 <= xBefore) {
windLeft += curve.winding; windLeft += curve.winding;
} else if (x0 >= xAfter) { } else if (x0 >= xAfter) {
@ -448,12 +451,16 @@ PathItem.inject(new function() {
* *
* @param {Point} point the location for which to determine the winding * @param {Point} point the location for which to determine the winding
* direction * direction
* @param {Boolean} horizontal wether we need to consider this point as * @param {Boolean} horizontal whether we need to consider this point as
* part of a horizontal curve * part of a horizontal curve
* @param {Boolean} testContains whether we need to consider this point
* as part of stationary points on the curve itself, used when checking
* the winding about a point.
* @return {Number} the winding number * @return {Number} the winding number
*/ */
_getWinding: function(point, horizontal) { _getWinding: function(point, horizontal, testContains) {
return getWinding(point, this._getMonoCurves(), horizontal); return getWinding(point, this._getMonoCurves(),
horizontal, testContains);
}, },
/** /**

View file

@ -296,7 +296,7 @@ var PathItem = Item.extend(/** @lends PathItem# */{
CanvasProvider.release(ctx); CanvasProvider.release(ctx);
return res; return res;
/*#*/ } else { // !__options.nativeContains && __options.booleanOperations /*#*/ } else { // !__options.nativeContains && __options.booleanOperations
var winding = this._getWinding(point); var winding = this._getWinding(point, false, true);
return !!(this.getWindingRule() === 'evenodd' ? winding & 1 : winding); return !!(this.getWindingRule() === 'evenodd' ? winding & 1 : winding);
/*#*/ } // !__options.nativeContains && __options.booleanOperations /*#*/ } // !__options.nativeContains && __options.booleanOperations
}, },