flo-mat 3.0.6 → 3.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/cp-node/fs/add-distance-from.spec.ts +7 -0
- package/__tests__/cp-node/fs/check-jsog-eql-calc.spec.ts +30 -0
- package/__tests__/cp-node/fs/clone.spec.ts +7 -0
- package/__tests__/cp-node/fs/cp-nodes-to-boundary-beziers.spec.ts +7 -0
- package/__tests__/cp-node/fs/create-cp-node.spec.ts +7 -0
- package/__tests__/cp-node/fs/enhance-cp-node.spec.ts +7 -0
- package/__tests__/cp-node/fs/find-first.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-all-between.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-all-on-circle.spec.ts +92 -0
- package/__tests__/cp-node/fs/get-all-on-loop.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-all-vertices.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-angle-between-mat-curves.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-avg-speed.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-boundary-bezier-parts-to-next.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-boundary-beziers-between.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-boundary-beziers-to-next.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-boundary-distance-to-next.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-branch-beziers.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-branch.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-children.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-cp-node-ordering.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-distance-between.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-distance-to-next.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-edge-direction.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-first-exit.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-hole-closers.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-implied-boundary-bezier-between.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-mat-curve-between.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-mat-curve-to-next.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-mat-curves-between.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-non-terminating-on-circle.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-prong-count.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-real-prong-count.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-salience.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-smoothed-speed.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-smoothed.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-speed.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +7 -0
- package/__tests__/cp-node/fs/get-vertex-forward-children.spec.ts +7 -0
- package/__tests__/cp-node/fs/insert-cp-node.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-fully-terminating.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-on-same-circle.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-one-prong.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-order-correct.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-sharp.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-special.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-terminating.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-trivial.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-two-prong.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-vertex-special.spec.ts +7 -0
- package/__tests__/cp-node/fs/is-vertex.spec.ts +7 -0
- package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +7 -0
- package/__tests__/cp-node/fs/mat-dummys.ts +6716 -0
- package/__tests__/cp-node/fs/remove-cp-node.spec.ts +7 -0
- package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +7 -0
- package/__tests__/cp-node/fs/traverse-cp.spec.ts +7 -0
- package/__tests__/cp-node/fs/traverse-edges.spec.ts +7 -0
- package/__tests__/cp-node/fs/traverse-vertices.spec.ts +7 -0
- package/__tests__/lib-load.spec.ts +9 -10
- package/browser/index.js +259 -174
- package/browser/index.min.js +1 -1
- package/jest.config.cjs +32 -0
- package/node/corner/get-interface-ccw.js +0 -1
- package/node/corner/get-interface-ccw.js.map +1 -1
- package/node/cp-node/cp-node-fs.d.ts +43 -43
- package/node/cp-node/cp-node-fs.js +43 -43
- package/node/cp-node/cp-node.d.ts +27 -35
- package/node/cp-node/fs/clone.d.ts +3 -3
- package/node/cp-node/fs/clone.js +3 -3
- package/node/cp-node/fs/enhance-cp-node.d.ts +1 -5
- package/node/cp-node/fs/enhance-cp-node.js.map +1 -1
- package/node/cp-node/fs/get-all-between.d.ts +3 -3
- package/node/cp-node/fs/get-all-between.js +3 -3
- package/node/cp-node/fs/get-all-between.js.map +1 -1
- package/node/cp-node/fs/get-all-on-circle.d.ts +7 -1
- package/node/cp-node/fs/get-all-on-circle.js +11 -7
- package/node/cp-node/fs/get-all-on-circle.js.map +1 -1
- package/node/cp-node/fs/get-all-on-loop.d.ts +1 -1
- package/node/cp-node/fs/get-all-on-loop.js.map +1 -1
- package/node/cp-node/fs/get-boundary-bezier-parts-to-next.d.ts +12 -3
- package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js +22 -7
- package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js.map +1 -1
- package/node/cp-node/fs/get-boundary-beziers-between.d.ts +1 -1
- package/node/cp-node/fs/get-boundary-beziers-between.js.map +1 -1
- package/node/cp-node/fs/get-boundary-beziers-to-next.js.map +1 -1
- package/node/cp-node/fs/insert-cp-node.d.ts +3 -1
- package/node/cp-node/fs/insert-cp-node.js +12 -2
- package/node/cp-node/fs/insert-cp-node.js.map +1 -1
- package/node/cp-node/fs/is-fully-terminating.d.ts +7 -0
- package/node/cp-node/fs/is-fully-terminating.js +7 -0
- package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
- package/node/cp-node/fs/is-terminating.d.ts +1 -1
- package/node/cp-node/fs/remove-cp-node.d.ts +3 -4
- package/node/cp-node/fs/remove-cp-node.js +3 -1
- package/node/cp-node/fs/remove-cp-node.js.map +1 -1
- package/node/curve/curve.d.ts +18 -11
- package/node/find-2-prong/add-1-prong.js +1 -1
- package/node/find-2-prong/add-1-prong.js.map +1 -1
- package/node/find-2-prong/add-2-prong.js +9 -7
- package/node/find-2-prong/add-2-prong.js.map +1 -1
- package/node/find-2-prong/calc-seperation-tolerance.d.ts +8 -1
- package/node/find-2-prong/calc-seperation-tolerance.js +73 -59
- package/node/find-2-prong/calc-seperation-tolerance.js.map +1 -1
- package/node/find-2-prong/find-2-prong.js +2 -2
- package/node/find-2-prong/find-2-prong.js.map +1 -1
- package/node/find-2-prong/get-initial-bezier-pieces.d.ts +2 -3
- package/node/find-2-prong/get-initial-bezier-pieces.js +4 -1
- package/node/find-2-prong/get-initial-bezier-pieces.js.map +1 -1
- package/node/find-3-prong.ts/find-and-add-3-prong.js +1 -1
- package/node/find-3-prong.ts/find-and-add-3-prong.js.map +1 -1
- package/node/find-3-prong.ts/find-and-add-3-prongs-on-loop.d.ts +2 -2
- package/node/find-3-prong.ts/find-and-add-3-prongs-on-loop.js +8 -3
- package/node/find-3-prong.ts/find-and-add-3-prongs-on-loop.js.map +1 -1
- package/node/find-mat/create-initial-cp-tree.d.ts +7 -3
- package/node/find-mat/create-initial-cp-tree.js +7 -5
- package/node/find-mat/create-initial-cp-tree.js.map +1 -1
- package/node/find-mat/find-mat.d.ts +2 -1
- package/node/find-mat/find-mat.js +14 -4
- package/node/find-mat/find-mat.js.map +1 -1
- package/node/find-mat/get-meta.d.ts +5 -2
- package/node/find-mat/get-meta.js +15 -14
- package/node/find-mat/get-meta.js.map +1 -1
- package/node/index.d.ts +1 -1
- package/node/index.js +1 -1
- package/node/index.js.map +1 -1
- package/node/mat/add-to-cp-tree.d.ts +5 -6
- package/node/mat/add-to-cp-tree.js +5 -2
- package/node/mat/add-to-cp-tree.js.map +1 -1
- package/node/mat/get-branches.d.ts +7 -0
- package/node/mat/get-branches.js +7 -0
- package/node/mat/get-branches.js.map +1 -1
- package/node/mat/mat-meta.d.ts +8 -1
- package/node/mat/mat.d.ts +3 -3
- package/node/mat/simplify-mat.js +1 -1
- package/node/mat/simplify-mat.js.map +1 -1
- package/node/point-on-shape/compare-poss.d.ts +3 -3
- package/node/point-on-shape/compare-poss.js +3 -3
- package/node/point-on-shape/get-osculating-circle.d.ts +1 -1
- package/node/point-on-shape/get-osculating-circle.js +1 -1
- package/node/point-on-shape/point-on-shape.d.ts +1 -1
- package/node/point-on-shape/pos-to-human-string.d.ts +1 -1
- package/node/point-on-shape/pos-to-human-string.js +1 -1
- package/node/sat/to-scale-axis.d.ts +1 -1
- package/node/sat/to-scale-axis.js +1 -1
- package/node/vertex/remove-vertex.d.ts +3 -4
- package/node/vertex/remove-vertex.js +3 -2
- package/node/vertex/remove-vertex.js.map +1 -1
- package/package.json +9 -6
- package/src/corner/get-interface-ccw.ts +0 -1
- package/src/cp-node/cp-node-fs.ts +43 -43
- package/src/cp-node/cp-node.ts +27 -39
- package/src/cp-node/fs/clone.ts +3 -3
- package/src/cp-node/fs/enhance-cp-node.ts +0 -1
- package/src/cp-node/fs/get-all-between.ts +31 -28
- package/src/cp-node/fs/get-all-on-circle.ts +13 -8
- package/src/cp-node/fs/get-all-on-loop.ts +12 -10
- package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +39 -22
- package/src/cp-node/fs/get-boundary-beziers-between.ts +6 -2
- package/src/cp-node/fs/get-boundary-beziers-to-next.ts +6 -4
- package/src/cp-node/fs/insert-cp-node.ts +13 -2
- package/src/cp-node/fs/is-fully-terminating.ts +7 -0
- package/src/cp-node/fs/is-terminating.ts +1 -1
- package/src/cp-node/fs/remove-cp-node.ts +8 -4
- package/src/curve/curve.ts +19 -13
- package/src/debug/functions/check-ordering.ts +7 -3
- package/src/find-2-prong/add-1-prong.ts +1 -1
- package/src/find-2-prong/add-2-prong.ts +79 -74
- package/src/find-2-prong/calc-seperation-tolerance.ts +88 -78
- package/src/find-2-prong/find-2-prong.ts +2 -2
- package/src/find-2-prong/get-initial-bezier-pieces.ts +5 -1
- package/src/find-3-prong.ts/add-3-prong.ts +73 -70
- package/src/find-3-prong.ts/find-and-add-3-prong.ts +1 -1
- package/src/find-3-prong.ts/find-and-add-3-prongs-on-loop.ts +9 -8
- package/src/find-mat/create-initial-cp-tree.ts +10 -6
- package/src/find-mat/find-mat.ts +18 -5
- package/src/find-mat/get-meta.ts +36 -20
- package/src/get-curve/get-curve-between.ts +2 -2
- package/src/index.ts +1 -1
- package/src/mat/add-to-cp-tree.ts +18 -9
- package/src/mat/get-branches.ts +35 -28
- package/src/mat/mat-meta.ts +6 -1
- package/src/mat/mat.ts +3 -3
- package/src/mat/simplify-mat.ts +1 -1
- package/src/point-on-shape/compare-poss.ts +3 -3
- package/src/point-on-shape/get-osculating-circle.ts +1 -1
- package/src/point-on-shape/point-on-shape.ts +1 -1
- package/src/point-on-shape/pos-to-human-string.ts +1 -1
- package/src/sat/to-scale-axis.ts +1 -1
- package/src/vertex/remove-vertex.ts +7 -5
- package/.mocharc.cjs +0 -17
- package/src/debug/functions/draw-elem/branch.ts +0 -26
- package/src/find-mat/create-initial-cp-graph.ts +0 -59
|
@@ -9,6 +9,7 @@ import { calcPosOrder } from '../point-on-shape/calc-pos-order.js';
|
|
|
9
9
|
import { Circle } from '../geometry/circle.js';
|
|
10
10
|
import { isPosCorner } from '../point-on-shape/is-pos-corner.js';
|
|
11
11
|
import { getPosCorner } from '../point-on-shape/get-pos-corner.js';
|
|
12
|
+
import { MatMeta } from '../index.js';
|
|
12
13
|
|
|
13
14
|
|
|
14
15
|
/** @internal */
|
|
@@ -17,10 +18,13 @@ function getInitialBezierPieces(
|
|
|
17
18
|
isHoleClosing: boolean,
|
|
18
19
|
loop: Loop,
|
|
19
20
|
loops: Loop[],
|
|
20
|
-
cpTrees: Map<Loop,LlRbTree<CpNode>>,
|
|
21
|
+
// cpTrees: Map<Loop,LlRbTree<CpNode>>,
|
|
22
|
+
meta: MatMeta,
|
|
21
23
|
y: PointOnShape,
|
|
22
24
|
circle: Circle): CurvePiece[] {
|
|
23
25
|
|
|
26
|
+
const { cpTrees } = meta;
|
|
27
|
+
|
|
24
28
|
if (isHoleClosing) {
|
|
25
29
|
return loops
|
|
26
30
|
.filter(_loop => _loop !== loop)
|
|
@@ -8,6 +8,7 @@ import { Circle } from '../geometry/circle.js';
|
|
|
8
8
|
import { PointOnShape } from '../point-on-shape/point-on-shape.js';
|
|
9
9
|
import { addToCpGraph } from '../mat/add-to-cp-graph.js';
|
|
10
10
|
import { isAnotherCpCloseby } from '../mat/is-another-cp-closeby.js';
|
|
11
|
+
import { MatMeta } from '../mat/mat-meta.js';
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -24,86 +25,88 @@ import { isAnotherCpCloseby } from '../mat/is-another-cp-closeby.js';
|
|
|
24
25
|
* @param threeProng
|
|
25
26
|
*/
|
|
26
27
|
function add3Prong(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
// cpTrees: Map<Loop,LlRbTree<CpNode>>,
|
|
29
|
+
meta: MatMeta,
|
|
30
|
+
orders: number[],
|
|
31
|
+
threeProng: {
|
|
32
|
+
circle: Circle,
|
|
33
|
+
ps: PointOnShape[],
|
|
34
|
+
δ3s: CpNode[][]
|
|
35
|
+
}): CpNode[] {
|
|
36
|
+
|
|
37
|
+
const { cpTrees } = meta;
|
|
38
|
+
const { circle, ps: poss, δ3s } = threeProng;
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
// Keep for possible future debugging.
|
|
38
41
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
/*
|
|
43
|
+
let ii = -1;
|
|
44
|
+
if (typeof _debug_ !== 'undefined') {
|
|
45
|
+
for (let i=0; i<3; i++) {
|
|
46
|
+
const cpBef = threeProng.δ3s[i][0].cp;
|
|
47
|
+
const cpAft = threeProng.δ3s[i][1].cp;
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
//let cmpBef = PointOnShape.compareInclOrder(cpBef.pointOnShape, poss[i], cpBef.order, orders[i]);
|
|
50
|
+
//let cmpAft = PointOnShape.compareInclOrder(cpAft.pointOnShape, poss[i], cpAft.order, orders[i]);
|
|
51
|
+
const cmpBef = compareCps(cpBef, { pointOnShape: poss[i], order: orders[i], order2: 0, circle: undefined });
|
|
52
|
+
const cmpAft = compareCps(cpAft, { pointOnShape: poss[i], order: orders[i], order2: 0, circle: undefined });
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
// const cmpBef = comparePoss(cpBef.pointOnShape, poss[i]);
|
|
55
|
+
// const cmpAft = comparePoss(cpAft.pointOnShape, poss[i]);
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
57
|
+
// len is used by debug functions to reference a particular
|
|
58
|
+
// three-prong.
|
|
59
|
+
const len = _debug_.generated.elems.threeProng.length-1;
|
|
60
|
+
if (cmpBef > 0) {
|
|
61
|
+
console.log('----------------------------------------');
|
|
62
|
+
console.log(`3-prong order is wrong (bef) : i: ${i} - cmp: ${cmpBef} - n: ${len}`);
|
|
63
|
+
console.log(threeProng);
|
|
64
|
+
console.log(cpBef);
|
|
65
|
+
console.log(cpAft);
|
|
66
|
+
console.log(poss[i]);
|
|
67
|
+
ii = i;
|
|
68
|
+
}
|
|
69
|
+
if (cmpAft < 0) {
|
|
70
|
+
console.log('----------------------------------------');
|
|
71
|
+
console.log(`3-prong order is wrong (aft) : i: ${i} - cmp: ${cmpAft} - n: ${len}`);
|
|
72
|
+
console.log(threeProng);
|
|
73
|
+
console.log(cpBef);
|
|
74
|
+
console.log(cpAft);
|
|
75
|
+
console.log(poss[i]);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
*/
|
|
77
80
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
// TODO - replace 1000 below with correct value
|
|
82
|
+
const c1 = isAnotherCpCloseby(cpTrees, poss[0], circle, orders[0], 0, 1000);
|
|
83
|
+
const c2 = isAnotherCpCloseby(cpTrees, poss[1], circle, orders[1], 0, 1000);
|
|
84
|
+
const c3 = isAnotherCpCloseby(cpTrees, poss[2], circle, orders[2], 0, 1000);
|
|
82
85
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
86
|
+
// for (let pos of poss) {
|
|
87
|
+
// if (pos.t === 0.9978869234519733) {
|
|
88
|
+
// console.log(pos)
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
91
|
+
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
// if (!!c1) {
|
|
94
|
+
// console.log(getRealProngCount(c1));
|
|
95
|
+
// }
|
|
96
|
+
// if (!!c2) {
|
|
97
|
+
// console.log(getRealProngCount(c2));
|
|
98
|
+
// }
|
|
99
|
+
// if (!!c3) {
|
|
100
|
+
// console.log(getRealProngCount(c3));
|
|
101
|
+
// }
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
+
// if (!!c1) { return [c1]; }
|
|
104
|
+
// if (!!c2) { return [c2]; }
|
|
105
|
+
// if (!!c3) { return [c3]; }
|
|
103
106
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
const cps = addToCpGraph(circle, orders, cpTrees, poss, δ3s);
|
|
108
|
+
|
|
109
|
+
return cps;
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
|
|
@@ -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
|
|
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,
|
|
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
|
|
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;
|
package/src/find-mat/find-mat.ts
CHANGED
|
@@ -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 {
|
|
10
|
+
import { getPointToCpNode, getPartialMeta, addDebugInfo2, addDebugInfo3, addDebugInfo4 } from './get-meta.js';
|
|
11
11
|
import { getSharpCornersOnLoop } from './get-sharp-corners.js';
|
|
12
12
|
import { getDullCornersOnLoop } from './get-dull-corners-on-loop.js';
|
|
13
13
|
import { findAndAdd2ProngsOnAllLoops } from '../find-2-prong/find-and-add-2-prongs-on-all-loops.js';
|
|
@@ -16,6 +16,7 @@ import { getFor1ProngsOnLoop } from './get-for-1-prongs-on-loop.js';
|
|
|
16
16
|
import { findAndAddHoleClosing2Prongs } from '../find-2-prong/find-and-add-hole-closing-2-prongs.js';
|
|
17
17
|
import { getShapeBounds } from '../svg/get-shape-bounds.js';
|
|
18
18
|
import { MatOptions } from './mat-options.js';
|
|
19
|
+
import { MatMeta } from '../mat/mat-meta.js';
|
|
19
20
|
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -38,15 +39,27 @@ function findMat(
|
|
|
38
39
|
|
|
39
40
|
const sharpCornersPerLoop = loops.map(getSharpCornersOnLoop_);
|
|
40
41
|
|
|
41
|
-
const cpTrees: Map<Loop, LlRbTree<CpNode>> = new Map();
|
|
42
|
-
createInitialCpTree(loops, cpTrees, sharpCornersPerLoop);
|
|
43
|
-
|
|
44
42
|
const bounds = getShapeBounds(loops);
|
|
45
43
|
const squaredDiagonalLength =
|
|
46
44
|
(bounds.maxX.p[0] - bounds.minX.p[0])**2 +
|
|
47
45
|
(bounds.maxY.p[1] - bounds.minY.p[1])**2;
|
|
48
46
|
|
|
49
|
-
const
|
|
47
|
+
const cpTrees: Map<Loop, LlRbTree<CpNode>> = new Map();
|
|
48
|
+
const lastInsertId = { id: 0 };
|
|
49
|
+
createInitialCpTree(loops, cpTrees, sharpCornersPerLoop, lastInsertId);
|
|
50
|
+
|
|
51
|
+
const _meta = getPartialMeta(loops);
|
|
52
|
+
const pointToCpNode = getPointToCpNode(loops, cpTrees);
|
|
53
|
+
const meta: MatMeta = {
|
|
54
|
+
maxCoordinate, squaredDiagonalLength, loops, cpTrees, pointToCpNode,
|
|
55
|
+
lastInsertId, ..._meta
|
|
56
|
+
};
|
|
57
|
+
// const cpTrees: Map<Loop, LlRbTree<CpNode>> = new Map();
|
|
58
|
+
// const lastInsertId = { id: 0 };
|
|
59
|
+
// createInitialCpTree(loops, cpTrees, sharpCornersPerLoop, lastInsertId);
|
|
60
|
+
|
|
61
|
+
// const meta = getMeta(maxCoordinate, squaredDiagonalLength, loops, cpTrees, lastInsertId);
|
|
62
|
+
|
|
50
63
|
|
|
51
64
|
let cpNode: CpNode | undefined;
|
|
52
65
|
|
package/src/find-mat/get-meta.ts
CHANGED
|
@@ -18,23 +18,14 @@ let timingStart: number;
|
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
/** @internal */
|
|
21
|
-
function
|
|
22
|
-
maxCoordinate: number,
|
|
23
|
-
squaredDiagonalLength: number,
|
|
21
|
+
function getPointToCpNode(
|
|
24
22
|
loops: Loop[],
|
|
25
|
-
cpTrees: Map<Loop, LlRbTree<CpNode>>):
|
|
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
|
-
|
|
41
|
+
|
|
42
|
+
/** @internal */
|
|
43
|
+
function getPartialMeta(
|
|
44
|
+
loops: Loop[]): Omit<
|
|
45
|
+
MatMeta,
|
|
46
|
+
| 'cpTrees'
|
|
47
|
+
| 'pointToCpNode'
|
|
48
|
+
| 'loops'
|
|
49
|
+
| 'maxCoordinate'
|
|
50
|
+
| 'squaredDiagonalLength'
|
|
51
|
+
| 'lastInsertId'
|
|
52
|
+
> {
|
|
53
|
+
|
|
54
|
+
const looseBoundingBoxes: number[][][] = [];
|
|
55
|
+
const tightBoundingBoxes: number[][][] = [];
|
|
56
|
+
const boundingHulls: number[][][] = [];
|
|
57
|
+
const sharpCorners: Curve[] = [];
|
|
58
|
+
const dullCorners: Curve[] = [];
|
|
59
|
+
|
|
60
|
+
for (const loop of loops) {
|
|
61
|
+
for (const curve of loop.curves) {
|
|
47
62
|
const ps = curve.ps;
|
|
48
63
|
const hull = getBoundingHull(ps, true)!;
|
|
49
64
|
|
|
@@ -65,16 +80,11 @@ function getMeta(
|
|
|
65
80
|
}
|
|
66
81
|
|
|
67
82
|
return {
|
|
68
|
-
maxCoordinate,
|
|
69
|
-
squaredDiagonalLength,
|
|
70
83
|
looseBoundingBoxes,
|
|
71
84
|
tightBoundingBoxes,
|
|
72
85
|
boundingHulls,
|
|
73
86
|
sharpCorners,
|
|
74
|
-
dullCorners
|
|
75
|
-
loops,
|
|
76
|
-
cpTrees,
|
|
77
|
-
pointToCpNode
|
|
87
|
+
dullCorners
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
|
|
@@ -112,4 +122,10 @@ function addDebugInfo4() {
|
|
|
112
122
|
}
|
|
113
123
|
|
|
114
124
|
|
|
115
|
-
export {
|
|
125
|
+
export {
|
|
126
|
+
getPointToCpNode,
|
|
127
|
+
getPartialMeta,
|
|
128
|
+
addDebugInfo2,
|
|
129
|
+
addDebugInfo3,
|
|
130
|
+
addDebugInfo4
|
|
131
|
+
}
|
|
@@ -13,8 +13,8 @@ const TOLERANCE_USE_LINE = 0.0001; // else cubic
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* Returns the bezier curve from the maximal disk of one
|
|
17
|
-
*
|
|
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 {
|
|
52
|
+
export { getPartialMeta, getPointToCpNode } from './find-mat/get-meta.js';
|
|
53
53
|
export { findAndAddHoleClosing2Prongs } from './find-2-prong/find-and-add-hole-closing-2-prongs.js';
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
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(
|
|
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
|
|
package/src/mat/get-branches.ts
CHANGED
|
@@ -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
|
-
|
|
14
|
+
cpNode: CpNode): CpNode[][] {
|
|
8
15
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
if (branch.length === 0) {
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
19
26
|
|
|
20
|
-
|
|
27
|
+
branches.push(branch);
|
|
21
28
|
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
const cpNodeS = branch[0];
|
|
30
|
+
const cpNodeE = branch[branch.length-1].next.prevOnCircle;
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
takenBranches.add(cpNodeS);
|
|
33
|
+
takenBranches.add(cpNodeE);
|
|
27
34
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
47
|
+
cpNodeStack.push(...cpNodesS, ...cpNodesE);
|
|
48
|
+
}
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
return branches;
|
|
44
51
|
}
|
|
45
52
|
|
|
46
53
|
|
package/src/mat/mat-meta.ts
CHANGED
|
@@ -19,12 +19,17 @@ interface MatMeta {
|
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* Primarily for internal use. A tree structure storing the
|
|
22
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
package/src/mat/simplify-mat.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { PointOnShape } from "./point-on-shape.js";
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
|
-
* Compares two
|
|
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
|
|
8
|
-
* @param b The second
|
|
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
|
|
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
|
|
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;
|