Rename CurveLocation#getLength() and #getCurveLength() to #getOffset() and #getCurveOffset(), and seperate Path#getLength([location]) into #getLength() and #_getOffset().

This commit is contained in:
Jürg Lehni 2011-04-27 20:08:57 +01:00
parent b0a1f4b1a9
commit 016f4c15aa
2 changed files with 22 additions and 30 deletions

View file

@ -72,22 +72,18 @@ CurveLocation = Base.extend({
* The length of the path from its beginning up to the location described
* by this object.
*/
getLength: function() {
getOffset: function() {
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
* by this object.
*/
getCurveLength: function() {
if (this.curve) {
var parameter = this.getParameter();
return parameter != null
? curve.getLength(0, parameter)
: null;
}
getCurveOffset: function() {
var parameter = this._curve && this.getParameter();
return parameter != null ? this._curve.getLength(0, parameter) : null;
},
/**

View file

@ -233,30 +233,26 @@ var Path = this.Path = PathItem.extend({
}
return null;
},
getLength: function(/* location */) {
var location;
if (arguments.length)
location = arguments[0];
var curves = this.getCurves(),
index = location
? location.getIndex()
: curves.length;
getLength: function() {
var curves = this.getCurves();
var length = 0;
for (var i = 0, l = curves.length; i < l; i++)
length += curves[i].getLength();
return length;
},
_getOffset: function(location) {
var index = location && location.getIndex();
if (index != null) {
var length = 0;
var curves = this.getCurves(),
offset = 0;
for (var i = 0; i < index; i++)
length += curves[i].getLength();
var curve;
if (location) {
// 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;
offset += curves[i].getLength();
var curve = curves[index];
return offset + curve.getLength(0, location.getParameter());
}
return -1;
return null;
},
/**