2011-03-04 08:34:31 -05:00
|
|
|
var Segment = this.Segment = Base.extend({
|
2011-03-06 05:57:14 -05:00
|
|
|
beans: true,
|
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
initialize: function() {
|
2011-02-13 11:26:24 -05:00
|
|
|
if (arguments.length == 0) {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._point = new Point();
|
2011-02-13 11:26:24 -05:00
|
|
|
} else if (arguments.length == 1) {
|
2011-03-06 05:57:14 -05:00
|
|
|
// TODO: If beans are not activated, this won't copy from
|
|
|
|
// an existing segment. OK?
|
|
|
|
var arg = arguments[0];
|
|
|
|
if (arg.point) {
|
|
|
|
this._point = new Point(arg.point);
|
|
|
|
this._handleIn = new Point(arg.handleIn);
|
|
|
|
this._handleOut = new Point(arg.handleOut);
|
2011-02-07 13:28:09 -05:00
|
|
|
} else {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._point = new Point(arguments[0]);
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
2011-02-13 11:26:24 -05:00
|
|
|
} else if (arguments.length < 6) {
|
|
|
|
if (arguments.length == 2 && !arguments[1].x) {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._point = new Point(arguments[0], arguments[1]);
|
2011-02-07 13:28:09 -05:00
|
|
|
} else {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._point = new Point(arguments[0]);
|
|
|
|
// Doesn't matter if these arguments exist, it creates 0, 0
|
|
|
|
// points otherwise
|
|
|
|
this._handleIn = new Point(arguments[1]);
|
|
|
|
this._handleOut = new Point(arguments[2]);
|
2011-02-07 13:28:09 -05:00
|
|
|
}
|
2011-02-13 11:26:24 -05:00
|
|
|
} else if (arguments.length == 6) {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._point = new Point(arguments[0], arguments[1]);
|
|
|
|
this._handleIn = new Point(arguments[2], arguments[3]);
|
|
|
|
this._handleOut = new Point(arguments[4], arguments[5]);
|
2011-02-13 10:09:24 -05:00
|
|
|
}
|
2011-03-06 05:57:14 -05:00
|
|
|
if (!this._handleIn)
|
|
|
|
this._handleIn = new Point();
|
|
|
|
if (!this._handleOut)
|
|
|
|
this._handleOut = new Point();
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
getPoint: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
return this._point;
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
setPoint: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._point = Point.read(arguments);
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
getHandleIn: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
return this._handleIn;
|
|
|
|
},
|
|
|
|
|
|
|
|
getHandleInIfSet: function() {
|
|
|
|
return this._handleIn.x == this._handleIn.y == 0
|
|
|
|
? null : this._handleIn;
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
setHandleIn: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._handleIn = Point.read(arguments);
|
|
|
|
// Update corner accordingly
|
|
|
|
// this.corner = !this._handleIn.isParallel(this._handleOut);
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
getHandleOut: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
return this._handleOut;
|
|
|
|
},
|
|
|
|
|
|
|
|
getHandleOutIfSet: function() {
|
|
|
|
return this._handleOut.x == this._handleOut.y == 0
|
|
|
|
? null : this._handleOut;
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
setHandleOut: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
this._handleOut = Point.read(arguments);
|
|
|
|
// Update corner accordingly
|
|
|
|
// this.corner = !this._handleIn.isParallel(this._handleOut);
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
getIndex: function() {
|
2011-02-13 10:09:24 -05:00
|
|
|
// TODO: Cache and update indices instead of searching?
|
2011-03-04 16:34:31 -05:00
|
|
|
return this.path ? this.path._segments.indexOf(this) : -1;
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-14 05:35:40 -05:00
|
|
|
// TODO:
|
2011-02-07 13:28:09 -05:00
|
|
|
// getCurve: function() {
|
2011-02-13 11:26:24 -05:00
|
|
|
// if (this._segments && this._segments.path) {
|
2011-02-13 08:52:51 -05:00
|
|
|
// var curves = this._segments.path.getCurves();
|
2011-02-07 13:28:09 -05:00
|
|
|
// // The curves list handles closing curves, so the curves.size
|
|
|
|
// // is adjusted accordingly. just check to be in the boundaries here:
|
|
|
|
// return index < curves.length ? curves[index] : null;
|
|
|
|
// }
|
|
|
|
// },
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
getNext: function() {
|
2011-03-04 16:34:31 -05:00
|
|
|
return this.path && this.path._segments[this.getIndex() + 1] || null;
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
getPrevious: function() {
|
2011-03-04 16:34:31 -05:00
|
|
|
return this.path && this.path._segments[this.getIndex() - 1] || null;
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-14 05:35:40 -05:00
|
|
|
// TODO:
|
2011-02-07 13:28:09 -05:00
|
|
|
// isSelected: function() {
|
2011-03-03 17:45:17 -05:00
|
|
|
//
|
2011-02-07 13:28:09 -05:00
|
|
|
// }
|
|
|
|
//
|
|
|
|
// setSelected: function(pt, selected)
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
reverse: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
return new Segment(this._point, this._handleOut, this._handleIn);
|
2011-02-07 13:28:09 -05:00
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
clone: function() {
|
|
|
|
return new Segment(this);
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
remove: function() {
|
2011-02-13 11:26:24 -05:00
|
|
|
if (this.path && this.path._segments)
|
2011-03-04 16:34:31 -05:00
|
|
|
return !!this.path._segments.splice(this.getIndex(), 1).length;
|
2011-02-07 13:28:09 -05:00
|
|
|
return false;
|
|
|
|
},
|
2011-03-03 17:45:17 -05:00
|
|
|
|
2011-02-07 13:28:09 -05:00
|
|
|
toString: function() {
|
2011-03-06 05:57:14 -05:00
|
|
|
return '{ point: ' + this._point
|
|
|
|
+ (this._handleIn ? ', handleIn: ' + this._handleIn : '')
|
|
|
|
+ (this._handleOut ? ', handleOut: ' + this._handleOut : '')
|
2011-02-07 13:28:09 -05:00
|
|
|
+ ' }';
|
|
|
|
}
|
2011-02-13 11:26:24 -05:00
|
|
|
});
|