Replace SegmentPoint.create() in favor of normal constructor.

This commit is contained in:
Jürg Lehni 2013-06-25 09:48:51 -07:00
parent 3d5ae373a8
commit 7e24de7c74
2 changed files with 25 additions and 33 deletions

View file

@ -112,7 +112,6 @@ var Segment = Base.extend(/** @lends Segment# */{
*/
initialize: function Segment(arg0, arg1, arg2, arg3, arg4, arg5) {
var count = arguments.length,
createPoint = SegmentPoint.create,
point, handleIn, handleOut;
// TODO: Use Point.read or Point.readNamed to read these?
if (count === 0) {
@ -141,9 +140,9 @@ var Segment = Base.extend(/** @lends Segment# */{
handleIn = [ arg2, arg3 ];
handleOut = [ arg4, arg5 ];
}
createPoint(this, '_point', point);
createPoint(this, '_handleIn', handleIn);
createPoint(this, '_handleOut', handleOut);
this._point = new SegmentPoint(point, this);
this._handleIn = new SegmentPoint(handleIn, this);
this._handleOut = new SegmentPoint(handleOut, this);
},
_serialize: function(options) {

View file

@ -18,6 +18,28 @@
* @private
*/
var SegmentPoint = Point.extend({
initialize: function SegmentPoint(point, owner) {
var x, y, selected;
if (!point) {
x = y = 0;
} else if ((x = point[0]) !== undefined) { // Array-like
y = point[1];
} else {
// If not Point-like already, read Point from arguments
if ((x = point.x) === undefined) {
point = Point.read(arguments);
x = point.x;
}
y = point.y;
selected = point.selected;
}
this._x = x;
this._y = y;
this._owner = owner;
if (selected)
this.setSelected(true);
},
set: function(x, y) {
this._x = x;
this._y = y;
@ -56,34 +78,5 @@ var SegmentPoint = Point.extend({
isSelected: function() {
return this._owner._isSelected(this);
},
statics: {
create: function(segment, key, pt) {
var point = Base.create(SegmentPoint),
x, y, selected;
if (!pt) {
x = y = 0;
} else if ((x = pt[0]) !== undefined) { // Array-like
y = pt[1];
} else {
// If not Point-like already, read Point from pt = 3rd argument
if ((x = pt.x) === undefined) {
pt = Point.read(arguments, 2);
x = pt.x;
}
y = pt.y;
selected = pt.selected;
}
point._x = x;
point._y = y;
point._owner = segment;
// We need to set the point on the segment before copying over the
// selected state, as otherwise this won't actually select it.
segment[key] = point;
if (selected)
point.setSelected(true);
return point;
}
}
});