flo-mat 4.0.2 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/__tests__/find-2-prong/get-medial/dd-get-medial-point-coeffs-same-curve.spec.ts +106 -0
  2. package/__tests__/find-2-prong/get-medial/dd-get-medial-point-coeffs.spec.ts +73 -0
  3. package/__tests__/find-2-prong/get-medial/get-closest-points.spec.ts +5 -2
  4. package/__tests__/helpers/close-to.ts +5 -5
  5. package/__tests__/specific-cases/load-svg/load-svg.ts +30 -0
  6. package/__tests__/specific-cases/specific-cases.spec.ts +170 -0
  7. package/__tests__/specific-cases/test-svgs/achispado.svg +5052 -0
  8. package/browser/index.js +5129 -8785
  9. package/browser/index.min.js +1 -1
  10. package/{jest.config.cjs → jest.config.ts} +8 -3
  11. package/node/closest-boundary-point/get-close-boundary-points-certified.js +3 -2
  12. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  13. package/node/corner/get-corner.js +1 -1
  14. package/node/corner/get-corner.js.map +1 -1
  15. package/node/cp-node/fs/get-all-on-loop-by-loop.d.ts +11 -0
  16. package/node/cp-node/fs/get-all-on-loop-by-loop.js +42 -0
  17. package/node/cp-node/fs/get-all-on-loop-by-loop.js.map +1 -0
  18. package/node/cp-node/fs/get-boundary-beziers-to-next.d.ts +1 -0
  19. package/node/cp-node/fs/get-boundary-beziers-to-next.js +1 -59
  20. package/node/cp-node/fs/get-boundary-beziers-to-next.js.map +1 -1
  21. package/node/cp-node/fs/get-edge-direction.d.ts +3 -1
  22. package/node/cp-node/fs/get-edge-direction.js +5 -3
  23. package/node/cp-node/fs/get-edge-direction.js.map +1 -1
  24. package/node/cp-node/fs/get-mat-curve-between.js +6 -6
  25. package/node/cp-node/fs/get-mat-curve-between.js.map +1 -1
  26. package/node/cp-node/fs/is-fully-terminating.js +12 -0
  27. package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
  28. package/node/cp-node/fs/is-on-same-loop.d.ts +3 -0
  29. package/node/cp-node/fs/is-on-same-loop.js +6 -0
  30. package/node/cp-node/fs/is-on-same-loop.js.map +1 -0
  31. package/node/debug/debug.d.ts +8 -22
  32. package/node/debug/debug.js +12 -50
  33. package/node/debug/debug.js.map +1 -1
  34. package/node/find-2-prong/add-1-prong.js +1 -4
  35. package/node/find-2-prong/add-1-prong.js.map +1 -1
  36. package/node/find-2-prong/find-2-prong.js +24 -10
  37. package/node/find-2-prong/find-2-prong.js.map +1 -1
  38. package/node/find-2-prong/get-medial/get-antipodal-points.d.ts +1 -1
  39. package/node/find-2-prong/get-medial/get-antipodal-points.js +2 -2
  40. package/node/find-2-prong/get-medial/get-antipodal-points.js.map +1 -1
  41. package/node/find-2-prong/get-medial/get-closest-points.d.ts +7 -1
  42. package/node/find-2-prong/get-medial/get-closest-points.js +60 -14
  43. package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -1
  44. package/node/find-2-prong/reduce-radius.d.ts +3 -1
  45. package/node/find-2-prong/reduce-radius.js +8 -6
  46. package/node/find-2-prong/reduce-radius.js.map +1 -1
  47. package/node/find-3-prong/calc-better-x.js +1 -3
  48. package/node/find-3-prong/calc-better-x.js.map +1 -1
  49. package/node/find-3-prong/calc-initial-3-prong-center.js +1 -2
  50. package/node/find-3-prong/calc-initial-3-prong-center.js.map +1 -1
  51. package/node/find-3-prong/find-3-prong-for-delta3s.js +1 -4
  52. package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
  53. package/node/find-3-prong/find-3-prong.js.map +1 -1
  54. package/node/find-3-prong/find-and-add-3-prong.js +0 -14
  55. package/node/find-3-prong/find-and-add-3-prong.js.map +1 -1
  56. package/node/find-mat/find-mat.js +2 -2
  57. package/node/find-mat/find-mat.js.map +1 -1
  58. package/node/find-mat/find-mats.js.map +1 -1
  59. package/node/find-mat/get-dull-corners-on-loop.js +3 -2
  60. package/node/find-mat/get-dull-corners-on-loop.js.map +1 -1
  61. package/node/find-mat/get-for-1-prongs-on-loop.js +6 -3
  62. package/node/find-mat/get-for-1-prongs-on-loop.js.map +1 -1
  63. package/node/find-mat/get-for-2-prongs-on-loop.js +5 -1
  64. package/node/find-mat/get-for-2-prongs-on-loop.js.map +1 -1
  65. package/node/find-mat/get-meta.d.ts +4 -6
  66. package/node/find-mat/get-meta.js +12 -26
  67. package/node/find-mat/get-meta.js.map +1 -1
  68. package/node/find-mat/get-sharp-corners.js +4 -2
  69. package/node/find-mat/get-sharp-corners.js.map +1 -1
  70. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.d.ts +21 -0
  71. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.js +46 -0
  72. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.js.map +1 -0
  73. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.d.ts +28 -0
  74. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.js +97 -0
  75. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.js.map +1 -0
  76. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.d.ts +28 -0
  77. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.js +109 -0
  78. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.js.map +1 -0
  79. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.d.ts +29 -0
  80. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.js +123 -0
  81. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.js.map +1 -0
  82. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.d.ts +30 -0
  83. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.js +177 -0
  84. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.js.map +1 -0
  85. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.d.ts +29 -0
  86. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js +156 -0
  87. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js.map +1 -0
  88. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.d.ts +28 -0
  89. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.js +40 -0
  90. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.js.map +1 -0
  91. package/node/index.d.ts +6 -10
  92. package/node/index.js +5 -6
  93. package/node/index.js.map +1 -1
  94. package/node/point-on-shape/point-on-shape.d.ts +2 -0
  95. package/node/point-on-shape/to-p.d.ts +1 -1
  96. package/node/point-on-shape/to-p.js +1 -1
  97. package/node/point-on-shape/to-p.js.map +1 -1
  98. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.d.ts +4 -0
  99. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js +15 -0
  100. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js.map +1 -0
  101. package/node/reconstruct-from-mat/reconstruct-from-mat.d.ts +10 -0
  102. package/node/reconstruct-from-mat/reconstruct-from-mat.js +160 -0
  103. package/node/reconstruct-from-mat/reconstruct-from-mat.js.map +1 -0
  104. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.d.ts +12 -0
  105. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js +46 -0
  106. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js.map +1 -0
  107. package/node/sat/add-debug-info.js +1 -2
  108. package/node/sat/add-debug-info.js.map +1 -1
  109. package/node/svg/get-loop-bounds.js +6 -2
  110. package/node/svg/get-loop-bounds.js.map +1 -1
  111. package/node/utils/map-deep.d.ts +15 -0
  112. package/node/utils/map-deep.js +34 -0
  113. package/node/utils/map-deep.js.map +1 -0
  114. package/package.json +14 -8
  115. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +3 -2
  116. package/src/corner/get-corner.ts +1 -1
  117. package/src/cp-node/fs/get-all-on-loop-by-loop.ts +56 -0
  118. package/src/cp-node/fs/get-all-on-loop.ts +1 -1
  119. package/src/cp-node/fs/get-boundary-beziers-to-next.ts +1 -72
  120. package/src/cp-node/fs/get-edge-direction.ts +8 -4
  121. package/src/cp-node/fs/get-mat-curve-between.ts +6 -6
  122. package/src/cp-node/fs/is-fully-terminating.ts +16 -0
  123. package/src/cp-node/fs/is-on-same-loop.ts +15 -0
  124. package/src/debug/debug.ts +27 -87
  125. package/src/find-2-prong/add-1-prong.ts +1 -5
  126. package/src/find-2-prong/find-2-prong.ts +37 -14
  127. package/src/find-2-prong/get-medial/get-antipodal-points.ts +3 -2
  128. package/src/find-2-prong/get-medial/get-closest-points-d.ts +213 -0
  129. package/src/find-2-prong/get-medial/get-closest-points.ts +74 -13
  130. package/src/find-2-prong/reduce-radius.ts +8 -5
  131. package/src/find-3-prong/calc-better-x.ts +1 -3
  132. package/src/find-3-prong/calc-initial-3-prong-center.ts +1 -2
  133. package/src/find-3-prong/find-3-prong-for-delta3s.ts +1 -4
  134. package/src/find-3-prong/find-3-prong.ts +0 -1
  135. package/src/find-3-prong/find-and-add-3-prong.ts +1 -15
  136. package/src/find-mat/find-mat.ts +3 -2
  137. package/src/find-mat/find-mats.ts +0 -1
  138. package/src/find-mat/get-dull-corners-on-loop.ts +4 -3
  139. package/src/find-mat/get-for-1-prongs-on-loop.ts +8 -3
  140. package/src/find-mat/get-for-2-prongs-on-loop.ts +6 -1
  141. package/src/find-mat/get-meta.ts +14 -38
  142. package/src/find-mat/get-sharp-corners.ts +5 -1
  143. package/src/get-medial-curve/__pycache__/get-cubic-self-medial-curve.cpython-313.pyc +0 -0
  144. package/src/get-medial-curve/get-cubic-self-medial-curve.py +419 -0
  145. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0-with-running-err.ts +76 -0
  146. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.ts +61 -0
  147. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.ts +116 -0
  148. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.ts +129 -0
  149. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.ts +142 -0
  150. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.ts +199 -0
  151. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.ts +177 -0
  152. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs.ts +48 -0
  153. package/src/get-medial-points/double-double/error-bound-calc.txt +72 -0
  154. package/src/index.ts +7 -11
  155. package/src/point-on-shape/point-on-shape.ts +3 -0
  156. package/src/point-on-shape/to-p.ts +2 -2
  157. package/src/reconstruct-from-mat/get-cp-nodess-for-sat.ts +24 -0
  158. package/src/reconstruct-from-mat/reconstruct-from-mat.ts +226 -0
  159. package/src/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.ts +62 -0
  160. package/src/sat/add-debug-info.ts +1 -2
  161. package/src/svg/get-loop-bounds.ts +11 -3
  162. package/src/utils/clip.ts +13 -0
  163. package/src/utils/map-deep.ts +75 -0
  164. package/src/utils/map-map.ts +33 -0
  165. package/wallaby.mjs +4 -4
  166. package/node/debug/debug-elem-types.d.ts +0 -26
  167. package/node/debug/debug-elem-types.js +0 -22
  168. package/node/debug/debug-elem-types.js.map +0 -1
  169. package/node/debug/functions/draw/draw-beziers-as-single-path.d.ts +0 -2
  170. package/node/debug/functions/draw/draw-beziers-as-single-path.js +0 -30
  171. package/node/debug/functions/draw/draw-beziers-as-single-path.js.map +0 -1
  172. package/node/debug/functions/draw/xmlns.d.ts +0 -2
  173. package/node/debug/functions/draw/xmlns.js +0 -3
  174. package/node/debug/functions/draw/xmlns.js.map +0 -1
  175. package/node/debug/functions/draw-elem/bounding-hull.d.ts +0 -3
  176. package/node/debug/functions/draw-elem/bounding-hull.js +0 -8
  177. package/node/debug/functions/draw-elem/bounding-hull.js.map +0 -1
  178. package/node/debug/functions/draw-elem/draw-branch.d.ts +0 -4
  179. package/node/debug/functions/draw-elem/draw-branch.js +0 -26
  180. package/node/debug/functions/draw-elem/draw-branch.js.map +0 -1
  181. package/node/debug/functions/draw-elem/draw-circle-percent.d.ts +0 -3
  182. package/node/debug/functions/draw-elem/draw-circle-percent.js +0 -13
  183. package/node/debug/functions/draw-elem/draw-circle-percent.js.map +0 -1
  184. package/node/debug/functions/draw-elem/draw-cp-node.d.ts +0 -4
  185. package/node/debug/functions/draw-elem/draw-cp-node.js +0 -26
  186. package/node/debug/functions/draw-elem/draw-cp-node.js.map +0 -1
  187. package/node/debug/functions/draw-elem/draw-cull.d.ts +0 -3
  188. package/node/debug/functions/draw-elem/draw-cull.js +0 -9
  189. package/node/debug/functions/draw-elem/draw-cull.js.map +0 -1
  190. package/node/debug/functions/draw-elem/draw-dull-corner.d.ts +0 -4
  191. package/node/debug/functions/draw-elem/draw-dull-corner.js +0 -10
  192. package/node/debug/functions/draw-elem/draw-dull-corner.js.map +0 -1
  193. package/node/debug/functions/draw-elem/draw-elem.d.ts +0 -10
  194. package/node/debug/functions/draw-elem/draw-elem.js +0 -39
  195. package/node/debug/functions/draw-elem/draw-elem.js.map +0 -1
  196. package/node/debug/functions/draw-elem/draw-leaves.d.ts +0 -4
  197. package/node/debug/functions/draw-elem/draw-leaves.js +0 -34
  198. package/node/debug/functions/draw-elem/draw-leaves.js.map +0 -1
  199. package/node/debug/functions/draw-elem/draw-loop.d.ts +0 -4
  200. package/node/debug/functions/draw-elem/draw-loop.js +0 -11
  201. package/node/debug/functions/draw-elem/draw-loop.js.map +0 -1
  202. package/node/debug/functions/draw-elem/draw-loops.d.ts +0 -4
  203. package/node/debug/functions/draw-elem/draw-loops.js +0 -6
  204. package/node/debug/functions/draw-elem/draw-loops.js.map +0 -1
  205. package/node/debug/functions/draw-elem/draw-loose-bounding-box.d.ts +0 -3
  206. package/node/debug/functions/draw-elem/draw-loose-bounding-box.js +0 -10
  207. package/node/debug/functions/draw-elem/draw-loose-bounding-box.js.map +0 -1
  208. package/node/debug/functions/draw-elem/draw-mat.d.ts +0 -4
  209. package/node/debug/functions/draw-elem/draw-mat.js +0 -34
  210. package/node/debug/functions/draw-elem/draw-mat.js.map +0 -1
  211. package/node/debug/functions/draw-elem/draw-max-vertex.d.ts +0 -4
  212. package/node/debug/functions/draw-elem/draw-max-vertex.js +0 -9
  213. package/node/debug/functions/draw-elem/draw-max-vertex.js.map +0 -1
  214. package/node/debug/functions/draw-elem/draw-min-y.d.ts +0 -4
  215. package/node/debug/functions/draw-elem/draw-min-y.js +0 -10
  216. package/node/debug/functions/draw-elem/draw-min-y.js.map +0 -1
  217. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.d.ts +0 -4
  218. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js +0 -22
  219. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js.map +0 -1
  220. package/node/debug/functions/draw-elem/draw-one-prong.d.ts +0 -4
  221. package/node/debug/functions/draw-elem/draw-one-prong.js +0 -13
  222. package/node/debug/functions/draw-elem/draw-one-prong.js.map +0 -1
  223. package/node/debug/functions/draw-elem/draw-sharp-corner.d.ts +0 -4
  224. package/node/debug/functions/draw-elem/draw-sharp-corner.js +0 -10
  225. package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +0 -1
  226. package/node/debug/functions/draw-elem/draw-three-prong.d.ts +0 -4
  227. package/node/debug/functions/draw-elem/draw-three-prong.js +0 -26
  228. package/node/debug/functions/draw-elem/draw-three-prong.js.map +0 -1
  229. package/node/debug/functions/draw-elem/draw-tight-bounding-box.d.ts +0 -3
  230. package/node/debug/functions/draw-elem/draw-tight-bounding-box.js +0 -8
  231. package/node/debug/functions/draw-elem/draw-tight-bounding-box.js.map +0 -1
  232. package/node/debug/functions/draw-elem/draw-two-prong.d.ts +0 -4
  233. package/node/debug/functions/draw-elem/draw-two-prong.js +0 -49
  234. package/node/debug/functions/draw-elem/draw-two-prong.js.map +0 -1
  235. package/node/debug/functions/draw-elem/draw-vertex.d.ts +0 -4
  236. package/node/debug/functions/draw-elem/draw-vertex.js +0 -13
  237. package/node/debug/functions/draw-elem/draw-vertex.js.map +0 -1
  238. package/node/debug/functions/general.d.ts +0 -48
  239. package/node/debug/functions/general.js +0 -53
  240. package/node/debug/functions/general.js.map +0 -1
  241. package/node/find-3-prong/timed-cc.d.ts +0 -3
  242. package/node/find-3-prong/timed-cc.js +0 -5
  243. package/node/find-3-prong/timed-cc.js.map +0 -1
  244. package/node/point-on-shape/pos-to-human-string.d.ts +0 -8
  245. package/node/point-on-shape/pos-to-human-string.js +0 -12
  246. package/node/point-on-shape/pos-to-human-string.js.map +0 -1
  247. package/node/utils/time-function-call.d.ts +0 -14
  248. package/node/utils/time-function-call.js +0 -32
  249. package/node/utils/time-function-call.js.map +0 -1
  250. package/src/debug/debug-elem-types.ts +0 -43
  251. package/src/debug/elem-type-two-prong.ts +0 -8
  252. package/src/debug/functions/cmp-cp-on-delta.ts +0 -54
  253. package/src/debug/functions/draw-elem/bounding-hull.ts +0 -18
  254. package/src/debug/functions/draw-elem/culls.ts +0 -39
  255. package/src/debug/functions/draw-elem/draw-branch.ts +0 -37
  256. package/src/debug/functions/draw-elem/draw-circle-percent.ts +0 -23
  257. package/src/debug/functions/draw-elem/draw-cp-node.ts +0 -46
  258. package/src/debug/functions/draw-elem/draw-cull.ts +0 -21
  259. package/src/debug/functions/draw-elem/draw-dull-corner.ts +0 -21
  260. package/src/debug/functions/draw-elem/draw-elem.ts +0 -64
  261. package/src/debug/functions/draw-elem/draw-leaves.ts +0 -51
  262. package/src/debug/functions/draw-elem/draw-loop.ts +0 -16
  263. package/src/debug/functions/draw-elem/draw-loops.ts +0 -10
  264. package/src/debug/functions/draw-elem/draw-loose-bounding-box.ts +0 -21
  265. package/src/debug/functions/draw-elem/draw-mat.ts +0 -43
  266. package/src/debug/functions/draw-elem/draw-max-vertex.ts +0 -15
  267. package/src/debug/functions/draw-elem/draw-min-y.ts +0 -18
  268. package/src/debug/functions/draw-elem/draw-one-prong-at-dull-corner.ts +0 -40
  269. package/src/debug/functions/draw-elem/draw-one-prong.ts +0 -25
  270. package/src/debug/functions/draw-elem/draw-sharp-corner.ts +0 -21
  271. package/src/debug/functions/draw-elem/draw-three-prong.ts +0 -44
  272. package/src/debug/functions/draw-elem/draw-tight-bounding-box.ts +0 -18
  273. package/src/debug/functions/draw-elem/draw-two-prong.ts +0 -68
  274. package/src/debug/functions/draw-elem/draw-vertex.ts +0 -27
  275. package/src/debug/functions/draw-elem/dull-corner.ts +0 -21
  276. package/src/debug/functions/draw-elem/leaves.ts +0 -20
  277. package/src/debug/functions/draw-elem/loop.ts +0 -16
  278. package/src/debug/functions/draw-elem/loops.ts +0 -10
  279. package/src/debug/functions/draw-elem/loose-bounding-box.ts +0 -21
  280. package/src/debug/functions/draw-elem/mat.ts +0 -47
  281. package/src/debug/functions/draw-elem/max-vertex.ts +0 -15
  282. package/src/debug/functions/draw-elem/min-y.ts +0 -18
  283. package/src/debug/functions/draw-elem/one-prong-at-dull-corner.ts +0 -26
  284. package/src/debug/functions/draw-elem/one-prong.ts +0 -23
  285. package/src/debug/functions/draw-elem/sharp-corner.ts +0 -20
  286. package/src/debug/functions/draw-elem/three-prong.ts +0 -30
  287. package/src/debug/functions/draw-elem/tight-bounding-box.ts +0 -18
  288. package/src/debug/functions/draw-elem/two-prong.ts +0 -50
  289. package/src/debug/functions/draw-elem/vertex.ts +0 -51
  290. package/src/debug/functions/general.ts +0 -79
  291. package/src/debug/functions/three-prong.ts +0 -249
  292. package/src/debug/functions/two-prong.ts +0 -203
  293. package/src/find-2-prong/add-debug-info.ts +0 -45
  294. package/src/find-3-prong/timed-cc.ts +0 -9
@@ -2,12 +2,19 @@ import type { RootInterval } from 'flo-poly';
2
2
  import type { CurvePiece } from "../../mat/curve-piece.js";
3
3
  import type { PrePointOnShape } from "../../point-on-shape/point-on-shape.js";
4
4
  import type { AntipodalPoint } from './antipodal-point.js';
5
+ import { ddMultDouble1 } from 'double-double';
5
6
  import { lengthSquared } from "flo-vector2d";
6
- import { roots, deflate, Horner } from 'flo-poly';
7
- import { evalDeCasteljau, getMedialPointCoeffs, getMedialPointCoeffsBez0, getMedialPointCoeffsBez2_SameCurve, getMedialPointCoeffsBez3_SameCurve } from 'flo-bezier3';
7
+ import { roots, Horner, ddHorner } from 'flo-poly';
8
+ import { evalDeCasteljau, getMedialPointCoeffs, getMedialPointCoeffsBez0 } from 'flo-bezier3';
9
+ import { ddGetMedialPointCoeffs } from '../../get-medial-points/double-double/dd-get-medial-point-coeffs.js';
10
+ import { ddGetMedialPointCoeffsBez2_SameCurve } from '../../get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.js';
11
+ import { ddGetMedialPointCoeffsBez3_SameCurve } from '../../get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.js';
12
+ import { ddGetMedialPointCoeffsBez0 } from '../../get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.js';
8
13
 
9
14
  const { sqrt, abs, max } = Math;
10
15
 
16
+ const qmd = ddMultDouble1;
17
+
11
18
 
12
19
  /**
13
20
  * @param maxCoordPowerOf2
@@ -22,6 +29,7 @@ const { sqrt, abs, max } = Math;
22
29
  function getClosestPoint(
23
30
  maxCoordPowerOf2: number,
24
31
  nnorm: number[],
32
+ nnormDd: number[][],
25
33
  yPos: PrePointOnShape,
26
34
  for1Prong: boolean,
27
35
  angle: number,
@@ -29,7 +37,7 @@ function getClosestPoint(
29
37
 
30
38
  const { curve, ts: [tS,tE] } = curvePiece;
31
39
  const { ps } = curve;
32
- const { curve: touchedCurve, t, p: y } = yPos;
40
+ const { curve: touchedCurve, t, p: y, pDd: yDd } = yPos;
33
41
 
34
42
  const isTouched = curve === touchedCurve;
35
43
  const shouldDeflate = angle === 0 && isTouched;
@@ -42,11 +50,14 @@ function getClosestPoint(
42
50
  if (tS !== tE &&
43
51
  !(shouldDeflate && ps.length === 2) &&
44
52
  !(isTouched && ps.length === 3 && for1Prong)) {
53
+
45
54
  const { A, B, H } = shouldDeflate
46
55
  ? ps.length === 3
47
- ? getMedialPointCoeffsBez2_SameCurve(t,nnorm,ps)
48
- : getMedialPointCoeffsBez3_SameCurve(t,nnorm,ps)
49
- : getMedialPointCoeffs(y, nnorm, ps);
56
+ ? ddGetMedialPointCoeffsBez2_SameCurve(t, nnormDd, ps)
57
+ : ddGetMedialPointCoeffsBez3_SameCurve(t, nnormDd, ps)
58
+ : ddGetMedialPointCoeffs(yDd, nnormDd, ps);
59
+
60
+ // const Hd = H.map(h => h[0] + h[1]);
50
61
 
51
62
  ss = roots(H, tS, tE) || [];
52
63
  //-----------------------
@@ -65,8 +76,14 @@ function getClosestPoint(
65
76
  const s = sE > 1 ? 1 : _s;
66
77
 
67
78
  //-----------------------
68
- const AS = Horner(A, s);
69
- const BS = Horner(B, s);
79
+ // const AS = Horner(A, s);
80
+ // const BS = Horner(B, s);
81
+
82
+ const ASDd = ddHorner(A, s);
83
+ const BSDd = ddHorner(B, s);
84
+ const AS = ASDd[0] + ASDd[1];
85
+ const BS = BSDd[0] + BSDd[1];
86
+
70
87
  // const CS = Horner(C, s);
71
88
  // const DS = Horner(D, s);
72
89
 
@@ -86,7 +103,8 @@ function getClosestPoint(
86
103
  continue;
87
104
  }
88
105
 
89
- const V = [w*nnorm[0], w*nnorm[1]];
106
+ const VDd = [qmd(w, nnormDd[0]), qmd(w, nnormDd[1])];
107
+ const V = [VDd[0][1], VDd[1][1]];
90
108
  const d = sqrt(lengthSquared(V));
91
109
 
92
110
  if (d <= 2**(maxCoordPowerOf2 - 40)) {
@@ -174,20 +192,21 @@ function getClosestPoint(
174
192
  for (let i=0; i<PS.length; i++) {
175
193
  //-----------------------
176
194
  const { P, t: s } = PS[i];
177
- const { a0, b0 } = getMedialPointCoeffsBez0(y,nnorm,P);
195
+ const { a0, b0 } = ddGetMedialPointCoeffsBez0(yDd, nnormDd, P);
178
196
 
179
- if (abs(a0) <= 2**-40 || abs(b0) <= 2**-40) {
197
+ if (abs(a0[1]) <= 2**-40 || abs(b0[1]) <= 2**-40) {
180
198
  continue;
181
199
  }
182
200
 
183
- const w = -b0 / a0;
201
+ const w = -b0[1] / a0[1];
184
202
 
185
203
  // too close to point of origin *or* negative;
186
204
  if (w < 2**-40) {
187
205
  continue;
188
206
  }
189
207
 
190
- const V = [w*nnorm[0], w*nnorm[1]];
208
+ const VDd = [qmd(w, nnormDd[0]), qmd(w, nnormDd[1])];
209
+ const V = [VDd[0][1], VDd[1][1]];
191
210
  const d = sqrt(lengthSquared(V));
192
211
 
193
212
  const x = [y[0] + V[0], y[1] + V[1]];
@@ -209,3 +228,45 @@ function getClosestPoint(
209
228
 
210
229
 
211
230
  export { getClosestPoint }
231
+
232
+
233
+
234
+ /**
235
+ * Recovers a numerically stable ray parameter `t` from linear equations
236
+ * `A*t + B = 0` and (optionally) `C*t + D = 0` evaluated at a fixed `s`.
237
+ *
238
+ * If `C,D` are unavailable, this falls back to `-B/A`.
239
+ */
240
+ // function chooseStableT(
241
+ // A: number,
242
+ // B: number,
243
+ // C: number,
244
+ // D: number) {
245
+
246
+ // const epsScale = max(1, abs(A), abs(B), abs(C), abs(D));
247
+ // const eps = Number.EPSILON * epsScale;
248
+
249
+ // const denomAB = abs(A);
250
+ // const hasAB = denomAB > eps;
251
+ // const denomCD = abs(C);
252
+ // const hasCD = denomCD > eps;
253
+
254
+ // if (!hasAB && !hasCD) {
255
+ // return undefined;
256
+ // }
257
+ // if (hasAB && !hasCD) {
258
+ // return -B / A;
259
+ // }
260
+ // if (!hasAB && hasCD) {
261
+ // return -D / C;
262
+ // }
263
+
264
+ // const tAB = -B / A;
265
+ // const tCD = -D / C;
266
+
267
+ // // Score each candidate by how well it satisfies the *other* equation.
268
+ // const scoreAB = abs(C*tAB + D) / (abs(C) + abs(D) + eps);
269
+ // const scoreCD = abs(A*tCD + B) / (abs(A) + abs(B) + eps);
270
+
271
+ // return scoreAB <= scoreCD ? tAB : tCD;
272
+ // }
@@ -11,15 +11,18 @@ const TOLERANCE = 1 + 2**-20;
11
11
  /**
12
12
  * Reduces the circle radius initially as an optimization step.
13
13
  *
14
+ * @param rO maximum possible initial radius
15
+ *
14
16
  * @internal
15
17
  */
16
18
  function reduceRadius(
17
19
  maxCoordPowerOf2: number,
20
+ rO: number,
18
21
  curvePieces: CurvePiece[],
19
22
  y: number[],
20
23
  nnorm: number[]): number {
21
24
 
22
- let minRadius = Infinity;
25
+ let minRadiusSqrd = rO**2;
23
26
  let x = [y[0] + nnorm[0], y[1] + nnorm[1]];
24
27
 
25
28
  for (let i=0; i<curvePieces.length; i++) {
@@ -31,7 +34,7 @@ function reduceRadius(
31
34
  const pE = ps[ps.length - 1];
32
35
 
33
36
  for (const P of [pS,pE]) {
34
- if (squaredDistanceBetween(x,P) > minRadius) {
37
+ if (squaredDistanceBetween(x,P) > minRadiusSqrd) {
35
38
  continue; // short-circuit
36
39
  }
37
40
 
@@ -49,15 +52,15 @@ function reduceRadius(
49
52
  const N = [w*nnorm[0], w*nnorm[1]];
50
53
  const r = lengthSquared(N);
51
54
 
52
- if (r < minRadius) {
53
- minRadius = r;
55
+ if (r < minRadiusSqrd) {
56
+ minRadiusSqrd = r;
54
57
  x = [y[0] + N[0], y[1] + N[1]];
55
58
  }
56
59
  }
57
60
  }
58
61
 
59
62
  // The extra bit is to account for floating point precision.
60
- return TOLERANCE*minRadius;
63
+ return TOLERANCE*minRadiusSqrd;
61
64
  }
62
65
 
63
66
 
@@ -1,8 +1,6 @@
1
1
  import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
2
2
  import type { CurvePiece } from '../mat/curve-piece.js';
3
- // import { fromTo, circumCenter, len, scale, translate } from 'flo-vector2d';
4
- import { fromTo, len, scale, translate } from 'flo-vector2d';
5
- import { circumCenter } from './timed-cc.js'; // TODO - testing - restore
3
+ import { circumCenter, fromTo, len, scale, translate } from 'flo-vector2d';
6
4
  import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
7
5
 
8
6
 
@@ -1,7 +1,6 @@
1
1
  import type { CpNode } from '../cp-node/cp-node.js';
2
2
  import type { CurvePiece } from '../mat/curve-piece.js';
3
- // import { circumCenter } from 'flo-vector2d';
4
- import { circumCenter } from './timed-cc.js'; // TODO - testing - restore
3
+ import { circumCenter } from 'flo-vector2d';
5
4
  import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
6
5
 
7
6
 
@@ -2,9 +2,7 @@ import type { CpNode } from '../cp-node/cp-node.js';
2
2
  import type { CurvePiece } from '../mat/curve-piece.js';
3
3
  import type { ThreeProngInfo } from './three-prong-info.js';
4
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';
6
- import { fromTo, len, distanceBetween, toUnitVector, rotate90Degrees, cross } from 'flo-vector2d';
7
- import { circumCenter as getCircumCenter } from './timed-cc.js'; // TODO - testing - restore
5
+ import { circumCenter as getCircumCenter, fromTo, len, distanceBetween, toUnitVector, rotate90Degrees, cross } from 'flo-vector2d';
8
6
  import { tangent } from 'flo-bezier3';
9
7
  import { calcInitial3ProngCenter } from './calc-initial-3-prong-center.js';
10
8
  import { getClosestPoints } from './get-closest-points.js';
@@ -69,7 +67,6 @@ function find3ProngForDelta3s(
69
67
 
70
68
  if (isSharp(δ3s[0][0])) { return undefined; }
71
69
 
72
- // TODO
73
70
  //----------------------------
74
71
  // const l1 = curvePiece3s[0].length;
75
72
  // const l2 = curvePiece3s[1].length;
@@ -2,7 +2,6 @@ import type { CpNode } from '../cp-node/cp-node.js';
2
2
  import type { ThreeProngInfo } from './three-prong-info.js';
3
3
  import { find3ProngForDelta3s } from './find-3-prong-for-delta3s.js';
4
4
  import { getBoundaryPieceBeziers } from '../mat/get-boundary-piece-beziers.js';
5
- import { timeFunctionCalls } from '../utils/time-function-call.js';
6
5
 
7
6
 
8
7
  /**
@@ -25,21 +25,7 @@ function findAndAdd3Prong(
25
25
  δs.push([visitedCp, visitedCp.next]);
26
26
  }
27
27
 
28
- // TODO - remove - debugging
29
- //-------------------------
30
- // ii++;
31
- // if (ii === 13) {
32
- // //@ts-ignore
33
- // if (_debug_.temp === undefined) { _debug_.temp = []; }
34
- // //@ts-ignore
35
- // _debug_.temp.push(δs);
36
- // }
37
- // //@ts-ignore
38
- // if (_debug_.temp2 === undefined) { _debug_.temp2 = []; }
39
- // //@ts-ignore
40
- // _debug_.temp2.push(δs.length);
41
- //-------------------------
42
-
28
+
43
29
  const threeProngInfo = find3Prong(δs, meta.maxCoordPowerOf2);
44
30
 
45
31
  const { circle, poss, δ3s } = threeProngInfo;
@@ -8,7 +8,7 @@ import type { MatOptions } from './mat-options.js';
8
8
  import type { MatMeta } from '../mat/mat-meta.js';
9
9
  import { findAndAdd3ProngsOnLoop } from '../find-3-prong/find-and-add-3-prongs-on-loop.js';
10
10
  import { createInitialCpTree } from './create-initial-cp-tree.js';
11
- import { /*getPointToCpNode,*/ getPartialMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4, getPointToCpNode } from './get-meta.js';
11
+ import { getPartialMeta, addDebugInfo1, addDebugInfo2, addDebugInfo3, addDebugInfo4 } from './get-meta.js';
12
12
  import { getSharpCornersOnLoop } from './get-sharp-corners.js';
13
13
  import { getDullCornersOnLoop } from './get-dull-corners-on-loop.js';
14
14
  import { findAndAdd2ProngsOnAllLoops } from '../find-2-prong/find-and-add-2-prongs-on-all-loops.js';
@@ -32,6 +32,8 @@ function findMat(
32
32
  meta: MatMeta;
33
33
  } {
34
34
 
35
+ addDebugInfo1();
36
+
35
37
  const { minBezLength, maxCurviness, maxLength, angleIncrement } = options;
36
38
 
37
39
  const getSharpCornersOnLoop_ = getSharpCornersOnLoop(minBezLength);
@@ -49,7 +51,6 @@ function findMat(
49
51
  const cpTrees = createInitialCpTree(loops, sharpCornersPerLoop, lastInsertId);
50
52
 
51
53
  const _meta = getPartialMeta(loops);
52
- const pointToCpNode = getPointToCpNode(loops, cpTrees);
53
54
  const meta: MatMeta = {
54
55
  maxCoordPowerOf2, squaredDiagonalLength, loops, cpTrees,// pointToCpNode,
55
56
  lastInsertId, ..._meta
@@ -6,7 +6,6 @@ import { toScaleAxis } from '../sat/to-scale-axis.js';
6
6
  import { clipOptions } from './clip-options.js';
7
7
  import { findMat } from './find-mat.js';
8
8
  import { defaultMatOptions, MatOptions } from './mat-options.js';
9
- import { circumCenter } from '../find-3-prong/timed-cc.js';
10
9
 
11
10
 
12
11
  const { ceil, log2 } = Math;
@@ -19,12 +19,13 @@ function getDullCornersOnLoop(
19
19
  }
20
20
 
21
21
  const { next, ps } = curve;
22
-
22
+
23
23
  if (getCorner(ps, next.ps).isQuiteDull) {
24
24
  const p = ps[ps.length - 1];
25
+ const pDd = [[0,p[0]], [0,p[1]]];
25
26
 
26
- dullCorners.push({ curve, t: 1, isSource: true, p });
27
- dullCorners.push({ curve: next, t: 0, isSource: true, p });
27
+ dullCorners.push({ curve, t: 1, isSource: true, p, pDd });
28
+ dullCorners.push({ curve: next, t: 0, isSource: true, p, pDd });
28
29
  }
29
30
  }
30
31
 
@@ -24,9 +24,14 @@ function getFor1ProngsOnLoop(
24
24
  continue;
25
25
  }
26
26
 
27
- poss.push(...getCurvatureExtremaDd(curve.ps).maxima.map(t => ({
28
- curve, t, isSource: true, p: toP(curve.ps, t)
29
- })));
27
+ const { ps } = curve;
28
+
29
+ poss.push(...getCurvatureExtremaDd(ps).maxima.map(t => {
30
+ const pDd = toP(ps, t);
31
+ const p = pDd.map(c => c[0] + c[1]);
32
+
33
+ return { curve, t, isSource: true, p, pDd }
34
+ }));
30
35
  }
31
36
 
32
37
  return poss;
@@ -36,7 +36,12 @@ function getFor2ProngsOnLoop(
36
36
  ts = ts.filter(t => t !== 0 && t !== 1);
37
37
 
38
38
  const byCurvatureAndLength: PrePointOnShape[] =
39
- ts.map(t => ({ curve, t, isSource: true, p: toP(curve.ps, t) }));
39
+ ts.map(t => {
40
+ const pDd = toP(curve.ps, t);
41
+ const p = pDd.map(c => c[0] + c[1]);
42
+
43
+ return { curve, t, isSource: true, p, pDd };
44
+ });
40
45
 
41
46
  for2Prongs.push(...byCurvatureAndLength);
42
47
  }
@@ -1,13 +1,9 @@
1
1
  import type { Debug } from '../debug/debug.js';
2
2
  import type { Loop } from 'flo-boolean';
3
3
  import type { Curve } from 'flo-boolean';
4
- import type { CpNode } from '../cp-node/cp-node.js';
5
- import type { TriMap } from '../utils/tri-map.js';
6
4
  import type { MatMeta } from '../mat/mat-meta.js';
7
- // import { TriMapFs } from '../utils/tri-map.js';
8
5
  import { getBoundingHull, getBoundingBoxTight } from 'flo-bezier3';
9
6
  import { getBoundingBox$ } from '../geometry/get-bounding-box-.js';
10
- import { RbTree } from 'flo-ll-rb-tree';
11
7
  import { getCorner } from '../corner/get-corner.js';
12
8
 
13
9
 
@@ -18,30 +14,6 @@ declare const _debug_: Debug;
18
14
  let timingStart: number;
19
15
 
20
16
 
21
- /** @internal */
22
- function getPointToCpNode(
23
- loops: Loop[],
24
- cpTrees: Map<Loop, RbTree<CpNode>>): TriMap<Loop,number,number,CpNode> {
25
-
26
- timingStart = performance.now();
27
-
28
- // const pointToCpNode: TriMap<Loop,number,number,CpNode> = new Map();
29
-
30
- // for (const loop of loops) {
31
- // // Populate `posMap`
32
- // const cpTree = cpTrees.get(loop)!;
33
- // const cpNodes = cpTree.toArrayInOrder();
34
- // for (const cpNode of cpNodes) {
35
- // const { p, t } = cpNode.pointOnShape;
36
- // TriMapFs.set(pointToCpNode,loop,p[0],p[1],cpNode);
37
- // }
38
- // }
39
-
40
- // return pointToCpNode;
41
- return undefined!
42
- }
43
-
44
-
45
17
  /** @internal */
46
18
  function getPartialMeta(
47
19
  loops: Loop[]): Omit<
@@ -92,42 +64,46 @@ function getPartialMeta(
92
64
  }
93
65
 
94
66
 
67
+ function addDebugInfo1() {
68
+ if (typeof _debug_ === 'undefined') { return; }
69
+
70
+ timingStart = performance.now();
71
+ }
72
+
73
+
74
+
95
75
  /** @internal */
96
76
  function addDebugInfo2() {
97
77
  if (typeof _debug_ === 'undefined') { return; }
98
78
 
99
- const timing = _debug_.generated.timing;
100
79
  const now = performance.now();
101
- timing.holeClosers += now - timingStart;
80
+ _debug_.timing.holeClosers += now - timingStart;
102
81
  timingStart = now;
103
82
  }
104
83
 
105
84
 
85
+ /** @internal */
106
86
  function addDebugInfo3() {
107
87
  if (typeof _debug_ === 'undefined') { return; }
108
88
 
109
- const generated = _debug_.generated;
110
- const timing = generated.timing;
111
89
  const now = performance.now();
112
90
 
113
- timing.oneAnd2Prongs += now - timingStart;
91
+ _debug_.timing.oneAnd2Prongs += now - timingStart;
114
92
  timingStart = now;
115
93
  }
116
94
 
117
95
 
96
+ /** @internal */
118
97
  function addDebugInfo4() {
119
98
  if (typeof _debug_ === 'undefined') { return; }
120
99
 
121
- const generated = _debug_.generated;
122
- const timing = generated.timing;
123
-
124
- timing.threeProngs += performance.now() - timingStart;
100
+ _debug_.timing.threeProngs += performance.now() - timingStart;
125
101
  }
126
102
 
127
103
 
128
104
  export {
129
- getPointToCpNode,
130
105
  getPartialMeta,
106
+ addDebugInfo1,
131
107
  addDebugInfo2,
132
108
  addDebugInfo3,
133
109
  addDebugInfo4
@@ -20,7 +20,11 @@ function getSharpCornersOnLoop(
20
20
  }
21
21
 
22
22
  if (getCorner(curve.ps, curve.next.ps).isQuiteSharp) {
23
- sharpCorners.push({ curve, t: 1, isSource: true, p: toP(curve.ps, 1) });
23
+ const { ps } = curve;
24
+
25
+ const p = ps[ps.length - 1];
26
+ const pDd = [[0,p[0]],[0,p[1]]];
27
+ sharpCorners.push({ curve, t: 1, isSource: true, p, pDd });
24
28
  }
25
29
  }
26
30