flo-mat 3.0.6 → 3.0.7

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 (185) 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 +239 -158
  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 +32 -32
  67. package/node/cp-node/cp-node-fs.js +32 -32
  68. package/node/cp-node/cp-node.d.ts +13 -21
  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 +10 -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 +0 -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/point-on-shape.d.ts +1 -1
  138. package/node/vertex/remove-vertex.d.ts +3 -4
  139. package/node/vertex/remove-vertex.js +3 -2
  140. package/node/vertex/remove-vertex.js.map +1 -1
  141. package/package.json +9 -6
  142. package/src/corner/get-interface-ccw.ts +0 -1
  143. package/src/cp-node/cp-node-fs.ts +43 -43
  144. package/src/cp-node/cp-node.ts +27 -39
  145. package/src/cp-node/fs/clone.ts +3 -3
  146. package/src/cp-node/fs/enhance-cp-node.ts +0 -1
  147. package/src/cp-node/fs/get-all-between.ts +31 -28
  148. package/src/cp-node/fs/get-all-on-circle.ts +13 -8
  149. package/src/cp-node/fs/get-all-on-loop.ts +12 -10
  150. package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +39 -22
  151. package/src/cp-node/fs/get-boundary-beziers-between.ts +6 -2
  152. package/src/cp-node/fs/get-boundary-beziers-to-next.ts +6 -4
  153. package/src/cp-node/fs/insert-cp-node.ts +13 -2
  154. package/src/cp-node/fs/is-fully-terminating.ts +7 -0
  155. package/src/cp-node/fs/is-terminating.ts +1 -1
  156. package/src/cp-node/fs/remove-cp-node.ts +8 -4
  157. package/src/curve/curve.ts +19 -13
  158. package/src/debug/functions/check-ordering.ts +7 -3
  159. package/src/find-2-prong/add-1-prong.ts +1 -1
  160. package/src/find-2-prong/add-2-prong.ts +79 -74
  161. package/src/find-2-prong/calc-seperation-tolerance.ts +88 -78
  162. package/src/find-2-prong/find-2-prong.ts +2 -2
  163. package/src/find-2-prong/get-initial-bezier-pieces.ts +5 -1
  164. package/src/find-3-prong.ts/add-3-prong.ts +73 -70
  165. package/src/find-3-prong.ts/find-and-add-3-prong.ts +1 -1
  166. package/src/find-3-prong.ts/find-and-add-3-prongs-on-loop.ts +9 -8
  167. package/src/find-mat/create-initial-cp-tree.ts +10 -6
  168. package/src/find-mat/find-mat.ts +12 -5
  169. package/src/find-mat/get-meta.ts +30 -20
  170. package/src/get-curve/get-curve-between.ts +2 -2
  171. package/src/index.ts +1 -1
  172. package/src/mat/add-to-cp-tree.ts +18 -9
  173. package/src/mat/get-branches.ts +35 -28
  174. package/src/mat/mat-meta.ts +6 -1
  175. package/src/mat/mat.ts +3 -3
  176. package/src/mat/simplify-mat.ts +1 -1
  177. package/src/point-on-shape/compare-poss.ts +3 -3
  178. package/src/point-on-shape/get-osculating-circle.ts +1 -1
  179. package/src/point-on-shape/point-on-shape.ts +1 -1
  180. package/src/point-on-shape/pos-to-human-string.ts +1 -1
  181. package/src/sat/to-scale-axis.ts +1 -1
  182. package/src/vertex/remove-vertex.ts +7 -5
  183. package/.mocharc.cjs +0 -17
  184. package/src/debug/functions/draw-elem/branch.ts +0 -26
  185. package/src/find-mat/create-initial-cp-graph.ts +0 -59
@@ -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,21 @@ 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
+ };
50
57
 
51
58
  let cpNode: CpNode | undefined;
52
59
 
@@ -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,4 @@ function addDebugInfo4() {
112
122
  }
113
123
 
114
124
 
115
- export { getMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4 }
125
+ export { getPointToCpNode, getPartialMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4 }
@@ -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 { getMeta } 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;
@@ -2,7 +2,7 @@ import { PointOnShape } from "./point-on-shape.js"
2
2
 
3
3
 
4
4
  /**
5
- * Returns a human-readable string of the given [[PointOnShape]].
5
+ * Returns a human-readable string of the given `PointOnShape`.
6
6
  * For debugging only.
7
7
  * @internal
8
8
  */
@@ -20,7 +20,7 @@ import { getSatCulls } from './get-sat-culls.js';
20
20
  * boundary of the shape. The SAT is a simplification of the MAT that preserves
21
21
  * less detail the higher the applied scale factor. The severity at which noise
22
22
  * are removed depends on the local scale of the shape.
23
- * @param mat The Medial Axis Transform ([[Mat]]) on which to apply the SAT.
23
+ * @param mat The Medial Axis Transform (`Mat`) on which to apply the SAT.
24
24
  * @param s The scale factor >= 1 (e.g. 1.3)
25
25
  */
26
26
  function toScaleAxis(
@@ -1,6 +1,7 @@
1
- import { Loop } from 'flo-boolean';
2
- import { LlRbTree } from 'flo-ll-rb-tree';
3
- import { CpNode } from "../cp-node/cp-node.js";
1
+ // import { Loop } from 'flo-boolean';
2
+ // import { LlRbTree } from 'flo-ll-rb-tree';
3
+ import type { CpNode } from "../cp-node/cp-node.js";
4
+ import type { MatMeta } from '../mat/mat-meta.js';
4
5
  import { getAllOnCircle } from '../cp-node/fs/get-all-on-circle.js';
5
6
  import { getProngCount } from '../cp-node/fs/get-prong-count.js';
6
7
  import { removeCpNode } from '../cp-node/fs/remove-cp-node.js';
@@ -8,14 +9,15 @@ import { removeCpNode } from '../cp-node/fs/remove-cp-node.js';
8
9
 
9
10
  function removeVertex(
10
11
  cpNode: CpNode,
11
- cpTrees: Map<Loop, LlRbTree<CpNode>>): void {
12
+ meta: MatMeta): void {
13
+ // cpTrees: Map<Loop, LlRbTree<CpNode>>): void {
12
14
 
13
15
  const prongCount = getProngCount(cpNode);
14
16
  if (prongCount !== 2) {
15
17
  throw new Error(`Cannot delete \`CpNode\` on ${prongCount}-prong`)
16
18
  }
17
19
 
18
- getAllOnCircle(cpNode).forEach(cpNode => removeCpNode(cpNode, cpTrees));
20
+ getAllOnCircle(cpNode).forEach(cpNode => removeCpNode(cpNode, meta));
19
21
  }
20
22
 
21
23
 
package/.mocharc.cjs DELETED
@@ -1,17 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- extension: ['ts', 'tsx'],
5
- spec: ['__tests__/**/*.spec.ts'],
6
- recursive: true,
7
- loader: ['ts-node/esm'],
8
- // slow: '75',
9
- // timeout: '2000',
10
- // ignore: ['/path/to/some/ignored/file'],
11
- color: true,
12
- diff: true,
13
- exit: false,
14
- parallel: true,
15
- timeout: '2000',
16
- 'v8-stack-trace-limit': 100 // V8 flags are prepended with "v8-"
17
- };
@@ -1,26 +0,0 @@
1
- import { drawFs } from 'flo-draw';
2
- import { CpNode, isTerminating } from '../../../cp-node/cp-node.js';
3
- import { getCurveToNext } from '../../../cp-node/get-curve-to-next.js';
4
-
5
-
6
- /** @internal */
7
- function drawBranch(g: SVGGElement, branch: CpNode[], delay?: number) {
8
-
9
- const classes = 'thin5 purple nofill';
10
-
11
- const $svgs: SVGElement[] = [];
12
- let i = 0;
13
-
14
- for (const cpNode of branch) {
15
- if (isTerminating(cpNode)) { continue; }
16
- const bezier = getCurveToNext(cpNode);
17
- if (!bezier) { continue; }
18
- i++;
19
- $svgs.push( ...drawFs.bezier(g, bezier, classes, delay));
20
- }
21
-
22
- return $svgs;
23
- }
24
-
25
-
26
- export { drawBranch }
@@ -1,59 +0,0 @@
1
- import { LlRbTree } from 'flo-ll-rb-tree';
2
- import { Loop } from 'flo-boolean';
3
- import { CpNode, cpNodeComparator, insertCpNode } from '../cp-node/cp-node.js';
4
- import { PointOnShape } from '../point-on-shape/point-on-shape.js';
5
- import { ContactPoint } from '../contact-point/contact-point.js';
6
-
7
-
8
- /**
9
- * @internal
10
- * Creates the initial ContactPoint loops from the given sharp corners.
11
- * @param shape
12
- * @param sharpCornerss
13
- */
14
- function createInitialCpGraph(
15
- loops: Loop[],
16
- cpTrees: Map<Loop, LlRbTree<CpNode>>,
17
- sharpCornerss: PointOnShape[][]/*,
18
- xMap: Map<number[][],{ ps: number[][] }>*/) {
19
-
20
- let cpNode;
21
-
22
- for (let k=0; k<sharpCornerss.length; k++) {
23
- const sharpCorners = sharpCornerss[k];
24
-
25
- const cpTree = new LlRbTree(cpNodeComparator, false);
26
-
27
- let cpNode1: CpNode = undefined!;
28
- let cpNode2: CpNode = undefined!;
29
- for (const pos of sharpCorners) {
30
- const ps = pos.curve.next.ps;
31
- //const x = xMap.get(ps);
32
- //const isIntersection = !!x;
33
-
34
- const circle = { center: pos.p, radius: 0 };
35
-
36
- const cp1: ContactPoint = { pointOnShape: pos, circle, order: -1, order2: 0 };
37
- const cp2: ContactPoint = { pointOnShape: pos, circle, order: +1, order2: 0 };
38
-
39
- cpNode1 = insertCpNode(false, /*isIntersection*/ false, cpTree, cp1, cpNode2!);
40
- cpNode2 = insertCpNode(false, /*isIntersection*/ false, cpTree, cp2, cpNode1);
41
-
42
- cpNode1.prevOnCircle = cpNode2;
43
- cpNode2.prevOnCircle = cpNode1;
44
-
45
- cpNode1.nextOnCircle = cpNode2;
46
- cpNode2.nextOnCircle = cpNode1;
47
- }
48
-
49
- if (!cpNode) { cpNode = cpNode1; }
50
-
51
- const loop = loops[k];
52
- cpTrees.set(loop, cpTree);
53
- }
54
-
55
- return cpNode;
56
- }
57
-
58
-
59
- export { createInitialCpGraph }