mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-07 13:22:07 -05:00
Rename CurveLocation#getLength() and #getCurveLength() to #getOffset() and #getCurveOffset(), and seperate Path#getLength([location]) into #getLength() and #_getOffset().
This commit is contained in:
parent
b0a1f4b1a9
commit
016f4c15aa
2 changed files with 22 additions and 30 deletions
|
@ -72,22 +72,18 @@ CurveLocation = Base.extend({
|
||||||
* The length of the path from its beginning up to the location described
|
* The length of the path from its beginning up to the location described
|
||||||
* by this object.
|
* by this object.
|
||||||
*/
|
*/
|
||||||
getLength: function() {
|
getOffset: function() {
|
||||||
var path = this._curve && this._curve.getPath();
|
var path = this._curve && this._curve.getPath();
|
||||||
return path && path.getLength(this);
|
return path && path._getOffset(this);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The length of the curve from its beginning up to the location described
|
* The length of the curve from its beginning up to the location described
|
||||||
* by this object.
|
* by this object.
|
||||||
*/
|
*/
|
||||||
getCurveLength: function() {
|
getCurveOffset: function() {
|
||||||
if (this.curve) {
|
var parameter = this._curve && this.getParameter();
|
||||||
var parameter = this.getParameter();
|
return parameter != null ? this._curve.getLength(0, parameter) : null;
|
||||||
return parameter != null
|
|
||||||
? curve.getLength(0, parameter)
|
|
||||||
: null;
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -233,30 +233,26 @@ var Path = this.Path = PathItem.extend({
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
getLength: function(/* location */) {
|
getLength: function() {
|
||||||
var location;
|
var curves = this.getCurves();
|
||||||
if (arguments.length)
|
var length = 0;
|
||||||
location = arguments[0];
|
for (var i = 0, l = curves.length; i < l; i++)
|
||||||
var curves = this.getCurves(),
|
length += curves[i].getLength();
|
||||||
index = location
|
return length;
|
||||||
? location.getIndex()
|
},
|
||||||
: curves.length;
|
|
||||||
|
_getOffset: function(location) {
|
||||||
|
var index = location && location.getIndex();
|
||||||
if (index != null) {
|
if (index != null) {
|
||||||
var length = 0;
|
var curves = this.getCurves(),
|
||||||
|
offset = 0;
|
||||||
for (var i = 0; i < index; i++)
|
for (var i = 0; i < index; i++)
|
||||||
length += curves[i].getLength();
|
offset += curves[i].getLength();
|
||||||
var curve;
|
var curve = curves[index];
|
||||||
if (location) {
|
return offset + curve.getLength(0, location.getParameter());
|
||||||
// Clone the curve as we're going to divide it to get the
|
|
||||||
// length. Without cloning it, this would modify the path.
|
|
||||||
curve = curves[index].clone();
|
|
||||||
curve.divide(location.getParameter());
|
|
||||||
length += curve.getLength();
|
|
||||||
}
|
|
||||||
return length;
|
|
||||||
}
|
}
|
||||||
return -1;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue