flo-mat 4.0.1 → 4.0.3

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 (220) hide show
  1. package/README.md +1 -1
  2. package/__tests__/find-2-prong/get-medial/get-closest-points.spec.ts +49 -0
  3. package/__tests__/specific-cases/specific-cases.spec.ts +6 -0
  4. package/browser/index.js +9994 -12650
  5. package/browser/index.min.js +1 -1
  6. package/node/closest-boundary-point/foot-and-endpoint-info.d.ts +0 -3
  7. package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +1 -1
  8. package/node/closest-boundary-point/get-close-boundary-points-certified.js +2 -2
  9. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  10. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.d.ts +1 -2
  11. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +34 -24
  12. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
  13. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.d.ts +1 -1
  14. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js +6 -9
  15. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js.map +1 -1
  16. package/node/cp-node/fs/insert-cp-node.d.ts +2 -2
  17. package/node/cp-node/fs/insert-cp-node.js.map +1 -1
  18. package/node/cp-node/fs/is-on-same-loop.d.ts +3 -0
  19. package/node/cp-node/fs/is-on-same-loop.js +6 -0
  20. package/node/cp-node/fs/is-on-same-loop.js.map +1 -0
  21. package/node/cp-node/fs/is-order-correct.d.ts +2 -2
  22. package/node/cp-node/fs/is-order-correct.js.map +1 -1
  23. package/node/cp-node/fs/traverse-cp.js.map +1 -1
  24. package/node/cp-node/fs/traverse-vertices.d.ts +1 -1
  25. package/node/cp-node/fs/traverse-vertices.js.map +1 -1
  26. package/node/debug/debug.d.ts +10 -15
  27. package/node/debug/debug.js +35 -46
  28. package/node/debug/debug.js.map +1 -1
  29. package/node/debug/functions/draw-elem/draw-branch.d.ts +1 -1
  30. package/node/debug/functions/draw-elem/draw-branch.js.map +1 -1
  31. package/node/debug/functions/draw-elem/draw-cp-node.d.ts +1 -1
  32. package/node/debug/functions/draw-elem/draw-cp-node.js +2 -2
  33. package/node/debug/functions/draw-elem/draw-cp-node.js.map +1 -1
  34. package/node/debug/functions/draw-elem/draw-leaves.d.ts +1 -1
  35. package/node/debug/functions/draw-elem/draw-leaves.js +2 -2
  36. package/node/debug/functions/draw-elem/draw-leaves.js.map +1 -1
  37. package/node/debug/functions/draw-elem/draw-mat.d.ts +1 -1
  38. package/node/debug/functions/draw-elem/draw-mat.js +1 -2
  39. package/node/debug/functions/draw-elem/draw-mat.js.map +1 -1
  40. package/node/debug/functions/draw-elem/draw-min-y.d.ts +1 -1
  41. package/node/debug/functions/draw-elem/draw-min-y.js.map +1 -1
  42. package/node/debug/functions/draw-elem/draw-three-prong.d.ts +1 -1
  43. package/node/debug/functions/draw-elem/draw-three-prong.js +2 -2
  44. package/node/debug/functions/draw-elem/draw-three-prong.js.map +1 -1
  45. package/node/debug/functions/draw-elem/draw-vertex.d.ts +1 -1
  46. package/node/debug/functions/draw-elem/draw-vertex.js +0 -2
  47. package/node/debug/functions/draw-elem/draw-vertex.js.map +1 -1
  48. package/node/error-analysis/gamma.d.ts +32 -0
  49. package/node/error-analysis/gamma.js +39 -0
  50. package/node/error-analysis/gamma.js.map +1 -0
  51. package/node/find-2-prong/add-1-prong.js +1 -4
  52. package/node/find-2-prong/add-1-prong.js.map +1 -1
  53. package/node/find-2-prong/find-2-prong.js +5 -5
  54. package/node/find-2-prong/find-2-prong.js.map +1 -1
  55. package/node/find-2-prong/get-medial/get-closest-points.js +27 -23
  56. package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -1
  57. package/node/find-3-prong/calc-better-x.d.ts +1 -1
  58. package/node/find-3-prong/calc-better-x.js +6 -4
  59. package/node/find-3-prong/calc-better-x.js.map +1 -1
  60. package/node/find-3-prong/calc-initial-3-prong-center.d.ts +1 -1
  61. package/node/find-3-prong/calc-initial-3-prong-center.js +4 -3
  62. package/node/find-3-prong/calc-initial-3-prong-center.js.map +1 -1
  63. package/node/find-3-prong/find-3-prong-for-delta3s.js +22 -5
  64. package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
  65. package/node/find-3-prong/find-and-add-3-prong.d.ts +2 -2
  66. package/node/find-3-prong/find-and-add-3-prong.js +15 -0
  67. package/node/find-3-prong/find-and-add-3-prong.js.map +1 -1
  68. package/node/find-3-prong/find-and-add-3-prongs-on-loop.js +8 -21
  69. package/node/find-3-prong/find-and-add-3-prongs-on-loop.js.map +1 -1
  70. package/node/find-3-prong/find-and-add-3-prongs.d.ts +1 -4
  71. package/node/find-3-prong/find-and-add-3-prongs.js +1 -2
  72. package/node/find-3-prong/find-and-add-3-prongs.js.map +1 -1
  73. package/node/find-3-prong/get-closest-points.d.ts +1 -1
  74. package/node/find-3-prong/get-closest-points.js +2 -2
  75. package/node/find-3-prong/get-closest-points.js.map +1 -1
  76. package/node/find-3-prong/timed-cc.d.ts +3 -0
  77. package/node/find-3-prong/timed-cc.js +5 -0
  78. package/node/find-3-prong/timed-cc.js.map +1 -0
  79. package/node/find-mat/create-initial-cp-tree.d.ts +2 -2
  80. package/node/find-mat/create-initial-cp-tree.js +2 -2
  81. package/node/find-mat/create-initial-cp-tree.js.map +1 -1
  82. package/node/find-mat/find-mat.d.ts +4 -4
  83. package/node/find-mat/find-mat.js +1 -2
  84. package/node/find-mat/find-mat.js.map +1 -1
  85. package/node/find-mat/find-mats.js +2 -2
  86. package/node/find-mat/find-mats.js.map +1 -1
  87. package/node/find-mat/get-meta.d.ts +1 -6
  88. package/node/find-mat/get-meta.js +4 -25
  89. package/node/find-mat/get-meta.js.map +1 -1
  90. package/node/index.d.ts +5 -2
  91. package/node/index.js +4 -1
  92. package/node/index.js.map +1 -1
  93. package/node/mat/create-new-cp-trees.d.ts +2 -2
  94. package/node/mat/create-new-cp-trees.js +2 -2
  95. package/node/mat/create-new-cp-trees.js.map +1 -1
  96. package/node/mat/get-cp-node-to-left-or-same.d.ts +2 -2
  97. package/node/mat/get-cp-node-to-left-or-same.js +2 -1
  98. package/node/mat/get-cp-node-to-left-or-same.js.map +1 -1
  99. package/node/mat/mat-meta.d.ts +2 -2
  100. package/node/point-on-shape/get-osculating-circle.js +2 -1
  101. package/node/point-on-shape/get-osculating-circle.js.map +1 -1
  102. package/node/reconstruct-from-mat/filter-zero-length.d.ts +10 -0
  103. package/node/reconstruct-from-mat/filter-zero-length.js +14 -0
  104. package/node/reconstruct-from-mat/filter-zero-length.js.map +1 -0
  105. package/node/reconstruct-from-mat/get-all-on-loop-by-loop.d.ts +7 -0
  106. package/node/reconstruct-from-mat/get-all-on-loop-by-loop.js +38 -0
  107. package/node/reconstruct-from-mat/get-all-on-loop-by-loop.js.map +1 -0
  108. package/node/reconstruct-from-mat/get-bezier-piece-length.d.ts +3 -0
  109. package/node/reconstruct-from-mat/get-bezier-piece-length.js +6 -0
  110. package/node/reconstruct-from-mat/get-bezier-piece-length.js.map +1 -0
  111. package/node/reconstruct-from-mat/get-boundary.d.ts +7 -0
  112. package/node/reconstruct-from-mat/get-boundary.js +18 -0
  113. package/node/reconstruct-from-mat/get-boundary.js.map +1 -0
  114. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.d.ts +4 -0
  115. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js +15 -0
  116. package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js.map +1 -0
  117. package/node/reconstruct-from-mat/get-matching-beziers.d.ts +10 -0
  118. package/node/reconstruct-from-mat/get-matching-beziers.js +29 -0
  119. package/node/reconstruct-from-mat/get-matching-beziers.js.map +1 -0
  120. package/node/reconstruct-from-mat/get-mbss-by-loop-per-sat.d.ts +6 -0
  121. package/node/reconstruct-from-mat/get-mbss-by-loop-per-sat.js +10 -0
  122. package/node/reconstruct-from-mat/get-mbss-by-loop-per-sat.js.map +1 -0
  123. package/node/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.d.ts +7 -0
  124. package/node/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.js +47 -0
  125. package/node/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.js.map +1 -0
  126. package/node/reconstruct-from-mat/get-sats2.d.ts +10 -0
  127. package/node/reconstruct-from-mat/get-sats2.js +16 -0
  128. package/node/reconstruct-from-mat/get-sats2.js.map +1 -0
  129. package/node/reconstruct-from-mat/is-fully-terminating.d.ts +3 -0
  130. package/node/reconstruct-from-mat/is-fully-terminating.js +19 -0
  131. package/node/reconstruct-from-mat/is-fully-terminating.js.map +1 -0
  132. package/node/reconstruct-from-mat/matched-beziers.d.ts +10 -0
  133. package/node/reconstruct-from-mat/matched-beziers.js +2 -0
  134. package/node/reconstruct-from-mat/matched-beziers.js.map +1 -0
  135. package/node/reconstruct-from-mat/reconstruct-from-mat.d.ts +4 -0
  136. package/node/reconstruct-from-mat/reconstruct-from-mat.js +28 -0
  137. package/node/reconstruct-from-mat/reconstruct-from-mat.js.map +1 -0
  138. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.d.ts +12 -0
  139. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js +46 -0
  140. package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js.map +1 -0
  141. package/node/reconstruct-from-mat/split-tri-path.d.ts +5 -0
  142. package/node/reconstruct-from-mat/split-tri-path.js +209 -0
  143. package/node/reconstruct-from-mat/split-tri-path.js.map +1 -0
  144. package/node/sat/add-debug-info.js +1 -2
  145. package/node/sat/add-debug-info.js.map +1 -1
  146. package/node/utils/clip.d.ts +2 -0
  147. package/node/utils/clip.js +6 -0
  148. package/node/utils/clip.js.map +1 -0
  149. package/package.json +6 -7
  150. package/src/closest-boundary-point/foot-and-endpoint-info.ts +0 -3
  151. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +0 -2
  152. package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +41 -27
  153. package/src/closest-boundary-point/root-interval-to-distance-squared-interval.ts +5 -10
  154. package/src/cp-node/fs/insert-cp-node.ts +2 -2
  155. package/src/cp-node/fs/is-on-same-loop.ts +15 -0
  156. package/src/cp-node/fs/is-order-correct.ts +2 -2
  157. package/src/cp-node/fs/traverse-cp.ts +1 -1
  158. package/src/cp-node/fs/traverse-vertices.ts +1 -2
  159. package/src/debug/debug.ts +54 -72
  160. package/src/debug/functions/check-ordering.ts +0 -1
  161. package/src/debug/functions/draw-elem/draw-branch.ts +1 -3
  162. package/src/debug/functions/draw-elem/draw-cp-node.ts +3 -4
  163. package/src/debug/functions/draw-elem/draw-leaves.ts +3 -3
  164. package/src/debug/functions/draw-elem/draw-mat.ts +2 -5
  165. package/src/debug/functions/draw-elem/draw-min-y.ts +2 -2
  166. package/src/debug/functions/draw-elem/draw-three-prong.ts +3 -3
  167. package/src/debug/functions/draw-elem/draw-vertex.ts +1 -4
  168. package/src/error-analysis/gamma.ts +9 -2
  169. package/src/find-2-prong/add-1-prong.ts +1 -5
  170. package/src/find-2-prong/find-2-prong.ts +7 -6
  171. package/src/find-2-prong/get-medial/get-closest-points.ts +24 -26
  172. package/src/find-3-prong/calc-better-x.ts +7 -4
  173. package/src/find-3-prong/calc-initial-3-prong-center.ts +2 -3
  174. package/src/find-3-prong/find-3-prong-for-delta3s.ts +23 -5
  175. package/src/find-3-prong/find-and-add-3-prong.ts +18 -4
  176. package/src/find-3-prong/find-and-add-3-prongs-on-loop.ts +7 -23
  177. package/src/find-3-prong/find-and-add-3-prongs.ts +5 -3
  178. package/src/find-3-prong/get-closest-points.ts +0 -2
  179. package/src/find-3-prong/timed-cc.ts +9 -0
  180. package/src/find-mat/create-initial-cp-tree.ts +3 -3
  181. package/src/find-mat/find-mat.ts +6 -8
  182. package/src/find-mat/find-mats.ts +4 -2
  183. package/src/find-mat/get-meta.ts +3 -38
  184. package/src/index.ts +6 -3
  185. package/src/mat/create-new-cp-trees.ts +3 -3
  186. package/src/mat/get-cp-node-to-left-or-same.ts +4 -3
  187. package/src/mat/mat-meta.ts +2 -2
  188. package/src/point-on-shape/get-osculating-circle.ts +2 -1
  189. package/src/reconstruct-from-mat/filter-zero-length.ts +23 -0
  190. package/src/reconstruct-from-mat/get-all-on-loop-by-loop.ts +52 -0
  191. package/src/reconstruct-from-mat/get-bezier-piece-length.ts +12 -0
  192. package/src/reconstruct-from-mat/get-boundary.ts +32 -0
  193. package/src/reconstruct-from-mat/get-cp-nodess-for-sat.ts +24 -0
  194. package/src/reconstruct-from-mat/get-matching-beziers.ts +46 -0
  195. package/src/reconstruct-from-mat/get-mbss-by-loop-per-sat.ts +19 -0
  196. package/src/reconstruct-from-mat/get-mbss-by-loop-with-opp-arr.ts +69 -0
  197. package/src/reconstruct-from-mat/get-sats2.ts +25 -0
  198. package/src/reconstruct-from-mat/is-fully-terminating.ts +27 -0
  199. package/src/reconstruct-from-mat/matched-beziers.ts +14 -0
  200. package/src/reconstruct-from-mat/reconstruct-from-mat.ts +45 -0
  201. package/src/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.ts +62 -0
  202. package/src/reconstruct-from-mat/split-tri-path.ts +280 -0
  203. package/src/sat/add-debug-info.ts +1 -2
  204. package/src/utils/clip.ts +13 -0
  205. package/wallaby.mjs +1 -0
  206. package/node/closest-boundary-point/get-p-from-box.d.ts +0 -3
  207. package/node/closest-boundary-point/get-p-from-box.js +0 -11
  208. package/node/closest-boundary-point/get-p-from-box.js.map +0 -1
  209. package/node/debug/functions/general.d.ts +0 -48
  210. package/node/debug/functions/general.js +0 -53
  211. package/node/debug/functions/general.js.map +0 -1
  212. package/node/point-on-shape/pos-to-human-string.d.ts +0 -8
  213. package/node/point-on-shape/pos-to-human-string.js +0 -12
  214. package/node/point-on-shape/pos-to-human-string.js.map +0 -1
  215. package/src/debug/elem-type-two-prong.ts +0 -8
  216. package/src/debug/functions/cmp-cp-on-delta.ts +0 -54
  217. package/src/debug/functions/general.ts +0 -79
  218. package/src/debug/functions/three-prong.ts +0 -249
  219. package/src/debug/functions/two-prong.ts +0 -203
  220. package/src/find-2-prong/add-debug-info.ts +0 -45
@@ -17,7 +17,6 @@ import { toP } from '../point-on-shape/to-p.js';
17
17
  * @internal
18
18
  */
19
19
  function getCloseBoundaryPointsCertified(
20
- maxCoordPowerOf2: number,
21
20
  curvePieces: CurvePiece[],
22
21
  x: number[]): PrePointOnShape[] {
23
22
 
@@ -28,7 +27,6 @@ function getCloseBoundaryPointsCertified(
28
27
  const curvePiece = curvePieces[i];
29
28
 
30
29
  const _pInfos = getPotentialClosestPointsOnCurveCertified(
31
- maxCoordPowerOf2,
32
30
  curvePiece.curve,
33
31
  x,
34
32
  curvePiece.ts as [number,number]
@@ -1,62 +1,76 @@
1
1
  import type { Curve } from "flo-boolean";
2
2
  import type { FootAndEndpointInfo } from './foot-and-endpoint-info.js';
3
- import { createRootExact, roots } from 'flo-poly';
4
- import { getFootPointsOnBezierPolysCertified, getIntervalBox } from 'flo-bezier3';
3
+ import { roots } from 'flo-poly';
4
+ import { evalDeCasteljauDd, getFootPointsOnBezierPolysCertified, getIntervalBox } from 'flo-bezier3';
5
5
  import { rootIntervalToDistanceSquaredInterval } from './root-interval-to-distance-squared-interval.js';
6
- import { getPFromBox } from './get-p-from-box.js';
7
-
8
- const { sqrt } = Math;
6
+ import { squaredDistanceBetweenDd } from "../find-2-prong/squared-distance-between-dd.js";
7
+ import { eps } from '../error-analysis/gamma.js';
9
8
 
10
9
 
11
10
  /**
12
11
  * @internal
13
12
  *
14
- * @param maxCoordPowerOf2
15
13
  * @param curve the curve
16
14
  * @param x the point from which to check
17
15
  * @param tRange The allowed t range
18
16
  */
19
17
  function getPotentialClosestPointsOnCurveCertified(
20
- maxCoordPowerOf2: number,
21
18
  curve: Curve,
22
19
  x: number[],
23
20
  tRange: [number, number]): FootAndEndpointInfo[] {
24
21
 
25
22
  const [tS,tE] = tRange;
26
- const ps = curve.ps;
23
+ const { ps } = curve;
24
+
25
+ const infos: FootAndEndpointInfo[] = [];
26
+
27
+ if (tS !== tE) {
28
+ const { polyDd: pDd, polyE: pDd_, getPolyExact } =
29
+ getFootPointsOnBezierPolysCertified(ps, x);
30
+
31
+ const ris = roots(pDd, tS, tE, pDd_, getPolyExact) || [];
32
+
33
+ infos.push(...ris.map(ri => {
34
+ const { tS: ts, tE: te, t: _t } = ri;
35
+
36
+ const t = _t < 0 ? 0 : _t > 1 ? 1 : _t;
37
+
38
+ const box = getIntervalBox(ps, [ts, te]);
27
39
 
28
- let { polyDd: pDd, polyE: pDd_, getPolyExact } =
29
- getFootPointsOnBezierPolysCertified(ps, x);
40
+ const dSquaredI = rootIntervalToDistanceSquaredInterval(box, x);
30
41
 
31
- const ris = roots(pDd, tS, tE, pDd_, getPolyExact) || [];
42
+ const t_ = t === 0 ? 1 : t;
43
+ const curve_ = t === 0 ? curve.prev : curve;
32
44
 
33
- ris.push(createRootExact(tS));
34
- ris.push(createRootExact(tE));
45
+ return {
46
+ curve: curve_,
47
+ t: t_,
48
+ dSquaredI
49
+ }
50
+ }));
51
+ }
35
52
 
36
- const infos = ris
37
- .map(ri => {
38
- const { tS: ts, tE: te } = ri;
53
+ const ts = tRange.slice();
54
+ if (tS === tE) {
55
+ ts.push(tS);
56
+ }
57
+
58
+ infos.push(...ts.map(t => {
59
+ const p = evalDeCasteljauDd(ps, [0,t]).map(v => v[0] + v[1]);
39
60
 
40
- const _t = (ts + te)/2;
41
- const t = _t < 0 ? 0 : _t > 1 ? 1 : _t;
61
+ const d = squaredDistanceBetweenDd(p, x);
42
62
 
43
- const box = getIntervalBox(ps, [ts, te]);
44
- const p_ = getPFromBox(box);
45
-
46
- const dSquaredI = rootIntervalToDistanceSquaredInterval(maxCoordPowerOf2, box, x);
63
+ const dSquaredI = [d*(1 - eps), d*(1 + eps)];
47
64
 
48
65
  const t_ = t === 0 ? 1 : t;
49
66
  const curve_ = t === 0 ? curve.prev : curve;
50
67
 
51
68
  return {
52
69
  curve: curve_,
53
- p: p_,
54
70
  t: t_,
55
- d: (sqrt(dSquaredI[0]) + sqrt(dSquaredI[1]))/2,
56
- dSquaredI,
57
- box
71
+ dSquaredI
58
72
  }
59
- });
73
+ }));
60
74
 
61
75
  return infos;
62
76
  }
@@ -1,12 +1,6 @@
1
- import { twoDiff, eEstimate, eMult, eAdd } from 'big-float-ts';
2
- import { ddMultDd, ddAddDd } from 'double-double';
1
+ import { twoDiff, ddMultDd, ddAddDd } from 'double-double';
3
2
 
4
-
5
- // We *have* to do the below to improve performance with bundlers❗ The assignee is a getter❗ The assigned is a pure function❗
6
- const estimate = eEstimate;
7
3
  const td = twoDiff;
8
- // const emult = eMult;
9
- // const eadd = eAdd;
10
4
  const qmq = ddMultDd;
11
5
  const qaq = ddAddDd;
12
6
 
@@ -25,7 +19,6 @@ const eps = Number.EPSILON;
25
19
  * @internal
26
20
  */
27
21
  function rootIntervalToDistanceSquaredInterval(
28
- maxCoordPowerOf2: number,
29
22
  box: number[][],
30
23
  p: number[]) {
31
24
 
@@ -62,8 +55,10 @@ function rootIntervalToDistanceSquaredInterval(
62
55
  const dc1Dd = qaq(qmq(ax,ax),qmq(by,by)); // ax**2 + bx**2
63
56
  const dc1 = dc1Dd[1];
64
57
 
65
- const dc1Min = dc1*(1 - 2**maxCoordPowerOf2*eps); // distance minus max error
66
- const dc1Max = dc1*(1 + 2**maxCoordPowerOf2*eps); // distance plus max error
58
+ // const dc1Min = dc1*(1 - 2**maxCoordPowerOf2*eps); // distance minus max error
59
+ // const dc1Max = dc1*(1 + 2**maxCoordPowerOf2*eps); // distance plus max error
60
+ const dc1Min = dc1*(1 - eps); // distance minus max error
61
+ const dc1Max = dc1*(1 + eps); // distance plus max error
67
62
 
68
63
  if (dc1Min <= minDSquared) {
69
64
  minDSquared = dc1Min;
@@ -1,7 +1,7 @@
1
1
  import type { CpNode } from "../cp-node.js";
2
2
  import type { PointOnShape } from "../../point-on-shape/point-on-shape.js";
3
3
  import type { Mutable } from "../../utils/mutable.js";
4
- import { LlRbTree } from "flo-ll-rb-tree";
4
+ import { RbTree } from "flo-ll-rb-tree";
5
5
  import { isOrderCorrect } from "./is-order-correct.js";
6
6
 
7
7
 
@@ -9,7 +9,7 @@ function insertCpNode(
9
9
  insertIfOrderWrong: boolean,
10
10
  isHoleClosing: boolean,
11
11
  isIntersection: boolean,
12
- cpTree: LlRbTree<CpNode>,
12
+ cpTree: RbTree<CpNode>,
13
13
  pos: PointOnShape,
14
14
  _prev: CpNode | undefined,
15
15
  lastInsertId: { id: number }): CpNode | undefined {
@@ -0,0 +1,15 @@
1
+ import type { CpNode } from "flo-mat";
2
+
3
+
4
+ function isOnSameLoop(
5
+ cpNode1: CpNode,
6
+ cpNode2: CpNode): boolean {
7
+
8
+ return (
9
+ cpNode1.pointOnShape.curve.loop ===
10
+ cpNode2.pointOnShape.curve.loop
11
+ );
12
+ }
13
+
14
+
15
+ export { isOnSameLoop }
@@ -1,11 +1,11 @@
1
1
  import type { CpNode } from "../cp-node.js";
2
- import { LlRbTree } from "flo-ll-rb-tree";
2
+ import { RbTree } from "flo-ll-rb-tree";
3
3
  import { PointOnShape } from "../../point-on-shape/point-on-shape.js";
4
4
  import { comparePoss } from "../../point-on-shape/compare-poss.js";
5
5
 
6
6
 
7
7
  function isOrderCorrect(
8
- cpTree: LlRbTree<CpNode>,
8
+ cpTree: RbTree<CpNode>,
9
9
  pos: PointOnShape,
10
10
  next: CpNode): boolean {
11
11
 
@@ -27,7 +27,7 @@ function traverseCp(
27
27
  const next = cpNode.next.prevOnCircle;
28
28
  cpNode = cpNode === next
29
29
  ? cpNode = cpNode.next.next // Terminal vertex
30
- : cpNode = next // Take last exit
30
+ : cpNode = next // Take last exit
31
31
 
32
32
  } while (cpNode !== cpStart);
33
33
 
@@ -1,5 +1,4 @@
1
- import { CpNode } from '../cp-node.js';
2
- import { CpNodeFs } from '../cp-node-fs.js';
1
+ import type { CpNode } from '../cp-node.js';
3
2
  import { getAllOnCircle } from './get-all-on-circle.js';
4
3
  import { isTerminating } from './is-terminating.js';
5
4
  import { getVertexForwardChildren } from './get-vertex-forward-children.js';
@@ -1,20 +1,20 @@
1
- import { generalDebugFunctions } from './functions/general.js';
2
- import { IGeneralDebugFunctions } from './functions/general.js';
3
- import { DrawElemFunctions } from './functions/draw-elem/draw-elem.js';
4
- import { DebugElems } from './debug-elem-types.js';
1
+ import type { DrawElemFunctions } from './functions/draw-elem/draw-elem.js';
2
+ import type { DebugElems } from './debug-elem-types.js';
5
3
  import { drawElemFs } from './functions/draw-elem/draw-elem.js';
6
4
 
7
5
 
8
6
  /** @internal */
9
7
  interface Debug {
10
8
  /** Generated by debug object for later inspection */
11
- generated: Generated;
9
+ elems: GeneratedElems;
10
+ timing: Timing;
11
+
12
12
  /**
13
13
  * These functions are meant to be used in the console, e.g. in the
14
14
  * console try typing d.fs.twoProng.traceConvergence(0);
15
15
  */
16
- fs: IDebugFunctions;
17
- directives: IDirectives;
16
+ fs: DebugFunctions;
17
+ directives: Directives;
18
18
  }
19
19
 
20
20
 
@@ -23,32 +23,23 @@ type GeneratedElems = { [T in keyof DebugElems]: DebugElems[T][] };
23
23
 
24
24
 
25
25
  /** @internal */
26
- interface ITiming {
27
- //normalize : number;
28
- //simplifyPaths : number;
29
- holeClosers : number;
30
- oneAnd2Prongs : number;
31
- threeProngs : number;
32
- sats : number;
33
- simplifyMat : number;
34
- }
35
-
36
-
37
- /** @internal */
38
- interface Generated {
39
- elems: GeneratedElems;
40
- timing: ITiming;
26
+ interface Timing {
27
+ holeClosers: number;
28
+ oneAnd2Prongs: number;
29
+ threeProngs: number;
30
+ sats: number;
31
+ simplifyMat: number;
41
32
  }
42
33
 
43
34
 
44
35
  /** @internal */
45
- interface IDebugFunctions extends IGeneralDebugFunctions {
46
- drawElem : DrawElemFunctions,
36
+ interface DebugFunctions {
37
+ drawElem: DrawElemFunctions,
47
38
  }
48
39
 
49
40
 
50
41
  /** @internal */
51
- interface IDirectives {
42
+ interface Directives {
52
43
  stopAfterHoleClosers: boolean,
53
44
  stopAfterHoleClosersNum: number,
54
45
  stopAfterTwoProngs: boolean,
@@ -68,59 +59,50 @@ function enableDebugForMat(debugOn: boolean) {
68
59
 
69
60
  debug = {
70
61
  ...debug,
71
- generated: {
72
- //...debug?.generated,
73
- ...(!debug ? {} : !debug.generated ? {} : debug.generated),
62
+ elems: {
63
+ ...debug?.elems,
74
64
  // @ts-ignore
75
- elems: {
76
- //...debug?.generated?.elems,
77
- ...(!debug ? {} : !debug.generated ? {} : !debug.generated.elems ? {} : debug.generated.elems),
78
- oneProng : [],
79
- // oneProngAtDullCorner : [],
80
- twoProng : [],
81
- // twoProng_regular : [],
82
- // twoProng_failed : [],
83
- // twoProng_notAdded : [],
84
- // twoProng_deleted : [],
85
- // twoProng_holeClosing : [],
86
- looseBoundingBox : [],
87
- tightBoundingBox : [],
88
- // sharpCorner : [],
89
- // dullCorner : [],
90
- vertex : [],
91
- threeProng : [],
92
- boundingHull : [],
93
- mat : [],
94
- // sat : [],
95
- cpNode : [],
96
- maxVertex : [],
97
- leaves : [],
98
- // culls : [],
99
- },
100
- timing: {
101
- //...debug?.generated?.timing,
102
- ...(!debug ? {} : !debug.generated ? {} : !debug.generated.timing ? {} : debug.generated.timing),
103
- holeClosers : 0,
104
- oneAnd2Prongs : 0,
105
- threeProngs : 0,
106
- sats : 0,
107
- simplifyMat : 0,
108
- }
65
+
66
+ oneProng : [],
67
+ // oneProngAtDullCorner : [],
68
+ twoProng : [],
69
+ // twoProng_regular : [],
70
+ // twoProng_failed : [],
71
+ // twoProng_notAdded : [],
72
+ // twoProng_deleted : [],
73
+ // twoProng_holeClosing : [],
74
+ looseBoundingBox : [],
75
+ tightBoundingBox : [],
76
+ // sharpCorner : [],
77
+ // dullCorner : [],
78
+ vertex : [],
79
+ threeProng : [],
80
+ boundingHull : [],
81
+ mat : [],
82
+ // sat : [],
83
+ cpNode : [],
84
+ maxVertex : [],
85
+ leaves : [],
86
+ // culls : [],
87
+ },
88
+ timing: {
89
+ ...debug?.timing,
90
+ holeClosers: 0,
91
+ oneAnd2Prongs: 0,
92
+ threeProngs: 0,
93
+ sats: 0,
94
+ simplifyMat: 0,
109
95
  },
110
96
  fs: {
111
- //...debug?.fs,
112
- ...(!debug ? {} : !debug.fs ? {} : debug.fs),
113
- // @ts-ignore
97
+ ...debug?.fs,
114
98
  drawElem: {
115
- //...debug?.fs?.drawElem,
116
- ...(!debug ? {} : !debug.fs ? {} : !debug.fs.drawElem ? {} : debug.fs.drawElem),
99
+ ...debug?.fs?.drawElem,
117
100
  ...drawElemFs
118
- },
119
- ...generalDebugFunctions
101
+ }
120
102
  },
121
103
  directives: {
122
104
  //...debug?.directives,
123
- ...(!debug ? {} : !debug.directives ? {} : debug.directives),
105
+ ...debug?.directives,
124
106
  stopAfterHoleClosers: false,
125
107
  stopAfterHoleClosersNum: undefined!,
126
108
  stopAfterTwoProngs: false,
@@ -135,6 +117,6 @@ function enableDebugForMat(debugOn: boolean) {
135
117
 
136
118
 
137
119
  export {
138
- Debug, GeneratedElems, ITiming, Generated,
139
- IDebugFunctions, IDirectives, enableDebugForMat
120
+ Debug, GeneratedElems, Timing,
121
+ DebugFunctions, Directives, enableDebugForMat
140
122
  }
@@ -1,5 +1,4 @@
1
1
  import type { Loop } from "flo-boolean";
2
- import type { LlRbTree } from "flo-ll-rb-tree";
3
2
  import type { MatMeta } from "../../mat/mat-meta.js";
4
3
  import { CpNode } from "../../cp-node/cp-node.js";
5
4
  import { getAllOnLoop } from "../../cp-node/fs/get-all-on-loop.js";
@@ -1,6 +1,4 @@
1
- import { drawFs } from 'flo-draw';
2
- import { CpNode } from '../../../cp-node/cp-node.js';
3
- import { CpNodeFs } from '../../../cp-node/cp-node-fs.js';
1
+ import type { CpNode } from '../../../cp-node/cp-node.js';
4
2
  import { getMatCurveToNext } from '../../../cp-node/fs/get-mat-curve-to-next.js';
5
3
  import { isTerminating } from '../../../cp-node/fs/is-terminating.js';
6
4
  import { drawBeziersAsSinglePath } from '../draw/draw-beziers-as-single-path.js';
@@ -1,8 +1,7 @@
1
-
1
+ import type { CpNode } from '../../../cp-node/cp-node.js';
2
2
  import { drawFs } from 'flo-draw';
3
3
  import { scaleCircle } from '../../../geometry/circle.js';
4
- import { CpNode } from '../../../cp-node/cp-node.js';
5
- import { CpNodeFs } from '../../../cp-node/cp-node-fs.js';
4
+ import { getAllOnCircle } from '../../../cp-node/fs/get-all-on-circle.js';
6
5
 
7
6
 
8
7
  /** @internal */
@@ -19,7 +18,7 @@ function drawCpNode(
19
18
  );
20
19
  const { center: c, radius: r } = circle;
21
20
 
22
- const poss = CpNodeFs.getAllOnCircle(cpNode)
21
+ const poss = getAllOnCircle(cpNode)
23
22
  .map(cpNode => cpNode.pointOnShape)
24
23
 
25
24
  const { dot, circle: drawCircle, crossHair } = drawFs;
@@ -1,7 +1,7 @@
1
+ import type { CpNode } from '../../../cp-node/cp-node.js';
1
2
  import { drawFs } from 'flo-draw';
2
- import { CpNodeFs } from '../../../cp-node/cp-node-fs.js';
3
- import { CpNode } from '../../../cp-node/cp-node.js';
4
3
  import { drawCirclePercent } from './draw-circle-percent.js';
4
+ import { getAllOnCircle } from '../../../cp-node/fs/get-all-on-circle.js';
5
5
 
6
6
 
7
7
  /** @internal */
@@ -22,7 +22,7 @@ function drawLeaves(
22
22
 
23
23
  const $center = [drawCirclePercent(g, c, 0.5, 'pinker thin5 nofill')];
24
24
 
25
- const poss = CpNodeFs.getAllOnCircle(cpNode)
25
+ const poss = getAllOnCircle(cpNode)
26
26
  .map(cpNode => cpNode.pointOnShape);
27
27
 
28
28
  const $ls: SVGElement[] = [];
@@ -1,11 +1,8 @@
1
+ import type { Mat } from '../../../mat/mat.js';
1
2
  import { drawFs } from 'flo-draw';
2
- import { Mat } from '../../../mat/mat.js';
3
3
  import { traverseEdges } from '../../../cp-node/fs/traverse-edges.js';
4
4
  import { getMatCurveToNext } from '../../../cp-node/fs/get-mat-curve-to-next.js';
5
- import { CpNodeFs } from '../../../cp-node/cp-node-fs.js';
6
-
7
-
8
- const { isTerminating } = CpNodeFs;
5
+ import { isTerminating } from '../../../cp-node/fs/is-terminating.js';
9
6
 
10
7
 
11
8
  const altClasses = [
@@ -1,6 +1,6 @@
1
- import { toCubic, evalDeCasteljau } from 'flo-bezier3';
1
+ import type { PointOnShape } from '../../../point-on-shape/point-on-shape.js';
2
+ import { evalDeCasteljau } from 'flo-bezier3';
2
3
  import { drawFs } from 'flo-draw';
3
- import { PointOnShape } from '../../../point-on-shape/point-on-shape.js';
4
4
 
5
5
 
6
6
  /** @internal */
@@ -1,7 +1,7 @@
1
+ import type { CpNode } from '../../../cp-node/cp-node.js';
1
2
  import { drawFs } from 'flo-draw';
2
3
  import { scaleCircle } from '../../../geometry/circle.js';
3
- import { CpNode } from '../../../cp-node/cp-node.js';
4
- import { CpNodeFs } from '../../../cp-node/cp-node-fs.js';
4
+ import { getAllOnCircle } from '../../../cp-node/fs/get-all-on-circle.js';
5
5
 
6
6
 
7
7
  /** @internal */
@@ -20,7 +20,7 @@ function drawThreeProng(
20
20
  const { center: c, radius: r } = circle;
21
21
 
22
22
  // const poss = threeProng.poss;
23
- const poss = CpNodeFs.getAllOnCircle(threeProng)
23
+ const poss = getAllOnCircle(threeProng)
24
24
  .map(cpNode => cpNode.pointOnShape)
25
25
 
26
26
  const { dot, circle: drawCircle, crossHair } = drawFs;
@@ -1,8 +1,5 @@
1
+ import type { CpNode } from '../../../cp-node/cp-node.js';
1
2
  import { drawFs } from 'flo-draw';
2
- import { CpNode } from '../../../cp-node/cp-node.js';
3
- import { CpNodeFs } from '../../../cp-node/cp-node-fs.js';
4
-
5
- const { getAllOnCircle } = CpNodeFs;
6
3
 
7
4
 
8
5
  /** @internal */
@@ -1,4 +1,11 @@
1
- const u = Number.EPSILON / 2;
1
+
2
+ /** `2 * 2^-53` -> 2x the standard round-of unit `=== Number.EPSILON` */
3
+ const eps = Number.EPSILON;
4
+
5
+ /** `2^-53` -> the standard round-of unit `=== eps/2` */
6
+ const u = eps / 2;
7
+
8
+ /** `2^-106` -> the standard round-of unit for double-double precision `=== (eps/2)**2` */
2
9
  const uu = u*u;
3
10
 
4
11
 
@@ -38,4 +45,4 @@ function γγ(n: number): number {
38
45
  }
39
46
 
40
47
 
41
- export { γ, γγ }
48
+ export { γ, γγ, u, uu, eps }
@@ -50,11 +50,7 @@ function add1Prong(
50
50
  return;
51
51
  }
52
52
 
53
- const { anyFailed, cpNodes } = addToCpTree(false, false, circle, [-0.5, +0.5], meta, [pos, pos]);
54
-
55
- // if (typeof _debug_ !== 'undefined') {
56
- // _debug_.generated.elems.oneProng.push(cpNodes);
57
- // }
53
+ addToCpTree(false, false, circle, [-0.5, +0.5], meta, [pos, pos]);
58
54
  }
59
55
 
60
56
 
@@ -83,11 +83,6 @@ function find2Prong(
83
83
  const xy2 = reduceRadius(maxCoordPowerOf2, curvePieces, y, nnorm);
84
84
  const xy = sqrt(xy2);
85
85
 
86
- if (for1Prong && rO < (1 - oneProngTolerance)*xy) {
87
- add1Prong(meta, rO, xO, yPos);
88
- return undefined;
89
- }
90
-
91
86
  const l = sqrt(nnorm[0]**2 + nnorm[1]**2);
92
87
  xO = [y[0] + nnorm[0]/l*xy, y[1] + nnorm[1]/l*xy];
93
88
 
@@ -110,6 +105,12 @@ function find2Prong(
110
105
  }
111
106
 
112
107
  const { x, d, curve, s } = antipodalPoints[0];
108
+
109
+ if (for1Prong && rO < (1 - oneProngTolerance)*d) {
110
+ add1Prong(meta, rO, xO, yPos);
111
+ return undefined;
112
+ }
113
+
113
114
  const z: PrePointOnShape = {
114
115
  curve, t: s, isSource: false,
115
116
  p: toP(curve.ps, s)
@@ -126,7 +127,7 @@ function find2Prong(
126
127
  // The lines below eliminate cases where the found 2-prong is too
127
128
  // close to a one-prong
128
129
  const squaredSeperationTolerance = max(
129
- calcSeperationTolerance(rO, sqrt(xz), 2**2*errorTolerance),
130
+ calcSeperationTolerance(rO, sqrt(xz), (2**2)*errorTolerance),
130
131
  minSquaredSeperationTolerance
131
132
  );
132
133
  if (yz <= squaredSeperationTolerance) {