flo-mat 3.0.6 → 3.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +239 -158
- 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 +32 -32
- package/node/cp-node/cp-node-fs.js +32 -32
- package/node/cp-node/cp-node.d.ts +13 -21
- 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 +10 -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 +0 -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/point-on-shape.d.ts +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 +12 -5
- package/src/find-mat/get-meta.ts +30 -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
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { Loop } from 'flo-boolean';
|
|
2
|
-
import { LlRbTree } from 'flo-ll-rb-tree';
|
|
3
|
-
import { CpNode } from "../cp-node.js";
|
|
1
|
+
// import { Loop } from 'flo-boolean';
|
|
2
|
+
// import { LlRbTree } from 'flo-ll-rb-tree';
|
|
3
|
+
import type { CpNode } from "../cp-node.js";
|
|
4
|
+
import type { MatMeta } from '../../mat/mat-meta.js';
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
function removeCpNode(
|
|
7
8
|
cpNode: CpNode,
|
|
8
|
-
|
|
9
|
+
meta: MatMeta): void {
|
|
10
|
+
// cpTrees: Map<Loop, LlRbTree<CpNode>>): void {
|
|
11
|
+
|
|
12
|
+
const { cpTrees } = meta;
|
|
9
13
|
|
|
10
14
|
const prev = cpNode.prev;
|
|
11
15
|
const next = cpNode.next;
|
package/src/curve/curve.ts
CHANGED
|
@@ -5,25 +5,31 @@ import { Loop } from 'flo-boolean';
|
|
|
5
5
|
* Represents a bezier curve on the shape boundary / loop.
|
|
6
6
|
*/
|
|
7
7
|
interface Curve {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
* Primarily for internal use.
|
|
11
|
-
* @param loop The closed loop of bezier curves representing the shape
|
|
8
|
+
/**
|
|
9
|
+
* The closed loop of bezier curves representing the shape
|
|
12
10
|
* boundary this curve belongs to.
|
|
13
|
-
* @param ps The bezier control points.
|
|
14
|
-
* @param prev The previous curve (when going in a negative direction around
|
|
15
|
-
* the shape boundary, i.e. clockwise for the outer shape and anti-clockwise
|
|
16
|
-
* for the holes (if any)).
|
|
17
|
-
* @param next The next curve (when going in a positive direction around
|
|
18
|
-
* the shape boundary, i.e. anti-clockwise for the outer shape and clockwise
|
|
19
|
-
* for the holes (if any)).
|
|
20
|
-
* @param idx The curve's ordered index in the loop. This imposes a cycling
|
|
21
|
-
* ordering of the curves in the loop.
|
|
22
11
|
*/
|
|
23
12
|
loop : Loop;
|
|
13
|
+
/**
|
|
14
|
+
* The bezier control points.
|
|
15
|
+
*/
|
|
24
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
|
+
*/
|
|
25
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
|
+
*/
|
|
26
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
|
+
*/
|
|
27
33
|
idx : number;
|
|
28
34
|
}
|
|
29
35
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Loop } from "flo-boolean";
|
|
2
|
-
import { LlRbTree } from "flo-ll-rb-tree";
|
|
1
|
+
import type { Loop } from "flo-boolean";
|
|
2
|
+
import type { LlRbTree } from "flo-ll-rb-tree";
|
|
3
|
+
import type { MatMeta } from "../../mat/mat-meta.js";
|
|
3
4
|
import { compareCps } from "../../contact-point/contact-point.js";
|
|
4
5
|
import { CpNode } from "../../cp-node/cp-node.js";
|
|
5
6
|
import { getAllOnLoop } from "../../cp-node/fs/get-all-on-loop.js";
|
|
@@ -8,9 +9,12 @@ import { isOrderCorrect } from "../../cp-node/fs/is-order-correct.js";
|
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
function checkOrdering(
|
|
11
|
-
cpTrees: Map<Loop,LlRbTree<CpNode>>,
|
|
12
|
+
// cpTrees: Map<Loop,LlRbTree<CpNode>>,
|
|
13
|
+
meta: MatMeta,
|
|
12
14
|
cpStart: CpNode) {
|
|
13
15
|
|
|
16
|
+
const { cpTrees } = meta;
|
|
17
|
+
|
|
14
18
|
const cpNodes = getAllOnLoop(cpStart);
|
|
15
19
|
|
|
16
20
|
const wrongsPerLoop: Map<Loop,[Order,Order][]> = new Map();
|
|
@@ -50,7 +50,7 @@ function add1Prong(
|
|
|
50
50
|
return;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
const { anyFailed, cpNodes } = addToCpTree(false, false, circle, [-0.5, +0.5], meta
|
|
53
|
+
const { anyFailed, cpNodes } = addToCpTree(false, false, circle, [-0.5, +0.5], meta, [pos, pos]);
|
|
54
54
|
|
|
55
55
|
// if (typeof _debug_ !== 'undefined') {
|
|
56
56
|
// _debug_.generated.elems.oneProng.push(cpNodes);
|
|
@@ -25,85 +25,90 @@ import { removeCpNode } from '../cp-node/fs/remove-cp-node.js';
|
|
|
25
25
|
* tolerances.
|
|
26
26
|
*/
|
|
27
27
|
function add2Prong(
|
|
28
|
-
|
|
28
|
+
meta: MatMeta,
|
|
29
29
|
circle: Circle,
|
|
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
|
-
|
|
30
|
+
poss: PointOnShape[],
|
|
31
|
+
isHoleClosing: boolean): CpNode | undefined {
|
|
32
|
+
|
|
33
|
+
poss[0] = poss[0].t === 0
|
|
34
|
+
? createPos(poss[0].curve.prev, 1, true)
|
|
35
|
+
: poss[0];
|
|
36
|
+
|
|
37
|
+
const orders = poss.map(pos => calcPosOrder(circle, pos));
|
|
38
|
+
|
|
39
|
+
// Make sure there isn't already a ContactPoint close by - it can cause
|
|
40
|
+
// floating point stability issues.
|
|
41
|
+
for (let i=0; i<poss.length; i++) {
|
|
42
|
+
if (!!getCloseByCpIfExist(meta, poss[i], circle, orders[i], 0, 2)) {
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { anyFailed, cpNodes } = addToCpTree(
|
|
48
|
+
isHoleClosing, isHoleClosing, circle, orders, meta, poss
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
if (anyFailed) {
|
|
52
|
+
cpNodes.forEach(cpNode => {
|
|
53
|
+
if (cpNode !== undefined) {
|
|
54
|
+
removeCpNode(cpNode, meta);
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Get points ordered according to their angle with the x-axis
|
|
61
|
+
// joinSpokes(circle, cpNodes);
|
|
62
|
+
|
|
63
|
+
if (isHoleClosing) {
|
|
64
|
+
closeHole(meta, cpNodes as CpNode[]);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return cpNodes[0]; // return the source `CpNode`
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
function closeHole(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
72
|
+
meta: MatMeta,
|
|
73
|
+
// cpTrees: Map<Loop, LlRbTree<CpNode>>,
|
|
74
|
+
cpNodes: CpNode[]) {
|
|
75
|
+
|
|
76
|
+
const { cpTrees } = meta;
|
|
77
|
+
|
|
78
|
+
const [cpNodeA, cpNodeB] = cpNodes;
|
|
79
|
+
// Duplicate ContactPoints
|
|
80
|
+
// const antipodeCpNode = cpNodeB[0];
|
|
81
|
+
const cpAntipode = cpNodeB.cp;
|
|
82
|
+
|
|
83
|
+
const cpNodeB2 = insertCpNode(
|
|
84
|
+
true,
|
|
85
|
+
true, false,
|
|
86
|
+
cpTrees.get(cpAntipode.pointOnShape.curve.loop)!,
|
|
87
|
+
{ ...cpAntipode, order2: +1 },
|
|
88
|
+
cpNodeB,
|
|
89
|
+
meta.lastInsertId
|
|
90
|
+
)!;
|
|
91
|
+
|
|
92
|
+
const cpNodeB1 = insertCpNode(
|
|
93
|
+
true,
|
|
94
|
+
true, false,
|
|
95
|
+
cpTrees.get(cpNodeA.cp.pointOnShape.curve.loop)!,
|
|
96
|
+
{ ...cpNodeA.cp, order2: -1 },
|
|
97
|
+
cpNodeA.prev,
|
|
98
|
+
meta.lastInsertId
|
|
99
|
+
)!;
|
|
100
|
+
|
|
101
|
+
// Connect graph
|
|
102
|
+
cpNodeB1.prevOnCircle = cpNodeB2;
|
|
103
|
+
cpNodeB1.nextOnCircle = cpNodeB2;
|
|
104
|
+
cpNodeB2.prevOnCircle = cpNodeB1;
|
|
105
|
+
cpNodeB2.nextOnCircle = cpNodeB1;
|
|
106
|
+
|
|
107
|
+
cpNodeB.next = cpNodeA;
|
|
108
|
+
cpNodeA.prev = cpNodeB;
|
|
109
|
+
|
|
110
|
+
cpNodeB1.next = cpNodeB2;
|
|
111
|
+
cpNodeB2.prev = cpNodeB1;
|
|
107
112
|
}
|
|
108
113
|
|
|
109
114
|
|
|
@@ -18,52 +18,6 @@ const { asin, acos, cos, sqrt, PI: π } = Math;
|
|
|
18
18
|
* @param r radius of the MAT circle
|
|
19
19
|
* @param θ angle between point...
|
|
20
20
|
*/
|
|
21
|
-
function calcSeperationTolerance2(
|
|
22
|
-
R: number,
|
|
23
|
-
r: number,
|
|
24
|
-
δ: number) {
|
|
25
|
-
|
|
26
|
-
const a = r + δ;
|
|
27
|
-
if (a >= R) {
|
|
28
|
-
return Number.POSITIVE_INFINITY;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const b = R - r; //?
|
|
32
|
-
const c = R; //?
|
|
33
|
-
|
|
34
|
-
const N = c*c - a*a - b*b; //?
|
|
35
|
-
const N_ = qdq(qdq(tp(c,c), tp(a,a)), tp(b,b));
|
|
36
|
-
const D = 2*a*b; //?
|
|
37
|
-
const D_ = tp(-2*a,b);
|
|
38
|
-
const Q = ddDivDd(N_,D_)[1]; //?
|
|
39
|
-
const cosC = -N/D; //?
|
|
40
|
-
const C = acos(cosC);
|
|
41
|
-
const CC = acos(Q);
|
|
42
|
-
|
|
43
|
-
const θ = π - CC; //?
|
|
44
|
-
|
|
45
|
-
return θ;
|
|
46
|
-
// return r*θ; // approximate arc with line
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export { calcSeperationTolerance }
|
|
51
|
-
|
|
52
|
-
function degToRad(degrees: number) {
|
|
53
|
-
return degrees/360*2*Math.PI;
|
|
54
|
-
}
|
|
55
|
-
function radToDeg(rad: number) {
|
|
56
|
-
return rad*360/2/Math.PI;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const R = 699;
|
|
61
|
-
const r = 698;
|
|
62
|
-
const δ = 1000*2**-46; //?
|
|
63
|
-
calcSeperationTolerance(R,r,δ); //?
|
|
64
|
-
calcSeperationTolerance2(R,r,δ); //?
|
|
65
|
-
calcSeperationTolerance3(R,r,δ); //?
|
|
66
|
-
|
|
67
21
|
function calcSeperationTolerance(
|
|
68
22
|
R: number,
|
|
69
23
|
r: number,
|
|
@@ -75,47 +29,103 @@ function calcSeperationTolerance(
|
|
|
75
29
|
}
|
|
76
30
|
|
|
77
31
|
|
|
78
|
-
const R_r_ = twoDiff(R,r);
|
|
79
|
-
const A_ = qmd(r,R_r_);
|
|
80
|
-
const N_ = qdq(qdq(A_, tp(r,δ)), tp(δ,δ/2));
|
|
81
|
-
const D_ = qaq(A_,qmd(δ,R_r_));
|
|
32
|
+
const R_r_ = twoDiff(R,r);
|
|
33
|
+
const A_ = qmd(r,R_r_);
|
|
34
|
+
const N_ = qdq(qdq(A_, tp(r,δ)), tp(δ,δ/2));
|
|
35
|
+
const D_ = qaq(A_,qmd(δ,R_r_));
|
|
82
36
|
|
|
83
|
-
const R_r = R - r;
|
|
84
|
-
const A = r*R_r;
|
|
85
|
-
const N = A - r*δ - (δ*δ)/2;
|
|
86
|
-
const D = A + R_r*δ;
|
|
87
|
-
const cosC = N/D;
|
|
88
|
-
const Q = ddDivDd(N_,D_)[1]
|
|
89
|
-
// const Q = N_[1]/D_[1]
|
|
37
|
+
const R_r = R - r;
|
|
38
|
+
const A = r*R_r;
|
|
39
|
+
const N = A - r*δ - (δ*δ)/2;
|
|
40
|
+
const D = A + R_r*δ;
|
|
41
|
+
const cosC = N/D;
|
|
42
|
+
const Q = ddDivDd(N_,D_)[1];
|
|
43
|
+
// const Q = N_[1]/D_[1];
|
|
90
44
|
const C = acos(cosC);
|
|
91
45
|
const CC = acos(Q)
|
|
92
46
|
|
|
93
|
-
const θ = CC;
|
|
47
|
+
const θ = CC;
|
|
94
48
|
|
|
95
49
|
// return r*θ;
|
|
96
50
|
return r*θ;
|
|
97
51
|
}
|
|
98
52
|
|
|
99
53
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
R: number,
|
|
103
|
-
r: number,
|
|
104
|
-
δ: number) {
|
|
54
|
+
export { calcSeperationTolerance }
|
|
55
|
+
|
|
105
56
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
57
|
+
// Quokka tests
|
|
58
|
+
|
|
59
|
+
// /**
|
|
60
|
+
// * Calculates and returns an appropriate seperation tolerance between `CpNode`s.
|
|
61
|
+
// *
|
|
62
|
+
// * @param R radius of the circle implied by the curvature at the boundary
|
|
63
|
+
// * @param r radius of the MAT circle
|
|
64
|
+
// * @param θ angle between point...
|
|
65
|
+
// */
|
|
66
|
+
// function calcSeperationTolerance2(
|
|
67
|
+
// R: number,
|
|
68
|
+
// r: number,
|
|
69
|
+
// δ: number) {
|
|
70
|
+
|
|
71
|
+
// const a = r + δ;
|
|
72
|
+
// if (a >= R) {
|
|
73
|
+
// return Number.POSITIVE_INFINITY;
|
|
74
|
+
// }
|
|
75
|
+
|
|
76
|
+
// const b = R - r;
|
|
77
|
+
// const c = R;
|
|
78
|
+
|
|
79
|
+
// const N = c*c - a*a - b*b;
|
|
80
|
+
// const N_ = qdq(qdq(tp(c,c), tp(a,a)), tp(b,b));
|
|
81
|
+
// const D = 2*a*b;
|
|
82
|
+
// const D_ = tp(-2*a,b);
|
|
83
|
+
// const Q = ddDivDd(N_,D_)[1];
|
|
84
|
+
// const cosC = -N/D;
|
|
85
|
+
// const C = acos(cosC);
|
|
86
|
+
// const CC = acos(Q);
|
|
87
|
+
|
|
88
|
+
// const θ = π - CC;
|
|
89
|
+
|
|
90
|
+
// return θ;
|
|
91
|
+
// // return r*θ; // approximate arc with line
|
|
92
|
+
// }
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
// function degToRad(degrees: number) {
|
|
96
|
+
// return degrees/360*2*Math.PI;
|
|
97
|
+
// }
|
|
98
|
+
// function radToDeg(rad: number) {
|
|
99
|
+
// return rad*360/2/Math.PI;
|
|
100
|
+
// }
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// const R = 699;
|
|
104
|
+
// const r = 698;
|
|
105
|
+
// const δ = 1000*2**-46;
|
|
106
|
+
// calcSeperationTolerance(R,r,δ);
|
|
107
|
+
// calcSeperationTolerance2(R,r,δ);
|
|
108
|
+
// calcSeperationTolerance3(R,r,δ);
|
|
109
|
+
|
|
110
|
+
// // * see https://en.wikipedia.org/wiki/Law_of_cosines, Version suited to small angles
|
|
111
|
+
// function calcSeperationTolerance3(
|
|
112
|
+
// R: number,
|
|
113
|
+
// r: number,
|
|
114
|
+
// δ: number) {
|
|
115
|
+
|
|
116
|
+
// const a = r + δ;
|
|
117
|
+
// const c = R - r;
|
|
118
|
+
// const b = R;
|
|
109
119
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
120
|
+
// // c² = (a - b)² + 4ab*sin²(θ/2) OR
|
|
121
|
+
// // (c² - (a - b)²)/4ab = sin²(θ/2)
|
|
122
|
+
// const cc = c*c;
|
|
123
|
+
// const abc = a*a + b*b - 2*a*b;
|
|
124
|
+
// const A = cc - abc;
|
|
125
|
+
// const B = sqrt(A/(4*a*b));
|
|
126
|
+
|
|
127
|
+
// const θ = 2*asin(B);
|
|
128
|
+
|
|
129
|
+
// return θ;
|
|
130
|
+
// // return r*θ; // approximate arc with line
|
|
131
|
+
// }
|
|
@@ -47,7 +47,7 @@ function find2Prong(
|
|
|
47
47
|
angle: number,
|
|
48
48
|
y: PointOnShape): { circle: Circle, zs: PointOnShape[] } | undefined {
|
|
49
49
|
|
|
50
|
-
const { loops, maxCoordinate, squaredDiagonalLength
|
|
50
|
+
const { loops, maxCoordinate, squaredDiagonalLength } = meta;
|
|
51
51
|
|
|
52
52
|
const loop = y.curve.loop;
|
|
53
53
|
|
|
@@ -68,7 +68,7 @@ function find2Prong(
|
|
|
68
68
|
// The boundary piece that should contain the other point of
|
|
69
69
|
// the 2-prong circle. (Defined by start and end points).
|
|
70
70
|
let bezierPieces = getInitialBezierPieces(
|
|
71
|
-
angle, isHoleClosing, loop, loops,
|
|
71
|
+
angle, isHoleClosing, loop, loops, meta, y, { center: xO, radius: rO }
|
|
72
72
|
);
|
|
73
73
|
// console.log(bezierPieces.length);
|
|
74
74
|
|
|
@@ -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
|
|