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.
Files changed (232) hide show
  1. package/README.md +2 -0
  2. package/changelog.md +57 -0
  3. package/dist/index.esm.js +856 -694
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.esm.min.js +1 -1
  6. package/dist/index.esm.min.js.map +1 -1
  7. package/dist/plotboilerplate.browser.min.js +1 -1
  8. package/dist/plotboilerplate.browser.min.js.map +1 -1
  9. package/dist/plotboilerplate.js +858 -598
  10. package/dist/plotboilerplate.min.js +1 -1
  11. package/package.json +1 -1
  12. package/src/cjs/BezierPath.d.ts +32 -14
  13. package/src/cjs/BezierPath.js +65 -24
  14. package/src/cjs/BezierPath.js.map +1 -1
  15. package/src/cjs/Bounds.d.ts +22 -1
  16. package/src/cjs/Bounds.js +24 -1
  17. package/src/cjs/Bounds.js.map +1 -1
  18. package/src/cjs/Circle.d.ts +15 -13
  19. package/src/cjs/Circle.js +16 -34
  20. package/src/cjs/Circle.js.map +1 -1
  21. package/src/cjs/CircleSector.d.ts +17 -16
  22. package/src/cjs/CircleSector.js +12 -24
  23. package/src/cjs/CircleSector.js.map +1 -1
  24. package/src/cjs/CubicBezierCurve.d.ts +16 -15
  25. package/src/cjs/CubicBezierCurve.js +57 -94
  26. package/src/cjs/CubicBezierCurve.js.map +1 -1
  27. package/src/cjs/KeyHandler.d.ts +10 -3
  28. package/src/cjs/KeyHandler.js +28 -23
  29. package/src/cjs/KeyHandler.js.map +1 -1
  30. package/src/cjs/Line.d.ts +2 -15
  31. package/src/cjs/Line.js +6 -31
  32. package/src/cjs/Line.js.map +1 -1
  33. package/src/cjs/MouseHandler.js +43 -53
  34. package/src/cjs/MouseHandler.js.map +1 -1
  35. package/src/cjs/PBImage.d.ts +15 -13
  36. package/src/cjs/PBImage.js +11 -15
  37. package/src/cjs/PBImage.js.map +1 -1
  38. package/src/cjs/PBText.d.ts +13 -12
  39. package/src/cjs/PBText.js +8 -12
  40. package/src/cjs/PBText.js.map +1 -1
  41. package/src/cjs/PlotBoilerplate.js +3 -2
  42. package/src/cjs/PlotBoilerplate.js.map +1 -1
  43. package/src/cjs/Polygon.d.ts +44 -14
  44. package/src/cjs/Polygon.js +116 -66
  45. package/src/cjs/Polygon.js.map +1 -1
  46. package/src/cjs/Triangle.d.ts +15 -13
  47. package/src/cjs/Triangle.js +23 -64
  48. package/src/cjs/Triangle.js.map +1 -1
  49. package/src/cjs/VEllipse.d.ts +14 -9
  50. package/src/cjs/VEllipse.js +10 -18
  51. package/src/cjs/VEllipse.js.map +1 -1
  52. package/src/cjs/VEllipseSector.d.ts +15 -1
  53. package/src/cjs/VEllipseSector.js +11 -1
  54. package/src/cjs/VEllipseSector.js.map +1 -1
  55. package/src/cjs/Vector.d.ts +3 -15
  56. package/src/cjs/Vector.js +9 -49
  57. package/src/cjs/Vector.js.map +1 -1
  58. package/src/cjs/VertTuple.d.ts +15 -1
  59. package/src/cjs/VertTuple.js +14 -19
  60. package/src/cjs/VertTuple.js.map +1 -1
  61. package/src/cjs/Vertex.d.ts +47 -13
  62. package/src/cjs/Vertex.js +62 -22
  63. package/src/cjs/Vertex.js.map +1 -1
  64. package/src/cjs/VertexListeners.d.ts +12 -8
  65. package/src/cjs/VertexListeners.js +18 -25
  66. package/src/cjs/VertexListeners.js.map +1 -1
  67. package/src/cjs/draw.d.ts +41 -2
  68. package/src/cjs/draw.js +140 -3
  69. package/src/cjs/draw.js.map +1 -1
  70. package/src/cjs/drawgl.d.ts +38 -2
  71. package/src/cjs/drawgl.js +41 -2
  72. package/src/cjs/drawgl.js.map +1 -1
  73. package/src/cjs/drawutilssvg.d.ts +66 -3
  74. package/src/cjs/drawutilssvg.js +140 -15
  75. package/src/cjs/drawutilssvg.js.map +1 -1
  76. package/src/cjs/index.d.ts +0 -1
  77. package/src/cjs/index.js +0 -1
  78. package/src/cjs/index.js.map +1 -1
  79. package/src/cjs/interfaces/DrawLib.d.ts +61 -26
  80. package/src/cjs/interfaces/DrawLib.js +2 -0
  81. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  82. package/src/cjs/interfaces/core.d.ts +0 -12
  83. package/src/cjs/module.d.ts +1 -3
  84. package/src/cjs/module.js +2 -5
  85. package/src/cjs/module.js.map +1 -1
  86. package/src/cjs/utils/creategui.js +16 -2
  87. package/src/cjs/utils/datastructures/Girih.d.ts +5 -0
  88. package/src/cjs/utils/datastructures/Girih.js +18 -14
  89. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  90. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +42 -25
  91. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  92. package/src/cjs/utils/datastructures/GirihTile.js +2 -13
  93. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  94. package/src/cjs/utils/findInVertexArray.d.ts +19 -0
  95. package/src/cjs/utils/findInVertexArray.js +29 -0
  96. package/src/cjs/utils/findInVertexArray.js.map +1 -0
  97. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +17 -1
  98. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +50 -32
  99. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  100. package/src/cjs/utils/io/DndFileHandler.d.ts +63 -0
  101. package/src/cjs/utils/io/DndFileHandler.js +112 -0
  102. package/src/cjs/utils/io/DndFileHandler.js.map +1 -0
  103. package/src/cjs/utils/io/FileDrop.d.ts +98 -0
  104. package/src/cjs/utils/io/FileDrop.js +142 -0
  105. package/src/cjs/utils/io/FileDrop.js.map +1 -0
  106. package/src/esm/BezierPath.d.ts +32 -14
  107. package/src/esm/BezierPath.js +65 -24
  108. package/src/esm/BezierPath.js.map +1 -1
  109. package/src/esm/Bounds.d.ts +22 -1
  110. package/src/esm/Bounds.js +24 -1
  111. package/src/esm/Bounds.js.map +1 -1
  112. package/src/esm/Circle.d.ts +15 -13
  113. package/src/esm/Circle.js +16 -34
  114. package/src/esm/Circle.js.map +1 -1
  115. package/src/esm/CircleSector.d.ts +17 -16
  116. package/src/esm/CircleSector.js +12 -24
  117. package/src/esm/CircleSector.js.map +1 -1
  118. package/src/esm/CubicBezierCurve.d.ts +16 -15
  119. package/src/esm/CubicBezierCurve.js +57 -94
  120. package/src/esm/CubicBezierCurve.js.map +1 -1
  121. package/src/esm/KeyHandler.d.ts +10 -3
  122. package/src/esm/KeyHandler.js +28 -23
  123. package/src/esm/KeyHandler.js.map +1 -1
  124. package/src/esm/Line.d.ts +2 -15
  125. package/src/esm/Line.js +6 -31
  126. package/src/esm/Line.js.map +1 -1
  127. package/src/esm/MouseHandler.js +43 -53
  128. package/src/esm/MouseHandler.js.map +1 -1
  129. package/src/esm/PBImage.d.ts +15 -13
  130. package/src/esm/PBImage.js +11 -15
  131. package/src/esm/PBImage.js.map +1 -1
  132. package/src/esm/PBText.d.ts +13 -12
  133. package/src/esm/PBText.js +8 -12
  134. package/src/esm/PBText.js.map +1 -1
  135. package/src/esm/PlotBoilerplate.js +3 -2
  136. package/src/esm/PlotBoilerplate.js.map +1 -1
  137. package/src/esm/Polygon.d.ts +44 -14
  138. package/src/esm/Polygon.js +116 -66
  139. package/src/esm/Polygon.js.map +1 -1
  140. package/src/esm/Triangle.d.ts +15 -13
  141. package/src/esm/Triangle.js +23 -64
  142. package/src/esm/Triangle.js.map +1 -1
  143. package/src/esm/VEllipse.d.ts +14 -9
  144. package/src/esm/VEllipse.js +10 -18
  145. package/src/esm/VEllipse.js.map +1 -1
  146. package/src/esm/VEllipseSector.d.ts +15 -1
  147. package/src/esm/VEllipseSector.js +11 -1
  148. package/src/esm/VEllipseSector.js.map +1 -1
  149. package/src/esm/Vector.d.ts +3 -15
  150. package/src/esm/Vector.js +9 -49
  151. package/src/esm/Vector.js.map +1 -1
  152. package/src/esm/VertTuple.d.ts +15 -1
  153. package/src/esm/VertTuple.js +14 -19
  154. package/src/esm/VertTuple.js.map +1 -1
  155. package/src/esm/Vertex.d.ts +47 -13
  156. package/src/esm/Vertex.js +62 -22
  157. package/src/esm/Vertex.js.map +1 -1
  158. package/src/esm/VertexListeners.d.ts +12 -8
  159. package/src/esm/VertexListeners.js +18 -25
  160. package/src/esm/VertexListeners.js.map +1 -1
  161. package/src/esm/draw.d.ts +41 -2
  162. package/src/esm/draw.js +139 -3
  163. package/src/esm/draw.js.map +1 -1
  164. package/src/esm/drawgl.d.ts +38 -2
  165. package/src/esm/drawgl.js +41 -2
  166. package/src/esm/drawgl.js.map +1 -1
  167. package/src/esm/drawutilssvg.d.ts +66 -3
  168. package/src/esm/drawutilssvg.js +140 -15
  169. package/src/esm/drawutilssvg.js.map +1 -1
  170. package/src/esm/index.d.ts +0 -1
  171. package/src/esm/index.js +0 -1
  172. package/src/esm/index.js.map +1 -1
  173. package/src/esm/interfaces/DrawLib.d.ts +61 -26
  174. package/src/esm/interfaces/DrawLib.js +2 -0
  175. package/src/esm/interfaces/DrawLib.js.map +1 -1
  176. package/src/esm/interfaces/core.d.ts +0 -12
  177. package/src/esm/module.d.ts +1 -3
  178. package/src/esm/module.js +5 -4
  179. package/src/esm/module.js.map +1 -1
  180. package/src/esm/utils/datastructures/Girih.d.ts +5 -0
  181. package/src/esm/utils/datastructures/Girih.js +18 -14
  182. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  183. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +42 -25
  184. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  185. package/src/esm/utils/datastructures/GirihTile.js +2 -13
  186. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  187. package/src/esm/utils/findInVertexArray.d.ts +19 -0
  188. package/src/esm/utils/findInVertexArray.js +25 -0
  189. package/src/esm/utils/findInVertexArray.js.map +1 -0
  190. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +17 -1
  191. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +49 -32
  192. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  193. package/src/esm/utils/io/DndFileHandler.d.ts +63 -0
  194. package/src/esm/utils/io/DndFileHandler.js +106 -0
  195. package/src/esm/utils/io/DndFileHandler.js.map +1 -0
  196. package/src/esm/utils/io/FileDrop.d.ts +98 -0
  197. package/src/esm/utils/io/FileDrop.js +136 -0
  198. package/src/esm/utils/io/FileDrop.js.map +1 -0
  199. package/src/ts/BezierPath.ts +78 -22
  200. package/src/ts/Bounds.ts +25 -1
  201. package/src/ts/Circle.ts +187 -200
  202. package/src/ts/CircleSector.ts +141 -141
  203. package/src/ts/CubicBezierCurve.ts +738 -810
  204. package/src/ts/KeyHandler.ts +221 -212
  205. package/src/ts/Line.ts +48 -80
  206. package/src/ts/MouseHandler.ts +356 -368
  207. package/src/ts/PBImage.ts +67 -69
  208. package/src/ts/PBText.ts +16 -14
  209. package/src/ts/PlotBoilerplate.ts +4 -2
  210. package/src/ts/Polygon.ts +493 -451
  211. package/src/ts/Triangle.ts +444 -489
  212. package/src/ts/VEllipse.ts +18 -17
  213. package/src/ts/VEllipseSector.ts +20 -1
  214. package/src/ts/Vector.ts +124 -160
  215. package/src/ts/VertTuple.ts +333 -338
  216. package/src/ts/Vertex.ts +75 -21
  217. package/src/ts/VertexListeners.ts +248 -266
  218. package/src/ts/draw.ts +192 -3
  219. package/src/ts/drawgl.ts +44 -2
  220. package/src/ts/drawutilssvg.ts +181 -15
  221. package/src/ts/index.ts +0 -1
  222. package/src/ts/interfaces/DrawLib.ts +69 -26
  223. package/src/ts/interfaces/core.ts +0 -11
  224. package/src/ts/module.ts +2 -4
  225. package/src/ts/utils/datastructures/Girih.ts +204 -209
  226. package/src/ts/utils/datastructures/GirihPenroseRhombus.ts +170 -152
  227. package/src/ts/utils/datastructures/GirihTile.ts +394 -419
  228. package/src/ts/utils/findInVertexArray.ts +28 -0
  229. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +56 -34
  230. package/src/ts/utils/io/FileDrop.ts +178 -0
  231. package/src/ts/SVGBuilder.ts +0 -109
  232. package/src/ts/utils/algorithms/sh-tmp.ts~ +0 -59
@@ -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
- * @version 1.1.0
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
- * 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
- /**
53
- * The factory is used by the `clone` method.
54
- */
55
- private factory: (a:Vertex,b:Vertex)=>T;
56
-
57
-
58
- /**
59
- * Creates an instance.
60
- *
61
- * @constructor
62
- * @name VertTuple
63
- * @param {Vertex} a The tuple's first point.
64
- * @param {Vertex} b The tuple's second point.
65
- **/
66
- constructor(a:Vertex,b:Vertex,factory:(a:Vertex,b:Vertex)=>T) {
67
- this.uid = UIDGenerator.next();
68
- this.a = a;
69
- this.b = b;
70
- this.factory = factory;
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
- * Get the length of this line.
76
- *
77
- * @method length
78
- * @instance
79
- * @memberof VertTuple
80
- **/
81
- length():number {
82
- return Math.sqrt( Math.pow(this.b.x-this.a.x,2) + Math.pow(this.b.y-this.a.y,2) );
83
- };
84
-
85
-
86
- /**
87
- * Set the length of this vector to the given amount. This only works if this
88
- * vector is not a null vector.
89
- *
90
- * @method setLength
91
- * @param {number} length - The desired length.
92
- * @memberof VertTuple
93
- * @return {T} this (for chaining)
94
- **/
95
- setLength( length:number ):VertTuple<T> {
96
- return this.scale( length/this.length() );
97
- };
98
-
99
-
100
- /**
101
- * Substract the given vertex from this line's end points.
102
- *
103
- * @method sub
104
- * @param {XYCoords} amount The amount (x,y) to substract.
105
- * @return {VertTuple} this
106
- * @instance
107
- * @memberof VertTuple
108
- **/
109
- sub( amount:XYCoords ):VertTuple<T> {
110
- this.a.sub( amount );
111
- this.b.sub( amount );
112
- return this;
113
- };
114
-
115
-
116
- /**
117
- * Add the given vertex to this line's end points.
118
- *
119
- * @method add
120
- * @param {XYCoords} amount The amount (x,y) to add.
121
- * @return {Line} this
122
- * @instance
123
- * @memberof VertTuple
124
- **/
125
- add( amount:XYCoords ):VertTuple<T> {
126
- this.a.add( amount );
127
- this.b.add( amount );
128
- return this;
129
- };
130
-
131
-
132
- /**
133
- * Normalize this line (set to length 1).
134
- *
135
- * @method normalize
136
- * @return {VertTuple} this
137
- * @instance
138
- * @memberof VertTuple
139
- **/
140
- normalize():VertTuple<T> {
141
- this.b.set( this.a.x + (this.b.x-this.a.x)/this.length(),
142
- this.a.y + (this.b.y-this.a.y)/this.length() );
143
- return this;
144
- };
145
-
146
-
147
- /**
148
- * Scale this line by the given factor.
149
- *
150
- * @method scale
151
- * @param {number} factor The factor for scaling (1.0 means no scale).
152
- * @return {VertTuple} this
153
- * @instance
154
- * @memberof VertTuple
155
- **/
156
- scale( factor:number ):VertTuple<T> {
157
- this.b.set( this.a.x + (this.b.x-this.a.x)*factor,
158
- this.a.y + (this.b.y-this.a.y)*factor );
159
- return this;
160
- };
161
-
162
-
163
- /**
164
- * Move this line to a new location.
165
- *
166
- * @method moveTo
167
- * @param {Vertex} newA - The new desired location of 'a'. Vertex 'b' will be moved, too.
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
- * Get the closest point on this line to the specified point.
301
- *
302
- * @method getClosestPoint
303
- * @param {Vertex} p The point (vertex) to measre the distance to.
304
- * @return {Vertex} The point on the line that is closest to p.
305
- * @instance
306
- * @memberof VertTuple
307
- **/
308
- getClosestPoint( p:Vertex ):Vertex {
309
- var t : number = this.getClosestT(p);
310
- return this.vertAt(t);
311
- };
312
-
313
-
314
- /**
315
- * The the minimal distance between this line and the specified point.
316
- *
317
- * @method pointDistance
318
- * @param {Vertex} p The point (vertex) to measre the distance to.
319
- * @return {number} The absolute minimal distance.
320
- * @instance
321
- * @memberof VertTuple
322
- **/
323
- pointDistance( p:Vertex ):number {
324
- // Taken From:
325
- // https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
326
- return Math.sqrt( VertTuple.vtutils.dist2(p, this.vertAt(this.getClosestT(p))) );
327
- };
328
-
329
-
330
-
331
- /**
332
- * Create a deep clone of this instance.
333
- *
334
- * @method cloneLine
335
- * @return {T} A type safe clone if this instance.
336
- * @instance
337
- * @memberof VertTuple
338
- **/
339
- clone():T {
340
- return this.factory(this.a.clone(),this.b.clone());
341
- };
342
-
343
-
344
- /**
345
- * Create a string representation of this line.
346
- *
347
- * @method totring
348
- * @return {string} The string representing this line.
349
- * @instance
350
- * @memberof VertTuple
351
- **/
352
- toString():string {
353
- return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + " }";
354
- };
355
-
356
-
357
- /**
358
- * @private
359
- **/
360
- static vtutils = {
361
- dist2 : (v:XYCoords, w:XYCoords) => {
362
- return (v.x - w.x)*(v.x - w.x) + (v.y - w.y)*(v.y - w.y);
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
  }