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
@@ -20,7 +20,10 @@
20
20
  * @modified 2020-07-24 Added the getClosestT(Vertex) function.
21
21
  * @modified 2020-12-29 Constructor is now private (no explicit use intended).
22
22
  * @modified 2021-05-25 Added BezierPath.fromReducedList( Array<number> ).
23
- * @version 2.3.1
23
+ * @modified 2022-01-31 Added `BezierPath.getEvenDistributionVertices(number)`.
24
+ * @modified 2022-02-02 Added the `destroy` method.
25
+ * @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
26
+ * @version 2.5.0
24
27
  *
25
28
  * @file BezierPath
26
29
  * @public
@@ -96,6 +99,14 @@ export class BezierPath implements SVGSerializable {
96
99
  */
97
100
  bezierCurves: Array<CubicBezierCurve>;
98
101
 
102
+ /**
103
+ * @member {boolean}
104
+ * @memberof BezierPath
105
+ * @type {boolean}
106
+ * @instance
107
+ */
108
+ isDestroyed: boolean;
109
+
99
110
  // +---------------------------------------------------------------------------------
100
111
  // | These constants equal the values from CubicBezierCurve.
101
112
  // +-------------------------------
@@ -1054,6 +1065,64 @@ export class BezierPath implements SVGSerializable {
1054
1065
  return new Bounds(min, max);
1055
1066
  }
1056
1067
 
1068
+ /**
1069
+ * Get n 'equally' distributed vertices along this Bézier path.
1070
+ *
1071
+ * As the changing curvature of the B slines makes prediction of distances difficult, the
1072
+ * returned vertices' distances are only relatively equal:
1073
+ * - the distance grows where curvature is large.
1074
+ * - the distance shrinks where curvature is small.
1075
+ *
1076
+ * Only the distance mean of all consecutive is 1/n-th of the total arc length.
1077
+ *
1078
+ * Usually this approximation is good enough for most use cases.
1079
+ *
1080
+ * @param {number} pointCount - (must be at least 2) The number of desired points (start and end point included).
1081
+ * @return {Array<Vertex>}
1082
+ */
1083
+ getEvenDistributionVertices(pointCount: number): Array<Vertex> {
1084
+ if (pointCount < 2) {
1085
+ throw new Error("pointCount must be larger than one; is " + pointCount + ".");
1086
+ }
1087
+
1088
+ const result: Array<Vertex> = [];
1089
+ if (this.bezierCurves.length === 0) {
1090
+ return result;
1091
+ }
1092
+
1093
+ // Fetch and add the start point from the source polygon
1094
+ var polygonPoint = new Vertex(this.bezierCurves[0].startPoint);
1095
+ result.push(polygonPoint);
1096
+ // if (this.bezierCurves.length === 1) {
1097
+ // return result;
1098
+ // }
1099
+
1100
+ const perimeter: number = this.totalArcLength;
1101
+ const stepSize: number = perimeter / (pointCount - 1);
1102
+ const n: number = this.bezierCurves.length;
1103
+
1104
+ let curveIndex: number = 0;
1105
+ let segmentLength: number = this.bezierCurves[0].arcLength;
1106
+ let curSegmentU: number = stepSize;
1107
+ let i: number = 1;
1108
+ while (i < pointCount && curveIndex < n) {
1109
+ // Check if next eq point is inside this segment
1110
+ if (curSegmentU < segmentLength) {
1111
+ var newPoint = this.bezierCurves[curveIndex].getPoint(curSegmentU);
1112
+ result.push(newPoint);
1113
+ curSegmentU += stepSize;
1114
+ i++;
1115
+ } else {
1116
+ curveIndex++;
1117
+ curSegmentU = curSegmentU - segmentLength;
1118
+ segmentLength = curveIndex < n ? this.bezierCurves[curveIndex].arcLength : 0;
1119
+ }
1120
+ }
1121
+
1122
+ result.push(new Vertex(this.bezierCurves[n - 1].endPoint));
1123
+ return result;
1124
+ }
1125
+
1057
1126
  /**
1058
1127
  * Clone this BezierPath (deep clone).
1059
1128
  *
@@ -1096,28 +1165,15 @@ export class BezierPath implements SVGSerializable {
1096
1165
  }
1097
1166
 
1098
1167
  /**
1099
- * Create a <pre>&lt;path&gt;</pre> SVG representation of this bézier curve.
1100
- *
1101
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
1102
- * @method toSVGString
1103
- * @param {object=} [options={}] - Like options.className
1104
- * @param {string=} [options.className] - The classname to use for the SVG item.
1105
- * @instance
1106
- * @memberof BezierPath
1107
- * @return {string} The SVG string.
1108
- **/
1109
- toSVGString(options: { className?: string }): string {
1110
- options = options || {};
1111
- var buffer: Array<string> = [];
1112
- buffer.push("<path");
1113
- if (options.className) buffer.push(' class="' + options.className + '"');
1114
- buffer.push(' d="');
1115
- for (var c = 0; c < this.bezierCurves.length; c++) {
1116
- if (c > 0) buffer.push(" ");
1117
- buffer.push(this.bezierCurves[c].toSVGPathData());
1168
+ * This function should invalidate any installed listeners and invalidate this object.
1169
+ * After calling this function the object might not hold valid data any more and
1170
+ * should not be used.
1171
+ */
1172
+ destroy() {
1173
+ for (var i = 0; i < this.bezierCurves.length; i++) {
1174
+ this.bezierCurves[i].destroy();
1118
1175
  }
1119
- buffer.push('" />');
1120
- return buffer.join("");
1176
+ this.isDestroyed = true;
1121
1177
  }
1122
1178
 
1123
1179
  /**
package/src/ts/Bounds.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  * @modified 2020-11-19 Set min, max, width and height to private.
6
6
  * @modified 2021-02-02 Added the `toPolygon` method.
7
7
  * @modified 2021-06-21 (mid-summer) Added `getCenter` method.
8
- * @version 1.3.0
8
+ * @modified 2022-02-01 Added the `toString` function.
9
+ * @version 1.4.0
9
10
  **/
10
11
 
11
12
  import { Polygon } from "./Polygon";
@@ -82,10 +83,48 @@ export class Bounds implements IBounds, XYDimension {
82
83
  );
83
84
  }
84
85
 
86
+ /**
87
+ * Get the center of this boinding box.
88
+ *
89
+ * @method getCenter
90
+ * @instance
91
+ * @memberof Bounds
92
+ * @returns {Vertex} The center of these bounds.
93
+ */
85
94
  getCenter(): Vertex {
86
95
  return new Vertex(this.min.x + (this.max.x - this.min.x) / 2.0, this.min.y + (this.max.y - this.min.y) / 2);
87
96
  }
88
97
 
98
+ /**
99
+ * Convert these bounds to a human readable form.
100
+ *
101
+ * Note: the returned format might change in the future, so please do not
102
+ * rely on the returned string format.
103
+ *
104
+ * @method toString
105
+ * @instance
106
+ * @memberof Bounds
107
+ * @returns {string} Get these bounds in a human readable form.
108
+ */
109
+ toString(): string {
110
+ return `{ min: ${this.min.toString()}, max : ${this.max.toString()}, width: ${this.width}, height : ${this.height} }`;
111
+ }
112
+
113
+ /**
114
+ * Clone this bounds object (create a deep clone).
115
+ *
116
+ * Note: the returned format might change in the future, so please do not
117
+ * rely on the returned string format.
118
+ *
119
+ * @method clone
120
+ * @instance
121
+ * @memberof Bounds
122
+ * @returns {string} Creates a deep clone of this bounds object. The returned object's `min` and `max` instances are `Vertex` instances.
123
+ */
124
+ // clone() {
125
+ // return new Bounds(new Vertex(this.min.x, this.min.y), new Vertex(this.max.x, this.max.y));
126
+ // }
127
+
89
128
  /**
90
129
  * Compute the minimal bounding box for a given set of vertices.
91
130
  *
package/src/ts/Circle.ts CHANGED
@@ -7,10 +7,11 @@
7
7
  * @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.
8
8
  * @modified 2020-10-16 Added the containsCircle(...) function.
9
9
  * @modified 2021-01-20 Added UID.
10
- * @version 1.2.0
10
+ * @modified 2022-02-02 Added the `destroy` method.
11
+ * @modified 2022-02-02 Cleared the `toSVGString` function (deprecated). Use `drawutilssvg` instead.
12
+ * @version 1.3.0
11
13
  **/
12
14
 
13
-
14
15
  import { Line } from "./Line";
15
16
  import { UIDGenerator } from "./UIDGenerator";
16
17
  import { Vector } from "./Vector";
@@ -18,214 +19,200 @@ import { VertTuple } from "./VertTuple";
18
19
  import { Vertex } from "./Vertex";
19
20
  import { SVGSerializable, UID } from "./interfaces";
20
21
 
21
-
22
22
  /**
23
23
  * @classdesc A simple circle: center point and radius.
24
24
  *
25
25
  * @requires Line
26
26
  * @requires Vector
27
- * @requires VertTuple
27
+ * @requires VertTuple
28
28
  * @requires Vertex
29
29
  * @requires SVGSerializale
30
30
  * @requires UID
31
31
  * @requires UIDGenerator
32
32
  **/
33
33
  export class Circle implements SVGSerializable {
34
-
35
- /**
36
- * Required to generate proper CSS classes and other class related IDs.
37
- **/
38
- readonly className : string = "Circle";
39
-
40
- /**
41
- * The UID of this drawable object.
42
- *
43
- * @member {UID}
44
- * @memberof Circle
45
- * @instance
46
- * @readonly
47
- */
48
- readonly uid : UID;
49
-
50
-
51
- /**
52
- * @member {Vertex}
53
- * @memberof Circle
54
- * @instance
55
- */
56
- center:Vertex;
57
-
58
- /**
59
- * @member {number}
60
- * @memberof Circle
61
- * @instance
62
- */
63
- radius:number;
64
-
65
-
66
- /**
67
- * Create a new circle with given center point and radius.
68
- *
69
- * @constructor
70
- * @name Circle
71
- * @param {Vertex} center - The center point of the circle.
72
- * @param {number} radius - The radius of the circle.
73
- */
74
- constructor( center:Vertex, radius:number ) {
75
- this.uid = UIDGenerator.next();
76
- this.center = center;
77
- this.radius = radius;
78
- };
79
-
80
-
81
- /**
82
- * Check if the given circle is fully contained inside this circle.
83
- *
84
- * @method containsCircle
85
- * @param {Circle} circle - The circle to check if it is contained in this circle.
86
- * @instance
87
- * @memberof Circle
88
- * @return {boolean} `true` if any only if the given circle is completely inside this circle.
89
- */
90
- containsCircle( circle:Circle ) : boolean {
91
- return this.center.distance(circle.center) + circle.radius < this.radius;
92
- };
93
-
94
-
95
- /**
96
- * Calculate the distance from this circle to the given line.
97
- *
98
- * * If the line does not intersect this ciecle then the returned
99
- * value will be the minimal distance.
100
- * * If the line goes through this circle then the returned value
101
- * will be max inner distance and it will be negative.
102
- *
103
- * @method lineDistance
104
- * @param {Line} line - The line to measure the distance to.
105
- * @return {number} The minimal distance from the outline of this circle to the given line.
106
- * @instance
107
- * @memberof Circle
108
- */
109
- lineDistance( line:VertTuple<any> ) : number {
110
- const closestPointOnLine : Vertex = line.getClosestPoint( this.center );
111
- return closestPointOnLine.distance( this.center ) - this.radius;
112
- };
113
-
114
- /**
115
- * Get the vertex on the this circle for the given angle.
116
- *
117
- * @method vertAt
118
- * @param {number} angle - The angle (in radians) to use.
119
- * @return {Vertex} The vertex (point) at the given angle.
120
- * @instance
121
- * @memberof Circle
122
- **/
123
- vertAt( angle: number ) : Vertex {
124
- // Find the point on the circle respective the angle. Then move relative to center.
125
- return Circle.circleUtils.vertAt( angle, this.radius ).add( this.center );
126
- };
127
-
128
-
129
- /**
130
- * Get a tangent line of this circle for a given angle.
131
- *
132
- * Point a of the returned line is located on the circle, the length equals the radius.
133
- *
134
- * @method tangentAt
135
- * @instance
136
- * @param {number} angle - The angle (in radians) to use.
137
- * @return {Line} The tangent line.
138
- * @memberof Circle
139
- **/
140
- tangentAt( angle: number ) : Vector {
141
- const pointA : Vertex = Circle.circleUtils.vertAt( angle, this.radius );
142
- // Construct the perpendicular of the line in point a. Then move relative to center.
143
- return (new Vector( pointA, new Vertex(0,0) ).add( this.center ) as Vector).perp() as Vector;
144
- };
145
-
146
- /**
147
- * Calculate the intersection points (if exists) with the given circle.
148
- *
149
- * @method circleIntersection
150
- * @instance
151
- * @memberof Circle
152
- * @param {Circle} circle
153
- * @return {Line|null} The intersection points (as a line) or null if the two circles do not intersect.
154
- **/
155
- circleIntersection( circle:Circle ) : Line | null {
156
- // Circles do not intersect at all?
157
- if( this.center.distance(circle.center) > this.radius+circle.radius ) {
158
- return null;
159
- }
160
- // One circle is fully inside the other?
161
- if( this.center.distance(circle.center) < Math.abs(this.radius-circle.radius) ) {
162
- return null;
163
- }
164
- // Based on the C++ implementation by Robert King
165
- // https://stackoverflow.com/questions/3349125/circle-circle-intersection-points
166
- // and the 'Circles and spheres' article by Paul Bourke.
167
- // http://paulbourke.net/geometry/circlesphere/
168
- //
169
- // This is the original C++ implementation:
170
- //
171
- // pair<Point, Point> intersections(Circle c) {
172
- // Point P0(x, y);
173
- // Point P1(c.x, c.y);
174
- // float d, a, h;
175
- // d = P0.distance(P1);
176
- // a = (r*r - c.r*c.r + d*d)/(2*d);
177
- // h = sqrt(r*r - a*a);
178
- // Point P2 = P1.sub(P0).scale(a/d).add(P0);
179
- // float x3, y3, x4, y4;
180
- // x3 = P2.x + h*(P1.y - P0.y)/d;
181
- // y3 = P2.y - h*(P1.x - P0.x)/d;
182
- // x4 = P2.x - h*(P1.y - P0.y)/d;
183
- // y4 = P2.y + h*(P1.x - P0.x)/d;
184
- // return pair<Point, Point>(Point(x3, y3), Point(x4, y4));
185
- // }
186
- var p0 = this.center;
187
- var p1 = circle.center;
188
- var d = p0.distance(p1);
189
- var a = (this.radius*this.radius - circle.radius*circle.radius + d*d)/(2*d);
190
- var h = Math.sqrt( this.radius*this.radius - a*a );
191
- var p2 = p1.clone().scale(a/d,p0);
192
- var x3 = p2.x + h*(p1.y - p0.y)/d;
193
- var y3 = p2.y - h*(p1.x - p0.x)/d;
194
- var x4 = p2.x - h*(p1.y - p0.y)/d;
195
- var y4 = p2.y + h*(p1.x - p0.x)/d;
196
- return new Line( new Vertex(x3,y3), new Vertex(x4,y4) );
197
- };
198
-
199
- /**
200
- * Create an SVG representation of this circle.
201
- *
202
- * @deprecated DEPRECATION Please use the drawutilssvg library and an XMLSerializer instead.
203
- * @method toSVGString
204
- * @param {object=} options - An optional set of options, like 'className'.
205
- * @return {string} A string representing the SVG code for this vertex.
206
- * @instance
207
- * @memberof Circle
208
- */
209
- toSVGString( options:{className?:string } ) {
210
- options = options || {};
211
- var buffer : Array<string> = [];
212
- buffer.push( '<circle' );
213
- if( options.className )
214
- buffer.push( ' class="' + options.className + '"' );
215
- buffer.push( ' cx="' + this.center.x + '"' );
216
- buffer.push( ' cy="' + this.center.y + '"' );
217
- buffer.push( ' r="' + this.radius + '"' );
218
- buffer.push( ' />' );
219
- return buffer.join('');
220
- };
221
-
222
- static circleUtils = {
223
- vertAt : (angle:number,radius:number) => {
224
- /* return new Vertex( Math.sin(angle) * radius,
34
+ /**
35
+ * Required to generate proper CSS classes and other class related IDs.
36
+ **/
37
+ readonly className: string = "Circle";
38
+
39
+ /**
40
+ * The UID of this drawable object.
41
+ *
42
+ * @member {UID}
43
+ * @memberof Circle
44
+ * @instance
45
+ * @readonly
46
+ */
47
+ readonly uid: UID;
48
+
49
+ /**
50
+ * @member {Vertex}
51
+ * @memberof Circle
52
+ * @instance
53
+ */
54
+ center: Vertex;
55
+
56
+ /**
57
+ * @member {number}
58
+ * @memberof Circle
59
+ * @instance
60
+ */
61
+ radius: number;
62
+
63
+ /**
64
+ * @member isDestroyed
65
+ * @memberof CubicBezierCurve
66
+ * @type {boolean}
67
+ * @instance
68
+ */
69
+ isDestroyed: boolean;
70
+
71
+ /**
72
+ * Create a new circle with given center point and radius.
73
+ *
74
+ * @constructor
75
+ * @name Circle
76
+ * @param {Vertex} center - The center point of the circle.
77
+ * @param {number} radius - The radius of the circle.
78
+ */
79
+ constructor(center: Vertex, radius: number) {
80
+ this.uid = UIDGenerator.next();
81
+ this.center = center;
82
+ this.radius = radius;
83
+ }
84
+
85
+ /**
86
+ * Check if the given circle is fully contained inside this circle.
87
+ *
88
+ * @method containsCircle
89
+ * @param {Circle} circle - The circle to check if it is contained in this circle.
90
+ * @instance
91
+ * @memberof Circle
92
+ * @return {boolean} `true` if any only if the given circle is completely inside this circle.
93
+ */
94
+ containsCircle(circle: Circle): boolean {
95
+ return this.center.distance(circle.center) + circle.radius < this.radius;
96
+ }
97
+
98
+ /**
99
+ * Calculate the distance from this circle to the given line.
100
+ *
101
+ * * If the line does not intersect this ciecle then the returned
102
+ * value will be the minimal distance.
103
+ * * If the line goes through this circle then the returned value
104
+ * will be max inner distance and it will be negative.
105
+ *
106
+ * @method lineDistance
107
+ * @param {Line} line - The line to measure the distance to.
108
+ * @return {number} The minimal distance from the outline of this circle to the given line.
109
+ * @instance
110
+ * @memberof Circle
111
+ */
112
+ lineDistance(line: VertTuple<any>): number {
113
+ const closestPointOnLine: Vertex = line.getClosestPoint(this.center);
114
+ return closestPointOnLine.distance(this.center) - this.radius;
115
+ }
116
+
117
+ /**
118
+ * Get the vertex on the this circle for the given angle.
119
+ *
120
+ * @method vertAt
121
+ * @param {number} angle - The angle (in radians) to use.
122
+ * @return {Vertex} The vertex (point) at the given angle.
123
+ * @instance
124
+ * @memberof Circle
125
+ **/
126
+ vertAt(angle: number): Vertex {
127
+ // Find the point on the circle respective the angle. Then move relative to center.
128
+ return Circle.circleUtils.vertAt(angle, this.radius).add(this.center);
129
+ }
130
+
131
+ /**
132
+ * Get a tangent line of this circle for a given angle.
133
+ *
134
+ * Point a of the returned line is located on the circle, the length equals the radius.
135
+ *
136
+ * @method tangentAt
137
+ * @instance
138
+ * @param {number} angle - The angle (in radians) to use.
139
+ * @return {Line} The tangent line.
140
+ * @memberof Circle
141
+ **/
142
+ tangentAt(angle: number): Vector {
143
+ const pointA: Vertex = Circle.circleUtils.vertAt(angle, this.radius);
144
+ // Construct the perpendicular of the line in point a. Then move relative to center.
145
+ return (new Vector(pointA, new Vertex(0, 0)).add(this.center) as Vector).perp() as Vector;
146
+ }
147
+
148
+ /**
149
+ * Calculate the intersection points (if exists) with the given circle.
150
+ *
151
+ * @method circleIntersection
152
+ * @instance
153
+ * @memberof Circle
154
+ * @param {Circle} circle
155
+ * @return {Line|null} The intersection points (as a line) or null if the two circles do not intersect.
156
+ **/
157
+ circleIntersection(circle: Circle): Line | null {
158
+ // Circles do not intersect at all?
159
+ if (this.center.distance(circle.center) > this.radius + circle.radius) {
160
+ return null;
161
+ }
162
+ // One circle is fully inside the other?
163
+ if (this.center.distance(circle.center) < Math.abs(this.radius - circle.radius)) {
164
+ return null;
165
+ }
166
+ // Based on the C++ implementation by Robert King
167
+ // https://stackoverflow.com/questions/3349125/circle-circle-intersection-points
168
+ // and the 'Circles and spheres' article by Paul Bourke.
169
+ // http://paulbourke.net/geometry/circlesphere/
170
+ //
171
+ // This is the original C++ implementation:
172
+ //
173
+ // pair<Point, Point> intersections(Circle c) {
174
+ // Point P0(x, y);
175
+ // Point P1(c.x, c.y);
176
+ // float d, a, h;
177
+ // d = P0.distance(P1);
178
+ // a = (r*r - c.r*c.r + d*d)/(2*d);
179
+ // h = sqrt(r*r - a*a);
180
+ // Point P2 = P1.sub(P0).scale(a/d).add(P0);
181
+ // float x3, y3, x4, y4;
182
+ // x3 = P2.x + h*(P1.y - P0.y)/d;
183
+ // y3 = P2.y - h*(P1.x - P0.x)/d;
184
+ // x4 = P2.x - h*(P1.y - P0.y)/d;
185
+ // y4 = P2.y + h*(P1.x - P0.x)/d;
186
+ // return pair<Point, Point>(Point(x3, y3), Point(x4, y4));
187
+ // }
188
+ var p0 = this.center;
189
+ var p1 = circle.center;
190
+ var d = p0.distance(p1);
191
+ var a = (this.radius * this.radius - circle.radius * circle.radius + d * d) / (2 * d);
192
+ var h = Math.sqrt(this.radius * this.radius - a * a);
193
+ var p2 = p1.clone().scale(a / d, p0);
194
+ var x3 = p2.x + (h * (p1.y - p0.y)) / d;
195
+ var y3 = p2.y - (h * (p1.x - p0.x)) / d;
196
+ var x4 = p2.x - (h * (p1.y - p0.y)) / d;
197
+ var y4 = p2.y + (h * (p1.x - p0.x)) / d;
198
+ return new Line(new Vertex(x3, y3), new Vertex(x4, y4));
199
+ }
200
+
201
+ /**
202
+ * This function should invalidate any installed listeners and invalidate this object.
203
+ * After calling this function the object might not hold valid data any more and
204
+ * should not be used.
205
+ */
206
+ destroy() {
207
+ this.center.destroy();
208
+ this.isDestroyed = true;
209
+ }
210
+
211
+ static circleUtils = {
212
+ vertAt: (angle: number, radius: number) => {
213
+ /* return new Vertex( Math.sin(angle) * radius,
225
214
  Math.cos(angle) * radius ); */
226
- return new Vertex( Math.cos(angle) * radius,
227
- Math.sin(angle) * radius );
228
- }
229
- };
230
-
215
+ return new Vertex(Math.cos(angle) * radius, Math.sin(angle) * radius);
216
+ }
217
+ };
231
218
  } // END class