-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsegment.js
More file actions
40 lines (34 loc) · 782 Bytes
/
Copy pathsegment.js
File metadata and controls
40 lines (34 loc) · 782 Bytes
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
class Segment {
constructor(x, y, angle, len, twoInstance) {
this.x = x;
this.y = y;
this.length = len;
this.rect = twoInstance.makeRectangle(0, 0, len, len / 10);
this.rect.rotation = angle;
this.rect.translation.set(x + len / 2, y);
this.point = twoInstance.makeGroup(this.rect);
}
setAngle(angle) {
this.point.rotation = angle;
}
getAngle() {
return this.point.rotation;
}
getLength() {
return this.length;
}
getPosition() {
return { x: this.x, y: this.y };
}
getComponents() {
return {
x: this.length * Math.cos(this.point.rotation),
y: this.length * Math.sin(this.point.rotation)
};
}
setPosition(x, y) {
this.x = x;
this.y = y;
this.point.translation.set(x, y);
}
}