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.
- package/__tests__/cp-node/check-clone-eql-calc.spec.ts +58 -0
- package/__tests__/cp-node/compare-cp-nodes-by-value.ts +35 -0
- package/__tests__/cp-node/compare-loops-by-value.ts +40 -0
- package/__tests__/cp-node/compare-poss-by-value.ts +25 -0
- package/__tests__/cp-node/fs/clone.spec.ts +19 -3
- package/__tests__/cp-node/fs/find-first.spec.ts +13 -3
- package/__tests__/cp-node/fs/get-all-between.spec.ts +20 -3
- package/__tests__/cp-node/fs/get-all-on-circle.spec.ts +2 -2
- package/__tests__/cp-node/fs/get-all-on-loop.spec.ts +16 -3
- package/__tests__/cp-node/fs/get-all-vertices.spec.ts +14 -3
- package/__tests__/cp-node/fs/get-children.spec.ts +18 -3
- package/__tests__/cp-node/fs/get-non-terminating-on-circle.spec.ts +14 -3
- package/__tests__/cp-node/fs/get-prong-count.spec.ts +16 -3
- package/__tests__/cp-node/fs/get-real-prong-count.spec.ts +11 -3
- package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +20 -3
- package/__tests__/cp-node/fs/is-fully-terminating.spec.ts +16 -3
- package/__tests__/cp-node/fs/is-on-same-circle.spec.ts +20 -3
- package/__tests__/cp-node/fs/is-one-prong.spec.ts +16 -3
- package/__tests__/cp-node/fs/is-sharp.spec.ts +10 -3
- package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +13 -3
- package/__tests__/cp-node/fs/is-special.spec.ts +12 -3
- package/__tests__/cp-node/fs/is-terminating.spec.ts +15 -3
- package/__tests__/cp-node/fs/is-trivial.spec.ts +13 -3
- package/__tests__/cp-node/fs/is-two-prong.spec.ts +11 -3
- package/__tests__/cp-node/fs/is-vertex-special.spec.ts +13 -3
- package/__tests__/cp-node/fs/is-vertex.spec.ts +14 -3
- package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +13 -3
- package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +10 -3
- package/__tests__/cp-node/fs/traverse-cp.spec.ts +9 -3
- package/__tests__/cp-node/fs/traverse-edges.spec.ts +13 -3
- package/__tests__/cp-node/fs/traverse-vertices.spec.ts +12 -3
- package/__tests__/cp-node/random-walk.ts +33 -0
- package/__tests__/cp-node/stringification/from-stringifyable.spec.ts +3 -0
- package/__tests__/cp-node/stringification/loop-from-stringifyable.spec.ts +4 -0
- package/__tests__/cp-node/stringification/loop-to-stringifyable.spec.ts +19 -0
- package/__tests__/cp-node/stringification/to-stringifyable.spec.ts +34 -0
- package/__tests__/get-mats1.ts +125 -0
- package/__tests__/jsog/check-jsog-eql-calc.spec.ts +47 -67
- package/__tests__/jsog/decode-jsog.ts +88 -85
- package/__tests__/jsog/mat-dummy-1.ts +19 -0
- package/__tests__/jsog/mat-dummys.ts +6197 -6195
- package/__tests__/jsog/to-jsog-breath-first.ts +110 -107
- package/__tests__/jsog/to-jsog-depth-first.ts +58 -55
- package/browser/index.js +7002 -6298
- package/browser/index.min.js +1 -1
- package/jest.config.cjs +1 -0
- package/node/closest-boundary-point/foot-and-endpoint-info.d.ts +1 -1
- package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +3 -3
- package/node/closest-boundary-point/get-close-boundary-points-certified.js +1 -1
- package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.d.ts +2 -2
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +7 -7
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
- package/node/cp-node/cp-node.d.ts +2 -2
- package/node/cp-node/fs/clone.d.ts +1 -1
- package/node/cp-node/fs/clone.js +17 -13
- package/node/cp-node/fs/clone.js.map +1 -1
- package/node/cp-node/fs/enhance-cp-node.d.ts +2 -2
- package/node/cp-node/fs/find-first.d.ts +9 -2
- package/node/cp-node/fs/find-first.js +12 -9
- package/node/cp-node/fs/find-first.js.map +1 -1
- package/node/cp-node/fs/get-all-on-loop.js +5 -6
- package/node/cp-node/fs/get-all-on-loop.js.map +1 -1
- package/node/cp-node/fs/get-edge-direction.d.ts +1 -1
- package/node/cp-node/fs/get-edge-direction.js.map +1 -1
- package/node/cp-node/fs/is-on-same-circle.d.ts +1 -0
- package/node/cp-node/fs/is-on-same-circle.js +1 -0
- package/node/cp-node/fs/is-on-same-circle.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.d.ts +1 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.js +1 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.d.ts +1 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.js +2 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +1 -1
- package/node/find-mat/find-mats.js +7 -2
- package/node/find-mat/find-mats.js.map +1 -1
- package/node/find-mat/get-meta.d.ts +4 -4
- package/node/find-mat/get-meta.js +1 -1
- package/node/find-mat/get-meta.js.map +1 -1
- package/node/geometry/circle.d.ts +4 -3
- package/node/geometry/circle.js +0 -7
- package/node/geometry/circle.js.map +1 -1
- package/node/index.d.ts +2 -2
- package/node/index.js +1 -0
- package/node/index.js.map +1 -1
- package/node/mat/curve-piece.d.ts +3 -3
- package/node/mat/get-boundary-piece-beziers.d.ts +2 -2
- package/node/mat/mat-meta.d.ts +4 -4
- package/node/mat/simplify-mat.d.ts +10 -8
- package/node/mat/simplify-mat.js +12 -10
- package/node/mat/simplify-mat.js.map +1 -1
- package/node/point-on-shape/create-pos.d.ts +2 -2
- package/node/point-on-shape/create-pos.js.map +1 -1
- package/node/point-on-shape/point-on-shape.d.ts +6 -6
- package/node/svg/get-loop-bounds.d.ts +2 -2
- package/node/svg/get-loop-bounds.js +1 -1
- package/node/svg/get-loop-bounds.js.map +1 -1
- package/package.json +10 -10
- package/src/closest-boundary-point/foot-and-endpoint-info.ts +1 -1
- package/src/closest-boundary-point/get-close-boundary-points-certified.ts +5 -5
- package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +9 -9
- package/src/cp-node/cp-node.ts +8 -3
- package/src/cp-node/fs/add-distance-from.ts +37 -37
- package/src/cp-node/fs/clone.ts +23 -17
- package/src/cp-node/fs/find-first.ts +14 -11
- package/src/cp-node/fs/get-all-on-loop.ts +5 -6
- package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +1 -1
- package/src/cp-node/fs/get-edge-direction.ts +3 -5
- package/src/cp-node/fs/is-on-same-circle.ts +1 -0
- package/src/cp-node/stringification/cp-node-stringifyable.ts +68 -0
- package/src/cp-node/stringification/from-stringifyable.ts +57 -0
- package/src/cp-node/stringification/loop-from-stringifyable.ts +15 -0
- package/src/cp-node/stringification/loop-stringifyable.ts +8 -0
- package/src/cp-node/stringification/loop-to-stringifyable.ts +14 -0
- package/src/cp-node/stringification/to-stringifyable.ts +71 -0
- package/src/curve/curve.ts +31 -33
- package/src/debug/functions/draw-elem/draw-dull-corner.ts +2 -2
- package/src/debug/functions/draw-elem/draw-sharp-corner.ts +4 -3
- package/src/find-mat/find-mats.ts +8 -2
- package/src/find-mat/get-meta.ts +7 -6
- package/src/geometry/circle.ts +5 -12
- package/src/index.ts +3 -4
- package/src/mat/curve-piece.ts +3 -3
- package/src/mat/get-boundary-piece-beziers.ts +3 -3
- package/src/mat/mat-meta.ts +4 -4
- package/src/mat/simplify-mat-map-only.ts +110 -110
- package/src/mat/simplify-mat.ts +15 -13
- package/src/point-on-shape/create-pos.ts +3 -3
- package/src/point-on-shape/point-on-shape.ts +6 -6
- package/src/svg/get-loop-bounds.ts +4 -5
- package/__tests__/cp-node/fs/add-distance-from.spec.ts +0 -7
- package/__tests__/cp-node/fs/cp-nodes-to-boundary-beziers.spec.ts +0 -7
- package/__tests__/cp-node/fs/create-cp-node.spec.ts +0 -7
- package/__tests__/cp-node/fs/enhance-cp-node.spec.ts +0 -7
- package/__tests__/jsog/get-mats1.ts +0 -41
- package/node/curve/curve.d.ts +0 -33
- package/node/curve/curve.js +0 -2
- 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,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
|
+
|
package/src/curve/curve.ts
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
import { Loop } from 'flo-boolean';
|
|
1
|
+
// import type { Loop } from 'flo-boolean';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
interface Curve {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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 =
|
|
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
|
|
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
|
|
package/src/find-mat/get-meta.ts
CHANGED
|
@@ -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
|
|
package/src/geometry/circle.ts
CHANGED
|
@@ -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
|
-
|
|
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';
|
package/src/mat/curve-piece.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Curve } from '
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
|
package/src/mat/mat-meta.ts
CHANGED
|
@@ -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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
function simplifyMatMapOnly(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
function getTotalHausdorffDistance(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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 }
|