2011-05-08 04:59:37 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-08 04:59:37 -04:00
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-05-08 04:59:37 -04:00
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-07-01 06:17:45 -04:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-05-08 04:59:37 -04:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2011-04-21 08:21:56 -04:00
|
|
|
/**
|
2011-06-22 18:56:05 -04:00
|
|
|
* @name SegmentPoint
|
|
|
|
* @class An internal version of Point that notifies its segment of each change
|
2011-04-21 08:21:56 -04:00
|
|
|
* Note: This prototype is not exported.
|
2011-06-30 06:01:51 -04:00
|
|
|
*
|
2011-06-22 18:56:05 -04:00
|
|
|
* @private
|
2011-04-21 08:21:56 -04:00
|
|
|
*/
|
|
|
|
var SegmentPoint = Point.extend({
|
|
|
|
set: function(x, y) {
|
|
|
|
this._x = x;
|
|
|
|
this._y = y;
|
2011-05-08 08:38:09 -04:00
|
|
|
this._owner._changed(this);
|
2011-04-21 08:21:56 -04:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
getX: function() {
|
|
|
|
return this._x;
|
|
|
|
},
|
|
|
|
|
|
|
|
setX: function(x) {
|
|
|
|
this._x = x;
|
2011-05-08 08:38:09 -04:00
|
|
|
this._owner._changed(this);
|
2011-04-21 08:21:56 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
getY: function() {
|
|
|
|
return this._y;
|
|
|
|
},
|
|
|
|
|
|
|
|
setY: function(y) {
|
|
|
|
this._y = y;
|
2011-05-08 08:38:09 -04:00
|
|
|
this._owner._changed(this);
|
2011-04-21 08:21:56 -04:00
|
|
|
},
|
2011-06-30 06:01:51 -04:00
|
|
|
|
2011-08-16 07:38:52 -04:00
|
|
|
isZero: function() {
|
|
|
|
// Provide our own version of Point#isZero() that does not use the x / y
|
|
|
|
// accessors but the internal properties directly, for performance
|
|
|
|
// reasons, since it is used a lot internally.
|
2012-11-06 00:06:13 -05:00
|
|
|
return Numerical.isZero(this._x) && Numerical.isZero(this._y);
|
2011-08-16 07:38:52 -04:00
|
|
|
},
|
|
|
|
|
2011-04-21 12:06:06 -04:00
|
|
|
setSelected: function(selected) {
|
2011-05-08 08:38:09 -04:00
|
|
|
this._owner._setSelected(this, selected);
|
2011-04-21 12:06:06 -04:00
|
|
|
},
|
2011-06-30 06:01:51 -04:00
|
|
|
|
2011-04-21 13:51:49 -04:00
|
|
|
isSelected: function() {
|
2011-05-08 08:38:09 -04:00
|
|
|
return this._owner._isSelected(this);
|
2011-04-21 12:06:06 -04:00
|
|
|
},
|
2011-06-30 06:01:51 -04:00
|
|
|
|
2011-04-21 08:21:56 -04:00
|
|
|
statics: {
|
2011-05-26 05:58:16 -04:00
|
|
|
create: function(segment, key, pt) {
|
2012-11-04 00:49:37 -04:00
|
|
|
var point = Base.create(SegmentPoint),
|
2011-05-26 05:58:16 -04:00
|
|
|
x, y, selected;
|
|
|
|
if (!pt) {
|
|
|
|
x = y = 0;
|
2011-07-13 07:46:16 -04:00
|
|
|
} 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) {
|
2012-10-18 17:24:15 -04:00
|
|
|
pt = Point.read(arguments, 2);
|
2011-07-13 07:46:16 -04:00
|
|
|
x = pt.x;
|
|
|
|
}
|
2011-05-21 09:27:29 -04:00
|
|
|
y = pt.y;
|
|
|
|
selected = pt.selected;
|
2011-04-21 08:21:56 -04:00
|
|
|
}
|
2011-05-01 19:17:21 -04:00
|
|
|
point._x = x;
|
|
|
|
point._y = y;
|
2011-05-08 08:38:09 -04:00
|
|
|
point._owner = segment;
|
2011-05-26 05:58:16 -04:00
|
|
|
// 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;
|
2011-05-21 09:27:29 -04:00
|
|
|
if (selected)
|
|
|
|
point.setSelected(true);
|
2011-04-21 08:21:56 -04:00
|
|
|
return point;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|