mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-29 09:22:22 -05:00
Implement CurveLocation#getOffsetTo(location)
This commit is contained in:
parent
ee48e6cd03
commit
caac1c18e3
1 changed files with 16 additions and 1 deletions
|
@ -290,7 +290,7 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
return this._distance;
|
||||
},
|
||||
|
||||
// DOCS: divide(), split()
|
||||
// DOCS: divide(), split(), getOffsetTo(loc)
|
||||
|
||||
divide: function() {
|
||||
var curve = this.getCurve(),
|
||||
|
@ -313,6 +313,21 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
return res;
|
||||
},
|
||||
|
||||
getOffsetTo: function(loc) {
|
||||
var offset = null,
|
||||
path = this.getPath();
|
||||
if (path && path === loc.getPath()) {
|
||||
var offset1 = this.getOffset(),
|
||||
offset2 = loc.getOffset();
|
||||
offset = offset2 - offset1;
|
||||
if (offset < 0 && path._closed) {
|
||||
// Wrap around the end of the path back to the beginning.
|
||||
offset = path.getLength() - offset2 + offset1;
|
||||
}
|
||||
}
|
||||
return offset;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether tow CurveLocation objects are describing the same location
|
||||
* on a path, by applying the same tolerances as elsewhere when dealing with
|
||||
|
|
Loading…
Reference in a new issue