flo-mat 4.0.3 → 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 (313) 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 +168 -4
  7. package/__tests__/specific-cases/test-svgs/achispado.svg +5052 -0
  8. package/browser/index.js +1686 -2738
  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/{reconstruct-from-mat → cp-node/fs}/get-all-on-loop-by-loop.d.ts +6 -2
  16. package/node/{reconstruct-from-mat → cp-node/fs}/get-all-on-loop-by-loop.js +5 -1
  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/debug/debug.d.ts +4 -13
  29. package/node/debug/debug.js +3 -30
  30. package/node/debug/debug.js.map +1 -1
  31. package/node/find-2-prong/find-2-prong.js +24 -10
  32. package/node/find-2-prong/find-2-prong.js.map +1 -1
  33. package/node/find-2-prong/get-medial/get-antipodal-points.d.ts +1 -1
  34. package/node/find-2-prong/get-medial/get-antipodal-points.js +2 -2
  35. package/node/find-2-prong/get-medial/get-antipodal-points.js.map +1 -1
  36. package/node/find-2-prong/get-medial/get-closest-points.d.ts +7 -1
  37. package/node/find-2-prong/get-medial/get-closest-points.js +60 -14
  38. package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -1
  39. package/node/find-2-prong/reduce-radius.d.ts +3 -1
  40. package/node/find-2-prong/reduce-radius.js +8 -6
  41. package/node/find-2-prong/reduce-radius.js.map +1 -1
  42. package/node/find-3-prong/calc-better-x.js +1 -3
  43. package/node/find-3-prong/calc-better-x.js.map +1 -1
  44. package/node/find-3-prong/calc-initial-3-prong-center.js +1 -2
  45. package/node/find-3-prong/calc-initial-3-prong-center.js.map +1 -1
  46. package/node/find-3-prong/find-3-prong-for-delta3s.js +1 -4
  47. package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
  48. package/node/find-3-prong/find-3-prong.js.map +1 -1
  49. package/node/find-3-prong/find-and-add-3-prong.js +0 -14
  50. package/node/find-3-prong/find-and-add-3-prong.js.map +1 -1
  51. package/node/find-mat/find-mat.js +2 -1
  52. package/node/find-mat/find-mat.js.map +1 -1
  53. package/node/find-mat/find-mats.js.map +1 -1
  54. package/node/find-mat/get-dull-corners-on-loop.js +3 -2
  55. package/node/find-mat/get-dull-corners-on-loop.js.map +1 -1
  56. package/node/find-mat/get-for-1-prongs-on-loop.js +6 -3
  57. package/node/find-mat/get-for-1-prongs-on-loop.js.map +1 -1
  58. package/node/find-mat/get-for-2-prongs-on-loop.js +5 -1
  59. package/node/find-mat/get-for-2-prongs-on-loop.js.map +1 -1
  60. package/node/find-mat/get-meta.d.ts +4 -1
  61. package/node/find-mat/get-meta.js +9 -1
  62. package/node/find-mat/get-meta.js.map +1 -1
  63. package/node/find-mat/get-sharp-corners.js +4 -2
  64. package/node/find-mat/get-sharp-corners.js.map +1 -1
  65. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.d.ts +21 -0
  66. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.js +46 -0
  67. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.js.map +1 -0
  68. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.d.ts +28 -0
  69. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.js +97 -0
  70. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.js.map +1 -0
  71. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.d.ts +28 -0
  72. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.js +109 -0
  73. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.js.map +1 -0
  74. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.d.ts +29 -0
  75. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.js +123 -0
  76. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.js.map +1 -0
  77. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.d.ts +30 -0
  78. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.js +177 -0
  79. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.js.map +1 -0
  80. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.d.ts +29 -0
  81. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js +156 -0
  82. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js.map +1 -0
  83. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.d.ts +28 -0
  84. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.js +40 -0
  85. package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.js.map +1 -0
  86. package/node/index.d.ts +4 -10
  87. package/node/index.js +3 -6
  88. package/node/index.js.map +1 -1
  89. package/node/point-on-shape/point-on-shape.d.ts +2 -0
  90. package/node/point-on-shape/to-p.d.ts +1 -1
  91. package/node/point-on-shape/to-p.js +1 -1
  92. package/node/point-on-shape/to-p.js.map +1 -1
  93. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js +2 -2
  94. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js.map +1 -1
  95. package/node/reconstruct-from-mat/reconstruct-from-mat.d.ts +8 -2
  96. package/node/reconstruct-from-mat/reconstruct-from-mat.js +154 -22
  97. package/node/reconstruct-from-mat/reconstruct-from-mat.js.map +1 -1
  98. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js +1 -1
  99. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js.map +1 -1
  100. package/node/svg/get-loop-bounds.js +6 -2
  101. package/node/svg/get-loop-bounds.js.map +1 -1
  102. package/node/utils/map-deep.d.ts +15 -0
  103. package/node/utils/map-deep.js +34 -0
  104. package/node/utils/map-deep.js.map +1 -0
  105. package/package.json +14 -8
  106. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +3 -2
  107. package/src/corner/get-corner.ts +1 -1
  108. package/src/{reconstruct-from-mat → cp-node/fs}/get-all-on-loop-by-loop.ts +7 -3
  109. package/src/cp-node/fs/get-all-on-loop.ts +1 -1
  110. package/src/cp-node/fs/get-boundary-beziers-to-next.ts +1 -72
  111. package/src/cp-node/fs/get-edge-direction.ts +8 -4
  112. package/src/cp-node/fs/get-mat-curve-between.ts +6 -6
  113. package/src/cp-node/fs/is-fully-terminating.ts +16 -0
  114. package/src/debug/debug.ts +8 -50
  115. package/src/find-2-prong/find-2-prong.ts +37 -14
  116. package/src/find-2-prong/get-medial/get-antipodal-points.ts +3 -2
  117. package/src/find-2-prong/get-medial/get-closest-points-d.ts +213 -0
  118. package/src/find-2-prong/get-medial/get-closest-points.ts +74 -13
  119. package/src/find-2-prong/reduce-radius.ts +8 -5
  120. package/src/find-3-prong/calc-better-x.ts +1 -3
  121. package/src/find-3-prong/calc-initial-3-prong-center.ts +1 -2
  122. package/src/find-3-prong/find-3-prong-for-delta3s.ts +1 -4
  123. package/src/find-3-prong/find-3-prong.ts +0 -1
  124. package/src/find-3-prong/find-and-add-3-prong.ts +1 -15
  125. package/src/find-mat/find-mat.ts +3 -1
  126. package/src/find-mat/find-mats.ts +0 -1
  127. package/src/find-mat/get-dull-corners-on-loop.ts +4 -3
  128. package/src/find-mat/get-for-1-prongs-on-loop.ts +8 -3
  129. package/src/find-mat/get-for-2-prongs-on-loop.ts +6 -1
  130. package/src/find-mat/get-meta.ts +11 -0
  131. package/src/find-mat/get-sharp-corners.ts +5 -1
  132. package/src/get-medial-curve/__pycache__/get-cubic-self-medial-curve.cpython-313.pyc +0 -0
  133. package/src/get-medial-curve/get-cubic-self-medial-curve.py +419 -0
  134. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0-with-running-err.ts +76 -0
  135. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.ts +61 -0
  136. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.ts +116 -0
  137. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.ts +129 -0
  138. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.ts +142 -0
  139. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.ts +199 -0
  140. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.ts +177 -0
  141. package/src/get-medial-points/double-double/dd-get-medial-point-coeffs.ts +48 -0
  142. package/src/get-medial-points/double-double/error-bound-calc.txt +72 -0
  143. package/src/index.ts +4 -10
  144. package/src/point-on-shape/point-on-shape.ts +3 -0
  145. package/src/point-on-shape/to-p.ts +2 -2
  146. package/src/reconstruct-from-mat/get-cp-nodess-for-sat.ts +2 -2
  147. package/src/reconstruct-from-mat/reconstruct-from-mat.ts +202 -21
  148. package/src/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.ts +1 -1
  149. package/src/svg/get-loop-bounds.ts +11 -3
  150. package/src/utils/map-deep.ts +75 -0
  151. package/src/utils/map-map.ts +33 -0
  152. package/wallaby.mjs +4 -4
  153. package/node/debug/debug-elem-types.d.ts +0 -26
  154. package/node/debug/debug-elem-types.js +0 -22
  155. package/node/debug/debug-elem-types.js.map +0 -1
  156. package/node/debug/functions/draw/draw-beziers-as-single-path.d.ts +0 -2
  157. package/node/debug/functions/draw/draw-beziers-as-single-path.js +0 -30
  158. package/node/debug/functions/draw/draw-beziers-as-single-path.js.map +0 -1
  159. package/node/debug/functions/draw/xmlns.d.ts +0 -2
  160. package/node/debug/functions/draw/xmlns.js +0 -3
  161. package/node/debug/functions/draw/xmlns.js.map +0 -1
  162. package/node/debug/functions/draw-elem/bounding-hull.d.ts +0 -3
  163. package/node/debug/functions/draw-elem/bounding-hull.js +0 -8
  164. package/node/debug/functions/draw-elem/bounding-hull.js.map +0 -1
  165. package/node/debug/functions/draw-elem/draw-branch.d.ts +0 -4
  166. package/node/debug/functions/draw-elem/draw-branch.js +0 -26
  167. package/node/debug/functions/draw-elem/draw-branch.js.map +0 -1
  168. package/node/debug/functions/draw-elem/draw-circle-percent.d.ts +0 -3
  169. package/node/debug/functions/draw-elem/draw-circle-percent.js +0 -13
  170. package/node/debug/functions/draw-elem/draw-circle-percent.js.map +0 -1
  171. package/node/debug/functions/draw-elem/draw-cp-node.d.ts +0 -4
  172. package/node/debug/functions/draw-elem/draw-cp-node.js +0 -26
  173. package/node/debug/functions/draw-elem/draw-cp-node.js.map +0 -1
  174. package/node/debug/functions/draw-elem/draw-cull.d.ts +0 -3
  175. package/node/debug/functions/draw-elem/draw-cull.js +0 -9
  176. package/node/debug/functions/draw-elem/draw-cull.js.map +0 -1
  177. package/node/debug/functions/draw-elem/draw-dull-corner.d.ts +0 -4
  178. package/node/debug/functions/draw-elem/draw-dull-corner.js +0 -10
  179. package/node/debug/functions/draw-elem/draw-dull-corner.js.map +0 -1
  180. package/node/debug/functions/draw-elem/draw-elem.d.ts +0 -10
  181. package/node/debug/functions/draw-elem/draw-elem.js +0 -39
  182. package/node/debug/functions/draw-elem/draw-elem.js.map +0 -1
  183. package/node/debug/functions/draw-elem/draw-leaves.d.ts +0 -4
  184. package/node/debug/functions/draw-elem/draw-leaves.js +0 -34
  185. package/node/debug/functions/draw-elem/draw-leaves.js.map +0 -1
  186. package/node/debug/functions/draw-elem/draw-loop.d.ts +0 -4
  187. package/node/debug/functions/draw-elem/draw-loop.js +0 -11
  188. package/node/debug/functions/draw-elem/draw-loop.js.map +0 -1
  189. package/node/debug/functions/draw-elem/draw-loops.d.ts +0 -4
  190. package/node/debug/functions/draw-elem/draw-loops.js +0 -6
  191. package/node/debug/functions/draw-elem/draw-loops.js.map +0 -1
  192. package/node/debug/functions/draw-elem/draw-loose-bounding-box.d.ts +0 -3
  193. package/node/debug/functions/draw-elem/draw-loose-bounding-box.js +0 -10
  194. package/node/debug/functions/draw-elem/draw-loose-bounding-box.js.map +0 -1
  195. package/node/debug/functions/draw-elem/draw-mat.d.ts +0 -4
  196. package/node/debug/functions/draw-elem/draw-mat.js +0 -34
  197. package/node/debug/functions/draw-elem/draw-mat.js.map +0 -1
  198. package/node/debug/functions/draw-elem/draw-max-vertex.d.ts +0 -4
  199. package/node/debug/functions/draw-elem/draw-max-vertex.js +0 -9
  200. package/node/debug/functions/draw-elem/draw-max-vertex.js.map +0 -1
  201. package/node/debug/functions/draw-elem/draw-min-y.d.ts +0 -4
  202. package/node/debug/functions/draw-elem/draw-min-y.js +0 -10
  203. package/node/debug/functions/draw-elem/draw-min-y.js.map +0 -1
  204. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.d.ts +0 -4
  205. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js +0 -22
  206. package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js.map +0 -1
  207. package/node/debug/functions/draw-elem/draw-one-prong.d.ts +0 -4
  208. package/node/debug/functions/draw-elem/draw-one-prong.js +0 -13
  209. package/node/debug/functions/draw-elem/draw-one-prong.js.map +0 -1
  210. package/node/debug/functions/draw-elem/draw-sharp-corner.d.ts +0 -4
  211. package/node/debug/functions/draw-elem/draw-sharp-corner.js +0 -10
  212. package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +0 -1
  213. package/node/debug/functions/draw-elem/draw-three-prong.d.ts +0 -4
  214. package/node/debug/functions/draw-elem/draw-three-prong.js +0 -26
  215. package/node/debug/functions/draw-elem/draw-three-prong.js.map +0 -1
  216. package/node/debug/functions/draw-elem/draw-tight-bounding-box.d.ts +0 -3
  217. package/node/debug/functions/draw-elem/draw-tight-bounding-box.js +0 -8
  218. package/node/debug/functions/draw-elem/draw-tight-bounding-box.js.map +0 -1
  219. package/node/debug/functions/draw-elem/draw-two-prong.d.ts +0 -4
  220. package/node/debug/functions/draw-elem/draw-two-prong.js +0 -49
  221. package/node/debug/functions/draw-elem/draw-two-prong.js.map +0 -1
  222. package/node/debug/functions/draw-elem/draw-vertex.d.ts +0 -4
  223. package/node/debug/functions/draw-elem/draw-vertex.js +0 -13
  224. package/node/debug/functions/draw-elem/draw-vertex.js.map +0 -1
  225. package/node/find-3-prong/timed-cc.d.ts +0 -3
  226. package/node/find-3-prong/timed-cc.js +0 -5
  227. package/node/find-3-prong/timed-cc.js.map +0 -1
  228. package/node/reconstruct-from-mat/filter-zero-length.d.ts +0 -10
  229. package/node/reconstruct-from-mat/filter-zero-length.js +0 -14
  230. package/node/reconstruct-from-mat/filter-zero-length.js.map +0 -1
  231. package/node/reconstruct-from-mat/get-all-on-loop-by-loop.js.map +0 -1
  232. package/node/reconstruct-from-mat/get-bezier-piece-length.d.ts +0 -3
  233. package/node/reconstruct-from-mat/get-bezier-piece-length.js +0 -6
  234. package/node/reconstruct-from-mat/get-bezier-piece-length.js.map +0 -1
  235. package/node/reconstruct-from-mat/get-boundary.d.ts +0 -7
  236. package/node/reconstruct-from-mat/get-boundary.js +0 -18
  237. package/node/reconstruct-from-mat/get-boundary.js.map +0 -1
  238. package/node/reconstruct-from-mat/get-matching-beziers.d.ts +0 -10
  239. package/node/reconstruct-from-mat/get-matching-beziers.js +0 -29
  240. package/node/reconstruct-from-mat/get-matching-beziers.js.map +0 -1
  241. package/node/reconstruct-from-mat/get-mbss-by-loop-per-sat.d.ts +0 -6
  242. package/node/reconstruct-from-mat/get-mbss-by-loop-per-sat.js +0 -10
  243. package/node/reconstruct-from-mat/get-mbss-by-loop-per-sat.js.map +0 -1
  244. package/node/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.d.ts +0 -7
  245. package/node/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.js +0 -47
  246. package/node/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.js.map +0 -1
  247. package/node/reconstruct-from-mat/get-sats2.d.ts +0 -10
  248. package/node/reconstruct-from-mat/get-sats2.js +0 -16
  249. package/node/reconstruct-from-mat/get-sats2.js.map +0 -1
  250. package/node/reconstruct-from-mat/is-fully-terminating.d.ts +0 -3
  251. package/node/reconstruct-from-mat/is-fully-terminating.js +0 -19
  252. package/node/reconstruct-from-mat/is-fully-terminating.js.map +0 -1
  253. package/node/reconstruct-from-mat/matched-beziers.d.ts +0 -10
  254. package/node/reconstruct-from-mat/matched-beziers.js +0 -2
  255. package/node/reconstruct-from-mat/matched-beziers.js.map +0 -1
  256. package/node/reconstruct-from-mat/split-tri-path.d.ts +0 -5
  257. package/node/reconstruct-from-mat/split-tri-path.js +0 -209
  258. package/node/reconstruct-from-mat/split-tri-path.js.map +0 -1
  259. package/node/utils/clip.d.ts +0 -2
  260. package/node/utils/clip.js +0 -6
  261. package/node/utils/clip.js.map +0 -1
  262. package/node/utils/time-function-call.d.ts +0 -14
  263. package/node/utils/time-function-call.js +0 -32
  264. package/node/utils/time-function-call.js.map +0 -1
  265. package/src/debug/debug-elem-types.ts +0 -43
  266. package/src/debug/functions/draw-elem/bounding-hull.ts +0 -18
  267. package/src/debug/functions/draw-elem/culls.ts +0 -39
  268. package/src/debug/functions/draw-elem/draw-branch.ts +0 -37
  269. package/src/debug/functions/draw-elem/draw-circle-percent.ts +0 -23
  270. package/src/debug/functions/draw-elem/draw-cp-node.ts +0 -46
  271. package/src/debug/functions/draw-elem/draw-cull.ts +0 -21
  272. package/src/debug/functions/draw-elem/draw-dull-corner.ts +0 -21
  273. package/src/debug/functions/draw-elem/draw-elem.ts +0 -64
  274. package/src/debug/functions/draw-elem/draw-leaves.ts +0 -51
  275. package/src/debug/functions/draw-elem/draw-loop.ts +0 -16
  276. package/src/debug/functions/draw-elem/draw-loops.ts +0 -10
  277. package/src/debug/functions/draw-elem/draw-loose-bounding-box.ts +0 -21
  278. package/src/debug/functions/draw-elem/draw-mat.ts +0 -43
  279. package/src/debug/functions/draw-elem/draw-max-vertex.ts +0 -15
  280. package/src/debug/functions/draw-elem/draw-min-y.ts +0 -18
  281. package/src/debug/functions/draw-elem/draw-one-prong-at-dull-corner.ts +0 -40
  282. package/src/debug/functions/draw-elem/draw-one-prong.ts +0 -25
  283. package/src/debug/functions/draw-elem/draw-sharp-corner.ts +0 -21
  284. package/src/debug/functions/draw-elem/draw-three-prong.ts +0 -44
  285. package/src/debug/functions/draw-elem/draw-tight-bounding-box.ts +0 -18
  286. package/src/debug/functions/draw-elem/draw-two-prong.ts +0 -68
  287. package/src/debug/functions/draw-elem/draw-vertex.ts +0 -27
  288. package/src/debug/functions/draw-elem/dull-corner.ts +0 -21
  289. package/src/debug/functions/draw-elem/leaves.ts +0 -20
  290. package/src/debug/functions/draw-elem/loop.ts +0 -16
  291. package/src/debug/functions/draw-elem/loops.ts +0 -10
  292. package/src/debug/functions/draw-elem/loose-bounding-box.ts +0 -21
  293. package/src/debug/functions/draw-elem/mat.ts +0 -47
  294. package/src/debug/functions/draw-elem/max-vertex.ts +0 -15
  295. package/src/debug/functions/draw-elem/min-y.ts +0 -18
  296. package/src/debug/functions/draw-elem/one-prong-at-dull-corner.ts +0 -26
  297. package/src/debug/functions/draw-elem/one-prong.ts +0 -23
  298. package/src/debug/functions/draw-elem/sharp-corner.ts +0 -20
  299. package/src/debug/functions/draw-elem/three-prong.ts +0 -30
  300. package/src/debug/functions/draw-elem/tight-bounding-box.ts +0 -18
  301. package/src/debug/functions/draw-elem/two-prong.ts +0 -50
  302. package/src/debug/functions/draw-elem/vertex.ts +0 -51
  303. package/src/find-3-prong/timed-cc.ts +0 -9
  304. package/src/reconstruct-from-mat/filter-zero-length.ts +0 -23
  305. package/src/reconstruct-from-mat/get-bezier-piece-length.ts +0 -12
  306. package/src/reconstruct-from-mat/get-boundary.ts +0 -32
  307. package/src/reconstruct-from-mat/get-matching-beziers.ts +0 -46
  308. package/src/reconstruct-from-mat/get-mbss-by-loop-per-sat.ts +0 -19
  309. package/src/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.ts +0 -69
  310. package/src/reconstruct-from-mat/get-sats2.ts +0 -25
  311. package/src/reconstruct-from-mat/is-fully-terminating.ts +0 -27
  312. package/src/reconstruct-from-mat/matched-beziers.ts +0 -14
  313. package/src/reconstruct-from-mat/split-tri-path.ts +0 -280
@@ -0,0 +1,177 @@
1
+ import { toPowerBasisDd } from 'flo-bezier3';
2
+ import { twoDiff, ddMultDouble2, ddAddDd, ddMultDd, ddNegativeOf, ddMultByNeg2, ddMultBy2, ddDiffDouble } from 'double-double';
3
+
4
+ const td = twoDiff;
5
+ const qmd = ddMultDouble2;
6
+ const qaq = ddAddDd;
7
+ const qmq = ddMultDd;
8
+ const qno = ddNegativeOf;
9
+ const qmn2 = ddMultByNeg2;
10
+ const qm2 = ddMultBy2;
11
+ const qdd = ddDiffDouble;
12
+
13
+
14
+ /**
15
+ * Returns the polynomial coefficients for the ray parameter `t` and the
16
+ * curve parameter `s` that encode the medial condition for `q(t) = p + t⋅v`
17
+ * and a cubic bezier curve `ps`.
18
+ *
19
+ * The returned coefficients describe the equations whose common solutions
20
+ * satisfy:
21
+ * * `q(t)` is equidistant from `p` and the nearest point on `ps`
22
+ * * that common distance is locally minimal among such candidates
23
+ *
24
+ * More specifically, this function returns:
25
+ * * `A` and `B`: the coefficients of `E2(s,t) = A(s)⋅t + B(s)`
26
+ * * `C` and `D`: the coefficients of `E1(s,t) = C(s)⋅t + D(s)`
27
+ * * `H`: the eliminated polynomial `A(s)⋅D(s) - B(s)⋅C(s)` whose roots are
28
+ * candidate `s` values for medial points
29
+ *
30
+ * @param p base point
31
+ * @param v ray direction from `p`
32
+ * @param ps cubic bezier control points, i.e. an order 3 bezier curve
33
+ * given as an array of control points, e.g. `[[0,0],[1,1],[2,1],[3,0]]`
34
+ */
35
+ function ddGetMedialPointCoeffsBez3(
36
+ p: number[][],
37
+ v: number[][],
38
+ ps: number[][]) {
39
+
40
+ // -----------------------------------------------------
41
+ // See get-medial-points.md for implementation details.
42
+ // -----------------------------------------------------
43
+
44
+ const [px, py] = p;
45
+ const [vx, vy] = v;
46
+
47
+ // Cubic bezier in power basis: b(s) = a*s^3 + b*s^2 + c*s + d
48
+ const [[ax,bx,cx,[,dx]],[ay,by,cy,[,dy]]] = toPowerBasisDd(ps);
49
+
50
+ // const u0x = px - dx;
51
+ // const u0y = py - dy;
52
+ const u0x = qdd(px,dx);
53
+ const u0y = qdd(py,dy);
54
+
55
+ // Reuse dot products across A, B, C, D, and H.
56
+ // const va = vx*ax + vy*ay;
57
+ // const vb = vx*bx + vy*by;
58
+ // const vc = vx*cx + vy*cy;
59
+ // const vu0 = vx*u0x + vy*u0y;
60
+ const va = qaq(qmq(vx,ax),qmq(vy,ay));
61
+ const vb = qaq(qmq(vx,bx),qmq(vy,by));
62
+ const vc = qaq(qmq(vx,cx),qmq(vy,cy));
63
+ const vu0 = qaq(qmq(vx,u0x),qmq(vy,u0y));
64
+
65
+ // const b6 = ax*ax + ay*ay;
66
+ // const ab = ax*bx + ay*by;
67
+ // const ac = ax*cx + ay*cy;
68
+ // const bb = bx*bx + by*by;
69
+ // const bc = bx*cx + by*cy;
70
+ // const cc = cx*cx + cy*cy;
71
+ const b6 = qaq(qmq(ax,ax),qmq(ay,ay));
72
+ const ab = qaq(qmq(ax,bx),qmq(ay,by));
73
+ const ac = qaq(qmq(ax,cx),qmq(ay,cy));
74
+ const bb = qaq(qmq(bx,bx),qmq(by,by));
75
+ const bc = qaq(qmq(bx,cx),qmq(by,cy));
76
+ const cc = qaq(qmq(cx,cx),qmq(cy,cy));
77
+
78
+ // const au0 = ax*u0x + ay*u0y;
79
+ // const bu0 = bx*u0x + by*u0y;
80
+ // const d0 = cx*u0x + cy*u0y;
81
+ // const b0 = u0x*u0x + u0y*u0y;
82
+ const au0 = qaq(qmq(ax,u0x),qmq(ay,u0y));
83
+ const bu0 = qaq(qmq(bx,u0x),qmq(by,u0y));
84
+ const d0 = qaq(qmq(cx,u0x),qmq(cy,u0y));
85
+ const b0 = qaq(qmq(u0x,u0x),qmq(u0y,u0y));
86
+
87
+ // -----------------------------------------------------
88
+ // E1(s,t): (u(s) + t*v) * b'(s) = 0
89
+ // => C(s)*t + D(s) = 0
90
+ // const c2 = 3*va;
91
+ // const c1 = 2*vb;
92
+ // const c0 = vc;
93
+ const c2 = qmd(3,va);
94
+ const c1 = qm2(vb);
95
+ const c0 = vc;
96
+ // -----------------------------------------------------
97
+
98
+ // -----------------------------------------------------
99
+ // const d5 = -3*b6;
100
+ // const d4 = -5*ab;
101
+ // const d3 = -4*ac - 2*bb;
102
+ // const d2 = 3*au0 - 3*bc;
103
+ // const d1 = 2*bu0 - cc;
104
+ const d5 = qmd(-3,b6);
105
+ const d4 = qmd(-5,ab);
106
+ const d3 = qaq(qmd(-4,ac),qmn2(bb));
107
+ const d2 = qaq(qmd(3,au0),qmd(-3,bc));
108
+ const d1 = qaq(qm2(bu0),qno(cc));
109
+ // -----------------------------------------------------
110
+
111
+ // -----------------------------------------------------
112
+ // E2(s,t): |t*v|^2 - |u(s) + t*v|^2 = 0
113
+ // => 2*(v*u(s))*t + |u(s)|^2 = 0
114
+ // => A(s)*t + B(s) = 0
115
+ // const a3 = -2*va;
116
+ // const a2 = -2*vb;
117
+ // const a1 = -2*vc;
118
+ // const a0 = 2*vu0;
119
+ const a3 = qmn2(va);
120
+ const a2 = qmn2(vb);
121
+ const a1 = qmn2(vc);
122
+ const a0 = qm2(vu0);
123
+ // -----------------------------------------------------
124
+
125
+ // -----------------------------------------------------
126
+ // const b5 = 2*ab;
127
+ // const b4 = 2*ac + bb;
128
+ // const b3 = 2*bc - 2*au0;
129
+ // const b2 = cc - 2*bu0;
130
+ // const b1 = -2*d0;
131
+ const b5 = qm2(ab);
132
+ const b4 = qaq(qm2(ac),bb);
133
+ const b3 = qaq(qm2(bc),qmn2(au0));
134
+ const b2 = qaq(cc,qmn2(bu0));
135
+ const b1 = qmn2(d0);
136
+ // -----------------------------------------------------
137
+
138
+
139
+ // Eliminate t from:
140
+ // A(s)*t + B(s) = 0
141
+ // C(s)*t + D(s) = 0
142
+ // by taking H(s) = A(s)*D(s) - B(s)*C(s) = 0 (degree <= 8 in s).
143
+ // Using:
144
+ // a2 = -c1, a1 = -2*c0,
145
+ // d5 = -3*b6, d4 = -(5/2)*b5, d3 = -2*b4, d2 = -(3/2)*b3,
146
+ // d1 = -b2, d0 = -(1/2)*b1,
147
+ // we can compute H directly with fewer operations.
148
+ // const H8 = 3*va*b6;
149
+ // const H7 = 4*(va*ab + vb*b6);
150
+ // const H6 = va*b4 + 6*vb*ab + 5*vc*b6;
151
+ // const H5 = 2*vb*b4 + 8*vc*ab - 6*vu0*b6;
152
+ // const H4 = -va*b2 + vb*b3 + 3*vc*b4 - 10*vu0*ab;
153
+ // const H3 = -2*va*b1 + 2*vc*b3 - 4*vu0*b4;
154
+ // const H2 = vc*b2 - vb*b1 - 3*vu0*b3 - 3*va*b0;
155
+ // const H1 = -2*vu0*b2 - 2*vb*b0;
156
+ // const H0 = -vu0*b1 - vc*b0;
157
+ const H8 = qmd(3,qmq(va,b6));
158
+ const H7 = qm2(qm2(qaq(qmq(va,ab),qmq(vb,b6))));
159
+ const H6 = qaq(qaq(qmq(va,b4),qmd(6,qmq(vb,ab))),qmd(5,qmq(vc,b6)));
160
+ const H5 = qaq(qaq(qm2(qmq(vb,b4)),qmd(8,qmq(vc,ab))),qno(qmd(6,qmq(vu0,b6))));
161
+ const H4 = qaq(qaq(qno(qmq(va,b2)),qmq(vb,b3)),qaq(qmd(3,qmq(vc,b4)),qno(qmd(10,qmq(vu0,ab)))));
162
+ const H3 = qaq(qaq(qmn2(qmq(va,b1)),qm2(qmq(vc,b3))),qno(qm2(qm2(qmq(vu0,b4)))));
163
+ const H2 = qaq(qaq(qaq(qmq(vc,b2),qno(qmq(vb,b1))),qno(qmd(3,qmq(vu0,b3)))),qno(qmd(3,qmq(va,b0))));
164
+ const H1 = qaq(qmn2(qmq(vu0,b2)),qmn2(qmq(vb,b0)));
165
+ const H0 = qaq(qno(qmq(vu0,b1)),qno(qmq(vc,b0)));
166
+
167
+ return {
168
+ A: [a3, a2, a1, a0],
169
+ B: [b6, b5, b4, b3, b2, b1, b0],
170
+ C: [c2, c1, c0],
171
+ D: [d5, d4, d3, d2, d1, d0],
172
+ H: [H8, H7, H6, H5, H4, H3, H2, H1, H0]
173
+ };
174
+ }
175
+
176
+
177
+ export { ddGetMedialPointCoeffsBez3 }
@@ -0,0 +1,48 @@
1
+ import { ddGetMedialPointCoeffsBez2 } from './dd-get-medial-point-coeffs-bez2.js';
2
+ import { ddGetMedialPointCoeffsBez1 } from './dd-get-medial-point-coeffs-bez1.js';
3
+ import { ddGetMedialPointCoeffsBez3 } from './dd-get-medial-point-coeffs-bez3.js';
4
+ import { ddGetMedialPointCoeffsBez0 } from './dd-get-medial-point-coeffs-bez0.js';
5
+
6
+
7
+ const getMedialPointCoeffss = [
8
+ ,,
9
+ ddGetMedialPointCoeffsBez1,
10
+ ddGetMedialPointCoeffsBez2,
11
+ ddGetMedialPointCoeffsBez3
12
+ ];
13
+
14
+
15
+ /**
16
+ * Returns polynomial coefficients for ray parameter values `t`, bezier
17
+ * parameter values `s` and medial points for points `q(t)` and b(s) (an order
18
+ * 0, 1, 2 or 3 bezier curve) that satisfy the medial condition with respect to `p` and `ps`:
19
+ *
20
+ * Let `p` be a fixed point in the plane.
21
+ * Let `v` be a direction vector defining the ray `q(t) = p + t⋅v`.
22
+ * Let `ps` be a cubic bezier curve.
23
+ *
24
+ * * `q(t)` is equidistant from `p` and the nearest point on `ps`
25
+ * * that common distance is locally minimal among such candidates
26
+ *
27
+ * In other words, this function returns candidate ray parameters for the
28
+ * sought medial point(s). Selecting physically valid solutions (if needed)
29
+ * is done by the caller or by a later stage of this routine.
30
+ *
31
+ * @param p base point
32
+ * @param v ray direction from `p`
33
+ * @param ps bezier control points, e.g. `[[0,0],[1,1],[2,1],[3,0]]`
34
+ */
35
+ function ddGetMedialPointCoeffs(
36
+ p: number[][],
37
+ v: number[][],
38
+ ps: number[][]) {
39
+
40
+ if (ps.length === 1) {
41
+ const { a0, b0 } = ddGetMedialPointCoeffsBez0(p,v,ps[0]);
42
+ return { A: [a0], B: [b0], C: [], D: [], H: [] };
43
+ }
44
+ return getMedialPointCoeffss[ps.length]!(p,v,ps);
45
+ }
46
+
47
+
48
+ export { ddGetMedialPointCoeffs }
@@ -0,0 +1,72 @@
1
+
2
+ //--------------------------------------------------------------------------
3
+ // `var` -> a variable
4
+ // `$var` -> the double precision approximation to `var`
5
+ // `_var` -> the absolute value of $var (a prefix underscore on a variable means absolute value)
6
+ // `var_` -> the error in var (a postfix underscore means error bound but should still be multiplied by 3*γ²)
7
+ // `_var_` -> means both absolute value and absolute error bound
8
+ // recall: `a*b`, where both `a` and `b` have errors |a| and |b| we get for the
9
+ // * error bound of (a*b) === a_|b| + |a|b_ + |a*b| (when either of a and b is double)
10
+ // * error bound of (a*b) === a_|b| + |a|b_ + 2|a*b| (when both a and b is double-double)
11
+ // * error bound of (a+b) === a_ + b_ + |a+b| (when a and/or b is double or double-double)
12
+ // * the returned errors need to be multiplied by 3γ² to get the true error
13
+ // * can use either `$var` or `var[var.length-1]` (the approx value) in error calculations
14
+ // due to multiplication by 3*γ² and not 3*u²
15
+ //--------------------------------------------------------------------------
16
+ // examples: (all?)
17
+ // ----------------
18
+ // let qmd === ddMultDouble2, etc.
19
+ //
20
+ // ---------------
21
+ // 1. double-double X by double
22
+ // ---------------
23
+ // qmd(a,b); // both `a` and `b` is error-free
24
+ // use: error bound of (a*b) === a_|b| + |a|b_ + |a*b| (by definition)
25
+ // === 0|b| + |a|0 + |a*b|
26
+ // === |a*b|
27
+ //
28
+ // ---------------
29
+ // 2a. double-double +/- double-double
30
+ // ---------------
31
+ // qdq(a,b); // error in a === |a|, thus call the error _a_, same with b
32
+ // use: error bound of (a+b) === a_ + b_ + |a+b| (by definition)
33
+ // === _a_ + _b_ + |a+b|
34
+ //
35
+ // ---------------
36
+ // 2b. double-double +/- double-double
37
+ // ---------------
38
+ // qaq(a,b); // error in a === 2|a|, thus the error is 2*_a, same with b
39
+ // use: error bound of (a+b) === a_ + b_ + |a+b| (by definition)
40
+ // === 2*_a + 2*_b + |a+b|
41
+ // === 2*(_a + _b) + |a+b| OR
42
+ // === a_ + b_ + |a+b|
43
+ //
44
+ // ---------------
45
+ // 3a. double-double X double-double
46
+ // ---------------
47
+ // qmq(a,b); // both `a` and `b` error-free
48
+ // use: error bound of (a*b) === a_|b| + |a|b_ + |a*b| (by definition)
49
+ // === 0|b| + |a|0 + 2|a*b|
50
+ // === 2|a*b|
51
+ //
52
+ // ---------------
53
+ // 3b. double-double X double-double
54
+ // ---------------
55
+ // qmq(a,b); // both `a` and `b` not error-free
56
+ // use: error bound of (a*b) === a_|b| + |a|b_ + 2|a*b| (by definition)
57
+ //
58
+ // ---------------
59
+ // 3b. double-double X double-double
60
+ // ---------------
61
+ // qmq(a,b); // both `a` not error-free and `b` error-free
62
+ // use: error bound of (a*b) === a_|b| + |a|b_ + 2|a*b| (by definition)
63
+ // === a_|b| + 2|a*b|
64
+ //
65
+ // ---------------
66
+ // 4a. double-double +/- double
67
+ // ---------------
68
+ // qad(a,b); // both `a` and `b` error-free
69
+ // use: error bound of (a+b) === a_ + b_ + |a+b| (by definition)
70
+ // === 0 + 0 + |a+b|
71
+ // === |a+b|
72
+ //--------------------------------------------------------------------------
package/src/index.ts CHANGED
@@ -7,14 +7,10 @@ export type { CpNode } from './cp-node/cp-node.js';
7
7
  export type { PointOnShape } from './point-on-shape/point-on-shape.js';
8
8
  export type { Circle } from './geometry/circle.js';
9
9
  export type { CurvePiece } from './mat/curve-piece.js';
10
- export type { DrawElemFunctions } from './debug/functions/draw-elem/draw-elem.js';
11
- export type { Timing as ITiming } from './debug/debug.js';
12
- export type { DebugElems } from './debug/debug-elem-types.js';
10
+ export type { Timing } from './debug/debug.js';
13
11
  export type { Debug } from './debug/debug.js';
14
- export type { DebugElemKey } from './debug/debug-elem-types.js';
15
12
  export type { MatOptions } from './find-mat/mat-options.js';
16
13
 
17
- export { drawBeziersAsSinglePath } from './debug/functions/draw/draw-beziers-as-single-path.js';
18
14
  export { floydWarshall } from './floyd-warshall/floyd-warshall.js';
19
15
  export { CpNodeFs } from './cp-node/cp-node-fs.js';
20
16
  export { isVertexSpecial } from './cp-node/fs/is-vertex-special.js';
@@ -23,13 +19,9 @@ export { trimMat } from './mat/trim-mat.js';
23
19
  export { toScaleAxis } from './sat/to-scale-axis.js';
24
20
  export { getBranches } from './mat/get-branches.js';
25
21
  export { enableDebugForMat } from './debug/debug.js';
26
- export { drawBranch } from './debug/functions/draw-elem/draw-branch.js';
27
- export { drawMat } from './debug/functions/draw-elem/draw-mat.js';
28
- export { debugElemNames, emptyDebugElems } from './debug/debug-elem-types.js';
29
22
  export { getShapeBounds } from './svg/get-shape-bounds.js';
30
23
  export { getBoundaryPieceBeziers } from './mat/get-boundary-piece-beziers.js';
31
24
  export { simplifyMat } from './mat/simplify-mat.js';
32
- export { drawElemFs, drawElemFsDetailed } from './debug/functions/draw-elem/draw-elem.js';
33
25
  export { sweepLine } from './sweep-line/sweep-line.js';
34
26
  export { getClosestSquareDistanceToRect } from './geometry/get-closest-square-distance-to-rect.js';
35
27
  export { getImpliedBoundaryBezierBetween } from './cp-node/fs/get-implied-boundary-bezier-between.js';
@@ -43,6 +35,8 @@ export { getPotentialClosestPointsOnCurveCertified } from './closest-boundary-po
43
35
  export { getCloseBoundaryPointsCertified } from './closest-boundary-point/get-close-boundary-points-certified.js';
44
36
  export { getPartialMeta } from './find-mat/get-meta.js';
45
37
  export { findAndAddHoleClosing2Prongs } from './find-2-prong/find-and-add-hole-closing-2-prongs.js';
38
+ export { reconstructFromMats } from './reconstruct-from-mat/reconstruct-from-mat.js';
39
+ export { getOsculatingCircle } from './point-on-shape/get-osculating-circle.js';
46
40
 
47
41
 
48
42
  // CpNodeFs functions
@@ -82,4 +76,4 @@ export { getAllVertices } from './cp-node/fs/get-all-vertices.js';
82
76
  export { isTrivial } from './cp-node/fs/is-trivial.js';
83
77
  export { scaleCircle } from './geometry/circle.js';
84
78
  export { isOnSameLoop } from './cp-node/fs/is-on-same-loop.js';
85
- export { reconstructFromMats } from './reconstruct-from-mat/reconstruct-from-mat.js';
79
+ export { getAllOnLoop_ByLoop } from './cp-node/fs/get-all-on-loop-by-loop.js';
@@ -28,6 +28,9 @@ interface PrePointOnShape {
28
28
 
29
29
  /** The (cached) point on the shape boundary. */
30
30
  readonly p: number[];
31
+
32
+ /** The (cached) double-double precision point on the shape boundary. */
33
+ readonly pDd: number[][];
31
34
  }
32
35
 
33
36
 
@@ -10,9 +10,9 @@ import { evalDeCasteljauDd } from "flo-bezier3";
10
10
  */
11
11
  function toP(
12
12
  ps: number[][],
13
- t: number): number[] {
13
+ t: number): number[][] {
14
14
 
15
- return evalDeCasteljauDd(ps, [0,t]).map(c => c[0] + c[1]);
15
+ return evalDeCasteljauDd(ps, [0,t]);
16
16
  }
17
17
 
18
18
 
@@ -1,8 +1,8 @@
1
1
  import type { CpNode } from "../cp-node/cp-node.js";
2
2
  import type { Mat } from '../mat/mat.js';
3
3
  import { isOnSameLoop } from "../cp-node/fs/is-on-same-loop.js";
4
- import { isFullyTerminating } from "./is-fully-terminating.js";
5
- import { getAllOnLoop_ByLoop } from "./get-all-on-loop-by-loop.js";
4
+ import { getAllOnLoop_ByLoop } from "../cp-node/fs/get-all-on-loop-by-loop.js";
5
+ import { isFullyTerminating } from "../cp-node/fs/is-fully-terminating.js";
6
6
 
7
7
 
8
8
  function getCpNodessForSat(
@@ -1,44 +1,225 @@
1
1
  import type { BezierPiece } from 'flo-bezier3';
2
2
  import type { Mat } from '../mat/mat.js';
3
- import { getMbssByLoopPerSat } from './get-mbss-by-loop-per-sat.js';
4
- import { getMbssByLoopWithOppArr } from './get-mbss-by-loop-with-opp-arr.js';
3
+ import type { CpNode } from '../cp-node/cp-node.js';
4
+ import {
5
+ toUnitVector, distanceBetween, fromTo as fromToVec, dot, rotate90Degrees,
6
+ cross, interpolate, translate, lineLineIntersection
7
+ } from 'flo-vector2d';
8
+ import { tangent as getTangent } from 'flo-bezier3';
9
+ import { mapDeep } from '../utils/map-deep.js';
10
+ import { removeSatInducedTrivial3Prongs } from './remove-sat-induced-trivial-3prongs.js';
11
+ import { getCpNodessForSat } from './get-cp-nodess-for-sat.js';
12
+ import { getRealProngCount } from '../cp-node/fs/get-real-prong-count.js';
5
13
 
6
14
 
15
+ const { max, abs, round, log2 } = Math;
16
+
17
+
18
+ // let ii = 0;
19
+
20
+
21
+ /**
22
+ * * used for debugging only
23
+ *
24
+ * @param mats
25
+ *
26
+ * @internal
27
+ */
7
28
  function reconstructFromMats(
8
- mats: Mat[]) {
29
+ mats: Mat[],
30
+ minNumAccurateBits: number | undefined = undefined) {
9
31
 
10
- const loopss: number[][][][] = [];
32
+ const maxPO2 = max(...mats.map(mat => mat.meta.maxCoordPowerOf2));
33
+ const recoverBoundary_ = recoverBoundary(maxPO2, minNumAccurateBits);
11
34
 
12
- const bzs: BezierPiece[] = [];
35
+ // Really only required if getSats was called on the `Mat`s
36
+ const cpNodessPerSat = mats
37
+ .map(removeSatInducedTrivial3Prongs)
38
+ .map(getCpNodessForSat);
13
39
 
14
- const mbssByLoopPerSat = getMbssByLoopPerSat(mats, 1.5)!;
40
+ const r = mapDeep(3, cpNodessPerSat, recoverBoundary_, true);
41
+ // ii;//?
15
42
 
16
- for (const mbssByLoopPS of mbssByLoopPerSat) {
17
- const { mbssByLoop, oppArr } = mbssByLoopPS;
43
+ return r;
44
+ }
18
45
 
19
- for (let l=0; l<mbssByLoop.length; l++) {
20
- const rs = mbssByLoop[l];
21
46
 
22
- for (let i=0; i<rs.length; i++) {
23
- const r = mbssByLoop[l][i];
47
+ const FROM = 0;
48
+ const TO = 1;
24
49
 
25
- if (r === undefined) { continue; }
50
+ /**
51
+ *
52
+ * @param cpNode
53
+ *
54
+ * @internal
55
+ */
56
+ function recoverBoundary(
57
+ maxPO2: number,
58
+ minNumAccurateBits: number | undefined) {
26
59
 
27
- const matchedBezierss = r;
60
+ return function (cpNode: CpNode) {
61
+ const cpNode_ = cpNode.next;
28
62
 
29
- for (let j=0; j<matchedBezierss.length; j++) {
30
- const mb = matchedBezierss[j];
31
- const { boundaryBezier, medialBezier } = mb;
63
+ const pos = cpNode.pointOnShape;
64
+ const pos_ = cpNode_.pointOnShape;
32
65
 
33
- bzs.push(boundaryBezier)
34
- }
66
+ const { curve, circle, p } = pos;
67
+ const { curve: curve_, p: p_ } = pos_;
68
+
69
+ if (p[0] === p_[0] && p[1] === p_[1]) {
70
+ return undefined;
71
+ }
72
+
73
+ if (curve.loop !== curve_.loop) {
74
+ // It is a hole-closer going over to the other loop
75
+ // return undefined;
76
+ return undefined;
77
+ }
78
+
79
+ const d = distanceBetween(circle.center, p);
80
+
81
+ if (getRealProngCount(cpNode)) {
82
+
83
+ }
84
+
85
+ // DON'T remove these - they tell us the accuracy of the algorithm
86
+ // if (!closeTo(2**34)(circle.radius, d) && getRealProngCount(cpNode) === 3) {
87
+ // ii++;
88
+ // circle.center;//?
89
+ // circle.radius;//?
90
+ // d; //?
91
+ // p;//?
92
+ // pos.isSource;//?
93
+ // getRealProngCount(cpNode);//?
94
+ // }
95
+ // if (!closeTo(2**28)(circle.radius, d) && getRealProngCount(cpNode) !== 3) {
96
+ // ii++;
97
+ // circle.center;//?
98
+ // circle.radius;//?
99
+ // d; //?
100
+ // p;//?
101
+ // pos.isSource;//?
102
+ // getRealProngCount(cpNode);//?
103
+ // }
104
+ if (minNumAccurateBits !== undefined) {
105
+ const TOL = 2**(maxPO2 - minNumAccurateBits);
106
+
107
+ if (abs(circle.radius - d) > TOL) {
108
+ throw new Error(
109
+ `Medial circle radius must be about the same (2**${round(log2(TOL))}) ` +
110
+ `as distance from medial circle center to point on shape, ` +
111
+ `found: medial radius ${circle.radius}, distance: ${d}`
112
+ );
35
113
  }
36
114
  }
115
+
116
+ return getBoundaryPiece(cpNode);
117
+ }
118
+ }
119
+
120
+
121
+ /** @internal */
122
+ const TOLERANCE_ADD_2PRONG = 0.01;
123
+ /** @internal */
124
+ const TOLERANCE_USE_LINE = 0.0001; // else cubic
125
+
126
+
127
+ function getBoundaryPiece(
128
+ cpNode: CpNode) {
129
+
130
+ const cpNode_ = cpNode.next;
131
+
132
+ const pos = cpNode.pointOnShape;
133
+ const pos_ = cpNode_.pointOnShape;
134
+
135
+ const { p } = pos;
136
+ const { p: p_ } = pos_;
137
+
138
+ const fromCc = p;
139
+ const fromL = getEdgeDirection(cpNode, FROM);
140
+
141
+ const toCc = p_;
142
+ const toL = getEdgeDirection(cpNode_, TO);
143
+
144
+ const mid = lineLineIntersection(fromL, toL);
145
+
146
+ const c = fromToVec(fromCc,toCc);
147
+
148
+ let twisted: boolean;
149
+ if (!mid) {
150
+ twisted = true;
151
+ } else {
152
+ const a = fromToVec(fromCc, mid);
153
+ const b = fromToVec(toCc, mid);
154
+
155
+ twisted = dot(a,c) < 0 || dot(b,c) > 0;
156
+ }
157
+
158
+ if (!twisted) {
159
+ return [fromCc, mid!, toCc];
160
+ }
161
+
162
+ const r = rotate90Degrees(c);
163
+ const w1 = fromToVec(fromL[0], fromL[1]); // This is a unit vector
164
+ const w2 = fromToVec(toL[0], toL[1]); // This is a unit vector
165
+
166
+ const d1 = abs(cross(c, w1)) / (3*3);
167
+ const d2 = abs(cross(c, w2)) / (3*3);
168
+
169
+ if (d1 > TOLERANCE_ADD_2PRONG || d2 > TOLERANCE_ADD_2PRONG) {
170
+ // FUTURE - not within tolerance - must add additional 2-prong
171
+ return [fromCc, toCc];
172
+ }
173
+
174
+ if (d1 > TOLERANCE_USE_LINE || d2 > TOLERANCE_USE_LINE) {
175
+ // approximate with cubic bezier
176
+ const m1 = interpolate(fromCc,toCc,1/3);
177
+ const m2 = interpolate(fromCc,toCc,2/3);
178
+ const v1 = translate(r, m1);
179
+ const v2 = translate(r, m2);
180
+ const l1 = [m1,v1];
181
+ const l2 = [m2,v2];
182
+ const mid1 = lineLineIntersection(fromL, l1)!;
183
+ const mid2 = lineLineIntersection(toL, l2)!;
184
+
185
+ return [fromCc, mid1, mid2, toCc];
186
+ }
187
+
188
+ // Within tolerance - approximate with a straight line.
189
+ return [fromCc, toCc];
190
+ }
191
+
192
+
193
+ /**
194
+ * Returns a line segment of unit length starting at the given point and
195
+ * being tangent to the shape boundary.
196
+ *
197
+ * @internal
198
+ */
199
+ function getEdgeDirection(
200
+ cpNode: CpNode,
201
+ fromOrTo: typeof FROM | typeof TO) {
202
+
203
+ let { pointOnShape } = cpNode;
204
+ let { curve, t, p } = pointOnShape;
205
+ let { ps } = curve;
206
+
207
+ if (fromOrTo === FROM && t === 1) {
208
+ t = 0;
209
+ curve = curve.next;
210
+ ps = curve.ps;
211
+ }
212
+ if (fromOrTo === TO && t === 0 ) {
213
+ t = 1;
214
+ curve = curve.prev;
215
+ ps = curve.ps;
37
216
  }
38
217
 
218
+ const tangent = getTangent(ps, t);
219
+
220
+ const v = translate(p, tangent);
39
221
 
40
- return bzs;
41
- // return loopss;
222
+ return [p,v];
42
223
  }
43
224
 
44
225
 
@@ -1,6 +1,6 @@
1
1
  import type { Mutable } from '../utils/mutable.js';
2
2
  import type { Mat } from '../mat/mat.js';
3
- import { isFullyTerminating } from './is-fully-terminating.js';
3
+ import { isFullyTerminating } from '../cp-node/fs/is-fully-terminating.js';
4
4
 
5
5
 
6
6
  /**
@@ -12,12 +12,20 @@ type Extreme = {
12
12
  };
13
13
 
14
14
 
15
- function toPrePoint(extreme: Extreme): PrePointOnShape {
15
+ function toPrePoint(
16
+ extreme: Extreme): PrePointOnShape {
17
+
18
+ const { curve, t } = extreme;
19
+ const { ps } = curve;
20
+
21
+ const pDd = toP(ps, t);
22
+ const p = pDd.map(c => c[0] + c[1]);
23
+
16
24
  return {
17
- curve: extreme.curve,
25
+ curve,
18
26
  t: extreme.t,
19
27
  isSource: true,
20
- p: toP(extreme.curve.ps, extreme.t)
28
+ p, pDd
21
29
  };
22
30
  }
23
31