mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-07-29 23:29:06 -04:00
Define #getNearestLocation() / #getNearestPoint() for Path.
This commit is contained in:
parent
fadf6e98b5
commit
d6b666024b
1 changed files with 18 additions and 0 deletions
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue