mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-08 05:42:07 -05:00
Clean-up CurveLocation code and switch from returning -1 to null for #getIndex().
This commit is contained in:
parent
c4ede92e81
commit
ead1600afe
2 changed files with 21 additions and 17 deletions
|
@ -53,12 +53,19 @@ CurveLocation = Base.extend({
|
||||||
return this._curve;
|
return this._curve;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The path on which the location is defined.
|
||||||
|
*/
|
||||||
|
getPath: function() {
|
||||||
|
return this._curve && this._curve.getPath();
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The index of the curve within the {@link Path#getCurves()} list, if the
|
* The index of the curve within the {@link Path#getCurves()} list, if the
|
||||||
* curve is part of a {@link Path} item.
|
* curve is part of a {@link Path} item.
|
||||||
*/
|
*/
|
||||||
getIndex: function() {
|
getIndex: function() {
|
||||||
return this._curve ? this._curve.getIndex() : -1;
|
return this._curve && this._curve.getIndex();
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -66,10 +73,8 @@ CurveLocation = Base.extend({
|
||||||
* by this object.
|
* by this object.
|
||||||
*/
|
*/
|
||||||
getLength: function() {
|
getLength: function() {
|
||||||
var path = this._curve.getPath();
|
var path = this._curve && this._curve.getPath();
|
||||||
if (path)
|
return path && path.getLength(this);
|
||||||
return path.getLength(this);
|
|
||||||
return path ? path.getLength(this) : null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +82,7 @@ CurveLocation = Base.extend({
|
||||||
* by this object.
|
* by this object.
|
||||||
*/
|
*/
|
||||||
getCurveLength: function() {
|
getCurveLength: function() {
|
||||||
if (this.curve != null) {
|
if (this.curve) {
|
||||||
var parameter = this.getParameter();
|
var parameter = this.getParameter();
|
||||||
return parameter != null
|
return parameter != null
|
||||||
? curve.getLength(0, parameter)
|
? curve.getLength(0, parameter)
|
||||||
|
@ -91,9 +96,9 @@ CurveLocation = Base.extend({
|
||||||
* the curve).
|
* the curve).
|
||||||
*/
|
*/
|
||||||
getParameter: function() {
|
getParameter: function() {
|
||||||
if (this._parameter == -1 && this._point != null)
|
if (this._parameter != null && this._point)
|
||||||
this._parameter = this._curve.getParameter(point);
|
this._parameter = this._curve.getParameter(point);
|
||||||
return this._parameter != -1 ? this._parameter : null;
|
return this._parameter;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,20 +115,19 @@ CurveLocation = Base.extend({
|
||||||
* The item this curve belongs to, if any.
|
* The item this curve belongs to, if any.
|
||||||
*/
|
*/
|
||||||
getItem: function() {
|
getItem: function() {
|
||||||
return this._curve != null ? this._curve.getPath() : null;
|
return this._curve && this._curve.getPath();
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
var string = '';
|
var parts = [];
|
||||||
if (this._point)
|
if (this._point)
|
||||||
string += ', point: ' + this.getPoint();
|
parts.push('point: ' + this.getPoint());
|
||||||
var index = this.getIndex();
|
var index = this.getIndex();
|
||||||
if (index >= 0)
|
if (index >= 0)
|
||||||
string += ', index: ' + index;
|
parts.push('index: ' + index);
|
||||||
var parameter = this.getParameter();
|
var parameter = this.getParameter();
|
||||||
if (parameter != -1)
|
if (parameter != -1)
|
||||||
string += ', parameter: ' + parameter;
|
parts.push('parameter: ' + parameter);
|
||||||
string[0] = '{';
|
return '{ ' + parts.join(', ') + ' }'
|
||||||
return string + ' }';
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -164,7 +164,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
join: function(path) {
|
join: function(path) {
|
||||||
if (path != null) {
|
if (path) {
|
||||||
var segments = path.segments,
|
var segments = path.segments,
|
||||||
last1 = this.getLastSegment(),
|
last1 = this.getLastSegment(),
|
||||||
last2 = path.getLastSegment();
|
last2 = path.getLastSegment();
|
||||||
|
@ -235,7 +235,7 @@ var Path = this.Path = PathItem.extend({
|
||||||
index = location
|
index = location
|
||||||
? location.getIndex()
|
? location.getIndex()
|
||||||
: curves.length;
|
: curves.length;
|
||||||
if (index != -1) {
|
if (index != null) {
|
||||||
var length = 0;
|
var length = 0;
|
||||||
for (var i = 0; i < index; i++)
|
for (var i = 0; i < index; i++)
|
||||||
length += curves[i].getLength();
|
length += curves[i].getLength();
|
||||||
|
|
Loading…
Reference in a new issue