plotboilerplate 1.21.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 (325) hide show
  1. package/README.md +2 -0
  2. package/dist/index.esm.js +252 -77
  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 +522 -338
  9. package/dist/plotboilerplate.min.js +1 -1
  10. package/package.json +7 -5
  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.d.ts +13 -1
  33. package/src/cjs/Polygon.js +30 -1
  34. package/src/cjs/Polygon.js.map +1 -1
  35. package/src/cjs/Triangle.js +1 -1
  36. package/src/cjs/Triangle.js.map +1 -1
  37. package/src/cjs/UIDGenerator.js +1 -1
  38. package/src/cjs/UIDGenerator.js.map +1 -1
  39. package/src/cjs/VEllipse.js.map +1 -1
  40. package/src/cjs/VEllipseSector.js +1 -1
  41. package/src/cjs/VEllipseSector.js.map +1 -1
  42. package/src/cjs/Vector.js +2 -0
  43. package/src/cjs/Vector.js.map +1 -1
  44. package/src/cjs/VertTuple.js.map +1 -1
  45. package/src/cjs/Vertex.d.ts +3 -2
  46. package/src/cjs/Vertex.js +13 -7
  47. package/src/cjs/Vertex.js.map +1 -1
  48. package/src/cjs/VertexAttr.d.ts +2 -1
  49. package/src/cjs/VertexAttr.js +2 -1
  50. package/src/cjs/VertexAttr.js.map +1 -1
  51. package/src/cjs/VertexListeners.d.ts +1 -1
  52. package/src/cjs/VertexListeners.js.map +1 -1
  53. package/src/cjs/draw.js +1 -1
  54. package/src/cjs/draw.js.map +1 -1
  55. package/src/cjs/drawgl.js.map +1 -1
  56. package/src/cjs/drawutilssvg.d.ts +17 -3
  57. package/src/cjs/drawutilssvg.js +97 -91
  58. package/src/cjs/drawutilssvg.js.map +1 -1
  59. package/src/cjs/geomutils.js +2 -2
  60. package/src/cjs/geomutils.js.map +1 -1
  61. package/src/cjs/index.js +5 -1
  62. package/src/cjs/index.js.map +1 -1
  63. package/src/cjs/interfaces/DrawLib.d.ts +2 -2
  64. package/src/cjs/interfaces/core.d.ts +3 -3
  65. package/src/cjs/interfaces/index.js +5 -1
  66. package/src/cjs/interfaces/index.js.map +1 -1
  67. package/src/cjs/utils/NGons.d.ts +13 -0
  68. package/src/cjs/utils/NGons.js +36 -0
  69. package/src/cjs/utils/NGons.js.map +1 -0
  70. package/src/cjs/utils/Params.d.ts +15 -0
  71. package/src/cjs/utils/Params.js +49 -0
  72. package/src/cjs/utils/Params.js.map +1 -0
  73. package/src/cjs/utils/WebColors.js.map +1 -1
  74. package/src/cjs/utils/WebColorsContrast.js +1 -1
  75. package/src/cjs/utils/WebColorsContrast.js.map +1 -1
  76. package/src/cjs/utils/algorithms/CatmullRomPath.js.map +1 -1
  77. package/src/cjs/utils/algorithms/CircleIntersections.d.ts +3 -2
  78. package/src/cjs/utils/algorithms/CircleIntersections.js +12 -20
  79. package/src/cjs/utils/algorithms/CircleIntersections.js.map +1 -1
  80. package/src/cjs/utils/algorithms/ContourLineDetection.d.ts +150 -0
  81. package/src/cjs/utils/algorithms/ContourLineDetection.js +367 -0
  82. package/src/cjs/utils/algorithms/ContourLineDetection.js.map +1 -0
  83. package/src/cjs/utils/algorithms/CubicSplinePath.js.map +1 -1
  84. package/src/cjs/utils/algorithms/HobbyPath.js.map +1 -1
  85. package/src/cjs/utils/algorithms/Metaballs.d.ts +30 -0
  86. package/src/cjs/utils/algorithms/Metaballs.js +114 -0
  87. package/src/cjs/utils/algorithms/Metaballs.js.map +1 -0
  88. package/src/cjs/utils/algorithms/arrayResize.d.ts +8 -0
  89. package/src/cjs/utils/algorithms/arrayResize.js +24 -0
  90. package/src/cjs/utils/algorithms/arrayResize.js.map +1 -0
  91. package/src/cjs/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  92. package/src/cjs/utils/algorithms/clearDuplicateVertices.js +48 -0
  93. package/src/cjs/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  94. package/src/cjs/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  95. package/src/cjs/utils/algorithms/convexHull.js.map +1 -1
  96. package/src/cjs/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  97. package/src/cjs/utils/algorithms/delaunay.js.map +1 -1
  98. package/src/cjs/utils/algorithms/delaunay2voronoi.js.map +1 -1
  99. package/src/cjs/utils/algorithms/detectPaths.js.map +1 -1
  100. package/src/cjs/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  101. package/src/cjs/utils/algorithms/matrixFill.js +1 -1
  102. package/src/cjs/utils/algorithms/matrixFill.js.map +1 -1
  103. package/src/cjs/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  104. package/src/cjs/utils/algorithms/sutherlandHodgman.js.map +1 -1
  105. package/src/cjs/utils/cloneVertexArray.js.map +1 -1
  106. package/src/cjs/utils/creategui.js +20 -12
  107. package/src/cjs/utils/datastructures/CircularIntervalSet.js.map +1 -1
  108. package/src/cjs/utils/datastructures/Color.d.ts +2 -1
  109. package/src/cjs/utils/datastructures/Color.js +35 -16
  110. package/src/cjs/utils/datastructures/Color.js.map +1 -1
  111. package/src/cjs/utils/datastructures/DataGrid2d.d.ts +47 -0
  112. package/src/cjs/utils/datastructures/DataGrid2d.js +20 -0
  113. package/src/cjs/utils/datastructures/DataGrid2d.js.map +1 -0
  114. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  115. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js +84 -0
  116. package/src/cjs/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  117. package/src/cjs/utils/datastructures/GenericPath.d.ts +14 -3
  118. package/src/cjs/utils/datastructures/GenericPath.js +20 -3
  119. package/src/cjs/utils/datastructures/GenericPath.js.map +1 -1
  120. package/src/cjs/utils/datastructures/Girih.d.ts +3 -2
  121. package/src/cjs/utils/datastructures/Girih.js +2 -1
  122. package/src/cjs/utils/datastructures/Girih.js.map +1 -1
  123. package/src/cjs/utils/datastructures/GirihBowtie.js +2 -0
  124. package/src/cjs/utils/datastructures/GirihBowtie.js.map +1 -1
  125. package/src/cjs/utils/datastructures/GirihDecagon.js +2 -0
  126. package/src/cjs/utils/datastructures/GirihDecagon.js.map +1 -1
  127. package/src/cjs/utils/datastructures/GirihHexagon.js +2 -0
  128. package/src/cjs/utils/datastructures/GirihHexagon.js.map +1 -1
  129. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js +3 -1
  130. package/src/cjs/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  131. package/src/cjs/utils/datastructures/GirihPentagon.js +2 -0
  132. package/src/cjs/utils/datastructures/GirihPentagon.js.map +1 -1
  133. package/src/cjs/utils/datastructures/GirihRhombus.js +2 -0
  134. package/src/cjs/utils/datastructures/GirihRhombus.js.map +1 -1
  135. package/src/cjs/utils/datastructures/GirihTile.js +4 -2
  136. package/src/cjs/utils/datastructures/GirihTile.js.map +1 -1
  137. package/src/cjs/utils/datastructures/Matrix4x4.js.map +1 -1
  138. package/src/cjs/utils/datastructures/VoronoiCell.js.map +1 -1
  139. package/src/cjs/utils/datastructures/interfaces.d.ts +3 -3
  140. package/src/cjs/utils/detectDarkMode.js.map +1 -1
  141. package/src/cjs/utils/dom/getAvailableContainerSpace.js +1 -1
  142. package/src/cjs/utils/dom/getAvailableContainerSpace.js.map +1 -1
  143. package/src/cjs/utils/findInVertexArray.js.map +1 -1
  144. package/src/cjs/utils/gup.d.ts +8 -0
  145. package/src/cjs/utils/gup.js +8 -0
  146. package/src/cjs/utils/gup.js.map +1 -1
  147. package/src/cjs/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  148. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js +3 -2
  149. package/src/cjs/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  150. package/src/cjs/utils/helpers/CircleHelper.d.ts +38 -3
  151. package/src/cjs/utils/helpers/CircleHelper.js +51 -11
  152. package/src/cjs/utils/helpers/CircleHelper.js.map +1 -1
  153. package/src/cjs/utils/helpers/CircleSectorHelper.d.ts +47 -1
  154. package/src/cjs/utils/helpers/CircleSectorHelper.js +85 -14
  155. package/src/cjs/utils/helpers/CircleSectorHelper.js.map +1 -1
  156. package/src/cjs/utils/io/FileDrop.d.ts +3 -3
  157. package/src/cjs/utils/io/FileDrop.js.map +1 -1
  158. package/src/cjs/utils/parsers/OBJParser.d.ts +2 -2
  159. package/src/cjs/utils/parsers/OBJParser.js.map +1 -1
  160. package/src/cjs/utils/parsers/STLParser.d.ts +4 -3
  161. package/src/cjs/utils/parsers/STLParser.js +62 -12
  162. package/src/cjs/utils/parsers/STLParser.js.map +1 -1
  163. package/src/cjs/utils/parsers/svg/parseSVGPathData.js +1 -1
  164. package/src/cjs/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  165. package/src/cjs/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  166. package/src/cjs/utils/parsers/svg/types.d.ts +13 -13
  167. package/src/createDemoDrawables.js +48 -3
  168. package/src/esm/BezierPath.js.map +1 -1
  169. package/src/esm/Bounds.js.map +1 -1
  170. package/src/esm/Circle.js.map +1 -1
  171. package/src/esm/CircleSector.d.ts +64 -1
  172. package/src/esm/CircleSector.js +121 -1
  173. package/src/esm/CircleSector.js.map +1 -1
  174. package/src/esm/CubicBezierCurve.js.map +1 -1
  175. package/src/esm/Grid.js.map +1 -1
  176. package/src/esm/KeyHandler.d.ts +1 -1
  177. package/src/esm/KeyHandler.js +13 -13
  178. package/src/esm/KeyHandler.js.map +1 -1
  179. package/src/esm/Line.js.map +1 -1
  180. package/src/esm/MouseHandler.d.ts +2 -2
  181. package/src/esm/MouseHandler.js +4 -4
  182. package/src/esm/MouseHandler.js.map +1 -1
  183. package/src/esm/PlotBoilerplate.d.ts +1 -1
  184. package/src/esm/PlotBoilerplate.js +43 -29
  185. package/src/esm/PlotBoilerplate.js.map +1 -1
  186. package/src/esm/Polygon.d.ts +13 -1
  187. package/src/esm/Polygon.js +30 -1
  188. package/src/esm/Polygon.js.map +1 -1
  189. package/src/esm/Triangle.js.map +1 -1
  190. package/src/esm/VEllipse.js.map +1 -1
  191. package/src/esm/VEllipseSector.js +1 -1
  192. package/src/esm/VEllipseSector.js.map +1 -1
  193. package/src/esm/Vector.js.map +1 -1
  194. package/src/esm/VertTuple.js.map +1 -1
  195. package/src/esm/Vertex.d.ts +3 -2
  196. package/src/esm/Vertex.js +9 -3
  197. package/src/esm/Vertex.js.map +1 -1
  198. package/src/esm/VertexAttr.d.ts +2 -1
  199. package/src/esm/VertexAttr.js +2 -1
  200. package/src/esm/VertexAttr.js.map +1 -1
  201. package/src/esm/VertexListeners.d.ts +1 -1
  202. package/src/esm/VertexListeners.js.map +1 -1
  203. package/src/esm/draw.js.map +1 -1
  204. package/src/esm/drawgl.js.map +1 -1
  205. package/src/esm/drawutilssvg.d.ts +17 -3
  206. package/src/esm/drawutilssvg.js +28 -22
  207. package/src/esm/drawutilssvg.js.map +1 -1
  208. package/src/esm/geomutils.js +2 -2
  209. package/src/esm/geomutils.js.map +1 -1
  210. package/src/esm/interfaces/DrawLib.d.ts +2 -2
  211. package/src/esm/interfaces/core.d.ts +3 -3
  212. package/src/esm/utils/NGons.d.ts +13 -0
  213. package/src/esm/utils/NGons.js +33 -0
  214. package/src/esm/utils/NGons.js.map +1 -0
  215. package/src/esm/utils/Params.d.ts +15 -0
  216. package/src/esm/utils/Params.js +44 -0
  217. package/src/esm/utils/Params.js.map +1 -0
  218. package/src/esm/utils/WebColors.js.map +1 -1
  219. package/src/esm/utils/algorithms/CatmullRomPath.js.map +1 -1
  220. package/src/esm/utils/algorithms/CircleIntersections.d.ts +3 -2
  221. package/src/esm/utils/algorithms/CircleIntersections.js +11 -19
  222. package/src/esm/utils/algorithms/CircleIntersections.js.map +1 -1
  223. package/src/esm/utils/algorithms/ContourLineDetection.d.ts +150 -0
  224. package/src/esm/utils/algorithms/ContourLineDetection.js +362 -0
  225. package/src/esm/utils/algorithms/ContourLineDetection.js.map +1 -0
  226. package/src/esm/utils/algorithms/CubicSplinePath.js.map +1 -1
  227. package/src/esm/utils/algorithms/HobbyPath.js.map +1 -1
  228. package/src/esm/utils/algorithms/Metaballs.d.ts +30 -0
  229. package/src/esm/utils/algorithms/Metaballs.js +109 -0
  230. package/src/esm/utils/algorithms/Metaballs.js.map +1 -0
  231. package/src/esm/utils/algorithms/arrayResize.d.ts +8 -0
  232. package/src/esm/utils/algorithms/arrayResize.js +20 -0
  233. package/src/esm/utils/algorithms/arrayResize.js.map +1 -0
  234. package/src/esm/utils/algorithms/clearDuplicateVertices.d.ts +21 -0
  235. package/src/esm/utils/algorithms/clearDuplicateVertices.js +44 -0
  236. package/src/esm/utils/algorithms/clearDuplicateVertices.js.map +1 -0
  237. package/src/esm/utils/algorithms/clearPolygonDuplicateVertices.js.map +1 -1
  238. package/src/esm/utils/algorithms/convexHull.js.map +1 -1
  239. package/src/esm/utils/algorithms/convexPolygonIncircle.js.map +1 -1
  240. package/src/esm/utils/algorithms/delaunay.js.map +1 -1
  241. package/src/esm/utils/algorithms/delaunay2voronoi.js.map +1 -1
  242. package/src/esm/utils/algorithms/detectPaths.js.map +1 -1
  243. package/src/esm/utils/algorithms/findPolygonSelfIntersections.js.map +1 -1
  244. package/src/esm/utils/algorithms/matrixFill.js.map +1 -1
  245. package/src/esm/utils/algorithms/splitPolygonToNonIntersecting.js.map +1 -1
  246. package/src/esm/utils/algorithms/sutherlandHodgman.js.map +1 -1
  247. package/src/esm/utils/cloneVertexArray.js.map +1 -1
  248. package/src/esm/utils/datastructures/CircularIntervalSet.js.map +1 -1
  249. package/src/esm/utils/datastructures/Color.d.ts +2 -1
  250. package/src/esm/utils/datastructures/Color.js +33 -14
  251. package/src/esm/utils/datastructures/Color.js.map +1 -1
  252. package/src/esm/utils/datastructures/DataGrid2d.d.ts +47 -0
  253. package/src/esm/utils/datastructures/DataGrid2d.js +19 -0
  254. package/src/esm/utils/datastructures/DataGrid2d.js.map +1 -0
  255. package/src/esm/utils/datastructures/DataGrid2dListAdapter.d.ts +65 -0
  256. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js +79 -0
  257. package/src/esm/utils/datastructures/DataGrid2dListAdapter.js.map +1 -0
  258. package/src/esm/utils/datastructures/GenericPath.d.ts +14 -3
  259. package/src/esm/utils/datastructures/GenericPath.js +20 -3
  260. package/src/esm/utils/datastructures/GenericPath.js.map +1 -1
  261. package/src/esm/utils/datastructures/Girih.d.ts +3 -2
  262. package/src/esm/utils/datastructures/Girih.js +2 -1
  263. package/src/esm/utils/datastructures/Girih.js.map +1 -1
  264. package/src/esm/utils/datastructures/GirihBowtie.js.map +1 -1
  265. package/src/esm/utils/datastructures/GirihDecagon.js.map +1 -1
  266. package/src/esm/utils/datastructures/GirihHexagon.js.map +1 -1
  267. package/src/esm/utils/datastructures/GirihPenroseRhombus.js +1 -1
  268. package/src/esm/utils/datastructures/GirihPenroseRhombus.js.map +1 -1
  269. package/src/esm/utils/datastructures/GirihPentagon.js.map +1 -1
  270. package/src/esm/utils/datastructures/GirihRhombus.js.map +1 -1
  271. package/src/esm/utils/datastructures/GirihTile.js.map +1 -1
  272. package/src/esm/utils/datastructures/Matrix4x4.js.map +1 -1
  273. package/src/esm/utils/datastructures/VoronoiCell.js.map +1 -1
  274. package/src/esm/utils/datastructures/interfaces.d.ts +3 -3
  275. package/src/esm/utils/detectDarkMode.js.map +1 -1
  276. package/src/esm/utils/findInVertexArray.js.map +1 -1
  277. package/src/esm/utils/gup.d.ts +8 -0
  278. package/src/esm/utils/gup.js +8 -0
  279. package/src/esm/utils/gup.js.map +1 -1
  280. package/src/esm/utils/helpers/BezierPathInteractionHelper.d.ts +6 -5
  281. package/src/esm/utils/helpers/BezierPathInteractionHelper.js +3 -2
  282. package/src/esm/utils/helpers/BezierPathInteractionHelper.js.map +1 -1
  283. package/src/esm/utils/helpers/CircleHelper.d.ts +38 -3
  284. package/src/esm/utils/helpers/CircleHelper.js +51 -11
  285. package/src/esm/utils/helpers/CircleHelper.js.map +1 -1
  286. package/src/esm/utils/helpers/CircleSectorHelper.d.ts +47 -1
  287. package/src/esm/utils/helpers/CircleSectorHelper.js +85 -14
  288. package/src/esm/utils/helpers/CircleSectorHelper.js.map +1 -1
  289. package/src/esm/utils/io/FileDrop.d.ts +3 -3
  290. package/src/esm/utils/io/FileDrop.js.map +1 -1
  291. package/src/esm/utils/parsers/OBJParser.d.ts +2 -2
  292. package/src/esm/utils/parsers/OBJParser.js.map +1 -1
  293. package/src/esm/utils/parsers/STLParser.d.ts +4 -3
  294. package/src/esm/utils/parsers/STLParser.js +63 -13
  295. package/src/esm/utils/parsers/STLParser.js.map +1 -1
  296. package/src/esm/utils/parsers/svg/parseSVGPathData.js.map +1 -1
  297. package/src/esm/utils/parsers/svg/splitSVGPathData.js.map +1 -1
  298. package/src/esm/utils/parsers/svg/types.d.ts +13 -13
  299. package/src/index-gl.js +77 -85
  300. package/src/index.js +124 -129
  301. package/src/ts/CircleSector.ts +134 -3
  302. package/src/ts/PlotBoilerplate.ts +20 -11
  303. package/src/ts/Polygon.ts +31 -1
  304. package/src/ts/Vertex.ts +8 -3
  305. package/src/ts/VertexAttr.ts +3 -2
  306. package/src/ts/drawutilssvg.ts +38 -25
  307. package/src/ts/geomutils.ts +60 -64
  308. package/src/ts/interfaces/DrawLib.ts +0 -15
  309. package/src/ts/utils/NGons.ts +35 -0
  310. package/src/ts/utils/Params.ts +47 -0
  311. package/src/ts/utils/algorithms/CircleIntersections.ts +280 -288
  312. package/src/ts/utils/algorithms/ContourLineDetection.ts +485 -0
  313. package/src/ts/utils/algorithms/Metaballs.ts +144 -0
  314. package/src/ts/utils/algorithms/arrayResize.ts +22 -0
  315. package/src/ts/utils/algorithms/clearDuplicateVertices.ts +49 -0
  316. package/src/ts/utils/datastructures/Color.ts +39 -15
  317. package/src/ts/utils/datastructures/DataGrid2d.ts +54 -0
  318. package/src/ts/utils/datastructures/DataGrid2dListAdapter.ts +121 -0
  319. package/src/ts/utils/datastructures/GenericPath.ts +21 -3
  320. package/src/ts/utils/datastructures/Girih.ts +9 -8
  321. package/src/ts/utils/gup.ts +10 -2
  322. package/src/ts/utils/helpers/BezierPathInteractionHelper.ts +9 -8
  323. package/src/ts/utils/helpers/CircleHelper.ts +70 -22
  324. package/src/ts/utils/helpers/CircleSectorHelper.ts +101 -17
  325. package/src/ts/utils/parsers/STLParser.ts +50 -16
@@ -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");
@@ -0,0 +1,54 @@
1
+ /**
2
+ * A 2D datagrid interface for getting/storing data in some 2 dimensional array style types.
3
+ *
4
+ * _|---- xIndex --->
5
+ * | d[0][0], d[1][0], d[2][0], ..., d[xSegmentCount-1][0]
6
+ * yIndex
7
+ * | d[0][1], d[1][1], d[2][1], ..., d[xSegmentCount-1][1]
8
+ * |
9
+ * v ...
10
+ *
11
+ * d[0][ySegmentCount-1], ..., ..., d[xSegmentCount-1][ySegmentCount-1]
12
+ *
13
+ *
14
+ * @date 2023-11-04
15
+ * @author Ikaros Kappler
16
+ * @version 1.0.0
17
+ */
18
+
19
+ export type DataGridFace4<T> = [[T | null, T | null], [T | null, T | null]];
20
+
21
+ export interface IDataGrid2d<T> {
22
+ readonly xSegmentCount: number;
23
+
24
+ readonly ySegmentCount: number;
25
+
26
+ getMinDataValue(): T;
27
+
28
+ getMaxDataValue(): T;
29
+
30
+ getDataValueAt(xIndex: number, yIndex: number): T | null;
31
+
32
+ /**
33
+ * Extract a 2x2 matrix (a "face4") from the underlyting data.
34
+ *
35
+ * Imagine a face4 element like this
36
+ * (x,y) (x+1,y)
37
+ * A-----B
38
+ * | |
39
+ * | |
40
+ * D-----C
41
+ * (x,y+1) (x+1,y+1)
42
+ *
43
+ * then result in the buffer will be
44
+ * [ [A,B],
45
+ * [D,C] ]
46
+ *
47
+ * If any index is invalid then the resulting buffer element will be null.
48
+ *
49
+ * @param {number} xIndex - The x index in `0 <= xIndex < xSegmentCount`.
50
+ * @param {number} yIndex - The y index in `0 <= yIndex < ySegmentCount`.
51
+ * @param {[[T,T],[T,T]]} buffer - The result buffer for four elements.
52
+ */
53
+ getDataFace4At(xIndex: number, yIndex: number, buffer: DataGridFace4<T>): void;
54
+ }
@@ -0,0 +1,121 @@
1
+ /**
2
+ * A DataGrid2d implementation on a linear array of triplets/Vector3.
3
+ *
4
+ * @author Ikaros Kappler
5
+ * @date 2023-10-28
6
+ * @modified 2023-11-04 Converted to a Typescript class.
7
+ * @version 1.0.0
8
+ **/
9
+
10
+ import { DataGridFace4, IDataGrid2d } from "./DataGrid2d";
11
+
12
+ type Triplet<T> = {
13
+ x: T;
14
+ y: T;
15
+ z: T;
16
+ };
17
+
18
+ type RasterPosition = {
19
+ xIndex: number;
20
+ yIndex: number;
21
+ xRel?: number;
22
+ yRel?: number;
23
+ };
24
+
25
+ export class DataGrid2dListAdapter<T> implements IDataGrid2d<T> {
26
+ /**
27
+ * @override
28
+ */
29
+ readonly xSegmentCount: number;
30
+
31
+ /**
32
+ * @override
33
+ */
34
+ readonly ySegmentCount: number;
35
+
36
+ minDataValue: T;
37
+ maxDataValue: T;
38
+ minXValue: T;
39
+ maxXValue: T;
40
+ minYValue: T;
41
+ maxYValue: T;
42
+ private _dataList: Array<Triplet<T>>;
43
+
44
+ /**
45
+ * Create a new DataGrid2d from the given
46
+ * @throws Error if xSegmentCount*ySegmentCount is larger than the capacity of the array/list.
47
+ * @param list
48
+ * @param xSegmentCount
49
+ * @param ySegmentCount
50
+ */
51
+ constructor(list: Array<Triplet<T>>, xSegmentCount: number, ySegmentCount: number) {
52
+ if (xSegmentCount * ySegmentCount > list.length) {
53
+ throw `Cannot create DataGrid2dListAdapter, the list (length ${list.length}) does not provide enough items for ${xSegmentCount}x${ySegmentCount} required entries.`;
54
+ }
55
+
56
+ // this.canvas = document.getElementById(canvasId);
57
+ this.xSegmentCount = xSegmentCount;
58
+ this.ySegmentCount = ySegmentCount;
59
+
60
+ this._dataList = list;
61
+ }
62
+
63
+ getIndicesFromBufferIndex(bufferIndex: number): RasterPosition {
64
+ return { xIndex: Math.floor(bufferIndex % this.xSegmentCount), yIndex: Math.floor(bufferIndex / this.xSegmentCount) };
65
+ }
66
+
67
+ getCoordsFromBufferIndex(bufferIndex: number): RasterPosition {
68
+ var index = this.getIndicesFromBufferIndex(bufferIndex);
69
+ // Note that the xSegmentCount and ySegmentCount counts plane squares, each consisting of four vertices
70
+ index.xRel = index.xIndex / (this.xSegmentCount - 1);
71
+ index.yRel = index.yIndex / (this.ySegmentCount - 1);
72
+ return index;
73
+ }
74
+
75
+ coordinateIndicesToBufferIndex(xIndex: number, yIndex: number): number {
76
+ return yIndex * this.xSegmentCount + xIndex;
77
+ }
78
+
79
+ /**
80
+ * @override
81
+ */
82
+ getMinDataValue(): T {
83
+ return this.minDataValue;
84
+ }
85
+
86
+ /**
87
+ * @override
88
+ */
89
+ getMaxDataValue(): T {
90
+ return this.maxDataValue;
91
+ }
92
+
93
+ /**
94
+ * @override
95
+ */
96
+ getDataValueAt(xIndex: number, yIndex: number, isDebug?: boolean): T | null {
97
+ // var bufferIndex = yIndex * this.xSegmentCount + xIndex;
98
+ var bufferIndex = this.coordinateIndicesToBufferIndex(xIndex, yIndex);
99
+ if (isDebug) {
100
+ console.log("xIndex", xIndex, "yIndex", yIndex, "bufferIndex", bufferIndex);
101
+ }
102
+ if (bufferIndex > this._dataList.length) {
103
+ console.error("ERR buffer index is out of bounds! xIndex", xIndex, "yIndex", yIndex, "bufferIndex", bufferIndex);
104
+ }
105
+ if (!this._dataList[bufferIndex]) {
106
+ console.error("ERR buffer element is null! xIndex", xIndex, "yIndex", yIndex, "bufferIndex", bufferIndex);
107
+ }
108
+ return this._dataList && bufferIndex < this._dataList.length ? this._dataList[bufferIndex].z : null;
109
+ }
110
+
111
+ /**
112
+ * @override
113
+ */
114
+ getDataFace4At(xIndex: number, yIndex: number, buffer: DataGridFace4<T>) {
115
+ // buffer: array[2][2]
116
+ buffer[0][0] = this.getDataValueAt(xIndex, yIndex);
117
+ buffer[1][0] = this.getDataValueAt(xIndex + 1, yIndex);
118
+ buffer[1][1] = this.getDataValueAt(xIndex + 1, yIndex + 1);
119
+ buffer[0][1] = this.getDataValueAt(xIndex, yIndex + 1);
120
+ }
121
+ }
@@ -1,7 +1,8 @@
1
1
  /**
2
- * @author Ikaros Kappler
3
- * @version 1.0.0
4
- * @date 2022-10-17
2
+ * @author Ikaros Kappler
3
+ * @version 1.1.0
4
+ * @date 2022-10-17
5
+ * @modified 2023-11-27 Added the `GenericPath.getAllStartEndPoints()` function.
5
6
  */
6
7
 
7
8
  import { Path, PathSegment } from "../../interfaces/additionals";
@@ -110,4 +111,21 @@ export class GenericPath implements Path {
110
111
  getEndTangent(): Vertex {
111
112
  return this.segments[this.segments.length - 1].getEndTangent();
112
113
  }
114
+
115
+ /**
116
+ * Get the sequence of all start/end points of this path.
117
+ * Assumption is: each path segment's end point is located on the next segment's start point
118
+ * to shape a full connected path.
119
+ *
120
+ * No arcs are considered here, just plain linear segments.
121
+ *
122
+ * @returns {Array<Vertex>}
123
+ */
124
+ getAllStartEndPoints(): Array<Vertex> {
125
+ const verts: Array<Vertex> = [this.segments[0].getStartPoint()];
126
+ this.segments.forEach((segment: PathSegment) => {
127
+ verts.push(segment.getEndPoint());
128
+ });
129
+ return verts;
130
+ }
113
131
  }
@@ -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
  }