flo-mat 3.0.6 → 3.0.9

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 (193) hide show
  1. package/__tests__/cp-node/fs/add-distance-from.spec.ts +7 -0
  2. package/__tests__/cp-node/fs/check-jsog-eql-calc.spec.ts +30 -0
  3. package/__tests__/cp-node/fs/clone.spec.ts +7 -0
  4. package/__tests__/cp-node/fs/cp-nodes-to-boundary-beziers.spec.ts +7 -0
  5. package/__tests__/cp-node/fs/create-cp-node.spec.ts +7 -0
  6. package/__tests__/cp-node/fs/enhance-cp-node.spec.ts +7 -0
  7. package/__tests__/cp-node/fs/find-first.spec.ts +7 -0
  8. package/__tests__/cp-node/fs/get-all-between.spec.ts +7 -0
  9. package/__tests__/cp-node/fs/get-all-on-circle.spec.ts +92 -0
  10. package/__tests__/cp-node/fs/get-all-on-loop.spec.ts +7 -0
  11. package/__tests__/cp-node/fs/get-all-vertices.spec.ts +7 -0
  12. package/__tests__/cp-node/fs/get-angle-between-mat-curves.spec.ts +7 -0
  13. package/__tests__/cp-node/fs/get-avg-speed.spec.ts +7 -0
  14. package/__tests__/cp-node/fs/get-boundary-bezier-parts-to-next.spec.ts +7 -0
  15. package/__tests__/cp-node/fs/get-boundary-beziers-between.spec.ts +7 -0
  16. package/__tests__/cp-node/fs/get-boundary-beziers-to-next.spec.ts +7 -0
  17. package/__tests__/cp-node/fs/get-boundary-distance-to-next.spec.ts +7 -0
  18. package/__tests__/cp-node/fs/get-branch-beziers.spec.ts +7 -0
  19. package/__tests__/cp-node/fs/get-branch.spec.ts +7 -0
  20. package/__tests__/cp-node/fs/get-children.spec.ts +7 -0
  21. package/__tests__/cp-node/fs/get-cp-node-ordering.spec.ts +7 -0
  22. package/__tests__/cp-node/fs/get-distance-between.spec.ts +7 -0
  23. package/__tests__/cp-node/fs/get-distance-to-next.spec.ts +7 -0
  24. package/__tests__/cp-node/fs/get-edge-direction.spec.ts +7 -0
  25. package/__tests__/cp-node/fs/get-first-exit.spec.ts +7 -0
  26. package/__tests__/cp-node/fs/get-hole-closers.spec.ts +7 -0
  27. package/__tests__/cp-node/fs/get-implied-boundary-bezier-between.spec.ts +7 -0
  28. package/__tests__/cp-node/fs/get-mat-curve-between.spec.ts +7 -0
  29. package/__tests__/cp-node/fs/get-mat-curve-to-next.spec.ts +7 -0
  30. package/__tests__/cp-node/fs/get-mat-curves-between.spec.ts +7 -0
  31. package/__tests__/cp-node/fs/get-non-terminating-on-circle.spec.ts +7 -0
  32. package/__tests__/cp-node/fs/get-prong-count.spec.ts +7 -0
  33. package/__tests__/cp-node/fs/get-real-prong-count.spec.ts +7 -0
  34. package/__tests__/cp-node/fs/get-salience.spec.ts +7 -0
  35. package/__tests__/cp-node/fs/get-smoothed-speed.spec.ts +7 -0
  36. package/__tests__/cp-node/fs/get-smoothed.spec.ts +7 -0
  37. package/__tests__/cp-node/fs/get-speed.spec.ts +7 -0
  38. package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +7 -0
  39. package/__tests__/cp-node/fs/get-vertex-forward-children.spec.ts +7 -0
  40. package/__tests__/cp-node/fs/insert-cp-node.spec.ts +7 -0
  41. package/__tests__/cp-node/fs/is-fully-terminating.spec.ts +7 -0
  42. package/__tests__/cp-node/fs/is-on-same-circle.spec.ts +7 -0
  43. package/__tests__/cp-node/fs/is-one-prong.spec.ts +7 -0
  44. package/__tests__/cp-node/fs/is-order-correct.spec.ts +7 -0
  45. package/__tests__/cp-node/fs/is-sharp.spec.ts +7 -0
  46. package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +7 -0
  47. package/__tests__/cp-node/fs/is-special.spec.ts +7 -0
  48. package/__tests__/cp-node/fs/is-terminating.spec.ts +7 -0
  49. package/__tests__/cp-node/fs/is-trivial.spec.ts +7 -0
  50. package/__tests__/cp-node/fs/is-two-prong.spec.ts +7 -0
  51. package/__tests__/cp-node/fs/is-vertex-special.spec.ts +7 -0
  52. package/__tests__/cp-node/fs/is-vertex.spec.ts +7 -0
  53. package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +7 -0
  54. package/__tests__/cp-node/fs/mat-dummys.ts +6716 -0
  55. package/__tests__/cp-node/fs/remove-cp-node.spec.ts +7 -0
  56. package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +7 -0
  57. package/__tests__/cp-node/fs/traverse-cp.spec.ts +7 -0
  58. package/__tests__/cp-node/fs/traverse-edges.spec.ts +7 -0
  59. package/__tests__/cp-node/fs/traverse-vertices.spec.ts +7 -0
  60. package/__tests__/lib-load.spec.ts +9 -10
  61. package/browser/index.js +259 -174
  62. package/browser/index.min.js +1 -1
  63. package/jest.config.cjs +32 -0
  64. package/node/corner/get-interface-ccw.js +0 -1
  65. package/node/corner/get-interface-ccw.js.map +1 -1
  66. package/node/cp-node/cp-node-fs.d.ts +43 -43
  67. package/node/cp-node/cp-node-fs.js +43 -43
  68. package/node/cp-node/cp-node.d.ts +27 -35
  69. package/node/cp-node/fs/clone.d.ts +3 -3
  70. package/node/cp-node/fs/clone.js +3 -3
  71. package/node/cp-node/fs/enhance-cp-node.d.ts +1 -5
  72. package/node/cp-node/fs/enhance-cp-node.js.map +1 -1
  73. package/node/cp-node/fs/get-all-between.d.ts +3 -3
  74. package/node/cp-node/fs/get-all-between.js +3 -3
  75. package/node/cp-node/fs/get-all-between.js.map +1 -1
  76. package/node/cp-node/fs/get-all-on-circle.d.ts +7 -1
  77. package/node/cp-node/fs/get-all-on-circle.js +11 -7
  78. package/node/cp-node/fs/get-all-on-circle.js.map +1 -1
  79. package/node/cp-node/fs/get-all-on-loop.d.ts +1 -1
  80. package/node/cp-node/fs/get-all-on-loop.js.map +1 -1
  81. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.d.ts +12 -3
  82. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js +22 -7
  83. package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js.map +1 -1
  84. package/node/cp-node/fs/get-boundary-beziers-between.d.ts +1 -1
  85. package/node/cp-node/fs/get-boundary-beziers-between.js.map +1 -1
  86. package/node/cp-node/fs/get-boundary-beziers-to-next.js.map +1 -1
  87. package/node/cp-node/fs/insert-cp-node.d.ts +3 -1
  88. package/node/cp-node/fs/insert-cp-node.js +12 -2
  89. package/node/cp-node/fs/insert-cp-node.js.map +1 -1
  90. package/node/cp-node/fs/is-fully-terminating.d.ts +7 -0
  91. package/node/cp-node/fs/is-fully-terminating.js +7 -0
  92. package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
  93. package/node/cp-node/fs/is-terminating.d.ts +1 -1
  94. package/node/cp-node/fs/remove-cp-node.d.ts +3 -4
  95. package/node/cp-node/fs/remove-cp-node.js +3 -1
  96. package/node/cp-node/fs/remove-cp-node.js.map +1 -1
  97. package/node/curve/curve.d.ts +18 -11
  98. package/node/find-2-prong/add-1-prong.js +1 -1
  99. package/node/find-2-prong/add-1-prong.js.map +1 -1
  100. package/node/find-2-prong/add-2-prong.js +9 -7
  101. package/node/find-2-prong/add-2-prong.js.map +1 -1
  102. package/node/find-2-prong/calc-seperation-tolerance.d.ts +8 -1
  103. package/node/find-2-prong/calc-seperation-tolerance.js +73 -59
  104. package/node/find-2-prong/calc-seperation-tolerance.js.map +1 -1
  105. package/node/find-2-prong/find-2-prong.js +2 -2
  106. package/node/find-2-prong/find-2-prong.js.map +1 -1
  107. package/node/find-2-prong/get-initial-bezier-pieces.d.ts +2 -3
  108. package/node/find-2-prong/get-initial-bezier-pieces.js +4 -1
  109. package/node/find-2-prong/get-initial-bezier-pieces.js.map +1 -1
  110. package/node/find-3-prong.ts/find-and-add-3-prong.js +1 -1
  111. package/node/find-3-prong.ts/find-and-add-3-prong.js.map +1 -1
  112. package/node/find-3-prong.ts/find-and-add-3-prongs-on-loop.d.ts +2 -2
  113. package/node/find-3-prong.ts/find-and-add-3-prongs-on-loop.js +8 -3
  114. package/node/find-3-prong.ts/find-and-add-3-prongs-on-loop.js.map +1 -1
  115. package/node/find-mat/create-initial-cp-tree.d.ts +7 -3
  116. package/node/find-mat/create-initial-cp-tree.js +7 -5
  117. package/node/find-mat/create-initial-cp-tree.js.map +1 -1
  118. package/node/find-mat/find-mat.d.ts +2 -1
  119. package/node/find-mat/find-mat.js +14 -4
  120. package/node/find-mat/find-mat.js.map +1 -1
  121. package/node/find-mat/get-meta.d.ts +5 -2
  122. package/node/find-mat/get-meta.js +15 -14
  123. package/node/find-mat/get-meta.js.map +1 -1
  124. package/node/index.d.ts +1 -1
  125. package/node/index.js +1 -1
  126. package/node/index.js.map +1 -1
  127. package/node/mat/add-to-cp-tree.d.ts +5 -6
  128. package/node/mat/add-to-cp-tree.js +5 -2
  129. package/node/mat/add-to-cp-tree.js.map +1 -1
  130. package/node/mat/get-branches.d.ts +7 -0
  131. package/node/mat/get-branches.js +7 -0
  132. package/node/mat/get-branches.js.map +1 -1
  133. package/node/mat/mat-meta.d.ts +8 -1
  134. package/node/mat/mat.d.ts +3 -3
  135. package/node/mat/simplify-mat.js +1 -1
  136. package/node/mat/simplify-mat.js.map +1 -1
  137. package/node/point-on-shape/compare-poss.d.ts +3 -3
  138. package/node/point-on-shape/compare-poss.js +3 -3
  139. package/node/point-on-shape/get-osculating-circle.d.ts +1 -1
  140. package/node/point-on-shape/get-osculating-circle.js +1 -1
  141. package/node/point-on-shape/point-on-shape.d.ts +1 -1
  142. package/node/point-on-shape/pos-to-human-string.d.ts +1 -1
  143. package/node/point-on-shape/pos-to-human-string.js +1 -1
  144. package/node/sat/to-scale-axis.d.ts +1 -1
  145. package/node/sat/to-scale-axis.js +1 -1
  146. package/node/vertex/remove-vertex.d.ts +3 -4
  147. package/node/vertex/remove-vertex.js +3 -2
  148. package/node/vertex/remove-vertex.js.map +1 -1
  149. package/package.json +9 -6
  150. package/src/corner/get-interface-ccw.ts +0 -1
  151. package/src/cp-node/cp-node-fs.ts +43 -43
  152. package/src/cp-node/cp-node.ts +27 -39
  153. package/src/cp-node/fs/clone.ts +3 -3
  154. package/src/cp-node/fs/enhance-cp-node.ts +0 -1
  155. package/src/cp-node/fs/get-all-between.ts +31 -28
  156. package/src/cp-node/fs/get-all-on-circle.ts +13 -8
  157. package/src/cp-node/fs/get-all-on-loop.ts +12 -10
  158. package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +39 -22
  159. package/src/cp-node/fs/get-boundary-beziers-between.ts +6 -2
  160. package/src/cp-node/fs/get-boundary-beziers-to-next.ts +6 -4
  161. package/src/cp-node/fs/insert-cp-node.ts +13 -2
  162. package/src/cp-node/fs/is-fully-terminating.ts +7 -0
  163. package/src/cp-node/fs/is-terminating.ts +1 -1
  164. package/src/cp-node/fs/remove-cp-node.ts +8 -4
  165. package/src/curve/curve.ts +19 -13
  166. package/src/debug/functions/check-ordering.ts +7 -3
  167. package/src/find-2-prong/add-1-prong.ts +1 -1
  168. package/src/find-2-prong/add-2-prong.ts +79 -74
  169. package/src/find-2-prong/calc-seperation-tolerance.ts +88 -78
  170. package/src/find-2-prong/find-2-prong.ts +2 -2
  171. package/src/find-2-prong/get-initial-bezier-pieces.ts +5 -1
  172. package/src/find-3-prong.ts/add-3-prong.ts +73 -70
  173. package/src/find-3-prong.ts/find-and-add-3-prong.ts +1 -1
  174. package/src/find-3-prong.ts/find-and-add-3-prongs-on-loop.ts +9 -8
  175. package/src/find-mat/create-initial-cp-tree.ts +10 -6
  176. package/src/find-mat/find-mat.ts +18 -5
  177. package/src/find-mat/get-meta.ts +36 -20
  178. package/src/get-curve/get-curve-between.ts +2 -2
  179. package/src/index.ts +1 -1
  180. package/src/mat/add-to-cp-tree.ts +18 -9
  181. package/src/mat/get-branches.ts +35 -28
  182. package/src/mat/mat-meta.ts +6 -1
  183. package/src/mat/mat.ts +3 -3
  184. package/src/mat/simplify-mat.ts +1 -1
  185. package/src/point-on-shape/compare-poss.ts +3 -3
  186. package/src/point-on-shape/get-osculating-circle.ts +1 -1
  187. package/src/point-on-shape/point-on-shape.ts +1 -1
  188. package/src/point-on-shape/pos-to-human-string.ts +1 -1
  189. package/src/sat/to-scale-axis.ts +1 -1
  190. package/src/vertex/remove-vertex.ts +7 -5
  191. package/.mocharc.cjs +0 -17
  192. package/src/debug/functions/draw-elem/branch.ts +0 -26
  193. package/src/find-mat/create-initial-cp-graph.ts +0 -59
@@ -9,6 +9,7 @@ import { calcPosOrder } from '../point-on-shape/calc-pos-order.js';
9
9
  import { Circle } from '../geometry/circle.js';
10
10
  import { isPosCorner } from '../point-on-shape/is-pos-corner.js';
11
11
  import { getPosCorner } from '../point-on-shape/get-pos-corner.js';
12
+ import { MatMeta } from '../index.js';
12
13
 
13
14
 
14
15
  /** @internal */
@@ -17,10 +18,13 @@ function getInitialBezierPieces(
17
18
  isHoleClosing: boolean,
18
19
  loop: Loop,
19
20
  loops: Loop[],
20
- cpTrees: Map<Loop,LlRbTree<CpNode>>,
21
+ // cpTrees: Map<Loop,LlRbTree<CpNode>>,
22
+ meta: MatMeta,
21
23
  y: PointOnShape,
22
24
  circle: Circle): CurvePiece[] {
23
25
 
26
+ const { cpTrees } = meta;
27
+
24
28
  if (isHoleClosing) {
25
29
  return loops
26
30
  .filter(_loop => _loop !== loop)
@@ -8,6 +8,7 @@ import { Circle } from '../geometry/circle.js';
8
8
  import { PointOnShape } from '../point-on-shape/point-on-shape.js';
9
9
  import { addToCpGraph } from '../mat/add-to-cp-graph.js';
10
10
  import { isAnotherCpCloseby } from '../mat/is-another-cp-closeby.js';
11
+ import { MatMeta } from '../mat/mat-meta.js';
11
12
 
12
13
 
13
14
  /**
@@ -24,86 +25,88 @@ import { isAnotherCpCloseby } from '../mat/is-another-cp-closeby.js';
24
25
  * @param threeProng
25
26
  */
26
27
  function add3Prong(
27
- cpTrees: Map<Loop,LlRbTree<CpNode>>,
28
- orders: number[],
29
- threeProng: {
30
- circle: Circle,
31
- ps: PointOnShape[],
32
- δ3s: CpNode[][]
33
- }): CpNode[] {
34
-
35
- const { circle, ps: poss, δ3s } = threeProng;
28
+ // cpTrees: Map<Loop,LlRbTree<CpNode>>,
29
+ meta: MatMeta,
30
+ orders: number[],
31
+ threeProng: {
32
+ circle: Circle,
33
+ ps: PointOnShape[],
34
+ δ3s: CpNode[][]
35
+ }): CpNode[] {
36
+
37
+ const { cpTrees } = meta;
38
+ const { circle, ps: poss, δ3s } = threeProng;
36
39
 
37
- // Keep for possible future debugging.
40
+ // Keep for possible future debugging.
38
41
 
39
- /*
40
- let ii = -1;
41
- if (typeof _debug_ !== 'undefined') {
42
- for (let i=0; i<3; i++) {
43
- const cpBef = threeProng.δ3s[i][0].cp;
44
- const cpAft = threeProng.δ3s[i][1].cp;
42
+ /*
43
+ let ii = -1;
44
+ if (typeof _debug_ !== 'undefined') {
45
+ for (let i=0; i<3; i++) {
46
+ const cpBef = threeProng.δ3s[i][0].cp;
47
+ const cpAft = threeProng.δ3s[i][1].cp;
45
48
 
46
- //let cmpBef = PointOnShape.compareInclOrder(cpBef.pointOnShape, poss[i], cpBef.order, orders[i]);
47
- //let cmpAft = PointOnShape.compareInclOrder(cpAft.pointOnShape, poss[i], cpAft.order, orders[i]);
48
- const cmpBef = compareCps(cpBef, { pointOnShape: poss[i], order: orders[i], order2: 0, circle: undefined });
49
- const cmpAft = compareCps(cpAft, { pointOnShape: poss[i], order: orders[i], order2: 0, circle: undefined });
49
+ //let cmpBef = PointOnShape.compareInclOrder(cpBef.pointOnShape, poss[i], cpBef.order, orders[i]);
50
+ //let cmpAft = PointOnShape.compareInclOrder(cpAft.pointOnShape, poss[i], cpAft.order, orders[i]);
51
+ const cmpBef = compareCps(cpBef, { pointOnShape: poss[i], order: orders[i], order2: 0, circle: undefined });
52
+ const cmpAft = compareCps(cpAft, { pointOnShape: poss[i], order: orders[i], order2: 0, circle: undefined });
50
53
 
51
- // const cmpBef = comparePoss(cpBef.pointOnShape, poss[i]);
52
- // const cmpAft = comparePoss(cpAft.pointOnShape, poss[i]);
54
+ // const cmpBef = comparePoss(cpBef.pointOnShape, poss[i]);
55
+ // const cmpAft = comparePoss(cpAft.pointOnShape, poss[i]);
53
56
 
54
- // len is used by debug functions to reference a particular
55
- // three-prong.
56
- const len = _debug_.generated.elems.threeProng.length-1;
57
- if (cmpBef > 0) {
58
- console.log('----------------------------------------');
59
- console.log(`3-prong order is wrong (bef) : i: ${i} - cmp: ${cmpBef} - n: ${len}`);
60
- console.log(threeProng);
61
- console.log(cpBef);
62
- console.log(cpAft);
63
- console.log(poss[i]);
64
- ii = i;
65
- }
66
- if (cmpAft < 0) {
67
- console.log('----------------------------------------');
68
- console.log(`3-prong order is wrong (aft) : i: ${i} - cmp: ${cmpAft} - n: ${len}`);
69
- console.log(threeProng);
70
- console.log(cpBef);
71
- console.log(cpAft);
72
- console.log(poss[i]);
73
- }
74
- }
75
- }
76
- */
57
+ // len is used by debug functions to reference a particular
58
+ // three-prong.
59
+ const len = _debug_.generated.elems.threeProng.length-1;
60
+ if (cmpBef > 0) {
61
+ console.log('----------------------------------------');
62
+ console.log(`3-prong order is wrong (bef) : i: ${i} - cmp: ${cmpBef} - n: ${len}`);
63
+ console.log(threeProng);
64
+ console.log(cpBef);
65
+ console.log(cpAft);
66
+ console.log(poss[i]);
67
+ ii = i;
68
+ }
69
+ if (cmpAft < 0) {
70
+ console.log('----------------------------------------');
71
+ console.log(`3-prong order is wrong (aft) : i: ${i} - cmp: ${cmpAft} - n: ${len}`);
72
+ console.log(threeProng);
73
+ console.log(cpBef);
74
+ console.log(cpAft);
75
+ console.log(poss[i]);
76
+ }
77
+ }
78
+ }
79
+ */
77
80
 
78
- // TODO - replace 1000 below with correct value
79
- const c1 = isAnotherCpCloseby(cpTrees, poss[0], circle, orders[0], 0, 1000);
80
- const c2 = isAnotherCpCloseby(cpTrees, poss[1], circle, orders[1], 0, 1000);
81
- const c3 = isAnotherCpCloseby(cpTrees, poss[2], circle, orders[2], 0, 1000);
81
+ // TODO - replace 1000 below with correct value
82
+ const c1 = isAnotherCpCloseby(cpTrees, poss[0], circle, orders[0], 0, 1000);
83
+ const c2 = isAnotherCpCloseby(cpTrees, poss[1], circle, orders[1], 0, 1000);
84
+ const c3 = isAnotherCpCloseby(cpTrees, poss[2], circle, orders[2], 0, 1000);
82
85
 
83
- // for (let pos of poss) {
84
- // if (pos.t === 0.9978869234519733) {
85
- // console.log(pos)
86
- // }
87
- // }
88
-
86
+ // for (let pos of poss) {
87
+ // if (pos.t === 0.9978869234519733) {
88
+ // console.log(pos)
89
+ // }
90
+ // }
91
+
89
92
 
90
- // if (!!c1) {
91
- // console.log(getRealProngCount(c1));
92
- // }
93
- // if (!!c2) {
94
- // console.log(getRealProngCount(c2));
95
- // }
96
- // if (!!c3) {
97
- // console.log(getRealProngCount(c3));
98
- // }
93
+ // if (!!c1) {
94
+ // console.log(getRealProngCount(c1));
95
+ // }
96
+ // if (!!c2) {
97
+ // console.log(getRealProngCount(c2));
98
+ // }
99
+ // if (!!c3) {
100
+ // console.log(getRealProngCount(c3));
101
+ // }
99
102
 
100
- // if (!!c1) { return [c1]; }
101
- // if (!!c2) { return [c2]; }
102
- // if (!!c3) { return [c3]; }
103
+ // if (!!c1) { return [c1]; }
104
+ // if (!!c2) { return [c2]; }
105
+ // if (!!c3) { return [c3]; }
103
106
 
104
- const cps = addToCpGraph(circle, orders, cpTrees, poss, δ3s);
105
-
106
- return cps;
107
+ const cps = addToCpGraph(circle, orders, cpTrees, poss, δ3s);
108
+
109
+ return cps;
107
110
  }
108
111
 
109
112
 
@@ -50,7 +50,7 @@ function findAndAdd3Prong(
50
50
 
51
51
  const cpNodes = closeBysFor3Prong.length === 0
52
52
  ? addToCpTree(
53
- true, false, circle, orders, meta.cpTrees, poss, δ3s.map(v => v[0])
53
+ true, false, circle, orders, meta, poss, δ3s.map(v => v[0])
54
54
  ).cpNodes
55
55
  : [];
56
56
 
@@ -1,11 +1,11 @@
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 { findAndAdd3Prongs } from './find-and-add-3-prongs.js';
3
- import { MatMeta } from '../mat/mat-meta.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';
6
+ // import { LlRbTree } from 'flo-ll-rb-tree';
7
+ // import { Loop } from 'flo-boolean';
8
+ // import { drawFs } from 'flo-draw';
9
9
  import { getAllOnCircle } from '../cp-node/fs/get-all-on-circle.js';
10
10
 
11
11
 
@@ -38,7 +38,7 @@ function findAndAdd3ProngsOnLoop(
38
38
  cpNodeGoodSet.add(cpNode);
39
39
  } else {
40
40
  reLoop = true;
41
- replaceCloseBys(meta.cpTrees, closeBysFor3Prong, cpNodeSet, cpNodeGoodSet);
41
+ replaceCloseBys(meta, closeBysFor3Prong, cpNodeSet, cpNodeGoodSet);
42
42
  }
43
43
 
44
44
  addedCpNodes.forEach(cpNodes => cpNodes.forEach(cpNode => cpNodeGoodSet.add(cpNode)));
@@ -71,7 +71,8 @@ function getLastItemOfSet<T>(set: Set<T>) {
71
71
 
72
72
 
73
73
  function replaceCloseBys(
74
- cpTrees: Map<Loop,LlRbTree<CpNode>>,
74
+ // cpTrees: Map<Loop,LlRbTree<CpNode>>,
75
+ meta: MatMeta,
75
76
  closeBysFor3Prong: CpNode[],
76
77
  cpNodeSet: Set<CpNode>,
77
78
  cpNodeGoodSet: Set<CpNode>) {
@@ -81,7 +82,7 @@ function replaceCloseBys(
81
82
  cpNodeSet.delete(v);
82
83
  cpNodeGoodSet.delete(v);
83
84
  });
84
- removeVertex(closeBy, cpTrees);
85
+ removeVertex(closeBy, meta);
85
86
  }
86
87
  }
87
88
 
@@ -5,6 +5,7 @@ import { CpNodeFs } from '../cp-node/cp-node-fs.js';
5
5
  import { PointOnShape } from '../point-on-shape/point-on-shape.js';
6
6
  import { ContactPoint } from '../contact-point/contact-point.js';
7
7
  import { insertCpNode } from '../cp-node/fs/insert-cp-node.js';
8
+ import { MatMeta } from '../index.js';
8
9
 
9
10
  const { cpNodeComparator } = CpNodeFs;
10
11
 
@@ -13,17 +14,20 @@ const { cpNodeComparator } = CpNodeFs;
13
14
  * @internal
14
15
  * Creates the initial ContactPoint loops from the given sharp corners.
15
16
  *
16
- * * modifies `cpTrees`
17
+ * * modifies `cpTrees` and `lastInsertId` of `meta`
17
18
  *
18
- * @param shape
19
+ * @param loops
20
+ * @param cpTrees
19
21
  * @param sharpCornerss
22
+ * @param lastInsertId
20
23
  */
21
24
  function createInitialCpTree(
22
25
  loops: Loop[],
23
26
  cpTrees: Map<Loop, LlRbTree<CpNode>>,
24
- sharpCornerss: PointOnShape[][]) {
27
+ sharpCornerss: PointOnShape[][],
28
+ lastInsertId: { id: number }) {
25
29
 
26
- let cpNode;
30
+ let cpNode: CpNode | undefined;
27
31
  for (let k=0; k<sharpCornerss.length; k++) {
28
32
  const sharpCorners = sharpCornerss[k];
29
33
 
@@ -37,8 +41,8 @@ function createInitialCpTree(
37
41
  const cp1: ContactPoint = { pointOnShape: pos, circle, order: -1, order2: 0 };
38
42
  const cp2: ContactPoint = { pointOnShape: pos, circle, order: +1, order2: 0 };
39
43
 
40
- cpNode1 = insertCpNode(true, false, false, cpTree, cp1, cpNode2)!;
41
- cpNode2 = insertCpNode(true, false, false, cpTree, cp2, cpNode1)!;
44
+ cpNode1 = insertCpNode(true, false, false, cpTree, cp1, cpNode2, lastInsertId)!;
45
+ cpNode2 = insertCpNode(true, false, false, cpTree, cp2, cpNode1, lastInsertId)!;
42
46
 
43
47
  cpNode1.prevOnCircle = cpNode2;
44
48
  cpNode2.prevOnCircle = cpNode1;
@@ -7,7 +7,7 @@ import { CpNode } from '../cp-node/cp-node.js';
7
7
  import { Loop } from 'flo-boolean';
8
8
  import { findAndAdd3ProngsOnLoop } from '../find-3-prong.ts/find-and-add-3-prongs-on-loop.js';
9
9
  import { createInitialCpTree } from './create-initial-cp-tree.js';
10
- import { getMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4 } from './get-meta.js';
10
+ import { getPointToCpNode, getPartialMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4 } from './get-meta.js';
11
11
  import { getSharpCornersOnLoop } from './get-sharp-corners.js';
12
12
  import { getDullCornersOnLoop } from './get-dull-corners-on-loop.js';
13
13
  import { findAndAdd2ProngsOnAllLoops } from '../find-2-prong/find-and-add-2-prongs-on-all-loops.js';
@@ -16,6 +16,7 @@ import { getFor1ProngsOnLoop } from './get-for-1-prongs-on-loop.js';
16
16
  import { findAndAddHoleClosing2Prongs } from '../find-2-prong/find-and-add-hole-closing-2-prongs.js';
17
17
  import { getShapeBounds } from '../svg/get-shape-bounds.js';
18
18
  import { MatOptions } from './mat-options.js';
19
+ import { MatMeta } from '../mat/mat-meta.js';
19
20
 
20
21
 
21
22
  /**
@@ -38,15 +39,27 @@ function findMat(
38
39
 
39
40
  const sharpCornersPerLoop = loops.map(getSharpCornersOnLoop_);
40
41
 
41
- const cpTrees: Map<Loop, LlRbTree<CpNode>> = new Map();
42
- createInitialCpTree(loops, cpTrees, sharpCornersPerLoop);
43
-
44
42
  const bounds = getShapeBounds(loops);
45
43
  const squaredDiagonalLength =
46
44
  (bounds.maxX.p[0] - bounds.minX.p[0])**2 +
47
45
  (bounds.maxY.p[1] - bounds.minY.p[1])**2;
48
46
 
49
- const meta = getMeta(maxCoordinate, squaredDiagonalLength, loops, cpTrees);
47
+ const cpTrees: Map<Loop, LlRbTree<CpNode>> = new Map();
48
+ const lastInsertId = { id: 0 };
49
+ createInitialCpTree(loops, cpTrees, sharpCornersPerLoop, lastInsertId);
50
+
51
+ const _meta = getPartialMeta(loops);
52
+ const pointToCpNode = getPointToCpNode(loops, cpTrees);
53
+ const meta: MatMeta = {
54
+ maxCoordinate, squaredDiagonalLength, loops, cpTrees, pointToCpNode,
55
+ lastInsertId, ..._meta
56
+ };
57
+ // const cpTrees: Map<Loop, LlRbTree<CpNode>> = new Map();
58
+ // const lastInsertId = { id: 0 };
59
+ // createInitialCpTree(loops, cpTrees, sharpCornersPerLoop, lastInsertId);
60
+
61
+ // const meta = getMeta(maxCoordinate, squaredDiagonalLength, loops, cpTrees, lastInsertId);
62
+
50
63
 
51
64
  let cpNode: CpNode | undefined;
52
65
 
@@ -18,23 +18,14 @@ let timingStart: number;
18
18
 
19
19
 
20
20
  /** @internal */
21
- function getMeta(
22
- maxCoordinate: number,
23
- squaredDiagonalLength: number,
21
+ function getPointToCpNode(
24
22
  loops: Loop[],
25
- cpTrees: Map<Loop, LlRbTree<CpNode>>): MatMeta {
23
+ cpTrees: Map<Loop, LlRbTree<CpNode>>): TriMap<Loop,number,number,CpNode> {
26
24
 
27
25
  timingStart = performance.now();
28
26
 
29
27
  const pointToCpNode: TriMap<Loop,number,number,CpNode> = new Map();
30
-
31
- const looseBoundingBoxes: number[][][] = [];
32
- const tightBoundingBoxes: number[][][] = [];
33
- const boundingHulls: number[][][] = [];
34
- const sharpCorners: Curve[] = [];
35
- const dullCorners: Curve[] = [];
36
-
37
- for (const loop of loops) {
28
+ for (const loop of loops) {
38
29
  // Populate `posMap`
39
30
  const cpTree = cpTrees.get(loop)!;
40
31
  const cpNodes = cpTree.toArrayInOrder();
@@ -42,8 +33,32 @@ function getMeta(
42
33
  const { p, t } = cpNode.cp.pointOnShape;
43
34
  TriMapFs.set(pointToCpNode,loop,p[0],p[1],cpNode);
44
35
  }
36
+ }
37
+
38
+ return pointToCpNode;
39
+ }
45
40
 
46
- for (let curve of loop.curves) {
41
+
42
+ /** @internal */
43
+ function getPartialMeta(
44
+ loops: Loop[]): Omit<
45
+ MatMeta,
46
+ | 'cpTrees'
47
+ | 'pointToCpNode'
48
+ | 'loops'
49
+ | 'maxCoordinate'
50
+ | 'squaredDiagonalLength'
51
+ | 'lastInsertId'
52
+ > {
53
+
54
+ const looseBoundingBoxes: number[][][] = [];
55
+ const tightBoundingBoxes: number[][][] = [];
56
+ const boundingHulls: number[][][] = [];
57
+ const sharpCorners: Curve[] = [];
58
+ const dullCorners: Curve[] = [];
59
+
60
+ for (const loop of loops) {
61
+ for (const curve of loop.curves) {
47
62
  const ps = curve.ps;
48
63
  const hull = getBoundingHull(ps, true)!;
49
64
 
@@ -65,16 +80,11 @@ function getMeta(
65
80
  }
66
81
 
67
82
  return {
68
- maxCoordinate,
69
- squaredDiagonalLength,
70
83
  looseBoundingBoxes,
71
84
  tightBoundingBoxes,
72
85
  boundingHulls,
73
86
  sharpCorners,
74
- dullCorners,
75
- loops,
76
- cpTrees,
77
- pointToCpNode
87
+ dullCorners
78
88
  }
79
89
  }
80
90
 
@@ -112,4 +122,10 @@ function addDebugInfo4() {
112
122
  }
113
123
 
114
124
 
115
- export { getMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4 }
125
+ export {
126
+ getPointToCpNode,
127
+ getPartialMeta,
128
+ addDebugInfo2,
129
+ addDebugInfo3,
130
+ addDebugInfo4
131
+ }
@@ -13,8 +13,8 @@ const TOLERANCE_USE_LINE = 0.0001; // else cubic
13
13
 
14
14
 
15
15
  /**
16
- * Returns the bezier curve from the maximal disk of one [[CpNode]] to another
17
- * [[CpNode]]'s maximal disk.
16
+ * Returns the bezier curve from the maximal disk of one `CpNode` to another
17
+ * `CpNode`'s maximal disk.
18
18
  * @param cpNodeFrom
19
19
  * @param cpNodeTo
20
20
  */
package/src/index.ts CHANGED
@@ -49,5 +49,5 @@ export { getSharpCornersOnLoop } from './find-mat/get-sharp-corners.js';
49
49
  export { getFor2ProngsOnLoop } from './find-mat/get-for-2-prongs-on-loop.js';
50
50
  export { getPotentialClosestPointsOnCurveCertified } from './closest-boundary-point/get-potential-closest-points-on-curve-certified.js';
51
51
  export { getCloseBoundaryPointsCertified } from './closest-boundary-point/get-close-boundary-points-certified.js';
52
- export { getMeta } from './find-mat/get-meta.js';
52
+ export { getPartialMeta, getPointToCpNode } from './find-mat/get-meta.js';
53
53
  export { findAndAddHoleClosing2Prongs } from './find-2-prong/find-and-add-hole-closing-2-prongs.js';
@@ -1,10 +1,8 @@
1
- import { LlRbTree } from 'flo-ll-rb-tree';
2
- import { Loop } from 'flo-boolean';
3
- import { Circle } from '../geometry/circle.js';
4
- import { ContactPoint } from '../contact-point/contact-point.js';
5
- import { PointOnShape } from '../point-on-shape/point-on-shape.js';
6
- import { CpNode } from '../cp-node/cp-node.js';
7
- import { CpNodeFs } from '../cp-node/cp-node-fs.js';
1
+ import type { Circle } from '../geometry/circle.js';
2
+ import type { ContactPoint } from '../contact-point/contact-point.js';
3
+ import type { PointOnShape } from '../point-on-shape/point-on-shape.js';
4
+ import type { CpNode } from '../cp-node/cp-node.js';
5
+ import type { MatMeta } from '../index.js';
8
6
  import { getCpNodeToLeftOrSame } from './get-cp-node-to-left-or-same.js';
9
7
  import { insertCpNode } from '../cp-node/fs/insert-cp-node.js';
10
8
  import { joinSpokes } from '../add-n-prong.ts/join-spokes.js';
@@ -24,10 +22,13 @@ function addToCpTree(
24
22
  isHoleClosing: boolean,
25
23
  circle: Circle,
26
24
  orders: number[],
27
- cpTrees: Map<Loop,LlRbTree<CpNode>>,
25
+ // cpTrees: Map<Loop,LlRbTree<CpNode>>,
26
+ meta: MatMeta,
28
27
  poss: PointOnShape[],
29
28
  neighbors? : CpNode[]): { anyFailed: boolean, cpNodes: (CpNode | undefined) [] } {
30
29
 
30
+ const { cpTrees } = meta;
31
+
31
32
  let anyFailed = false;
32
33
  const cpNodes = poss.map((pos,i) => {
33
34
  const order = orders[i];
@@ -38,7 +39,15 @@ function addToCpTree(
38
39
  ? getCpNodeToLeftOrSame(cpTree, pos, order, 0)
39
40
  : neighbors[i];
40
41
 
41
- const cpNode = insertCpNode(insertIfOrderIsWrong, isHoleClosing, false, cpTree, cp, pred);
42
+ const cpNode = insertCpNode(
43
+ insertIfOrderIsWrong,
44
+ isHoleClosing,
45
+ false,
46
+ cpTree,
47
+ cp,
48
+ pred,
49
+ meta.lastInsertId
50
+ );
42
51
 
43
52
  if (cpNode === undefined) { anyFailed = true; }
44
53
 
@@ -3,44 +3,51 @@ import { getBranch } from '../cp-node/fs/get-branch.js';
3
3
  import { getNonTerminatingOnCircle } from '../cp-node/fs/get-non-terminating-on-circle.js';
4
4
 
5
5
 
6
+ /**
7
+ * Returns all branches associated with the give cpNode.
8
+ *
9
+ * * the final `CpNode` of each branch is not returned to improve symmetry
10
+ *
11
+ * @param cpNode `CpNode` representing the start vertex.
12
+ */
6
13
  function getBranches(
7
- cpNode: CpNode): CpNode[][] {
14
+ cpNode: CpNode): CpNode[][] {
8
15
 
9
- const branches: CpNode[][] = [];
10
- const cpNodeStack: CpNode[] = [cpNode];
11
- const takenBranches: Set<CpNode> = new Set();
12
- while (cpNodeStack.length > 0) {
13
- const cpNode = cpNodeStack.pop()!;
14
- const branch = getBranch(cpNode);
16
+ const branches: CpNode[][] = [];
17
+ const cpNodeStack: CpNode[] = [cpNode];
18
+ const takenBranches: Set<CpNode> = new Set();
19
+ while (cpNodeStack.length > 0) {
20
+ const cpNode = cpNodeStack.pop()!;
21
+ const branch = getBranch(cpNode);
15
22
 
16
- if (branch.length === 0) {
17
- continue;
18
- }
23
+ if (branch.length === 0) {
24
+ continue;
25
+ }
19
26
 
20
- branches.push(branch);
27
+ branches.push(branch);
21
28
 
22
- const cpNodeS = branch[0];
23
- const cpNodeE = branch[branch.length-1].next.prevOnCircle;
29
+ const cpNodeS = branch[0];
30
+ const cpNodeE = branch[branch.length-1].next.prevOnCircle;
24
31
 
25
- takenBranches.add(cpNodeS);
26
- takenBranches.add(cpNodeE);
32
+ takenBranches.add(cpNodeS);
33
+ takenBranches.add(cpNodeE);
27
34
 
28
- const _cpNodesS = getNonTerminatingOnCircle(cpNodeS, true);
29
- const _cpNodesE = getNonTerminatingOnCircle(cpNodeE, true);
30
- const cpNodesS = _cpNodesS.filter(cpNode => !takenBranches.has(cpNode));
31
- const cpNodesE = _cpNodesE.filter(cpNode => !takenBranches.has(cpNode));
35
+ const _cpNodesS = getNonTerminatingOnCircle(cpNodeS, true);
36
+ const _cpNodesE = getNonTerminatingOnCircle(cpNodeE, true);
37
+ const cpNodesS = _cpNodesS.filter(cpNode => !takenBranches.has(cpNode));
38
+ const cpNodesE = _cpNodesE.filter(cpNode => !takenBranches.has(cpNode));
32
39
 
33
- for (const cpNode of cpNodesS) {
34
- takenBranches.add(cpNode);
35
- }
36
- for (const cpNode of cpNodesE) {
37
- takenBranches.add(cpNode);
38
- }
40
+ for (const cpNode of cpNodesS) {
41
+ takenBranches.add(cpNode);
42
+ }
43
+ for (const cpNode of cpNodesE) {
44
+ takenBranches.add(cpNode);
45
+ }
39
46
 
40
- cpNodeStack.push(...cpNodesS, ...cpNodesE);
41
- }
47
+ cpNodeStack.push(...cpNodesS, ...cpNodesE);
48
+ }
42
49
 
43
- return branches;
50
+ return branches;
44
51
  }
45
52
 
46
53
 
@@ -19,12 +19,17 @@ interface MatMeta {
19
19
 
20
20
  /**
21
21
  * Primarily for internal use. A tree structure storing the
22
- * [[CpNode]]s of the MAT by their compare order, i.e. their cyclic order
22
+ * `CpNode`s of the MAT by their compare order, i.e. their cyclic order
23
23
  * around the shape boundary.
24
24
  */
25
25
  readonly cpTrees: Map<Loop, LlRbTree<CpNode>>;
26
26
  /** A map from a bezier and t value to a `PointOnShape` */
27
27
  readonly pointToCpNode: TriMap<Loop,number,number,CpNode>;
28
+ /**
29
+ * Stores the last insert id so each `CpNode` can have a unique id for
30
+ * debugging purposes
31
+ */
32
+ readonly lastInsertId: { id: number };
28
33
  }
29
34
 
30
35
 
package/src/mat/mat.ts CHANGED
@@ -5,13 +5,13 @@ import { MatMeta } from './mat-meta.js';
5
5
  /**
6
6
  * Represents a complete Medial Axis Transform (MAT).
7
7
  *
8
- * The MAT is fully described through its [[CpNode]] property. The [[cpTrees]]
8
+ * The MAT is fully described through its `CpNode` property. The `cpTrees`
9
9
  * property is only added to facilitate extension of the MAT, e.g. by adding
10
- * extra maximal disks and is typically not used. See [[CpNode]] for more
10
+ * extra maximal disks and is typically not used. See `CpNode` for more
11
11
  * details.
12
12
  */
13
13
  interface Mat {
14
- /** A complete representation of the MAT. See [[CpNode]]. */
14
+ /** A complete representation of the MAT. See `CpNode`. */
15
15
  cpNode: CpNode;
16
16
  /**
17
17
  * Stores additional info about the shape that could be useful for various
@@ -75,7 +75,7 @@ function simplifyMat(
75
75
  !cpNode.isHoleClosing
76
76
  )(cpNode)) {
77
77
 
78
- removeVertex(cpNode, mat.meta.cpTrees);
78
+ removeVertex(cpNode, mat.meta);
79
79
  }
80
80
  }
81
81
 
@@ -2,10 +2,10 @@ import { PointOnShape } from "./point-on-shape.js";
2
2
 
3
3
 
4
4
  /**
5
- * Compares two [[PointOnShape]]s according to their cyclic ordering imposed
5
+ * Compares two `PointOnShape`s according to their cyclic ordering imposed
6
6
  * by their relative positions on the shape boundary.
7
- * @param a The first [[PointOnShape]].
8
- * @param b The second [[PointOnShape]].
7
+ * @param a The first `PointOnShape`.
8
+ * @param b The second `PointOnShape`.
9
9
  * @internal
10
10
  */
11
11
  function comparePoss(
@@ -9,7 +9,7 @@ import { PointOnShape } from './point-on-shape.js';
9
9
  *
10
10
  * @param minCurvature If not Number.POSITIVE_INFINITY then the
11
11
  * circle radius will be limited to this value.
12
- * @param pos The [[PointOnShape]] identifying the point.
12
+ * @param pos The `PointOnShape` identifying the point.
13
13
  * @param useMaxRadius
14
14
  */
15
15
  function getOsculatingCircle(
@@ -2,7 +2,7 @@ import { Curve } from '../curve/curve.js';
2
2
 
3
3
 
4
4
  interface PointOnShape {
5
- /** The [[ICurve]] on the shape boundary this points belong to. */
5
+ /** The `Curve` on the shape boundary this points belong to. */
6
6
  curve: Curve;
7
7
  /** The bezier parameter value on the curve identifying the point coordinates. */
8
8
  t: number;