flo-mat 3.0.15 → 4.0.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 (572) hide show
  1. package/__tests__/cp-node/compare-cp-nodes-by-value.ts +5 -3
  2. package/__tests__/cp-node/compare-poss-by-value.ts +7 -7
  3. package/__tests__/cp-node/fs/get-all-on-circle.spec.ts +8 -8
  4. package/__tests__/cp-node/fs/is-one-prong.spec.ts +3 -3
  5. package/__tests__/cp-node/fs/is-sharp.spec.ts +1 -1
  6. package/__tests__/get-mats1.ts +29 -32
  7. package/__tests__/helpers/close-to.ts +71 -0
  8. package/__tests__/helpers/jest-extend-nearly.ts +39 -0
  9. package/__tests__/helpers/jest.setup.ts +6 -0
  10. package/__tests__/helpers/obj-or-array.ts +8 -0
  11. package/__tests__/jest-extensions.d.ts +26 -0
  12. package/__tests__/lib-load.spec.ts +1 -1
  13. package/browser/index.js +14846 -12124
  14. package/browser/index.min.js +1 -1
  15. package/jest.config.cjs +1 -0
  16. package/node/add-n-prong.ts/join-spokes.d.ts +2 -2
  17. package/node/add-n-prong.ts/join-spokes.js +5 -4
  18. package/node/add-n-prong.ts/join-spokes.js.map +1 -1
  19. package/node/closest-boundary-point/cull-bezier-pieces-1.d.ts +9 -0
  20. package/node/closest-boundary-point/{cull-bezier-pieces.js → cull-bezier-pieces-1.js} +6 -7
  21. package/node/closest-boundary-point/cull-bezier-pieces-1.js.map +1 -0
  22. package/node/closest-boundary-point/cull-by-loose-bounding-box.d.ts +7 -5
  23. package/node/closest-boundary-point/cull-by-loose-bounding-box.js +12 -10
  24. package/node/closest-boundary-point/cull-by-loose-bounding-box.js.map +1 -1
  25. package/node/closest-boundary-point/cull-by-tight-boundary-box.js +2 -2
  26. package/node/closest-boundary-point/foot-and-endpoint-info.d.ts +9 -9
  27. package/node/closest-boundary-point/get-best-distance-squared.d.ts +4 -3
  28. package/node/closest-boundary-point/get-best-distance-squared.js +11 -11
  29. package/node/closest-boundary-point/get-best-distance-squared.js.map +1 -1
  30. package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +5 -9
  31. package/node/closest-boundary-point/get-close-boundary-points-certified.js +22 -18
  32. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  33. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.d.ts +4 -8
  34. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +12 -79
  35. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
  36. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.d.ts +1 -1
  37. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js +5 -5
  38. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js.map +1 -1
  39. package/node/corner/compare-curvatures-at-interface.d.ts +1 -1
  40. package/node/corner/compare-curvatures-at-interface.js +1 -1
  41. package/node/corner/corner.d.ts +7 -6
  42. package/node/corner/get-corner.d.ts +1 -6
  43. package/node/corner/get-corner.js +2 -9
  44. package/node/corner/get-corner.js.map +1 -1
  45. package/node/corner/get-interface-ccw.d.ts +2 -2
  46. package/node/corner/get-interface-ccw.js +4 -5
  47. package/node/corner/get-interface-ccw.js.map +1 -1
  48. package/node/cp-node/cp-node-fs.d.ts +0 -15
  49. package/node/cp-node/cp-node-fs.js +0 -4
  50. package/node/cp-node/cp-node-fs.js.map +1 -1
  51. package/node/cp-node/cp-node.d.ts +10 -10
  52. package/node/cp-node/fs/clone.js.map +1 -1
  53. package/node/cp-node/fs/cp-node-comparator.js +2 -2
  54. package/node/cp-node/fs/cp-node-comparator.js.map +1 -1
  55. package/node/cp-node/fs/enhance-cp-node.d.ts +1 -1
  56. package/node/cp-node/fs/enhance-cp-node.js +5 -5
  57. package/node/cp-node/fs/enhance-cp-node.js.map +1 -1
  58. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js +2 -2
  59. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js.map +1 -1
  60. package/node/cp-node/fs/get-cp-node-ordering.js +4 -4
  61. package/node/cp-node/fs/get-cp-node-ordering.js.map +1 -1
  62. package/node/cp-node/fs/get-edge-direction.js +3 -3
  63. package/node/cp-node/fs/get-edge-direction.js.map +1 -1
  64. package/node/cp-node/fs/get-hole-closers.d.ts +1 -1
  65. package/node/cp-node/fs/get-implied-boundary-bezier-between.js +2 -2
  66. package/node/cp-node/fs/get-implied-boundary-bezier-between.js.map +1 -1
  67. package/node/cp-node/fs/get-mat-curve-between.d.ts +1 -1
  68. package/node/cp-node/fs/get-mat-curve-between.js +6 -5
  69. package/node/cp-node/fs/get-mat-curve-between.js.map +1 -1
  70. package/node/cp-node/fs/get-salience.d.ts +1 -1
  71. package/node/cp-node/fs/get-salience.js +3 -3
  72. package/node/cp-node/fs/get-salience.js.map +1 -1
  73. package/node/cp-node/fs/insert-cp-node.d.ts +3 -3
  74. package/node/cp-node/fs/insert-cp-node.js +3 -4
  75. package/node/cp-node/fs/insert-cp-node.js.map +1 -1
  76. package/node/cp-node/fs/is-one-prong.d.ts +1 -1
  77. package/node/cp-node/fs/is-one-prong.js +2 -9
  78. package/node/cp-node/fs/is-one-prong.js.map +1 -1
  79. package/node/cp-node/fs/is-order-correct.d.ts +2 -2
  80. package/node/cp-node/fs/is-order-correct.js +5 -8
  81. package/node/cp-node/fs/is-order-correct.js.map +1 -1
  82. package/node/cp-node/fs/is-sharp.js +1 -1
  83. package/node/cp-node/fs/is-sharp.js.map +1 -1
  84. package/node/cp-node/fs/remove-cp-node.js +1 -2
  85. package/node/cp-node/fs/remove-cp-node.js.map +1 -1
  86. package/node/debug/debug-elem-types.d.ts +1 -2
  87. package/node/debug/debug-elem-types.js +1 -2
  88. package/node/debug/debug-elem-types.js.map +1 -1
  89. package/node/debug/functions/draw-elem/draw-cp-node.js +2 -2
  90. package/node/debug/functions/draw-elem/draw-cp-node.js.map +1 -1
  91. package/node/debug/functions/draw-elem/draw-elem.js +1 -5
  92. package/node/debug/functions/draw-elem/draw-elem.js.map +1 -1
  93. package/node/debug/functions/draw-elem/draw-leaves.js +2 -2
  94. package/node/debug/functions/draw-elem/draw-leaves.js.map +1 -1
  95. package/node/debug/functions/draw-elem/draw-max-vertex.d.ts +1 -1
  96. package/node/debug/functions/draw-elem/draw-max-vertex.js +1 -1
  97. package/node/debug/functions/draw-elem/draw-max-vertex.js.map +1 -1
  98. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js +12 -3
  99. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js.map +1 -1
  100. package/node/debug/functions/draw-elem/draw-one-prong.d.ts +2 -2
  101. package/node/debug/functions/draw-elem/draw-one-prong.js +8 -7
  102. package/node/debug/functions/draw-elem/draw-one-prong.js.map +1 -1
  103. package/node/debug/functions/draw-elem/draw-three-prong.js +2 -2
  104. package/node/debug/functions/draw-elem/draw-three-prong.js.map +1 -1
  105. package/node/debug/functions/draw-elem/draw-two-prong.js +4 -3
  106. package/node/debug/functions/draw-elem/draw-two-prong.js.map +1 -1
  107. package/node/debug/functions/draw-elem/draw-vertex.js +1 -1
  108. package/node/debug/functions/draw-elem/draw-vertex.js.map +1 -1
  109. package/node/debug/functions/general.js +1 -1
  110. package/node/debug/functions/general.js.map +1 -1
  111. package/node/find-2-prong/add-1-prong.d.ts +3 -3
  112. package/node/find-2-prong/add-1-prong.js +4 -4
  113. package/node/find-2-prong/add-1-prong.js.map +1 -1
  114. package/node/find-2-prong/add-2-prong.d.ts +10 -11
  115. package/node/find-2-prong/add-2-prong.js +42 -37
  116. package/node/find-2-prong/add-2-prong.js.map +1 -1
  117. package/node/find-2-prong/calc-seperation-tolerance.js +4 -7
  118. package/node/find-2-prong/calc-seperation-tolerance.js.map +1 -1
  119. package/node/find-2-prong/cull-bezier-pieces.d.ts +9 -7
  120. package/node/find-2-prong/cull-bezier-pieces.js +30 -15
  121. package/node/find-2-prong/cull-bezier-pieces.js.map +1 -1
  122. package/node/find-2-prong/find-2-prong.d.ts +12 -13
  123. package/node/find-2-prong/find-2-prong.js +73 -116
  124. package/node/find-2-prong/find-2-prong.js.map +1 -1
  125. package/node/find-2-prong/find-and-add-2-prongs-on-all-loops.d.ts +4 -4
  126. package/node/find-2-prong/find-and-add-2-prongs-on-all-loops.js.map +1 -1
  127. package/node/find-2-prong/find-and-add-2-prongs.d.ts +5 -4
  128. package/node/find-2-prong/find-and-add-2-prongs.js +28 -24
  129. package/node/find-2-prong/find-and-add-2-prongs.js.map +1 -1
  130. package/node/find-2-prong/find-and-add-hole-closing-2-prongs.d.ts +6 -8
  131. package/node/find-2-prong/find-and-add-hole-closing-2-prongs.js +11 -12
  132. package/node/find-2-prong/find-and-add-hole-closing-2-prongs.js.map +1 -1
  133. package/node/find-2-prong/get-initial-bezier-pieces.d.ts +5 -6
  134. package/node/find-2-prong/get-initial-bezier-pieces.js +8 -11
  135. package/node/find-2-prong/get-initial-bezier-pieces.js.map +1 -1
  136. package/node/find-2-prong/get-initial-x.d.ts +12 -0
  137. package/node/find-2-prong/get-initial-x.js +35 -0
  138. package/node/find-2-prong/get-initial-x.js.map +1 -0
  139. package/node/find-2-prong/get-medial/antipodal-point.d.ts +8 -0
  140. package/node/find-2-prong/get-medial/antipodal-point.js +2 -0
  141. package/node/find-2-prong/get-medial/antipodal-point.js.map +1 -0
  142. package/node/find-2-prong/get-medial/get-antipodal-points.d.ts +18 -0
  143. package/node/find-2-prong/get-medial/get-antipodal-points.js +41 -0
  144. package/node/find-2-prong/get-medial/get-antipodal-points.js.map +1 -0
  145. package/node/find-2-prong/get-medial/get-closest-points.d.ts +15 -0
  146. package/node/find-2-prong/get-medial/get-closest-points.js +163 -0
  147. package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -0
  148. package/node/find-2-prong/reduce-radius.d.ts +4 -4
  149. package/node/find-2-prong/reduce-radius.js +30 -50
  150. package/node/find-2-prong/reduce-radius.js.map +1 -1
  151. package/node/find-3-prong/calc-better-x.d.ts +22 -0
  152. package/node/{find-3-prong.ts → find-3-prong}/calc-better-x.js +8 -5
  153. package/node/find-3-prong/calc-better-x.js.map +1 -0
  154. package/node/find-3-prong/calc-initial-3-prong-center.d.ts +15 -0
  155. package/node/find-3-prong/calc-initial-3-prong-center.js +26 -0
  156. package/node/find-3-prong/calc-initial-3-prong-center.js.map +1 -0
  157. package/node/find-3-prong/find-3-prong-for-delta3s.d.ts +19 -0
  158. package/node/{find-3-prong.ts → find-3-prong}/find-3-prong-for-delta3s.js +32 -34
  159. package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -0
  160. package/node/find-3-prong/find-3-prong.d.ts +13 -0
  161. package/node/{find-3-prong.ts → find-3-prong}/find-3-prong.js +14 -9
  162. package/node/find-3-prong/find-3-prong.js.map +1 -0
  163. package/node/{find-3-prong.ts → find-3-prong}/find-and-add-3-prong.js +2 -2
  164. package/node/find-3-prong/find-and-add-3-prong.js.map +1 -0
  165. package/node/find-3-prong/find-and-add-3-prongs-on-loop.js.map +1 -0
  166. package/node/{find-3-prong.ts → find-3-prong}/find-and-add-3-prongs.js +1 -1
  167. package/node/find-3-prong/find-and-add-3-prongs.js.map +1 -0
  168. package/node/find-3-prong/get-closest-points.d.ts +10 -0
  169. package/node/{find-3-prong.ts → find-3-prong}/get-closest-points.js +5 -5
  170. package/node/find-3-prong/get-closest-points.js.map +1 -0
  171. package/node/find-3-prong/three-prong-info.d.ts +9 -0
  172. package/node/find-3-prong/three-prong-info.js +2 -0
  173. package/node/find-3-prong/three-prong-info.js.map +1 -0
  174. package/node/find-mat/clip-options.d.ts +2 -2
  175. package/node/find-mat/clip-options.js +7 -14
  176. package/node/find-mat/clip-options.js.map +1 -1
  177. package/node/find-mat/create-initial-cp-tree.d.ts +8 -7
  178. package/node/find-mat/create-initial-cp-tree.js +16 -19
  179. package/node/find-mat/create-initial-cp-tree.js.map +1 -1
  180. package/node/find-mat/find-mat.d.ts +1 -1
  181. package/node/find-mat/find-mat.js +6 -12
  182. package/node/find-mat/find-mat.js.map +1 -1
  183. package/node/find-mat/find-mats.js +7 -12
  184. package/node/find-mat/find-mats.js.map +1 -1
  185. package/node/find-mat/get-dull-corners-on-loop.d.ts +3 -3
  186. package/node/find-mat/get-dull-corners-on-loop.js +5 -4
  187. package/node/find-mat/get-dull-corners-on-loop.js.map +1 -1
  188. package/node/find-mat/get-for-1-prongs-on-loop.d.ts +7 -7
  189. package/node/find-mat/get-for-1-prongs-on-loop.js +9 -21
  190. package/node/find-mat/get-for-1-prongs-on-loop.js.map +1 -1
  191. package/node/find-mat/get-for-2-prongs-on-loop.d.ts +5 -4
  192. package/node/find-mat/get-for-2-prongs-on-loop.js +4 -6
  193. package/node/find-mat/get-for-2-prongs-on-loop.js.map +1 -1
  194. package/node/find-mat/get-meta.d.ts +1 -1
  195. package/node/find-mat/get-meta.js +12 -12
  196. package/node/find-mat/get-meta.js.map +1 -1
  197. package/node/find-mat/get-sharp-corners.d.ts +3 -3
  198. package/node/find-mat/get-sharp-corners.js +2 -3
  199. package/node/find-mat/get-sharp-corners.js.map +1 -1
  200. package/node/find-mat/mat-options.d.ts +15 -15
  201. package/node/find-mat/mat-options.js +7 -4
  202. package/node/find-mat/mat-options.js.map +1 -1
  203. package/node/floyd-warshall/floyd-warshall.js +1 -1
  204. package/node/floyd-warshall/floyd-warshall.js.map +1 -1
  205. package/node/floyd-warshall/get-graph.js +2 -2
  206. package/node/floyd-warshall/get-graph.js.map +1 -1
  207. package/node/floyd-warshall/get-hole-closer-pairs.js +6 -6
  208. package/node/floyd-warshall/get-hole-closer-pairs.js.map +1 -1
  209. package/node/geometry/circle.d.ts +1 -0
  210. package/node/geometry/circle.js +1 -0
  211. package/node/geometry/circle.js.map +1 -1
  212. package/node/geometry/get-closest-square-distance-to-rect.js +1 -4
  213. package/node/geometry/get-closest-square-distance-to-rect.js.map +1 -1
  214. package/node/geometry/get-closest-squared-distance-to-rotated-rect.js +2 -1
  215. package/node/geometry/get-closest-squared-distance-to-rotated-rect.js.map +1 -1
  216. package/node/index.d.ts +0 -7
  217. package/node/index.js +0 -5
  218. package/node/index.js.map +1 -1
  219. package/node/loop/get-max-coordinate.d.ts +2 -1
  220. package/node/loop/get-max-coordinate.js +6 -8
  221. package/node/loop/get-max-coordinate.js.map +1 -1
  222. package/node/mat/add-to-cp-tree.d.ts +3 -3
  223. package/node/mat/add-to-cp-tree.js +5 -5
  224. package/node/mat/add-to-cp-tree.js.map +1 -1
  225. package/node/mat/create-new-cp-trees.d.ts +10 -0
  226. package/node/mat/create-new-cp-trees.js +24 -0
  227. package/node/mat/create-new-cp-trees.js.map +1 -0
  228. package/node/mat/curve-piece.d.ts +1 -1
  229. package/node/mat/get-boundary-piece-beziers.d.ts +3 -3
  230. package/node/mat/get-boundary-piece-beziers.js +125 -20
  231. package/node/mat/get-boundary-piece-beziers.js.map +1 -1
  232. package/node/mat/get-branches.d.ts +1 -1
  233. package/node/mat/get-closeby-cp-if-exist.d.ts +5 -5
  234. package/node/mat/get-closeby-cp-if-exist.js +6 -5
  235. package/node/mat/get-closeby-cp-if-exist.js.map +1 -1
  236. package/node/mat/get-cp-node-to-left-or-same.d.ts +3 -3
  237. package/node/mat/get-cp-node-to-left-or-same.js +2 -2
  238. package/node/mat/get-cp-node-to-left-or-same.js.map +1 -1
  239. package/node/mat/get-largest-vertex.d.ts +1 -1
  240. package/node/mat/get-largest-vertex.js +1 -1
  241. package/node/mat/get-largest-vertex.js.map +1 -1
  242. package/node/mat/mat-meta.d.ts +2 -3
  243. package/node/mat/mat.d.ts +5 -5
  244. package/node/mat/simplify-mat.js +5 -4
  245. package/node/mat/simplify-mat.js.map +1 -1
  246. package/node/mat/trim-mat.d.ts +3 -2
  247. package/node/mat/trim-mat.js +5 -3
  248. package/node/mat/trim-mat.js.map +1 -1
  249. package/node/point-on-shape/calc-pos-order.d.ts +8 -5
  250. package/node/point-on-shape/calc-pos-order.js +7 -7
  251. package/node/point-on-shape/calc-pos-order.js.map +1 -1
  252. package/node/point-on-shape/compare-poss.d.ts +4 -0
  253. package/node/point-on-shape/compare-poss.js +12 -0
  254. package/node/point-on-shape/compare-poss.js.map +1 -1
  255. package/node/point-on-shape/get-osculating-circle.d.ts +5 -6
  256. package/node/point-on-shape/get-osculating-circle.js +17 -20
  257. package/node/point-on-shape/get-osculating-circle.js.map +1 -1
  258. package/node/point-on-shape/get-pos-corner.d.ts +18 -4
  259. package/node/point-on-shape/get-pos-corner.js +6 -6
  260. package/node/point-on-shape/get-pos-corner.js.map +1 -1
  261. package/node/point-on-shape/is-pos-corner.d.ts +3 -2
  262. package/node/point-on-shape/is-pos-corner.js.map +1 -1
  263. package/node/point-on-shape/is-pos-sharp-corner.d.ts +1 -12
  264. package/node/point-on-shape/is-pos-sharp-corner.js +4 -5
  265. package/node/point-on-shape/is-pos-sharp-corner.js.map +1 -1
  266. package/node/point-on-shape/point-on-shape.d.ts +39 -6
  267. package/node/point-on-shape/pos-to-human-string.d.ts +1 -1
  268. package/node/point-on-shape/pos-to-human-string.js.map +1 -1
  269. package/node/point-on-shape/to-p.d.ts +9 -0
  270. package/node/point-on-shape/to-p.js +13 -0
  271. package/node/point-on-shape/to-p.js.map +1 -0
  272. package/node/sat/add-debug-info.d.ts +2 -1
  273. package/node/sat/add-debug-info.js +2 -1
  274. package/node/sat/add-debug-info.js.map +1 -1
  275. package/node/sat/cull-non-cycles.d.ts +2 -1
  276. package/node/sat/cull-non-cycles.js +5 -3
  277. package/node/sat/cull-non-cycles.js.map +1 -1
  278. package/node/sat/cull.js +3 -4
  279. package/node/sat/cull.js.map +1 -1
  280. package/node/sat/get-leaves.d.ts +1 -1
  281. package/node/sat/get-leaves.js +1 -2
  282. package/node/sat/get-leaves.js.map +1 -1
  283. package/node/sat/get-sat-culls.d.ts +2 -2
  284. package/node/sat/get-sat-culls.js +3 -3
  285. package/node/sat/get-sat-culls.js.map +1 -1
  286. package/node/sat/to-scale-axis.d.ts +1 -1
  287. package/node/sat/to-scale-axis.js +2 -2
  288. package/node/sat/to-scale-axis.js.map +1 -1
  289. package/node/svg/get-loop-bounds.d.ts +7 -7
  290. package/node/svg/get-loop-bounds.js +33 -70
  291. package/node/svg/get-loop-bounds.js.map +1 -1
  292. package/node/svg/get-min-y-pos.d.ts +2 -3
  293. package/node/svg/get-min-y-pos.js +2 -2
  294. package/node/svg/get-min-y-pos.js.map +1 -1
  295. package/node/svg/get-shape-bounds.d.ts +6 -6
  296. package/node/svg/get-shape-bounds.js +6 -6
  297. package/node/svg/get-shape-bounds.js.map +1 -1
  298. package/node/utils/mutable.d.ts +4 -0
  299. package/node/utils/mutable.js +2 -0
  300. package/node/utils/mutable.js.map +1 -0
  301. package/node/utils/sum.js.map +1 -1
  302. package/node/utils/time-function-call.d.ts +14 -0
  303. package/node/utils/time-function-call.js +32 -0
  304. package/node/utils/time-function-call.js.map +1 -0
  305. package/node/vertex/remove-vertex.d.ts +1 -0
  306. package/node/vertex/remove-vertex.js +1 -1
  307. package/node/vertex/remove-vertex.js.map +1 -1
  308. package/package.json +3 -5
  309. package/src/add-n-prong.ts/join-spokes.ts +8 -6
  310. package/src/closest-boundary-point/{cull-bezier-pieces.ts → cull-bezier-pieces-1.ts} +7 -7
  311. package/src/closest-boundary-point/cull-by-loose-bounding-box.ts +15 -14
  312. package/src/closest-boundary-point/cull-by-tight-boundary-box.ts +2 -2
  313. package/src/closest-boundary-point/foot-and-endpoint-info.ts +8 -10
  314. package/src/closest-boundary-point/get-best-distance-squared.ts +18 -15
  315. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +27 -31
  316. package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +13 -88
  317. package/src/closest-boundary-point/root-interval-to-distance-squared-interval.ts +5 -5
  318. package/src/corner/compare-curvatures-at-interface.ts +1 -1
  319. package/src/corner/corner.ts +7 -6
  320. package/src/corner/get-corner.ts +4 -11
  321. package/src/corner/get-interface-ccw.ts +5 -5
  322. package/src/cp-node/cp-node-fs.ts +0 -5
  323. package/src/cp-node/cp-node.ts +12 -10
  324. package/src/cp-node/fs/add-distance-from.ts +1 -2
  325. package/src/cp-node/fs/clone.ts +2 -1
  326. package/src/cp-node/fs/cp-node-comparator.ts +2 -2
  327. package/src/cp-node/fs/enhance-cp-node.ts +5 -5
  328. package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +2 -2
  329. package/src/cp-node/fs/get-cp-node-ordering.ts +4 -4
  330. package/src/cp-node/fs/get-edge-direction.ts +3 -3
  331. package/src/cp-node/fs/get-hole-closers.ts +1 -1
  332. package/src/cp-node/fs/get-implied-boundary-bezier-between.ts +2 -2
  333. package/src/cp-node/fs/get-mat-curve-between.ts +8 -6
  334. package/src/cp-node/fs/get-salience.ts +4 -4
  335. package/src/cp-node/fs/insert-cp-node.ts +10 -10
  336. package/src/cp-node/fs/is-one-prong.ts +3 -14
  337. package/src/cp-node/fs/is-order-correct.ts +6 -8
  338. package/src/cp-node/fs/is-sharp.ts +1 -1
  339. package/src/cp-node/fs/remove-cp-node.ts +4 -6
  340. package/src/cp-node/stringification/cp-node-stringifyable.ts +7 -16
  341. package/src/cp-node/stringification/from-stringifyable.ts +6 -6
  342. package/src/cp-node/stringification/to-stringifyable.ts +5 -9
  343. package/src/debug/debug-elem-types.ts +2 -3
  344. package/src/{mat → debug}/elem-type-two-prong.ts +1 -1
  345. package/src/debug/functions/check-ordering.ts +13 -16
  346. package/src/debug/functions/cmp-cp-on-delta.ts +3 -3
  347. package/src/debug/functions/draw-elem/draw-cp-node.ts +2 -2
  348. package/src/debug/functions/draw-elem/draw-elem.ts +1 -5
  349. package/src/debug/functions/draw-elem/draw-leaves.ts +2 -2
  350. package/src/debug/functions/draw-elem/draw-max-vertex.ts +3 -3
  351. package/src/debug/functions/draw-elem/draw-one-prong-at-dull-corner.ts +17 -3
  352. package/src/debug/functions/draw-elem/draw-one-prong.ts +10 -8
  353. package/src/debug/functions/draw-elem/draw-three-prong.ts +2 -2
  354. package/src/debug/functions/draw-elem/draw-two-prong.ts +4 -3
  355. package/src/debug/functions/draw-elem/draw-vertex.ts +1 -1
  356. package/src/debug/functions/draw-elem/one-prong-at-dull-corner.ts +2 -2
  357. package/src/debug/functions/general.ts +1 -1
  358. package/src/debug/functions/three-prong.ts +220 -220
  359. package/src/find-2-prong/add-1-prong.ts +8 -8
  360. package/src/find-2-prong/add-2-prong.ts +64 -58
  361. package/src/find-2-prong/calc-seperation-tolerance.ts +4 -8
  362. package/src/find-2-prong/cull-bezier-pieces.ts +41 -21
  363. package/src/find-2-prong/find-2-prong.ts +102 -151
  364. package/src/find-2-prong/find-and-add-2-prong.ts +23 -23
  365. package/src/find-2-prong/find-and-add-2-prongs-on-all-loops.ts +4 -6
  366. package/src/find-2-prong/find-and-add-2-prongs.ts +44 -29
  367. package/src/find-2-prong/find-and-add-hole-closing-2-prongs.ts +15 -15
  368. package/src/find-2-prong/get-initial-bezier-pieces.ts +21 -24
  369. package/src/find-2-prong/get-initial-x.ts +52 -0
  370. package/src/find-2-prong/get-medial/antipodal-point.ts +12 -0
  371. package/src/find-2-prong/get-medial/get-antipodal-points.ts +63 -0
  372. package/src/find-2-prong/get-medial/get-closest-points.ts +213 -0
  373. package/src/find-2-prong/reduce-radius.ts +38 -61
  374. package/src/find-2-prong/x-for-debugging.ts +9 -9
  375. package/src/{find-3-prong.ts → find-3-prong}/calc-better-x.ts +18 -11
  376. package/src/{find-3-prong.ts → find-3-prong}/calc-initial-3-prong-center.ts +12 -14
  377. package/src/{find-3-prong.ts → find-3-prong}/find-3-prong-for-delta3s.ts +46 -51
  378. package/src/find-3-prong/find-3-prong.ts +52 -0
  379. package/src/{find-3-prong.ts → find-3-prong}/find-and-add-3-prong.ts +2 -2
  380. package/src/{find-3-prong.ts → find-3-prong}/find-and-add-3-prongs.ts +1 -1
  381. package/src/{find-3-prong.ts → find-3-prong}/get-closest-points.ts +8 -5
  382. package/src/find-3-prong/three-prong-info.ts +13 -0
  383. package/src/find-mat/clip-options.ts +11 -16
  384. package/src/find-mat/create-initial-cp-tree.ts +28 -33
  385. package/src/find-mat/find-mat.ts +10 -17
  386. package/src/find-mat/find-mats.ts +9 -13
  387. package/src/find-mat/fix-ordering.ts +58 -58
  388. package/src/find-mat/get-dull-corners-on-loop.ts +12 -10
  389. package/src/find-mat/get-for-1-prongs-on-loop.ts +11 -33
  390. package/src/find-mat/get-for-2-prongs-on-loop.ts +9 -12
  391. package/src/find-mat/get-meta.ts +16 -14
  392. package/src/find-mat/get-sharp-corners.ts +7 -8
  393. package/src/find-mat/mat-options.ts +22 -19
  394. package/src/floyd-warshall/floyd-warshall.ts +1 -1
  395. package/src/floyd-warshall/get-graph.ts +2 -2
  396. package/src/floyd-warshall/get-hole-closer-pairs.ts +6 -6
  397. package/src/geometry/circle.ts +1 -0
  398. package/src/geometry/get-closest-square-distance-to-rect.ts +3 -8
  399. package/src/geometry/get-closest-squared-distance-to-rotated-rect.ts +3 -2
  400. package/src/index.ts +0 -7
  401. package/src/loop/get-max-coordinate.ts +8 -9
  402. package/src/mat/add-to-cp-tree.ts +10 -11
  403. package/src/mat/clone-mat.ts +8 -4
  404. package/src/mat/clone-meta.ts +22 -10
  405. package/src/mat/create-new-cp-trees.ts +35 -0
  406. package/src/mat/curve-piece.ts +1 -1
  407. package/src/mat/get-boundary-piece-beziers.ts +153 -37
  408. package/src/mat/get-branches.ts +1 -1
  409. package/src/mat/get-closeby-cp-if-exist.ts +11 -12
  410. package/src/mat/get-cp-node-to-left-or-same.ts +5 -5
  411. package/src/mat/get-largest-3-prong.ts +2 -2
  412. package/src/mat/get-largest-vertex.ts +2 -2
  413. package/src/mat/mat-meta.ts +3 -2
  414. package/src/mat/mat.ts +5 -5
  415. package/src/mat/simplify-mat.ts +5 -4
  416. package/src/mat/trim-mat.ts +6 -4
  417. package/src/point-on-shape/calc-pos-order.ts +10 -11
  418. package/src/point-on-shape/compare-poss.ts +11 -1
  419. package/src/point-on-shape/get-osculating-circle.ts +25 -28
  420. package/src/point-on-shape/get-pos-corner.ts +14 -12
  421. package/src/point-on-shape/is-pos-corner.ts +1 -4
  422. package/src/point-on-shape/is-pos-dull-corner.ts +9 -9
  423. package/src/point-on-shape/is-pos-quite-dull-corner.ts +7 -6
  424. package/src/point-on-shape/is-pos-quite-sharp-corner.ts +7 -6
  425. package/src/point-on-shape/is-pos-sharp-corner.ts +6 -5
  426. package/src/point-on-shape/point-on-shape.ts +44 -6
  427. package/src/point-on-shape/pos-to-human-string.ts +4 -2
  428. package/src/point-on-shape/to-p.ts +19 -0
  429. package/src/sat/add-debug-info.ts +3 -3
  430. package/src/sat/cull-non-cycles.ts +8 -6
  431. package/src/sat/cull.ts +7 -8
  432. package/src/sat/get-leaves.ts +2 -4
  433. package/src/sat/get-sat-culls.ts +6 -5
  434. package/src/sat/to-scale-axis.ts +4 -5
  435. package/src/svg/get-loop-bounds.ts +61 -86
  436. package/src/svg/get-min-y-pos.ts +3 -4
  437. package/src/svg/get-shape-bounds.ts +12 -12
  438. package/src/sweep-line/are-boxes-intersecting.ts +3 -2
  439. package/src/utils/mutable.ts +7 -0
  440. package/src/utils/rad-to-deg.ts +1 -1
  441. package/src/utils/smart-log.ts +20 -0
  442. package/src/utils/sum.ts +3 -1
  443. package/src/utils/time-function-call.ts +53 -0
  444. package/src/vertex/remove-vertex.ts +1 -3
  445. package/.eslintrc.cjs +0 -69
  446. package/__tests__/cp-node/fs/get-avg-speed.spec.ts +0 -7
  447. package/__tests__/cp-node/fs/get-smoothed-speed.spec.ts +0 -7
  448. package/__tests__/cp-node/fs/get-smoothed.spec.ts +0 -7
  449. package/__tests__/cp-node/fs/get-speed.spec.ts +0 -7
  450. package/__tests__/cp-node/fs/is-order-correct.spec.ts +0 -7
  451. package/node/bezier/fit-quads-to-cubic.d.ts +0 -19
  452. package/node/bezier/fit-quads-to-cubic.js +0 -83
  453. package/node/bezier/fit-quads-to-cubic.js.map +0 -1
  454. package/node/bezier/total-curvature.d.ts +0 -14
  455. package/node/bezier/total-curvature.js +0 -5
  456. package/node/bezier/total-curvature.js.map +0 -1
  457. package/node/bezier/total-length.d.ts +0 -14
  458. package/node/bezier/total-length.js +0 -5
  459. package/node/bezier/total-length.js.map +0 -1
  460. package/node/closest-boundary-point/cull-bezier-pieces.d.ts +0 -10
  461. package/node/closest-boundary-point/cull-bezier-pieces.js.map +0 -1
  462. package/node/closest-boundary-point/dd-deflate-with-running-error.d.ts +0 -25
  463. package/node/closest-boundary-point/dd-deflate-with-running-error.js +0 -68
  464. package/node/closest-boundary-point/dd-deflate-with-running-error.js.map +0 -1
  465. package/node/contact-point/contact-point.d.ts +0 -26
  466. package/node/contact-point/contact-point.js +0 -22
  467. package/node/contact-point/contact-point.js.map +0 -1
  468. package/node/cp-node/fs/get-smoothed-speed.d.ts +0 -14
  469. package/node/cp-node/fs/get-smoothed-speed.js +0 -75
  470. package/node/cp-node/fs/get-smoothed-speed.js.map +0 -1
  471. package/node/cp-node/fs/get-speed.d.ts +0 -15
  472. package/node/cp-node/fs/get-speed.js +0 -39
  473. package/node/cp-node/fs/get-speed.js.map +0 -1
  474. package/node/debug/cp-node-for-debugging.d.ts +0 -11
  475. package/node/debug/cp-node-for-debugging.js +0 -2
  476. package/node/debug/cp-node-for-debugging.js.map +0 -1
  477. package/node/debug/functions/draw-elem/draw-speed.d.ts +0 -4
  478. package/node/debug/functions/draw-elem/draw-speed.js +0 -21
  479. package/node/debug/functions/draw-elem/draw-speed.js.map +0 -1
  480. package/node/error-analysis/gamma.d.ts +0 -26
  481. package/node/error-analysis/gamma.js +0 -35
  482. package/node/error-analysis/gamma.js.map +0 -1
  483. package/node/find-2-prong/find-and-add-2-prong.d.ts +0 -11
  484. package/node/find-2-prong/find-and-add-2-prong.js +0 -19
  485. package/node/find-2-prong/find-and-add-2-prong.js.map +0 -1
  486. package/node/find-2-prong/find-equidistant-point-on-line-dd.d.ts +0 -10
  487. package/node/find-2-prong/find-equidistant-point-on-line-dd.js +0 -56
  488. package/node/find-2-prong/find-equidistant-point-on-line-dd.js.map +0 -1
  489. package/node/find-3-prong.ts/calc-better-x.d.ts +0 -19
  490. package/node/find-3-prong.ts/calc-better-x.js.map +0 -1
  491. package/node/find-3-prong.ts/calc-initial-3-prong-center.d.ts +0 -13
  492. package/node/find-3-prong.ts/calc-initial-3-prong-center.js +0 -27
  493. package/node/find-3-prong.ts/calc-initial-3-prong-center.js.map +0 -1
  494. package/node/find-3-prong.ts/find-3-prong-for-delta3s.d.ts +0 -22
  495. package/node/find-3-prong.ts/find-3-prong-for-delta3s.js.map +0 -1
  496. package/node/find-3-prong.ts/find-3-prong.d.ts +0 -16
  497. package/node/find-3-prong.ts/find-3-prong.js.map +0 -1
  498. package/node/find-3-prong.ts/find-and-add-3-prong.js.map +0 -1
  499. package/node/find-3-prong.ts/find-and-add-3-prongs-on-loop.js.map +0 -1
  500. package/node/find-3-prong.ts/find-and-add-3-prongs.js.map +0 -1
  501. package/node/find-3-prong.ts/get-closest-points.d.ts +0 -9
  502. package/node/find-3-prong.ts/get-closest-points.js.map +0 -1
  503. package/node/mat/connect-hole-closers.d.ts +0 -3
  504. package/node/mat/connect-hole-closers.js +0 -5
  505. package/node/mat/connect-hole-closers.js.map +0 -1
  506. package/node/mat/create-new-cp-tree.d.ts +0 -9
  507. package/node/mat/create-new-cp-tree.js +0 -23
  508. package/node/mat/create-new-cp-tree.js.map +0 -1
  509. package/node/memoize-primitive.d.ts +0 -11
  510. package/node/memoize-primitive.js +0 -25
  511. package/node/memoize-primitive.js.map +0 -1
  512. package/node/point-on-shape/create-pos.d.ts +0 -4
  513. package/node/point-on-shape/create-pos.js +0 -11
  514. package/node/point-on-shape/create-pos.js.map +0 -1
  515. package/node/point-on-shape/is-pos-quite-sharp-corner.d.ts +0 -17
  516. package/node/point-on-shape/is-pos-quite-sharp-corner.js +0 -14
  517. package/node/point-on-shape/is-pos-quite-sharp-corner.js.map +0 -1
  518. package/src/bezier/fit-quads-to-cubic.ts +0 -103
  519. package/src/bezier/total-curvature.ts +0 -8
  520. package/src/bezier/total-length.ts +0 -8
  521. package/src/closest-boundary-point/closest-points-on-curve-precise.ts +0 -75
  522. package/src/closest-boundary-point/closest-points-on-curve.ts +0 -72
  523. package/src/closest-boundary-point/dd-deflate-with-running-error.ts +0 -88
  524. package/src/contact-point/contact-point.ts +0 -42
  525. package/src/cp-node/fs/get-avg-speed.ts +0 -31
  526. package/src/cp-node/fs/get-smoothed-speed.ts +0 -97
  527. package/src/cp-node/fs/get-smoothed.ts +0 -62
  528. package/src/cp-node/fs/get-speed.ts +0 -56
  529. package/src/curve/curve.ts +0 -35
  530. package/src/dbscan/dbscan.ts +0 -91
  531. package/src/debug/cp-node-for-debugging.ts +0 -15
  532. package/src/debug/functions/draw-elem/draw-speed.ts +0 -35
  533. package/src/debug/three-prong-for-debugging.ts +0 -58
  534. package/src/debug/two-prong-for-debugging.ts +0 -30
  535. package/src/dijkstra/dijkstra.ts +0 -418
  536. package/src/find-2-prong/find-and-add-2-prongs-on-all-paths.ts +0 -38
  537. package/src/find-2-prong/find-equidistant-point-on-line-dd.ts +0 -77
  538. package/src/find-2-prong/find-equidistant-point-on-line.ts +0 -40
  539. package/src/find-2-prong/pyth-trips.ts +0 -146
  540. package/src/find-3-prong.ts/add-3-prong.ts +0 -113
  541. package/src/find-3-prong.ts/array-set.ts +0 -47
  542. package/src/find-3-prong.ts/find-3-prong.ts +0 -48
  543. package/src/find-3-prong.ts/find-and-add-all-3-prongs.ts +0 -109
  544. package/src/find-mat/add-2-prongs-by-error.ts +0 -122
  545. package/src/find-mat/add-debug-info.ts +0 -93
  546. package/src/find-mat/cp-node-for-insertion.ts +0 -13
  547. package/src/find-mat/get-dull-corners.ts +0 -34
  548. package/src/find-mat/get-half-angles.ts +0 -95
  549. package/src/find-mat/get-size-params.ts +0 -34
  550. package/src/find-mat/get-total-by.ts +0 -27
  551. package/src/get-curve/get-curve-between.ts +0 -80
  552. package/src/get-curve/get-edge-direction.ts +0 -70
  553. package/src/mat/add-to-cp-graph.ts +0 -60
  554. package/src/mat/cmp-cp-on-delta.ts +0 -56
  555. package/src/mat/connect-hole-closers.ts +0 -9
  556. package/src/mat/create-new-cp-tree.ts +0 -32
  557. package/src/mat/get-edges-as-array.ts +0 -18
  558. package/src/mat/get-largest-three-prong.ts +0 -14
  559. package/src/mat/get-neighboring-cps.ts +0 -49
  560. package/src/mat/is-another-cp-closeby.ts +0 -69
  561. package/src/mat/simplify-mat-map-only.ts +0 -110
  562. package/src/memoize-primitive.ts +0 -31
  563. package/src/point-on-shape/create-pos.ts +0 -20
  564. package/src/sat/cull-by-salience.ts +0 -115
  565. package/src/svg/get-extreme.ts +0 -23
  566. package/src/utils/bezier-piece-to-bezier.ts +0 -13
  567. package/src/utils/sleep.ts +0 -7
  568. /package/node/{find-3-prong.ts → find-3-prong}/find-and-add-3-prong.d.ts +0 -0
  569. /package/node/{find-3-prong.ts → find-3-prong}/find-and-add-3-prongs-on-loop.d.ts +0 -0
  570. /package/node/{find-3-prong.ts → find-3-prong}/find-and-add-3-prongs-on-loop.js +0 -0
  571. /package/node/{find-3-prong.ts → find-3-prong}/find-and-add-3-prongs.d.ts +0 -0
  572. /package/src/{find-3-prong.ts → find-3-prong}/find-and-add-3-prongs-on-loop.ts +0 -0
@@ -1,86 +1,63 @@
1
- import { evalDeCasteljau } from "flo-bezier3";
2
- import { dot, lineLineIntersection, squaredDistanceBetween } from "flo-vector2d";
3
- import { CurvePiece } from '../mat/curve-piece.js';
1
+ import type { CurvePiece } from '../mat/curve-piece.js';
2
+ import { getMedialPointCoeffsBez0 } from "flo-bezier3";
3
+ import { lengthSquared, squaredDistanceBetween } from "flo-vector2d";
4
+
5
+ const { abs } = Math;
6
+
7
+
8
+ const TOLERANCE = 1 + 2**-20;
4
9
 
5
10
 
6
11
  /**
7
- * @internal
8
- *
9
12
  * Reduces the circle radius initially as an optimization step.
13
+ *
14
+ * @internal
10
15
  */
11
16
  function reduceRadius(
12
- extreme: number,
17
+ maxCoordPowerOf2: number,
13
18
  curvePieces: CurvePiece[],
14
- p: number[],
15
- x: number[]) {
19
+ y: number[],
20
+ nnorm: number[]): number {
16
21
 
17
- const TOLERANCE = 1 + 2**-10;
22
+ let minRadius = Infinity;
23
+ let x = [y[0] + nnorm[0], y[1] + nnorm[1]];
18
24
 
19
- let minRadius = Number.POSITIVE_INFINITY;
20
25
  for (let i=0; i<curvePieces.length; i++) {
21
26
  const curvePiece = curvePieces[i];
22
27
 
23
- const ps = curvePiece.curve.ps;
24
-
25
- // let min = Number.POSITIVE_INFINITY;
26
- const num = 2;
27
- for (let j=0; j<(num + 1); j++) {
28
- const p_ = evalDeCasteljau(ps, curvePiece.ts[j/num]);
29
- const cc = getCircleCenterFrom2PointsAndNormal(extreme, p, x, p_);
30
- if (cc) {
31
- let r = squaredDistanceBetween(p, cc);
32
- if (r < minRadius) {
33
- minRadius = r;
34
- }
35
- }
36
- }
37
- }
38
-
39
- // The extra bit is to account for floating point precision.
40
- return TOLERANCE*minRadius;
41
- }
28
+ const { ps } = curvePiece.curve;
42
29
 
30
+ const pS = ps[0];
31
+ const pE = ps[ps.length - 1];
43
32
 
44
- /**
45
- * @internal
46
- * @param p A point on the circle with normal pointing to x towards the center
47
- * of the circle.
48
- * @param x
49
- * @param p1 Another point on the circle.
50
- */
51
- function getCircleCenterFrom2PointsAndNormal(
52
- extreme: number,
53
- p: number[],
54
- x: number[],
55
- p1: number[]) {
33
+ for (const P of [pS,pE]) {
34
+ if (squaredDistanceBetween(x,P) > minRadius) {
35
+ continue; // short-circuit
36
+ }
56
37
 
57
- const TOLERANCE = (2**-14*extreme)**2;
38
+ const { a0, b0 } = getMedialPointCoeffsBez0(y, nnorm, P);
58
39
 
59
- // Ignore if p and p1 are too close together
60
- if (squaredDistanceBetween(p,p1) < TOLERANCE) {
61
- return undefined;
62
- }
40
+ if (abs(a0) <= 2**-40 || abs(b0) <= 2**-40) {
41
+ continue;
42
+ }
63
43
 
64
- /** The perpindicular bisector between the two given points on the circle */
65
- const pb = [
66
- (p[0] + p1[0]) / 2,
67
- (p[1] + p1[1]) / 2,
68
- ];
69
- const tan = [p1[0] - p[0], p1[1] - p[1]];
70
- const norm = [-tan[1], tan[0]]; // Rotate by 90 degrees
71
- const pb2 = [pb[0] + norm[0], pb[1] + norm[1]];
44
+ const w = -b0 / a0;
72
45
 
73
- const res = lineLineIntersection([p,x], [pb, pb2]);
46
+ // too close to point of origin *or* negative;
47
+ if (w < 2**-40) { continue; }
74
48
 
75
- if (!res) { return undefined; }
49
+ const N = [w*nnorm[0], w*nnorm[1]];
50
+ const r = lengthSquared(N);
76
51
 
77
- const resO = [res[0] - p[0], res[1] - p[1]];
78
- const xO = [x[0] - p[0], x[1] - p[1]];
79
- if (dot(resO, xO) < 0) {
80
- return undefined;
52
+ if (r < minRadius) {
53
+ minRadius = r;
54
+ x = [y[0] + N[0], y[1] + N[1]];
55
+ }
56
+ }
81
57
  }
82
58
 
83
- return res;
59
+ // The extra bit is to account for floating point precision.
60
+ return TOLERANCE*minRadius;
84
61
  }
85
62
 
86
63
 
@@ -1,13 +1,13 @@
1
- import { PointOnShape } from '../point-on-shape/point-on-shape.js';
1
+ // import { PointOnShape } from '../point-on-shape/point-on-shape.js';
2
2
 
3
3
 
4
- /** @internal */
5
- type TXForDebugging = {
6
- x: number[];
7
- y: PointOnShape;
8
- z: PointOnShape;
9
- t: number;
10
- }
4
+ // /** @internal */
5
+ // type TXForDebugging = {
6
+ // x: number[];
7
+ // y: PointOnShape;
8
+ // z: PointOnShape;
9
+ // t: number;
10
+ // }
11
11
 
12
12
 
13
- export { TXForDebugging }
13
+ // export { TXForDebugging }
@@ -1,39 +1,46 @@
1
+ import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
2
+ import type { CurvePiece } from '../mat/curve-piece.js';
1
3
  import { fromTo, circumCenter, len, scale, translate } from 'flo-vector2d';
2
- import { PointOnShape } from '../point-on-shape/point-on-shape.js';
3
- import { CurvePiece } from '../mat/curve-piece.js';
4
4
  import { getClosestPoints } from './get-closest-points.js';
5
5
 
6
6
 
7
7
  /**
8
- * @internal
9
- * Find new x and ps that are a better estimate of the 3-prong circle.
8
+ * Find new `x` and `ps` that are better estimates of the 3-prong circle.
9
+ *
10
10
  * The potential function, V, is defined as the distance to the actual 3 prong
11
11
  * circle center.
12
+ *
13
+ * @param maxCoordPowerOf2
12
14
  * @param curvePiece3s The three boundary pieces, each of which should contain
13
15
  * a point of the 3-prong to be found.
14
16
  * @param x The currently best guess at the center of the 3-prong circle.
15
17
  * @param vectorToZeroV
16
- * @param extreme
18
+ *
19
+ * @internal
17
20
  */
18
21
  function calcBetterX(
22
+ maxCoordPowerOf2: number,
19
23
  curvePiece3s: CurvePiece[][],
20
24
  x: number[],
21
- vectorToZeroV: number[]) {
25
+ vectorToZeroV: number[]): {
26
+ newX: number[];
27
+ newV: number;
28
+ newPoss: PrePointOnShape[];
29
+ } {
22
30
 
23
31
  const V = len(vectorToZeroV);
24
32
 
25
33
  let nu = 1;
26
34
  let better;
27
35
  let newX;
28
- let newPoss: PointOnShape[];
36
+ let newPoss: PrePointOnShape[];
29
37
  let newV;
30
- let i = 0; // Safeguard
38
+ let i = 0; // Safeguard
31
39
  do {
32
40
  const shift = scale(vectorToZeroV, nu);
33
41
  newX = translate(shift, x);
34
-
35
-
36
- newPoss = getClosestPoints(newX, curvePiece3s);
42
+
43
+ newPoss = getClosestPoints(maxCoordPowerOf2, newX, curvePiece3s);
37
44
 
38
45
  // Point of zero V
39
46
  const newCircleCenter = circumCenter(newPoss.map(pos => pos!.p));
@@ -1,40 +1,38 @@
1
- /** @internal */
1
+ import type { CpNode } from '../cp-node/cp-node.js';
2
+ import type { CurvePiece } from '../mat/curve-piece.js';
2
3
  import { circumCenter } from 'flo-vector2d';
3
- import { CpNode } from '../cp-node/cp-node.js';
4
- import { CurvePiece } from '../mat/curve-piece.js';
5
4
  import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
6
- import { createPos } from '../point-on-shape/create-pos.js';
7
5
 
8
- const { max, ceil, log2 } = Math;
9
6
 
10
7
  /**
11
- * @internal
12
8
  * Finds an initial 3-prong circle center point from which to iterate. The point
13
9
  * must be within the shape.
14
- * @param δ3s - The three boundary pieces of which we need to find the three
10
+ *
11
+ * @param maxCoordPowerOf2
12
+ * @param δ3s the three boundary pieces of which we need to find the three
15
13
  * 3-prong points.
16
14
  * @param curvePiece3s
17
- * @param extreme
15
+ *
16
+ * @internal
18
17
  */
19
18
  function calcInitial3ProngCenter(
20
- maxCoordinate: number,
19
+ maxCoordPowerOf2: number,
21
20
  δ3s: CpNode[][],
22
21
  curvePiece3s: CurvePiece[][]) {
23
22
 
24
- const circle = δ3s[0][0].cp.circle;
23
+ const circle = δ3s[0][0].pointOnShape.circle;
25
24
  const twoProngCircleCenter = circle.center;
26
25
 
27
- const pow = max(0,ceil(log2(maxCoordinate/circle.radius))) + 1; // determines accuracy;
28
26
  const pos = getCloseBoundaryPointsCertified(
29
- pow,
27
+ maxCoordPowerOf2,
30
28
  curvePiece3s[1],
31
29
  twoProngCircleCenter
32
30
  )[0];
33
31
 
34
32
  const meanPoints = [
35
- δ3s[0][0].cp.pointOnShape.p,
33
+ δ3s[0][0].pointOnShape.p,
36
34
  pos.p,
37
- δ3s[2][1].cp.pointOnShape.p,
35
+ δ3s[2][1].pointOnShape.p,
38
36
  ];
39
37
 
40
38
  return circumCenter(meanPoints);
@@ -1,44 +1,40 @@
1
- import {
2
- fromTo, circumCenter, len, distanceBetween, toUnitVector, rotate90Degrees,
3
- cross
4
- } from 'flo-vector2d';
1
+ import type { CpNode } from '../cp-node/cp-node.js';
2
+ import type { CurvePiece } from '../mat/curve-piece.js';
3
+ import type { ThreeProngInfo } from './three-prong-info.js';
4
+ import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
5
+ import { fromTo, circumCenter as getCircumCenter, len, distanceBetween, toUnitVector, rotate90Degrees, cross } from 'flo-vector2d';
5
6
  import { tangent } from 'flo-bezier3';
6
- import { CpNode } from '../cp-node/cp-node.js';
7
- import { CpNodeFs } from '../cp-node/cp-node-fs.js';
8
- import { CurvePiece } from '../mat/curve-piece.js';
9
- import { PointOnShape } from '../point-on-shape/point-on-shape.js';
10
7
  import { calcInitial3ProngCenter } from './calc-initial-3-prong-center.js';
11
8
  import { getClosestPoints } from './get-closest-points.js';
12
9
  import { calcBetterX } from './calc-better-x.js';
13
10
  import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
14
11
  import { getCorner } from '../corner/get-corner.js';
15
12
  import { isPosCorner } from '../point-on-shape/is-pos-corner.js';
16
- import { getPosCorner } from '../point-on-shape/get-pos-corner.js';
13
+ import { getPosCorner$ } from '../point-on-shape/get-pos-corner.js';
14
+ import { isSharp } from '../cp-node/fs/is-sharp.js';
17
15
 
18
- const { isSharp } = CpNodeFs;
19
-
20
-
21
- /** @internal */
22
- const calcVectorToZeroV_StraightToIt = fromTo;
16
+ const { min, abs, asin } = Math;
23
17
 
24
18
 
25
19
  /**
26
- * @internal
27
20
  * Finds a 3-prong using only the 3 given δs.
28
- * @param δs The boundary pieces
21
+ *
22
+ * @param δs the boundary pieces
29
23
  * @param idx δ identifier
24
+ * @param k δs identifier
30
25
  * @param curvePiecess
31
- * @param maxCoordinate The maximum coordinate value used to calculate floating point
32
- * tolerances.
26
+ * @param maxCoordPowerOf2
27
+ *
28
+ * @internal
33
29
  */
34
30
  function find3ProngForDelta3s(
35
31
  δs: CpNode[][],
36
32
  idx: number,
37
33
  k: number,
38
34
  curvePiecess: CurvePiece[][],
39
- maxCoordinate: number) {
35
+ maxCoordPowerOf2: number): { error: number, threeProngInfo: ThreeProngInfo } | undefined {
40
36
 
41
- const TOLERANCE = 2**-32*maxCoordinate;
37
+ const TOLERANCE = 2**(maxCoordPowerOf2 - 32);
42
38
  const MAX_ITERATIONS = 10;
43
39
 
44
40
  const δs_ = [
@@ -72,44 +68,42 @@ function find3ProngForDelta3s(
72
68
  if (isSharp(δ3s[0][0])) { return undefined; }
73
69
 
74
70
 
75
- let poss: PointOnShape[] = undefined!;
76
- let circumCenter_;
77
- let j = 0; // Safeguard for slow convergence
78
- let x = calcInitial3ProngCenter(maxCoordinate, δ3s, curvePiece3s);
71
+ let poss: PrePointOnShape[] = undefined!;
72
+ let j = 0; // Safeguard for slow convergence
73
+ let x = calcInitial3ProngCenter(maxCoordPowerOf2, δ3s, curvePiece3s);
79
74
 
80
- let tolerance = Number.POSITIVE_INFINITY;
75
+ let tolerance = Infinity;
81
76
  while (tolerance > TOLERANCE && j < MAX_ITERATIONS) {
82
77
  j++;
83
78
 
84
- poss = getClosestPoints(x, curvePiece3s);
79
+ poss = getClosestPoints(maxCoordPowerOf2, x, curvePiece3s);
85
80
  if (!Number.isFinite(x[0]) || !Number.isFinite(x[1])) {
86
81
 
87
- // TODO - the code can be cleaned up and sped up a lot if we don't
82
+ // FUTURE - the code can be cleaned up and sped up a lot if we don't
88
83
  // use this function as is but instead use δs[0] and δs[2] as is
89
84
  // and make δs[1] include all the rest of the beziers around the
90
85
  // loop. This check, for instance, would be eliminated completely.
91
86
  return undefined;
92
87
  }
93
88
 
94
- circumCenter_ = circumCenter(poss.map(x => x!.p));
95
-
96
- const vectorToZeroV = calcVectorToZeroV_StraightToIt(x, circumCenter_);
89
+ const circumCenter = getCircumCenter(poss.map(x => x.p));
90
+ const vectorToZeroV = fromTo(x, circumCenter);
97
91
 
98
92
  if (!Number.isFinite(vectorToZeroV[0]) || !Number.isFinite(vectorToZeroV[1])) {
99
93
 
100
- // TODO - the code can be cleaned up and sped up a lot if we don't
94
+ // FUTURE - the code can be cleaned up and sped up a lot if we don't
101
95
  // use this function as is but instead use δs[0] and δs[2] as is
102
96
  // and make δs[1] include all the rest of the beziers around the
103
97
  // loop. This check, for instance, would be eliminated completely.
104
98
  return undefined;
105
99
  }
106
- const upds = calcBetterX(curvePiece3s, x, vectorToZeroV);
100
+ const upds = calcBetterX(maxCoordPowerOf2, curvePiece3s, x, vectorToZeroV);
107
101
  x = upds.newX;
108
102
  poss = upds.newPoss;
109
103
 
110
104
  const V = len(vectorToZeroV); // The 'potential'
111
105
 
112
- tolerance = Math.abs(V - upds.newV);
106
+ tolerance = abs(V - upds.newV);
113
107
  }
114
108
 
115
109
  const radius = (distanceBetween(x, poss[0].p) +
@@ -121,28 +115,28 @@ function find3ProngForDelta3s(
121
115
  //-------------------------------------------------------------------------
122
116
  // Calculate the unit tangent vector at 3-prong circle points - they should
123
117
  // be very close to tangent to the boundary piece tangents at those points
124
- // (up to sign). Sharp corners are a common special case.
118
+ // (up to sign). Dull corners is a common special case.
125
119
  //-------------------------------------------------------------------------
126
120
  let totalAngleError = 0;
127
121
  for (let i=0; i<3; i++) {
128
- const pos = poss![i];
122
+ const pos = poss[i];
129
123
  //----------------------------
130
124
  // Tangent of circle at point
131
125
  //----------------------------
132
- const v = toUnitVector(fromTo(pos!.p, x));
126
+ const v = toUnitVector(fromTo(pos.p, x));
133
127
  const v1 = rotate90Degrees(v);
134
128
 
135
129
 
136
130
  //-----------------------------------
137
131
  // Check if point is on dull crorner
138
132
  //-----------------------------------
139
- if (isPosCorner(pos!) && getPosCorner(pos!).isDull) {
140
- const corner = getCorner(pos!.curve.ps, pos!.curve.next.ps);
133
+ if (isPosCorner(pos) && getPosCorner$(pos).isDull) {
134
+ const corner = getCorner(pos.curve.ps, pos.curve.next.ps);
141
135
  const tans = corner.tangents;
142
136
  const perps = tans.map( rotate90Degrees );
143
137
 
144
- const angleError1 = Math.asin( cross( perps[0], v ) );
145
- const angleError2 = Math.asin( cross( v, perps[1] ) );
138
+ const angleError1 = asin( cross( perps[0], v ) );
139
+ const angleError2 = asin( cross( v, perps[1] ) );
146
140
 
147
141
  let angleError = 0;
148
142
  if (angleError1 > 0) { angleError += angleError1; }
@@ -153,18 +147,18 @@ function find3ProngForDelta3s(
153
147
  //---------------------------
154
148
  // Tangent of curve at point
155
149
  //---------------------------
156
- const v2 = toUnitVector( tangent(pos!.curve.ps, pos!.t) );
150
+ const v2 = toUnitVector( tangent(pos.curve.ps, pos.t) );
157
151
 
158
152
  // Cross is more numerically stable than Vector.dot at angles a
159
- // multiple of Math.PI **and** is close to the actual angle value
153
+ // multiple of `Math.PI` **and** is close to the actual angle value
160
154
  // and can thus just be added to cone method of looking at
161
155
  // tolerance.
162
156
 
163
157
  // Should be close to zero and is close to the actual angle.
164
- const cross_ = Math.abs( Math.asin( cross(v1, v2) ) );
158
+ const cross_ = abs( asin( cross(v1, v2) ) );
165
159
 
166
160
  totalAngleError += cross_;
167
- }
161
+ }
168
162
  }
169
163
 
170
164
  //-------------------------------------------------------------------------
@@ -174,22 +168,23 @@ function find3ProngForDelta3s(
174
168
  //-------------------------------------------------------------------------
175
169
  const closestDs = [];
176
170
  for (let i=0; i<curvePiecess.length; i++) {
177
- const p = getCloseBoundaryPointsCertified(
178
- 5, // TODO - see find-2-prong
179
- curvePiecess[i], x
171
+ const pos = getCloseBoundaryPointsCertified(
172
+ maxCoordPowerOf2,
173
+ curvePiecess[i],
174
+ x
180
175
  )[0];
181
176
 
182
- closestDs.push( distanceBetween(p.p, x) );
177
+ closestDs.push( distanceBetween(pos.p, x) );
183
178
  }
184
- const closestD = Math.min(...closestDs);
185
- const radiusDelta = Math.abs(radius - closestD);
179
+ const closestD = min(...closestDs);
180
+ const radiusDelta = abs(radius - closestD);
186
181
 
187
182
  // Weights below still need to be optimized.
188
183
  const W1 = 1;
189
184
  const W2 = 1;
190
185
  const error = W1*radiusDelta + W2*totalAngleError;
191
186
 
192
- return { poss: poss!, circle, error, δ3s };
187
+ return { threeProngInfo: { poss, circle, δ3s }, error };
193
188
  }
194
189
 
195
190
 
@@ -0,0 +1,52 @@
1
+ import type { CpNode } from '../cp-node/cp-node.js';
2
+ import type { ThreeProngInfo } from './three-prong-info.js';
3
+ import { find3ProngForDelta3s } from './find-3-prong-for-delta3s.js';
4
+ import { getBoundaryPieceBeziers } from '../mat/get-boundary-piece-beziers.js';
5
+ import { timeFunctionCalls } from '../utils/time-function-call.js';
6
+
7
+
8
+ /**
9
+ * Find and return a 3-prong from the given boundary piece.
10
+ *
11
+ * @param δs A boundary piece
12
+ * @param maxCoordPowerOf2 The maximum coordinate power of 2 value used to
13
+ * calculate floating point tolerances.
14
+ *
15
+ * @internal
16
+ */
17
+ function find3Prong(
18
+ δs: CpNode[][],
19
+ maxCoordPowerOf2: number): ThreeProngInfo {
20
+
21
+ // FUTURE if `δs.length > (some threshold (say 4 or 5))` then add two-prongs
22
+ // to reduced the number of permutations required
23
+ // if (δs.length > 3) { console.log(δs.length); }
24
+
25
+ const curvePiecess = δs.map(getBoundaryPieceBeziers);
26
+
27
+ // The best candidate amongst the different 'permutations' of the given δs.
28
+ let threeProng: ThreeProngInfo;
29
+
30
+ let smallestError = Infinity;
31
+ for (let i=1; i<δs.length - 1; i++) {
32
+ for (let k=0; k<3; k++) {
33
+ const r = find3ProngForDelta3s(
34
+ δs, i, k, curvePiecess, maxCoordPowerOf2
35
+ );
36
+
37
+ if (r === undefined) { continue; }
38
+
39
+ const { error, threeProngInfo } = r;
40
+
41
+ if (error < smallestError) {
42
+ smallestError = error;
43
+ threeProng = threeProngInfo;
44
+ }
45
+ }
46
+ }
47
+
48
+ return threeProng!;
49
+ }
50
+
51
+
52
+ export { find3Prong }
@@ -26,13 +26,13 @@ function findAndAdd3Prong(
26
26
  δs.push([visitedCp, visitedCp.next]);
27
27
  }
28
28
 
29
- const threeProngInfo = find3Prong(δs, meta.maxCoordinate);
29
+ const threeProngInfo = find3Prong(δs, meta.maxCoordPowerOf2);
30
30
 
31
31
  const { circle, poss, δ3s } = threeProngInfo;
32
32
 
33
33
  const orders: number[] = [];
34
34
  for (let i=0; i<3; i++) {
35
- orders.push(calcPosOrder(circle, poss[i]));
35
+ orders.push(calcPosOrder(circle.center, poss[i]));
36
36
  }
37
37
 
38
38
  const closeBysFor3Prong: CpNode[] = [];
@@ -28,7 +28,7 @@ function findAndAdd3Prongs(
28
28
  meta: MatMeta,
29
29
  cpStart: CpNode) {
30
30
 
31
- if (isPosSharpCorner(cpStart.cp.pointOnShape)) {
31
+ if (isPosSharpCorner(cpStart.pointOnShape)) {
32
32
  return { closeBysFor3Prong: undefined, addedCpNodes: [] };
33
33
  }
34
34
 
@@ -1,21 +1,24 @@
1
- import { CurvePiece } from '../mat/curve-piece.js';
1
+ import type { CurvePiece } from '../mat/curve-piece.js';
2
2
  import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
3
3
 
4
4
 
5
5
  /**
6
- * @internal
6
+ * @param maxCoordPowerOf2
7
7
  * @param x
8
8
  * @param curvePiece3s
9
- * @param extreme
9
+ *
10
+ * @internal
10
11
  */
11
12
  function getClosestPoints(
13
+ maxCoordPowerOf2: number,
12
14
  x: number[],
13
15
  curvePiece3s: CurvePiece[][]) {
14
16
 
15
17
  return curvePiece3s.map(curvePieces => {
16
18
  return getCloseBoundaryPointsCertified(
17
- 5, // TODO - see find-2-prong
18
- curvePieces, x
19
+ maxCoordPowerOf2,
20
+ curvePieces,
21
+ x
19
22
  )[0];
20
23
  });
21
24
  }
@@ -0,0 +1,13 @@
1
+ import type { CpNode } from '../cp-node/cp-node.js';
2
+ import type { Circle } from '../geometry/circle.js';
3
+ import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
4
+
5
+
6
+ interface ThreeProngInfo {
7
+ readonly circle: Circle;
8
+ readonly poss: PrePointOnShape[];
9
+ readonly δ3s: CpNode[][];
10
+ }
11
+
12
+
13
+ export type { ThreeProngInfo }
@@ -1,34 +1,29 @@
1
- import { MatOptionMeta, matOptionRanges, MatOptions } from './mat-options.js';
1
+ import type { Mutable } from '../utils/mutable.js';
2
+ import { matOptionRanges, type MatOptions } from './mat-options.js';
2
3
 
3
4
 
4
5
  function clipOptions(
5
- maxCoordinate: number,
6
- maxRadius: number,
6
+ maxCoordPowerOf2: number,
7
7
  options: Required<MatOptions>): Required<MatOptions> {
8
8
 
9
- const expMaxCoord = Math.ceil(Math.log2(maxCoordinate));
10
- const expMaxRadius = Math.ceil(Math.log2(maxRadius));
11
9
  const scaleSigBits = 10; // 1024 x 1024
12
10
 
13
- const options_ = { ...options };
11
+ const options_: Mutable<Required<MatOptions>> = { ...options };
12
+
14
13
  for (const k in matOptionRanges) {
15
- // @ts-ignore
16
- let o = options_[k];
17
- // @ts-ignore
18
- const c = matOptionRanges[k] as MatOptionMeta;
19
- const { range, scaleByMaxCoordinate, scaleByMaxRadius } = c;
14
+ const key = k as keyof typeof matOptionRanges;
15
+ let o = options_[key];
16
+ const c = matOptionRanges[key];
17
+ const { range, scaleByMaxCoordinate } = c;
20
18
  if (o < range[0]) { o = range[0]; }
21
19
  if (o > range[1]) { o = range[1]; }
22
20
 
23
21
  // Adjust length tolerance according to a reference max coordinate
24
22
  if (!!scaleByMaxCoordinate) {
25
- o = o * (2**expMaxCoord * 2**(-scaleSigBits));
26
- } else if (!!scaleByMaxRadius) {
27
- o = o * (2**expMaxRadius * 2**(-scaleSigBits));
23
+ o *= 2**(maxCoordPowerOf2 - scaleSigBits);
28
24
  }
29
25
 
30
- // @ts-ignore
31
- options_[k] = o;
26
+ options_[key] = o;
32
27
  }
33
28
 
34
29
  return options_;