flo-mat 3.0.13 → 3.0.15

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 (138) hide show
  1. package/__tests__/cp-node/check-clone-eql-calc.spec.ts +58 -0
  2. package/__tests__/cp-node/compare-cp-nodes-by-value.ts +35 -0
  3. package/__tests__/cp-node/compare-loops-by-value.ts +40 -0
  4. package/__tests__/cp-node/compare-poss-by-value.ts +25 -0
  5. package/__tests__/cp-node/fs/clone.spec.ts +19 -3
  6. package/__tests__/cp-node/fs/find-first.spec.ts +13 -3
  7. package/__tests__/cp-node/fs/get-all-between.spec.ts +20 -3
  8. package/__tests__/cp-node/fs/get-all-on-circle.spec.ts +2 -2
  9. package/__tests__/cp-node/fs/get-all-on-loop.spec.ts +16 -3
  10. package/__tests__/cp-node/fs/get-all-vertices.spec.ts +14 -3
  11. package/__tests__/cp-node/fs/get-children.spec.ts +18 -3
  12. package/__tests__/cp-node/fs/get-non-terminating-on-circle.spec.ts +14 -3
  13. package/__tests__/cp-node/fs/get-prong-count.spec.ts +16 -3
  14. package/__tests__/cp-node/fs/get-real-prong-count.spec.ts +11 -3
  15. package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +20 -3
  16. package/__tests__/cp-node/fs/is-fully-terminating.spec.ts +16 -3
  17. package/__tests__/cp-node/fs/is-on-same-circle.spec.ts +20 -3
  18. package/__tests__/cp-node/fs/is-one-prong.spec.ts +16 -3
  19. package/__tests__/cp-node/fs/is-sharp.spec.ts +10 -3
  20. package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +13 -3
  21. package/__tests__/cp-node/fs/is-special.spec.ts +12 -3
  22. package/__tests__/cp-node/fs/is-terminating.spec.ts +15 -3
  23. package/__tests__/cp-node/fs/is-trivial.spec.ts +13 -3
  24. package/__tests__/cp-node/fs/is-two-prong.spec.ts +11 -3
  25. package/__tests__/cp-node/fs/is-vertex-special.spec.ts +13 -3
  26. package/__tests__/cp-node/fs/is-vertex.spec.ts +14 -3
  27. package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +13 -3
  28. package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +10 -3
  29. package/__tests__/cp-node/fs/traverse-cp.spec.ts +9 -3
  30. package/__tests__/cp-node/fs/traverse-edges.spec.ts +13 -3
  31. package/__tests__/cp-node/fs/traverse-vertices.spec.ts +12 -3
  32. package/__tests__/cp-node/random-walk.ts +33 -0
  33. package/__tests__/cp-node/stringification/from-stringifyable.spec.ts +3 -0
  34. package/__tests__/cp-node/stringification/loop-from-stringifyable.spec.ts +4 -0
  35. package/__tests__/cp-node/stringification/loop-to-stringifyable.spec.ts +19 -0
  36. package/__tests__/cp-node/stringification/to-stringifyable.spec.ts +34 -0
  37. package/__tests__/get-mats1.ts +125 -0
  38. package/__tests__/jsog/check-jsog-eql-calc.spec.ts +47 -67
  39. package/__tests__/jsog/decode-jsog.ts +88 -85
  40. package/__tests__/jsog/mat-dummy-1.ts +19 -0
  41. package/__tests__/jsog/mat-dummys.ts +6197 -6195
  42. package/__tests__/jsog/to-jsog-breath-first.ts +110 -107
  43. package/__tests__/jsog/to-jsog-depth-first.ts +58 -55
  44. package/browser/index.js +7002 -6298
  45. package/browser/index.min.js +1 -1
  46. package/jest.config.cjs +1 -0
  47. package/node/closest-boundary-point/foot-and-endpoint-info.d.ts +1 -1
  48. package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +3 -3
  49. package/node/closest-boundary-point/get-close-boundary-points-certified.js +1 -1
  50. package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
  51. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.d.ts +2 -2
  52. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +7 -7
  53. package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
  54. package/node/cp-node/cp-node.d.ts +2 -2
  55. package/node/cp-node/fs/clone.d.ts +1 -1
  56. package/node/cp-node/fs/clone.js +17 -13
  57. package/node/cp-node/fs/clone.js.map +1 -1
  58. package/node/cp-node/fs/enhance-cp-node.d.ts +2 -2
  59. package/node/cp-node/fs/find-first.d.ts +9 -2
  60. package/node/cp-node/fs/find-first.js +12 -9
  61. package/node/cp-node/fs/find-first.js.map +1 -1
  62. package/node/cp-node/fs/get-all-on-loop.js +5 -6
  63. package/node/cp-node/fs/get-all-on-loop.js.map +1 -1
  64. package/node/cp-node/fs/get-edge-direction.d.ts +1 -1
  65. package/node/cp-node/fs/get-edge-direction.js.map +1 -1
  66. package/node/cp-node/fs/is-on-same-circle.d.ts +1 -0
  67. package/node/cp-node/fs/is-on-same-circle.js +1 -0
  68. package/node/cp-node/fs/is-on-same-circle.js.map +1 -1
  69. package/node/debug/functions/draw-elem/draw-dull-corner.d.ts +1 -1
  70. package/node/debug/functions/draw-elem/draw-dull-corner.js +1 -1
  71. package/node/debug/functions/draw-elem/draw-dull-corner.js.map +1 -1
  72. package/node/debug/functions/draw-elem/draw-sharp-corner.d.ts +1 -1
  73. package/node/debug/functions/draw-elem/draw-sharp-corner.js +2 -1
  74. package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +1 -1
  75. package/node/find-mat/find-mats.js +7 -2
  76. package/node/find-mat/find-mats.js.map +1 -1
  77. package/node/find-mat/get-meta.d.ts +4 -4
  78. package/node/find-mat/get-meta.js +1 -1
  79. package/node/find-mat/get-meta.js.map +1 -1
  80. package/node/geometry/circle.d.ts +4 -3
  81. package/node/geometry/circle.js +0 -7
  82. package/node/geometry/circle.js.map +1 -1
  83. package/node/index.d.ts +2 -2
  84. package/node/index.js +1 -0
  85. package/node/index.js.map +1 -1
  86. package/node/mat/curve-piece.d.ts +3 -3
  87. package/node/mat/get-boundary-piece-beziers.d.ts +2 -2
  88. package/node/mat/mat-meta.d.ts +4 -4
  89. package/node/mat/simplify-mat.d.ts +10 -8
  90. package/node/mat/simplify-mat.js +12 -10
  91. package/node/mat/simplify-mat.js.map +1 -1
  92. package/node/point-on-shape/create-pos.d.ts +2 -2
  93. package/node/point-on-shape/create-pos.js.map +1 -1
  94. package/node/point-on-shape/point-on-shape.d.ts +6 -6
  95. package/node/svg/get-loop-bounds.d.ts +2 -2
  96. package/node/svg/get-loop-bounds.js +1 -1
  97. package/node/svg/get-loop-bounds.js.map +1 -1
  98. package/package.json +10 -10
  99. package/src/closest-boundary-point/foot-and-endpoint-info.ts +1 -1
  100. package/src/closest-boundary-point/get-close-boundary-points-certified.ts +5 -5
  101. package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +9 -9
  102. package/src/cp-node/cp-node.ts +8 -3
  103. package/src/cp-node/fs/add-distance-from.ts +37 -37
  104. package/src/cp-node/fs/clone.ts +23 -17
  105. package/src/cp-node/fs/find-first.ts +14 -11
  106. package/src/cp-node/fs/get-all-on-loop.ts +5 -6
  107. package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +1 -1
  108. package/src/cp-node/fs/get-edge-direction.ts +3 -5
  109. package/src/cp-node/fs/is-on-same-circle.ts +1 -0
  110. package/src/cp-node/stringification/cp-node-stringifyable.ts +68 -0
  111. package/src/cp-node/stringification/from-stringifyable.ts +57 -0
  112. package/src/cp-node/stringification/loop-from-stringifyable.ts +15 -0
  113. package/src/cp-node/stringification/loop-stringifyable.ts +8 -0
  114. package/src/cp-node/stringification/loop-to-stringifyable.ts +14 -0
  115. package/src/cp-node/stringification/to-stringifyable.ts +71 -0
  116. package/src/curve/curve.ts +31 -33
  117. package/src/debug/functions/draw-elem/draw-dull-corner.ts +2 -2
  118. package/src/debug/functions/draw-elem/draw-sharp-corner.ts +4 -3
  119. package/src/find-mat/find-mats.ts +8 -2
  120. package/src/find-mat/get-meta.ts +7 -6
  121. package/src/geometry/circle.ts +5 -12
  122. package/src/index.ts +3 -4
  123. package/src/mat/curve-piece.ts +3 -3
  124. package/src/mat/get-boundary-piece-beziers.ts +3 -3
  125. package/src/mat/mat-meta.ts +4 -4
  126. package/src/mat/simplify-mat-map-only.ts +110 -110
  127. package/src/mat/simplify-mat.ts +15 -13
  128. package/src/point-on-shape/create-pos.ts +3 -3
  129. package/src/point-on-shape/point-on-shape.ts +6 -6
  130. package/src/svg/get-loop-bounds.ts +4 -5
  131. package/__tests__/cp-node/fs/add-distance-from.spec.ts +0 -7
  132. package/__tests__/cp-node/fs/cp-nodes-to-boundary-beziers.spec.ts +0 -7
  133. package/__tests__/cp-node/fs/create-cp-node.spec.ts +0 -7
  134. package/__tests__/cp-node/fs/enhance-cp-node.spec.ts +0 -7
  135. package/__tests__/jsog/get-mats1.ts +0 -41
  136. package/node/curve/curve.d.ts +0 -33
  137. package/node/curve/curve.js +0 -2
  138. package/node/curve/curve.js.map +0 -1
@@ -0,0 +1,57 @@
1
+ import type { ContactPoint } from "../../contact-point/contact-point";
2
+ import type { CpNode } from "../cp-node";
3
+ import type { CpNodeStringifyable } from "./cp-node-stringifyable";
4
+ import { EDGES } from "./cp-node-stringifyable";
5
+ import { loopFromStringifyable } from './loop-from-stringifyable.js';
6
+
7
+
8
+ function fromStringifyable(
9
+ cpNodesStringifyable: CpNodeStringifyable) {
10
+
11
+ const { cpNodes: _cpNodes, loops: _loops } = cpNodesStringifyable;
12
+ const loops = _loops.map(loopFromStringifyable);
13
+
14
+ //--------------------------------------------------------------------------
15
+ // First pass: build all CpNode objects with proper `cp`.
16
+ // Edges still hold number ids at this point.
17
+ //--------------------------------------------------------------------------
18
+ const cpNodes: CpNode[] = _cpNodes.map(cpNode_ => {
19
+ const { id, cp, isHoleClosing, isIntersection } = cpNode_;
20
+ const { circle, pointOnShape, order, order2 } = cp;
21
+ const { curveIdx, loopIdx, p, t, isSource } = pointOnShape;
22
+
23
+ const curve = loops[loopIdx].curves[curveIdx];
24
+
25
+ const cp_: ContactPoint = {
26
+ circle,
27
+ pointOnShape: { curve, p, t, isSource },
28
+ order, order2
29
+ };
30
+
31
+ return {
32
+ ...cpNode_,
33
+ id, isHoleClosing, isIntersection,
34
+ cp: cp_
35
+ } as CpNode;
36
+ });
37
+
38
+ //--------------------------------------------------------------------------
39
+ // Second pass: replace number id edges with real CpNode references.
40
+ //--------------------------------------------------------------------------
41
+ const nodeMap = new Map<number, CpNode>(cpNodes.map(n => [n.id, n]));
42
+
43
+ for (const cpNode of cpNodes) {
44
+ for (const edge of EDGES) {
45
+ const id = cpNode[edge] as unknown as number | undefined;
46
+ if (id === undefined) { continue; }
47
+
48
+ // @ts-ignore
49
+ cpNode[edge] = nodeMap.get(id)!;
50
+ }
51
+ }
52
+
53
+ return cpNodes[0];
54
+ }
55
+
56
+
57
+ export { fromStringifyable }
@@ -0,0 +1,15 @@
1
+ import type { Loop } from "flo-boolean";
2
+ import type { LoopStringifyable } from "./loop-stringifyable";
3
+ import { loopFromBeziers } from "flo-boolean";
4
+
5
+
6
+ function loopFromStringifyable(
7
+ loopStringifyable: LoopStringifyable): Loop {
8
+
9
+ const { idx, beziers } = loopStringifyable;
10
+
11
+ return loopFromBeziers(beziers, idx);
12
+ }
13
+
14
+
15
+ export { loopFromStringifyable }
@@ -0,0 +1,8 @@
1
+
2
+ interface LoopStringifyable {
3
+ readonly idx: number;
4
+ readonly beziers: number[][][];
5
+ }
6
+
7
+
8
+ export type { LoopStringifyable }
@@ -0,0 +1,14 @@
1
+ import type { Loop } from "flo-boolean";
2
+ import type { LoopStringifyable } from "./loop-stringifyable";
3
+
4
+
5
+ function loopToStringifyable(
6
+ loop: Loop): LoopStringifyable {
7
+
8
+ const { idx, beziers } = loop;
9
+
10
+ return { idx: idx!, beziers };
11
+ }
12
+
13
+
14
+ export { loopToStringifyable }
@@ -0,0 +1,71 @@
1
+ import type { Loop } from "flo-boolean";
2
+ import type { CpNodeStringifyable, CpNodeWithAnyEdges, PointOnShapeSimplified } from "./cp-node-stringifyable.js";
3
+ import type { CpNode } from "../cp-node.js";
4
+ import { loopToStringifyable } from "./loop-to-stringifyable.js";
5
+
6
+
7
+ /**
8
+ * Returns a deep clone of this `CpNode`. Can be used to copy the MAT
9
+ * since cloning a single `CpNode` necessarily implies cloning all
10
+ * `CpNode`s on the same MAT tree.
11
+ */
12
+ function toStringifyable(
13
+ cpNode: CpNode): CpNodeStringifyable {
14
+
15
+ const cpNodes_: CpNodeWithAnyEdges[] = [];
16
+ const loopSet = new Set<Loop>();
17
+
18
+ //--------------------------------------------------------------------------
19
+ // Clone `CpNode`s with edges replaced with ids AND
20
+ // set the `nodeMap` to map original `CpNode`s to their ids.
21
+ //--------------------------------------------------------------------------
22
+ const cpStart = cpNode;
23
+ do {
24
+ const {
25
+ id, isHoleClosing, isIntersection,
26
+ cp,
27
+ prev, next, nextOnCircle, prevOnCircle, holeCloserTwin,
28
+ } = cpNode
29
+
30
+ const { pointOnShape, circle, order, order2 } = cp;
31
+ const { curve, p, t, isSource } = pointOnShape;
32
+ const { idx: curveIdx, loop, ps, prev: prevCurve, next: nextCurve } = curve;
33
+
34
+ if (!loopSet.has(loop)) {
35
+ loopSet.add(loop);
36
+ }
37
+
38
+ const posSimplified: PointOnShapeSimplified = {
39
+ curveIdx, loopIdx: loop.idx!, p, t, isSource
40
+ };
41
+
42
+ cpNodes_.push({
43
+ id, isHoleClosing, isIntersection,
44
+ cp: {
45
+ circle,
46
+ pointOnShape: posSimplified,
47
+ order, order2
48
+ },
49
+ prev: prev.id,
50
+ next: next.id,
51
+ prevOnCircle: prevOnCircle.id,
52
+ nextOnCircle: nextOnCircle.id,
53
+ holeCloserTwin: holeCloserTwin?.id
54
+ });
55
+
56
+ cpNode = cpNode.next;
57
+ } while (cpNode !== cpStart);
58
+ //--------------------------------------------------------------------------
59
+
60
+ const loops = Array.from(loopSet).sort((a, b) => a.idx! - b.idx!);
61
+ const loops_ = loops.map(loopToStringifyable);
62
+
63
+ return {
64
+ cpNodes: cpNodes_,
65
+ loops: loops_
66
+ };
67
+ }
68
+
69
+
70
+ export { toStringifyable }
71
+
@@ -1,37 +1,35 @@
1
- import { Loop } from 'flo-boolean';
1
+ // import type { Loop } from 'flo-boolean';
2
2
 
3
3
 
4
- /**
5
- * Represents a bezier curve on the shape boundary / loop.
6
- */
7
- interface Curve {
8
- /**
9
- * The closed loop of bezier curves representing the shape
10
- * boundary this curve belongs to.
11
- */
12
- loop: Loop;
13
- /**
14
- * The bezier control points.
15
- */
16
- ps: number[][];
17
- /**
18
- * The previous curve (when going in a negative direction around
19
- * the shape boundary, i.e. clockwise for the outer shape and anti-clockwise
20
- * for the holes (if any))
21
- */
22
- prev: Curve;
23
- /**
24
- * The next curve (when going in a positive direction around
25
- * the shape boundary, i.e. anti-clockwise for the outer shape and clockwise
26
- * for the holes (if any))
27
- */
28
- next: Curve;
29
- /**
30
- * The curve's ordered index in the loop. This imposes a cycling
31
- * ordering of the curves in the loop
32
- */
33
- idx: number;
34
- }
4
+ // /**
5
+ // * Represents a bezier curve on the shape boundary / loop.
6
+ // */
7
+ // interface Curve {
8
+ // /**
9
+ // * The curve's ordered index in the loop. This imposes a cycling
10
+ // * ordering of the curves in the loop
11
+ // */
12
+ // readonly idx: number;
13
+ // /** The bezier control points. */
14
+ // readonly ps: number[][];
15
+ // /**
16
+ // * The closed loop of bezier curves representing the shape
17
+ // * boundary this curve belongs to.
18
+ // */
19
+ // readonly loop: Loop;
20
+ // /**
21
+ // * The previous curve (when going in a negative direction around
22
+ // * the shape boundary, i.e. clockwise for the outer shape and anti-clockwise
23
+ // * for the holes (if any))
24
+ // */
25
+ // readonly prev: Curve;
26
+ // /**
27
+ // * The next curve (when going in a positive direction around
28
+ // * the shape boundary, i.e. anti-clockwise for the outer shape and clockwise
29
+ // * for the holes (if any))
30
+ // */
31
+ // readonly next: Curve;
32
+ // }
35
33
 
36
34
 
37
- export { Curve }
35
+ // export { Curve }
@@ -1,5 +1,5 @@
1
+ import type { Curve } from 'flo-boolean';
1
2
  import { drawFs } from 'flo-draw';
2
- import { Curve } from '../../../curve/curve.js';
3
3
 
4
4
 
5
5
  /** @internal */
@@ -11,7 +11,7 @@ function dullCorner(
11
11
  scaleFactor = 1) {
12
12
 
13
13
  const ps = curve.ps;
14
- const p = curve.ps[ps.length-1];
14
+ const p = ps[ps.length-1];
15
15
  const $pos = drawFs.dot(g, p, 0.1*0.5*scaleFactor, classes, delay);
16
16
 
17
17
  return $pos;
@@ -1,5 +1,5 @@
1
+ import type { Curve } from 'flo-boolean';
1
2
  import { drawFs } from 'flo-draw';
2
- import { Curve } from '../../../curve/curve.js';
3
3
 
4
4
 
5
5
  /** @internal */
@@ -10,9 +10,10 @@ function sharpCorner(
10
10
  delay = 0,
11
11
  scaleFactor = 1) {
12
12
 
13
- const p = curve.ps[curve.ps.length-1];
13
+ const { ps } = curve;
14
+ const p = ps[ps.length-1];
14
15
  const $pos = drawFs.dot(g, p, 0.6*scaleFactor, 'green', delay);
15
-
16
+
16
17
  return $pos;
17
18
  }
18
19
 
@@ -52,10 +52,16 @@ function findMats(
52
52
  } = options_;
53
53
 
54
54
 
55
- const loopss = simplifyPaths(bezierLoops);
55
+ const loopss = simplifyPaths(bezierLoops, undefined, { forceOrientationNegative: true });
56
+
56
57
  // console.log(loopsToSvgPathStr(bezierLoops));
58
+ // console.log(loopsToSvgPathStr(loopss[0].map(loop => loop.beziers.map(ps => ps.map(p => p.map(c => Math.round(c*1)/1))))));
59
+ // console.log(loopsToSvgPathStr(loopss[1].map(loop => loop.beziers.map(ps => ps.map(p => p.map(c => Math.round(c*1)/1))))));
60
+ // console.log(loopsToSvgPathStr(loopss[0].map(loop => loop.beziers.map(ps => ps.map(p => p.map(c => Math.round(c*1000)/1000))))));
61
+ // console.log(loopsToSvgPathStr(loopss[1].map(loop => loop.beziers.map(ps => ps.map(p => p.map(c => Math.round(c*1000)/1000))))));
62
+ // console.log(loopss.map(loops => loops.map(loop => loop.beziers)));
63
+ // console.log(loopss.map(loops => loopsToSvgPathStr(loops.map(loop => loop.beziers))));
57
64
  // const loopss = [bezierLoops.map(loop => loopFromBeziers(loop,0))];
58
- // console.log(loopsToSvgPathStr(bezierLoops.map(v => v.map(v => v.map(v => v.map(v => v*2**4))))));
59
65
  // console.log(loopsToSvgPathStr(bezierLoops.map(v => v.map(v => v.map(v => [-v[0],v[1]])))));
60
66
  // console.log(loopsToSvgPathStr(loopss[0].map(loop => loop.beziers)));
61
67
 
@@ -1,12 +1,13 @@
1
+ import type { Debug } from '../debug/debug.js';
2
+ import type { Loop } from 'flo-boolean';
3
+ import type { Curve } from 'flo-boolean';
4
+ import type { CpNode } from '../cp-node/cp-node.js';
5
+ import type { TriMap } from '../utils/tri-map.js';
6
+ import type { MatMeta } from '../mat/mat-meta.js';
7
+ import { TriMapFs } from '../utils/tri-map.js';
1
8
  import { getBoundingHull, getBoundingBoxTight } from 'flo-bezier3';
2
- import { Debug } from '../debug/debug.js';
3
- import { Loop } from 'flo-boolean';
4
- import { Curve } from '../curve/curve.js';
5
9
  import { getBoundingBox$ } from '../geometry/get-bounding-box-.js';
6
10
  import { LlRbTree } from 'flo-ll-rb-tree';
7
- import { CpNode } from '../cp-node/cp-node.js';
8
- import { TriMap, TriMapFs } from '../utils/tri-map.js';
9
- import { MatMeta } from '../mat/mat-meta.js';
10
11
  import { getCorner } from '../corner/get-corner.js';
11
12
 
12
13
 
@@ -5,8 +5,8 @@ import { squaredDistanceBetween } from 'flo-vector2d';
5
5
  * Canonical circle representation.
6
6
  */
7
7
  interface Circle {
8
- center: number[];
9
- radius: number;
8
+ readonly center: number[];
9
+ readonly radius: number;
10
10
  }
11
11
 
12
12
 
@@ -29,7 +29,7 @@ function engulfsCircle(c1: Circle, c2: Circle) {
29
29
  if (c1.radius <= c2.radius) {
30
30
  return false;
31
31
  }
32
-
32
+
33
33
  const d = squaredDistanceBetween(c1.center, c2.center);
34
34
  const dr = c1.radius - c2.radius;
35
35
  const δ = dr*dr;
@@ -38,12 +38,5 @@ function engulfsCircle(c1: Circle, c2: Circle) {
38
38
  }
39
39
 
40
40
 
41
- /**
42
- * Returns a human-readable string description of the given circle.
43
- * @param circle
44
- */
45
- function toString(circle: Circle): string {
46
- return 'c: ' + circle.center + ' r: ' + circle.radius;
47
- }
48
-
49
- export { Circle, scaleCircle, engulfsCircle }
41
+ export type { Circle }
42
+ export { scaleCircle, engulfsCircle }
package/src/index.ts CHANGED
@@ -1,10 +1,8 @@
1
-
1
+ export type { Curve, Loop } from 'flo-boolean';
2
2
  export { loopFromBeziers, beziersToSvgPathStr, getPathsFromStr } from 'flo-boolean';
3
3
 
4
4
  export type { MatMeta } from './mat/mat-meta.js';
5
- export type { Loop } from 'flo-boolean';
6
5
  export type { Mat } from './mat/mat.js';
7
- export type { Curve } from './curve/curve.js';
8
6
  export type { CpNode } from './cp-node/cp-node.js';
9
7
  export type { PointOnShape } from './point-on-shape/point-on-shape.js';
10
8
  export type { Circle } from './geometry/circle.js';
@@ -87,4 +85,5 @@ export { getHoleClosers } from './cp-node/fs/get-hole-closers.js';
87
85
  export { getSpeed } from './cp-node/fs/get-speed.js';
88
86
  export { getSmoothedSpeed$ } from './cp-node/fs/get-smoothed-speed.js';
89
87
  export { getInitialDegAngleBetweenMatCurves } from './cp-node/fs/get-angle-between-mat-curves.js';
90
- export { getAllVertices } from './cp-node/fs/get-all-vertices.js';
88
+ export { getAllVertices } from './cp-node/fs/get-all-vertices.js';
89
+ export { isTrivial } from './cp-node/fs/is-trivial.js';
@@ -1,4 +1,4 @@
1
- import { Curve } from '../curve/curve.js';
1
+ import type { Curve } from 'flo-boolean';
2
2
 
3
3
 
4
4
  /**
@@ -7,9 +7,9 @@ import { Curve } from '../curve/curve.js';
7
7
  */
8
8
  interface CurvePiece {
9
9
  /** A bezier curve within the shape boundary. */
10
- curve: Curve;
10
+ readonly curve: Curve;
11
11
  /** The start and end t parameter values of the bezier curve. */
12
- ts: number[];
12
+ readonly ts: number[];
13
13
  }
14
14
 
15
15
 
@@ -1,6 +1,6 @@
1
- import { CpNode } from '../cp-node/cp-node.js';
2
- import { Curve } from '../curve/curve.js';
3
- import { CurvePiece } from './curve-piece.js';
1
+ import type { Curve } from 'flo-boolean';
2
+ import type { CpNode } from '../cp-node/cp-node.js';
3
+ import type { CurvePiece } from './curve-piece.js';
4
4
  import { isPosQuiteSharpCorner } from '../point-on-shape/is-pos-quite-sharp-corner.js';
5
5
  import { compareCps } from '../contact-point/contact-point.js';
6
6
 
@@ -1,8 +1,8 @@
1
+ import type { Loop } from 'flo-boolean';
2
+ import type { CpNode } from '../cp-node/cp-node.js';
3
+ import type { Curve } from 'flo-boolean';
4
+ import type { TriMap } from '../utils/tri-map.js';
1
5
  import { LlRbTree } from 'flo-ll-rb-tree';
2
- import { Loop } from 'flo-boolean';
3
- import { CpNode } from '../cp-node/cp-node.js';
4
- import { Curve } from '../curve/curve.js';
5
- import { TriMap } from '../utils/tri-map.js';
6
6
 
7
7
 
8
8
  interface MatMeta {
@@ -1,110 +1,110 @@
1
- import { closestPointOnBezier, hausdorffDistance, toCubic } from 'flo-bezier3';
2
- import { CpNode, isTerminating } from '../cp-node/cp-node.js';
3
- import { getBranches } from './get-branches.js';
4
- import { getCurveToNext } from '../cp-node/get-curve-to-next.js';
5
- import { getCurveBetween } from '../get-curve/get-curve-between.js';
6
-
7
-
8
- /**
9
- * Simplifies the given MAT by replacing the piecewise quad beziers composing
10
- * the MAT with fewer ones to within a given tolerance. Returns the map of
11
- * to be deleted nodes only - does not actually delete them. Use simplifyMat
12
- * instead if you want to delete the nodes.
13
- * @param cpNode A representation of the MAT
14
- * @param anlgeTolerance Tolerance given as the degrees difference of the unit
15
- * direction vectors at the interface between curves. A tolerance of zero means
16
- * perfect smoothness is required - defaults to 15.
17
- * @param hausdorffTolerance The approximate maximum Hausdorff Distance tolerance -
18
- * defaults to 0.1
19
- * @param hausdorffSpacing The spacing on the curves used to calculate the Hausdorff
20
- * Distance - defaults to 1
21
- */
22
- function simplifyMatMapOnly(
23
- cpNode: CpNode,
24
- anlgeTolerance = 15,
25
- hausdorffTolerance = 1e-1,
26
- hausdorffSpacing = 1e0) {
27
-
28
- const simpleMap: Map<CpNode, { ps: number[][], ts: number[] }> = new Map();
29
-
30
- // Start from a leaf
31
- while (!isTerminating(cpNode)) {
32
- cpNode = cpNode.next;
33
- }
34
-
35
- const branches = getBranches(cpNode, anlgeTolerance);
36
-
37
- const canDeletes: CpNode[] = [];
38
- for (let k=0; k<branches.length; k++) {
39
- const branch = branches[k];
40
-
41
- // Try to remove some
42
- let j = 0;
43
- while (j < branch.length) {
44
- const i = j;
45
- while (true) {
46
- j++;
47
-
48
- if (j === branch.length) { break; }
49
-
50
- const hd = getTotalHausdorffDistance(i, j, branch, hausdorffSpacing);
51
-
52
- if (hd > hausdorffTolerance) {
53
- break;
54
- } else {
55
- canDeletes.push(branch[j]);
56
- }
57
- }
58
-
59
- if (i + 1 === j) {
60
- // no simplification occured
61
- } else {
62
- const branStart = branch[i];
63
- const branEnd = branch[j-1];
64
-
65
- const medial = toCubic(getCurveBetween(branStart, branEnd.next));
66
- const rev = medial.slice().reverse();
67
- let curCpNode = branStart;
68
- let prevT = 0;
69
- while (curCpNode !== branEnd) {
70
- const t = closestPointOnBezier(medial, curCpNode.next.cp.circle.center).t;
71
- simpleMap.set(curCpNode, { ps: medial, ts: [prevT, t] });
72
- const oppositeCpNode = curCpNode.nextOnCircle.prev;
73
- simpleMap.set(oppositeCpNode, { ps: rev, ts: [1-t, 1-prevT] });
74
-
75
- prevT = t;
76
- curCpNode = curCpNode.next;
77
- }
78
- simpleMap.set(curCpNode, { ps: medial, ts: [prevT, 1] });
79
-
80
- const oppositeCpNode = curCpNode.nextOnCircle.prev;
81
- simpleMap.set(oppositeCpNode, { ps: rev, ts: [0, 1-prevT] });
82
- }
83
- }
84
- }
85
-
86
- return { simpleMap, cpNode };
87
- }
88
-
89
-
90
- function getTotalHausdorffDistance(
91
- i: number,
92
- j: number,
93
- branch: CpNode[],
94
- hausdorffSpacing: number) {
95
-
96
- const hds: number[] = [];
97
- const longCurve = getCurveBetween(branch[i], branch[j].next);
98
- for (let m=i; m<j+1; m++) {
99
- hds.push(hausdorffDistance(
100
- getCurveToNext(branch[m]),
101
- longCurve,
102
- hausdorffSpacing
103
- ));
104
- }
105
-
106
- return Math.max(...hds);
107
- }
108
-
109
-
110
- export { simplifyMatMapOnly }
1
+ // import { closestPointOnBezier, hausdorffDistance, toCubic } from 'flo-bezier3';
2
+ // import { CpNode, isTerminating } from '../cp-node/cp-node.js';
3
+ // import { getBranches } from './get-branches.js';
4
+ // import { getCurveToNext } from '../cp-node/get-curve-to-next.js';
5
+ // import { getCurveBetween } from '../get-curve/get-curve-between.js';
6
+
7
+
8
+ // /**
9
+ // * Simplifies the given MAT by replacing the piecewise quad beziers composing
10
+ // * the MAT with fewer ones to within a given tolerance. Returns the map of
11
+ // * to be deleted nodes only - does not actually delete them. Use simplifyMat
12
+ // * instead if you want to delete the nodes.
13
+ // * @param cpNode A representation of the MAT
14
+ // * @param anlgeTolerance Tolerance given as the degrees difference of the unit
15
+ // * direction vectors at the interface between curves. A tolerance of zero means
16
+ // * perfect smoothness is required - defaults to 15.
17
+ // * @param hausdorffTolerance The approximate maximum Hausdorff Distance tolerance -
18
+ // * defaults to 0.1
19
+ // * @param hausdorffSpacing The spacing on the curves used to calculate the Hausdorff
20
+ // * Distance - defaults to 1
21
+ // */
22
+ // function simplifyMatMapOnly(
23
+ // cpNode: CpNode,
24
+ // anlgeTolerance = 15,
25
+ // hausdorffTolerance = 1e-1,
26
+ // hausdorffSpacing = 1e0) {
27
+
28
+ // const simpleMap: Map<CpNode, { ps: number[][], ts: number[] }> = new Map();
29
+
30
+ // // Start from a leaf
31
+ // while (!isTerminating(cpNode)) {
32
+ // cpNode = cpNode.next;
33
+ // }
34
+
35
+ // const branches = getBranches(cpNode, anlgeTolerance);
36
+
37
+ // const canDeletes: CpNode[] = [];
38
+ // for (let k=0; k<branches.length; k++) {
39
+ // const branch = branches[k];
40
+
41
+ // // Try to remove some
42
+ // let j = 0;
43
+ // while (j < branch.length) {
44
+ // const i = j;
45
+ // while (true) {
46
+ // j++;
47
+
48
+ // if (j === branch.length) { break; }
49
+
50
+ // const hd = getTotalHausdorffDistance(i, j, branch, hausdorffSpacing);
51
+
52
+ // if (hd > hausdorffTolerance) {
53
+ // break;
54
+ // } else {
55
+ // canDeletes.push(branch[j]);
56
+ // }
57
+ // }
58
+
59
+ // if (i + 1 === j) {
60
+ // // no simplification occured
61
+ // } else {
62
+ // const branStart = branch[i];
63
+ // const branEnd = branch[j-1];
64
+
65
+ // const medial = toCubic(getCurveBetween(branStart, branEnd.next));
66
+ // const rev = medial.slice().reverse();
67
+ // let curCpNode = branStart;
68
+ // let prevT = 0;
69
+ // while (curCpNode !== branEnd) {
70
+ // const t = closestPointOnBezier(medial, curCpNode.next.cp.circle.center).t;
71
+ // simpleMap.set(curCpNode, { ps: medial, ts: [prevT, t] });
72
+ // const oppositeCpNode = curCpNode.nextOnCircle.prev;
73
+ // simpleMap.set(oppositeCpNode, { ps: rev, ts: [1-t, 1-prevT] });
74
+
75
+ // prevT = t;
76
+ // curCpNode = curCpNode.next;
77
+ // }
78
+ // simpleMap.set(curCpNode, { ps: medial, ts: [prevT, 1] });
79
+
80
+ // const oppositeCpNode = curCpNode.nextOnCircle.prev;
81
+ // simpleMap.set(oppositeCpNode, { ps: rev, ts: [0, 1-prevT] });
82
+ // }
83
+ // }
84
+ // }
85
+
86
+ // return { simpleMap, cpNode };
87
+ // }
88
+
89
+
90
+ // function getTotalHausdorffDistance(
91
+ // i: number,
92
+ // j: number,
93
+ // branch: CpNode[],
94
+ // hausdorffSpacing: number) {
95
+
96
+ // const hds: number[] = [];
97
+ // const longCurve = getCurveBetween(branch[i], branch[j].next);
98
+ // for (let m=i; m<j+1; m++) {
99
+ // hds.push(hausdorffDistance(
100
+ // getCurveToNext(branch[m]),
101
+ // longCurve,
102
+ // hausdorffSpacing
103
+ // ));
104
+ // }
105
+
106
+ // return Math.max(...hds);
107
+ // }
108
+
109
+
110
+ // export { simplifyMatMapOnly }