Handle edge case in crossing number algorithm where the beam in right x-direction is touching a tip where the curves change y-direction but do not interesect with the shape, by checking for slope changes.

This commit is contained in:
Jürg Lehni 2011-07-05 01:15:45 +02:00
parent 24d77c1ece
commit 6cc7417201
2 changed files with 20 additions and 9 deletions
src/path

View file

@ -1164,14 +1164,19 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
contains: function(point) {
point = Point.read(arguments);
if (!this.getBounds().contains(point))
if (!this._closed || !this.getBounds().contains(point))
return false;
var curves = this.getCurves(),
prevCurve = this.getLastCurve(),
crossings = 0;
for (var i = 0, l = curves.length; i < l; i++)
crossings += curves[i].getCrossingsFor(point);
for (var i = 0, l = curves.length; i < l; i++) {
var curve = curves[i];
crossings += curve.getCrossingsFor(point,
prevCurve.getTangent(1).y);
prevCurve = curve;
}
return (crossings & 1) == 1;
},
}
// TODO: intersects(item)
// TODO: contains(item)