Define #getNearestLocation() / #getNearestPoint() for Path.

This commit is contained in:
Jürg Lehni 2011-07-06 22:25:20 +02:00
parent fadf6e98b5
commit d6b666024b

View file

@ -1162,6 +1162,24 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
return loc && loc.getNormal();
},
getNearestLocation: function(point) {
var curves = this.getCurves(),
minDist = Infinity,
minLoc = null;
for (var i = 0, l = curves.length; i < l; i++) {
var loc = curves[i].getNearestLocation(point);
if (loc._distance < minDist) {
minDist = loc._distance;
minLoc = loc;
}
}
return minLoc;
},
getNearestPoint: function(point) {
return this.getNearestLocation(point).getPoint();
},
contains: function(point) {
point = Point.read(arguments);
if (!this._closed || !this.getBounds().contains(point))