flo-mat 4.1.5 → 5.0.2

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 (356) hide show
  1. package/__tests__/closest-boundary-point/get-endpoint-info.spec.ts +140 -0
  2. package/__tests__/closest-boundary-point/root-interval-to-distance-squared-interval.spec.ts +87 -0
  3. package/__tests__/cp-node/fs/get-all-on-loop-by-loop.spec.ts +55 -0
  4. package/__tests__/cp-node/fs/get-angle-between-mat-curves.spec.ts +39 -3
  5. package/__tests__/cp-node/fs/get-boundary-bezier-parts-to-next.spec.ts +87 -3
  6. package/__tests__/cp-node/fs/get-boundary-beziers-between.spec.ts +68 -3
  7. package/__tests__/cp-node/fs/get-boundary-beziers-to-next.spec.ts +41 -3
  8. package/__tests__/cp-node/fs/get-boundary-distance-to-next.spec.ts +20 -3
  9. package/__tests__/cp-node/fs/get-branch-beziers.spec.ts +42 -3
  10. package/__tests__/cp-node/fs/get-branch.spec.ts +60 -3
  11. package/__tests__/cp-node/fs/get-cp-node-ordering.spec.ts +19 -3
  12. package/__tests__/cp-node/fs/get-distance-to-next.spec.ts +37 -4
  13. package/__tests__/cp-node/fs/get-edge-direction.spec.ts +50 -3
  14. package/__tests__/cp-node/fs/get-first-exit.spec.ts +78 -3
  15. package/__tests__/cp-node/fs/get-hole-closers.spec.ts +32 -3
  16. package/__tests__/cp-node/fs/get-implied-boundary-bezier-between.spec.ts +48 -3
  17. package/__tests__/cp-node/fs/get-mat-curve-between.spec.ts +77 -3
  18. package/__tests__/cp-node/fs/get-mat-curve-to-next.spec.ts +17 -4
  19. package/__tests__/cp-node/fs/get-mat-curves-between.spec.ts +38 -3
  20. package/__tests__/cp-node/fs/get-salience.spec.ts +68 -3
  21. package/__tests__/cp-node/fs/get-vertex-forward-children.spec.ts +40 -3
  22. package/__tests__/cp-node/fs/insert-cp-node.spec.ts +87 -3
  23. package/__tests__/cp-node/fs/is-special.spec.ts +1 -1
  24. package/__tests__/cp-node/fs/remove-cp-node.spec.ts +42 -3
  25. package/__tests__/find-2-prong/calc-seperation-tolerance.spec.ts +46 -0
  26. package/__tests__/find-2-prong/get-medial/get-closest-points.spec.ts +1 -1
  27. package/__tests__/floyd-warshall/get-graph.spec.ts +100 -0
  28. package/__tests__/get-mats-with-hole.ts +28 -0
  29. package/__tests__/get-mats1.spec.ts +61 -0
  30. package/__tests__/get-mats1.ts +75 -67
  31. package/__tests__/helpers/cp-node-by-id.ts +27 -0
  32. package/__tests__/helpers/expect-point-close.ts +42 -0
  33. package/__tests__/mat/hausdorff-distance-one-sided-exceeds.spec.ts +129 -0
  34. package/__tests__/mat/simplify-mat.spec.ts +85 -0
  35. package/__tests__/reconstruct-from-mat/reconstruct-from-mat.spec.ts +39 -0
  36. package/__tests__/specific-cases/test-svgs/achispado.svg +14 -0
  37. package/__tests__/utils/get-beziers-from-tangents.spec.ts +142 -0
  38. package/browser/index.js +12985 -9965
  39. package/browser/index.min.js +1 -1
  40. package/node/closest-boundary-point/cull-curve-pieces.d.ts +21 -0
  41. package/node/closest-boundary-point/cull-curve-pieces.js +40 -0
  42. package/node/closest-boundary-point/cull-curve-pieces.js.map +1 -0
  43. package/node/closest-boundary-point/get-close-boundary-points-certified.js +5 -2
  44. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  45. package/node/closest-boundary-point/get-endpoint-info.d.ts +39 -0
  46. package/node/closest-boundary-point/get-endpoint-info.js +78 -0
  47. package/node/closest-boundary-point/get-endpoint-info.js.map +1 -0
  48. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +5 -19
  49. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
  50. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.d.ts +17 -5
  51. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js +37 -50
  52. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js.map +1 -1
  53. package/node/corner/get-corner.d.ts +18 -1
  54. package/node/corner/get-corner.js +8 -1
  55. package/node/corner/get-corner.js.map +1 -1
  56. package/node/corner/get-interface-ccw.js.map +1 -1
  57. package/node/cp-node/cp-node.d.ts +4 -3
  58. package/node/cp-node/fs/get-all-on-loop-by-loop.js +0 -4
  59. package/node/cp-node/fs/get-all-on-loop-by-loop.js.map +1 -1
  60. package/node/cp-node/fs/get-angle-between-mat-curves.js +6 -4
  61. package/node/cp-node/fs/get-angle-between-mat-curves.js.map +1 -1
  62. package/node/cp-node/fs/get-boundary-beziers-between.d.ts +6 -4
  63. package/node/cp-node/fs/get-boundary-beziers-between.js +6 -4
  64. package/node/cp-node/fs/get-boundary-beziers-between.js.map +1 -1
  65. package/node/cp-node/fs/get-branch-beziers.d.ts +2 -1
  66. package/node/cp-node/fs/get-branch-beziers.js +3 -2
  67. package/node/cp-node/fs/get-branch-beziers.js.map +1 -1
  68. package/node/cp-node/fs/get-branch.js +1 -2
  69. package/node/cp-node/fs/get-branch.js.map +1 -1
  70. package/node/cp-node/fs/get-distance-to-next.js +4 -2
  71. package/node/cp-node/fs/get-distance-to-next.js.map +1 -1
  72. package/node/cp-node/fs/get-first-exit.d.ts +7 -3
  73. package/node/cp-node/fs/get-first-exit.js +13 -11
  74. package/node/cp-node/fs/get-first-exit.js.map +1 -1
  75. package/node/cp-node/fs/get-implied-boundary-bezier-between.d.ts +9 -1
  76. package/node/cp-node/fs/get-implied-boundary-bezier-between.js +11 -55
  77. package/node/cp-node/fs/get-implied-boundary-bezier-between.js.map +1 -1
  78. package/node/cp-node/fs/get-mat-curve-between.d.ts +4 -3
  79. package/node/cp-node/fs/get-mat-curve-between.js +5 -49
  80. package/node/cp-node/fs/get-mat-curve-between.js.map +1 -1
  81. package/node/cp-node/fs/get-mat-curve-to-next.d.ts +1 -1
  82. package/node/cp-node/fs/get-mat-curves-between.d.ts +8 -0
  83. package/node/cp-node/fs/get-mat-curves-between.js +9 -2
  84. package/node/cp-node/fs/get-mat-curves-between.js.map +1 -1
  85. package/node/cp-node/fs/get-real-prong-count.d.ts +2 -1
  86. package/node/cp-node/fs/get-real-prong-count.js +11 -5
  87. package/node/cp-node/fs/get-real-prong-count.js.map +1 -1
  88. package/node/cp-node/fs/get-salience.d.ts +10 -0
  89. package/node/cp-node/fs/get-salience.js +17 -1
  90. package/node/cp-node/fs/get-salience.js.map +1 -1
  91. package/node/cp-node/fs/is-fully-terminating.d.ts +4 -2
  92. package/node/cp-node/fs/is-fully-terminating.js +6 -15
  93. package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
  94. package/node/cp-node/fs/is-on-same-loop.d.ts +1 -1
  95. package/node/cp-node/fs/is-special.d.ts +7 -0
  96. package/node/cp-node/fs/is-special.js +9 -2
  97. package/node/cp-node/fs/is-special.js.map +1 -1
  98. package/node/cp-node/fs/is-vertex.d.ts +1 -1
  99. package/node/cp-node/fs/traverse-edges.d.ts +7 -3
  100. package/node/cp-node/fs/traverse-edges.js +7 -3
  101. package/node/cp-node/fs/traverse-edges.js.map +1 -1
  102. package/node/cp-node/stringification/from-stringifyable.d.ts +2 -2
  103. package/node/cp-node/stringification/from-stringifyable.js +1 -1
  104. package/node/cp-node/stringification/from-stringifyable.js.map +1 -1
  105. package/node/cp-node/stringification/to-stringifyable.d.ts +3 -3
  106. package/node/cp-node/stringification/to-stringifyable.js +3 -3
  107. package/node/debug/debug.d.ts +26 -3
  108. package/node/debug/debug.js +16 -5
  109. package/node/debug/debug.js.map +1 -1
  110. package/node/find-2-prong/add-2-prong.js +1 -7
  111. package/node/find-2-prong/add-2-prong.js.map +1 -1
  112. package/node/find-2-prong/calc-seperation-tolerance.d.ts +28 -5
  113. package/node/find-2-prong/calc-seperation-tolerance.js +32 -89
  114. package/node/find-2-prong/calc-seperation-tolerance.js.map +1 -1
  115. package/node/find-2-prong/find-2-prong.js +8 -10
  116. package/node/find-2-prong/find-2-prong.js.map +1 -1
  117. package/node/find-2-prong/find-and-add-2-prongs.js +2 -2
  118. package/node/find-2-prong/find-and-add-2-prongs.js.map +1 -1
  119. package/node/find-2-prong/get-medial/get-antipodal-points.d.ts +1 -2
  120. package/node/find-2-prong/get-medial/get-antipodal-points.js +2 -3
  121. package/node/find-2-prong/get-medial/get-antipodal-points.js.map +1 -1
  122. package/node/find-2-prong/get-medial/get-closest-points.d.ts +1 -8
  123. package/node/find-2-prong/get-medial/get-closest-points.js +4 -40
  124. package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -1
  125. package/node/find-2-prong/reduce-radius.d.ts +1 -1
  126. package/node/find-2-prong/reduce-radius.js +6 -3
  127. package/node/find-2-prong/reduce-radius.js.map +1 -1
  128. package/node/find-3-prong/calc-better-x.js +1 -1
  129. package/node/find-3-prong/calc-better-x.js.map +1 -1
  130. package/node/find-3-prong/find-3-prong-for-delta3s.d.ts +3 -2
  131. package/node/find-3-prong/find-3-prong-for-delta3s.js +35 -41
  132. package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
  133. package/node/find-3-prong/find-3-prong.js +3 -1
  134. package/node/find-3-prong/find-3-prong.js.map +1 -1
  135. package/node/find-3-prong/find-and-add-3-prongs.js +16 -0
  136. package/node/find-3-prong/find-and-add-3-prongs.js.map +1 -1
  137. package/node/find-mat/create-initial-cp-tree.js +2 -2
  138. package/node/find-mat/create-initial-cp-tree.js.map +1 -1
  139. package/node/find-mat/find-mat.js +3 -4
  140. package/node/find-mat/find-mat.js.map +1 -1
  141. package/node/find-mat/find-mats.d.ts +6 -12
  142. package/node/find-mat/find-mats.js +10 -27
  143. package/node/find-mat/find-mats.js.map +1 -1
  144. package/node/find-mat/get-dull-corners-on-loop.js +2 -2
  145. package/node/find-mat/get-dull-corners-on-loop.js.map +1 -1
  146. package/node/find-mat/get-for-1-prongs-on-loop.js +36 -8
  147. package/node/find-mat/get-for-1-prongs-on-loop.js.map +1 -1
  148. package/node/find-mat/get-meta.d.ts +14 -4
  149. package/node/find-mat/get-meta.js +30 -24
  150. package/node/find-mat/get-meta.js.map +1 -1
  151. package/node/find-mat/get-sharp-corners.js +2 -2
  152. package/node/find-mat/get-sharp-corners.js.map +1 -1
  153. package/node/find-mat/mat-options.d.ts +2 -2
  154. package/node/floyd-warshall/get-graph.d.ts +12 -1
  155. package/node/floyd-warshall/get-graph.js +41 -38
  156. package/node/floyd-warshall/get-graph.js.map +1 -1
  157. package/node/geometry/get-bounding-box-.d.ts +16 -2
  158. package/node/geometry/get-bounding-box-.js +5 -2
  159. package/node/geometry/get-bounding-box-.js.map +1 -1
  160. package/node/geometry/get-closest-square-distance-to-rect.d.ts +3 -0
  161. package/node/geometry/get-closest-square-distance-to-rect.js +7 -5
  162. package/node/geometry/get-closest-square-distance-to-rect.js.map +1 -1
  163. package/node/geometry/get-closest-squared-distance-to-rotated-rect.d.ts +4 -0
  164. package/node/geometry/get-closest-squared-distance-to-rotated-rect.js +11 -5
  165. package/node/geometry/get-closest-squared-distance-to-rotated-rect.js.map +1 -1
  166. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js +1 -2
  167. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js.map +1 -1
  168. package/node/index.d.ts +3 -2
  169. package/node/index.js +2 -1
  170. package/node/index.js.map +1 -1
  171. package/node/mat/clone-mat.d.ts +9 -0
  172. package/node/mat/clone-mat.js +17 -0
  173. package/node/mat/clone-mat.js.map +1 -0
  174. package/node/mat/clone-meta.d.ts +12 -0
  175. package/node/mat/clone-meta.js +24 -0
  176. package/node/mat/clone-meta.js.map +1 -0
  177. package/node/mat/get-boundary-piece-beziers.d.ts +5 -0
  178. package/node/mat/get-boundary-piece-beziers.js +7 -93
  179. package/node/mat/get-boundary-piece-beziers.js.map +1 -1
  180. package/node/mat/get-largest-3-prong.d.ts +6 -0
  181. package/node/mat/get-largest-3-prong.js +8 -5
  182. package/node/mat/get-largest-3-prong.js.map +1 -1
  183. package/node/mat/get-largest-vertex.d.ts +15 -1
  184. package/node/mat/get-largest-vertex.js +20 -7
  185. package/node/mat/get-largest-vertex.js.map +1 -1
  186. package/node/mat/hausdorff-distance-one-sided-exceeds.d.ts +79 -0
  187. package/node/mat/hausdorff-distance-one-sided-exceeds.js +251 -0
  188. package/node/mat/hausdorff-distance-one-sided-exceeds.js.map +1 -0
  189. package/node/mat/mat-meta.d.ts +0 -6
  190. package/node/mat/simplify-mat.d.ts +25 -8
  191. package/node/mat/simplify-mat.js +182 -53
  192. package/node/mat/simplify-mat.js.map +1 -1
  193. package/node/mat/trim-mat.d.ts +4 -2
  194. package/node/mat/trim-mat.js +3 -1
  195. package/node/mat/trim-mat.js.map +1 -1
  196. package/node/point-on-shape/get-boundary-tangent-line.d.ts +19 -0
  197. package/node/point-on-shape/get-boundary-tangent-line.js +33 -0
  198. package/node/point-on-shape/get-boundary-tangent-line.js.map +1 -0
  199. package/node/point-on-shape/get-osculating-circle.d.ts +6 -4
  200. package/node/point-on-shape/get-osculating-circle.js +6 -4
  201. package/node/point-on-shape/get-osculating-circle.js.map +1 -1
  202. package/node/point-on-shape/get-pos-corner.js +2 -2
  203. package/node/point-on-shape/get-pos-corner.js.map +1 -1
  204. package/node/reconstruct-from-mat/reconstruct-from-mat.js +20 -80
  205. package/node/reconstruct-from-mat/reconstruct-from-mat.js.map +1 -1
  206. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.d.ts +4 -0
  207. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js +4 -0
  208. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js.map +1 -1
  209. package/node/sat/cull.d.ts +7 -6
  210. package/node/sat/cull.js +13 -16
  211. package/node/sat/cull.js.map +1 -1
  212. package/node/sat/get-sat-culls.d.ts +12 -2
  213. package/node/sat/get-sat-culls.js +21 -16
  214. package/node/sat/get-sat-culls.js.map +1 -1
  215. package/node/svg/get-shape-bounds.d.ts +1 -12
  216. package/node/svg/get-shape-bounds.js +2 -3
  217. package/node/svg/get-shape-bounds.js.map +1 -1
  218. package/node/sweep-line/sweep-line.js.map +1 -1
  219. package/node/utils/get-beziers-from-tangents.d.ts +28 -0
  220. package/node/utils/get-beziers-from-tangents.js +92 -0
  221. package/node/utils/get-beziers-from-tangents.js.map +1 -0
  222. package/node/vertex/remove-vertex.d.ts +5 -3
  223. package/node/vertex/remove-vertex.js +5 -3
  224. package/node/vertex/remove-vertex.js.map +1 -1
  225. package/package.json +9 -9
  226. package/qv-infinite-loop.md +120 -0
  227. package/src/closest-boundary-point/cull-curve-pieces.ts +49 -0
  228. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +5 -2
  229. package/src/closest-boundary-point/get-endpoint-info.ts +96 -0
  230. package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +5 -23
  231. package/src/closest-boundary-point/root-interval-to-distance-squared-interval.ts +42 -60
  232. package/src/corner/get-corner.ts +10 -1
  233. package/src/corner/get-interface-ccw.ts +2 -2
  234. package/src/cp-node/cp-node.ts +4 -3
  235. package/src/cp-node/fs/get-all-on-loop-by-loop.ts +0 -4
  236. package/src/cp-node/fs/get-angle-between-mat-curves.ts +6 -4
  237. package/src/cp-node/fs/get-boundary-beziers-between.ts +10 -8
  238. package/src/cp-node/fs/get-branch-beziers.ts +3 -2
  239. package/src/cp-node/fs/get-branch.ts +1 -2
  240. package/src/cp-node/fs/get-distance-to-next.ts +4 -2
  241. package/src/cp-node/fs/get-first-exit.ts +15 -14
  242. package/src/cp-node/fs/get-implied-boundary-bezier-between.ts +17 -69
  243. package/src/cp-node/fs/get-mat-curve-between.ts +9 -67
  244. package/src/cp-node/fs/get-mat-curves-between.ts +9 -2
  245. package/src/cp-node/fs/get-real-prong-count.ts +11 -7
  246. package/src/cp-node/fs/get-salience.ts +15 -2
  247. package/src/cp-node/fs/is-fully-terminating.ts +6 -18
  248. package/src/cp-node/fs/is-on-same-loop.ts +2 -2
  249. package/src/cp-node/fs/is-special.ts +11 -6
  250. package/src/cp-node/fs/is-vertex.ts +1 -1
  251. package/src/cp-node/fs/traverse-edges.ts +8 -4
  252. package/src/cp-node/stringification/from-stringifyable.ts +75 -75
  253. package/src/cp-node/stringification/to-stringifyable.ts +3 -3
  254. package/src/debug/debug.ts +44 -8
  255. package/src/find-2-prong/add-2-prong.ts +2 -9
  256. package/src/find-2-prong/calc-seperation-tolerance.ts +34 -115
  257. package/src/find-2-prong/find-2-prong.ts +9 -11
  258. package/src/find-2-prong/find-and-add-2-prongs.ts +2 -2
  259. package/src/find-2-prong/get-medial/get-antipodal-points.ts +1 -3
  260. package/src/find-2-prong/get-medial/get-closest-points.ts +6 -51
  261. package/src/find-2-prong/reduce-radius.ts +6 -4
  262. package/src/find-3-prong/calc-better-x.ts +2 -2
  263. package/src/find-3-prong/find-3-prong-for-delta3s.ts +197 -214
  264. package/src/find-3-prong/find-3-prong.ts +54 -51
  265. package/src/find-3-prong/find-and-add-3-prongs.ts +20 -1
  266. package/src/find-mat/create-initial-cp-tree.ts +2 -2
  267. package/src/find-mat/find-mat.ts +4 -6
  268. package/src/find-mat/find-mats.ts +83 -105
  269. package/src/find-mat/get-dull-corners-on-loop.ts +2 -2
  270. package/src/find-mat/get-for-1-prongs-on-loop.ts +40 -8
  271. package/src/find-mat/get-meta.ts +34 -39
  272. package/src/find-mat/get-sharp-corners.ts +2 -2
  273. package/src/find-mat/mat-options.ts +2 -2
  274. package/src/floyd-warshall/get-graph.ts +46 -47
  275. package/src/geometry/get-bounding-box-.ts +5 -2
  276. package/src/geometry/get-closest-square-distance-to-rect.ts +7 -7
  277. package/src/geometry/get-closest-squared-distance-to-rotated-rect.ts +12 -10
  278. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.ts +1 -2
  279. package/src/index.ts +3 -2
  280. package/src/mat/clone-mat.ts +9 -3
  281. package/src/mat/clone-meta.ts +8 -0
  282. package/src/mat/get-boundary-piece-beziers.ts +16 -117
  283. package/src/mat/get-largest-3-prong.ts +9 -6
  284. package/src/mat/get-largest-vertex.ts +25 -9
  285. package/src/mat/hausdorff-distance-one-sided-exceeds.ts +314 -0
  286. package/src/mat/mat-meta.ts +0 -9
  287. package/src/mat/simplify-mat.ts +254 -116
  288. package/src/mat/trim-mat.ts +6 -4
  289. package/src/point-on-shape/get-boundary-tangent-line.ts +36 -0
  290. package/src/point-on-shape/get-osculating-circle.ts +7 -5
  291. package/src/point-on-shape/get-pos-corner.ts +2 -2
  292. package/src/reconstruct-from-mat/reconstruct-from-mat.ts +22 -111
  293. package/src/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.ts +4 -0
  294. package/src/sat/cull.ts +16 -20
  295. package/src/sat/get-sat-culls.ts +28 -23
  296. package/src/svg/get-shape-bounds.ts +2 -3
  297. package/src/sweep-line/sweep-line.ts +1 -1
  298. package/src/utils/get-beziers-from-tangents.ts +110 -0
  299. package/src/utils/map-map.ts +1 -1
  300. package/src/vertex/remove-vertex.ts +5 -3
  301. package/__tests__/cp-node/fs/get-distance-between.spec.ts +0 -7
  302. package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +0 -24
  303. package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +0 -17
  304. package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +0 -17
  305. package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +0 -14
  306. package/node/closest-boundary-point/cull-bezier-pieces-1.d.ts +0 -9
  307. package/node/closest-boundary-point/cull-bezier-pieces-1.js +0 -17
  308. package/node/closest-boundary-point/cull-bezier-pieces-1.js.map +0 -1
  309. package/node/closest-boundary-point/cull-by-loose-bounding-box.d.ts +0 -13
  310. package/node/closest-boundary-point/cull-by-loose-bounding-box.js +0 -27
  311. package/node/closest-boundary-point/cull-by-loose-bounding-box.js.map +0 -1
  312. package/node/closest-boundary-point/cull-by-tight-boundary-box.d.ts +0 -11
  313. package/node/closest-boundary-point/cull-by-tight-boundary-box.js +0 -27
  314. package/node/closest-boundary-point/cull-by-tight-boundary-box.js.map +0 -1
  315. package/node/cp-node/fs/find-first.d.ts +0 -10
  316. package/node/cp-node/fs/find-first.js +0 -19
  317. package/node/cp-node/fs/find-first.js.map +0 -1
  318. package/node/debug/functions/check-ordering.d.ts +0 -4
  319. package/node/debug/functions/check-ordering.js +0 -43
  320. package/node/debug/functions/check-ordering.js.map +0 -1
  321. package/node/find-2-prong/cull-bezier-pieces.d.ts +0 -13
  322. package/node/find-2-prong/cull-bezier-pieces.js +0 -43
  323. package/node/find-2-prong/cull-bezier-pieces.js.map +0 -1
  324. package/node/floyd-warshall/get-hole-closer-pairs.d.ts +0 -8
  325. package/node/floyd-warshall/get-hole-closer-pairs.js +0 -27
  326. package/node/floyd-warshall/get-hole-closer-pairs.js.map +0 -1
  327. package/node/utils/dual-set.d.ts +0 -27
  328. package/node/utils/dual-set.js +0 -55
  329. package/node/utils/dual-set.js.map +0 -1
  330. package/node/utils/tri-map.d.ts +0 -27
  331. package/node/utils/tri-map.js +0 -49
  332. package/node/utils/tri-map.js.map +0 -1
  333. package/src/closest-boundary-point/cull-bezier-pieces-1.ts +0 -36
  334. package/src/closest-boundary-point/cull-by-loose-bounding-box.ts +0 -42
  335. package/src/closest-boundary-point/cull-by-tight-boundary-box.ts +0 -43
  336. package/src/closest-boundary-point/get-p-from-box.ts +0 -14
  337. package/src/cp-node/fs/add-distance-from.ts +0 -49
  338. package/src/cp-node/fs/get-distance-between.ts +0 -16
  339. package/src/cp-node/fs/get-terminating-on-circle.ts +0 -24
  340. package/src/cp-node/fs/is-single-3-prong.ts +0 -15
  341. package/src/cp-node/fs/iterate-all-on-loop.ts +0 -15
  342. package/src/cp-node/fs/traverse-all-forward.ts +0 -24
  343. package/src/debug/functions/draw/draw-beziers-as-single-path.ts +0 -40
  344. package/src/debug/functions/draw/draw-disk.ts +0 -34
  345. package/src/debug/functions/draw/xmlns.ts +0 -5
  346. package/src/find-2-prong/cull-bezier-pieces.ts +0 -61
  347. package/src/find-2-prong/find-and-add-2-prong.ts +0 -30
  348. package/src/find-2-prong/get-medial/get-closest-points-d.ts +0 -213
  349. package/src/find-2-prong/x-for-debugging.ts +0 -13
  350. package/src/floyd-warshall/get-hole-closer-pairs.ts +0 -35
  351. package/src/mat/get-two-prong-type.ts +0 -13
  352. package/src/point-on-shape/is-pos-dull-corner.ts +0 -18
  353. package/src/point-on-shape/is-pos-quite-dull-corner.ts +0 -18
  354. package/src/point-on-shape/is-pos-quite-sharp-corner.ts +0 -18
  355. package/src/point-on-shape/pos-to-human-string.ts +0 -18
  356. package/src/sweep-line/are-boxes-intersecting.ts +0 -37
@@ -1,105 +1,83 @@
1
- import { beziersToSvgPathStr, simplifyPaths } from 'flo-boolean';
2
- import { getLoopsMetrics } from '../loop/get-max-coordinate.js';
3
- import { Mat } from '../mat/mat.js';
4
- import { simplifyMat } from '../mat/simplify-mat.js';
5
- import { toScaleAxis } from '../sat/to-scale-axis.js';
6
- import { clipOptions } from './clip-options.js';
7
- import { findMat } from './find-mat.js';
8
- import { defaultMatOptions, MatOptions } from './mat-options.js';
9
-
10
-
11
- const { ceil, log2 } = Math;
12
-
13
-
14
- /**
15
- * Finds and returns the Medial Axis Transforms (MATs) from the given array of
16
- * bezier loops representing shape boundaries.
17
- *
18
- * @param bezierLoops An array of (possibly intersecting) loops with each loop
19
- * representing one or more piecewise smooth closed curves (i.e. shapes). Each
20
- * loop consists of an array of beziers represented by an array of control
21
- * points with 2,3 or 4 elements corresponding to linear, quadratic and cubic
22
- * beziers respectively. Each point is a two-element array (ordered pair), the
23
- * first of which is the x-coordinate and the second the y-coordinate.
24
- *
25
- * @param maxCurviness The maximum value the 'curviness' of a curve can have
26
- * before an additional MAT point is inserted in between. Defaults to 0.4.
27
- * (Curviness is measured as the total angle in radians between the consecutive
28
- * vectors formed by the ordered control points of th bezier curve). The value
29
- * is clipped in the range `[0.01,3]`.
30
- *
31
- * @param maxLength The maximum length a curve can have before an additional MAT
32
- * point is inserted. This value is scaled to a reference 1024 x 1024
33
- * grid (e.g. if the shape fits in a 512 x 512 axis-aligned box the value will be
34
- * halved, e.g. from 10 to 5). Together with maxCurviness it represents a
35
- * tolerance for the accuracy of the MAT. Defaults to 4. The value is clipped
36
- * in [1,100].
37
- */
38
- function findMats(
39
- bezierLoops: number[][][][],
40
- options?: MatOptions): Mat[] {
41
-
42
- // if (typeof _debug_ !== 'undefined') { var timingStart = performance.now(); }
43
- const { maxCoordinate } = getLoopsMetrics(bezierLoops);
44
- const maxCoordPowerOf2 = ceil(log2(maxCoordinate));
45
-
46
- const options_: Required<MatOptions> = clipOptions(
47
- maxCoordPowerOf2, {
48
- ...defaultMatOptions,
49
- ...(options || {})
50
- });
51
-
52
- const {
53
- applySat, simplify,
54
- satScale, simplifyTolerance
55
- } = options_;
56
-
57
-
58
- const loopss = simplifyPaths(bezierLoops, {
59
- forceOrientationNegative: true,
60
- });
61
-
62
- // console.log(loopsToSvgPathStr(bezierLoops));
63
-
64
- const mats: Mat[] = [];
65
- for (const loops of loopss) {
66
- let mat = findMat(loops, maxCoordPowerOf2, options_);
67
- if (mat === undefined) { continue; }
68
-
69
- if (applySat) {
70
- mat = toScaleAxis(mat, satScale);
71
- }
72
-
73
- if (simplify) {
74
- mat = simplifyMat(mat, simplifyTolerance, 50)
75
- }
76
-
77
- mats.push(mat);
78
- }
79
-
80
- // console.log(structuredClone(circumCenter.getStats()));
81
- // circumCenter.resetStats();
82
-
83
- return mats;
84
- }
85
-
86
-
87
-
88
- /**
89
- * Returns an SVG path string representation of the given bezier loops.
90
- * @param loops An array of loops having an array of bezier curves each given as
91
- * an array of control points.
92
- */
93
- function loopsToSvgPathStr(
94
- loops: number[][][][]) {
95
-
96
- let str = '';
97
- for (const loop of loops) {
98
- str = str + beziersToSvgPathStr(loop) + '\n';
99
- }
100
-
101
- return str;
102
- }
103
-
104
-
105
- export { findMats }
1
+ import { simplifyPaths } from 'flo-boolean';
2
+ import { getLoopsMetrics } from '../loop/get-max-coordinate.js';
3
+ import { Mat } from '../mat/mat.js';
4
+ import { simplifyMat } from '../mat/simplify-mat.js';
5
+ import { toScaleAxis } from '../sat/to-scale-axis.js';
6
+ import { clipOptions } from './clip-options.js';
7
+ import { findMat } from './find-mat.js';
8
+ import { resetDebugElems } from './get-meta.js';
9
+ import { defaultMatOptions, MatOptions } from './mat-options.js';
10
+
11
+
12
+ const { ceil, log2 } = Math;
13
+
14
+
15
+ /**
16
+ * Finds and returns the Medial Axis Transforms (MATs) from the given array of
17
+ * bezier loops representing shape boundaries.
18
+ *
19
+ * @param bezierLoops An array of (possibly intersecting) loops with each loop
20
+ * representing one or more piecewise smooth closed curves (i.e. shapes). Each
21
+ * loop consists of an array of beziers represented by an array of control
22
+ * points with 2,3 or 4 elements corresponding to linear, quadratic and cubic
23
+ * beziers respectively. Each point is a two-element array (ordered pair), the
24
+ * first of which is the x-coordinate and the second the y-coordinate.
25
+ *
26
+ * @param options the `MatOptions` (see there for a description of each option
27
+ * and its default), e.g. `maxCurviness` and `maxLength` together determine the
28
+ * accuracy of the MAT, `simplify` and `simplifyTolerance` control the
29
+ * simplification of the result and `applySat` and `satScale` whether and how
30
+ * the Scale Axis Transform is applied. Missing options take their defaults
31
+ * (`defaultMatOptions`) and all values are clipped to their allowed ranges.
32
+ */
33
+ function findMats(
34
+ bezierLoops: number[][][][],
35
+ options?: MatOptions): Mat[] {
36
+
37
+ // if (typeof _debug_ !== 'undefined') { var timingStart = performance.now(); }
38
+ resetDebugElems();
39
+ const { maxCoordinate } = getLoopsMetrics(bezierLoops);
40
+ const maxCoordPowerOf2 = ceil(log2(maxCoordinate));
41
+
42
+ const options_: Required<MatOptions> = clipOptions(
43
+ maxCoordPowerOf2, {
44
+ ...defaultMatOptions,
45
+ ...(options || {})
46
+ });
47
+
48
+ const {
49
+ applySat, simplify,
50
+ satScale, simplifyTolerance
51
+ } = options_;
52
+
53
+
54
+ const loopss = simplifyPaths(bezierLoops, {
55
+ forceOrientationNegative: true,
56
+ });
57
+
58
+
59
+ const mats: Mat[] = [];
60
+ for (const loops of loopss) {
61
+ let mat = findMat(loops, maxCoordPowerOf2, options_);
62
+ if (mat === undefined) { continue; }
63
+
64
+ if (applySat) {
65
+ mat = toScaleAxis(mat, satScale);
66
+ }
67
+
68
+ if (simplify) {
69
+ mat = simplifyMat(mat, simplifyTolerance)
70
+ }
71
+
72
+ mats.push(mat);
73
+ }
74
+
75
+ // console.log(structuredClone(circumCenter.getStats()));
76
+ // circumCenter.resetStats();
77
+
78
+ return mats;
79
+ }
80
+
81
+
82
+
83
+ export { findMats }
@@ -1,7 +1,7 @@
1
1
  import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
2
2
  import type { Loop } from 'flo-boolean';
3
3
  import { controlPointLinesLength } from 'flo-bezier3';
4
- import { getCorner } from '../corner/get-corner.js';
4
+ import { getCorner$ } from '../corner/get-corner.js';
5
5
 
6
6
 
7
7
  /** @internal */
@@ -20,7 +20,7 @@ function getDullCornersOnLoop(
20
20
 
21
21
  const { next, ps } = curve;
22
22
 
23
- if (getCorner(ps, next.ps).isQuiteDull) {
23
+ if (getCorner$(ps, next.ps).isQuiteDull) {
24
24
  const p = ps[ps.length - 1];
25
25
  const pDd = [[0,p[0]], [0,p[1]]];
26
26
 
@@ -1,9 +1,28 @@
1
1
  import type { Loop } from 'flo-boolean';
2
2
  import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
3
3
  import { getCurvatureExtremaDd, controlPointLinesLength } from 'flo-bezier3';
4
+ import { distanceBetween } from 'flo-vector2d';
4
5
  import { toP } from '../point-on-shape/to-p.js';
5
6
 
6
7
 
8
+ /**
9
+ * @internal
10
+ * Curvature maxima closer than this (in parameter space) to a curve endpoint
11
+ * are ignored - they are handled by the corner logic.
12
+ */
13
+ const EDGE_T_TOLERANCE = 2**-20;
14
+ /**
15
+ * @internal
16
+ * Curvature maxima closer than this fraction of the curve's control polygon
17
+ * length to a curve endpoint are ignored. A curve with (near) coincident
18
+ * control points at an end has (near) zero speed there and its curvature
19
+ * blows up towards that end; the resulting "maximum" (that can be well
20
+ * inside the parameter tolerance above) is an artifact and not a feature of
21
+ * the shape.
22
+ */
23
+ const EDGE_DISTANCE_TOLERANCE = 2**-20;
24
+
25
+
7
26
  /**
8
27
  * Get points of maximum curvature.
9
28
  *
@@ -19,24 +38,37 @@ function getFor1ProngsOnLoop(
19
38
 
20
39
  for (let i=0; i<loop.curves.length; i++) {
21
40
  const curve = loop.curves[i];
41
+ const { ps } = curve;
22
42
 
23
- if (controlPointLinesLength(curve.ps) < minBezLength) {
43
+ const len = controlPointLinesLength(ps);
44
+ if (len < minBezLength) {
24
45
  continue;
25
46
  }
26
47
 
27
- const { ps } = curve;
48
+ const pS = ps[0];
49
+ const pE = ps[ps.length-1];
50
+ const edgeDistanceTolerance = len * EDGE_DISTANCE_TOLERANCE;
51
+
52
+ for (const t of getCurvatureExtremaDd(ps).maxima) {
53
+ // keep away from edges (in parameter space)
54
+ if (t < EDGE_T_TOLERANCE || t > 1 - EDGE_T_TOLERANCE) {
55
+ continue;
56
+ }
28
57
 
29
- poss.push(...getCurvatureExtremaDd(ps).maxima.map(t => {
30
58
  const pDd = toP(ps, t);
31
59
  const p = pDd.map(c => c[0] + c[1]);
32
60
 
33
- return { curve, t, isSource: true, p, pDd }
34
- }));
61
+ // keep away from edges (in distance)
62
+ if (distanceBetween(p, pS) < edgeDistanceTolerance ||
63
+ distanceBetween(p, pE) < edgeDistanceTolerance) {
64
+ continue;
65
+ }
66
+
67
+ poss.push({ curve, t, isSource: true, p, pDd });
68
+ }
35
69
  }
36
70
 
37
- return poss
38
- // keep away from edges
39
- .filter(pos => pos.t > 2**-20 && pos.t < 2**-20);
71
+ return poss;
40
72
  }
41
73
  }
42
74
 
@@ -1,10 +1,9 @@
1
1
  import type { Debug } from '../debug/debug.js';
2
2
  import type { Loop } from 'flo-boolean';
3
- import type { Curve } from 'flo-boolean';
4
- import type { MatMeta } from '../mat/mat-meta.js';
5
- import { getBoundingHull, getBoundingBoxTight } from 'flo-bezier3';
6
- import { getBoundingBox$ } from '../geometry/get-bounding-box-.js';
3
+ import { getBoundingHull } from 'flo-bezier3';
4
+ import { getBoundingBox$, getBoundingBoxTight$ } from '../geometry/get-bounding-box-.js';
7
5
  import { getCorner } from '../corner/get-corner.js';
6
+ import { createEmptyElems } from '../debug/debug.js';
8
7
 
9
8
 
10
9
  /** @internal */
@@ -14,38 +13,41 @@ declare const _debug_: Debug;
14
13
  let timingStart: number;
15
14
 
16
15
 
17
- /** @internal */
18
- function getPartialMeta(
19
- loops: Loop[]): Omit<
20
- MatMeta,
21
- | 'cpTrees'
22
- // | 'pointToCpNode'
23
- | 'loops'
24
- | 'maxCoordPowerOf2'
25
- | 'squaredDiagonalLength'
26
- | 'lastInsertId'
27
- > {
28
-
29
- const looseBoundingBoxes: number[][][] = [];
30
- const tightBoundingBoxes: number[][][] = [];
31
- const boundingHulls: number[][][] = [];
32
- const sharpCorners: Curve[] = [];
33
- const dullCorners: Curve[] = [];
16
+ /**
17
+ * @internal
18
+ * Resets the generated debug `_debug_.elems` (if debug is enabled) so that
19
+ * they only reflect the current `findMats` call.
20
+ */
21
+ function resetDebugElems() {
22
+ if (typeof _debug_ === 'undefined') { return; }
23
+
24
+ _debug_.elems = { ..._debug_.elems, ...createEmptyElems() };
25
+ }
26
+
27
+
28
+ /**
29
+ * @internal
30
+ * Adds (if debug is enabled) the loose and tight bounding boxes, the bounding
31
+ * hulls and the sharp and dull corners of the given loops' curves to
32
+ * `_debug_.elems` for later inspection by consumers.
33
+ */
34
+ function addDebugElems(loops: Loop[]) {
35
+ if (typeof _debug_ === 'undefined') { return; }
36
+
37
+ const {
38
+ looseBoundingBoxes, tightBoundingBoxes, boundingHulls,
39
+ sharpCorners, dullCorners
40
+ } = _debug_.elems;
34
41
 
35
42
  for (const loop of loops) {
36
43
  for (const curve of loop.curves) {
37
44
  const ps = curve.ps;
38
- const hull = getBoundingHull(ps, true)!;
39
-
40
- boundingHulls.push(hull);
41
45
 
42
- const looseBoundingBox = getBoundingBox$(ps);
43
- looseBoundingBoxes.push(looseBoundingBox);
46
+ boundingHulls.push(getBoundingHull(ps, true)!);
47
+ looseBoundingBoxes.push(getBoundingBox$(ps));
48
+ tightBoundingBoxes.push(getBoundingBoxTight$(ps));
44
49
 
45
- const tightBoundingBox = getBoundingBoxTight(ps);
46
- tightBoundingBoxes.push(tightBoundingBox);
47
-
48
- const corner = getCorner(curve.ps, curve.next.ps);
50
+ const corner = getCorner(ps, curve.next.ps);
49
51
  if (corner.isQuiteSharp) {
50
52
  sharpCorners.push(curve);
51
53
  } else if (corner.isQuiteDull) {
@@ -53,14 +55,6 @@ function getPartialMeta(
53
55
  }
54
56
  }
55
57
  }
56
-
57
- return {
58
- looseBoundingBoxes,
59
- tightBoundingBoxes,
60
- boundingHulls,
61
- sharpCorners,
62
- dullCorners
63
- }
64
58
  }
65
59
 
66
60
 
@@ -102,7 +96,8 @@ function addDebugInfo4() {
102
96
 
103
97
 
104
98
  export {
105
- getPartialMeta,
99
+ resetDebugElems,
100
+ addDebugElems,
106
101
  addDebugInfo1,
107
102
  addDebugInfo2,
108
103
  addDebugInfo3,
@@ -2,7 +2,7 @@ import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
2
2
  import type { Loop } from 'flo-boolean';
3
3
  import { controlPointLinesLength } from 'flo-bezier3';
4
4
  import { toP } from '../point-on-shape/to-p.js';
5
- import { getCorner } from '../corner/get-corner.js';
5
+ import { getCorner$ } from '../corner/get-corner.js';
6
6
 
7
7
 
8
8
  /** @internal */
@@ -19,7 +19,7 @@ function getSharpCornersOnLoop(
19
19
  continue;
20
20
  }
21
21
 
22
- if (getCorner(curve.ps, curve.next.ps).isQuiteSharp) {
22
+ if (getCorner$(curve.ps, curve.next.ps).isQuiteSharp) {
23
23
  const { ps } = curve;
24
24
 
25
25
  const p = ps[ps.length - 1];
@@ -59,7 +59,7 @@ interface MatOptions {
59
59
  *
60
60
  * * Only applies if `simplify` is `true`
61
61
  * * Defaults to `1/16`
62
- * * The value is clipped in `[2**-10,1024]`
62
+ * * The value is clipped in `[2**-20,2**20]`
63
63
  * * scaled to a 1024x1024 vector image size, i.e. a value of `1` on such
64
64
  * a vector image will have a `1` pixel accuracy. If the vector is, say,
65
65
  * 512x400 then the accuracy is scaled to `1/2` a pixel. This ensures
@@ -72,7 +72,7 @@ interface MatOptions {
72
72
  *
73
73
  * * it is not recommended to change this value
74
74
  * * scaled to a 1024x1024 vector image size
75
- * * Defaults to `1/16`
75
+ * * Defaults to `1/64`
76
76
  */
77
77
  readonly minBezLength?: number;
78
78
 
@@ -1,59 +1,66 @@
1
1
  import type { CpNode } from "../cp-node/cp-node.js";
2
- import { getAllOnCircle } from "../cp-node/fs/get-all-on-circle.js";
2
+ import type { Circle } from "../geometry/circle.js";
3
3
  import { getMatDistanceToNext$ } from "../cp-node/fs/get-distance-to-next.js";
4
- import { isOnSameCircle } from "../cp-node/fs/is-on-same-circle.js";
5
4
  import { isVertexSpecial } from "../cp-node/fs/is-vertex-special.js";
6
- import { getHoleCloserPairs } from "./get-hole-closer-pairs.js";
7
5
 
8
6
 
7
+ /**
8
+ * Returns the adjacency matrix (MAT edge lengths, `Infinity` if not adjacent)
9
+ * of the given special vertices (leaves, 3-prongs, ...) seen as the vertices of
10
+ * a graph with the MAT branches between them as edges.
11
+ *
12
+ * * for each vertex every MAT edge leaving it is walked once, up to the next
13
+ * special vertex; if that vertex is one of the given ones the walked length
14
+ * is its distance (the minimum over all such walks if there are several)
15
+ *
16
+ * @param specialVertices the special `CpNode`s (one per vertex)
17
+ */
9
18
  function getGraph(
10
- specialVertices: CpNode[],
11
- holeClosers: CpNode[]) {
12
-
13
- const pairs = getHoleCloserPairs(holeClosers);
19
+ specialVertices: CpNode[]) {
14
20
 
15
21
  const V = specialVertices.length;
16
22
 
23
+ // the column of each given vertex, identified by its circle (all `CpNode`s
24
+ // on a vertex share the same `Circle` object)
25
+ const columnOf = new Map<Circle, number>(
26
+ specialVertices.map((cpNode, j) => [cpNode.pointOnShape.circle, j])
27
+ );
28
+
17
29
  const graph: number[][] = [];
18
30
  for (let i=0; i<V; i++) {
19
31
  const cpNodeA = specialVertices[i];
20
32
 
21
- const row: number[] = [];
22
- for (let j=0; j<V; j++) {
23
- const cpNodeB = specialVertices[j];
24
- if (i === j) {
25
- row.push(0);
26
- continue;
27
- }
28
-
29
- let minD = Infinity;
30
- for (const toChild of getAllOnCircle(cpNodeA)) {
31
- let d = getMatDistanceToNext$(toChild);
32
- let child = toChild.next;
33
- while (true) {
34
- if (isOnSameCircle(child, cpNodeB)) {
35
- break; // Found path from A to B
36
- }
37
- if (child.isHoleClosing) {
38
- // Hole closer found - don't go around loop
39
- child = getHoleCloserNext(pairs, child);
40
- continue;
41
- }
42
- if (isVertexSpecial(child)) {
43
- // we only find the immediate next special ones
44
- d = Infinity;
45
- break; // Next special vertex found but it's not B
46
- }
47
-
48
- d += getMatDistanceToNext$(child);
49
- child = child.next;
33
+ const row: number[] = new Array(V).fill(Infinity);
34
+ row[i] = 0;
35
+
36
+ // walk each edge leaving the vertex up to the next special vertex
37
+ let toChild = cpNodeA;
38
+ do {
39
+ let d = getMatDistanceToNext$(toChild);
40
+ let child = toChild.next;
41
+ while (true) {
42
+ const j = columnOf.get(child.pointOnShape.circle);
43
+ if (j !== undefined) {
44
+ // Found a path from A to one of the given vertices
45
+ if (j !== i && d < row[j]) { row[j] = d; }
46
+ break;
47
+ }
48
+ if (child.isHoleClosing) {
49
+ // Hole closer found - skip it (don't go around loop)
50
+ child = child.holeCloserTwin!.next;
51
+ continue;
52
+ }
53
+ if (isVertexSpecial(child)) {
54
+ // we only find the immediate next special ones
55
+ break; // Next special vertex found but it's not a given one
50
56
  }
51
57
 
52
- if (d < minD) { minD = d; }
58
+ d += getMatDistanceToNext$(child);
59
+ child = child.next;
53
60
  }
54
61
 
55
- row.push(minD);
56
- }
62
+ toChild = toChild.nextOnCircle;
63
+ } while (toChild !== cpNodeA);
57
64
 
58
65
  graph.push(row);
59
66
  }
@@ -62,12 +69,4 @@ function getGraph(
62
69
  }
63
70
 
64
71
 
65
- function getHoleCloserNext(
66
- pairs: Map<CpNode,CpNode>,
67
- holeCloser: CpNode) {
68
-
69
- return pairs.get(holeCloser)!.next;
70
- }
71
-
72
-
73
72
  export { getGraph }
@@ -1,8 +1,11 @@
1
- import { getBoundingBox } from "flo-bezier3";
1
+ import { getBoundingBox, getBoundingBoxTight } from "flo-bezier3";
2
2
  import { memoize } from "flo-memoize";
3
3
 
4
4
 
5
+ /** The (loose, axis-aligned) bounding box of a bezier curve - memoized on its control points. */
5
6
  const getBoundingBox$ = memoize(getBoundingBox);
7
+ /** The tight (rotated) bounding box of a bezier curve - memoized on its control points. */
8
+ const getBoundingBoxTight$ = memoize(getBoundingBoxTight);
6
9
 
7
10
 
8
- export { getBoundingBox$ }
11
+ export { getBoundingBox$, getBoundingBoxTight$ }
@@ -1,7 +1,7 @@
1
- import { squaredDistanceBetween } from 'flo-vector2d';
2
-
3
-
4
1
  /**
2
+ * Returns the closest squared distance from the point `p` to the given
3
+ * axis-aligned box `[[minX, minY], [maxX, maxY]]`, i.e. `0` if `p` is inside.
4
+ *
5
5
  * @internal
6
6
  */
7
7
  function getClosestSquareDistanceToRect(
@@ -18,17 +18,17 @@ function getClosestSquareDistanceToRect(
18
18
 
19
19
  if (xp < x0) {
20
20
  if (yp < y0) {
21
- return squaredDistanceBetween(box[0], p);
21
+ return (x0 - xp)**2 + (y0 - yp)**2;
22
22
  } else if (yp > y1) {
23
- return squaredDistanceBetween([x0,y1], p);
23
+ return (x0 - xp)**2 + (yp - y1)**2;
24
24
  } else {
25
25
  return (x0 - xp)**2;
26
26
  }
27
27
  } else if (xp > x1) {
28
28
  if (yp < y0) {
29
- return squaredDistanceBetween([x1,y0], p);
29
+ return (xp - x1)**2 + (y0 - yp)**2;
30
30
  } else if (yp > y1) {
31
- return squaredDistanceBetween(box[1], p);
31
+ return (xp - x1)**2 + (yp - y1)**2;
32
32
  } else {
33
33
  return (xp - x1)**2;
34
34
  }
@@ -4,26 +4,28 @@ const { min } = Math;
4
4
 
5
5
 
6
6
  /**
7
+ * Returns the closest squared distance from the point `p` to the given
8
+ * (rotated) rectangle given by its 4 corners in order, i.e. `0` if `p` is
9
+ * inside the rectangle.
10
+ *
7
11
  * @internal
8
12
  */
9
13
  function getClosestSquaredDistanceToRotatedRect(ps: number[][], p: number[]) {
10
- const ds = [0,1,2,3]
11
- .map(i => squaredDistanceBetweenPointAndLineSegment(
12
- p,
13
- [ps[i], ps[(i + 1) % 4]]
14
- )
15
- );
16
-
14
+ const d0 = squaredDistanceBetweenPointAndLineSegment(p, [ps[0], ps[1]]);
15
+ const d1 = squaredDistanceBetweenPointAndLineSegment(p, [ps[1], ps[2]]);
16
+ const d2 = squaredDistanceBetweenPointAndLineSegment(p, [ps[2], ps[3]]);
17
+ const d3 = squaredDistanceBetweenPointAndLineSegment(p, [ps[3], ps[0]]);
18
+
17
19
  const width = squaredDistanceBetween(ps[0], ps[1]);
18
20
  const height = squaredDistanceBetween(ps[0], ps[3]);
19
21
 
20
- if (ds[0] <= height && ds[2] <= height &&
21
- ds[1] <= width && ds[3] <= width) {
22
+ if (d0 <= height && d2 <= height &&
23
+ d1 <= width && d3 <= width) {
22
24
 
23
25
  return 0; // Inside rotated rect
24
26
  }
25
27
 
26
- return min(...ds);
28
+ return min(d0, d1, d2, d3);
27
29
  }
28
30
 
29
31
 
@@ -1,7 +1,6 @@
1
1
  import { toPowerBasisDd } from 'flo-bezier3';
2
- import { twoDiff, ddMultDouble2, ddAddDd, ddMultDd, ddNegativeOf, ddMultByNeg2, ddMultBy2, ddDiffDouble } from 'double-double';
2
+ import { ddMultDouble2, ddAddDd, ddMultDd, ddNegativeOf, ddMultByNeg2, ddMultBy2, ddDiffDouble } from 'double-double';
3
3
 
4
- const td = twoDiff;
5
4
  const qmd = ddMultDouble2;
6
5
  const qaq = ddAddDd;
7
6
  const qmq = ddMultDd;