mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Merge Path#_getOffset() with CurveLocation#getOffset()
This commit is contained in:
parent
e3f065277e
commit
c8cc653004
2 changed files with 9 additions and 19 deletions
|
@ -212,9 +212,15 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{
|
|||
getOffset: function() {
|
||||
var offset = this._offset;
|
||||
if (offset == null) {
|
||||
var path = this.getPath();
|
||||
offset = this._offset = path ? path._getOffset(this)
|
||||
: this.getCurveOffset();
|
||||
offset = 0;
|
||||
var path = this.getPath(),
|
||||
index = this.getIndex();
|
||||
if (path && index != null) {
|
||||
var curves = path.getCurves();
|
||||
for (var i = 0; i < index; i++)
|
||||
offset += curves[i].getLength();
|
||||
}
|
||||
this._offset = offset += this.getCurveOffset();
|
||||
}
|
||||
return offset;
|
||||
},
|
||||
|
|
|
@ -1680,22 +1680,6 @@ var Path = PathItem.extend(/** @lends Path# */{
|
|||
// See #getLocationOf(), #getNearestLocation(), #getNearestPoint()
|
||||
beans: false,
|
||||
|
||||
_getOffset: function(location) {
|
||||
var index = location && location.getIndex();
|
||||
if (index != null) {
|
||||
var curves = this.getCurves(),
|
||||
offset = 0;
|
||||
for (var i = 0; i < index; i++)
|
||||
offset += curves[i].getLength();
|
||||
var curve = curves[index],
|
||||
parameter = location.getParameter();
|
||||
if (parameter > 0)
|
||||
offset += curve.getPartLength(0, parameter);
|
||||
return offset;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* {@grouptitle Positions on Paths and Curves}
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue