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
package/src/ts/PBImage.ts CHANGED
@@ -4,20 +4,20 @@
4
4
  * @modified 2019-03-23 Added JSDoc tags.
5
5
  * @modified 2020-03-25 Ported this class from vanilla-JS to Typescript.
6
6
  * @modified 2021-01-20 Added UID.
7
- * @version 1.1.0
7
+ * @modified 2022-02-02 Added the `destroy` method.
8
+ * @modified 2022-02-02 Cleared the `PBImage.toSVGString` function (deprecated). Use `drawutilssvg` instead.
9
+ * @version 1.2.0
8
10
  *
9
11
  * @file PBImage
10
- * @fileoverview As native Image objects have only a position and with
12
+ * @fileoverview As native Image objects have only a position and with
11
13
  * and height thei are not suitable for UI dragging interfaces.
12
14
  * @public
13
15
  **/
14
16
 
15
-
16
17
  import { Vertex } from "./Vertex";
17
18
  import { UIDGenerator } from "./UIDGenerator";
18
19
  import { SVGSerializable, UID } from "./interfaces";
19
20
 
20
-
21
21
  /**
22
22
  * @classdesc A wrapper for image objects. Has an upper left and a lower right corner point.
23
23
  *
@@ -27,76 +27,74 @@ import { SVGSerializable, UID } from "./interfaces";
27
27
  * @requires UIDGenerator
28
28
  */
29
29
  export class PBImage implements SVGSerializable {
30
+ /**
31
+ * Required to generate proper CSS classes and other class related IDs.
32
+ **/
33
+ readonly className: string = "PBImage";
30
34
 
35
+ /**
36
+ * The UID of this drawable object.
37
+ *
38
+ * @member {UID}
39
+ * @memberof PBImage
40
+ * @instance
41
+ * @readonly
42
+ */
43
+ readonly uid: UID;
31
44
 
32
- /**
33
- * Required to generate proper CSS classes and other class related IDs.
34
- **/
35
- readonly className : string = "PBImage";
36
-
45
+ /**
46
+ * @member {Vertex}
47
+ * @memberof PBImage
48
+ * @instance
49
+ */
50
+ image: HTMLImageElement;
37
51
 
38
- /**
39
- * The UID of this drawable object.
40
- *
41
- * @member {UID}
42
- * @memberof PBImage
43
- * @instance
44
- * @readonly
45
- */
46
- readonly uid : UID;
47
-
52
+ /**
53
+ * @member {Vertex}
54
+ * @memberof PBImage
55
+ * @instance
56
+ */
57
+ upperLeft: Vertex;
48
58
 
49
- /**
50
- * @member {Vertex}
51
- * @memberof PBImage
52
- * @instance
53
- */
54
- image:HTMLImageElement;
59
+ /**
60
+ * @member {Vertex}
61
+ * @memberof PBImage
62
+ * @instance
63
+ */
64
+ lowerRight: Vertex;
55
65
 
56
- /**
57
- * @member {Vertex}
58
- * @memberof PBImage
59
- * @instance
60
- */
61
- upperLeft:Vertex;
66
+ /**
67
+ * @member isDestroyed
68
+ * @memberof PBImage
69
+ * @type {boolean}
70
+ * @instance
71
+ */
72
+ isDestroyed: boolean;
62
73
 
63
- /**
64
- * @member {Vertex}
65
- * @memberof PBImage
66
- * @instance
67
- */
68
- lowerRight:Vertex;
69
-
70
-
71
- /**
72
- * The constructor.
73
- *
74
- * @constructor
75
- * @name PBImage
76
- * @param {Image} image - The actual image.
77
- * @param {Vertex} upperLeft - The upper left corner.
78
- * @param {Vertex} lowerRight - The lower right corner.
79
- **/
80
- constructor( image:HTMLImageElement, upperLeft:Vertex, lowerRight:Vertex ) {
81
- this.uid = UIDGenerator.next();
82
- this.image = image;
83
- this.upperLeft = upperLeft;
84
- this.lowerRight = lowerRight;
85
- };
74
+ /**
75
+ * The constructor.
76
+ *
77
+ * @constructor
78
+ * @name PBImage
79
+ * @param {Image} image - The actual image.
80
+ * @param {Vertex} upperLeft - The upper left corner.
81
+ * @param {Vertex} lowerRight - The lower right corner.
82
+ **/
83
+ constructor(image: HTMLImageElement, upperLeft: Vertex, lowerRight: Vertex) {
84
+ this.uid = UIDGenerator.next();
85
+ this.image = image;
86
+ this.upperLeft = upperLeft;
87
+ this.lowerRight = lowerRight;
88
+ }
86
89
 
87
-
88
- /**
89
- * Convert this vertex to SVG code.
90
- *
91
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
92
- * @method toSVGString
93
- * @param {object=} options - An optional set of options, like 'className'.
94
- * @return {string} A string representing the SVG code for this vertex.
95
- * @instance
96
- * @memberof PBImage
97
- **/
98
- toSVGString( options:{ className?:string } ) : string {
99
- console.warn( "PBImage is not yet SVG serializable. Returning empty SVG string." );
100
- return "";
101
- };
90
+ /**
91
+ * This function should invalidate any installed listeners and invalidate this object.
92
+ * After calling this function the object might not hold valid data any more and
93
+ * should not be used.
94
+ */
95
+ destroy() {
96
+ this.upperLeft.destroy();
97
+ this.lowerRight.destroy();
98
+ this.isDestroyed = true;
99
+ }
102
100
  }
package/src/ts/PBText.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * @author Ikaros Kappler
3
3
  * @date 2021-11-16
4
- * @version 1.0.0
4
+ * @modified 2022-02-02 Added the `destroy` method.
5
+ * @version 1.1.0
5
6
  **/
6
7
 
7
8
  import { UIDGenerator } from "./UIDGenerator";
@@ -106,6 +107,14 @@ export class PBText implements SVGSerializable, FontOptions {
106
107
  */
107
108
  color: string | undefined;
108
109
 
110
+ /**
111
+ * @member isDestroyed
112
+ * @memberof PBText
113
+ * @type {boolean}
114
+ * @instance
115
+ */
116
+ isDestroyed: boolean;
117
+
109
118
  /**
110
119
  * Create a new circle with given center point and radius.
111
120
  *
@@ -129,19 +138,12 @@ export class PBText implements SVGSerializable, FontOptions {
129
138
  }
130
139
 
131
140
  /**
132
- * Create an SVG representation of this circle.
133
- *
134
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
135
- * @method toSVGString
136
- * @param {object=} options - An optional set of options, like 'className'.
137
- * @return {string} A string representing the SVG code for this vertex.
138
- * @instance
139
- * @memberof Circle
141
+ * This function should invalidate any installed listeners and invalidate this object.
142
+ * After calling this function the object might not hold valid data any more and
143
+ * should not be used.
140
144
  */
141
- toSVGString(options: { className?: string }) {
142
- console.warn(
143
- "[PBText.toSVGString()] This function is not implemented as it defines a deprecated method. Use the 'drawutilssvg.text()' method instead."
144
- );
145
- return "";
145
+ destroy() {
146
+ this.anchor.destroy();
147
+ this.isDestroyed = true;
146
148
  }
147
149
  } // END class
@@ -74,7 +74,8 @@
74
74
  * @modified 2021-03-29 Clearing `currentClassName` and `currentId` after drawing each drawable.
75
75
  * @modified 2021-04-25 Extending `remove` to accept arrays of drawables.
76
76
  * @modified 2021-11-16 Adding the `PBText` drawable.
77
- * @version 1.15.0
77
+ * @modified 2022-08-01 Added `title` to the params.
78
+ * @version 1.15.1
78
79
  *
79
80
  * @file PlotBoilerplate
80
81
  * @fileoverview The main class.
@@ -376,6 +377,7 @@ export class PlotBoilerplate {
376
377
  * @param {boolean=} [config.enableGL=false] - Indicates if the application should use the experimental WebGL features (not recommended).
377
378
  * @param {boolean=} [config.enableSVGExport=true] - Indicates if the SVG export should be enabled (default is true).
378
379
  * Note that changes from the postDraw hook might not be visible in the export.
380
+ * @param {string=} [config.title=null] - Specify any hover tile here. It will be attached as a `title` attribute to the most elevated element.
379
381
  */
380
382
  constructor(config: PBParams) {
381
383
  // This should be in some static block ...
@@ -592,6 +594,11 @@ export class PlotBoilerplate {
592
594
  } else {
593
595
  throw "Element is neither a canvas nor an svg element.";
594
596
  }
597
+ // At this point the event cacher element is deinfed and located at highest elevation.
598
+ // Set `title` attribut?
599
+ if (config.title) {
600
+ this.eventCatcher.setAttribute("title", config.title);
601
+ }
595
602
  this.draw.scale.set(this.config.scaleX, this.config.scaleY);
596
603
  this.fill.scale.set(this.config.scaleX, this.config.scaleY);
597
604
  this.vertices = [];
@@ -897,7 +904,7 @@ export class PlotBoilerplate {
897
904
  }
898
905
  }
899
906
  for (var i = 0; i < this.drawables.length; i++) {
900
- if (this.drawables[i] === drawable) {
907
+ if (this.drawables[i] === drawable || this.drawables[i].uid === drawable.uid) {
901
908
  this.drawables.splice(i, 1);
902
909
 
903
910
  if (removeWithVertices) {
package/src/ts/Polygon.ts CHANGED
@@ -21,7 +21,10 @@
21
21
  * @modified 2021-01-29 Changed the param type for `containsVert` from Vertex to XYCoords.
22
22
  * @modified 2021-12-14 Added the `perimeter()` function.
23
23
  * @modified 2021-12-16 Added the `getEvenDistributionPolygon()` function.
24
- * @version 1.8.0
24
+ * @modified 2022-02-02 Added the `destroy` method.
25
+ * @modified 2022-02-02 Cleared the `Polygon.toSVGString` function (deprecated). Use `drawutilssvg` instead.
26
+ * @modified 2022-03-08 Added the `Polygon.clone()` function.
27
+ * @version 1.10.0
25
28
  *
26
29
  * @file Polygon
27
30
  * @public
@@ -76,6 +79,14 @@ export class Polygon implements SVGSerializable {
76
79
  */
77
80
  isOpen: boolean;
78
81
 
82
+ /**
83
+ * @member isDestroyed
84
+ * @memberof Polygon
85
+ * @type {boolean}
86
+ * @instance
87
+ */
88
+ isDestroyed: boolean;
89
+
79
90
  /**
80
91
  * The constructor.
81
92
  *
@@ -133,9 +144,9 @@ export class Polygon implements SVGSerializable {
133
144
  * @memberof Polygon
134
145
  * @return {Polygon} this for chaining
135
146
  **/
136
- move(vert: XYCoords): Polygon {
147
+ move(amount: XYCoords): Polygon {
137
148
  for (var i in this.vertices) {
138
- this.vertices[i].add(vert);
149
+ this.vertices[i].add(amount);
139
150
  }
140
151
  return this;
141
152
  }
@@ -326,6 +337,18 @@ export class Polygon implements SVGSerializable {
326
337
  return Bounds.computeFromVertices(this.vertices);
327
338
  }
328
339
 
340
+ /**
341
+ * Create a deep copy of this polygon.
342
+ *
343
+ * @return {Polygon} The cloned polygon.
344
+ */
345
+ clone(): Polygon {
346
+ return new Polygon(
347
+ this.vertices.map(vert => vert.clone()),
348
+ this.isOpen
349
+ );
350
+ }
351
+
329
352
  /**
330
353
  * Convert this polygon to a sequence of quadratic Bézier curves.<br>
331
354
  * <br>
@@ -470,38 +493,15 @@ export class Polygon implements SVGSerializable {
470
493
  }
471
494
 
472
495
  /**
473
- * Create an SVG representation of this polygon.
474
- *
475
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
476
- * @method toSVGString
477
- * @param {object=} options - An optional set of options, like 'className'.
478
- * @return {string} The SVG string.
479
- * @instance
480
- * @memberof Polygon
481
- **/
482
- toSVGString(options: { className?: string } | undefined): string {
483
- options = options || {};
484
- var buffer: Array<string> = [];
485
- buffer.push("<path");
486
- if (options.className) buffer.push(' class="' + options.className + '"');
487
- buffer.push(' d="');
488
- if (this.vertices.length > 0) {
489
- buffer.push("M ");
490
- buffer.push(this.vertices[0].x.toString());
491
- buffer.push(" ");
492
- buffer.push(this.vertices[0].y.toString());
493
- for (var i = 1; i < this.vertices.length; i++) {
494
- buffer.push(" L ");
495
- buffer.push(this.vertices[i].x.toString());
496
- buffer.push(" ");
497
- buffer.push(this.vertices[i].y.toString());
498
- }
499
- if (!this.isOpen) {
500
- buffer.push(" Z");
501
- }
496
+ * This function should invalidate any installed listeners and invalidate this object.
497
+ * After calling this function the object might not hold valid data any more and
498
+ * should not be used.
499
+ */
500
+ destroy() {
501
+ for (var i = 0; i < this.vertices.length; i++) {
502
+ this.vertices[i].destroy();
502
503
  }
503
- buffer.push('" />');
504
- return buffer.join("");
504
+ this.isDestroyed = true;
505
505
  }
506
506
 
507
507
  static utils = {