plotboilerplate 1.14.0 → 1.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/changelog.md +57 -0
- package/dist/index.esm.js +856 -694
- package/dist/index.esm.js.map +1 -1
- package/dist/index.esm.min.js +1 -1
- package/dist/index.esm.min.js.map +1 -1
- package/dist/plotboilerplate.browser.min.js +1 -1
- package/dist/plotboilerplate.browser.min.js.map +1 -1
- package/dist/plotboilerplate.js +858 -598
- package/dist/plotboilerplate.min.js +1 -1
- package/package.json +1 -1
- package/src/cjs/BezierPath.d.ts +32 -14
- package/src/cjs/BezierPath.js +65 -24
- package/src/cjs/BezierPath.js.map +1 -1
- package/src/cjs/Bounds.d.ts +22 -1
- package/src/cjs/Bounds.js +24 -1
- package/src/cjs/Bounds.js.map +1 -1
- package/src/cjs/Circle.d.ts +15 -13
- package/src/cjs/Circle.js +16 -34
- package/src/cjs/Circle.js.map +1 -1
- package/src/cjs/CircleSector.d.ts +17 -16
- package/src/cjs/CircleSector.js +12 -24
- package/src/cjs/CircleSector.js.map +1 -1
- package/src/cjs/CubicBezierCurve.d.ts +16 -15
- package/src/cjs/CubicBezierCurve.js +57 -94
- package/src/cjs/CubicBezierCurve.js.map +1 -1
- package/src/cjs/KeyHandler.d.ts +10 -3
- package/src/cjs/KeyHandler.js +28 -23
- package/src/cjs/KeyHandler.js.map +1 -1
- package/src/cjs/Line.d.ts +2 -15
- package/src/cjs/Line.js +6 -31
- package/src/cjs/Line.js.map +1 -1
- package/src/cjs/MouseHandler.js +43 -53
- package/src/cjs/MouseHandler.js.map +1 -1
- package/src/cjs/PBImage.d.ts +15 -13
- package/src/cjs/PBImage.js +11 -15
- package/src/cjs/PBImage.js.map +1 -1
- package/src/cjs/PBText.d.ts +13 -12
- package/src/cjs/PBText.js +8 -12
- package/src/cjs/PBText.js.map +1 -1
- package/src/cjs/PlotBoilerplate.js +3 -2
- package/src/cjs/PlotBoilerplate.js.map +1 -1
- package/src/cjs/Polygon.d.ts +44 -14
- package/src/cjs/Polygon.js +116 -66
- package/src/cjs/Polygon.js.map +1 -1
- package/src/cjs/Triangle.d.ts +15 -13
- package/src/cjs/Triangle.js +23 -64
- package/src/cjs/Triangle.js.map +1 -1
- package/src/cjs/VEllipse.d.ts +14 -9
- package/src/cjs/VEllipse.js +10 -18
- package/src/cjs/VEllipse.js.map +1 -1
- package/src/cjs/VEllipseSector.d.ts +15 -1
- package/src/cjs/VEllipseSector.js +11 -1
- package/src/cjs/VEllipseSector.js.map +1 -1
- package/src/cjs/Vector.d.ts +3 -15
- package/src/cjs/Vector.js +9 -49
- package/src/cjs/Vector.js.map +1 -1
- package/src/cjs/VertTuple.d.ts +15 -1
- package/src/cjs/VertTuple.js +14 -19
- package/src/cjs/VertTuple.js.map +1 -1
- package/src/cjs/Vertex.d.ts +47 -13
- package/src/cjs/Vertex.js +62 -22
- package/src/cjs/Vertex.js.map +1 -1
- package/src/cjs/VertexListeners.d.ts +12 -8
- package/src/cjs/VertexListeners.js +18 -25
- package/src/cjs/VertexListeners.js.map +1 -1
- package/src/cjs/draw.d.ts +41 -2
- package/src/cjs/draw.js +140 -3
- package/src/cjs/draw.js.map +1 -1
- package/src/cjs/drawgl.d.ts +38 -2
- package/src/cjs/drawgl.js +41 -2
- package/src/cjs/drawgl.js.map +1 -1
- package/src/cjs/drawutilssvg.d.ts +66 -3
- package/src/cjs/drawutilssvg.js +140 -15
- package/src/cjs/drawutilssvg.js.map +1 -1
- package/src/cjs/index.d.ts +0 -1
- package/src/cjs/index.js +0 -1
- package/src/cjs/index.js.map +1 -1
- package/src/cjs/interfaces/DrawLib.d.ts +61 -26
- package/src/cjs/interfaces/DrawLib.js +2 -0
- package/src/cjs/interfaces/DrawLib.js.map +1 -1
- package/src/cjs/interfaces/core.d.ts +0 -12
- package/src/cjs/module.d.ts +1 -3
- package/src/cjs/module.js +2 -5
- package/src/cjs/module.js.map +1 -1
- package/src/cjs/utils/creategui.js +16 -2
- package/src/cjs/utils/datastructures/Girih.d.ts +5 -0
- package/src/cjs/utils/datastructures/Girih.js +18 -14
- package/src/cjs/utils/datastructures/Girih.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +42 -25
- package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
- package/src/cjs/utils/datastructures/GirihTile.js +2 -13
- package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
- package/src/cjs/utils/findInVertexArray.d.ts +19 -0
- package/src/cjs/utils/findInVertexArray.js +29 -0
- package/src/cjs/utils/findInVertexArray.js.map +1 -0
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +17 -1
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +50 -32
- package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/cjs/utils/io/DndFileHandler.d.ts +63 -0
- package/src/cjs/utils/io/DndFileHandler.js +112 -0
- package/src/cjs/utils/io/DndFileHandler.js.map +1 -0
- package/src/cjs/utils/io/FileDrop.d.ts +98 -0
- package/src/cjs/utils/io/FileDrop.js +142 -0
- package/src/cjs/utils/io/FileDrop.js.map +1 -0
- package/src/esm/BezierPath.d.ts +32 -14
- package/src/esm/BezierPath.js +65 -24
- package/src/esm/BezierPath.js.map +1 -1
- package/src/esm/Bounds.d.ts +22 -1
- package/src/esm/Bounds.js +24 -1
- package/src/esm/Bounds.js.map +1 -1
- package/src/esm/Circle.d.ts +15 -13
- package/src/esm/Circle.js +16 -34
- package/src/esm/Circle.js.map +1 -1
- package/src/esm/CircleSector.d.ts +17 -16
- package/src/esm/CircleSector.js +12 -24
- package/src/esm/CircleSector.js.map +1 -1
- package/src/esm/CubicBezierCurve.d.ts +16 -15
- package/src/esm/CubicBezierCurve.js +57 -94
- package/src/esm/CubicBezierCurve.js.map +1 -1
- package/src/esm/KeyHandler.d.ts +10 -3
- package/src/esm/KeyHandler.js +28 -23
- package/src/esm/KeyHandler.js.map +1 -1
- package/src/esm/Line.d.ts +2 -15
- package/src/esm/Line.js +6 -31
- package/src/esm/Line.js.map +1 -1
- package/src/esm/MouseHandler.js +43 -53
- package/src/esm/MouseHandler.js.map +1 -1
- package/src/esm/PBImage.d.ts +15 -13
- package/src/esm/PBImage.js +11 -15
- package/src/esm/PBImage.js.map +1 -1
- package/src/esm/PBText.d.ts +13 -12
- package/src/esm/PBText.js +8 -12
- package/src/esm/PBText.js.map +1 -1
- package/src/esm/PlotBoilerplate.js +3 -2
- package/src/esm/PlotBoilerplate.js.map +1 -1
- package/src/esm/Polygon.d.ts +44 -14
- package/src/esm/Polygon.js +116 -66
- package/src/esm/Polygon.js.map +1 -1
- package/src/esm/Triangle.d.ts +15 -13
- package/src/esm/Triangle.js +23 -64
- package/src/esm/Triangle.js.map +1 -1
- package/src/esm/VEllipse.d.ts +14 -9
- package/src/esm/VEllipse.js +10 -18
- package/src/esm/VEllipse.js.map +1 -1
- package/src/esm/VEllipseSector.d.ts +15 -1
- package/src/esm/VEllipseSector.js +11 -1
- package/src/esm/VEllipseSector.js.map +1 -1
- package/src/esm/Vector.d.ts +3 -15
- package/src/esm/Vector.js +9 -49
- package/src/esm/Vector.js.map +1 -1
- package/src/esm/VertTuple.d.ts +15 -1
- package/src/esm/VertTuple.js +14 -19
- package/src/esm/VertTuple.js.map +1 -1
- package/src/esm/Vertex.d.ts +47 -13
- package/src/esm/Vertex.js +62 -22
- package/src/esm/Vertex.js.map +1 -1
- package/src/esm/VertexListeners.d.ts +12 -8
- package/src/esm/VertexListeners.js +18 -25
- package/src/esm/VertexListeners.js.map +1 -1
- package/src/esm/draw.d.ts +41 -2
- package/src/esm/draw.js +139 -3
- package/src/esm/draw.js.map +1 -1
- package/src/esm/drawgl.d.ts +38 -2
- package/src/esm/drawgl.js +41 -2
- package/src/esm/drawgl.js.map +1 -1
- package/src/esm/drawutilssvg.d.ts +66 -3
- package/src/esm/drawutilssvg.js +140 -15
- package/src/esm/drawutilssvg.js.map +1 -1
- package/src/esm/index.d.ts +0 -1
- package/src/esm/index.js +0 -1
- package/src/esm/index.js.map +1 -1
- package/src/esm/interfaces/DrawLib.d.ts +61 -26
- package/src/esm/interfaces/DrawLib.js +2 -0
- package/src/esm/interfaces/DrawLib.js.map +1 -1
- package/src/esm/interfaces/core.d.ts +0 -12
- package/src/esm/module.d.ts +1 -3
- package/src/esm/module.js +5 -4
- package/src/esm/module.js.map +1 -1
- package/src/esm/utils/datastructures/Girih.d.ts +5 -0
- package/src/esm/utils/datastructures/Girih.js +18 -14
- package/src/esm/utils/datastructures/Girih.js.map +1 -1
- package/src/esm/utils/datastructures/GirihPenroseRhombus.js +42 -25
- package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
- package/src/esm/utils/datastructures/GirihTile.js +2 -13
- package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
- package/src/esm/utils/findInVertexArray.d.ts +19 -0
- package/src/esm/utils/findInVertexArray.js +25 -0
- package/src/esm/utils/findInVertexArray.js.map +1 -0
- package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +17 -1
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js +49 -32
- package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
- package/src/esm/utils/io/DndFileHandler.d.ts +63 -0
- package/src/esm/utils/io/DndFileHandler.js +106 -0
- package/src/esm/utils/io/DndFileHandler.js.map +1 -0
- package/src/esm/utils/io/FileDrop.d.ts +98 -0
- package/src/esm/utils/io/FileDrop.js +136 -0
- package/src/esm/utils/io/FileDrop.js.map +1 -0
- package/src/ts/BezierPath.ts +78 -22
- package/src/ts/Bounds.ts +25 -1
- package/src/ts/Circle.ts +187 -200
- package/src/ts/CircleSector.ts +141 -141
- package/src/ts/CubicBezierCurve.ts +738 -810
- package/src/ts/KeyHandler.ts +221 -212
- package/src/ts/Line.ts +48 -80
- package/src/ts/MouseHandler.ts +356 -368
- package/src/ts/PBImage.ts +67 -69
- package/src/ts/PBText.ts +16 -14
- package/src/ts/PlotBoilerplate.ts +4 -2
- package/src/ts/Polygon.ts +493 -451
- package/src/ts/Triangle.ts +444 -489
- package/src/ts/VEllipse.ts +18 -17
- package/src/ts/VEllipseSector.ts +20 -1
- package/src/ts/Vector.ts +124 -160
- package/src/ts/VertTuple.ts +333 -338
- package/src/ts/Vertex.ts +75 -21
- package/src/ts/VertexListeners.ts +248 -266
- package/src/ts/draw.ts +192 -3
- package/src/ts/drawgl.ts +44 -2
- package/src/ts/drawutilssvg.ts +181 -15
- package/src/ts/index.ts +0 -1
- package/src/ts/interfaces/DrawLib.ts +69 -26
- package/src/ts/interfaces/core.ts +0 -11
- package/src/ts/module.ts +2 -4
- package/src/ts/utils/datastructures/Girih.ts +204 -209
- package/src/ts/utils/datastructures/GirihPenroseRhombus.ts +170 -152
- package/src/ts/utils/datastructures/GirihTile.ts +394 -419
- package/src/ts/utils/findInVertexArray.ts +28 -0
- package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +56 -34
- package/src/ts/utils/io/FileDrop.ts +178 -0
- package/src/ts/SVGBuilder.ts +0 -109
- package/src/ts/utils/algorithms/sh-tmp.ts~ +0 -59
package/src/ts/VertTuple.ts
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* @modified 2020-12-04 Changed `getClosestT` param from `Vertex` to `XYCoords` (generalized).
|
|
9
9
|
* @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
|
|
10
10
|
* @modified 2021-01-20 Added UID.
|
|
11
|
-
* @
|
|
11
|
+
* @modified 2022-02-02 Added the `destroy` method.
|
|
12
|
+
* @version 1.2.0
|
|
12
13
|
*/
|
|
13
14
|
|
|
14
15
|
import { Vertex } from "./Vertex";
|
|
@@ -23,343 +24,337 @@ import { XYCoords, UID } from "./interfaces";
|
|
|
23
24
|
* @requires XYCoords
|
|
24
25
|
*/
|
|
25
26
|
export class VertTuple<T extends VertTuple<T>> {
|
|
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
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The UID of this drawable object.
|
|
29
|
+
*
|
|
30
|
+
* @member {UID}
|
|
31
|
+
* @memberof VertTuple
|
|
32
|
+
* @instance
|
|
33
|
+
* @readonly
|
|
34
|
+
*/
|
|
35
|
+
readonly uid: UID;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @member {Vertex}
|
|
39
|
+
* @memberof VertTuple
|
|
40
|
+
* @instance
|
|
41
|
+
*/
|
|
42
|
+
a: Vertex;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @member {Vertex}
|
|
46
|
+
* @memberof VertTuple
|
|
47
|
+
* @instance
|
|
48
|
+
*/
|
|
49
|
+
b: Vertex;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @member isDestroyed
|
|
53
|
+
* @memberof VertTuple
|
|
54
|
+
* @type {boolean}
|
|
55
|
+
* @instance
|
|
56
|
+
*/
|
|
57
|
+
isDestroyed: boolean;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The factory is used by the `clone` method.
|
|
61
|
+
*/
|
|
62
|
+
private factory: (a: Vertex, b: Vertex) => T;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Creates an instance.
|
|
66
|
+
*
|
|
67
|
+
* @constructor
|
|
68
|
+
* @name VertTuple
|
|
69
|
+
* @param {Vertex} a The tuple's first point.
|
|
70
|
+
* @param {Vertex} b The tuple's second point.
|
|
71
|
+
**/
|
|
72
|
+
constructor(a: Vertex, b: Vertex, factory: (a: Vertex, b: Vertex) => T) {
|
|
73
|
+
this.uid = UIDGenerator.next();
|
|
74
|
+
this.a = a;
|
|
75
|
+
this.b = b;
|
|
76
|
+
this.factory = factory;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get the length of this line.
|
|
81
|
+
*
|
|
82
|
+
* @method length
|
|
83
|
+
* @instance
|
|
84
|
+
* @memberof VertTuple
|
|
85
|
+
**/
|
|
86
|
+
length(): number {
|
|
87
|
+
return Math.sqrt(Math.pow(this.b.x - this.a.x, 2) + Math.pow(this.b.y - this.a.y, 2));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Set the length of this vector to the given amount. This only works if this
|
|
92
|
+
* vector is not a null vector.
|
|
93
|
+
*
|
|
94
|
+
* @method setLength
|
|
95
|
+
* @param {number} length - The desired length.
|
|
96
|
+
* @memberof VertTuple
|
|
97
|
+
* @return {T} this (for chaining)
|
|
98
|
+
**/
|
|
99
|
+
setLength(length: number): VertTuple<T> {
|
|
100
|
+
return this.scale(length / this.length());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Substract the given vertex from this line's end points.
|
|
105
|
+
*
|
|
106
|
+
* @method sub
|
|
107
|
+
* @param {XYCoords} amount The amount (x,y) to substract.
|
|
108
|
+
* @return {VertTuple} this
|
|
109
|
+
* @instance
|
|
110
|
+
* @memberof VertTuple
|
|
111
|
+
**/
|
|
112
|
+
sub(amount: XYCoords): VertTuple<T> {
|
|
113
|
+
this.a.sub(amount);
|
|
114
|
+
this.b.sub(amount);
|
|
115
|
+
return this;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Add the given vertex to this line's end points.
|
|
120
|
+
*
|
|
121
|
+
* @method add
|
|
122
|
+
* @param {XYCoords} amount The amount (x,y) to add.
|
|
123
|
+
* @return {Line} this
|
|
124
|
+
* @instance
|
|
125
|
+
* @memberof VertTuple
|
|
126
|
+
**/
|
|
127
|
+
add(amount: XYCoords): VertTuple<T> {
|
|
128
|
+
this.a.add(amount);
|
|
129
|
+
this.b.add(amount);
|
|
130
|
+
return this;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Normalize this line (set to length 1).
|
|
135
|
+
*
|
|
136
|
+
* @method normalize
|
|
137
|
+
* @return {VertTuple} this
|
|
138
|
+
* @instance
|
|
139
|
+
* @memberof VertTuple
|
|
140
|
+
**/
|
|
141
|
+
normalize(): VertTuple<T> {
|
|
142
|
+
this.b.set(this.a.x + (this.b.x - this.a.x) / this.length(), this.a.y + (this.b.y - this.a.y) / this.length());
|
|
143
|
+
return this;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Scale this line by the given factor.
|
|
148
|
+
*
|
|
149
|
+
* @method scale
|
|
150
|
+
* @param {number} factor The factor for scaling (1.0 means no scale).
|
|
151
|
+
* @return {VertTuple} this
|
|
152
|
+
* @instance
|
|
153
|
+
* @memberof VertTuple
|
|
154
|
+
**/
|
|
155
|
+
scale(factor: number): VertTuple<T> {
|
|
156
|
+
this.b.set(this.a.x + (this.b.x - this.a.x) * factor, this.a.y + (this.b.y - this.a.y) * factor);
|
|
157
|
+
return this;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Move this line to a new location.
|
|
162
|
+
*
|
|
163
|
+
* @method moveTo
|
|
164
|
+
* @param {Vertex} newA - The new desired location of 'a'. Vertex 'b' will be moved, too.
|
|
165
|
+
* @return {VertTuple} this
|
|
166
|
+
* @instance
|
|
167
|
+
* @memberof VertTuple
|
|
168
|
+
**/
|
|
169
|
+
moveTo(newA: Vertex): VertTuple<T> {
|
|
170
|
+
let diff = this.a.difference(newA);
|
|
171
|
+
this.a.add(diff);
|
|
172
|
+
this.b.add(diff);
|
|
173
|
+
return this;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Get the angle between this and the passed line (in radians).
|
|
178
|
+
*
|
|
179
|
+
* @method angle
|
|
180
|
+
* @param {VertTuple} line - (optional) The line to calculate the angle to. If null the baseline (x-axis) will be used.
|
|
181
|
+
* @return {number} this
|
|
182
|
+
* @instance
|
|
183
|
+
* @memberof VertTuple
|
|
184
|
+
**/
|
|
185
|
+
angle(line?: VertTuple<any>): number {
|
|
186
|
+
if (line == null || typeof line == "undefined") {
|
|
187
|
+
line = this.factory(new Vertex(0, 0), new Vertex(100, 0));
|
|
71
188
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
* @return {VertTuple} this
|
|
169
|
-
* @instance
|
|
170
|
-
* @memberof VertTuple
|
|
171
|
-
**/
|
|
172
|
-
moveTo( newA:Vertex ):VertTuple<T> {
|
|
173
|
-
let diff = this.a.difference( newA );
|
|
174
|
-
this.a.add( diff );
|
|
175
|
-
this.b.add( diff );
|
|
176
|
-
return this;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Get the angle between this and the passed line (in radians).
|
|
182
|
-
*
|
|
183
|
-
* @method angle
|
|
184
|
-
* @param {VertTuple} line - (optional) The line to calculate the angle to. If null the baseline (x-axis) will be used.
|
|
185
|
-
* @return {number} this
|
|
186
|
-
* @instance
|
|
187
|
-
* @memberof VertTuple
|
|
188
|
-
**/
|
|
189
|
-
angle( line?:VertTuple<any> ):number {
|
|
190
|
-
if( line == null || typeof line == 'undefined' ) {
|
|
191
|
-
line = this.factory( new Vertex(0,0), new Vertex(100,0) );
|
|
192
|
-
}
|
|
193
|
-
// Compute the angle from x axis and the return the difference :)
|
|
194
|
-
const v0 : Vertex = this.b.clone().sub( this.a );
|
|
195
|
-
const v1 : Vertex = line.b.clone().sub( line.a );
|
|
196
|
-
// Thank you, Javascript, for this second atan function. No additional math is needed here!
|
|
197
|
-
// The result might be negative, but isn't it usually nicer to determine angles in positive values only?
|
|
198
|
-
return Math.atan2( v1.x, v1.y ) - Math.atan2( v0.x, v0.y );
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Get line point at position t in [0 ... 1]:<br>
|
|
204
|
-
* <pre>[P(0)]=[A]--------------------[P(t)]------[B]=[P(1)]</pre><br>
|
|
205
|
-
* <br>
|
|
206
|
-
* The counterpart of this function is Line.getClosestT(Vertex).
|
|
207
|
-
*
|
|
208
|
-
* @method vertAt
|
|
209
|
-
* @param {number} t The position scalar.
|
|
210
|
-
* @return {Vertex} The vertex a position t.
|
|
211
|
-
* @instance
|
|
212
|
-
* @memberof VertTuple
|
|
213
|
-
**/
|
|
214
|
-
vertAt( t:number ):Vertex {
|
|
215
|
-
return new Vertex( this.a.x + (this.b.x-this.a.x)*t,
|
|
216
|
-
this.a.y + (this.b.y-this.a.y)*t );
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Get the denominator of this and the given line.
|
|
222
|
-
*
|
|
223
|
-
* If the denominator is zero (or close to zero) both line are co-linear.
|
|
224
|
-
*
|
|
225
|
-
* @method denominator
|
|
226
|
-
* @param {VertTuple} line
|
|
227
|
-
* @instance
|
|
228
|
-
* @memberof VertTuple
|
|
229
|
-
* @return {Number}
|
|
230
|
-
**/
|
|
231
|
-
denominator( line:VertTuple<T> ):number {
|
|
232
|
-
// http://jsfiddle.net/justin_c_rounds/Gd2S2/
|
|
233
|
-
return ((line.b.y - line.a.y) * (this.b.x - this.a.x)) - ((line.b.x - line.a.x) * (this.b.y - this.a.y));
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* Checks if this and the given line are co-linear.
|
|
239
|
-
*
|
|
240
|
-
* The constant Vertex.EPSILON is used for tolerance.
|
|
241
|
-
*
|
|
242
|
-
* @method colinear
|
|
243
|
-
* @param {VertTuple} line
|
|
244
|
-
* @instance
|
|
245
|
-
* @memberof VertTuple
|
|
246
|
-
* @return true if both lines are co-linear.
|
|
247
|
-
*/
|
|
248
|
-
colinear( line:VertTuple<T> ):boolean {
|
|
249
|
-
return Math.abs( this.denominator(line) ) < Vertex.EPSILON;
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Get the closest position T from this line to the specified point.
|
|
255
|
-
*
|
|
256
|
-
* The counterpart for this function is Line.vertAt(Number).
|
|
257
|
-
*
|
|
258
|
-
* @name getClosetT
|
|
259
|
-
* @method getClosestT
|
|
260
|
-
* @param {XYCoords} p The point (vertex) to measure the distance to.
|
|
261
|
-
* @return {number} The line position t of minimal distance to p.
|
|
262
|
-
* @instance
|
|
263
|
-
* @memberof VertTuple
|
|
264
|
-
**/
|
|
265
|
-
getClosestT( p:XYCoords ):number {
|
|
266
|
-
var l2 = VertTuple.vtutils.dist2(this.a, this.b);
|
|
267
|
-
if( l2 === 0 ) return 0;
|
|
268
|
-
var t = ((p.x - this.a.x) * (this.b.x - this.a.x) + (p.y - this.a.y) * (this.b.y - this.a.y)) / l2;
|
|
269
|
-
// Do not wrap to [0,1] here.
|
|
270
|
-
// Other results are of interest, too.
|
|
271
|
-
// t = Math.max(0, Math.min(1, t));
|
|
272
|
-
return t;
|
|
273
|
-
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Check if the given point is located on this line. Optionally also check if
|
|
278
|
-
* that point is located between point `a` and `b`.
|
|
279
|
-
*
|
|
280
|
-
* @method hasPoint
|
|
281
|
-
* @param {Vertex} point The point to check.
|
|
282
|
-
* @param {boolean=} insideBoundsOnly If set to to true (default=false) the point must be between start and end point of the line.
|
|
283
|
-
* @return {boolean} True if the given point is on this line.
|
|
284
|
-
* @instance
|
|
285
|
-
* @memberof VertTuple
|
|
286
|
-
*/
|
|
287
|
-
hasPoint( point:XYCoords, insideBoundsOnly?:boolean ) : boolean {
|
|
288
|
-
const t : number = this.getClosestT(point);
|
|
289
|
-
// Compare to pointDistance?
|
|
290
|
-
if( typeof insideBoundsOnly !== "undefined" && insideBoundsOnly ) {
|
|
291
|
-
const distance : number = Math.sqrt( VertTuple.vtutils.dist2(point, this.vertAt(t)) );
|
|
292
|
-
return distance < Vertex.EPSILON && t >= 0 && t <= 1;
|
|
293
|
-
} else {
|
|
294
|
-
return t >= 0 && t <= 1;
|
|
295
|
-
}
|
|
189
|
+
// Compute the angle from x axis and the return the difference :)
|
|
190
|
+
const v0: Vertex = this.b.clone().sub(this.a);
|
|
191
|
+
const v1: Vertex = line.b.clone().sub(line.a);
|
|
192
|
+
// Thank you, Javascript, for this second atan function. No additional math is needed here!
|
|
193
|
+
// The result might be negative, but isn't it usually nicer to determine angles in positive values only?
|
|
194
|
+
return Math.atan2(v1.x, v1.y) - Math.atan2(v0.x, v0.y);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get line point at position t in [0 ... 1]:<br>
|
|
199
|
+
* <pre>[P(0)]=[A]--------------------[P(t)]------[B]=[P(1)]</pre><br>
|
|
200
|
+
* <br>
|
|
201
|
+
* The counterpart of this function is Line.getClosestT(Vertex).
|
|
202
|
+
*
|
|
203
|
+
* @method vertAt
|
|
204
|
+
* @param {number} t The position scalar.
|
|
205
|
+
* @return {Vertex} The vertex a position t.
|
|
206
|
+
* @instance
|
|
207
|
+
* @memberof VertTuple
|
|
208
|
+
**/
|
|
209
|
+
vertAt(t: number): Vertex {
|
|
210
|
+
return new Vertex(this.a.x + (this.b.x - this.a.x) * t, this.a.y + (this.b.y - this.a.y) * t);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Get the denominator of this and the given line.
|
|
215
|
+
*
|
|
216
|
+
* If the denominator is zero (or close to zero) both line are co-linear.
|
|
217
|
+
*
|
|
218
|
+
* @method denominator
|
|
219
|
+
* @param {VertTuple} line
|
|
220
|
+
* @instance
|
|
221
|
+
* @memberof VertTuple
|
|
222
|
+
* @return {Number}
|
|
223
|
+
**/
|
|
224
|
+
denominator(line: VertTuple<T>): number {
|
|
225
|
+
// http://jsfiddle.net/justin_c_rounds/Gd2S2/
|
|
226
|
+
return (line.b.y - line.a.y) * (this.b.x - this.a.x) - (line.b.x - line.a.x) * (this.b.y - this.a.y);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Checks if this and the given line are co-linear.
|
|
231
|
+
*
|
|
232
|
+
* The constant Vertex.EPSILON is used for tolerance.
|
|
233
|
+
*
|
|
234
|
+
* @method colinear
|
|
235
|
+
* @param {VertTuple} line
|
|
236
|
+
* @instance
|
|
237
|
+
* @memberof VertTuple
|
|
238
|
+
* @return true if both lines are co-linear.
|
|
239
|
+
*/
|
|
240
|
+
colinear(line: VertTuple<T>): boolean {
|
|
241
|
+
return Math.abs(this.denominator(line)) < Vertex.EPSILON;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Get the closest position T from this line to the specified point.
|
|
246
|
+
*
|
|
247
|
+
* The counterpart for this function is Line.vertAt(Number).
|
|
248
|
+
*
|
|
249
|
+
* @name getClosetT
|
|
250
|
+
* @method getClosestT
|
|
251
|
+
* @param {XYCoords} p The point (vertex) to measure the distance to.
|
|
252
|
+
* @return {number} The line position t of minimal distance to p.
|
|
253
|
+
* @instance
|
|
254
|
+
* @memberof VertTuple
|
|
255
|
+
**/
|
|
256
|
+
getClosestT(p: XYCoords): number {
|
|
257
|
+
var l2 = VertTuple.vtutils.dist2(this.a, this.b);
|
|
258
|
+
if (l2 === 0) return 0;
|
|
259
|
+
var t = ((p.x - this.a.x) * (this.b.x - this.a.x) + (p.y - this.a.y) * (this.b.y - this.a.y)) / l2;
|
|
260
|
+
// Do not wrap to [0,1] here.
|
|
261
|
+
// Other results are of interest, too.
|
|
262
|
+
// t = Math.max(0, Math.min(1, t));
|
|
263
|
+
return t;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Check if the given point is located on this line. Optionally also check if
|
|
268
|
+
* that point is located between point `a` and `b`.
|
|
269
|
+
*
|
|
270
|
+
* @method hasPoint
|
|
271
|
+
* @param {Vertex} point The point to check.
|
|
272
|
+
* @param {boolean=} insideBoundsOnly If set to to true (default=false) the point must be between start and end point of the line.
|
|
273
|
+
* @return {boolean} True if the given point is on this line.
|
|
274
|
+
* @instance
|
|
275
|
+
* @memberof VertTuple
|
|
276
|
+
*/
|
|
277
|
+
hasPoint(point: XYCoords, insideBoundsOnly?: boolean): boolean {
|
|
278
|
+
const t: number = this.getClosestT(point);
|
|
279
|
+
// Compare to pointDistance?
|
|
280
|
+
if (typeof insideBoundsOnly !== "undefined" && insideBoundsOnly) {
|
|
281
|
+
const distance: number = Math.sqrt(VertTuple.vtutils.dist2(point, this.vertAt(t)));
|
|
282
|
+
return distance < Vertex.EPSILON && t >= 0 && t <= 1;
|
|
283
|
+
} else {
|
|
284
|
+
return t >= 0 && t <= 1;
|
|
296
285
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/**
|
|
289
|
+
* Get the closest point on this line to the specified point.
|
|
290
|
+
*
|
|
291
|
+
* @method getClosestPoint
|
|
292
|
+
* @param {Vertex} p The point (vertex) to measre the distance to.
|
|
293
|
+
* @return {Vertex} The point on the line that is closest to p.
|
|
294
|
+
* @instance
|
|
295
|
+
* @memberof VertTuple
|
|
296
|
+
**/
|
|
297
|
+
getClosestPoint(p: Vertex): Vertex {
|
|
298
|
+
var t: number = this.getClosestT(p);
|
|
299
|
+
return this.vertAt(t);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* The the minimal distance between this line and the specified point.
|
|
304
|
+
*
|
|
305
|
+
* @method pointDistance
|
|
306
|
+
* @param {Vertex} p The point (vertex) to measre the distance to.
|
|
307
|
+
* @return {number} The absolute minimal distance.
|
|
308
|
+
* @instance
|
|
309
|
+
* @memberof VertTuple
|
|
310
|
+
**/
|
|
311
|
+
pointDistance(p: Vertex): number {
|
|
312
|
+
// Taken From:
|
|
313
|
+
// https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
|
|
314
|
+
return Math.sqrt(VertTuple.vtutils.dist2(p, this.vertAt(this.getClosestT(p))));
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Create a deep clone of this instance.
|
|
319
|
+
*
|
|
320
|
+
* @method cloneLine
|
|
321
|
+
* @return {T} A type safe clone if this instance.
|
|
322
|
+
* @instance
|
|
323
|
+
* @memberof VertTuple
|
|
324
|
+
**/
|
|
325
|
+
clone(): T {
|
|
326
|
+
return this.factory(this.a.clone(), this.b.clone());
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* Create a string representation of this line.
|
|
331
|
+
*
|
|
332
|
+
* @method totring
|
|
333
|
+
* @return {string} The string representing this line.
|
|
334
|
+
* @instance
|
|
335
|
+
* @memberof VertTuple
|
|
336
|
+
**/
|
|
337
|
+
toString(): string {
|
|
338
|
+
return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + " }";
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* This function should invalidate any installed listeners and invalidate this object.
|
|
343
|
+
* After calling this function the object might not hold valid data any more and
|
|
344
|
+
* should not be used.
|
|
345
|
+
*/
|
|
346
|
+
destroy() {
|
|
347
|
+
this.a.destroy();
|
|
348
|
+
this.b.destroy();
|
|
349
|
+
this.isDestroyed = true;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* @private
|
|
354
|
+
**/
|
|
355
|
+
static vtutils = {
|
|
356
|
+
dist2: (v: XYCoords, w: XYCoords) => {
|
|
357
|
+
return (v.x - w.x) * (v.x - w.x) + (v.y - w.y) * (v.y - w.y);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
365
360
|
}
|