forked from paperjs/paper.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSegmentPoint.js
More file actions
94 lines (84 loc) · 2.07 KB
/
Copy pathSegmentPoint.js
File metadata and controls
94 lines (84 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* Paper.js - The Swiss Army Knife of Vector Graphics Scripting.
* http://paperjs.org/
*
* Copyright (c) 2011 - 2013, Juerg Lehni & Jonathan Puckey
* http://lehni.org/ & http://jonathanpuckey.com/
*
* Distributed under the MIT license. See LICENSE file for details.
*
* All rights reserved.
*/
/**
* @name SegmentPoint
* @class An internal version of Point that notifies its segment of each change
* Note: This prototype is not exported.
*
* @private
*/
var SegmentPoint = Point.extend({
initialize: function SegmentPoint(point, owner, key) {
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;
// We have to set the owner's property that points to this point already
// now, so #setSelected(true) can work.
owner[key] = this;
if (selected)
this.setSelected(true);
},
set: function(x, y) {
this._x = x;
this._y = y;
this._owner._changed(this);
return this;
},
_serialize: function(options) {
var f = options.formatter,
x = f.number(this._x),
y = f.number(this._y);
return this.isSelected()
? { x: x, y: y, selected: true }
: [x, y];
},
getX: function() {
return this._x;
},
setX: function(x) {
this._x = x;
this._owner._changed(this);
},
getY: function() {
return this._y;
},
setY: function(y) {
this._y = y;
this._owner._changed(this);
},
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.
return Numerical.isZero(this._x) && Numerical.isZero(this._y);
},
setSelected: function(selected) {
this._owner._setSelected(this, selected);
},
isSelected: function() {
return this._owner._isSelected(this);
}
});