flo-mat 4.0.1 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) 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/browser/index.js +1153 -1205
  4. package/browser/index.min.js +1 -1
  5. package/node/closest-boundary-point/foot-and-endpoint-info.d.ts +0 -3
  6. package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +1 -1
  7. package/node/closest-boundary-point/get-close-boundary-points-certified.js +2 -2
  8. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  9. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.d.ts +1 -2
  10. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +34 -24
  11. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
  12. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.d.ts +1 -1
  13. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js +6 -9
  14. package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js.map +1 -1
  15. package/node/cp-node/fs/insert-cp-node.d.ts +2 -2
  16. package/node/cp-node/fs/insert-cp-node.js.map +1 -1
  17. package/node/cp-node/fs/is-order-correct.d.ts +2 -2
  18. package/node/cp-node/fs/is-order-correct.js.map +1 -1
  19. package/node/cp-node/fs/traverse-cp.js.map +1 -1
  20. package/node/cp-node/fs/traverse-vertices.d.ts +1 -1
  21. package/node/cp-node/fs/traverse-vertices.js.map +1 -1
  22. package/node/debug/functions/draw-elem/draw-branch.d.ts +1 -1
  23. package/node/debug/functions/draw-elem/draw-branch.js.map +1 -1
  24. package/node/debug/functions/draw-elem/draw-cp-node.d.ts +1 -1
  25. package/node/debug/functions/draw-elem/draw-cp-node.js +2 -2
  26. package/node/debug/functions/draw-elem/draw-cp-node.js.map +1 -1
  27. package/node/debug/functions/draw-elem/draw-leaves.d.ts +1 -1
  28. package/node/debug/functions/draw-elem/draw-leaves.js +2 -2
  29. package/node/debug/functions/draw-elem/draw-leaves.js.map +1 -1
  30. package/node/debug/functions/draw-elem/draw-mat.d.ts +1 -1
  31. package/node/debug/functions/draw-elem/draw-mat.js +1 -2
  32. package/node/debug/functions/draw-elem/draw-mat.js.map +1 -1
  33. package/node/debug/functions/draw-elem/draw-min-y.d.ts +1 -1
  34. package/node/debug/functions/draw-elem/draw-min-y.js.map +1 -1
  35. package/node/debug/functions/draw-elem/draw-three-prong.d.ts +1 -1
  36. package/node/debug/functions/draw-elem/draw-three-prong.js +2 -2
  37. package/node/debug/functions/draw-elem/draw-three-prong.js.map +1 -1
  38. package/node/debug/functions/draw-elem/draw-vertex.d.ts +1 -1
  39. package/node/debug/functions/draw-elem/draw-vertex.js +0 -2
  40. package/node/debug/functions/draw-elem/draw-vertex.js.map +1 -1
  41. package/node/error-analysis/gamma.d.ts +32 -0
  42. package/node/error-analysis/gamma.js +39 -0
  43. package/node/error-analysis/gamma.js.map +1 -0
  44. package/node/find-2-prong/find-2-prong.js +5 -5
  45. package/node/find-2-prong/find-2-prong.js.map +1 -1
  46. package/node/find-2-prong/get-medial/get-closest-points.js +27 -23
  47. package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -1
  48. package/node/find-3-prong/calc-better-x.d.ts +1 -1
  49. package/node/find-3-prong/calc-better-x.js +6 -4
  50. package/node/find-3-prong/calc-better-x.js.map +1 -1
  51. package/node/find-3-prong/calc-initial-3-prong-center.d.ts +1 -1
  52. package/node/find-3-prong/calc-initial-3-prong-center.js +4 -3
  53. package/node/find-3-prong/calc-initial-3-prong-center.js.map +1 -1
  54. package/node/find-3-prong/find-3-prong-for-delta3s.js +22 -5
  55. package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
  56. package/node/find-3-prong/find-and-add-3-prong.d.ts +2 -2
  57. package/node/find-3-prong/find-and-add-3-prong.js +15 -0
  58. package/node/find-3-prong/find-and-add-3-prong.js.map +1 -1
  59. package/node/find-3-prong/find-and-add-3-prongs-on-loop.js +8 -21
  60. package/node/find-3-prong/find-and-add-3-prongs-on-loop.js.map +1 -1
  61. package/node/find-3-prong/find-and-add-3-prongs.d.ts +1 -4
  62. package/node/find-3-prong/find-and-add-3-prongs.js +1 -2
  63. package/node/find-3-prong/find-and-add-3-prongs.js.map +1 -1
  64. package/node/find-3-prong/get-closest-points.d.ts +1 -1
  65. package/node/find-3-prong/get-closest-points.js +2 -2
  66. package/node/find-3-prong/get-closest-points.js.map +1 -1
  67. package/node/find-3-prong/timed-cc.d.ts +3 -0
  68. package/node/find-3-prong/timed-cc.js +5 -0
  69. package/node/find-3-prong/timed-cc.js.map +1 -0
  70. package/node/find-mat/create-initial-cp-tree.d.ts +2 -2
  71. package/node/find-mat/create-initial-cp-tree.js +2 -2
  72. package/node/find-mat/create-initial-cp-tree.js.map +1 -1
  73. package/node/find-mat/find-mat.d.ts +4 -4
  74. package/node/find-mat/find-mat.js.map +1 -1
  75. package/node/find-mat/find-mats.js +2 -2
  76. package/node/find-mat/find-mats.js.map +1 -1
  77. package/node/find-mat/get-meta.d.ts +2 -2
  78. package/node/find-mat/get-meta.js +1 -0
  79. package/node/find-mat/get-meta.js.map +1 -1
  80. package/node/index.d.ts +1 -0
  81. package/node/index.js +1 -0
  82. package/node/index.js.map +1 -1
  83. package/node/mat/create-new-cp-trees.d.ts +2 -2
  84. package/node/mat/create-new-cp-trees.js +2 -2
  85. package/node/mat/create-new-cp-trees.js.map +1 -1
  86. package/node/mat/get-cp-node-to-left-or-same.d.ts +2 -2
  87. package/node/mat/get-cp-node-to-left-or-same.js +2 -1
  88. package/node/mat/get-cp-node-to-left-or-same.js.map +1 -1
  89. package/node/mat/mat-meta.d.ts +2 -2
  90. package/node/point-on-shape/get-osculating-circle.js +2 -1
  91. package/node/point-on-shape/get-osculating-circle.js.map +1 -1
  92. package/package.json +5 -6
  93. package/src/closest-boundary-point/foot-and-endpoint-info.ts +0 -3
  94. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +0 -2
  95. package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +41 -27
  96. package/src/closest-boundary-point/root-interval-to-distance-squared-interval.ts +5 -10
  97. package/src/cp-node/fs/insert-cp-node.ts +2 -2
  98. package/src/cp-node/fs/is-order-correct.ts +2 -2
  99. package/src/cp-node/fs/traverse-cp.ts +1 -1
  100. package/src/cp-node/fs/traverse-vertices.ts +1 -2
  101. package/src/debug/functions/check-ordering.ts +0 -1
  102. package/src/debug/functions/draw-elem/draw-branch.ts +1 -3
  103. package/src/debug/functions/draw-elem/draw-cp-node.ts +3 -4
  104. package/src/debug/functions/draw-elem/draw-leaves.ts +3 -3
  105. package/src/debug/functions/draw-elem/draw-mat.ts +2 -5
  106. package/src/debug/functions/draw-elem/draw-min-y.ts +2 -2
  107. package/src/debug/functions/draw-elem/draw-three-prong.ts +3 -3
  108. package/src/debug/functions/draw-elem/draw-vertex.ts +1 -4
  109. package/src/error-analysis/gamma.ts +9 -2
  110. package/src/find-2-prong/find-2-prong.ts +7 -6
  111. package/src/find-2-prong/get-medial/get-closest-points.ts +24 -26
  112. package/src/find-3-prong/calc-better-x.ts +7 -4
  113. package/src/find-3-prong/calc-initial-3-prong-center.ts +2 -3
  114. package/src/find-3-prong/find-3-prong-for-delta3s.ts +23 -5
  115. package/src/find-3-prong/find-and-add-3-prong.ts +18 -4
  116. package/src/find-3-prong/find-and-add-3-prongs-on-loop.ts +7 -23
  117. package/src/find-3-prong/find-and-add-3-prongs.ts +5 -3
  118. package/src/find-3-prong/get-closest-points.ts +0 -2
  119. package/src/find-3-prong/timed-cc.ts +9 -0
  120. package/src/find-mat/create-initial-cp-tree.ts +3 -3
  121. package/src/find-mat/find-mat.ts +5 -6
  122. package/src/find-mat/find-mats.ts +4 -2
  123. package/src/find-mat/get-meta.ts +3 -3
  124. package/src/index.ts +2 -1
  125. package/src/mat/create-new-cp-trees.ts +3 -3
  126. package/src/mat/get-cp-node-to-left-or-same.ts +4 -3
  127. package/src/mat/mat-meta.ts +2 -2
  128. package/src/point-on-shape/get-osculating-circle.ts +2 -1
  129. package/wallaby.mjs +1 -0
  130. package/node/closest-boundary-point/get-p-from-box.d.ts +0 -3
  131. package/node/closest-boundary-point/get-p-from-box.js +0 -11
  132. package/node/closest-boundary-point/get-p-from-box.js.map +0 -1
@@ -4,7 +4,7 @@ import type { PrePointOnShape } from "../../point-on-shape/point-on-shape.js";
4
4
  import type { AntipodalPoint } from './antipodal-point.js';
5
5
  import { lengthSquared } from "flo-vector2d";
6
6
  import { roots, deflate, Horner } from 'flo-poly';
7
- import { evalDeCasteljau, getMedialPointCoeffs, getMedialPointCoeffsBez0 } from 'flo-bezier3';
7
+ import { evalDeCasteljau, getMedialPointCoeffs, getMedialPointCoeffsBez0, getMedialPointCoeffsBez2_SameCurve, getMedialPointCoeffsBez3_SameCurve } from 'flo-bezier3';
8
8
 
9
9
  const { sqrt, abs, max } = Math;
10
10
 
@@ -31,30 +31,24 @@ function getClosestPoint(
31
31
  const { ps } = curve;
32
32
  const { curve: touchedCurve, t, p: y } = yPos;
33
33
 
34
- const shouldDeflate = angle === 0 && curve === touchedCurve;
34
+ const isTouched = curve === touchedCurve;
35
+ const shouldDeflate = angle === 0 && isTouched;
35
36
 
36
37
  const infos: AntipodalPoint[] = [];
37
- // let onePushed = false;
38
38
  let startPushed = false;
39
39
  let endPushed = false;
40
40
 
41
41
  let ss: RootInterval[];
42
- if (tS !== tE) {
43
- const { A, B, C, D, H } = getMedialPointCoeffs(y, nnorm, ps);
44
-
45
- const def = shouldDeflate ? deflate(H, t!) : undefined;
46
-
47
- const def2 = for1Prong && shouldDeflate
48
- ? deflate(def!, t!)
49
- : undefined;
50
-
51
- const def3 = for1Prong && shouldDeflate
52
- ? deflate(def2!, t!)
53
- : undefined;
54
-
55
- const pDd = def3 ?? def ?? H;
42
+ if (tS !== tE &&
43
+ !(shouldDeflate && ps.length === 2) &&
44
+ !(isTouched && ps.length === 3 && for1Prong)) {
45
+ const { A, B, H } = shouldDeflate
46
+ ? ps.length === 3
47
+ ? getMedialPointCoeffsBez2_SameCurve(t,nnorm,ps)
48
+ : getMedialPointCoeffsBez3_SameCurve(t,nnorm,ps)
49
+ : getMedialPointCoeffs(y, nnorm, ps);
56
50
 
57
- ss = roots(pDd, tS, tE) || [];
51
+ ss = roots(H, tS, tE) || [];
58
52
  //-----------------------
59
53
 
60
54
  for (let i=0; i<ss.length; i++) {
@@ -65,23 +59,27 @@ function getClosestPoint(
65
59
  }
66
60
 
67
61
  if (sE < tS || sS > tE) { continue; } // outside curve piece
62
+ if (sS < 0) { continue; } // outside curve piece
68
63
 
69
- const s = _s < 0 ? 0 : _s > 1 ? 1 : _s; // clip to [0,1]
64
+ // clip to [0,1]
65
+ const s = sE > 1 ? 1 : _s;
70
66
 
71
67
  //-----------------------
72
68
  const AS = Horner(A, s);
73
69
  const BS = Horner(B, s);
74
- const CS = Horner(C, s);
75
- const DS = Horner(D, s);
70
+ // const CS = Horner(C, s);
71
+ // const DS = Horner(D, s);
76
72
 
77
73
  const _AS = abs(AS);
78
- const _CS = abs(CS);
74
+ // const _CS = abs(CS);
79
75
 
80
- if (max(_AS, _CS) < 2**-40) { continue; }
76
+ // if (max(_AS, _CS) < 2**-40) { continue; }
77
+ if (max(_AS) < 2**-40) { continue; }
81
78
 
82
- const w = _AS > _CS
83
- ? -BS / AS
84
- : -DS / CS; // alternative
79
+ // const w = _AS > _CS
80
+ // ? -BS / AS
81
+ // : -DS / CS; // alternative
82
+ const w = -BS / AS;
85
83
 
86
84
  if (w <= 0) {
87
85
  // If `w` is negative the circle radius is negative -> discard
@@ -1,7 +1,9 @@
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 { getClosestPoints } from './get-closest-points.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
6
+ import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
5
7
 
6
8
 
7
9
  /**
@@ -19,7 +21,6 @@ import { getClosestPoints } from './get-closest-points.js';
19
21
  * @internal
20
22
  */
21
23
  function calcBetterX(
22
- maxCoordPowerOf2: number,
23
24
  curvePiece3s: CurvePiece[][],
24
25
  x: number[],
25
26
  vectorToZeroV: number[]): {
@@ -40,7 +41,9 @@ function calcBetterX(
40
41
  const shift = scale(vectorToZeroV, nu);
41
42
  newX = translate(shift, x);
42
43
 
43
- newPoss = getClosestPoints(maxCoordPowerOf2, newX, curvePiece3s);
44
+ newPoss = curvePiece3s.map(curvePieces =>
45
+ getCloseBoundaryPointsCertified(curvePieces, x)[0]
46
+ );
44
47
 
45
48
  // Point of zero V
46
49
  const newCircleCenter = circumCenter(newPoss.map(pos => pos!.p));
@@ -1,6 +1,7 @@
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';
3
+ // import { circumCenter } from 'flo-vector2d';
4
+ import { circumCenter } from './timed-cc.js'; // TODO - testing - restore
4
5
  import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
5
6
 
6
7
 
@@ -16,7 +17,6 @@ import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-c
16
17
  * @internal
17
18
  */
18
19
  function calcInitial3ProngCenter(
19
- maxCoordPowerOf2: number,
20
20
  δ3s: CpNode[][],
21
21
  curvePiece3s: CurvePiece[][]) {
22
22
 
@@ -24,7 +24,6 @@ function calcInitial3ProngCenter(
24
24
  const twoProngCircleCenter = circle.center;
25
25
 
26
26
  const pos = getCloseBoundaryPointsCertified(
27
- maxCoordPowerOf2,
28
27
  curvePiece3s[1],
29
28
  twoProngCircleCenter
30
29
  )[0];
@@ -2,7 +2,9 @@ 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';
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
6
8
  import { tangent } from 'flo-bezier3';
7
9
  import { calcInitial3ProngCenter } from './calc-initial-3-prong-center.js';
8
10
  import { getClosestPoints } from './get-closest-points.js';
@@ -67,16 +69,33 @@ function find3ProngForDelta3s(
67
69
 
68
70
  if (isSharp(δ3s[0][0])) { return undefined; }
69
71
 
72
+ // TODO
73
+ //----------------------------
74
+ // const l1 = curvePiece3s[0].length;
75
+ // const l2 = curvePiece3s[1].length;
76
+ // const l3 = curvePiece3s[2].length;
77
+ // if (l1 === 1 && l2 == 1 && l3 === 1) {
78
+ // // console.log('aaa');
79
+ // const A = curvePiece3s[0][0].curve.ps;
80
+ // const B = curvePiece3s[1][0].curve.ps;
81
+ // const C = curvePiece3s[2][0].curve.ps;
82
+
83
+ // console.log(A.length, B.length, C.length);
84
+ // } else {
85
+ // // console.log('bbb');
86
+ // }
87
+ //----------------------------
88
+
70
89
 
71
90
  let poss: PrePointOnShape[] = undefined!;
72
91
  let j = 0; // Safeguard for slow convergence
73
- let x = calcInitial3ProngCenter(maxCoordPowerOf2, δ3s, curvePiece3s);
92
+ let x = calcInitial3ProngCenter(δ3s, curvePiece3s);
74
93
 
75
94
  let tolerance = Infinity;
76
95
  while (tolerance > TOLERANCE && j < MAX_ITERATIONS) {
77
96
  j++;
78
97
 
79
- poss = getClosestPoints(maxCoordPowerOf2, x, curvePiece3s);
98
+ poss = getClosestPoints(x, curvePiece3s);
80
99
  if (!Number.isFinite(x[0]) || !Number.isFinite(x[1])) {
81
100
 
82
101
  // FUTURE - the code can be cleaned up and sped up a lot if we don't
@@ -97,7 +116,7 @@ function find3ProngForDelta3s(
97
116
  // loop. This check, for instance, would be eliminated completely.
98
117
  return undefined;
99
118
  }
100
- const upds = calcBetterX(maxCoordPowerOf2, curvePiece3s, x, vectorToZeroV);
119
+ const upds = calcBetterX(curvePiece3s, x, vectorToZeroV);
101
120
  x = upds.newX;
102
121
  poss = upds.newPoss;
103
122
 
@@ -169,7 +188,6 @@ function find3ProngForDelta3s(
169
188
  const closestDs = [];
170
189
  for (let i=0; i<curvePiecess.length; i++) {
171
190
  const pos = getCloseBoundaryPointsCertified(
172
- maxCoordPowerOf2,
173
191
  curvePiecess[i],
174
192
  x
175
193
  )[0];
@@ -1,14 +1,13 @@
1
- import { CpNode } from '../cp-node/cp-node.js';
1
+ import type { CpNode } from '../cp-node/cp-node.js';
2
+ import type { MatMeta } from '../mat/mat-meta.js';
2
3
  import { calcPosOrder } from '../point-on-shape/calc-pos-order.js';
3
4
  import { find3Prong } from './find-3-prong.js';
4
- import { MatMeta } from '../mat/mat-meta.js';
5
5
  import { addToCpTree } from '../mat/add-to-cp-tree.js';
6
6
  import { getCloseByCpIfExist } from '../mat/get-closeby-cp-if-exist.js';
7
- import { getRealProngCount } from '../cp-node/fs/get-real-prong-count.js';
8
- import { removeVertex } from '../vertex/remove-vertex.js';
9
7
  import { getProngCount } from '../cp-node/fs/get-prong-count.js';
10
8
 
11
9
 
10
+ let ii = 0;
12
11
  /**
13
12
  * @internal
14
13
  * Finds and add a 3-prong MAT circle to the given shape.
@@ -25,6 +24,21 @@ function findAndAdd3Prong(
25
24
  for (const visitedCp of visitedCps) {
26
25
  δs.push([visitedCp, visitedCp.next]);
27
26
  }
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
+ //-------------------------
28
42
 
29
43
  const threeProngInfo = find3Prong(δs, meta.maxCoordPowerOf2);
30
44
 
@@ -3,9 +3,6 @@ import type { MatMeta } from '../mat/mat-meta.js';
3
3
  import { findAndAdd3Prongs } from './find-and-add-3-prongs.js';
4
4
  import { getAllOnLoop } from '../cp-node/fs/get-all-on-loop.js';
5
5
  import { removeVertex } from '../vertex/remove-vertex.js';
6
- // import { LlRbTree } from 'flo-ll-rb-tree';
7
- // import { Loop } from 'flo-boolean';
8
- // import { drawFs } from 'flo-draw';
9
6
  import { getAllOnCircle } from '../cp-node/fs/get-all-on-circle.js';
10
7
 
11
8
 
@@ -28,7 +25,6 @@ function findAndAdd3ProngsOnLoop(
28
25
  reLoop = false;
29
26
  const cpNodeSet = new Set(getAllOnLoop(cpStart));
30
27
  for (const cpNode of cpNodeSet) {
31
-
32
28
  const { closeBysFor3Prong, addedCpNodes } =
33
29
  findAndAdd3Prongs(meta, cpNode);
34
30
 
@@ -46,7 +42,7 @@ function findAndAdd3ProngsOnLoop(
46
42
  cpStart = getFirstItemOfSet(cpNodeGoodSet)!;
47
43
  }
48
44
 
49
- return getFirstItemOfSet(cpNodeGoodSet);
45
+ return cpStart;
50
46
  }
51
47
 
52
48
 
@@ -60,30 +56,18 @@ function getFirstItemOfSet<T>(set: Set<T>) {
60
56
  }
61
57
 
62
58
 
63
- // Unfortunately O(n) until Javascript gives us the simple ability to
64
- // retrieve the first or last item of a set
65
- function getLastItemOfSet<T>(set: Set<T>) {
66
- let item;
67
- for (item of set) {}
68
-
69
- return item;
70
- }
71
-
72
-
73
59
  function replaceCloseBys(
74
- // cpTrees: Map<Loop,LlRbTree<CpNode>>,
75
60
  meta: MatMeta,
76
61
  closeBysFor3Prong: CpNode[],
77
62
  cpNodeSet: Set<CpNode>,
78
63
  cpNodeGoodSet: Set<CpNode>) {
79
64
 
80
- for (const closeBy of [closeBysFor3Prong[0]]) {
81
- getAllOnCircle(closeBy).forEach(v => {
82
- cpNodeSet.delete(v);
83
- cpNodeGoodSet.delete(v);
84
- });
85
- removeVertex(closeBy, meta);
86
- }
65
+ const closeBy = closeBysFor3Prong[0];
66
+ getAllOnCircle(closeBy).forEach(v => {
67
+ cpNodeSet.delete(v);
68
+ cpNodeGoodSet.delete(v);
69
+ });
70
+ removeVertex(closeBy, meta);
87
71
  }
88
72
 
89
73
 
@@ -26,14 +26,16 @@ let ii = 0;
26
26
  */
27
27
  function findAndAdd3Prongs(
28
28
  meta: MatMeta,
29
- cpStart: CpNode) {
29
+ cpStart: CpNode): {
30
+ closeBysFor3Prong: CpNode[] | undefined;
31
+ addedCpNodes: CpNode[][];
32
+ } {
30
33
 
31
34
  if (isPosSharpCorner(cpStart.pointOnShape)) {
32
35
  return { closeBysFor3Prong: undefined, addedCpNodes: [] };
33
36
  }
34
37
 
35
38
  const addedCpNodes: CpNode[][] = [];
36
- let closeBysFor3Prong: CpNode[] | undefined = undefined;
37
39
  do {
38
40
  if (cpStart === undefined) { continue; }
39
41
  const visitedCps = traverseCp(cpStart);
@@ -54,7 +56,7 @@ function findAndAdd3Prongs(
54
56
  }
55
57
  } while (true);
56
58
 
57
- return { closeBysFor3Prong, addedCpNodes };
59
+ return { closeBysFor3Prong: undefined, addedCpNodes };
58
60
  }
59
61
 
60
62
 
@@ -10,13 +10,11 @@ import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-c
10
10
  * @internal
11
11
  */
12
12
  function getClosestPoints(
13
- maxCoordPowerOf2: number,
14
13
  x: number[],
15
14
  curvePiece3s: CurvePiece[][]) {
16
15
 
17
16
  return curvePiece3s.map(curvePieces => {
18
17
  return getCloseBoundaryPointsCertified(
19
- maxCoordPowerOf2,
20
18
  curvePieces,
21
19
  x
22
20
  )[0];
@@ -0,0 +1,9 @@
1
+ import { circumCenter } from 'flo-vector2d';
2
+ import { timeFunctionCalls } from '../utils/time-function-call.js';
3
+
4
+
5
+ // const timeCircumCenter = timeFunctionCalls(circumCenter);
6
+ const timeCircumCenter = circumCenter;
7
+
8
+
9
+ export { timeCircumCenter as circumCenter }
@@ -2,7 +2,7 @@ import type { Loop } from 'flo-boolean';
2
2
  import type { CpNode } from '../cp-node/cp-node.js';
3
3
  import type { PointOnShape, PrePointOnShape } from '../point-on-shape/point-on-shape.js';
4
4
  import type { Mutable } from '../utils/mutable.js';
5
- import { LlRbTree } from 'flo-ll-rb-tree';
5
+ import { RbTree } from 'flo-ll-rb-tree';
6
6
  import { insertCpNode } from '../cp-node/fs/insert-cp-node.js';
7
7
  import { cpNodeComparator } from '../cp-node/fs/cp-node-comparator.js';
8
8
 
@@ -24,10 +24,10 @@ function createInitialCpTree(
24
24
  sharpCornerss: PrePointOnShape[][],
25
25
  lastInsertId: { id: number }) {
26
26
 
27
- const cpTrees: Map<Loop, LlRbTree<CpNode>> = new Map();
27
+ const cpTrees: Map<Loop, RbTree<CpNode>> = new Map();
28
28
 
29
29
  for (let k=0; k<sharpCornerss.length; k++) {
30
- const cpTree = new LlRbTree(cpNodeComparator, false);
30
+ const cpTree = new RbTree(cpNodeComparator);
31
31
  cpTrees.set(loops[k], cpTree);
32
32
 
33
33
  const sharpCorners = sharpCornerss[k];
@@ -1,10 +1,11 @@
1
1
  /** @internal */
2
2
  declare const _debug_: Debug;
3
3
 
4
- import { LlRbTree } from 'flo-ll-rb-tree';
5
- import { Debug } from '../debug/debug.js';
6
- import { CpNode } from '../cp-node/cp-node.js';
7
- import { Loop } from 'flo-boolean';
4
+ import type { Debug } from '../debug/debug.js';
5
+ import type { CpNode } from '../cp-node/cp-node.js';
6
+ import type { Loop } from 'flo-boolean';
7
+ import type { MatOptions } from './mat-options.js';
8
+ import type { MatMeta } from '../mat/mat-meta.js';
8
9
  import { findAndAdd3ProngsOnLoop } from '../find-3-prong/find-and-add-3-prongs-on-loop.js';
9
10
  import { createInitialCpTree } from './create-initial-cp-tree.js';
10
11
  import { /*getPointToCpNode,*/ getPartialMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4, getPointToCpNode } from './get-meta.js';
@@ -15,8 +16,6 @@ import { getFor2ProngsOnLoop } from './get-for-2-prongs-on-loop.js';
15
16
  import { getFor1ProngsOnLoop } from './get-for-1-prongs-on-loop.js';
16
17
  import { findAndAddHoleClosing2Prongs } from '../find-2-prong/find-and-add-hole-closing-2-prongs.js';
17
18
  import { getShapeBounds } from '../svg/get-shape-bounds.js';
18
- import { MatOptions } from './mat-options.js';
19
- import { MatMeta } from '../mat/mat-meta.js';
20
19
 
21
20
 
22
21
  /**
@@ -6,6 +6,8 @@ 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
  const { ceil, log2 } = Math;
11
13
 
@@ -74,8 +76,8 @@ function findMats(
74
76
  mats.push(mat);
75
77
  }
76
78
 
77
- // console.log(structuredClone(find3Prong.getStats()));
78
- // find3Prong.resetStats();
79
+ // console.log(structuredClone(circumCenter.getStats()));
80
+ // circumCenter.resetStats();
79
81
 
80
82
  return mats;
81
83
  }
@@ -4,10 +4,10 @@ import type { Curve } from 'flo-boolean';
4
4
  import type { CpNode } from '../cp-node/cp-node.js';
5
5
  import type { TriMap } from '../utils/tri-map.js';
6
6
  import type { MatMeta } from '../mat/mat-meta.js';
7
- import { TriMapFs } from '../utils/tri-map.js';
7
+ // import { TriMapFs } from '../utils/tri-map.js';
8
8
  import { getBoundingHull, getBoundingBoxTight } from 'flo-bezier3';
9
9
  import { getBoundingBox$ } from '../geometry/get-bounding-box-.js';
10
- import { LlRbTree } from 'flo-ll-rb-tree';
10
+ import { RbTree } from 'flo-ll-rb-tree';
11
11
  import { getCorner } from '../corner/get-corner.js';
12
12
 
13
13
 
@@ -21,7 +21,7 @@ let timingStart: number;
21
21
  /** @internal */
22
22
  function getPointToCpNode(
23
23
  loops: Loop[],
24
- cpTrees: Map<Loop, LlRbTree<CpNode>>): TriMap<Loop,number,number,CpNode> {
24
+ cpTrees: Map<Loop, RbTree<CpNode>>): TriMap<Loop,number,number,CpNode> {
25
25
 
26
26
  timingStart = performance.now();
27
27
 
package/src/index.ts CHANGED
@@ -79,4 +79,5 @@ export { getMatCurvesBetween } from './cp-node/fs/get-mat-curves-between.js';
79
79
  export { getHoleClosers } from './cp-node/fs/get-hole-closers.js';
80
80
  export { getInitialDegAngleBetweenMatCurves } from './cp-node/fs/get-angle-between-mat-curves.js';
81
81
  export { getAllVertices } from './cp-node/fs/get-all-vertices.js';
82
- export { isTrivial } from './cp-node/fs/is-trivial.js';
82
+ export { isTrivial } from './cp-node/fs/is-trivial.js';
83
+ export { scaleCircle } from './geometry/circle.js';
@@ -1,6 +1,6 @@
1
1
  import type { Loop } from 'flo-boolean';
2
2
  import type { CpNode } from '../cp-node/cp-node.js';
3
- import { LlRbTree } from 'flo-ll-rb-tree';
3
+ import { RbTree } from 'flo-ll-rb-tree';
4
4
  import { cpNodeComparator } from '../cp-node/fs/cp-node-comparator.js';
5
5
  import { getAllOnLoop } from '../cp-node/fs/get-all-on-loop.js';
6
6
 
@@ -14,7 +14,7 @@ import { getAllOnLoop } from '../cp-node/fs/get-all-on-loop.js';
14
14
  function createNewCpTrees(
15
15
  cpNode: CpNode) {
16
16
 
17
- const cpTrees_: Map<Loop,LlRbTree<CpNode>> = new Map();
17
+ const cpTrees_: Map<Loop,RbTree<CpNode>> = new Map();
18
18
 
19
19
  getAllOnLoop(cpNode).forEach(createNewCpTree_);
20
20
 
@@ -22,7 +22,7 @@ function createNewCpTrees(
22
22
  const loop = cpNode.pointOnShape.curve.loop;
23
23
  let cpTree = cpTrees_.get(loop);
24
24
  if (!cpTree) {
25
- cpTree = new LlRbTree(cpNodeComparator, false);
25
+ cpTree = new RbTree(cpNodeComparator);
26
26
  cpTrees_.set(loop, cpTree);
27
27
  }
28
28
  cpTree.insert(cpNode);
@@ -1,6 +1,6 @@
1
1
  import type { PrePointOnShape } from '../point-on-shape/point-on-shape.js';
2
2
  import type { CpNode } from '../cp-node/cp-node.js';
3
- import { LlRbTree } from 'flo-ll-rb-tree';
3
+ import { RbTree } from 'flo-ll-rb-tree';
4
4
 
5
5
 
6
6
  /**
@@ -17,7 +17,7 @@ import { LlRbTree } from 'flo-ll-rb-tree';
17
17
  * @param order2
18
18
  */
19
19
  function getCpNodeToLeftOrSame(
20
- cpTree: LlRbTree<CpNode>,
20
+ cpTree: RbTree<CpNode>,
21
21
  pos: PrePointOnShape,
22
22
  order: number,
23
23
  order2: number): CpNode | undefined {
@@ -33,7 +33,8 @@ function getCpNodeToLeftOrSame(
33
33
  if (cps[0] === undefined || cps[1] === undefined) {
34
34
  // Smaller than all -> cptree.min() === cps[1].data OR
35
35
  // Larger than all -> cptree.max() === cps[0].data
36
- return cpTree.max(cpTree.root);
36
+ // return cpTree.max(cpTree.root);
37
+ return cpTree.getMaxNode()?.datum;
37
38
  }
38
39
 
39
40
  return cps[0].datum;
@@ -2,7 +2,7 @@ import type { Loop } from 'flo-boolean';
2
2
  import type { CpNode } from '../cp-node/cp-node.js';
3
3
  import type { Curve } from 'flo-boolean';
4
4
  import type { TriMap } from '../utils/tri-map.js';
5
- import { LlRbTree } from 'flo-ll-rb-tree';
5
+ import { RbTree } from 'flo-ll-rb-tree';
6
6
 
7
7
 
8
8
  interface MatMeta {
@@ -23,7 +23,7 @@ interface MatMeta {
23
23
  * `CpNode`s of the MAT by their compare order, i.e. their cyclic order
24
24
  * around the shape boundary.
25
25
  */
26
- readonly cpTrees: Map<Loop, LlRbTree<CpNode>>;
26
+ readonly cpTrees: Map<Loop, RbTree<CpNode>>;
27
27
  /** A map from a bezier and t value to a `PointOnShape` */
28
28
  // readonly pointToCpNode: TriMap<Loop,number,number,CpNode>;
29
29
  /**
@@ -22,7 +22,8 @@ function getOsculatingCircle(
22
22
 
23
23
  const minCurvature = 1/maxOsculatingCircleRadius;
24
24
 
25
- const k_ = -(ddCurvature(ps, t)[1]);
25
+ const kDd = ddCurvature(ps, t);
26
+ const k_ = -(kDd[0] + kDd[1]);
26
27
  const k = k_ < minCurvature ? minCurvature : k_;
27
28
 
28
29
  const [tx, ty] = norm;
package/wallaby.mjs CHANGED
@@ -6,6 +6,7 @@ export default function(wallaby) {
6
6
  'src/**/*.ts',
7
7
  'test/helpers/*.ts'
8
8
  ],
9
+
9
10
  tests: [
10
11
  'test/**/*.spec.ts'
11
12
  ],
@@ -1,3 +0,0 @@
1
- /** @internal */
2
- declare function getPFromBox(box: number[][]): number[];
3
- export { getPFromBox };
@@ -1,11 +0,0 @@
1
- /** @internal */
2
- function getPFromBox(box) {
3
- const tl = box[0];
4
- const br = box[1];
5
- return [
6
- (tl[0] + br[0]) / 2,
7
- (tl[1] + br[1]) / 2,
8
- ];
9
- }
10
- export { getPFromBox };
11
- //# sourceMappingURL=get-p-from-box.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-p-from-box.js","sourceRoot":"","sources":["../../src/closest-boundary-point/get-p-from-box.ts"],"names":[],"mappings":"AACA,gBAAgB;AAChB,SAAS,WAAW,CAAC,GAAe;IAChC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAClB,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAElB,OAAO;QACH,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC;QACjB,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,GAAC,CAAC;KACpB,CAAC;AACN,CAAC;AAGD,OAAO,EAAE,WAAW,EAAE,CAAA"}