plotboilerplate 1.15.0 → 1.17.1

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 (237) hide show
  1. package/README.md +1 -0
  2. package/changelog.md +65 -0
  3. package/dist/index.esm.js +760 -667
  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 +765 -571
  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 +33 -1
  16. package/src/cjs/Bounds.js +38 -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.d.ts +3 -1
  42. package/src/cjs/PlotBoilerplate.js +9 -2
  43. package/src/cjs/PlotBoilerplate.js.map +1 -1
  44. package/src/cjs/Polygon.d.ts +23 -14
  45. package/src/cjs/Polygon.js +22 -35
  46. package/src/cjs/Polygon.js.map +1 -1
  47. package/src/cjs/Triangle.d.ts +15 -13
  48. package/src/cjs/Triangle.js +23 -64
  49. package/src/cjs/Triangle.js.map +1 -1
  50. package/src/cjs/VEllipse.d.ts +14 -9
  51. package/src/cjs/VEllipse.js +10 -18
  52. package/src/cjs/VEllipse.js.map +1 -1
  53. package/src/cjs/VEllipseSector.d.ts +15 -1
  54. package/src/cjs/VEllipseSector.js +11 -1
  55. package/src/cjs/VEllipseSector.js.map +1 -1
  56. package/src/cjs/Vector.d.ts +3 -15
  57. package/src/cjs/Vector.js +9 -49
  58. package/src/cjs/Vector.js.map +1 -1
  59. package/src/cjs/VertTuple.d.ts +15 -1
  60. package/src/cjs/VertTuple.js +14 -19
  61. package/src/cjs/VertTuple.js.map +1 -1
  62. package/src/cjs/Vertex.d.ts +23 -13
  63. package/src/cjs/Vertex.js +24 -22
  64. package/src/cjs/Vertex.js.map +1 -1
  65. package/src/cjs/VertexListeners.d.ts +12 -8
  66. package/src/cjs/VertexListeners.js +18 -25
  67. package/src/cjs/VertexListeners.js.map +1 -1
  68. package/src/cjs/draw.d.ts +45 -3
  69. package/src/cjs/draw.js +149 -6
  70. package/src/cjs/draw.js.map +1 -1
  71. package/src/cjs/drawgl.d.ts +41 -3
  72. package/src/cjs/drawgl.js +45 -3
  73. package/src/cjs/drawgl.js.map +1 -1
  74. package/src/cjs/drawutilssvg.d.ts +69 -4
  75. package/src/cjs/drawutilssvg.js +147 -16
  76. package/src/cjs/drawutilssvg.js.map +1 -1
  77. package/src/cjs/index.d.ts +0 -1
  78. package/src/cjs/index.js +0 -1
  79. package/src/cjs/index.js.map +1 -1
  80. package/src/cjs/interfaces/DrawLib.d.ts +64 -27
  81. package/src/cjs/interfaces/DrawLib.js +3 -0
  82. package/src/cjs/interfaces/DrawLib.js.map +1 -1
  83. package/src/cjs/interfaces/core.d.ts +2 -12
  84. package/src/cjs/interfaces/core.js +1 -0
  85. package/src/cjs/interfaces/core.js.map +1 -1
  86. package/src/cjs/module.d.ts +1 -3
  87. package/src/cjs/module.js +2 -5
  88. package/src/cjs/module.js.map +1 -1
  89. package/src/cjs/utils/creategui.js +16 -2
  90. package/src/cjs/utils/datastructures/Color.d.ts +3 -1
  91. package/src/cjs/utils/datastructures/Color.js +17 -6
  92. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  93. package/src/cjs/utils/datastructures/Girih.d.ts +5 -0
  94. package/src/cjs/utils/datastructures/Girih.js +18 -14
  95. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  96. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +42 -25
  97. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  98. package/src/cjs/utils/datastructures/GirihTile.js +2 -13
  99. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  100. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +17 -1
  101. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +50 -32
  102. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  103. package/src/cjs/utils/io/DndFileHandler.d.ts +63 -0
  104. package/src/cjs/utils/io/DndFileHandler.js +112 -0
  105. package/src/cjs/utils/io/DndFileHandler.js.map +1 -0
  106. package/src/cjs/utils/io/FileDrop.d.ts +98 -0
  107. package/src/cjs/utils/io/FileDrop.js +142 -0
  108. package/src/cjs/utils/io/FileDrop.js.map +1 -0
  109. package/src/esm/BezierPath.d.ts +32 -14
  110. package/src/esm/BezierPath.js +65 -24
  111. package/src/esm/BezierPath.js.map +1 -1
  112. package/src/esm/Bounds.d.ts +33 -1
  113. package/src/esm/Bounds.js +38 -1
  114. package/src/esm/Bounds.js.map +1 -1
  115. package/src/esm/Circle.d.ts +15 -13
  116. package/src/esm/Circle.js +16 -34
  117. package/src/esm/Circle.js.map +1 -1
  118. package/src/esm/CircleSector.d.ts +17 -16
  119. package/src/esm/CircleSector.js +12 -24
  120. package/src/esm/CircleSector.js.map +1 -1
  121. package/src/esm/CubicBezierCurve.d.ts +16 -15
  122. package/src/esm/CubicBezierCurve.js +57 -94
  123. package/src/esm/CubicBezierCurve.js.map +1 -1
  124. package/src/esm/KeyHandler.d.ts +10 -3
  125. package/src/esm/KeyHandler.js +28 -23
  126. package/src/esm/KeyHandler.js.map +1 -1
  127. package/src/esm/Line.d.ts +2 -15
  128. package/src/esm/Line.js +6 -31
  129. package/src/esm/Line.js.map +1 -1
  130. package/src/esm/MouseHandler.js +43 -53
  131. package/src/esm/MouseHandler.js.map +1 -1
  132. package/src/esm/PBImage.d.ts +15 -13
  133. package/src/esm/PBImage.js +11 -15
  134. package/src/esm/PBImage.js.map +1 -1
  135. package/src/esm/PBText.d.ts +13 -12
  136. package/src/esm/PBText.js +8 -12
  137. package/src/esm/PBText.js.map +1 -1
  138. package/src/esm/PlotBoilerplate.d.ts +3 -1
  139. package/src/esm/PlotBoilerplate.js +9 -2
  140. package/src/esm/PlotBoilerplate.js.map +1 -1
  141. package/src/esm/Polygon.d.ts +23 -14
  142. package/src/esm/Polygon.js +22 -35
  143. package/src/esm/Polygon.js.map +1 -1
  144. package/src/esm/Triangle.d.ts +15 -13
  145. package/src/esm/Triangle.js +23 -64
  146. package/src/esm/Triangle.js.map +1 -1
  147. package/src/esm/VEllipse.d.ts +14 -9
  148. package/src/esm/VEllipse.js +10 -18
  149. package/src/esm/VEllipse.js.map +1 -1
  150. package/src/esm/VEllipseSector.d.ts +15 -1
  151. package/src/esm/VEllipseSector.js +11 -1
  152. package/src/esm/VEllipseSector.js.map +1 -1
  153. package/src/esm/Vector.d.ts +3 -15
  154. package/src/esm/Vector.js +9 -49
  155. package/src/esm/Vector.js.map +1 -1
  156. package/src/esm/VertTuple.d.ts +15 -1
  157. package/src/esm/VertTuple.js +14 -19
  158. package/src/esm/VertTuple.js.map +1 -1
  159. package/src/esm/Vertex.d.ts +23 -13
  160. package/src/esm/Vertex.js +24 -22
  161. package/src/esm/Vertex.js.map +1 -1
  162. package/src/esm/VertexListeners.d.ts +12 -8
  163. package/src/esm/VertexListeners.js +18 -25
  164. package/src/esm/VertexListeners.js.map +1 -1
  165. package/src/esm/draw.d.ts +45 -3
  166. package/src/esm/draw.js +147 -6
  167. package/src/esm/draw.js.map +1 -1
  168. package/src/esm/drawgl.d.ts +41 -3
  169. package/src/esm/drawgl.js +44 -3
  170. package/src/esm/drawgl.js.map +1 -1
  171. package/src/esm/drawutilssvg.d.ts +69 -4
  172. package/src/esm/drawutilssvg.js +146 -16
  173. package/src/esm/drawutilssvg.js.map +1 -1
  174. package/src/esm/index.d.ts +0 -1
  175. package/src/esm/index.js +0 -1
  176. package/src/esm/index.js.map +1 -1
  177. package/src/esm/interfaces/DrawLib.d.ts +64 -27
  178. package/src/esm/interfaces/DrawLib.js +3 -0
  179. package/src/esm/interfaces/DrawLib.js.map +1 -1
  180. package/src/esm/interfaces/core.d.ts +2 -12
  181. package/src/esm/interfaces/core.js +1 -0
  182. package/src/esm/interfaces/core.js.map +1 -1
  183. package/src/esm/module.d.ts +1 -3
  184. package/src/esm/module.js +5 -4
  185. package/src/esm/module.js.map +1 -1
  186. package/src/esm/utils/datastructures/Color.d.ts +3 -1
  187. package/src/esm/utils/datastructures/Color.js +17 -6
  188. package/src/esm/utils/datastructures/Color.js.map +1 -1
  189. package/src/esm/utils/datastructures/Girih.d.ts +5 -0
  190. package/src/esm/utils/datastructures/Girih.js +18 -14
  191. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  192. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +42 -25
  193. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  194. package/src/esm/utils/datastructures/GirihTile.js +2 -13
  195. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  196. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +17 -1
  197. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +49 -32
  198. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  199. package/src/esm/utils/io/DndFileHandler.d.ts +63 -0
  200. package/src/esm/utils/io/DndFileHandler.js +106 -0
  201. package/src/esm/utils/io/DndFileHandler.js.map +1 -0
  202. package/src/esm/utils/io/FileDrop.d.ts +98 -0
  203. package/src/esm/utils/io/FileDrop.js +136 -0
  204. package/src/esm/utils/io/FileDrop.js.map +1 -0
  205. package/src/ts/BezierPath.ts +78 -22
  206. package/src/ts/Bounds.ts +40 -1
  207. package/src/ts/Circle.ts +187 -200
  208. package/src/ts/CircleSector.ts +141 -141
  209. package/src/ts/CubicBezierCurve.ts +738 -810
  210. package/src/ts/KeyHandler.ts +221 -212
  211. package/src/ts/Line.ts +48 -80
  212. package/src/ts/MouseHandler.ts +356 -368
  213. package/src/ts/PBImage.ts +67 -69
  214. package/src/ts/PBText.ts +16 -14
  215. package/src/ts/PlotBoilerplate.ts +9 -2
  216. package/src/ts/Polygon.ts +34 -34
  217. package/src/ts/Triangle.ts +444 -489
  218. package/src/ts/VEllipse.ts +18 -17
  219. package/src/ts/VEllipseSector.ts +20 -1
  220. package/src/ts/Vector.ts +124 -160
  221. package/src/ts/VertTuple.ts +333 -338
  222. package/src/ts/Vertex.ts +35 -21
  223. package/src/ts/VertexListeners.ts +248 -266
  224. package/src/ts/draw.ts +201 -6
  225. package/src/ts/drawgl.ts +47 -3
  226. package/src/ts/drawutilssvg.ts +187 -16
  227. package/src/ts/index.ts +0 -1
  228. package/src/ts/interfaces/DrawLib.ts +72 -27
  229. package/src/ts/interfaces/core.ts +3 -13
  230. package/src/ts/module.ts +2 -4
  231. package/src/ts/utils/datastructures/Color.ts +17 -6
  232. package/src/ts/utils/datastructures/Girih.ts +204 -209
  233. package/src/ts/utils/datastructures/GirihPenroseRhombus.ts +170 -152
  234. package/src/ts/utils/datastructures/GirihTile.ts +394 -419
  235. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +56 -34
  236. package/src/ts/utils/io/FileDrop.ts +178 -0
  237. package/src/ts/SVGBuilder.ts +0 -109
@@ -445,7 +445,10 @@ class AlloyFinger {
445
445
  * @modified 2020-07-24 Added the getClosestT(Vertex) function.
446
446
  * @modified 2020-12-29 Constructor is now private (no explicit use intended).
447
447
  * @modified 2021-05-25 Added BezierPath.fromReducedList( Array<number> ).
448
- * @version 2.3.1
448
+ * @modified 2022-01-31 Added `BezierPath.getEvenDistributionVertices(number)`.
449
+ * @modified 2022-02-02 Added the `destroy` method.
450
+ * @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
451
+ * @version 2.5.0
449
452
  *
450
453
  * @file BezierPath
451
454
  * @public
@@ -1342,6 +1345,59 @@ var BezierPath = /** @class */ (function () {
1342
1345
  }
1343
1346
  return new Bounds_1.Bounds(min, max);
1344
1347
  };
1348
+ /**
1349
+ * Get n 'equally' distributed vertices along this Bézier path.
1350
+ *
1351
+ * As the changing curvature of the B slines makes prediction of distances difficult, the
1352
+ * returned vertices' distances are only relatively equal:
1353
+ * - the distance grows where curvature is large.
1354
+ * - the distance shrinks where curvature is small.
1355
+ *
1356
+ * Only the distance mean of all consecutive is 1/n-th of the total arc length.
1357
+ *
1358
+ * Usually this approximation is good enough for most use cases.
1359
+ *
1360
+ * @param {number} pointCount - (must be at least 2) The number of desired points (start and end point included).
1361
+ * @return {Array<Vertex>}
1362
+ */
1363
+ BezierPath.prototype.getEvenDistributionVertices = function (pointCount) {
1364
+ if (pointCount < 2) {
1365
+ throw new Error("pointCount must be larger than one; is " + pointCount + ".");
1366
+ }
1367
+ var result = [];
1368
+ if (this.bezierCurves.length === 0) {
1369
+ return result;
1370
+ }
1371
+ // Fetch and add the start point from the source polygon
1372
+ var polygonPoint = new Vertex_1.Vertex(this.bezierCurves[0].startPoint);
1373
+ result.push(polygonPoint);
1374
+ // if (this.bezierCurves.length === 1) {
1375
+ // return result;
1376
+ // }
1377
+ var perimeter = this.totalArcLength;
1378
+ var stepSize = perimeter / (pointCount - 1);
1379
+ var n = this.bezierCurves.length;
1380
+ var curveIndex = 0;
1381
+ var segmentLength = this.bezierCurves[0].arcLength;
1382
+ var curSegmentU = stepSize;
1383
+ var i = 1;
1384
+ while (i < pointCount && curveIndex < n) {
1385
+ // Check if next eq point is inside this segment
1386
+ if (curSegmentU < segmentLength) {
1387
+ var newPoint = this.bezierCurves[curveIndex].getPoint(curSegmentU);
1388
+ result.push(newPoint);
1389
+ curSegmentU += stepSize;
1390
+ i++;
1391
+ }
1392
+ else {
1393
+ curveIndex++;
1394
+ curSegmentU = curSegmentU - segmentLength;
1395
+ segmentLength = curveIndex < n ? this.bezierCurves[curveIndex].arcLength : 0;
1396
+ }
1397
+ }
1398
+ result.push(new Vertex_1.Vertex(this.bezierCurves[n - 1].endPoint));
1399
+ return result;
1400
+ };
1345
1401
  /**
1346
1402
  * Clone this BezierPath (deep clone).
1347
1403
  *
@@ -1388,30 +1444,15 @@ var BezierPath = /** @class */ (function () {
1388
1444
  return true;
1389
1445
  };
1390
1446
  /**
1391
- * Create a <pre>&lt;path&gt;</pre> SVG representation of this bézier curve.
1392
- *
1393
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
1394
- * @method toSVGString
1395
- * @param {object=} [options={}] - Like options.className
1396
- * @param {string=} [options.className] - The classname to use for the SVG item.
1397
- * @instance
1398
- * @memberof BezierPath
1399
- * @return {string} The SVG string.
1400
- **/
1401
- BezierPath.prototype.toSVGString = function (options) {
1402
- options = options || {};
1403
- var buffer = [];
1404
- buffer.push("<path");
1405
- if (options.className)
1406
- buffer.push(' class="' + options.className + '"');
1407
- buffer.push(' d="');
1408
- for (var c = 0; c < this.bezierCurves.length; c++) {
1409
- if (c > 0)
1410
- buffer.push(" ");
1411
- buffer.push(this.bezierCurves[c].toSVGPathData());
1447
+ * This function should invalidate any installed listeners and invalidate this object.
1448
+ * After calling this function the object might not hold valid data any more and
1449
+ * should not be used.
1450
+ */
1451
+ BezierPath.prototype.destroy = function () {
1452
+ for (var i = 0; i < this.bezierCurves.length; i++) {
1453
+ this.bezierCurves[i].destroy();
1412
1454
  }
1413
- buffer.push('" />');
1414
- return buffer.join("");
1455
+ this.isDestroyed = true;
1415
1456
  };
1416
1457
  /**
1417
1458
  * Create a JSON string representation of this bézier curve.
@@ -1640,7 +1681,8 @@ exports.BezierPath = BezierPath;
1640
1681
  * @modified 2020-11-19 Set min, max, width and height to private.
1641
1682
  * @modified 2021-02-02 Added the `toPolygon` method.
1642
1683
  * @modified 2021-06-21 (mid-summer) Added `getCenter` method.
1643
- * @version 1.3.0
1684
+ * @modified 2022-02-01 Added the `toString` function.
1685
+ * @version 1.4.0
1644
1686
  **/
1645
1687
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1646
1688
  exports.Bounds = void 0;
@@ -1679,9 +1721,45 @@ var Bounds = /** @class */ (function () {
1679
1721
  Bounds.prototype.toPolygon = function () {
1680
1722
  return new Polygon_1.Polygon([new Vertex_1.Vertex(this.min), new Vertex_1.Vertex(this.max.x, this.min.y), new Vertex_1.Vertex(this.max), new Vertex_1.Vertex(this.min.x, this.max.y)], false);
1681
1723
  };
1724
+ /**
1725
+ * Get the center of this boinding box.
1726
+ *
1727
+ * @method getCenter
1728
+ * @instance
1729
+ * @memberof Bounds
1730
+ * @returns {Vertex} The center of these bounds.
1731
+ */
1682
1732
  Bounds.prototype.getCenter = function () {
1683
1733
  return new Vertex_1.Vertex(this.min.x + (this.max.x - this.min.x) / 2.0, this.min.y + (this.max.y - this.min.y) / 2);
1684
1734
  };
1735
+ /**
1736
+ * Convert these bounds to a human readable form.
1737
+ *
1738
+ * Note: the returned format might change in the future, so please do not
1739
+ * rely on the returned string format.
1740
+ *
1741
+ * @method toString
1742
+ * @instance
1743
+ * @memberof Bounds
1744
+ * @returns {string} Get these bounds in a human readable form.
1745
+ */
1746
+ Bounds.prototype.toString = function () {
1747
+ return "{ min: " + this.min.toString() + ", max : " + this.max.toString() + ", width: " + this.width + ", height : " + this.height + " }";
1748
+ };
1749
+ /**
1750
+ * Clone this bounds object (create a deep clone).
1751
+ *
1752
+ * Note: the returned format might change in the future, so please do not
1753
+ * rely on the returned string format.
1754
+ *
1755
+ * @method clone
1756
+ * @instance
1757
+ * @memberof Bounds
1758
+ * @returns {string} Creates a deep clone of this bounds object. The returned object's `min` and `max` instances are `Vertex` instances.
1759
+ */
1760
+ // clone() {
1761
+ // return new Bounds(new Vertex(this.min.x, this.min.y), new Vertex(this.max.x, this.max.y));
1762
+ // }
1685
1763
  /**
1686
1764
  * Compute the minimal bounding box for a given set of vertices.
1687
1765
  *
@@ -1730,7 +1808,9 @@ exports.Bounds = Bounds;
1730
1808
  * @modified 2020-09-07 Changed the vertAt function by switching sin and cos! The old version did not return the correct vertex (by angle) accoring to the assumed circle math.
1731
1809
  * @modified 2020-10-16 Added the containsCircle(...) function.
1732
1810
  * @modified 2021-01-20 Added UID.
1733
- * @version 1.2.0
1811
+ * @modified 2022-02-02 Added the `destroy` method.
1812
+ * @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
1813
+ * @version 1.3.0
1734
1814
  **/
1735
1815
  Object.defineProperty(exports, "__esModule", ({ value: true }));
1736
1816
  exports.Circle = void 0;
@@ -1767,7 +1847,6 @@ var Circle = /** @class */ (function () {
1767
1847
  this.center = center;
1768
1848
  this.radius = radius;
1769
1849
  }
1770
- ;
1771
1850
  /**
1772
1851
  * Check if the given circle is fully contained inside this circle.
1773
1852
  *
@@ -1780,7 +1859,6 @@ var Circle = /** @class */ (function () {
1780
1859
  Circle.prototype.containsCircle = function (circle) {
1781
1860
  return this.center.distance(circle.center) + circle.radius < this.radius;
1782
1861
  };
1783
- ;
1784
1862
  /**
1785
1863
  * Calculate the distance from this circle to the given line.
1786
1864
  *
@@ -1799,7 +1877,6 @@ var Circle = /** @class */ (function () {
1799
1877
  var closestPointOnLine = line.getClosestPoint(this.center);
1800
1878
  return closestPointOnLine.distance(this.center) - this.radius;
1801
1879
  };
1802
- ;
1803
1880
  /**
1804
1881
  * Get the vertex on the this circle for the given angle.
1805
1882
  *
@@ -1813,7 +1890,6 @@ var Circle = /** @class */ (function () {
1813
1890
  // Find the point on the circle respective the angle. Then move relative to center.
1814
1891
  return Circle.circleUtils.vertAt(angle, this.radius).add(this.center);
1815
1892
  };
1816
- ;
1817
1893
  /**
1818
1894
  * Get a tangent line of this circle for a given angle.
1819
1895
  *
@@ -1830,7 +1906,6 @@ var Circle = /** @class */ (function () {
1830
1906
  // Construct the perpendicular of the line in point a. Then move relative to center.
1831
1907
  return new Vector_1.Vector(pointA, new Vertex_1.Vertex(0, 0)).add(this.center).perp();
1832
1908
  };
1833
- ;
1834
1909
  /**
1835
1910
  * Calculate the intersection points (if exists) with the given circle.
1836
1911
  *
@@ -1870,47 +1945,32 @@ var Circle = /** @class */ (function () {
1870
1945
  // x4 = P2.x - h*(P1.y - P0.y)/d;
1871
1946
  // y4 = P2.y + h*(P1.x - P0.x)/d;
1872
1947
  // return pair<Point, Point>(Point(x3, y3), Point(x4, y4));
1873
- // }
1948
+ // }
1874
1949
  var p0 = this.center;
1875
1950
  var p1 = circle.center;
1876
1951
  var d = p0.distance(p1);
1877
1952
  var a = (this.radius * this.radius - circle.radius * circle.radius + d * d) / (2 * d);
1878
1953
  var h = Math.sqrt(this.radius * this.radius - a * a);
1879
1954
  var p2 = p1.clone().scale(a / d, p0);
1880
- var x3 = p2.x + h * (p1.y - p0.y) / d;
1881
- var y3 = p2.y - h * (p1.x - p0.x) / d;
1882
- var x4 = p2.x - h * (p1.y - p0.y) / d;
1883
- var y4 = p2.y + h * (p1.x - p0.x) / d;
1955
+ var x3 = p2.x + (h * (p1.y - p0.y)) / d;
1956
+ var y3 = p2.y - (h * (p1.x - p0.x)) / d;
1957
+ var x4 = p2.x - (h * (p1.y - p0.y)) / d;
1958
+ var y4 = p2.y + (h * (p1.x - p0.x)) / d;
1884
1959
  return new Line_1.Line(new Vertex_1.Vertex(x3, y3), new Vertex_1.Vertex(x4, y4));
1885
1960
  };
1886
- ;
1887
1961
  /**
1888
- * Create an SVG representation of this circle.
1889
- *
1890
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
1891
- * @method toSVGString
1892
- * @param {object=} options - An optional set of options, like 'className'.
1893
- * @return {string} A string representing the SVG code for this vertex.
1894
- * @instance
1895
- * @memberof Circle
1896
- */
1897
- Circle.prototype.toSVGString = function (options) {
1898
- options = options || {};
1899
- var buffer = [];
1900
- buffer.push('<circle');
1901
- if (options.className)
1902
- buffer.push(' class="' + options.className + '"');
1903
- buffer.push(' cx="' + this.center.x + '"');
1904
- buffer.push(' cy="' + this.center.y + '"');
1905
- buffer.push(' r="' + this.radius + '"');
1906
- buffer.push(' />');
1907
- return buffer.join('');
1962
+ * This function should invalidate any installed listeners and invalidate this object.
1963
+ * After calling this function the object might not hold valid data any more and
1964
+ * should not be used.
1965
+ */
1966
+ Circle.prototype.destroy = function () {
1967
+ this.center.destroy();
1968
+ this.isDestroyed = true;
1908
1969
  };
1909
- ;
1910
1970
  Circle.circleUtils = {
1911
1971
  vertAt: function (angle, radius) {
1912
1972
  /* return new Vertex( Math.sin(angle) * radius,
1913
- Math.cos(angle) * radius ); */
1973
+ Math.cos(angle) * radius ); */
1914
1974
  return new Vertex_1.Vertex(Math.cos(angle) * radius, Math.sin(angle) * radius);
1915
1975
  }
1916
1976
  };
@@ -1964,27 +2024,15 @@ var CircleSector = /** @class */ (function () {
1964
2024
  this.startAngle = startAngle;
1965
2025
  this.endAngle = endAngle;
1966
2026
  }
1967
- ;
1968
2027
  /**
1969
- * Create an SVG representation of this circle.
1970
- *
1971
- * @method toSVGString
1972
- * @param {object=} options - An optional set of options, like 'className'.
1973
- * @return {string} A string representing the SVG code for this vertex.
1974
- * @instance
1975
- * @memberof Circle
1976
- */
1977
- CircleSector.prototype.toSVGString = function (options) {
1978
- options = options || {};
1979
- var buffer = [];
1980
- buffer.push('<path ');
1981
- if (options.className)
1982
- buffer.push(' class="' + options.className + '"');
1983
- var data = CircleSector.circleSectorUtils.describeSVGArc(this.circle.center.x, this.circle.center.y, this.circle.radius, this.startAngle, this.endAngle);
1984
- buffer.push(' d="' + data.join(" ") + '" />');
1985
- return buffer.join('');
2028
+ * This function should invalidate any installed listeners and invalidate this object.
2029
+ * After calling this function the object might not hold valid data any more and
2030
+ * should not be used.
2031
+ */
2032
+ CircleSector.prototype.destroy = function () {
2033
+ this.circle.destroy();
2034
+ this.isDestroyed = true;
1986
2035
  };
1987
- ;
1988
2036
  CircleSector.circleSectorUtils = {
1989
2037
  /**
1990
2038
  * Helper function to convert polar circle coordinates to cartesian coordinates.
@@ -1992,11 +2040,11 @@ var CircleSector = /** @class */ (function () {
1992
2040
  * TODO: generalize for ellipses (two radii).
1993
2041
  *
1994
2042
  * @param {number} angle - The angle in radians.
1995
- */
2043
+ */
1996
2044
  polarToCartesian: function (centerX, centerY, radius, angle) {
1997
2045
  return {
1998
- x: centerX + (radius * Math.cos(angle)),
1999
- y: centerY + (radius * Math.sin(angle))
2046
+ x: centerX + radius * Math.cos(angle),
2047
+ y: centerY + radius * Math.sin(angle)
2000
2048
  };
2001
2049
  },
2002
2050
  /**
@@ -2009,7 +2057,7 @@ var CircleSector = /** @class */ (function () {
2009
2057
  * @return [ 'A', radiusx, radiusy, rotation=0, largeArcFlag=1|0, sweepFlag=0, endx, endy ]
2010
2058
  */
2011
2059
  describeSVGArc: function (x, y, radius, startAngle, endAngle, options) {
2012
- if (typeof options === 'undefined')
2060
+ if (typeof options === "undefined")
2013
2061
  options = { moveToStart: true };
2014
2062
  var end = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, endAngle);
2015
2063
  var start = CircleSector.circleSectorUtils.polarToCartesian(x, y, radius, startAngle);
@@ -2034,7 +2082,7 @@ var CircleSector = /** @class */ (function () {
2034
2082
  }
2035
2083
  var pathData = [];
2036
2084
  if (options.moveToStart) {
2037
- pathData.push('M', start.x, start.y);
2085
+ pathData.push("M", start.x, start.y);
2038
2086
  }
2039
2087
  pathData.push("A", radius, radius, 0, largeArcFlag, sweepFlag, end.x, end.y);
2040
2088
  return pathData;
@@ -2071,7 +2119,9 @@ exports.CircleSector = CircleSector;
2071
2119
  * @modified 2020-07-14 Changed the moveCurvePoint(...,Vertex) to moveCurvePoint(...,XYCoords), which is more generic.
2072
2120
  * @modified 2020-07-24 Added the getClosestT function and the helper function locateIntervalByDistance(...).
2073
2121
  * @modified 2021-01-20 Added UID.
2074
- * @version 2.5.0
2122
+ * @modified 2022-02-02 Added the `destroy` method.
2123
+ * @modified 2022-02-02 Cleared the `toSVGPathData` function (deprecated). Use `drawutilssvg` instead.
2124
+ * @version 2.6.0
2075
2125
  *
2076
2126
  * @file CubicBezierCurve
2077
2127
  * @public
@@ -2126,7 +2176,6 @@ var CubicBezierCurve = /** @class */ (function () {
2126
2176
  this.arcLength = null;
2127
2177
  this.updateArcLengths();
2128
2178
  }
2129
- ;
2130
2179
  /**
2131
2180
  * Move the given curve point (the start point, end point or one of the two
2132
2181
  * control points).
@@ -2163,7 +2212,6 @@ var CubicBezierCurve = /** @class */ (function () {
2163
2212
  if (updateArcLengths)
2164
2213
  this.updateArcLengths();
2165
2214
  };
2166
- ;
2167
2215
  /**
2168
2216
  * Translate the whole curve by the given {x,y} amount: moves all four points.
2169
2217
  *
@@ -2180,7 +2228,6 @@ var CubicBezierCurve = /** @class */ (function () {
2180
2228
  this.endPoint.add(amount);
2181
2229
  return this;
2182
2230
  };
2183
- ;
2184
2231
  /**
2185
2232
  * Reverse this curve, means swapping start- and end-point and swapping
2186
2233
  * start-control- and end-control-point.
@@ -2199,7 +2246,6 @@ var CubicBezierCurve = /** @class */ (function () {
2199
2246
  this.endControlPoint = tmp;
2200
2247
  return this;
2201
2248
  };
2202
- ;
2203
2249
  /**
2204
2250
  * Get the total curve length.<br>
2205
2251
  * <br>
@@ -2218,7 +2264,6 @@ var CubicBezierCurve = /** @class */ (function () {
2218
2264
  CubicBezierCurve.prototype.getLength = function () {
2219
2265
  return this.arcLength;
2220
2266
  };
2221
- ;
2222
2267
  /**
2223
2268
  * Uptate the internal arc segment buffer and their lengths.<br>
2224
2269
  * <br>
@@ -2256,7 +2301,6 @@ var CubicBezierCurve = /** @class */ (function () {
2256
2301
  }
2257
2302
  this.arcLength = newLength;
2258
2303
  };
2259
- ;
2260
2304
  /**
2261
2305
  * Get a 't' (relative position on curve) with the closest distance to point 'p'.
2262
2306
  *
@@ -2279,7 +2323,6 @@ var CubicBezierCurve = /** @class */ (function () {
2279
2323
  } while (iteration < 4 && this.getPointAt(result.tPrev).distance(this.getPointAt(result.tNext)) > desiredEpsilon);
2280
2324
  return result.t;
2281
2325
  };
2282
- ;
2283
2326
  /**
2284
2327
  * This helper function locates the 't' on a fixed step interval with the minimal distance
2285
2328
  * between the curve (at 't') and the given point.
@@ -2308,12 +2351,12 @@ var CubicBezierCurve = /** @class */ (function () {
2308
2351
  minDist = dist;
2309
2352
  }
2310
2353
  }
2311
- return { t: tStart + tDiff * (minIndex / stepCount),
2354
+ return {
2355
+ t: tStart + tDiff * (minIndex / stepCount),
2312
2356
  tPrev: tStart + tDiff * (Math.max(0, minIndex - 1) / stepCount),
2313
2357
  tNext: tStart + tDiff * (Math.min(stepCount, minIndex + 1) / stepCount)
2314
2358
  };
2315
2359
  };
2316
- ;
2317
2360
  /**
2318
2361
  * Get the bounds of this bezier curve.
2319
2362
  *
@@ -2335,7 +2378,6 @@ var CubicBezierCurve = /** @class */ (function () {
2335
2378
  }
2336
2379
  return new Bounds_1.Bounds(min, max);
2337
2380
  };
2338
- ;
2339
2381
  /**
2340
2382
  * Get the start point of the curve.<br>
2341
2383
  * <br>
@@ -2349,7 +2391,6 @@ var CubicBezierCurve = /** @class */ (function () {
2349
2391
  CubicBezierCurve.prototype.getStartPoint = function () {
2350
2392
  return this.startPoint;
2351
2393
  };
2352
- ;
2353
2394
  /**
2354
2395
  * Get the end point of the curve.<br>
2355
2396
  * <br>
@@ -2363,7 +2404,6 @@ var CubicBezierCurve = /** @class */ (function () {
2363
2404
  CubicBezierCurve.prototype.getEndPoint = function () {
2364
2405
  return this.endPoint;
2365
2406
  };
2366
- ;
2367
2407
  /**
2368
2408
  * Get the start control point of the curve.<br>
2369
2409
  * <br>
@@ -2377,7 +2417,6 @@ var CubicBezierCurve = /** @class */ (function () {
2377
2417
  CubicBezierCurve.prototype.getStartControlPoint = function () {
2378
2418
  return this.startControlPoint;
2379
2419
  };
2380
- ;
2381
2420
  /**
2382
2421
  * Get the end control point of the curve.<br>
2383
2422
  * <br>
@@ -2391,7 +2430,6 @@ var CubicBezierCurve = /** @class */ (function () {
2391
2430
  CubicBezierCurve.prototype.getEndControlPoint = function () {
2392
2431
  return this.endControlPoint;
2393
2432
  };
2394
- ;
2395
2433
  /**
2396
2434
  * Get one of the four curve points specified by the passt point ID.
2397
2435
  *
@@ -2412,7 +2450,6 @@ var CubicBezierCurve = /** @class */ (function () {
2412
2450
  return this.endControlPoint;
2413
2451
  throw new Error("Invalid point ID '" + id + "'.");
2414
2452
  };
2415
- ;
2416
2453
  /**
2417
2454
  * Get the curve point at a given position t, where t is in [0,1].<br>
2418
2455
  * <br>
@@ -2427,13 +2464,16 @@ var CubicBezierCurve = /** @class */ (function () {
2427
2464
  **/
2428
2465
  CubicBezierCurve.prototype.getPointAt = function (t) {
2429
2466
  // Perform some powerful math magic
2430
- var x = this.startPoint.x * Math.pow(1.0 - t, 3) + this.startControlPoint.x * 3 * t * Math.pow(1.0 - t, 2)
2431
- + this.endControlPoint.x * 3 * Math.pow(t, 2) * (1.0 - t) + this.endPoint.x * Math.pow(t, 3);
2432
- var y = this.startPoint.y * Math.pow(1.0 - t, 3) + this.startControlPoint.y * 3 * t * Math.pow(1.0 - t, 2)
2433
- + this.endControlPoint.y * 3 * Math.pow(t, 2) * (1.0 - t) + this.endPoint.y * Math.pow(t, 3);
2467
+ var x = this.startPoint.x * Math.pow(1.0 - t, 3) +
2468
+ this.startControlPoint.x * 3 * t * Math.pow(1.0 - t, 2) +
2469
+ this.endControlPoint.x * 3 * Math.pow(t, 2) * (1.0 - t) +
2470
+ this.endPoint.x * Math.pow(t, 3);
2471
+ var y = this.startPoint.y * Math.pow(1.0 - t, 3) +
2472
+ this.startControlPoint.y * 3 * t * Math.pow(1.0 - t, 2) +
2473
+ this.endControlPoint.y * 3 * Math.pow(t, 2) * (1.0 - t) +
2474
+ this.endPoint.y * Math.pow(t, 3);
2434
2475
  return new Vertex_1.Vertex(x, y);
2435
2476
  };
2436
- ;
2437
2477
  /**
2438
2478
  * Get the curve point at a given position u, where u is in [0,arcLength].<br>
2439
2479
  * <br>
@@ -2449,7 +2489,6 @@ var CubicBezierCurve = /** @class */ (function () {
2449
2489
  CubicBezierCurve.prototype.getPoint = function (u) {
2450
2490
  return this.getPointAt(u / this.arcLength);
2451
2491
  };
2452
- ;
2453
2492
  /**
2454
2493
  * Get the curve tangent vector at a given absolute curve position t in [0,1].<br>
2455
2494
  * <br>
@@ -2470,18 +2509,11 @@ var CubicBezierCurve = /** @class */ (function () {
2470
2509
  var t2 = t * t;
2471
2510
  // (1 - t)^2 = (1-t)*(1-t) = 1 - t - t + t^2 = 1 - 2*t + t^2
2472
2511
  var nt2 = 1 - 2 * t + t2;
2473
- var tX = -3 * a.x * nt2 +
2474
- b.x * (3 * nt2 - 6 * (t - t2)) +
2475
- c.x * (6 * (t - t2) - 3 * t2) +
2476
- 3 * d.x * t2;
2477
- var tY = -3 * a.y * nt2 +
2478
- b.y * (3 * nt2 - 6 * (t - t2)) +
2479
- c.y * (6 * (t - t2) - 3 * t2) +
2480
- 3 * d.y * t2;
2512
+ var tX = -3 * a.x * nt2 + b.x * (3 * nt2 - 6 * (t - t2)) + c.x * (6 * (t - t2) - 3 * t2) + 3 * d.x * t2;
2513
+ var tY = -3 * a.y * nt2 + b.y * (3 * nt2 - 6 * (t - t2)) + c.y * (6 * (t - t2) - 3 * t2) + 3 * d.y * t2;
2481
2514
  // Note: my implementation does NOT normalize tangent vectors!
2482
2515
  return new Vertex_1.Vertex(tX, tY);
2483
2516
  };
2484
- ;
2485
2517
  /**
2486
2518
  * Get a sub curve at the given start end end offsets (values between 0.0 and 1.0).
2487
2519
  *
@@ -2507,7 +2539,6 @@ var CubicBezierCurve = /** @class */ (function () {
2507
2539
  // pb.draw.cubicBezier( startVec.a, endVec.a, startVec.b, endVec.b, '#8800ff', 2 );
2508
2540
  return new CubicBezierCurve(startVec.a, endVec.a, startVec.b, endVec.b);
2509
2541
  };
2510
- ;
2511
2542
  /**
2512
2543
  * Convert a relative curve position u to the absolute curve position t.
2513
2544
  *
@@ -2518,9 +2549,8 @@ var CubicBezierCurve = /** @class */ (function () {
2518
2549
  * @return {number}
2519
2550
  **/
2520
2551
  CubicBezierCurve.prototype.convertU2T = function (u) {
2521
- return Math.max(0.0, Math.min(1.0, (u / this.arcLength)));
2552
+ return Math.max(0.0, Math.min(1.0, u / this.arcLength));
2522
2553
  };
2523
- ;
2524
2554
  /**
2525
2555
  * Get the curve tangent vector at a given relative position u in [0,arcLength].<br>
2526
2556
  * <br>
@@ -2535,7 +2565,6 @@ var CubicBezierCurve = /** @class */ (function () {
2535
2565
  CubicBezierCurve.prototype.getTangent = function (u) {
2536
2566
  return this.getTangentAt(this.convertU2T(u));
2537
2567
  };
2538
- ;
2539
2568
  /**
2540
2569
  * Get the curve perpendicular at a given relative position u in [0,arcLength] as a vector.<br>
2541
2570
  * <br>
@@ -2550,7 +2579,6 @@ var CubicBezierCurve = /** @class */ (function () {
2550
2579
  CubicBezierCurve.prototype.getPerpendicular = function (u) {
2551
2580
  return this.getPerpendicularAt(this.convertU2T(u));
2552
2581
  };
2553
- ;
2554
2582
  /**
2555
2583
  * Get the curve perpendicular at a given absolute position t in [0,1] as a vector.<br>
2556
2584
  * <br>
@@ -2566,7 +2594,6 @@ var CubicBezierCurve = /** @class */ (function () {
2566
2594
  var tangentVector = this.getTangentAt(t);
2567
2595
  return new Vertex_1.Vertex(tangentVector.y, -tangentVector.x);
2568
2596
  };
2569
- ;
2570
2597
  /**
2571
2598
  * Clone this Bézier curve (deep clone).
2572
2599
  *
@@ -2578,7 +2605,6 @@ var CubicBezierCurve = /** @class */ (function () {
2578
2605
  CubicBezierCurve.prototype.clone = function () {
2579
2606
  return new CubicBezierCurve(this.getStartPoint().clone(), this.getEndPoint().clone(), this.getStartControlPoint().clone(), this.getEndControlPoint().clone());
2580
2607
  };
2581
- ;
2582
2608
  /**
2583
2609
  * Check if this and the specified curve are equal.<br>
2584
2610
  * <br>
@@ -2597,17 +2623,25 @@ var CubicBezierCurve = /** @class */ (function () {
2597
2623
  // Let's see if this restricted version works out.
2598
2624
  if (!curve)
2599
2625
  return false;
2600
- if (!curve.startPoint ||
2601
- !curve.endPoint ||
2602
- !curve.startControlPoint ||
2603
- !curve.endControlPoint)
2626
+ if (!curve.startPoint || !curve.endPoint || !curve.startControlPoint || !curve.endControlPoint)
2604
2627
  return false;
2605
- return this.startPoint.equals(curve.startPoint)
2606
- && this.endPoint.equals(curve.endPoint)
2607
- && this.startControlPoint.equals(curve.startControlPoint)
2608
- && this.endControlPoint.equals(curve.endControlPoint);
2628
+ return (this.startPoint.equals(curve.startPoint) &&
2629
+ this.endPoint.equals(curve.endPoint) &&
2630
+ this.startControlPoint.equals(curve.startControlPoint) &&
2631
+ this.endControlPoint.equals(curve.endControlPoint));
2632
+ };
2633
+ /**
2634
+ * This function should invalidate any installed listeners and invalidate this object.
2635
+ * After calling this function the object might not hold valid data any more and
2636
+ * should not be used.
2637
+ */
2638
+ CubicBezierCurve.prototype.destroy = function () {
2639
+ this.startPoint.destroy();
2640
+ this.endPoint.destroy();
2641
+ this.startControlPoint.destroy();
2642
+ this.endControlPoint.destroy();
2643
+ this.isDestroyed = true;
2609
2644
  };
2610
- ;
2611
2645
  /**
2612
2646
  * Quick check for class instance.
2613
2647
  * Is there a better way?
@@ -2633,41 +2667,6 @@ var CubicBezierCurve = /** @class */ (function () {
2633
2667
  */
2634
2668
  return obj instanceof CubicBezierCurve;
2635
2669
  };
2636
- ;
2637
- /**
2638
- * Create an SVG path data representation of this bézier curve.
2639
- *
2640
- * Path data string format is:<br>
2641
- * <pre>'M x0 y1 C dx0 dy1 dx1 dy1 x1 x2'</pre><br>
2642
- * or in other words<br>
2643
- * <pre>'M startoint.x startPoint.y C startControlPoint.x startControlPoint.y endControlPoint.x endControlPoint.y endPoint.x endPoint.y'</pre>
2644
- *
2645
- * @method toSVGPathData
2646
- * @instance
2647
- * @memberof CubicBezierCurve
2648
- * @return {string} The SVG path data string.
2649
- **/
2650
- CubicBezierCurve.prototype.toSVGPathData = function () {
2651
- var buffer = [];
2652
- buffer.push('M ');
2653
- buffer.push(this.startPoint.x.toString());
2654
- buffer.push(' ');
2655
- buffer.push(this.startPoint.y.toString());
2656
- buffer.push(' C ');
2657
- buffer.push(this.startControlPoint.x.toString());
2658
- buffer.push(' ');
2659
- buffer.push(this.startControlPoint.y.toString());
2660
- buffer.push(' ');
2661
- buffer.push(this.endControlPoint.x.toString());
2662
- buffer.push(' ');
2663
- buffer.push(this.endControlPoint.y.toString());
2664
- buffer.push(' ');
2665
- buffer.push(this.endPoint.x.toString());
2666
- buffer.push(' ');
2667
- buffer.push(this.endPoint.y.toString());
2668
- return buffer.join('');
2669
- };
2670
- ;
2671
2670
  /**
2672
2671
  * Convert this curve to a JSON string.
2673
2672
  *
@@ -2680,18 +2679,33 @@ var CubicBezierCurve = /** @class */ (function () {
2680
2679
  CubicBezierCurve.prototype.toJSON = function (prettyFormat) {
2681
2680
  var jsonString = "{ " + // begin object
2682
2681
  (prettyFormat ? "\n\t" : "") +
2683
- "\"startPoint\" : [" + this.getStartPoint().x + "," + this.getStartPoint().y + "], " +
2682
+ '"startPoint" : [' +
2683
+ this.getStartPoint().x +
2684
+ "," +
2685
+ this.getStartPoint().y +
2686
+ "], " +
2684
2687
  (prettyFormat ? "\n\t" : "") +
2685
- "\"endPoint\" : [" + this.getEndPoint().x + "," + this.getEndPoint().y + "], " +
2688
+ '"endPoint" : [' +
2689
+ this.getEndPoint().x +
2690
+ "," +
2691
+ this.getEndPoint().y +
2692
+ "], " +
2686
2693
  (prettyFormat ? "\n\t" : "") +
2687
- "\"startControlPoint\": [" + this.getStartControlPoint().x + "," + this.getStartControlPoint().y + "], " +
2694
+ '"startControlPoint": [' +
2695
+ this.getStartControlPoint().x +
2696
+ "," +
2697
+ this.getStartControlPoint().y +
2698
+ "], " +
2688
2699
  (prettyFormat ? "\n\t" : "") +
2689
- "\"endControlPoint\" : [" + this.getEndControlPoint().x + "," + this.getEndControlPoint().y + "]" +
2700
+ '"endControlPoint" : [' +
2701
+ this.getEndControlPoint().x +
2702
+ "," +
2703
+ this.getEndControlPoint().y +
2704
+ "]" +
2690
2705
  (prettyFormat ? "\n\t" : "") +
2691
2706
  " }"; // end object
2692
2707
  return jsonString;
2693
2708
  };
2694
- ;
2695
2709
  /**
2696
2710
  * Parse a Bézier curve from the given JSON string.
2697
2711
  *
@@ -2706,7 +2720,6 @@ var CubicBezierCurve = /** @class */ (function () {
2706
2720
  var obj = JSON.parse(jsonString);
2707
2721
  return CubicBezierCurve.fromObject(obj);
2708
2722
  };
2709
- ;
2710
2723
  /**
2711
2724
  * Try to convert the passed object to a CubicBezierCurve.
2712
2725
  *
@@ -2721,16 +2734,15 @@ var CubicBezierCurve = /** @class */ (function () {
2721
2734
  if (typeof obj !== "object")
2722
2735
  throw "Can only build from object.";
2723
2736
  if (!obj.startPoint)
2724
- throw "Object member \"startPoint\" missing.";
2737
+ throw 'Object member "startPoint" missing.';
2725
2738
  if (!obj.endPoint)
2726
- throw "Object member \"endPoint\" missing.";
2739
+ throw 'Object member "endPoint" missing.';
2727
2740
  if (!obj.startControlPoint)
2728
- throw "Object member \"startControlPoint\" missing.";
2741
+ throw 'Object member "startControlPoint" missing.';
2729
2742
  if (!obj.endControlPoint)
2730
- throw "Object member \"endControlPoint\" missing.";
2743
+ throw 'Object member "endControlPoint" missing.';
2731
2744
  return new CubicBezierCurve(new Vertex_1.Vertex(obj.startPoint[0], obj.startPoint[1]), new Vertex_1.Vertex(obj.endPoint[0], obj.endPoint[1]), new Vertex_1.Vertex(obj.startControlPoint[0], obj.startControlPoint[1]), new Vertex_1.Vertex(obj.endControlPoint[0], obj.endControlPoint[1]));
2732
2745
  };
2733
- ;
2734
2746
  /**
2735
2747
  * Convert a 4-element array of vertices to a cubic bézier curve.
2736
2748
  *
@@ -2747,7 +2759,6 @@ var CubicBezierCurve = /** @class */ (function () {
2747
2759
  throw "Can only build from array with four elements.";
2748
2760
  return new CubicBezierCurve(arr[0], arr[1], arr[2], arr[3]);
2749
2761
  };
2750
- ;
2751
2762
  /** @constant {number} */
2752
2763
  CubicBezierCurve.START_POINT = 0;
2753
2764
  /** @constant {number} */
@@ -2870,7 +2881,8 @@ exports.Grid = Grid;
2870
2881
  * @modified 2020-07-28 Changed the `delete` key code from 8 to 46.
2871
2882
  * @modified 2020-10-04 Changed `window` to `globalThis`.
2872
2883
  * @modified 2020-10-04 Added extended JSDoc.
2873
- * @version 1.0.4
2884
+ * @modified 2022-02-02 Added the `destroy` method.
2885
+ * @version 1.1.0
2874
2886
  *
2875
2887
  * @file KeyHandler
2876
2888
  * @public
@@ -2903,7 +2915,7 @@ var KeyHandler = /** @class */ (function () {
2903
2915
  * @memberof KeyHandler
2904
2916
  * @param {HTMLElement} options.element (optional) The HTML element to listen on; if null then 'window' will be used.
2905
2917
  * @param {boolean} options.trackAll (optional) Set to true if you want to keep track of _all_ keys (keyStatus).
2906
- **/
2918
+ **/
2907
2919
  function KeyHandler(options) {
2908
2920
  this.downListeners = [];
2909
2921
  this.pressListeners = [];
@@ -2922,7 +2934,6 @@ var KeyHandler = /** @class */ (function () {
2922
2934
  // Install the listeners
2923
2935
  this.installListeners();
2924
2936
  }
2925
- ;
2926
2937
  /**
2927
2938
  * A helper function to fire key events from this KeyHandler.
2928
2939
  *
@@ -2940,7 +2951,6 @@ var KeyHandler = /** @class */ (function () {
2940
2951
  }
2941
2952
  return hasListener;
2942
2953
  };
2943
- ;
2944
2954
  /**
2945
2955
  * Internal function to fire a new keydown event to all listeners.
2946
2956
  * You should not call this function on your own unless you know what you do.
@@ -2956,10 +2966,9 @@ var KeyHandler = /** @class */ (function () {
2956
2966
  KeyHandler.prototype.fireDownEvent = function (e, handler) {
2957
2967
  if (handler.fireEvent(e, handler.downListeners) || handler.trackAllKeys) {
2958
2968
  // Down event has listeners. Update key state.
2959
- handler.keyStates[e.keyCode] = 'down';
2969
+ handler.keyStates[e.keyCode] = "down";
2960
2970
  }
2961
2971
  };
2962
- ;
2963
2972
  /**
2964
2973
  * Internal function to fire a new keypress event to all listeners.
2965
2974
  * You should not call this function on your own unless you know what you do.
@@ -2975,7 +2984,6 @@ var KeyHandler = /** @class */ (function () {
2975
2984
  KeyHandler.prototype.firePressEvent = function (e, handler) {
2976
2985
  handler.fireEvent(e, handler.pressListeners);
2977
2986
  };
2978
- ;
2979
2987
  /**
2980
2988
  * Internal function to fire a new keyup event to all listeners.
2981
2989
  * You should not call this function on your own unless you know what you do.
@@ -2994,20 +3002,18 @@ var KeyHandler = /** @class */ (function () {
2994
3002
  delete handler.keyStates[e.keyCode];
2995
3003
  }
2996
3004
  };
2997
- ;
2998
3005
  /**
2999
3006
  * Resolve the key/name code.
3000
3007
  */
3001
3008
  KeyHandler.key2code = function (key) {
3002
- if (typeof key == 'number')
3009
+ if (typeof key == "number")
3003
3010
  return key;
3004
- if (typeof key != 'string')
3011
+ if (typeof key != "string")
3005
3012
  throw "Unknown key name or key type (should be a string or integer): " + key;
3006
3013
  if (KeyHandler.KEY_CODES[key])
3007
3014
  return KeyHandler.KEY_CODES[key];
3008
3015
  throw "Unknown key (cannot resolve key code): " + key;
3009
3016
  };
3010
- ;
3011
3017
  /**
3012
3018
  * Install the required listeners into the initially passed element.
3013
3019
  *
@@ -3016,20 +3022,24 @@ var KeyHandler = /** @class */ (function () {
3016
3022
  */
3017
3023
  KeyHandler.prototype.installListeners = function () {
3018
3024
  var _self = this;
3019
- this.element.addEventListener('keydown', this._keyDownListener = function (e) { _self.fireDownEvent(e, _self); });
3020
- this.element.addEventListener('keypress', this._keyPressListener = function (e) { _self.firePressEvent(e, _self); });
3021
- this.element.addEventListener('keyup', this._keyUpListener = function (e) { _self.fireUpEvent(e, _self); });
3025
+ this.element.addEventListener("keydown", (this._keyDownListener = function (e) {
3026
+ _self.fireDownEvent(e, _self);
3027
+ }));
3028
+ this.element.addEventListener("keypress", (this._keyPressListener = function (e) {
3029
+ _self.firePressEvent(e, _self);
3030
+ }));
3031
+ this.element.addEventListener("keyup", (this._keyUpListener = function (e) {
3032
+ _self.fireUpEvent(e, _self);
3033
+ }));
3022
3034
  };
3023
- ;
3024
3035
  /**
3025
3036
  * Remove all installed event listeners from the underlying element.
3026
3037
  */
3027
3038
  KeyHandler.prototype.releaseListeners = function () {
3028
- this.element.removeEventListener('keydown', this._keyDownListener);
3029
- this.element.removeEventListener('keypress', this._keyPressListener);
3030
- this.element.removeEventListener('keyup', this._keyUpListener);
3039
+ this.element.removeEventListener("keydown", this._keyDownListener);
3040
+ this.element.removeEventListener("keypress", this._keyPressListener);
3041
+ this.element.removeEventListener("keyup", this._keyUpListener);
3031
3042
  };
3032
- ;
3033
3043
  /**
3034
3044
  * Listen for key down. This function allows chaining.
3035
3045
  *
@@ -3046,7 +3056,6 @@ var KeyHandler = /** @class */ (function () {
3046
3056
  this.downListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
3047
3057
  return this;
3048
3058
  };
3049
- ;
3050
3059
  /**
3051
3060
  * Listen for key press.
3052
3061
  *
@@ -3063,7 +3072,6 @@ var KeyHandler = /** @class */ (function () {
3063
3072
  this.pressListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
3064
3073
  return this;
3065
3074
  };
3066
- ;
3067
3075
  /**
3068
3076
  * Listen for key up.
3069
3077
  *
@@ -3080,22 +3088,30 @@ var KeyHandler = /** @class */ (function () {
3080
3088
  this.upListeners.push({ key: key, keyCode: KeyHandler.key2code(key), listener: listener });
3081
3089
  return this;
3082
3090
  };
3083
- ;
3084
3091
  /**
3085
3092
  * Check if a specific key is currently held pressed.
3086
3093
  *
3087
3094
  * @param {string|number} key - Any key identifier, key code or one from the KEY_CODES list.
3088
3095
  */
3089
3096
  KeyHandler.prototype.isDown = function (key) {
3090
- if (typeof key == 'number')
3097
+ if (typeof key == "number")
3091
3098
  return this.keyStates[key] ? true : false;
3092
3099
  else
3093
3100
  return this.keyStates[KeyHandler.key2code(key)] ? true : false;
3094
3101
  };
3102
+ /**
3103
+ * This function should invalidate any installed listeners and invalidate this object.
3104
+ * After calling this function the object might not hold valid data any more and
3105
+ * should not be used any more.
3106
+ */
3107
+ KeyHandler.prototype.destroy = function () {
3108
+ this.releaseListeners();
3109
+ };
3095
3110
  /**
3096
3111
  * Source:
3097
3112
  * https://keycode.info/
3098
3113
  */
3114
+ // prettier-ignore
3099
3115
  KeyHandler.KEY_CODES = {
3100
3116
  'break': 3,
3101
3117
  'backspace': 8,
@@ -3313,7 +3329,8 @@ exports.KeyHandler = KeyHandler;
3313
3329
  * @modified 2020-03-16 The Line.angle(Line) parameter is now optional. The baseline (x-axis) will be used if not defined.
3314
3330
  * @modified 2020-03-23 Ported to Typescript from JS.
3315
3331
  * @modified 2020-12-04 The `intersection` function returns undefined if both lines are parallel.
3316
- * @version 2.1.3
3332
+ * @modified 2022-02-02 Added the `destroy` method.
3333
+ * @version 2.2.0
3317
3334
  *
3318
3335
  * @file Line
3319
3336
  * @public
@@ -3377,45 +3394,19 @@ var Line = /** @class */ (function (_super) {
3377
3394
  return null;
3378
3395
  var a = this.a.y - line.a.y;
3379
3396
  var b = this.a.x - line.a.x;
3380
- var numerator1 = ((line.b.x - line.a.x) * a) - ((line.b.y - line.a.y) * b);
3381
- var numerator2 = ((this.b.x - this.a.x) * a) - ((this.b.y - this.a.y) * b);
3397
+ var numerator1 = (line.b.x - line.a.x) * a - (line.b.y - line.a.y) * b;
3398
+ var numerator2 = (this.b.x - this.a.x) * a - (this.b.y - this.a.y) * b;
3382
3399
  a = numerator1 / denominator; // NaN if parallel lines
3383
3400
  b = numerator2 / denominator;
3384
3401
  // Catch NaN?
3385
- var x = this.a.x + (a * (this.b.x - this.a.x));
3386
- var y = this.a.y + (a * (this.b.y - this.a.y));
3402
+ var x = this.a.x + a * (this.b.x - this.a.x);
3403
+ var y = this.a.y + a * (this.b.y - this.a.y);
3387
3404
  if (isNaN(a) || isNaN(x) || isNaN(y)) {
3388
3405
  return undefined;
3389
3406
  }
3390
3407
  // if we cast these lines infinitely in both directions, they intersect here:
3391
3408
  return new Vertex_1.Vertex(x, y);
3392
3409
  };
3393
- ;
3394
- /**
3395
- * Create an SVG representation of this line.
3396
- *
3397
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
3398
- * @method toSVGString
3399
- * @param {options} p - A set of options, like the 'classname' to use
3400
- * for the line object.
3401
- * @return {string} The SVG string representing this line.
3402
- * @instance
3403
- * @memberof Line
3404
- **/
3405
- Line.prototype.toSVGString = function (options) {
3406
- options = options || {};
3407
- var buffer = [];
3408
- buffer.push('<line');
3409
- if (options.className)
3410
- buffer.push(' class="' + options.className + '"');
3411
- buffer.push(' x1="' + this.a.x + '"');
3412
- buffer.push(' y1="' + this.a.y + '"');
3413
- buffer.push(' x2="' + this.b.x + '"');
3414
- buffer.push(' y2="' + this.b.y + '"');
3415
- buffer.push(' />');
3416
- return buffer.join('');
3417
- };
3418
- ;
3419
3410
  return Line;
3420
3411
  }(VertTuple_1.VertTuple));
3421
3412
  exports.Line = Line;
@@ -3577,41 +3568,41 @@ var MouseHandler = /** @class */ (function () {
3577
3568
  // | drag offset, ...) to the callbacks.
3578
3569
  // +-------------------------------------------------
3579
3570
  var _self = this;
3580
- this.handlers['mousemove'] = function (e) {
3571
+ this.handlers["mousemove"] = function (e) {
3581
3572
  if (_self.listeners.mousemove)
3582
- _self.listeners.mousemove(_self.mkParams(e, 'mousemove'));
3573
+ _self.listeners.mousemove(_self.mkParams(e, "mousemove"));
3583
3574
  if (_self.mouseDragPos && _self.listeners.drag)
3584
- _self.listeners.drag(_self.mkParams(e, 'drag'));
3575
+ _self.listeners.drag(_self.mkParams(e, "drag"));
3585
3576
  if (_self.mouseDownPos)
3586
3577
  _self.mouseDragPos = _self.relPos(e);
3587
3578
  };
3588
- this.handlers['mouseup'] = function (e) {
3579
+ this.handlers["mouseup"] = function (e) {
3589
3580
  if (_self.listeners.mouseup)
3590
- _self.listeners.mouseup(_self.mkParams(e, 'mouseup'));
3581
+ _self.listeners.mouseup(_self.mkParams(e, "mouseup"));
3591
3582
  _self.mouseDragPos = undefined;
3592
3583
  _self.mouseDownPos = undefined;
3593
3584
  _self.mouseButton = -1;
3594
3585
  };
3595
- this.handlers['mousedown'] = function (e) {
3586
+ this.handlers["mousedown"] = function (e) {
3596
3587
  _self.mouseDragPos = _self.relPos(e);
3597
3588
  _self.mouseDownPos = _self.relPos(e);
3598
3589
  _self.mouseButton = e.button;
3599
3590
  if (_self.listeners.mousedown)
3600
- _self.listeners.mousedown(_self.mkParams(e, 'mousedown'));
3591
+ _self.listeners.mousedown(_self.mkParams(e, "mousedown"));
3601
3592
  };
3602
- this.handlers['click'] = function (e) {
3593
+ this.handlers["click"] = function (e) {
3603
3594
  if (_self.listeners.click)
3604
- _self.listeners.click(_self.mkParams(e, 'click'));
3595
+ _self.listeners.click(_self.mkParams(e, "click"));
3605
3596
  };
3606
- this.handlers['wheel'] = function (e) {
3597
+ this.handlers["wheel"] = function (e) {
3607
3598
  if (_self.listeners.wheel)
3608
- _self.listeners.wheel(_self.mkParams(e, 'wheel'));
3599
+ _self.listeners.wheel(_self.mkParams(e, "wheel"));
3609
3600
  };
3610
- this.element.addEventListener('mousemove', this.handlers['mousemove']);
3611
- this.element.addEventListener('mouseup', this.handlers['mouseup']);
3612
- this.element.addEventListener('mousedown', this.handlers['mousedown']);
3613
- this.element.addEventListener('click', this.handlers['click']);
3614
- this.element.addEventListener('wheel', this.handlers['wheel']);
3601
+ this.element.addEventListener("mousemove", this.handlers["mousemove"]);
3602
+ this.element.addEventListener("mouseup", this.handlers["mouseup"]);
3603
+ this.element.addEventListener("mousedown", this.handlers["mousedown"]);
3604
+ this.element.addEventListener("click", this.handlers["click"]);
3605
+ this.element.addEventListener("wheel", this.handlers["wheel"]);
3615
3606
  }
3616
3607
  /**
3617
3608
  * Get relative position from the given MouseEvent.
@@ -3624,11 +3615,8 @@ var MouseHandler = /** @class */ (function () {
3624
3615
  * @return {XYCoords} The relative mouse coordinates.
3625
3616
  */
3626
3617
  MouseHandler.prototype.relPos = function (e) {
3627
- return { x: e.offsetX,
3628
- y: e.offsetY
3629
- };
3618
+ return { x: e.offsetX, y: e.offsetY };
3630
3619
  };
3631
- ;
3632
3620
  /**
3633
3621
  * Build the extended event params.
3634
3622
  *
@@ -3654,8 +3642,8 @@ var MouseHandler = /** @class */ (function () {
3654
3642
  rightButton: this.mouseButton == 2,
3655
3643
  mouseDownPos: this.mouseDownPos,
3656
3644
  draggedFrom: this.mouseDragPos,
3657
- wasDragged: (this.mouseDownPos != null && (this.mouseDownPos.x != rel.x || this.mouseDownPos.y != rel.y)),
3658
- dragAmount: (this.mouseDownPos != null ? { x: rel.x - this.mouseDragPos.x, y: rel.y - this.mouseDragPos.y } : { x: 0, y: 0 })
3645
+ wasDragged: this.mouseDownPos != null && (this.mouseDownPos.x != rel.x || this.mouseDownPos.y != rel.y),
3646
+ dragAmount: this.mouseDownPos != null ? { x: rel.x - this.mouseDragPos.x, y: rel.y - this.mouseDragPos.y } : { x: 0, y: 0 }
3659
3647
  };
3660
3648
  return xEvent;
3661
3649
  };
@@ -3706,14 +3694,13 @@ var MouseHandler = /** @class */ (function () {
3706
3694
  */
3707
3695
  MouseHandler.prototype.drag = function (callback) {
3708
3696
  if (this.listeners.drag)
3709
- this.throwAlreadyInstalled('drag');
3697
+ this.throwAlreadyInstalled("drag");
3710
3698
  this.listeners.drag = callback;
3711
- this.listenFor('mousedown');
3712
- this.listenFor('mousemove');
3713
- this.listenFor('mouseup');
3699
+ this.listenFor("mousedown");
3700
+ this.listenFor("mousemove");
3701
+ this.listenFor("mouseup");
3714
3702
  return this;
3715
3703
  };
3716
- ;
3717
3704
  /**
3718
3705
  * Installer function to listen for a specific event: mouse-move.
3719
3706
  * Pass your callbacks here.
@@ -3728,12 +3715,11 @@ var MouseHandler = /** @class */ (function () {
3728
3715
  */
3729
3716
  MouseHandler.prototype.move = function (callback) {
3730
3717
  if (this.listeners.mousemove)
3731
- this.throwAlreadyInstalled('mousemove');
3732
- this.listenFor('mousemove');
3718
+ this.throwAlreadyInstalled("mousemove");
3719
+ this.listenFor("mousemove");
3733
3720
  this.listeners.mousemove = callback;
3734
3721
  return this;
3735
3722
  };
3736
- ;
3737
3723
  /**
3738
3724
  * Installer function to listen for a specific event: mouse-up.
3739
3725
  * Pass your callbacks here.
@@ -3748,12 +3734,11 @@ var MouseHandler = /** @class */ (function () {
3748
3734
  */
3749
3735
  MouseHandler.prototype.up = function (callback) {
3750
3736
  if (this.listeners.mouseup)
3751
- this.throwAlreadyInstalled('mouseup');
3752
- this.listenFor('mouseup');
3737
+ this.throwAlreadyInstalled("mouseup");
3738
+ this.listenFor("mouseup");
3753
3739
  this.listeners.mouseup = callback;
3754
3740
  return this;
3755
3741
  };
3756
- ;
3757
3742
  /**
3758
3743
  * Installer function to listen for a specific event: mouse-down.
3759
3744
  * Pass your callbacks here.
@@ -3768,12 +3753,11 @@ var MouseHandler = /** @class */ (function () {
3768
3753
  */
3769
3754
  MouseHandler.prototype.down = function (callback) {
3770
3755
  if (this.listeners.mousedown)
3771
- this.throwAlreadyInstalled('mousedown');
3772
- this.listenFor('mousedown');
3756
+ this.throwAlreadyInstalled("mousedown");
3757
+ this.listenFor("mousedown");
3773
3758
  this.listeners.mousedown = callback;
3774
3759
  return this;
3775
3760
  };
3776
- ;
3777
3761
  /**
3778
3762
  * Installer function to listen for a specific event: mouse-click.
3779
3763
  * Pass your callbacks here.
@@ -3788,12 +3772,11 @@ var MouseHandler = /** @class */ (function () {
3788
3772
  */
3789
3773
  MouseHandler.prototype.click = function (callback) {
3790
3774
  if (this.listeners.click)
3791
- this.throwAlreadyInstalled('click');
3792
- this.listenFor('click');
3775
+ this.throwAlreadyInstalled("click");
3776
+ this.listenFor("click");
3793
3777
  this.listeners.click = callback;
3794
3778
  return this;
3795
3779
  };
3796
- ;
3797
3780
  /**
3798
3781
  * Installer function to listen for a specific event: mouse-wheel.
3799
3782
  * Pass your callbacks here.
@@ -3808,12 +3791,11 @@ var MouseHandler = /** @class */ (function () {
3808
3791
  */
3809
3792
  MouseHandler.prototype.wheel = function (callback) {
3810
3793
  if (this.listeners.wheel)
3811
- this.throwAlreadyInstalled('wheel');
3812
- this.listenFor('wheel');
3794
+ this.throwAlreadyInstalled("wheel");
3795
+ this.listenFor("wheel");
3813
3796
  this.listeners.wheel = callback;
3814
3797
  return this;
3815
3798
  };
3816
- ;
3817
3799
  /**
3818
3800
  * An internal function to throw events.
3819
3801
  *
@@ -3827,7 +3809,6 @@ var MouseHandler = /** @class */ (function () {
3827
3809
  MouseHandler.prototype.throwAlreadyInstalled = function (name) {
3828
3810
  throw "This MouseHandler already has a '" + name + "' callback. To keep the code simple there is only room for one.";
3829
3811
  };
3830
- ;
3831
3812
  /**
3832
3813
  * Call this when your work is done.
3833
3814
  *
@@ -3840,16 +3821,16 @@ var MouseHandler = /** @class */ (function () {
3840
3821
  * @return {void}
3841
3822
  */
3842
3823
  MouseHandler.prototype.destroy = function () {
3843
- this.unlistenFor('mousedown');
3844
- this.unlistenFor('mousemove');
3845
- this.unlistenFor('moseup');
3846
- this.unlistenFor('click');
3847
- this.unlistenFor('wheel');
3848
- this.element.removeEventListener('mousemove', this.handlers['mousemove']);
3849
- this.element.removeEventListener('mouseup', this.handlers['mousedown']);
3850
- this.element.removeEventListener('mousedown', this.handlers['mousedown']);
3851
- this.element.removeEventListener('click', this.handlers['click']);
3852
- this.element.removeEventListener('wheel', this.handlers['wheel']);
3824
+ this.unlistenFor("mousedown");
3825
+ this.unlistenFor("mousemove");
3826
+ this.unlistenFor("moseup");
3827
+ this.unlistenFor("click");
3828
+ this.unlistenFor("wheel");
3829
+ this.element.removeEventListener("mousemove", this.handlers["mousemove"]);
3830
+ this.element.removeEventListener("mouseup", this.handlers["mousedown"]);
3831
+ this.element.removeEventListener("mousedown", this.handlers["mousedown"]);
3832
+ this.element.removeEventListener("click", this.handlers["click"]);
3833
+ this.element.removeEventListener("wheel", this.handlers["wheel"]);
3853
3834
  };
3854
3835
  return MouseHandler;
3855
3836
  }());
@@ -3868,7 +3849,9 @@ exports.MouseHandler = MouseHandler;
3868
3849
  * @modified 2019-03-23 Added JSDoc tags.
3869
3850
  * @modified 2020-03-25 Ported this class from vanilla-JS to Typescript.
3870
3851
  * @modified 2021-01-20 Added UID.
3871
- * @version 1.1.0
3852
+ * @modified 2022-02-02 Added the `destroy` method.
3853
+ * @modified 2022-02-02 Cleared the `PBImage.toSVGString` function (deprecated). Use `drawutilssvg` instead.
3854
+ * @version 1.2.0
3872
3855
  *
3873
3856
  * @file PBImage
3874
3857
  * @fileoverview As native Image objects have only a position and with
@@ -3906,22 +3889,16 @@ var PBImage = /** @class */ (function () {
3906
3889
  this.upperLeft = upperLeft;
3907
3890
  this.lowerRight = lowerRight;
3908
3891
  }
3909
- ;
3910
3892
  /**
3911
- * Convert this vertex to SVG code.
3912
- *
3913
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
3914
- * @method toSVGString
3915
- * @param {object=} options - An optional set of options, like 'className'.
3916
- * @return {string} A string representing the SVG code for this vertex.
3917
- * @instance
3918
- * @memberof PBImage
3919
- **/
3920
- PBImage.prototype.toSVGString = function (options) {
3921
- console.warn("PBImage is not yet SVG serializable. Returning empty SVG string.");
3922
- return "";
3893
+ * This function should invalidate any installed listeners and invalidate this object.
3894
+ * After calling this function the object might not hold valid data any more and
3895
+ * should not be used.
3896
+ */
3897
+ PBImage.prototype.destroy = function () {
3898
+ this.upperLeft.destroy();
3899
+ this.lowerRight.destroy();
3900
+ this.isDestroyed = true;
3923
3901
  };
3924
- ;
3925
3902
  return PBImage;
3926
3903
  }());
3927
3904
  exports.PBImage = PBImage;
@@ -3936,7 +3913,8 @@ exports.PBImage = PBImage;
3936
3913
  /**
3937
3914
  * @author Ikaros Kappler
3938
3915
  * @date 2021-11-16
3939
- * @version 1.0.0
3916
+ * @modified 2022-02-02 Added the `destroy` method.
3917
+ * @version 1.1.0
3940
3918
  **/
3941
3919
  Object.defineProperty(exports, "__esModule", ({ value: true }));
3942
3920
  exports.PBText = void 0;
@@ -3981,18 +3959,13 @@ var PBText = /** @class */ (function () {
3981
3959
  this.rotation = options.rotation;
3982
3960
  }
3983
3961
  /**
3984
- * Create an SVG representation of this circle.
3985
- *
3986
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
3987
- * @method toSVGString
3988
- * @param {object=} options - An optional set of options, like 'className'.
3989
- * @return {string} A string representing the SVG code for this vertex.
3990
- * @instance
3991
- * @memberof Circle
3962
+ * This function should invalidate any installed listeners and invalidate this object.
3963
+ * After calling this function the object might not hold valid data any more and
3964
+ * should not be used.
3992
3965
  */
3993
- PBText.prototype.toSVGString = function (options) {
3994
- console.warn("[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead.");
3995
- return "";
3966
+ PBText.prototype.destroy = function () {
3967
+ this.anchor.destroy();
3968
+ this.isDestroyed = true;
3996
3969
  };
3997
3970
  return PBText;
3998
3971
  }()); // END class
@@ -4082,7 +4055,8 @@ var __webpack_unused_export__;
4082
4055
  * @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
4083
4056
  * @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
4084
4057
  * @modified 2021-11-16 Adding the `PBText` drawable.
4085
- * @version 1.15.0
4058
+ * @modified 2022-08-01 Added `title` to the params.
4059
+ * @version 1.15.1
4086
4060
  *
4087
4061
  * @file PlotBoilerplate
4088
4062
  * @fileoverview The main class.
@@ -4197,6 +4171,7 @@ var PlotBoilerplate = /** @class */ (function () {
4197
4171
  * @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
4198
4172
  * @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
4199
4173
  * Note that changes from the postDraw hook might not be visible in the export.
4174
+ * @param {string=} [config.title=null] - Specify any hover tile here. It will be attached as a `title` attribute to the most elevated element.
4200
4175
  */
4201
4176
  function PlotBoilerplate(config) {
4202
4177
  /**
@@ -4412,6 +4387,11 @@ var PlotBoilerplate = /** @class */ (function () {
4412
4387
  else {
4413
4388
  throw "Element is neither a canvas nor an svg element.";
4414
4389
  }
4390
+ // At this point the event cacher element is deinfed and located at highest elevation.
4391
+ // Set `title` attribut?
4392
+ if (config.title) {
4393
+ this.eventCatcher.setAttribute("title", config.title);
4394
+ }
4415
4395
  this.draw.scale.set(this.config.scaleX, this.config.scaleY);
4416
4396
  this.fill.scale.set(this.config.scaleX, this.config.scaleY);
4417
4397
  this.vertices = [];
@@ -4714,7 +4694,7 @@ var PlotBoilerplate = /** @class */ (function () {
4714
4694
  }
4715
4695
  }
4716
4696
  for (var i = 0; i < this.drawables.length; i++) {
4717
- if (this.drawables[i] === drawable) {
4697
+ if (this.drawables[i] === drawable || this.drawables[i].uid === drawable.uid) {
4718
4698
  this.drawables.splice(i, 1);
4719
4699
  if (removeWithVertices) {
4720
4700
  // Check if some listeners need to be removed
@@ -6130,7 +6110,10 @@ __webpack_unused_export__ = PlotBoilerplate;
6130
6110
  * @modified 2021-01-29 Changed the param type for `containsVert` from Vertex to XYCoords.
6131
6111
  * @modified 2021-12-14 Added the `perimeter()` function.
6132
6112
  * @modified 2021-12-16 Added the `getEvenDistributionPolygon()` function.
6133
- * @version 1.8.0
6113
+ * @modified 2022-02-02 Added the `destroy` method.
6114
+ * @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
6115
+ * @modified 2022-03-08 Added the `Polygon.clone()` function.
6116
+ * @version 1.10.0
6134
6117
  *
6135
6118
  * @file Polygon
6136
6119
  * @public
@@ -6214,9 +6197,9 @@ var Polygon = /** @class */ (function () {
6214
6197
  * @memberof Polygon
6215
6198
  * @return {Polygon} this for chaining
6216
6199
  **/
6217
- Polygon.prototype.move = function (vert) {
6200
+ Polygon.prototype.move = function (amount) {
6218
6201
  for (var i in this.vertices) {
6219
- this.vertices[i].add(vert);
6202
+ this.vertices[i].add(amount);
6220
6203
  }
6221
6204
  return this;
6222
6205
  };
@@ -6395,6 +6378,14 @@ var Polygon = /** @class */ (function () {
6395
6378
  Polygon.prototype.getBounds = function () {
6396
6379
  return Bounds_1.Bounds.computeFromVertices(this.vertices);
6397
6380
  };
6381
+ /**
6382
+ * Create a deep copy of this polygon.
6383
+ *
6384
+ * @return {Polygon} The cloned polygon.
6385
+ */
6386
+ Polygon.prototype.clone = function () {
6387
+ return new Polygon(this.vertices.map(function (vert) { return vert.clone(); }), this.isOpen);
6388
+ };
6398
6389
  /**
6399
6390
  * Convert this polygon to a sequence of quadratic Bézier curves.<br>
6400
6391
  * <br>
@@ -6532,39 +6523,15 @@ var Polygon = /** @class */ (function () {
6532
6523
  return BezierPath_1.BezierPath.fromArray(pathdata);
6533
6524
  };
6534
6525
  /**
6535
- * Create an SVG representation of this polygon.
6536
- *
6537
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
6538
- * @method toSVGString
6539
- * @param {object=} options - An optional set of options, like 'className'.
6540
- * @return {string} The SVG string.
6541
- * @instance
6542
- * @memberof Polygon
6543
- **/
6544
- Polygon.prototype.toSVGString = function (options) {
6545
- options = options || {};
6546
- var buffer = [];
6547
- buffer.push("<path");
6548
- if (options.className)
6549
- buffer.push(' class="' + options.className + '"');
6550
- buffer.push(' d="');
6551
- if (this.vertices.length > 0) {
6552
- buffer.push("M ");
6553
- buffer.push(this.vertices[0].x.toString());
6554
- buffer.push(" ");
6555
- buffer.push(this.vertices[0].y.toString());
6556
- for (var i = 1; i < this.vertices.length; i++) {
6557
- buffer.push(" L ");
6558
- buffer.push(this.vertices[i].x.toString());
6559
- buffer.push(" ");
6560
- buffer.push(this.vertices[i].y.toString());
6561
- }
6562
- if (!this.isOpen) {
6563
- buffer.push(" Z");
6564
- }
6526
+ * This function should invalidate any installed listeners and invalidate this object.
6527
+ * After calling this function the object might not hold valid data any more and
6528
+ * should not be used.
6529
+ */
6530
+ Polygon.prototype.destroy = function () {
6531
+ for (var i = 0; i < this.vertices.length; i++) {
6532
+ this.vertices[i].destroy();
6565
6533
  }
6566
- buffer.push('" />');
6567
- return buffer.join("");
6534
+ this.isDestroyed = true;
6568
6535
  };
6569
6536
  Polygon.utils = {
6570
6537
  /**
@@ -6638,7 +6605,9 @@ exports.Polygon = Polygon;
6638
6605
  * @modified 2020-12-28 Added the `getArea` function.
6639
6606
  * @modified 2021-01-20 Added UID.
6640
6607
  * @modified 2021-01-22 Always updating circumcircle when retieving it.
6641
- * @version 2.5.1
6608
+ * @modified 2022-02-02 Added the `destroy` method.
6609
+ * @modified 2022-02-02 Cleared the `Triangle.toSVGString` function (deprecated). Use `drawutilssvg` instead.
6610
+ * @version 2.6.0
6642
6611
  *
6643
6612
  * @file Triangle
6644
6613
  * @fileoverview A simple triangle class: three vertices.
@@ -6708,7 +6677,6 @@ var Triangle = /** @class */ (function () {
6708
6677
  throw "Cannot create triangle from array with less than three vertices (" + arr.length + ")";
6709
6678
  return new Triangle(arr[0], arr[1], arr[2]);
6710
6679
  };
6711
- ;
6712
6680
  /**
6713
6681
  * Get the area of this triangle. The returned area is never negative.
6714
6682
  *
@@ -6724,7 +6692,6 @@ var Triangle = /** @class */ (function () {
6724
6692
  Triangle.prototype.getArea = function () {
6725
6693
  return Math.abs(Triangle.utils.signedArea(this.a.x, this.a.y, this.b.x, this.b.y, this.c.x, this.c.y));
6726
6694
  };
6727
- ;
6728
6695
  /**
6729
6696
  * Get the centroid of this triangle.
6730
6697
  *
@@ -6738,7 +6705,6 @@ var Triangle = /** @class */ (function () {
6738
6705
  Triangle.prototype.getCentroid = function () {
6739
6706
  return new Vertex_1.Vertex((this.a.x + this.b.x + this.c.x) / 3, (this.a.y + this.b.y + this.c.y) / 3);
6740
6707
  };
6741
- ;
6742
6708
  /**
6743
6709
  * Scale the triangle towards its centroid.
6744
6710
  *
@@ -6755,7 +6721,6 @@ var Triangle = /** @class */ (function () {
6755
6721
  this.c.scale(factor, centroid);
6756
6722
  return this;
6757
6723
  };
6758
- ;
6759
6724
  /**
6760
6725
  * Get the circumcircle of this triangle.
6761
6726
  *
@@ -6772,11 +6737,10 @@ var Triangle = /** @class */ (function () {
6772
6737
  * @memberof Triangle
6773
6738
  */
6774
6739
  Triangle.prototype.getCircumcircle = function () {
6775
- // if( !this.center || !this.radius )
6740
+ // if( !this.center || !this.radius )
6776
6741
  this.calcCircumcircle();
6777
6742
  return new Circle_1.Circle(this.center.clone(), this.radius);
6778
6743
  };
6779
- ;
6780
6744
  /**
6781
6745
  * Check if this triangle and the passed triangle share an
6782
6746
  * adjacent edge.
@@ -6796,7 +6760,6 @@ var Triangle = /** @class */ (function () {
6796
6760
  var c = this.c.equals(tri.a) || this.c.equals(tri.b) || this.c.equals(tri.c);
6797
6761
  return (a && b) || (a && c) || (b && c);
6798
6762
  };
6799
- ;
6800
6763
  /**
6801
6764
  * Get that vertex of this triangle (a,b,c) that is not vert1 nor vert2 of
6802
6765
  * the passed two.
@@ -6809,14 +6772,13 @@ var Triangle = /** @class */ (function () {
6809
6772
  * @memberof Triangle
6810
6773
  */
6811
6774
  Triangle.prototype.getThirdVertex = function (vert1, vert2) {
6812
- if (this.a.equals(vert1) && this.b.equals(vert2) || this.a.equals(vert2) && this.b.equals(vert1))
6775
+ if ((this.a.equals(vert1) && this.b.equals(vert2)) || (this.a.equals(vert2) && this.b.equals(vert1)))
6813
6776
  return this.c;
6814
- if (this.b.equals(vert1) && this.c.equals(vert2) || this.b.equals(vert2) && this.c.equals(vert1))
6777
+ if ((this.b.equals(vert1) && this.c.equals(vert2)) || (this.b.equals(vert2) && this.c.equals(vert1)))
6815
6778
  return this.a;
6816
6779
  //if( this.c.equals(vert1) && this.a.equals(vert2) || this.c.equals(vert2) && this.a.equals(vert1) )
6817
6780
  return this.b;
6818
6781
  };
6819
- ;
6820
6782
  /**
6821
6783
  * Re-compute the circumcircle of this triangle (if the vertices
6822
6784
  * have changed).
@@ -6856,8 +6818,7 @@ var Triangle = /** @class */ (function () {
6856
6818
  }
6857
6819
  this.radius_squared = dx * dx + dy * dy;
6858
6820
  this.radius = Math.sqrt(this.radius_squared);
6859
- };
6860
- ; // END calcCircumcircle
6821
+ }; // END calcCircumcircle
6861
6822
  /**
6862
6823
  * Check if the passed vertex is inside this triangle's
6863
6824
  * circumcircle.
@@ -6872,9 +6833,8 @@ var Triangle = /** @class */ (function () {
6872
6833
  var dx = this.center.x - v.x;
6873
6834
  var dy = this.center.y - v.y;
6874
6835
  var dist_squared = dx * dx + dy * dy;
6875
- return (dist_squared <= this.radius_squared);
6836
+ return dist_squared <= this.radius_squared;
6876
6837
  };
6877
- ;
6878
6838
  /**
6879
6839
  * Get the rectangular bounds for this triangle.
6880
6840
  *
@@ -6886,7 +6846,6 @@ var Triangle = /** @class */ (function () {
6886
6846
  Triangle.prototype.bounds = function () {
6887
6847
  return new Bounds_1.Bounds(new Vertex_1.Vertex(Triangle.utils.min3(this.a.x, this.b.x, this.c.x), Triangle.utils.min3(this.a.y, this.b.y, this.c.y)), new Vertex_1.Vertex(Triangle.utils.max3(this.a.x, this.b.x, this.c.x), Triangle.utils.max3(this.a.y, this.b.y, this.c.y)));
6888
6848
  };
6889
- ;
6890
6849
  /**
6891
6850
  * Convert this triangle to a polygon instance.
6892
6851
  *
@@ -6900,7 +6859,6 @@ var Triangle = /** @class */ (function () {
6900
6859
  Triangle.prototype.toPolygon = function () {
6901
6860
  return new Polygon_1.Polygon([this.a, this.b, this.c]);
6902
6861
  };
6903
- ;
6904
6862
  /**
6905
6863
  * Get the determinant of this triangle.
6906
6864
  *
@@ -6913,7 +6871,6 @@ var Triangle = /** @class */ (function () {
6913
6871
  // (b.y - a.y)*(c.x - b.x) - (c.y - b.y)*(b.x - a.x);
6914
6872
  return (this.b.y - this.a.y) * (this.c.x - this.b.x) - (this.c.y - this.b.y) * (this.b.x - this.a.x);
6915
6873
  };
6916
- ;
6917
6874
  /**
6918
6875
  * Checks if the passed vertex (p) is inside this triangle.
6919
6876
  *
@@ -6928,7 +6885,6 @@ var Triangle = /** @class */ (function () {
6928
6885
  Triangle.prototype.containsPoint = function (p) {
6929
6886
  return Triangle.utils.pointIsInTriangle(p.x, p.y, this.a.x, this.a.y, this.b.x, this.b.y, this.c.x, this.c.y);
6930
6887
  };
6931
- ;
6932
6888
  /**
6933
6889
  * Get that inner triangle which defines the maximal incircle.
6934
6890
  *
@@ -6947,7 +6903,6 @@ var Triangle = /** @class */ (function () {
6947
6903
  var circleIntersC = lineC.getClosestPoint(intersection);
6948
6904
  return new Triangle(circleIntersA, circleIntersB, circleIntersC);
6949
6905
  };
6950
- ;
6951
6906
  /**
6952
6907
  * Get the incircle of this triangle. That is the circle that touches each side
6953
6908
  * of this triangle in exactly one point.
@@ -6959,7 +6914,6 @@ var Triangle = /** @class */ (function () {
6959
6914
  Triangle.prototype.getIncircle = function () {
6960
6915
  return this.getIncircularTriangle().getCircumcircle();
6961
6916
  };
6962
- ;
6963
6917
  /**
6964
6918
  * Get the incenter of this triangle (which is the center of the circumcircle).
6965
6919
  *
@@ -6973,7 +6927,6 @@ var Triangle = /** @class */ (function () {
6973
6927
  this.calcCircumcircle();
6974
6928
  return this.center.clone();
6975
6929
  };
6976
- ;
6977
6930
  /**
6978
6931
  * Converts this triangle into a human-readable string.
6979
6932
  *
@@ -6983,46 +6936,19 @@ var Triangle = /** @class */ (function () {
6983
6936
  * @memberof Triangle
6984
6937
  */
6985
6938
  Triangle.prototype.toString = function () {
6986
- return '{ a : ' + this.a.toString() + ', b : ' + this.b.toString() + ', c : ' + this.c.toString() + '}';
6939
+ return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + ", c : " + this.c.toString() + "}";
6987
6940
  };
6988
- ;
6989
6941
  /**
6990
- * Create an SVG representation of this triangle.
6991
- *
6992
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
6993
- * @method toSVGString
6994
- * @param {object=} options - An optional set of options, like 'className'.
6995
- * @return {string} The SVG string.
6996
- * @instance
6997
- * @memberof Triangle
6998
- **/
6999
- Triangle.prototype.toSVGString = function (options) {
7000
- options = options || {};
7001
- var buffer = [];
7002
- buffer.push('<path');
7003
- if (options.className)
7004
- buffer.push(' class="' + options.className + '"');
7005
- buffer.push(' d="');
7006
- var vertices = [this.a, this.b, this.c];
7007
- if (vertices.length > 0) {
7008
- buffer.push('M ');
7009
- buffer.push(vertices[0].x);
7010
- buffer.push(' ');
7011
- buffer.push(vertices[0].y);
7012
- for (var i = 1; i < vertices.length; i++) {
7013
- buffer.push(' L ');
7014
- buffer.push(vertices[i].x);
7015
- buffer.push(' ');
7016
- buffer.push(vertices[i].y);
7017
- }
7018
- //if( !this.isOpen ) {
7019
- buffer.push(' Z');
7020
- //}
7021
- }
7022
- buffer.push('" />');
7023
- return buffer.join('');
6942
+ * This function should invalidate any installed listeners and invalidate this object.
6943
+ * After calling this function the object might not hold valid data any more and
6944
+ * should not be used.
6945
+ */
6946
+ Triangle.prototype.destroy = function () {
6947
+ this.a.destroy();
6948
+ this.b.destroy();
6949
+ this.c.destroy();
6950
+ this.isDestroyed = true;
7024
6951
  };
7025
- ;
7026
6952
  /**
7027
6953
  * An epsilon for comparison.
7028
6954
  * This should be the same epsilon as in Vertex.
@@ -7033,10 +6959,10 @@ var Triangle = /** @class */ (function () {
7033
6959
  Triangle.utils = {
7034
6960
  // Used in the bounds() function.
7035
6961
  max3: function (a, b, c) {
7036
- return (a >= b && a >= c) ? a : (b >= a && b >= c) ? b : c;
6962
+ return a >= b && a >= c ? a : b >= a && b >= c ? b : c;
7037
6963
  },
7038
6964
  min3: function (a, b, c) {
7039
- return (a <= b && a <= c) ? a : (b <= a && b <= c) ? b : c;
6965
+ return a <= b && a <= c ? a : b <= a && b <= c ? b : c;
7040
6966
  },
7041
6967
  signedArea: function (p0x, p0y, p1x, p1y, p2x, p2y) {
7042
6968
  return 0.5 * (-p1y * p2x + p0y * (-p1x + p2x) + p0x * (p1y - p2y) + p1x * p2y);
@@ -7052,9 +6978,9 @@ var Triangle = /** @class */ (function () {
7052
6978
  // http://stackoverflow.com/questions/2049582/how-to-determine-a-point-in-a-2d-triangle
7053
6979
  // var area : number = 1/2*(-p1y*p2x + p0y*(-p1x + p2x) + p0x*(p1y - p2y) + p1x*p2y);
7054
6980
  var area = Triangle.utils.signedArea(p0x, p0y, p1x, p1y, p2x, p2y);
7055
- var s = 1 / (2 * area) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
7056
- var t = 1 / (2 * area) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);
7057
- return s > 0 && t > 0 && (1 - s - t) > 0;
6981
+ var s = (1 / (2 * area)) * (p0y * p2x - p0x * p2y + (p2y - p0y) * px + (p0x - p2x) * py);
6982
+ var t = (1 / (2 * area)) * (p0x * p1y - p0y * p1x + (p0y - p1y) * px + (p1x - p0x) * py);
6983
+ return s > 0 && t > 0 && 1 - s - t > 0;
7058
6984
  }
7059
6985
  };
7060
6986
  return Triangle;
@@ -7110,7 +7036,9 @@ exports.UIDGenerator = UIDGenerator;
7110
7036
  * @modified 2021-03-10 Added the `toCubicBezier` method.
7111
7037
  * @modified 2021-03-15 Added `VEllipse.quarterSegmentCount` and `VEllipse.scale` functions.
7112
7038
  * @modified 2021-03-19 Added the `VEllipse.rotate` function.
7113
- * @version 1.2.2
7039
+ * @modified 2022-02-02 Added the `destroy` method.
7040
+ * @modified 2022-02-02 Cleared the `VEllipse.toSVGString` function (deprecated). Use `drawutilssvg` instead.
7041
+ * @version 1.3.0
7114
7042
  *
7115
7043
  * @file VEllipse
7116
7044
  * @fileoverview Ellipses with a center and an x- and a y-axis (stored as a vertex).
@@ -7436,24 +7364,14 @@ var VEllipse = /** @class */ (function () {
7436
7364
  return curves;
7437
7365
  };
7438
7366
  /**
7439
- * Create an SVG representation of this ellipse.
7440
- *
7441
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
7442
- * @param {object} options { className?:string }
7443
- * @return string The SVG string
7367
+ * This function should invalidate any installed listeners and invalidate this object.
7368
+ * After calling this function the object might not hold valid data any more and
7369
+ * should not be used.
7444
7370
  */
7445
- VEllipse.prototype.toSVGString = function (options) {
7446
- options = options || {};
7447
- var buffer = [];
7448
- buffer.push("<ellipse");
7449
- if (options.className)
7450
- buffer.push(' class="' + options.className + '"');
7451
- buffer.push(' cx="' + this.center.x + '"');
7452
- buffer.push(' cy="' + this.center.y + '"');
7453
- buffer.push(' rx="' + this.axis.x + '"');
7454
- buffer.push(' ry="' + this.axis.y + '"');
7455
- buffer.push(" />");
7456
- return buffer.join("");
7371
+ VEllipse.prototype.destroy = function () {
7372
+ this.center.destroy();
7373
+ this.axis.destroy();
7374
+ this.isDestroyed = true;
7457
7375
  };
7458
7376
  /**
7459
7377
  * A static collection of ellipse-related helper functions.
@@ -7529,7 +7447,8 @@ exports.VEllipse = VEllipse;
7529
7447
  *
7530
7448
  * @author Ikaros Kappler
7531
7449
  * @date 2021-02-26
7532
- * @version 1.0.0
7450
+ * @modified 2022-02-02 Added the `destroy` method.
7451
+ * @version 1.1.0
7533
7452
  */
7534
7453
  Object.defineProperty(exports, "__esModule", ({ value: true }));
7535
7454
  exports.VEllipseSector = void 0;
@@ -7623,6 +7542,15 @@ var VEllipseSector = /** @class */ (function () {
7623
7542
  }
7624
7543
  return curves;
7625
7544
  };
7545
+ /**
7546
+ * This function should invalidate any installed listeners and invalidate this object.
7547
+ * After calling this function the object might not hold valid data any more and
7548
+ * should not be used.
7549
+ */
7550
+ VEllipseSector.prototype.destroy = function () {
7551
+ this.ellipse.destroy();
7552
+ this.isDestroyed = true;
7553
+ };
7626
7554
  VEllipseSector.ellipseSectorUtils = {
7627
7555
  /**
7628
7556
  * Helper function to convert an elliptic section to SVG arc params (for the `d` attribute).
@@ -7807,7 +7735,9 @@ exports.VEllipseSector = VEllipseSector;
7807
7735
  * @modified 2019-12-04 Added the Vector.inv() function.
7808
7736
  * @modified 2020-03-23 Ported to Typescript from JS.
7809
7737
  * @modified 2021-01-20 Added UID.
7810
- * @version 1.3.0
7738
+ * @modified 2022-02-02 Added the `destroy` method.
7739
+ * @modified 2022-02-02 Cleared the `Vector.toSVGString` function (deprecated). Use `drawutilssvg` instead.
7740
+ * @version 1.4.0
7811
7741
  *
7812
7742
  * @file Vector
7813
7743
  * @public
@@ -7857,7 +7787,6 @@ var Vector = /** @class */ (function (_super) {
7857
7787
  _this.className = "Vector";
7858
7788
  return _this;
7859
7789
  }
7860
- ;
7861
7790
  /**
7862
7791
  * Get the perpendicular of this vector which is located at a.
7863
7792
  *
@@ -7872,7 +7801,6 @@ var Vector = /** @class */ (function (_super) {
7872
7801
  v.b.add(this.a);
7873
7802
  return v;
7874
7803
  };
7875
- ;
7876
7804
  /**
7877
7805
  * The inverse of a vector is a vector witht the same magnitude but oppose direction.
7878
7806
  *
@@ -7886,7 +7814,6 @@ var Vector = /** @class */ (function (_super) {
7886
7814
  this.b = tmp;
7887
7815
  return this;
7888
7816
  };
7889
- ;
7890
7817
  /**
7891
7818
  * This function computes the inverse of the vector, which means 'a' stays untouched.
7892
7819
  *
@@ -7897,7 +7824,6 @@ var Vector = /** @class */ (function (_super) {
7897
7824
  this.b.y = this.a.y - (this.b.y - this.a.y);
7898
7825
  return this;
7899
7826
  };
7900
- ;
7901
7827
  /**
7902
7828
  * Get the intersection if this vector and the specified vector.
7903
7829
  *
@@ -7913,53 +7839,15 @@ var Vector = /** @class */ (function (_super) {
7913
7839
  return null;
7914
7840
  var a = this.a.y - line.a.y;
7915
7841
  var b = this.a.x - line.a.x;
7916
- var numerator1 = ((line.b.x - line.a.x) * a) - ((line.b.y - line.a.y) * b);
7917
- var numerator2 = ((this.b.x - this.a.x) * a) - ((this.b.y - this.a.y) * b);
7842
+ var numerator1 = (line.b.x - line.a.x) * a - (line.b.y - line.a.y) * b;
7843
+ var numerator2 = (this.b.x - this.a.x) * a - (this.b.y - this.a.y) * b;
7918
7844
  a = numerator1 / denominator; // NaN if parallel lines
7919
7845
  b = numerator2 / denominator;
7920
7846
  // TODO:
7921
7847
  // FOR A VECTOR THE LINE-INTERSECTION MUST BE ON BOTH VECTORS
7922
7848
  // if we cast these lines infinitely in both directions, they intersect here:
7923
- return new Vertex_1.Vertex(this.a.x + (a * (this.b.x - this.a.x)), this.a.y + (a * (this.b.y - this.a.y)));
7924
- };
7925
- ;
7926
- /**
7927
- * Create an SVG representation of this line.
7928
- *
7929
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
7930
- * @method toSVGString
7931
- * @override
7932
- * @param {object=} options - A set of options, like 'className'.
7933
- * @return {string} The SVG string representation.
7934
- * @instance
7935
- * @memberof Vector
7936
- **/
7937
- Vector.prototype.toSVGString = function (options) {
7938
- options = options || {};
7939
- var buffer = [];
7940
- var vertices = Vector.utils.buildArrowHead(this.a, this.b, 8, 1.0, 1.0);
7941
- buffer.push('<g');
7942
- if (options.className)
7943
- buffer.push(' class="' + options.className + '"');
7944
- buffer.push('>');
7945
- buffer.push(' <line');
7946
- buffer.push(' x1="' + this.a.x + '"');
7947
- buffer.push(' y1="' + this.a.y + '"');
7948
- buffer.push(' x2="' + vertices[0].x + '"');
7949
- buffer.push(' y2="' + vertices[0].y + '"');
7950
- buffer.push(' />');
7951
- // Add arrow head
7952
- buffer.push(' <polygon points="');
7953
- for (var i = 0; i < vertices.length; i++) {
7954
- if (i > 0)
7955
- buffer.push(' ');
7956
- buffer.push('' + vertices[i].x + ',' + vertices[i].y);
7957
- }
7958
- buffer.push('"/>');
7959
- buffer.push('</g>');
7960
- return buffer.join('');
7849
+ return new Vertex_1.Vertex(this.a.x + a * (this.b.x - this.a.x), this.a.y + a * (this.b.y - this.a.y));
7961
7850
  };
7962
- ;
7963
7851
  Vector.utils = {
7964
7852
  /**
7965
7853
  * Generate a four-point arrow head, starting at the vector end minus the
@@ -7989,10 +7877,10 @@ var Vector = /** @class */ (function (_super) {
7989
7877
  buildArrowHead: function (zA, zB, headlen, scaleX, scaleY) {
7990
7878
  var angle = Math.atan2((zB.y - zA.y) * scaleY, (zB.x - zA.x) * scaleX);
7991
7879
  var vertices = [];
7992
- vertices.push(new Vertex_1.Vertex(zB.x * scaleX - (headlen) * Math.cos(angle), zB.y * scaleY - (headlen) * Math.sin(angle)));
7993
- vertices.push(new Vertex_1.Vertex(zB.x * scaleX - (headlen * 1.35) * Math.cos(angle - Math.PI / 8), zB.y * scaleY - (headlen * 1.35) * Math.sin(angle - Math.PI / 8)));
7880
+ vertices.push(new Vertex_1.Vertex(zB.x * scaleX - headlen * Math.cos(angle), zB.y * scaleY - headlen * Math.sin(angle)));
7881
+ vertices.push(new Vertex_1.Vertex(zB.x * scaleX - headlen * 1.35 * Math.cos(angle - Math.PI / 8), zB.y * scaleY - headlen * 1.35 * Math.sin(angle - Math.PI / 8)));
7994
7882
  vertices.push(new Vertex_1.Vertex(zB.x * scaleX, zB.y * scaleY));
7995
- vertices.push(new Vertex_1.Vertex(zB.x * scaleX - (headlen * 1.35) * Math.cos(angle + Math.PI / 8), zB.y * scaleY - (headlen * 1.35) * Math.sin(angle + Math.PI / 8)));
7883
+ vertices.push(new Vertex_1.Vertex(zB.x * scaleX - headlen * 1.35 * Math.cos(angle + Math.PI / 8), zB.y * scaleY - headlen * 1.35 * Math.sin(angle + Math.PI / 8)));
7996
7884
  return vertices;
7997
7885
  }
7998
7886
  };
@@ -8017,7 +7905,8 @@ exports.Vector = Vector;
8017
7905
  * @modified 2020-12-04 Changed `getClosestT` param from `Vertex` to `XYCoords` (generalized).
8018
7906
  * @modified 2020-12-04 Added the `hasPoint(XYCoords)` function.
8019
7907
  * @modified 2021-01-20 Added UID.
8020
- * @version 1.1.0
7908
+ * @modified 2022-02-02 Added the `destroy` method.
7909
+ * @version 1.2.0
8021
7910
  */
8022
7911
  Object.defineProperty(exports, "__esModule", ({ value: true }));
8023
7912
  exports.VertTuple = void 0;
@@ -8055,7 +7944,6 @@ var VertTuple = /** @class */ (function () {
8055
7944
  VertTuple.prototype.length = function () {
8056
7945
  return Math.sqrt(Math.pow(this.b.x - this.a.x, 2) + Math.pow(this.b.y - this.a.y, 2));
8057
7946
  };
8058
- ;
8059
7947
  /**
8060
7948
  * Set the length of this vector to the given amount. This only works if this
8061
7949
  * vector is not a null vector.
@@ -8068,7 +7956,6 @@ var VertTuple = /** @class */ (function () {
8068
7956
  VertTuple.prototype.setLength = function (length) {
8069
7957
  return this.scale(length / this.length());
8070
7958
  };
8071
- ;
8072
7959
  /**
8073
7960
  * Substract the given vertex from this line's end points.
8074
7961
  *
@@ -8083,7 +7970,6 @@ var VertTuple = /** @class */ (function () {
8083
7970
  this.b.sub(amount);
8084
7971
  return this;
8085
7972
  };
8086
- ;
8087
7973
  /**
8088
7974
  * Add the given vertex to this line's end points.
8089
7975
  *
@@ -8098,7 +7984,6 @@ var VertTuple = /** @class */ (function () {
8098
7984
  this.b.add(amount);
8099
7985
  return this;
8100
7986
  };
8101
- ;
8102
7987
  /**
8103
7988
  * Normalize this line (set to length 1).
8104
7989
  *
@@ -8111,7 +7996,6 @@ var VertTuple = /** @class */ (function () {
8111
7996
  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());
8112
7997
  return this;
8113
7998
  };
8114
- ;
8115
7999
  /**
8116
8000
  * Scale this line by the given factor.
8117
8001
  *
@@ -8125,7 +8009,6 @@ var VertTuple = /** @class */ (function () {
8125
8009
  this.b.set(this.a.x + (this.b.x - this.a.x) * factor, this.a.y + (this.b.y - this.a.y) * factor);
8126
8010
  return this;
8127
8011
  };
8128
- ;
8129
8012
  /**
8130
8013
  * Move this line to a new location.
8131
8014
  *
@@ -8141,7 +8024,6 @@ var VertTuple = /** @class */ (function () {
8141
8024
  this.b.add(diff);
8142
8025
  return this;
8143
8026
  };
8144
- ;
8145
8027
  /**
8146
8028
  * Get the angle between this and the passed line (in radians).
8147
8029
  *
@@ -8152,7 +8034,7 @@ var VertTuple = /** @class */ (function () {
8152
8034
  * @memberof VertTuple
8153
8035
  **/
8154
8036
  VertTuple.prototype.angle = function (line) {
8155
- if (line == null || typeof line == 'undefined') {
8037
+ if (line == null || typeof line == "undefined") {
8156
8038
  line = this.factory(new Vertex_1.Vertex(0, 0), new Vertex_1.Vertex(100, 0));
8157
8039
  }
8158
8040
  // Compute the angle from x axis and the return the difference :)
@@ -8162,7 +8044,6 @@ var VertTuple = /** @class */ (function () {
8162
8044
  // The result might be negative, but isn't it usually nicer to determine angles in positive values only?
8163
8045
  return Math.atan2(v1.x, v1.y) - Math.atan2(v0.x, v0.y);
8164
8046
  };
8165
- ;
8166
8047
  /**
8167
8048
  * Get line point at position t in [0 ... 1]:<br>
8168
8049
  * <pre>[P(0)]=[A]--------------------[P(t)]------[B]=[P(1)]</pre><br>
@@ -8178,7 +8059,6 @@ var VertTuple = /** @class */ (function () {
8178
8059
  VertTuple.prototype.vertAt = function (t) {
8179
8060
  return new Vertex_1.Vertex(this.a.x + (this.b.x - this.a.x) * t, this.a.y + (this.b.y - this.a.y) * t);
8180
8061
  };
8181
- ;
8182
8062
  /**
8183
8063
  * Get the denominator of this and the given line.
8184
8064
  *
@@ -8192,9 +8072,8 @@ var VertTuple = /** @class */ (function () {
8192
8072
  **/
8193
8073
  VertTuple.prototype.denominator = function (line) {
8194
8074
  // http://jsfiddle.net/justin_c_rounds/Gd2S2/
8195
- 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));
8075
+ 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);
8196
8076
  };
8197
- ;
8198
8077
  /**
8199
8078
  * Checks if this and the given line are co-linear.
8200
8079
  *
@@ -8209,7 +8088,6 @@ var VertTuple = /** @class */ (function () {
8209
8088
  VertTuple.prototype.colinear = function (line) {
8210
8089
  return Math.abs(this.denominator(line)) < Vertex_1.Vertex.EPSILON;
8211
8090
  };
8212
- ;
8213
8091
  /**
8214
8092
  * Get the closest position T from this line to the specified point.
8215
8093
  *
@@ -8232,7 +8110,6 @@ var VertTuple = /** @class */ (function () {
8232
8110
  // t = Math.max(0, Math.min(1, t));
8233
8111
  return t;
8234
8112
  };
8235
- ;
8236
8113
  /**
8237
8114
  * Check if the given point is located on this line. Optionally also check if
8238
8115
  * that point is located between point `a` and `b`.
@@ -8268,7 +8145,6 @@ var VertTuple = /** @class */ (function () {
8268
8145
  var t = this.getClosestT(p);
8269
8146
  return this.vertAt(t);
8270
8147
  };
8271
- ;
8272
8148
  /**
8273
8149
  * The the minimal distance between this line and the specified point.
8274
8150
  *
@@ -8283,7 +8159,6 @@ var VertTuple = /** @class */ (function () {
8283
8159
  // https://stackoverflow.com/questions/849211/shortest-distance-between-a-point-and-a-line-segment
8284
8160
  return Math.sqrt(VertTuple.vtutils.dist2(p, this.vertAt(this.getClosestT(p))));
8285
8161
  };
8286
- ;
8287
8162
  /**
8288
8163
  * Create a deep clone of this instance.
8289
8164
  *
@@ -8295,7 +8170,6 @@ var VertTuple = /** @class */ (function () {
8295
8170
  VertTuple.prototype.clone = function () {
8296
8171
  return this.factory(this.a.clone(), this.b.clone());
8297
8172
  };
8298
- ;
8299
8173
  /**
8300
8174
  * Create a string representation of this line.
8301
8175
  *
@@ -8307,7 +8181,16 @@ var VertTuple = /** @class */ (function () {
8307
8181
  VertTuple.prototype.toString = function () {
8308
8182
  return "{ a : " + this.a.toString() + ", b : " + this.b.toString() + " }";
8309
8183
  };
8310
- ;
8184
+ /**
8185
+ * This function should invalidate any installed listeners and invalidate this object.
8186
+ * After calling this function the object might not hold valid data any more and
8187
+ * should not be used.
8188
+ */
8189
+ VertTuple.prototype.destroy = function () {
8190
+ this.a.destroy();
8191
+ this.b.destroy();
8192
+ this.isDestroyed = true;
8193
+ };
8311
8194
  /**
8312
8195
  * @private
8313
8196
  **/
@@ -8354,7 +8237,10 @@ exports.VertTuple = VertTuple;
8354
8237
  * @modified 2021-12-01 Changed the type of param of `scale` to XYCoords.
8355
8238
  * @modified 2021-12-01 Added function `scaleXY` for non uniform scaling.
8356
8239
  * @modified 2021-12-17 Added the functions `lerp` and `lerpAbs` for linear interpolations.
8357
- * @version 2.6.0
8240
+ * @modified 2022-01-31 Added `Vertex.utils.arrayToJSON`.
8241
+ * @modified 2022-02-02 Added the `destroy` method.
8242
+ * @modified 2022-02-02 Cleared the `Vertex.toSVGString` function (deprecated). Use `drawutilssvg` instead.
8243
+ * @version 2.7.0
8358
8244
  *
8359
8245
  * @file Vertex
8360
8246
  * @public
@@ -8846,28 +8732,14 @@ var Vertex = /** @class */ (function () {
8846
8732
  return "(" + this.x + "," + this.y + ")";
8847
8733
  };
8848
8734
  /**
8849
- * Convert this vertex to SVG code.
8850
- *
8851
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
8852
- * @method toSVGString
8853
- * @param {object=} options - An optional set of options, like 'className'.
8854
- * @return {string} A string representing the SVG code for this vertex.
8855
- * @instance
8856
- * @memberof Vertex
8857
- **/
8858
- Vertex.prototype.toSVGString = function (options) {
8859
- options = options || {};
8860
- var buffer = [];
8861
- buffer.push("<circle");
8862
- if (options.className)
8863
- buffer.push(' class="' + options.className + '"');
8864
- buffer.push(' cx="' + this.x + '"');
8865
- buffer.push(' cy="' + this.y + '"');
8866
- buffer.push(' r="2"');
8867
- buffer.push(" />");
8868
- return buffer.join("");
8735
+ * This function should invalidate any installed listeners and invalidate this object.
8736
+ * After calling this function the object might not hold valid data any more and
8737
+ * should not be used.
8738
+ */
8739
+ Vertex.prototype.destroy = function () {
8740
+ this.listeners.removeAllListeners();
8741
+ this.isDestroyed = true;
8869
8742
  };
8870
- // END Vertex
8871
8743
  /**
8872
8744
  * Create a new random vertex inside the given viewport.
8873
8745
  *
@@ -8921,6 +8793,19 @@ var Vertex = /** @class */ (function () {
8921
8793
  vertices.push(new Vertex(zB.x * scaleX, zB.y * scaleY));
8922
8794
  vertices.push(new Vertex(zB.x * scaleX - headlen * 1.35 * Math.cos(angle + Math.PI / 8), zB.y * scaleY - headlen * 1.35 * Math.sin(angle + Math.PI / 8)));
8923
8795
  return vertices;
8796
+ },
8797
+ /**
8798
+ * Convert the given vertices (array) to a JSON string.
8799
+ *
8800
+ * @param {number?} precision - (optional) The numeric precision to be used (number of precision digits).
8801
+ * @returns {string}
8802
+ */
8803
+ arrayToJSON: function (vertices, precision) {
8804
+ return JSON.stringify(vertices.map(function (vert) {
8805
+ return typeof precision === undefined
8806
+ ? { x: vert.x, y: vert.y }
8807
+ : { x: Number(vert.x.toFixed(precision)), y: Number(vert.y.toFixed(precision)) };
8808
+ }));
8924
8809
  }
8925
8810
  };
8926
8811
  return Vertex;
@@ -9034,7 +8919,6 @@ var VertexListeners = /** @class */ (function () {
9034
8919
  this.dragEnd = [];
9035
8920
  this.vertex = vertex;
9036
8921
  }
9037
- ;
9038
8922
  /**
9039
8923
  * Add a click listener.
9040
8924
  *
@@ -9048,7 +8932,6 @@ var VertexListeners = /** @class */ (function () {
9048
8932
  VertexListeners._addListener(this.click, listener);
9049
8933
  return this;
9050
8934
  };
9051
- ;
9052
8935
  /**
9053
8936
  * The click listener is a function with a single drag event param.
9054
8937
  * @callback VertexListeners~clickListener
@@ -9067,7 +8950,6 @@ var VertexListeners = /** @class */ (function () {
9067
8950
  this.click = VertexListeners._removeListener(this.click, listener);
9068
8951
  return this;
9069
8952
  };
9070
- ;
9071
8953
  /**
9072
8954
  * The click listener is a function with a single drag event param.
9073
8955
  * @callback VertexListeners~clickListener
@@ -9086,7 +8968,6 @@ var VertexListeners = /** @class */ (function () {
9086
8968
  VertexListeners._addListener(this.drag, listener);
9087
8969
  return this;
9088
8970
  };
9089
- ;
9090
8971
  /**
9091
8972
  * The drag listener is a function with a single drag event param.
9092
8973
  * @callback VertexListeners~dragListener
@@ -9105,7 +8986,6 @@ var VertexListeners = /** @class */ (function () {
9105
8986
  this.drag = VertexListeners._removeListener(this.drag, listener);
9106
8987
  return this;
9107
8988
  };
9108
- ;
9109
8989
  /**
9110
8990
  * Add a dragStart listener.
9111
8991
  *
@@ -9119,7 +8999,6 @@ var VertexListeners = /** @class */ (function () {
9119
8999
  VertexListeners._addListener(this.dragStart, listener);
9120
9000
  return this;
9121
9001
  };
9122
- ;
9123
9002
  /**
9124
9003
  * The drag-start listener is a function with a single drag event param.
9125
9004
  * @callback VertexListeners~dragStartListener
@@ -9138,7 +9017,6 @@ var VertexListeners = /** @class */ (function () {
9138
9017
  this.dragStart = VertexListeners._removeListener(this.dragStart, listener);
9139
9018
  return this;
9140
9019
  };
9141
- ;
9142
9020
  /**
9143
9021
  * Add a dragEnd listener.
9144
9022
  *
@@ -9153,27 +9031,25 @@ var VertexListeners = /** @class */ (function () {
9153
9031
  VertexListeners._addListener(this.dragEnd, listener);
9154
9032
  return this;
9155
9033
  };
9156
- ;
9157
9034
  /**
9158
9035
  * The drag-end listener is a function with a single drag event param.
9159
9036
  * @callback VertexListeners~dragEndListener
9160
9037
  * @param {Event} e - The (extended) drag event.
9161
9038
  */
9162
9039
  /**
9163
- * Remove a drag listener.
9164
- *
9165
- * @method removeDragEndListener
9166
- * @param {VertexListeners~clickListener} listener - The drag listener to remove (a callback).
9167
- * @return {VertexListeners} this (for chaining)
9168
- * @instance
9169
- * @memberof VertexListeners
9170
- **/
9040
+ * Remove a drag listener.
9041
+ *
9042
+ * @method removeDragEndListener
9043
+ * @param {VertexListeners~clickListener} listener - The drag listener to remove (a callback).
9044
+ * @return {VertexListeners} this (for chaining)
9045
+ * @instance
9046
+ * @memberof VertexListeners
9047
+ **/
9171
9048
  VertexListeners.prototype.removeDragEndListener = function (listener) {
9172
9049
  // this.drag.push( listener );
9173
9050
  this.dragEnd = VertexListeners._removeListener(this.dragEnd, listener);
9174
9051
  return this;
9175
9052
  };
9176
- ;
9177
9053
  /**
9178
9054
  * Fire a click event with the given event instance to all
9179
9055
  * installed click listeners.
@@ -9187,7 +9063,6 @@ var VertexListeners = /** @class */ (function () {
9187
9063
  VertexListeners.prototype.fireClickEvent = function (e) {
9188
9064
  VertexListeners._fireEvent(this, this.click, e);
9189
9065
  };
9190
- ;
9191
9066
  /**
9192
9067
  * Fire a drag event with the given event instance to all
9193
9068
  * installed drag listeners.
@@ -9201,7 +9076,6 @@ var VertexListeners = /** @class */ (function () {
9201
9076
  VertexListeners.prototype.fireDragEvent = function (e) {
9202
9077
  VertexListeners._fireEvent(this, this.drag, e);
9203
9078
  };
9204
- ;
9205
9079
  /**
9206
9080
  * Fire a dragStart event with the given event instance to all
9207
9081
  * installed drag-start listeners.
@@ -9215,7 +9089,6 @@ var VertexListeners = /** @class */ (function () {
9215
9089
  VertexListeners.prototype.fireDragStartEvent = function (e) {
9216
9090
  VertexListeners._fireEvent(this, this.dragStart, e);
9217
9091
  };
9218
- ;
9219
9092
  /**
9220
9093
  * Fire a dragEnd event with the given event instance to all
9221
9094
  * installed drag-end listeners.
@@ -9229,13 +9102,21 @@ var VertexListeners = /** @class */ (function () {
9229
9102
  VertexListeners.prototype.fireDragEndEvent = function (e) {
9230
9103
  VertexListeners._fireEvent(this, this.dragEnd, e);
9231
9104
  };
9232
- ;
9105
+ /**
9106
+ * Removes all listeners from this listeners object.
9107
+ */
9108
+ VertexListeners.prototype.removeAllListeners = function () {
9109
+ this.click = [];
9110
+ this.drag = [];
9111
+ this.dragStart = [];
9112
+ this.dragEnd = [];
9113
+ };
9233
9114
  /**
9234
9115
  * @private
9235
9116
  **/
9236
9117
  VertexListeners._fireEvent = function (_self, listeners, e) {
9237
9118
  var ve = e;
9238
- if (typeof ve.params == 'undefined')
9119
+ if (typeof ve.params == "undefined")
9239
9120
  ve.params = { vertex: _self.vertex };
9240
9121
  else
9241
9122
  ve.params.vertex = _self.vertex;
@@ -9243,7 +9124,6 @@ var VertexListeners = /** @class */ (function () {
9243
9124
  listeners[i](ve);
9244
9125
  }
9245
9126
  };
9246
- ;
9247
9127
  /**
9248
9128
  * @private
9249
9129
  */
@@ -9255,7 +9135,6 @@ var VertexListeners = /** @class */ (function () {
9255
9135
  listeners.push(newListener);
9256
9136
  return true;
9257
9137
  };
9258
- ;
9259
9138
  /**
9260
9139
  * @private
9261
9140
  */
@@ -9266,7 +9145,6 @@ var VertexListeners = /** @class */ (function () {
9266
9145
  }
9267
9146
  return listeners;
9268
9147
  };
9269
- ;
9270
9148
  return VertexListeners;
9271
9149
  }());
9272
9150
  exports.VertexListeners = VertexListeners;
@@ -9319,7 +9197,12 @@ exports.VertexListeners = VertexListeners;
9319
9197
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
9320
9198
  * @modified 2021-11-12 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
9321
9199
  * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
9322
- * @version 1.10.0
9200
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
9201
+ * @modified 2022-02-03 Added the `cross(...)` function.
9202
+ * @modified 2022-03-27 Added the `texturedPoly` function.
9203
+ * @modified 2022-06-01 Tweaked the `polyline` function; lineWidth now scales with scale.x.
9204
+ * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
9205
+ * @version 1.12.2
9323
9206
  **/
9324
9207
  Object.defineProperty(exports, "__esModule", ({ value: true }));
9325
9208
  exports.drawutils = void 0;
@@ -9461,16 +9344,19 @@ var drawutils = /** @class */ (function () {
9461
9344
  * @param {Image} image - The image object to draw.
9462
9345
  * @param {Vertex} position - The position to draw the the upper left corner at.
9463
9346
  * @param {Vertex} size - The x/y-size to draw the image with.
9347
+ * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
9464
9348
  * @return {void}
9465
9349
  * @instance
9466
9350
  * @memberof drawutils
9467
9351
  **/
9468
- drawutils.prototype.image = function (image, position, size) {
9352
+ drawutils.prototype.image = function (image, position, size, alpha) {
9353
+ if (alpha === void 0) { alpha = 1.0; }
9469
9354
  if (!image.complete || !image.naturalWidth) {
9470
9355
  // Avoid drawing un-unloaded or broken images
9471
9356
  return;
9472
9357
  }
9473
9358
  this.ctx.save();
9359
+ this.ctx.globalAlpha = alpha;
9474
9360
  // Note that there is a Safari bug with the 3 or 5 params variant.
9475
9361
  // Only the 9-param varaint works.
9476
9362
  this.ctx.drawImage(image, 0, 0, image.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
@@ -9478,6 +9364,97 @@ var drawutils = /** @class */ (function () {
9478
9364
  this.offset.x + position.x * this.scale.x, this.offset.y + position.y * this.scale.y, size.x * this.scale.x, size.y * this.scale.y);
9479
9365
  this.ctx.restore();
9480
9366
  };
9367
+ /**
9368
+ * Draw an image at the given position with the given size.<br>
9369
+ * <br>
9370
+ * Note: SVG images may have resizing issues at the moment.Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
9371
+ *
9372
+ * @method texturedPoly
9373
+ * @param {Image} textureImage - The image object to draw.
9374
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
9375
+ * @param {Polygon} polygon - The polygon to use as clip path.
9376
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
9377
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
9378
+ * @param {XYCoords={x:0,y:0}} rotationCenter - (optional) The rotational center; default is center of bounding box.
9379
+ * @return {void}
9380
+ * @instance
9381
+ * @memberof drawutils
9382
+ **/
9383
+ drawutils.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
9384
+ var basePolygonBounds = polygon.getBounds();
9385
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9386
+ // var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
9387
+ // var rotationalOffset = { x: 0, y: 0 };
9388
+ var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
9389
+ // Get the position offset of the polygon
9390
+ var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
9391
+ // var targetTextureOffset = new Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
9392
+ var targetTextureOffset = new Vertex_1.Vertex(textureSize.min.x, textureSize.min.y).sub(polygonPosition);
9393
+ this.ctx.save();
9394
+ // this.ctx.translate(this.offset.x + rotationCenter.x * this.scale.x, this.offset.y + rotationCenter.y * this.scale.y);
9395
+ this.ctx.translate(this.offset.x + polygonPosition.x * this.scale.x, this.offset.y + polygonPosition.y * this.scale.y);
9396
+ drawutils.helpers.clipPoly(this.ctx, {
9397
+ x: -polygonPosition.x * this.scale.x,
9398
+ y: -polygonPosition.y * this.scale.y
9399
+ }, this.scale, polygon.vertices);
9400
+ this.ctx.scale(this.scale.x, this.scale.y);
9401
+ this.ctx.rotate(rotation);
9402
+ this.ctx.drawImage(textureImage, 0, 0, textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
9403
+ textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
9404
+ targetTextureOffset.x, // * this.scale.x,
9405
+ targetTextureOffset.y, // * this.scale.y,
9406
+ targetTextureSize.x, // * this.scale.x,
9407
+ targetTextureSize.y // * this.scale.y
9408
+ );
9409
+ this.ctx.restore();
9410
+ };
9411
+ drawutils.prototype._texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation, rotationCenter) {
9412
+ if (rotationCenter === void 0) { rotationCenter = { x: 0, y: 0 }; }
9413
+ var basePolygonBounds = polygon.getBounds();
9414
+ var targetCenterDifference = polygonPosition.clone().difference(basePolygonBounds.getCenter());
9415
+ var rotationalOffset = rotationCenter ? polygonPosition.difference(rotationCenter) : { x: 0, y: 0 };
9416
+ // var rotationalOffset = { x: 0, y: 0 };
9417
+ var tileCenter = basePolygonBounds.getCenter().sub(targetCenterDifference);
9418
+ // Get the position offset of the polygon
9419
+ var targetTextureSize = new Vertex_1.Vertex(textureSize.width, textureSize.height);
9420
+ var targetTextureOffset = new Vertex_1.Vertex(-textureSize.width / 2, -textureSize.height / 2).sub(targetCenterDifference);
9421
+ this.ctx.save();
9422
+ // this.ctx.translate(
9423
+ // this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x,
9424
+ // this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y
9425
+ // );
9426
+ this.ctx.translate(this.offset.x + (tileCenter.x - rotationalOffset.x * 0 + targetTextureOffset.x * 0.0) * this.scale.x, this.offset.y + (tileCenter.y - rotationalOffset.y * 0 + targetTextureOffset.y * 0.0) * this.scale.y);
9427
+ this.ctx.rotate(rotation);
9428
+ drawutils.helpers.clipPoly(this.ctx, {
9429
+ x: (-targetCenterDifference.x * 1 - tileCenter.x - rotationalOffset.x) * this.scale.x,
9430
+ y: (-targetCenterDifference.y * 1 - tileCenter.y - rotationalOffset.y) * this.scale.y
9431
+ }, this.scale, polygon.vertices);
9432
+ this.ctx.drawImage(textureImage, 0, 0, textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
9433
+ textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
9434
+ (-polygonPosition.x + targetTextureOffset.x * 1 - rotationalOffset.x * 1) * this.scale.x, (-polygonPosition.y + targetTextureOffset.y * 1 - rotationalOffset.y * 1) * this.scale.y, targetTextureSize.x * this.scale.x, targetTextureSize.y * this.scale.y);
9435
+ // const scaledTextureSize = new Bounds(
9436
+ // new Vertex(
9437
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x,
9438
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y
9439
+ // ).scaleXY(this.scale, rotationCenter),
9440
+ // new Vertex(
9441
+ // -polygonPosition.x + targetTextureOffset.x - rotationalOffset.x + targetTextureSize.x,
9442
+ // -polygonPosition.y + targetTextureOffset.y - rotationalOffset.y + targetTextureSize.y
9443
+ // ).scaleXY(this.scale, rotationCenter)
9444
+ // );
9445
+ // this.ctx.drawImage(
9446
+ // textureImage,
9447
+ // 0,
9448
+ // 0,
9449
+ // textureImage.naturalWidth - 1, // There is this horrible Safari bug (fixed in newer versions)
9450
+ // textureImage.naturalHeight - 1, // To avoid errors substract 1 here.
9451
+ // scaledTextureSize.min.x,
9452
+ // scaledTextureSize.min.y,
9453
+ // scaledTextureSize.width,
9454
+ // scaledTextureSize.height
9455
+ // );
9456
+ this.ctx.restore();
9457
+ };
9481
9458
  /**
9482
9459
  * Draw a rectangle.
9483
9460
  *
@@ -9918,11 +9895,12 @@ var drawutils = /** @class */ (function () {
9918
9895
  * @param {XYCoords} center - The center of the crosshair.
9919
9896
  * @param {number} radius - The radius of the crosshair.
9920
9897
  * @param {string} color - The CSS color to draw the crosshair with.
9898
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
9921
9899
  * @return {void}
9922
9900
  * @instance
9923
9901
  * @memberof drawutils
9924
9902
  */
9925
- drawutils.prototype.crosshair = function (center, radius, color) {
9903
+ drawutils.prototype.crosshair = function (center, radius, color, lineWidth) {
9926
9904
  this.ctx.save();
9927
9905
  this.ctx.beginPath();
9928
9906
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y);
@@ -9930,7 +9908,34 @@ var drawutils = /** @class */ (function () {
9930
9908
  this.ctx.moveTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y - radius);
9931
9909
  this.ctx.lineTo(this.offset.x + center.x * this.scale.x, this.offset.y + center.y * this.scale.y + radius);
9932
9910
  this.ctx.strokeStyle = color;
9933
- this.ctx.lineWidth = 0.5;
9911
+ this.ctx.lineWidth = lineWidth || 0.5;
9912
+ this.ctx.stroke();
9913
+ this.ctx.closePath();
9914
+ this.ctx.restore();
9915
+ };
9916
+ /**
9917
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
9918
+ * <br>
9919
+ * Note that the x's radius will not be affected by scaling.
9920
+ *
9921
+ * @method crosshair
9922
+ * @param {XYCoords} center - The center of the crosshair.
9923
+ * @param {number} radius - The radius of the crosshair.
9924
+ * @param {string} color - The CSS color to draw the crosshair with.
9925
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
9926
+ * @return {void}
9927
+ * @instance
9928
+ * @memberof drawutils
9929
+ */
9930
+ drawutils.prototype.cross = function (center, radius, color, lineWidth) {
9931
+ this.ctx.save();
9932
+ this.ctx.beginPath();
9933
+ this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y - radius);
9934
+ this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y + radius);
9935
+ this.ctx.moveTo(this.offset.x + center.x * this.scale.x - radius, this.offset.y + center.y * this.scale.y + radius);
9936
+ this.ctx.lineTo(this.offset.x + center.x * this.scale.x + radius, this.offset.y + center.y * this.scale.y - radius);
9937
+ this.ctx.strokeStyle = color;
9938
+ this.ctx.lineWidth = lineWidth || 1.0;
9934
9939
  this.ctx.stroke();
9935
9940
  this.ctx.closePath();
9936
9941
  this.ctx.restore();
@@ -9962,11 +9967,12 @@ var drawutils = /** @class */ (function () {
9962
9967
  * @memberof drawutils
9963
9968
  */
9964
9969
  drawutils.prototype.polyline = function (vertices, isOpen, color, lineWidth) {
9965
- if (vertices.length <= 1)
9970
+ if (vertices.length <= 1) {
9966
9971
  return;
9972
+ }
9967
9973
  this.ctx.save();
9968
9974
  this.ctx.beginPath();
9969
- this.ctx.lineWidth = lineWidth || 1.0;
9975
+ this.ctx.lineWidth = lineWidth * this.scale.x || 1.0;
9970
9976
  this.ctx.moveTo(this.offset.x + vertices[0].x * this.scale.x, this.offset.y + vertices[0].y * this.scale.y);
9971
9977
  for (var i = 0; i < vertices.length; i++) {
9972
9978
  this.ctx.lineTo(this.offset.x + vertices[i].x * this.scale.x, this.offset.y + vertices[i].y * this.scale.y);
@@ -10107,6 +10113,21 @@ var drawutils = /** @class */ (function () {
10107
10113
  this.ctx.fillStyle = color;
10108
10114
  this.ctx.fillRect(0, 0, this.ctx.canvas.width, this.ctx.canvas.height);
10109
10115
  };
10116
+ drawutils.helpers = {
10117
+ // A helper function to define the clipping path.
10118
+ // This could be a candidate for the draw library.
10119
+ clipPoly: function (ctx, offset, scale, vertices) {
10120
+ ctx.beginPath();
10121
+ // Set clip mask
10122
+ ctx.moveTo(offset.x + vertices[0].x * scale.x, offset.y + vertices[0].y * scale.y);
10123
+ for (var i = 1; i < vertices.length; i++) {
10124
+ var vert = vertices[i];
10125
+ ctx.lineTo(offset.x + vert.x * scale.x, offset.y + vert.y * scale.y);
10126
+ }
10127
+ ctx.closePath();
10128
+ ctx.clip();
10129
+ }
10130
+ };
10110
10131
  return drawutils;
10111
10132
  }());
10112
10133
  exports.drawutils = drawutils;
@@ -10126,7 +10147,11 @@ exports.drawutils = drawutils;
10126
10147
  * @modified 2020-10-15 Re-added the text() function.
10127
10148
  * @modified 2021-01-24 Added the `setCurrentId` function.
10128
10149
  * @modified 2021-05-31 Added the `setConfiguration` function from `DrawLib`.
10129
- * @version 0.0.5
10150
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
10151
+ * @modified 2022-02-03 Added the `cross(...)` function.
10152
+ * @modified 2022-03-27 Added the `texturedPoly` function.
10153
+ * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
10154
+ * @version 0.0.8
10130
10155
  **/
10131
10156
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10132
10157
  exports.drawutilsgl = void 0;
@@ -10319,11 +10344,31 @@ var drawutilsgl = /** @class */ (function () {
10319
10344
  * @param {Image} image - The image object to draw.
10320
10345
  * @param {Vertex} position - The position to draw the the upper left corner at.
10321
10346
  * @param {Vertex} size - The x/y-size to draw the image with.
10347
+ * @param {number=0.0} alpha - (optional, default=0.0) The transparency (0.0=opaque, 1.0=transparent).
10322
10348
  * @return {void}
10323
10349
  * @instance
10324
10350
  * @memberof drawutils
10325
10351
  **/
10326
- drawutilsgl.prototype.image = function (image, position, size) {
10352
+ drawutilsgl.prototype.image = function (image, position, size, alpha) {
10353
+ if (alpha === void 0) { alpha = 0.0; }
10354
+ // NOT YET IMPLEMENTED
10355
+ };
10356
+ /**
10357
+ * Draw an image at the given position with the given size.<br>
10358
+ * <br>
10359
+ * Note: SVG images may have resizing issues at the moment.Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
10360
+ *
10361
+ * @method texturedPoly
10362
+ * @param {Image} textureImage - The image object to draw.
10363
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
10364
+ * @param {Polygon} polygon - The polygon to use as clip path.
10365
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
10366
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
10367
+ * @return {void}
10368
+ * @instance
10369
+ * @memberof drawutilsgl
10370
+ **/
10371
+ drawutilsgl.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
10327
10372
  // NOT YET IMPLEMENTED
10328
10373
  };
10329
10374
  // +---------------------------------------------------------------------------------
@@ -10607,11 +10652,29 @@ var drawutilsgl = /** @class */ (function () {
10607
10652
  * @param {XYCoords} center - The center of the crosshair.
10608
10653
  * @param {number} radius - The radius of the crosshair.
10609
10654
  * @param {string} color - The CSS color to draw the crosshair with.
10655
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
10610
10656
  * @return {void}
10611
10657
  * @instance
10612
10658
  * @memberof drawutils
10613
10659
  */
10614
- drawutilsgl.prototype.crosshair = function (center, radius, color) {
10660
+ drawutilsgl.prototype.crosshair = function (center, radius, color, lineWidth) {
10661
+ // NOT YET IMPLEMENTED
10662
+ };
10663
+ /**
10664
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
10665
+ * <br>
10666
+ * Note that the x's radius will not be affected by scaling.
10667
+ *
10668
+ * @method crosshair
10669
+ * @param {XYCoords} center - The center of the crosshair.
10670
+ * @param {number} radius - The radius of the crosshair.
10671
+ * @param {string} color - The CSS color to draw the crosshair with.
10672
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
10673
+ * @return {void}
10674
+ * @instance
10675
+ * @memberof drawutils
10676
+ */
10677
+ drawutilsgl.prototype.cross = function (center, radius, color, lineWidth) {
10615
10678
  // NOT YET IMPLEMENTED
10616
10679
  };
10617
10680
  /**
@@ -10850,13 +10913,19 @@ var GLU = /** @class */ (function () {
10850
10913
  * @modified 2021-11-15 Adding more parameters tot the `text()` function: fontSize, textAlign, fontFamily, lineHeight.
10851
10914
  * @modified 2021-11-19 Fixing the `label(text,x,y)` position.
10852
10915
  * @modified 2021-11-19 Added the `color` param to the `label(...)` function.
10853
- * @version 1.4.0
10916
+ * @modified 2022-02-03 Added the `lineWidth` param to the `crosshair` function.
10917
+ * @modified 2022-02-03 Added the `cross(...)` function.
10918
+ * @modified 2022-03-26 Added the private `nodeDefs` and `bufferedNodeDefs` attributes.
10919
+ * @modified 2022-03-26 Added the `texturedPoly` function to draw textures polygons.
10920
+ * @modified 2022-07-26 Adding `alpha` to the `image(...)` function.
10921
+ * @version 1.6.1
10854
10922
  **/
10855
10923
  Object.defineProperty(exports, "__esModule", ({ value: true }));
10856
10924
  exports.drawutilssvg = void 0;
10857
10925
  var CircleSector_1 = __webpack_require__(946);
10858
10926
  var CubicBezierCurve_1 = __webpack_require__(510);
10859
10927
  var Vertex_1 = __webpack_require__(421);
10928
+ var UIDGenerator_1 = __webpack_require__(197);
10860
10929
  var RAD_TO_DEG = 180 / Math.PI;
10861
10930
  /**
10862
10931
  * @classdesc A helper class for basic SVG drawing operations. This class should
@@ -10882,7 +10951,7 @@ var drawutilssvg = /** @class */ (function () {
10882
10951
  * @param {boolean=} isSecondary - (optional) Indicates if this is the primary or secondary instance. Only primary instances manage child nodes.
10883
10952
  * @param {SVGGElement=} gNode - (optional) Primary and seconday instances share the same &lt;g> node.
10884
10953
  **/
10885
- function drawutilssvg(svgNode, offset, scale, canvasSize, fillShapes, drawConfig, isSecondary, gNode, bufferGNode) {
10954
+ function drawutilssvg(svgNode, offset, scale, canvasSize, fillShapes, drawConfig, isSecondary, gNode, bufferGNode, nodeDefs, bufferNodeDefs) {
10886
10955
  this.svgNode = svgNode;
10887
10956
  this.offset = new Vertex_1.Vertex(0, 0).set(offset);
10888
10957
  this.scale = new Vertex_1.Vertex(1, 1).set(scale);
@@ -10894,14 +10963,23 @@ var drawutilssvg = /** @class */ (function () {
10894
10963
  if (isSecondary) {
10895
10964
  this.gNode = gNode;
10896
10965
  this.bufferGNode = bufferGNode;
10966
+ this.nodeDefs = nodeDefs;
10967
+ this.bufferedNodeDefs = bufferNodeDefs;
10897
10968
  }
10898
10969
  else {
10899
10970
  this.addStyleDefs(drawConfig);
10971
+ this.addDefsNode();
10900
10972
  this.gNode = this.createSVGNode("g");
10901
10973
  this.bufferGNode = this.createSVGNode("g");
10902
10974
  this.svgNode.appendChild(this.gNode);
10903
10975
  }
10904
10976
  }
10977
+ /**
10978
+ * Adds a default style defintion based on the passed DrawConfig.
10979
+ * Twaek the draw config to change default colors or line thicknesses.
10980
+ *
10981
+ * @param {DrawConfig} drawConfig
10982
+ */
10905
10983
  drawutilssvg.prototype.addStyleDefs = function (drawConfig) {
10906
10984
  this.nodeStyle = this.createSVGNode("style");
10907
10985
  this.svgNode.appendChild(this.nodeStyle);
@@ -10934,6 +11012,15 @@ var drawutilssvg = /** @class */ (function () {
10934
11012
  }
10935
11013
  this.nodeStyle.innerHTML = rules.join("\n");
10936
11014
  };
11015
+ /**
11016
+ * Adds the internal <defs> node.
11017
+ */
11018
+ drawutilssvg.prototype.addDefsNode = function () {
11019
+ this.nodeDefs = this.createSVGNode("defs");
11020
+ // this.svgNode.appendChild(this.nodeDefs);
11021
+ this.bufferedNodeDefs = this.createSVGNode("defs");
11022
+ this.svgNode.appendChild(this.nodeDefs);
11023
+ };
10937
11024
  /**
10938
11025
  * This is a simple way to include custom CSS class mappings to the style defs of the generated SVG.
10939
11026
  *
@@ -11071,7 +11158,7 @@ var drawutilssvg = /** @class */ (function () {
11071
11158
  drawutilssvg.prototype.copyInstance = function (fillShapes) {
11072
11159
  var copy = new drawutilssvg(this.svgNode, this.offset, this.scale, this.canvasSize, fillShapes, null, // no DrawConfig
11073
11160
  true, // isSecondary
11074
- this.gNode, this.bufferGNode);
11161
+ this.gNode, this.bufferGNode, this.nodeDefs, this.bufferedNodeDefs);
11075
11162
  return copy;
11076
11163
  };
11077
11164
  /**
@@ -11148,11 +11235,15 @@ var drawutilssvg = /** @class */ (function () {
11148
11235
  // layout updates.
11149
11236
  // Replace the old <g>-node with the buffer node.
11150
11237
  // https://stackoverflow.com/questions/27442464/how-to-update-a-svg-image-without-seeing-a-blinking
11238
+ this.svgNode.replaceChild(this.bufferedNodeDefs, this.nodeDefs);
11151
11239
  this.svgNode.replaceChild(this.bufferGNode, this.gNode);
11152
11240
  }
11153
- var tmp = this.gNode;
11241
+ var tmpGNode = this.gNode;
11154
11242
  this.gNode = this.bufferGNode;
11155
- this.bufferGNode = tmp;
11243
+ this.bufferGNode = tmpGNode;
11244
+ var tmpDefsNode = this.nodeDefs;
11245
+ this.nodeDefs = this.bufferedNodeDefs;
11246
+ this.bufferedNodeDefs = tmpDefsNode;
11156
11247
  };
11157
11248
  drawutilssvg.prototype._x = function (x) {
11158
11249
  return this.offset.x + this.scale.x * x;
@@ -11215,12 +11306,14 @@ var drawutilssvg = /** @class */ (function () {
11215
11306
  * @param {Image} image - The image object to draw.
11216
11307
  * @param {Vertex} position - The position to draw the the upper left corner at.
11217
11308
  * @param {Vertex} size - The x/y-size to draw the image with.
11309
+ * @param {number=0.0} alpha - (optional, default=0.0) The transparency (1.0=opaque, 0.0=transparent).
11218
11310
  * @return {void}
11219
11311
  * @instance
11220
11312
  * @memberof drawutilssvg
11221
11313
  **/
11222
- drawutilssvg.prototype.image = function (image, position, size) {
11314
+ drawutilssvg.prototype.image = function (image, position, size, alpha) {
11223
11315
  var _this = this;
11316
+ if (alpha === void 0) { alpha = 1.0; }
11224
11317
  var node = this.makeNode("image");
11225
11318
  // We need to re-adjust the image if it was not yet fully loaded before.
11226
11319
  var setImageSize = function (image) {
@@ -11230,6 +11323,9 @@ var drawutilssvg = /** @class */ (function () {
11230
11323
  node.setAttribute("width", "" + image.naturalWidth * _this.scale.x);
11231
11324
  node.setAttribute("height", "" + image.naturalHeight * _this.scale.y);
11232
11325
  node.setAttribute("display", null); // Dislay when loaded
11326
+ // if (alpha) {
11327
+ node.setAttribute("opacity", "" + alpha);
11328
+ // }
11233
11329
  node.setAttribute("transform", "translate(" + _this._x(position.x) + " " + _this._y(position.y) + ") scale(" + ratioX + " " + ratioY + ")");
11234
11330
  }
11235
11331
  };
@@ -11245,6 +11341,75 @@ var drawutilssvg = /** @class */ (function () {
11245
11341
  node.setAttribute("href", image.src);
11246
11342
  return this._bindFillDraw(node, "image", null, null);
11247
11343
  };
11344
+ /**
11345
+ * Draw an image at the given position with the given size.<br>
11346
+ * <br>
11347
+ * Note: SVG images may have resizing issues at the moment.Draw a line and an arrow at the end (zB) of the given line with the specified (CSS-) color.
11348
+ *
11349
+ * @method texturedPoly
11350
+ * @param {Image} textureImage - The image object to draw.
11351
+ * @param {Bounds} textureSize - The texture size to use; these are the original bounds to map the polygon vertices to.
11352
+ * @param {Polygon} polygon - The polygon to use as clip path.
11353
+ * @param {Vertex} polygonPosition - The polygon's position (relative), measured at the bounding box's center.
11354
+ * @param {number} rotation - The rotation to use for the polygon (and for the texture).
11355
+ * @return {void}
11356
+ * @instance
11357
+ * @memberof drawutilssvg
11358
+ **/
11359
+ drawutilssvg.prototype.texturedPoly = function (textureImage, textureSize, polygon, polygonPosition, rotation) {
11360
+ var basePolygonBounds = polygon.getBounds();
11361
+ var rotatedScalingOrigin = new Vertex_1.Vertex(textureSize.min).clone().rotate(rotation, polygonPosition);
11362
+ var rotationCenter = polygonPosition.clone().add(rotatedScalingOrigin.difference(textureSize.min).inv());
11363
+ // Create something like this
11364
+ // ...
11365
+ // <defs>
11366
+ // <clipPath id="shape">
11367
+ // <path fill="none" d="..."/>
11368
+ // </clipPath>
11369
+ // </defs>
11370
+ // ...
11371
+ // <g clip-path="url(#shape)">
11372
+ // <g transform="scale(...)">
11373
+ // <image width="643" height="643" transform="rotate(...)" xlink:href="https://s3-us-west-2.amazonaws.com/s.cdpn.io/222579/beagle400.jpg" >
11374
+ // </g>
11375
+ // </g>
11376
+ // </image>
11377
+ // ...
11378
+ var clipPathNode = this.makeNode("clipPath");
11379
+ var clipPathId = "clippath_" + UIDGenerator_1.UIDGenerator.next(); // TODO: use a better UUID generator here?
11380
+ clipPathNode.setAttribute("id", clipPathId);
11381
+ var gNode = this.makeNode("g");
11382
+ var imageNode = this.makeNode("image");
11383
+ imageNode.setAttribute("x", "" + this._x(rotatedScalingOrigin.x));
11384
+ imageNode.setAttribute("y", "" + this._y(rotatedScalingOrigin.y));
11385
+ imageNode.setAttribute("width", "" + textureSize.width);
11386
+ imageNode.setAttribute("height", "" + textureSize.height);
11387
+ imageNode.setAttribute("href", textureImage.src);
11388
+ // imageNode.setAttribute("opacity", "0.5");
11389
+ // SVG rotations in degrees
11390
+ imageNode.setAttribute("transform", "rotate(" + rotation * RAD_TO_DEG + ", " + this._x(rotatedScalingOrigin.x) + ", " + this._y(rotatedScalingOrigin.y) + ")");
11391
+ var pathNode = this.makeNode("path");
11392
+ var pathData = [];
11393
+ if (polygon.vertices.length > 0) {
11394
+ var self_1 = this;
11395
+ pathData.push("M", "" + this._x(polygon.vertices[0].x), "" + this._y(polygon.vertices[0].y));
11396
+ for (var i = 1; i < polygon.vertices.length; i++) {
11397
+ pathData.push("L", "" + this._x(polygon.vertices[i].x), "" + this._y(polygon.vertices[i].y));
11398
+ }
11399
+ }
11400
+ pathNode.setAttribute("d", pathData.join(" "));
11401
+ clipPathNode.appendChild(pathNode);
11402
+ this.bufferedNodeDefs.appendChild(clipPathNode);
11403
+ gNode.appendChild(imageNode);
11404
+ gNode.setAttribute("transform-origin", this._x(rotatedScalingOrigin.x) + " " + this._y(rotatedScalingOrigin.y));
11405
+ gNode.setAttribute("transform", "scale(" + this.scale.x + ", " + this.scale.y + ")");
11406
+ var clipNode = this.makeNode("g");
11407
+ clipNode.appendChild(gNode);
11408
+ clipNode.setAttribute("clip-path", "url(#" + clipPathId + ")");
11409
+ // TODO: check if the image class is correct here or if we should use a 'clippedImage' class here
11410
+ this._bindFillDraw(clipNode, "image", null, null); // No color, no lineWidth
11411
+ return clipNode;
11412
+ };
11248
11413
  /**
11249
11414
  * Draw the given (cubic) bézier curve.
11250
11415
  *
@@ -11637,11 +11802,12 @@ var drawutilssvg = /** @class */ (function () {
11637
11802
  * @param {XYCoords} center - The center of the crosshair.
11638
11803
  * @param {number} radius - The radius of the crosshair.
11639
11804
  * @param {string} color - The CSS color to draw the crosshair with.
11805
+ * @param {number=0.5} lineWidth - (optional, default=0.5) The line width to use.
11640
11806
  * @return {void}
11641
11807
  * @instance
11642
11808
  * @memberof drawutilssvg
11643
11809
  */
11644
- drawutilssvg.prototype.crosshair = function (center, radius, color) {
11810
+ drawutilssvg.prototype.crosshair = function (center, radius, color, lineWidth) {
11645
11811
  var node = this.makeNode("path");
11646
11812
  var d = [
11647
11813
  "M",
@@ -11658,7 +11824,40 @@ var drawutilssvg = /** @class */ (function () {
11658
11824
  this._y(center.y) + radius
11659
11825
  ];
11660
11826
  node.setAttribute("d", d.join(" "));
11661
- return this._bindFillDraw(node, "crosshair", color, 0.5);
11827
+ return this._bindFillDraw(node, "crosshair", color, lineWidth || 0.5);
11828
+ };
11829
+ /**
11830
+ * Draw a cross with diagonal axes with given radius, color and lineWidth at the given position.<br>
11831
+ * <br>
11832
+ * Note that the x's radius will not be affected by scaling.
11833
+ *
11834
+ * @method crosshair
11835
+ * @param {XYCoords} center - The center of the crosshair.
11836
+ * @param {number} radius - The radius of the crosshair.
11837
+ * @param {string} color - The CSS color to draw the crosshair with.
11838
+ * @param {number=1} lineWidth - (optional, default=1.0) The line width to use.
11839
+ * @return {void}
11840
+ * @instance
11841
+ * @memberof drawutils
11842
+ */
11843
+ drawutilssvg.prototype.cross = function (center, radius, color, lineWidth) {
11844
+ var node = this.makeNode("path");
11845
+ var d = [
11846
+ "M",
11847
+ this._x(center.x) - radius,
11848
+ this._y(center.y) - radius,
11849
+ "L",
11850
+ this._x(center.x) + radius,
11851
+ this._y(center.y) + radius,
11852
+ "M",
11853
+ this._x(center.x) - radius,
11854
+ this._y(center.y) + radius,
11855
+ "L",
11856
+ this._x(center.x) + radius,
11857
+ this._y(center.y) - radius
11858
+ ];
11859
+ node.setAttribute("d", d.join(" "));
11860
+ return this._bindFillDraw(node, "cross", color, lineWidth || 1.0);
11662
11861
  };
11663
11862
  /**
11664
11863
  * Draw a polygon.
@@ -11821,14 +12020,6 @@ var drawutilssvg = /** @class */ (function () {
11821
12020
  if (this.isSecondary) {
11822
12021
  return;
11823
12022
  }
11824
- // // Clearing an SVG is equivalent to removing all its child elements.
11825
- // for (var i = 0; i < this.gNode.childNodes.length; i++) {
11826
- // // Hide all nodes here. Don't throw them away.
11827
- // // We can probably re-use them in the next draw cycle.
11828
- // var child: SVGElement = this.gNode.childNodes[i] as SVGElement;
11829
- // this.cache.set(child.getAttribute("id"), child);
11830
- // }
11831
- // this.removeAllChildNodes();
11832
12023
  // Add a covering rect with the given background color
11833
12024
  this.curId = "background";
11834
12025
  this.curClassName = undefined;
@@ -11854,6 +12045,9 @@ var drawutilssvg = /** @class */ (function () {
11854
12045
  while (this.bufferGNode.lastChild) {
11855
12046
  this.bufferGNode.removeChild(this.bufferGNode.lastChild);
11856
12047
  }
12048
+ while (this.bufferedNodeDefs.lastChild) {
12049
+ this.bufferedNodeDefs.removeChild(this.bufferedNodeDefs.lastChild);
12050
+ }
11857
12051
  };
11858
12052
  /**
11859
12053
  * Create a new and empty `SVGElement` &lt;svg&gt; in the svg-namespace.