mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-19 06:00:56 -05:00
Implement Curve#getOffsetOf(point) / Path#getOffsetOf(point)
Closes #463.
This commit is contained in:
parent
da22161d28
commit
4d4a39c752
3 changed files with 25 additions and 2 deletions
|
@ -856,6 +856,17 @@ statics: {
|
|||
return t != null ? new CurveLocation(this, t) : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the length of the path from its beginning up to up to the
|
||||
* specified point if it lies on the path, {@code null} otherwise.
|
||||
* @param {Point} point the point on the path.
|
||||
* @return {Number} the length of the path up to the specified point.
|
||||
*/
|
||||
getOffsetOf: function(/* point */) {
|
||||
var loc = this.getLocationOf.apply(this, arguments);
|
||||
return loc ? loc.getOffset() : null;
|
||||
},
|
||||
|
||||
getNearestLocation: function(/* point */) {
|
||||
var point = Point.read(arguments),
|
||||
values = this.getValues(),
|
||||
|
|
|
@ -152,14 +152,15 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
|
||||
/**
|
||||
* The length of the path from its beginning up to the location described
|
||||
* by this object.
|
||||
* by this object. If the curve is not part of a path, then the length
|
||||
* within the curve is returned instead.
|
||||
*
|
||||
* @type Number
|
||||
* @bean
|
||||
*/
|
||||
getOffset: function() {
|
||||
var path = this.getPath();
|
||||
return path && path._getOffset(this);
|
||||
return path ? path._getOffset(this) : this.getCurveOffset();
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -1637,6 +1637,17 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the length of the path from its beginning up to up to the
|
||||
* specified point if it lies on the path, {@code null} otherwise.
|
||||
* @param {Point} point the point on the path.
|
||||
* @return {Number} the length of the path up to the specified point.
|
||||
*/
|
||||
getOffsetOf: function(/* point */) {
|
||||
var loc = this.getLocationOf.apply(this, arguments);
|
||||
return loc ? loc.getOffset() : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the curve location of the specified offset on the path.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue