Implement CurveLocation#getOffsetTo(location)

This commit is contained in:
Jürg Lehni 2017-02-21 22:19:38 +01:00
parent ee48e6cd03
commit caac1c18e3

View file

@ -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