mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Replace SegmentPoint.create() in favor of normal constructor.
This commit is contained in:
parent
3d5ae373a8
commit
7e24de7c74
2 changed files with 25 additions and 33 deletions
|
@ -112,7 +112,6 @@ var Segment = Base.extend(/** @lends Segment# */{
|
||||||
*/
|
*/
|
||||||
initialize: function Segment(arg0, arg1, arg2, arg3, arg4, arg5) {
|
initialize: function Segment(arg0, arg1, arg2, arg3, arg4, arg5) {
|
||||||
var count = arguments.length,
|
var count = arguments.length,
|
||||||
createPoint = SegmentPoint.create,
|
|
||||||
point, handleIn, handleOut;
|
point, handleIn, handleOut;
|
||||||
// TODO: Use Point.read or Point.readNamed to read these?
|
// TODO: Use Point.read or Point.readNamed to read these?
|
||||||
if (count === 0) {
|
if (count === 0) {
|
||||||
|
@ -141,9 +140,9 @@ var Segment = Base.extend(/** @lends Segment# */{
|
||||||
handleIn = [ arg2, arg3 ];
|
handleIn = [ arg2, arg3 ];
|
||||||
handleOut = [ arg4, arg5 ];
|
handleOut = [ arg4, arg5 ];
|
||||||
}
|
}
|
||||||
createPoint(this, '_point', point);
|
this._point = new SegmentPoint(point, this);
|
||||||
createPoint(this, '_handleIn', handleIn);
|
this._handleIn = new SegmentPoint(handleIn, this);
|
||||||
createPoint(this, '_handleOut', handleOut);
|
this._handleOut = new SegmentPoint(handleOut, this);
|
||||||
},
|
},
|
||||||
|
|
||||||
_serialize: function(options) {
|
_serialize: function(options) {
|
||||||
|
|
|
@ -18,6 +18,28 @@
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
var SegmentPoint = Point.extend({
|
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) {
|
set: function(x, y) {
|
||||||
this._x = x;
|
this._x = x;
|
||||||
this._y = y;
|
this._y = y;
|
||||||
|
@ -56,34 +78,5 @@ var SegmentPoint = Point.extend({
|
||||||
|
|
||||||
isSelected: function() {
|
isSelected: function() {
|
||||||
return this._owner._isSelected(this);
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue