plotboilerplate 1.22.0 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/README.md +2 -0
  2. package/dist/index.esm.js +222 -76
  3. package/dist/index.esm.js.map +1 -1
  4. package/dist/index.esm.min.js +1 -1
  5. package/dist/index.esm.min.js.map +1 -1
  6. package/dist/plotboilerplate.browser.min.js +1 -1
  7. package/dist/plotboilerplate.browser.min.js.map +1 -1
  8. package/dist/plotboilerplate.js +492 -337
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +5 -4
  11. package/src/cjs/BezierPath.js.map +1 -1
  12. package/src/cjs/Bounds.js +1 -1
  13. package/src/cjs/Bounds.js.map +1 -1
  14. package/src/cjs/Circle.js.map +1 -1
  15. package/src/cjs/CircleSector.d.ts +64 -1
  16. package/src/cjs/CircleSector.js +121 -1
  17. package/src/cjs/CircleSector.js.map +1 -1
  18. package/src/cjs/CubicBezierCurve.js +2 -2
  19. package/src/cjs/CubicBezierCurve.js.map +1 -1
  20. package/src/cjs/Grid.js.map +1 -1
  21. package/src/cjs/KeyHandler.d.ts +1 -1
  22. package/src/cjs/KeyHandler.js +13 -13
  23. package/src/cjs/KeyHandler.js.map +1 -1
  24. package/src/cjs/Line.js +2 -0
  25. package/src/cjs/Line.js.map +1 -1
  26. package/src/cjs/MouseHandler.d.ts +2 -2
  27. package/src/cjs/MouseHandler.js +7 -5
  28. package/src/cjs/MouseHandler.js.map +1 -1
  29. package/src/cjs/PlotBoilerplate.d.ts +1 -1
  30. package/src/cjs/PlotBoilerplate.js +77 -63
  31. package/src/cjs/PlotBoilerplate.js.map +1 -1
  32. package/src/cjs/Polygon.js.map +1 -1
  33. package/src/cjs/Triangle.js +1 -1
  34. package/src/cjs/Triangle.js.map +1 -1
  35. package/src/cjs/UIDGenerator.js +1 -1
  36. package/src/cjs/UIDGenerator.js.map +1 -1
  37. package/src/cjs/VEllipse.js.map +1 -1
  38. package/src/cjs/VEllipseSector.js +1 -1
  39. package/src/cjs/VEllipseSector.js.map +1 -1
  40. package/src/cjs/Vector.js +2 -0
  41. package/src/cjs/Vector.js.map +1 -1
  42. package/src/cjs/VertTuple.js.map +1 -1
  43. package/src/cjs/Vertex.d.ts +3 -2
  44. package/src/cjs/Vertex.js +13 -7
  45. package/src/cjs/Vertex.js.map +1 -1
  46. package/src/cjs/VertexAttr.d.ts +2 -1
  47. package/src/cjs/VertexAttr.js +2 -1
  48. package/src/cjs/VertexAttr.js.map +1 -1
  49. package/src/cjs/VertexListeners.d.ts +1 -1
  50. package/src/cjs/VertexListeners.js.map +1 -1
  51. package/src/cjs/draw.js +1 -1
  52. package/src/cjs/draw.js.map +1 -1
  53. package/src/cjs/drawgl.js.map +1 -1
  54. package/src/cjs/drawutilssvg.d.ts +17 -3
  55. package/src/cjs/drawutilssvg.js +97 -91
  56. package/src/cjs/drawutilssvg.js.map +1 -1
  57. package/src/cjs/geomutils.js +2 -2
  58. package/src/cjs/geomutils.js.map +1 -1
  59. package/src/cjs/index.js +5 -1
  60. package/src/cjs/index.js.map +1 -1
  61. package/src/cjs/interfaces/DrawLib.d.ts +2 -2
  62. package/src/cjs/interfaces/core.d.ts +3 -3
  63. package/src/cjs/interfaces/index.js +5 -1
  64. package/src/cjs/interfaces/index.js.map +1 -1
  65. package/src/cjs/utils/NGons.d.ts +13 -0
  66. package/src/cjs/utils/NGons.js +36 -0
  67. package/src/cjs/utils/NGons.js.map +1 -0
  68. package/src/cjs/utils/Params.js.map +1 -1
  69. package/src/cjs/utils/WebColors.js.map +1 -1
  70. package/src/cjs/utils/WebColorsContrast.js +1 -1
  71. package/src/cjs/utils/WebColorsContrast.js.map +1 -1
  72. package/src/cjs/utils/algorithms/CatmullRomPath.js.map +1 -1
  73. package/src/cjs/utils/algorithms/CircleIntersections.d.ts +3 -2
  74. package/src/cjs/utils/algorithms/CircleIntersections.js +12 -20
  75. package/src/cjs/utils/algorithms/CircleIntersections.js.map +1 -1
  76. package/src/cjs/utils/algorithms/ContourLineDetection.js +5 -5
  77. package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -1
  78. package/src/cjs/utils/algorithms/CubicSplinePath.js.map +1 -1
  79. package/src/cjs/utils/algorithms/HobbyPath.js.map +1 -1
  80. package/src/cjs/utils/algorithms/Metaballs.d.ts +30 -0
  81. package/src/cjs/utils/algorithms/Metaballs.js +114 -0
  82. package/src/cjs/utils/algorithms/Metaballs.js.map +1 -0
  83. package/src/cjs/utils/algorithms/arrayResize.d.ts +8 -0
  84. package/src/cjs/utils/algorithms/arrayResize.js +24 -0
  85. package/src/cjs/utils/algorithms/arrayResize.js.map +1 -0
  86. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  87. package/src/cjs/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  88. package/src/cjs/utils/algorithms/convexHull.js.map +1 -1
  89. package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  90. package/src/cjs/utils/algorithms/delaunay.js.map +1 -1
  91. package/src/cjs/utils/algorithms/delaunay2voronoi.js.map +1 -1
  92. package/src/cjs/utils/algorithms/detectPaths.js.map +1 -1
  93. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  94. package/src/cjs/utils/algorithms/matrixFill.js +1 -1
  95. package/src/cjs/utils/algorithms/matrixFill.js.map +1 -1
  96. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  97. package/src/cjs/utils/algorithms/sutherlandHodgman.js.map +1 -1
  98. package/src/cjs/utils/cloneVertexArray.js.map +1 -1
  99. package/src/cjs/utils/creategui.js +20 -12
  100. package/src/cjs/utils/datastructures/CircularIntervalSet.js.map +1 -1
  101. package/src/cjs/utils/datastructures/Color.d.ts +2 -1
  102. package/src/cjs/utils/datastructures/Color.js +35 -16
  103. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  104. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +1 -1
  105. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +2 -2
  106. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +1 -1
  107. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  108. package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
  109. package/src/cjs/utils/datastructures/Girih.d.ts +3 -2
  110. package/src/cjs/utils/datastructures/Girih.js +2 -1
  111. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  112. package/src/cjs/utils/datastructures/GirihBowtie.js +2 -0
  113. package/src/cjs/utils/datastructures/GirihBowtie.js.map +1 -1
  114. package/src/cjs/utils/datastructures/GirihDecagon.js +2 -0
  115. package/src/cjs/utils/datastructures/GirihDecagon.js.map +1 -1
  116. package/src/cjs/utils/datastructures/GirihHexagon.js +2 -0
  117. package/src/cjs/utils/datastructures/GirihHexagon.js.map +1 -1
  118. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +3 -1
  119. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  120. package/src/cjs/utils/datastructures/GirihPentagon.js +2 -0
  121. package/src/cjs/utils/datastructures/GirihPentagon.js.map +1 -1
  122. package/src/cjs/utils/datastructures/GirihRhombus.js +2 -0
  123. package/src/cjs/utils/datastructures/GirihRhombus.js.map +1 -1
  124. package/src/cjs/utils/datastructures/GirihTile.js +4 -2
  125. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  126. package/src/cjs/utils/datastructures/Matrix4x4.js.map +1 -1
  127. package/src/cjs/utils/datastructures/VoronoiCell.js.map +1 -1
  128. package/src/cjs/utils/datastructures/interfaces.d.ts +3 -3
  129. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  130. package/src/cjs/utils/dom/getAvailableContainerSpace.js +1 -1
  131. package/src/cjs/utils/dom/getAvailableContainerSpace.js.map +1 -1
  132. package/src/cjs/utils/findInVertexArray.js.map +1 -1
  133. package/src/cjs/utils/gup.d.ts +8 -0
  134. package/src/cjs/utils/gup.js +8 -0
  135. package/src/cjs/utils/gup.js.map +1 -1
  136. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  137. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +3 -2
  138. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  139. package/src/cjs/utils/helpers/CircleHelper.d.ts +38 -3
  140. package/src/cjs/utils/helpers/CircleHelper.js +51 -11
  141. package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
  142. package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +47 -1
  143. package/src/cjs/utils/helpers/CircleSectorHelper.js +85 -14
  144. package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
  145. package/src/cjs/utils/io/FileDrop.d.ts +3 -3
  146. package/src/cjs/utils/io/FileDrop.js.map +1 -1
  147. package/src/cjs/utils/parsers/OBJParser.d.ts +2 -2
  148. package/src/cjs/utils/parsers/OBJParser.js.map +1 -1
  149. package/src/cjs/utils/parsers/STLParser.d.ts +4 -3
  150. package/src/cjs/utils/parsers/STLParser.js +62 -12
  151. package/src/cjs/utils/parsers/STLParser.js.map +1 -1
  152. package/src/cjs/utils/parsers/svg/parseSVGPathData.js +1 -1
  153. package/src/cjs/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  154. package/src/cjs/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  155. package/src/cjs/utils/parsers/svg/types.d.ts +13 -13
  156. package/src/createDemoDrawables.js +48 -3
  157. package/src/esm/BezierPath.js.map +1 -1
  158. package/src/esm/Bounds.js.map +1 -1
  159. package/src/esm/Circle.js.map +1 -1
  160. package/src/esm/CircleSector.d.ts +64 -1
  161. package/src/esm/CircleSector.js +121 -1
  162. package/src/esm/CircleSector.js.map +1 -1
  163. package/src/esm/CubicBezierCurve.js.map +1 -1
  164. package/src/esm/Grid.js.map +1 -1
  165. package/src/esm/KeyHandler.d.ts +1 -1
  166. package/src/esm/KeyHandler.js +13 -13
  167. package/src/esm/KeyHandler.js.map +1 -1
  168. package/src/esm/Line.js.map +1 -1
  169. package/src/esm/MouseHandler.d.ts +2 -2
  170. package/src/esm/MouseHandler.js +4 -4
  171. package/src/esm/MouseHandler.js.map +1 -1
  172. package/src/esm/PlotBoilerplate.d.ts +1 -1
  173. package/src/esm/PlotBoilerplate.js +43 -29
  174. package/src/esm/PlotBoilerplate.js.map +1 -1
  175. package/src/esm/Polygon.js.map +1 -1
  176. package/src/esm/Triangle.js.map +1 -1
  177. package/src/esm/VEllipse.js.map +1 -1
  178. package/src/esm/VEllipseSector.js +1 -1
  179. package/src/esm/VEllipseSector.js.map +1 -1
  180. package/src/esm/Vector.js.map +1 -1
  181. package/src/esm/VertTuple.js.map +1 -1
  182. package/src/esm/Vertex.d.ts +3 -2
  183. package/src/esm/Vertex.js +9 -3
  184. package/src/esm/Vertex.js.map +1 -1
  185. package/src/esm/VertexAttr.d.ts +2 -1
  186. package/src/esm/VertexAttr.js +2 -1
  187. package/src/esm/VertexAttr.js.map +1 -1
  188. package/src/esm/VertexListeners.d.ts +1 -1
  189. package/src/esm/VertexListeners.js.map +1 -1
  190. package/src/esm/draw.js.map +1 -1
  191. package/src/esm/drawgl.js.map +1 -1
  192. package/src/esm/drawutilssvg.d.ts +17 -3
  193. package/src/esm/drawutilssvg.js +28 -22
  194. package/src/esm/drawutilssvg.js.map +1 -1
  195. package/src/esm/geomutils.js +2 -2
  196. package/src/esm/geomutils.js.map +1 -1
  197. package/src/esm/interfaces/DrawLib.d.ts +2 -2
  198. package/src/esm/interfaces/core.d.ts +3 -3
  199. package/src/esm/utils/NGons.d.ts +13 -0
  200. package/src/esm/utils/NGons.js +33 -0
  201. package/src/esm/utils/NGons.js.map +1 -0
  202. package/src/esm/utils/Params.js.map +1 -1
  203. package/src/esm/utils/WebColors.js.map +1 -1
  204. package/src/esm/utils/algorithms/CatmullRomPath.js.map +1 -1
  205. package/src/esm/utils/algorithms/CircleIntersections.d.ts +3 -2
  206. package/src/esm/utils/algorithms/CircleIntersections.js +11 -19
  207. package/src/esm/utils/algorithms/CircleIntersections.js.map +1 -1
  208. package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -1
  209. package/src/esm/utils/algorithms/CubicSplinePath.js.map +1 -1
  210. package/src/esm/utils/algorithms/HobbyPath.js.map +1 -1
  211. package/src/esm/utils/algorithms/Metaballs.d.ts +30 -0
  212. package/src/esm/utils/algorithms/Metaballs.js +109 -0
  213. package/src/esm/utils/algorithms/Metaballs.js.map +1 -0
  214. package/src/esm/utils/algorithms/arrayResize.d.ts +8 -0
  215. package/src/esm/utils/algorithms/arrayResize.js +20 -0
  216. package/src/esm/utils/algorithms/arrayResize.js.map +1 -0
  217. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -1
  218. package/src/esm/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  219. package/src/esm/utils/algorithms/convexHull.js.map +1 -1
  220. package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  221. package/src/esm/utils/algorithms/delaunay.js.map +1 -1
  222. package/src/esm/utils/algorithms/delaunay2voronoi.js.map +1 -1
  223. package/src/esm/utils/algorithms/detectPaths.js.map +1 -1
  224. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  225. package/src/esm/utils/algorithms/matrixFill.js.map +1 -1
  226. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  227. package/src/esm/utils/algorithms/sutherlandHodgman.js.map +1 -1
  228. package/src/esm/utils/cloneVertexArray.js.map +1 -1
  229. package/src/esm/utils/datastructures/CircularIntervalSet.js.map +1 -1
  230. package/src/esm/utils/datastructures/Color.d.ts +2 -1
  231. package/src/esm/utils/datastructures/Color.js +33 -14
  232. package/src/esm/utils/datastructures/Color.js.map +1 -1
  233. package/src/esm/utils/datastructures/DataGrid2d.d.ts +1 -1
  234. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +2 -2
  235. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -1
  236. package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
  237. package/src/esm/utils/datastructures/Girih.d.ts +3 -2
  238. package/src/esm/utils/datastructures/Girih.js +2 -1
  239. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  240. package/src/esm/utils/datastructures/GirihBowtie.js.map +1 -1
  241. package/src/esm/utils/datastructures/GirihDecagon.js.map +1 -1
  242. package/src/esm/utils/datastructures/GirihHexagon.js.map +1 -1
  243. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +1 -1
  244. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  245. package/src/esm/utils/datastructures/GirihPentagon.js.map +1 -1
  246. package/src/esm/utils/datastructures/GirihRhombus.js.map +1 -1
  247. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  248. package/src/esm/utils/datastructures/Matrix4x4.js.map +1 -1
  249. package/src/esm/utils/datastructures/VoronoiCell.js.map +1 -1
  250. package/src/esm/utils/datastructures/interfaces.d.ts +3 -3
  251. package/src/esm/utils/detectDarkMode.js.map +1 -1
  252. package/src/esm/utils/findInVertexArray.js.map +1 -1
  253. package/src/esm/utils/gup.d.ts +8 -0
  254. package/src/esm/utils/gup.js +8 -0
  255. package/src/esm/utils/gup.js.map +1 -1
  256. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  257. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +3 -2
  258. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  259. package/src/esm/utils/helpers/CircleHelper.d.ts +38 -3
  260. package/src/esm/utils/helpers/CircleHelper.js +51 -11
  261. package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
  262. package/src/esm/utils/helpers/CircleSectorHelper.d.ts +47 -1
  263. package/src/esm/utils/helpers/CircleSectorHelper.js +85 -14
  264. package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
  265. package/src/esm/utils/io/FileDrop.d.ts +3 -3
  266. package/src/esm/utils/io/FileDrop.js.map +1 -1
  267. package/src/esm/utils/parsers/OBJParser.d.ts +2 -2
  268. package/src/esm/utils/parsers/OBJParser.js.map +1 -1
  269. package/src/esm/utils/parsers/STLParser.d.ts +4 -3
  270. package/src/esm/utils/parsers/STLParser.js +63 -13
  271. package/src/esm/utils/parsers/STLParser.js.map +1 -1
  272. package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  273. package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  274. package/src/esm/utils/parsers/svg/types.d.ts +13 -13
  275. package/src/index-gl.js +77 -85
  276. package/src/index.js +124 -129
  277. package/src/ts/CircleSector.ts +134 -3
  278. package/src/ts/PlotBoilerplate.ts +20 -11
  279. package/src/ts/Vertex.ts +8 -3
  280. package/src/ts/VertexAttr.ts +3 -2
  281. package/src/ts/drawutilssvg.ts +38 -25
  282. package/src/ts/geomutils.ts +60 -64
  283. package/src/ts/interfaces/DrawLib.ts +0 -15
  284. package/src/ts/utils/NGons.ts +35 -0
  285. package/src/ts/utils/algorithms/CircleIntersections.ts +280 -288
  286. package/src/ts/utils/algorithms/Metaballs.ts +144 -0
  287. package/src/ts/utils/algorithms/arrayResize.ts +22 -0
  288. package/src/ts/utils/datastructures/Color.ts +39 -15
  289. package/src/ts/utils/datastructures/Girih.ts +9 -8
  290. package/src/ts/utils/gup.ts +10 -2
  291. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +9 -8
  292. package/src/ts/utils/helpers/CircleHelper.ts +70 -22
  293. package/src/ts/utils/helpers/CircleSectorHelper.ts +101 -17
  294. package/src/ts/utils/parsers/STLParser.ts +50 -16
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Algorithm:
3
+ * Input Circles
4
+ * -> filter out fully contained circles
5
+ * -> build outer containing circles (given by detect radius)
6
+ * -> find radical lines
7
+ *
8
+ * This implementation currently does not detect any holes.
9
+ *
10
+ * @author Ikaros Kappler
11
+ * @version 1.0.0
12
+ * @date 2024-03-01
13
+ */
14
+
15
+ import { Circle } from "../../Circle";
16
+ import { Vertex } from "../../Vertex";
17
+ import { CircleIntersections } from "./CircleIntersections";
18
+
19
+ type Pair<T> = [T, T];
20
+
21
+ interface InverseCirclePair {
22
+ baseCircleIndexA: number;
23
+ baseCircleIndexB: number;
24
+ baseCircleA: Circle;
25
+ baseCircleB: Circle;
26
+ circleA: Circle;
27
+ circleB: Circle;
28
+ inverseCircleA: Circle;
29
+ inverseCircleB: Circle;
30
+ doIntersect: boolean;
31
+ circlePointsA: Pair<Vertex>;
32
+ circlePointsB: Pair<Vertex>;
33
+ }
34
+
35
+ interface MetaballsOptions {
36
+ metaRadiusAddon: number;
37
+ }
38
+
39
+ export class Metaballs {
40
+ private circleIsFullyContained: Array<boolean> = []; // Array<boolean>
41
+ private inputCircles: Array<Circle> = [];
42
+ private circlesOfInterest: Array<Circle> = [];
43
+ private containingCircles: Array<Circle> = [];
44
+
45
+ // Array< { baseCircleIndexA, baseCircleIndexB,
46
+ // baseCircleA, baseCircleB,
47
+ // circleA, circleB,
48
+ // inverseCircleA, inverseCircleB,
49
+ // doIntersect, circlePointsA:[], circlePointsB:[] } >
50
+ private inverseCirclesPairs: Array<InverseCirclePair> = [];
51
+
52
+ constructor(inputCircles: Array<Circle>) {
53
+ this.inputCircles = inputCircles;
54
+ }
55
+
56
+ public rebuild(options: MetaballsOptions) {
57
+ this.detectContainmentStatus();
58
+ this.rebuildContainingCircles(options);
59
+
60
+ this.inverseCirclesPairs = [];
61
+
62
+ const radicalLineMatrix = CircleIntersections.buildRadicalLineMatrix(this.containingCircles);
63
+ for (var i = 0; i < this.containingCircles.length; i++) {
64
+ var circleA = this.containingCircles[i];
65
+ var centerCircleA = this.circlesOfInterest[i];
66
+ for (var j = i + 1; j < this.containingCircles.length; j++) {
67
+ var radicalLine = radicalLineMatrix[i][j];
68
+ if (radicalLine == null) {
69
+ // The two circles do not have an intersection.
70
+ // console.log("Circles", i, j, "do not have any intersections");
71
+ continue;
72
+ }
73
+ var circleB = this.containingCircles[j];
74
+ var centerCircleB = this.circlesOfInterest[j];
75
+ // But if they have -> compute. outer circle(s).
76
+ // They are symmetrical.
77
+ var inverseCircle1 = new Circle(radicalLine.a, options.metaRadiusAddon);
78
+ var inverseCircle2 = new Circle(radicalLine.b, options.metaRadiusAddon);
79
+ var doIntersect = inverseCircle1.circleIntersection(inverseCircle2) != null;
80
+ // console.log("doIntersect", doIntersect);
81
+ // Now find the intersection points between inner and outer circles.
82
+ // We will need them later.
83
+ var circlePointsA: Pair<Vertex> = [
84
+ centerCircleA.closestPoint(inverseCircle1.center),
85
+ centerCircleA.closestPoint(inverseCircle2.center)
86
+ ];
87
+ var circlePointsB: Pair<Vertex> = [
88
+ centerCircleB.closestPoint(inverseCircle1.center),
89
+ centerCircleB.closestPoint(inverseCircle2.center)
90
+ ];
91
+
92
+ this.inverseCirclesPairs.push({
93
+ baseCircleIndexA: i,
94
+ baseCircleIndexB: j,
95
+ baseCircleA: this.circlesOfInterest[i],
96
+ baseCircleB: this.circlesOfInterest[j],
97
+ circleA: circleA,
98
+ inverseCircleA: inverseCircle1,
99
+ circleB: circleB,
100
+ inverseCircleB: inverseCircle2,
101
+ doIntersect: doIntersect,
102
+ circlePointsA: circlePointsA,
103
+ circlePointsB: circlePointsB
104
+ });
105
+ } // END for j
106
+ } // END for i
107
+ }
108
+
109
+ // public getInnerPath;
110
+
111
+ private checkCircleFullyContained(circleIndex: number): boolean {
112
+ for (var i = 0; i < this.inputCircles.length; i++) {
113
+ if (circleIndex == i) {
114
+ continue;
115
+ }
116
+ if (this.inputCircles[i].containsCircle(this.inputCircles[circleIndex])) {
117
+ return true;
118
+ }
119
+ }
120
+ return false;
121
+ }
122
+
123
+ private detectContainmentStatus() {
124
+ this.circleIsFullyContained = [];
125
+ this.circlesOfInterest = [];
126
+ for (var i = 0; i < this.inputCircles.length; i++) {
127
+ this.circleIsFullyContained[i] = this.checkCircleFullyContained(i);
128
+ if (!this.circleIsFullyContained[i]) {
129
+ this.circlesOfInterest.push(this.inputCircles[i]);
130
+ }
131
+ }
132
+ }
133
+
134
+ private rebuildContainingCircles(options: MetaballsOptions) {
135
+ this.containingCircles = [];
136
+ for (var i = 0; i < this.circlesOfInterest.length; i++) {
137
+ var containingCircle = new Circle(
138
+ this.circlesOfInterest[i].center,
139
+ this.circlesOfInterest[i].radius + options.metaRadiusAddon
140
+ );
141
+ this.containingCircles.push(containingCircle);
142
+ }
143
+ }
144
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Resize a given array to a desired number of elements by adding or removing some.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2024-02-07
6
+ * @version 1.0.0
7
+ */
8
+
9
+ export const arrayResize = <T>(arr: Array<T>, desiredSize: number, factoryFn: () => T) => {
10
+ if (arr.length === desiredSize) {
11
+ // No change required
12
+ return;
13
+ }
14
+
15
+ while (arr.length < desiredSize) {
16
+ arr.push(factoryFn());
17
+ }
18
+
19
+ if (arr.length > desiredSize) {
20
+ arr.splice(desiredSize);
21
+ }
22
+ };
@@ -17,7 +17,8 @@
17
17
  * @modified 2022-05-11 Modified the `clone` function by just copying the numeric calues, not re-calculating the whole color.
18
18
  * @modified 2022-05-11 Fixed the `interpolate` function.
19
19
  * @modified 2023-01-23 Added `Color.set(Color)` function to set all values (r,g,b,h,s,l,a) simultanoeusly.
20
- * @version 0.0.12
20
+ * @modified 2024-03-10 Fixed some NaN type check for Typescript 5 compatibility.
21
+ * @version 0.0.13
21
22
  **/
22
23
 
23
24
  /**
@@ -331,7 +332,8 @@ export class Color {
331
332
  // return this;
332
333
  // }
333
334
  saturate(v: string | number): Color {
334
- if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
335
+ // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
336
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
335
337
  this.s += (1 - this.s) * (v / 100);
336
338
  } else if ("number" == typeof v) {
337
339
  if (v >= -0.0 && v <= 1.0) {
@@ -350,7 +352,8 @@ export class Color {
350
352
  return this;
351
353
  }
352
354
  desaturate(v: string | number): Color {
353
- if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
355
+ // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
356
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
354
357
  this.s -= v / 100;
355
358
  } else if ("number" == typeof v) {
356
359
  if (v >= 0.0 && v <= 1.0) {
@@ -388,7 +391,9 @@ export class Color {
388
391
  // return this;
389
392
  // }
390
393
  lighten(v: string | number): Color {
391
- if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
394
+ // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
395
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
396
+
392
397
  this.l += (1 - this.l) * (v / 100);
393
398
  } else if ("number" == typeof v) {
394
399
  if (v >= 0.0 && v <= 1.0) {
@@ -407,7 +412,8 @@ export class Color {
407
412
  return this;
408
413
  }
409
414
  darken(v: string | number): Color {
410
- if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
415
+ // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
416
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
411
417
  this.l -= this.l * (v / 100);
412
418
  } else if ("number" == typeof v) {
413
419
  if (v >= 0.0 && v <= 1.0) {
@@ -426,7 +432,8 @@ export class Color {
426
432
  return this;
427
433
  }
428
434
  fadein(v: string | number): Color {
429
- if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
435
+ // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
436
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
430
437
  this.a += (1 - this.a) * (v / 100);
431
438
  } else if ("number" == typeof v) {
432
439
  if (v >= 0.0 && v <= 1.0) {
@@ -446,7 +453,8 @@ export class Color {
446
453
  return this;
447
454
  }
448
455
  fadeout(v: string | number): Color {
449
- if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
456
+ // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) {
457
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
450
458
  this.a -= v / 100;
451
459
  } else if ("number" == typeof v) {
452
460
  if (v >= 0.0 && v <= 1.0) {
@@ -465,11 +473,13 @@ export class Color {
465
473
  return this;
466
474
  }
467
475
  spin(v: string | number): Color {
468
- if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) this.h += v / 100;
469
- else if ("number" == typeof v)
476
+ // if ("string" == typeof v && v.indexOf("%") > -1 && (v = parseInt(v)) != NaN) this.h += v / 100;
477
+ if ("string" == typeof v && v.indexOf("%") > -1 && !Number.isNaN(v = parseInt(v))) {
478
+ this.h += v / 100;
479
+ } else if ("number" == typeof v) {
470
480
  // range 360
471
481
  this.h += v / 360;
472
- else throw new Error("error: bad modifier format (percent or number)");
482
+ } else throw new Error("error: bad modifier format (percent or number)");
473
483
  if (this.h > 1) this.h = 1;
474
484
  else if (this.h < 0) this.h = 0;
475
485
  Color.Converter.HSLToRGB(this);
@@ -579,11 +589,16 @@ export class Color {
579
589
  for (var i = 0; i < arguments.length; i++) {
580
590
  var c = arguments[i];
581
591
  if ("string" == typeof c && c.indexOf("%") > -1) {
582
- if ((c = parseInt(c)) == NaN) throw new Error("Bad format");
592
+ // if ((c = parseInt(c)) == NaN) throw new Error("Bad format");
593
+ if (Number.isNaN(c = parseInt(c))) {
594
+ throw new Error("Bad format");
595
+ }
583
596
  if (c < 0 || c > 100) throw new Error("Bad format");
584
597
  o[i] = c / 100;
585
598
  } else {
586
- if ("string" == typeof c && (c = parseInt(c)) == NaN) {
599
+ // if ("string" == typeof c && (c = parseInt(c)) == NaN) {
600
+ if ("string" == typeof c && Number.isNaN(c = parseInt(c))) {
601
+
587
602
  throw new Error("Bad format");
588
603
  }
589
604
  if (c < 0) {
@@ -610,16 +625,25 @@ export class Color {
610
625
  var h = arguments[0],
611
626
  s = arguments[1],
612
627
  l = arguments[2];
613
- if ("string" == typeof h && (h = parseFloat(h)) == NaN) throw new Error("Bad format for hue");
628
+ // if ("string" == typeof h && (h = parseFloat(h)) == NaN) throw new Error("Bad format for hue");
629
+ if ("string" == typeof h && Number.isNaN(h = parseFloat(h))) {
630
+ throw new Error("Bad format for hue");
631
+ }
614
632
  if (h < 0 || h > 360) throw new Error("Hue out of range (0..360)");
615
633
  else if ((("" + h).indexOf(".") > -1 && h > 1) || ("" + h).indexOf(".") == -1) h /= 360;
616
634
  if ("string" == typeof s && s.indexOf("%") > -1) {
617
- if ((s = parseInt(s)) == NaN) throw new Error("Bad format for saturation");
635
+ // if ((s = parseInt(s)) == NaN) throw new Error("Bad format for saturation");
636
+ if (Number.isNaN(s = parseInt(s))) {
637
+ throw new Error("Bad format for saturation");
638
+ }
618
639
  if (s < 0 || s > 100) throw new Error("Bad format for saturation");
619
640
  s /= 100;
620
641
  } else if (s < 0 || s > 1) throw new Error("Bad format for saturation");
621
642
  if ("string" == typeof l && l.indexOf("%") > -1) {
622
- if ((l = parseInt(l)) == NaN) throw new Error("Bad format for lightness");
643
+ // if ((l = parseInt(l)) == NaN) throw new Error("Bad format for lightness");
644
+ if (Number.isNaN(l = parseInt(l))) {
645
+ throw new Error("Bad format for lightness");
646
+ }
623
647
  if (l < 0 || l > 100) throw new Error("Bad format for lightness");
624
648
  l /= 100;
625
649
  } else if (l < 0 || l > 1) throw new Error("Bad format for lightness");
@@ -2,7 +2,8 @@
2
2
  * @author Ikaros Kappler
3
3
  * @date 2020-11-24
4
4
  * @modified 2020-11-25 Ported to TypeScript from vanilla JS.
5
- * @version 1.0.1
5
+ * @modified 2024-03-10 Fixed some types for Typescript 5 compatibility.
6
+ * @version 1.0.2
6
7
  * @file Girih
7
8
  **/
8
9
 
@@ -100,11 +101,11 @@ export class Girih {
100
101
 
101
102
  // Add tiles to array and put them in the correct adjacency position.
102
103
  this.TILE_TEMPLATES.push(decagon);
103
- this.TILE_TEMPLATES.push(decagon.transformTilePositionToAdjacency(2, pentagon));
104
- this.TILE_TEMPLATES.push(pentagon.transformTilePositionToAdjacency(1, penrose));
105
- this.TILE_TEMPLATES.push(penrose.transformTilePositionToAdjacency(3, hexagon));
106
- this.TILE_TEMPLATES.push(decagon.transformTilePositionToAdjacency(5, bowtie));
107
- this.TILE_TEMPLATES.push(pentagon.transformTilePositionToAdjacency(4, rhombus));
104
+ this.TILE_TEMPLATES.push(decagon.transformTilePositionToAdjacency(2, pentagon) as any as GirihTile);
105
+ this.TILE_TEMPLATES.push(pentagon.transformTilePositionToAdjacency(1, penrose) as any as GirihTile);
106
+ this.TILE_TEMPLATES.push(penrose.transformTilePositionToAdjacency(3, hexagon) as any as GirihTile);
107
+ this.TILE_TEMPLATES.push(decagon.transformTilePositionToAdjacency(5, bowtie) as any as GirihTile);
108
+ this.TILE_TEMPLATES.push(pentagon.transformTilePositionToAdjacency(4, rhombus) as any as GirihTile);
108
109
  }
109
110
 
110
111
  /**
@@ -137,7 +138,7 @@ export class Girih {
137
138
  *
138
139
  * @param tiles
139
140
  */
140
- replaceTiles(tiles: GirihTile): void {
141
+ replaceTiles(tiles: GirihTile[]): void {
141
142
  this.tiles.splice(0, this.tiles.length);
142
143
  for (var i in tiles) {
143
144
  this.addTile(tiles[i]);
@@ -218,7 +219,7 @@ export class Girih {
218
219
  // TODO: still required?
219
220
  return [];
220
221
 
221
- let template: GirihTile = null;
222
+ let template: GirihTile | null = null;
222
223
  for (var i in this.TILE_TEMPLATES) {
223
224
  template = this.TILE_TEMPLATES[i].clone();
224
225
  // Find all rotations and positions for that tile to match
@@ -1,6 +1,14 @@
1
1
  /**
2
+ * `gup` = "Get URL/URI Params".
3
+ *
4
+ * This function simply taktes the location string from the broser bar and retrieves all GET params
5
+ * as a record of string mappings.
6
+ *
7
+ * You can pass that result into the `Params` class to get proper type conversion for numbers and booleans.
8
+ *
2
9
  * Ported to typescript.
3
10
  * @date 2021-05-21
11
+ * @modified 2024-03-10 Fixed some type for Typescript 5 compatibility.
4
12
  */
5
13
 
6
14
  // Get the URI GET params as an assoc.
@@ -9,9 +17,9 @@
9
17
  // Found at
10
18
  // https://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-get-parameters?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
11
19
  export const gup = (): Record<string, string> => {
12
- const vars = {};
20
+ const vars: Record<string, string> = {};
13
21
  globalThis.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, (_m: string, key: string, value: string): string => {
14
- return (vars[key] = value);
22
+ return (vars[key as keyof Object] = value);
15
23
  });
16
24
  return vars;
17
25
  };
@@ -21,7 +21,8 @@
21
21
  * @modified 2021-01-03 Added following new functions: `addPathVertexDragStartListeners`, `removePathVertexDragStartListeners`, `addPathVertexDragEndListeners` and `removePathVertexDragEndListeners`.
22
22
  * @modified 2021-03-31 Fixed the issue with the new AlloyFinger (Typescript).
23
23
  * @modified 2022-02-03 Changing the element to catch events (eventCatcher instead of canvas).
24
- * @version 1.1.2
24
+ * @modified 2024-03-10 Fixing some types for Typescript 5 compatibility.
25
+ * @version 1.1.3
25
26
  *
26
27
  * @file BezierPathInteractionHelper
27
28
  * @public
@@ -44,7 +45,7 @@ import { XYCoords } from "../../interfaces";
44
45
  /**
45
46
  * Handler type for mouse-pointer-moved listeners.
46
47
  */
47
- type OnPointerMoved = (pathIndex: number, pathPoint: Vertex, pointerPos: Vertex, t: number) => void;
48
+ type OnPointerMoved = (pathIndex: number, pathPoint: Vertex | null, pointerPos: Vertex | null, t: number) => void;
48
49
  /**
49
50
  * Handler type for vertex-inserted listeners.
50
51
  */
@@ -152,7 +153,7 @@ export class BezierPathInteractionHelper {
152
153
  this.pb = pb;
153
154
  this.paths = [];
154
155
  this.onPointerMoved =
155
- typeof options.onPointerMoved === "function" ? options.onPointerMoved : (i: number, a: Vertex, b: Vertex, t: number) => {};
156
+ typeof options.onPointerMoved === "function" ? options.onPointerMoved : (i: number, a: Vertex | null, b: Vertex | null, t: number) => {};
156
157
  this.onVertexInserted =
157
158
  typeof options.onVertexInserted === "function"
158
159
  ? options.onVertexInserted
@@ -451,8 +452,8 @@ export class BezierPathInteractionHelper {
451
452
  _self._clearMoveEvent();
452
453
  }
453
454
  };
454
- if (window["createAlloyFinger"]) {
455
- return window["createAlloyFinger"](this.pb.eventCatcher ? this.pb.eventCatcher : this.pb.eventCatcher, afProps);
455
+ if (window["createAlloyFinger" as keyof Object]) {
456
+ return (window["createAlloyFinger" as keyof Object] as any)(this.pb.eventCatcher ? this.pb.eventCatcher : this.pb.eventCatcher, afProps);
456
457
  } else {
457
458
  return new AlloyFinger(this.pb.eventCatcher ? this.pb.eventCatcher : this.pb.eventCatcher, afProps);
458
459
  }
@@ -469,11 +470,11 @@ export class BezierPathInteractionHelper {
469
470
  if (_self._keyHandler.isDown("shift")) return;
470
471
  if (_self.currentDistance > _self.maxDetectDistance || !_self.mouseIsOver) return;
471
472
  const path: BezierPath = _self.paths[_self.currentPathIndex];
472
- const vertex: Vertex = _self.pb.getVertexNear(e.params.pos, PlotBoilerplate.DEFAULT_CLICK_TOLERANCE);
473
+ const vertex: Vertex | undefined = _self.pb.getVertexNear(e.params.pos, PlotBoilerplate.DEFAULT_CLICK_TOLERANCE);
473
474
  if (vertex) return;
474
475
  // Check if there is already a path point at the given split position
475
476
  const pathPoint: Vertex = path.getPointAt(_self.currentT);
476
- const pointNear: Vertex = _self.pb.getVertexNear(_self.pb.revertMousePosition(pathPoint.x, pathPoint.y), 6.0);
477
+ const pointNear: Vertex | undefined = _self.pb.getVertexNear(_self.pb.revertMousePosition(pathPoint.x, pathPoint.y), 6.0);
477
478
  if (pointNear) {
478
479
  for (var i = 0; i < path.bezierCurves.length; i++) {
479
480
  if (
@@ -556,7 +557,7 @@ export class BezierPathInteractionHelper {
556
557
  this.currentT = closestT;
557
558
  this.currentPathIndex = pathIndex;
558
559
  this.currentDistance = minDist;
559
- this.currentA.set(closestPoint);
560
+ closestPoint && this.currentA.set(closestPoint);
560
561
  }
561
562
 
562
563
  // +---------------------------------------------------------------------------------
@@ -7,37 +7,85 @@
7
7
  * @date 2020-09-07
8
8
  * @modified 2020-10-18 Ported to Typescript from vanilla JS.
9
9
  * @modified 2021-01-22 Removed `pb.redraw()` call from update handlers (changed vertices already triggered redraw).
10
- * @version 1.0.1
10
+ * @modified 2024-02-26 Removed the constructor param `pb` (unused).
11
+ * @modified 2024-02-25 Added `circle` and `radiusPoint` attributes.
12
+ * @modified 2024-03-10 Fixed some issues in the `destroy` method; listeners were not properly removed.
13
+ * @version 1.2.1
11
14
  **/
12
15
 
13
16
  import { Circle } from "../../Circle";
14
- import { PlotBoilerplate } from "../../PlotBoilerplate";
15
- import { VertEvent } from "../../VertexListeners";
17
+ import { VertEvent, VertListener } from "../../VertexListeners";
16
18
  import { Vertex } from "../../Vertex";
17
19
 
18
-
19
20
  /**
20
21
  * @classdesc A helper for handling circles with an additional radius-control-point.
21
22
  */
22
23
  export class CircleHelper {
24
+ circle: Circle;
25
+ radiusPoint: Vertex;
26
+
27
+ private centerHandler: VertListener;
28
+ private radiusHandler: VertListener;
29
+
30
+ /**
31
+ * The constructor.
32
+ *
33
+ * @constructor
34
+ * @name CircleHelper
35
+ * @param {Circle} circle - The circle to handle.
36
+ * @param {Vertex} radiusPoint - A point to define the radius (distance from center).
37
+ * @param {PlotBoilerplate} pb - The PlotBoilerplate which contains the circle and point.
38
+ **/
39
+ constructor(circle: Circle, radiusPoint: Vertex) {
40
+ this.circle = circle;
41
+ this.radiusPoint = radiusPoint;
42
+
43
+ circle.center.listeners.addDragListener( this.centerHandler = this._handleDragCenter());
44
+ radiusPoint.listeners.addDragListener(this.radiusHandler = this._handleDragRadiusPoint());
45
+ }
46
+
47
+ /**
48
+ * Destroy this circle helper.
49
+ * The listeners will be removed from the circle points.
50
+ *
51
+ * @method destroy
52
+ * @instance
53
+ * @memberof CircleHelper
54
+ */
55
+ destroy() {
56
+ this.circle.center.listeners.removeDragListener(this.centerHandler);
57
+ this.radiusPoint.listeners.removeDragListener(this.radiusHandler);
58
+ }
59
+
60
+ /**
61
+ * Creates a new drag handler for the circle's center point.
62
+ *
63
+ * @private
64
+ * @method _handleDragCenter
65
+ * @instance
66
+ * @memberof CircleHelper
67
+ * @returns A new event handler.
68
+ */
69
+ private _handleDragCenter(): VertListener {
70
+ const _self = this;
71
+ return (evt: VertEvent) => {
72
+ _self.radiusPoint.add(evt.params.dragAmount);
73
+ };
74
+ }
23
75
 
24
- /**
25
- * The constructor.
26
- *
27
- * @constructor
28
- * @name CircleHelper
29
- * @param {Circle} circle - The circle to handle.
30
- * @param {Vertex} radiusPoint - A point to define the radius (distance from center).
31
- * @param {PlotBoilerplate} pb - The PlotBoilerplate which contains the circle and point.
32
- **/
33
- constructor( circle:Circle, radiusPoint:Vertex, pb:PlotBoilerplate ) {
34
- circle.center.listeners.addDragListener( (e:VertEvent) => {
35
- radiusPoint.add( e.params.dragAmount );
36
- // pb.redraw();
37
- } );
38
- radiusPoint.listeners.addDragListener( (e:VertEvent) => {
39
- circle.radius = circle.center.distance( radiusPoint );
40
- // pb.redraw();
41
- } );
76
+ /**
77
+ * Creates a new drag handler for the circle's radius control point.
78
+ *
79
+ * @private
80
+ * @method _handleDragCenter
81
+ * @instance
82
+ * @memberof CircleHelper
83
+ * @returns A new event handler.
84
+ */
85
+ private _handleDragRadiusPoint(): VertListener {
86
+ const _self = this;
87
+ return (_evt: VertEvent) => {
88
+ _self.circle.radius = _self.circle.center.distance(_self.radiusPoint);
42
89
  };
90
+ }
43
91
  }