flo-mat 3.0.9 → 3.0.11
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__/jsog/check-jsog-eql-calc.spec.ts +81 -0
- package/__tests__/jsog/decode-jsog.ts +85 -0
- package/__tests__/jsog/get-mats1.ts +41 -0
- package/__tests__/{cp-node/fs → jsog}/mat-dummys.ts +51 -564
- package/__tests__/jsog/to-jsog-breath-first.ts +107 -0
- package/__tests__/jsog/to-jsog-depth-first.ts +55 -0
- package/browser/index.js +280 -236
- package/browser/index.min.js +1 -1
- package/node/add-n-prong.ts/join-spokes.js.map +1 -1
- package/node/closest-boundary-point/cull-bezier-pieces.d.ts +5 -4
- package/node/closest-boundary-point/cull-bezier-pieces.js +9 -8
- package/node/closest-boundary-point/cull-bezier-pieces.js.map +1 -1
- package/node/closest-boundary-point/cull-by-loose-bounding-box.d.ts +2 -2
- package/node/closest-boundary-point/cull-by-loose-bounding-box.js +8 -8
- package/node/closest-boundary-point/cull-by-loose-bounding-box.js.map +1 -1
- package/node/closest-boundary-point/cull-by-tight-boundary-box.d.ts +2 -2
- package/node/closest-boundary-point/cull-by-tight-boundary-box.js +8 -8
- package/node/closest-boundary-point/cull-by-tight-boundary-box.js.map +1 -1
- package/node/closest-boundary-point/dd-deflate-with-running-error.js.map +1 -1
- package/node/closest-boundary-point/get-best-distance-squared.d.ts +1 -1
- package/node/closest-boundary-point/get-best-distance-squared.js +6 -6
- package/node/closest-boundary-point/get-best-distance-squared.js.map +1 -1
- package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +2 -2
- package/node/closest-boundary-point/get-close-boundary-points-certified.js +7 -7
- package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
- package/node/contact-point/contact-point.js.map +1 -1
- package/node/corner/get-corner.js.map +1 -1
- package/node/corner/get-interface-ccw.js.map +1 -1
- package/node/cp-node/cp-node-fs.d.ts +2 -1
- package/node/cp-node/cp-node-fs.js +1 -2
- package/node/cp-node/cp-node-fs.js.map +1 -1
- package/node/cp-node/fs/cp-node-comparator.d.ts +3 -0
- package/node/cp-node/fs/cp-node-comparator.js +6 -0
- package/node/cp-node/fs/cp-node-comparator.js.map +1 -0
- package/node/cp-node/fs/find-first.js.map +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 +1 -1
- package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js +11 -16
- package/node/cp-node/fs/get-boundary-bezier-parts-to-next.js.map +1 -1
- package/node/cp-node/fs/get-boundary-beziers-between.js +4 -6
- package/node/cp-node/fs/get-boundary-beziers-between.js.map +1 -1
- package/node/cp-node/fs/get-boundary-beziers-to-next.d.ts +10 -1
- package/node/cp-node/fs/get-boundary-beziers-to-next.js +70 -35
- package/node/cp-node/fs/get-boundary-beziers-to-next.js.map +1 -1
- package/node/cp-node/fs/get-branch-beziers.js.map +1 -1
- package/node/cp-node/fs/get-branch.js.map +1 -1
- package/node/cp-node/fs/get-children.js.map +1 -1
- package/node/cp-node/fs/get-first-exit.js.map +1 -1
- package/node/cp-node/fs/get-mat-curve-to-next.js.map +1 -1
- package/node/cp-node/fs/get-mat-curves-between.js.map +1 -1
- package/node/cp-node/fs/get-prong-count.js.map +1 -1
- package/node/cp-node/fs/get-real-prong-count.js.map +1 -1
- package/node/cp-node/fs/get-salience.js +2 -2
- package/node/cp-node/fs/get-salience.js.map +1 -1
- package/node/cp-node/fs/get-speed.js +0 -1
- package/node/cp-node/fs/get-speed.js.map +1 -1
- package/node/cp-node/fs/get-vertex-forward-children.js.map +1 -1
- package/node/cp-node/fs/is-fully-terminating.d.ts +1 -1
- package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
- package/node/cp-node/fs/is-one-prong.js.map +1 -1
- package/node/cp-node/fs/is-sharp.js.map +1 -1
- package/node/cp-node/fs/is-terminating.js.map +1 -1
- package/node/cp-node/fs/traverse-cp.js.map +1 -1
- package/node/cp-node/fs/traverse-edges.js.map +1 -1
- package/node/cp-node/fs/traverse-vertices.js.map +1 -1
- package/node/debug/functions/draw-elem/bounding-hull.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-cp-node.js +1 -1
- package/node/debug/functions/draw-elem/draw-cp-node.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-cull.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-elem.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-leaves.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-loose-bounding-box.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-max-vertex.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-min-y.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-one-prong.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-speed.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-three-prong.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-tight-bounding-box.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-two-prong.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-vertex.js.map +1 -1
- package/node/debug/functions/general.js.map +1 -1
- package/node/find-2-prong/add-1-prong.js.map +1 -1
- package/node/find-2-prong/cull-bezier-pieces.d.ts +4 -4
- package/node/find-2-prong/cull-bezier-pieces.js +9 -9
- package/node/find-2-prong/cull-bezier-pieces.js.map +1 -1
- package/node/find-2-prong/find-2-prong.js +8 -8
- package/node/find-2-prong/find-2-prong.js.map +1 -1
- package/node/find-2-prong/find-equidistant-point-on-line-dd.js.map +1 -1
- package/node/find-2-prong/get-initial-bezier-pieces.d.ts +2 -2
- package/node/find-2-prong/get-initial-bezier-pieces.js +2 -2
- package/node/find-2-prong/get-initial-bezier-pieces.js.map +1 -1
- package/node/find-2-prong/reduce-radius.d.ts +1 -1
- package/node/find-2-prong/reduce-radius.js +5 -5
- package/node/find-2-prong/reduce-radius.js.map +1 -1
- package/node/find-3-prong.ts/calc-better-x.d.ts +2 -2
- package/node/find-3-prong.ts/calc-better-x.js +3 -3
- package/node/find-3-prong.ts/calc-better-x.js.map +1 -1
- package/node/find-3-prong.ts/calc-initial-3-prong-center.d.ts +2 -2
- package/node/find-3-prong.ts/calc-initial-3-prong-center.js +3 -3
- package/node/find-3-prong.ts/calc-initial-3-prong-center.js.map +1 -1
- package/node/find-3-prong.ts/find-3-prong-for-delta3s.d.ts +2 -2
- package/node/find-3-prong.ts/find-3-prong-for-delta3s.js +16 -16
- package/node/find-3-prong.ts/find-3-prong-for-delta3s.js.map +1 -1
- package/node/find-3-prong.ts/find-3-prong.js +2 -2
- package/node/find-3-prong.ts/find-3-prong.js.map +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.js.map +1 -1
- package/node/find-3-prong.ts/get-closest-points.d.ts +2 -2
- package/node/find-3-prong.ts/get-closest-points.js +4 -4
- package/node/find-3-prong.ts/get-closest-points.js.map +1 -1
- package/node/find-mat/find-mats.js.map +1 -1
- package/node/geometry/get-closest-square-distance-to-rect.js.map +1 -1
- package/node/geometry/get-closest-squared-distance-to-rotated-rect.js.map +1 -1
- package/node/index.d.ts +35 -1
- package/node/index.js +36 -1
- package/node/index.js.map +1 -1
- package/node/mat/create-new-cp-tree.js.map +1 -1
- package/node/mat/get-boundary-piece-beziers.js +7 -7
- package/node/mat/get-boundary-piece-beziers.js.map +1 -1
- package/node/mat/get-largest-vertex.js.map +1 -1
- package/node/mat/trim-mat.js.map +1 -1
- package/node/memoize-primitive.js.map +1 -1
- package/node/sat/add-debug-info.js.map +1 -1
- package/node/sat/cull.d.ts +7 -5
- package/node/sat/cull.js +7 -4
- package/node/sat/cull.js.map +1 -1
- package/node/sat/get-leaves.js.map +1 -1
- package/node/sat/to-scale-axis.d.ts +3 -2
- package/node/sat/to-scale-axis.js +3 -2
- package/node/sat/to-scale-axis.js.map +1 -1
- package/node/svg/get-loop-bounds.js.map +1 -1
- package/node/svg/get-min-y-pos.js.map +1 -1
- package/node/sweep-line/sweep-line.js.map +1 -1
- package/package.json +6 -6
- package/src/add-n-prong.ts/join-spokes.ts +11 -11
- package/src/closest-boundary-point/cull-bezier-pieces.ts +12 -11
- package/src/closest-boundary-point/cull-by-loose-bounding-box.ts +8 -8
- package/src/closest-boundary-point/cull-by-tight-boundary-box.ts +8 -8
- package/src/closest-boundary-point/dd-deflate-with-running-error.ts +22 -22
- package/src/closest-boundary-point/get-best-distance-squared.ts +6 -6
- package/src/closest-boundary-point/get-close-boundary-points-certified.ts +41 -41
- package/src/contact-point/contact-point.ts +13 -13
- package/src/corner/get-corner.ts +39 -39
- package/src/corner/get-interface-ccw.ts +3 -3
- package/src/cp-node/cp-node-fs.ts +132 -135
- package/src/cp-node/cp-node.ts +30 -30
- package/src/cp-node/fs/clone.ts +4 -4
- package/src/cp-node/fs/cp-node-comparator.ts +13 -0
- package/src/cp-node/fs/find-first.ts +6 -6
- package/src/cp-node/fs/get-all-on-loop.ts +1 -1
- package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +12 -18
- package/src/cp-node/fs/get-boundary-beziers-between.ts +6 -7
- package/src/cp-node/fs/get-boundary-beziers-to-next.ts +79 -53
- package/src/cp-node/fs/get-branch-beziers.ts +1 -1
- package/src/cp-node/fs/get-branch.ts +1 -1
- package/src/cp-node/fs/get-children.ts +8 -8
- package/src/cp-node/fs/get-first-exit.ts +11 -11
- package/src/cp-node/fs/get-mat-curve-to-next.ts +1 -1
- package/src/cp-node/fs/get-mat-curves-between.ts +1 -1
- package/src/cp-node/fs/get-prong-count.ts +8 -8
- package/src/cp-node/fs/get-real-prong-count.ts +3 -3
- package/src/cp-node/fs/get-salience.ts +2 -2
- package/src/cp-node/fs/get-speed.ts +1 -6
- package/src/cp-node/fs/get-vertex-forward-children.ts +10 -10
- package/src/cp-node/fs/is-fully-terminating.ts +3 -3
- package/src/cp-node/fs/is-one-prong.ts +8 -8
- package/src/cp-node/fs/is-sharp.ts +1 -1
- package/src/cp-node/fs/is-terminating.ts +1 -1
- package/src/cp-node/fs/iterate-all-on-loop.ts +6 -6
- package/src/cp-node/fs/traverse-all-forward.ts +11 -11
- package/src/cp-node/fs/traverse-cp.ts +19 -17
- package/src/cp-node/fs/traverse-edges.ts +10 -10
- package/src/cp-node/fs/traverse-vertices.ts +17 -17
- package/src/curve/curve.ts +26 -26
- package/src/debug/functions/cmp-cp-on-delta.ts +1 -1
- package/src/debug/functions/draw-elem/bounding-hull.ts +2 -2
- package/src/debug/functions/draw-elem/culls.ts +2 -2
- package/src/debug/functions/draw-elem/draw-cp-node.ts +30 -30
- package/src/debug/functions/draw-elem/draw-cull.ts +2 -2
- package/src/debug/functions/draw-elem/draw-dull-corner.ts +7 -7
- package/src/debug/functions/draw-elem/draw-elem.ts +28 -28
- package/src/debug/functions/draw-elem/draw-leaves.ts +12 -12
- package/src/debug/functions/draw-elem/draw-loose-bounding-box.ts +7 -7
- package/src/debug/functions/draw-elem/draw-max-vertex.ts +2 -2
- package/src/debug/functions/draw-elem/draw-min-y.ts +2 -2
- package/src/debug/functions/draw-elem/draw-one-prong-at-dull-corner.ts +1 -1
- package/src/debug/functions/draw-elem/draw-one-prong.ts +1 -1
- package/src/debug/functions/draw-elem/draw-sharp-corner.ts +6 -6
- package/src/debug/functions/draw-elem/draw-speed.ts +2 -2
- package/src/debug/functions/draw-elem/draw-three-prong.ts +28 -28
- package/src/debug/functions/draw-elem/draw-tight-bounding-box.ts +4 -4
- package/src/debug/functions/draw-elem/draw-two-prong.ts +51 -51
- package/src/debug/functions/draw-elem/draw-vertex.ts +12 -12
- package/src/debug/functions/draw-elem/dull-corner.ts +7 -7
- package/src/debug/functions/draw-elem/leaves.ts +2 -2
- package/src/debug/functions/draw-elem/loose-bounding-box.ts +7 -7
- package/src/debug/functions/draw-elem/max-vertex.ts +2 -2
- package/src/debug/functions/draw-elem/min-y.ts +2 -2
- package/src/debug/functions/draw-elem/one-prong-at-dull-corner.ts +1 -1
- package/src/debug/functions/draw-elem/one-prong.ts +1 -1
- package/src/debug/functions/draw-elem/sharp-corner.ts +6 -6
- package/src/debug/functions/draw-elem/three-prong.ts +19 -19
- package/src/debug/functions/draw-elem/tight-bounding-box.ts +4 -4
- package/src/debug/functions/draw-elem/two-prong.ts +44 -44
- package/src/debug/functions/draw-elem/vertex.ts +28 -28
- package/src/debug/functions/general.ts +18 -18
- package/src/debug/functions/three-prong.ts +184 -184
- package/src/debug/functions/two-prong.ts +201 -201
- package/src/debug/two-prong-for-debugging.ts +26 -26
- package/src/find-2-prong/add-1-prong.ts +25 -25
- package/src/find-2-prong/add-debug-info.ts +38 -38
- package/src/find-2-prong/cull-bezier-pieces.ts +10 -10
- package/src/find-2-prong/find-2-prong.ts +158 -158
- package/src/find-2-prong/find-equidistant-point-on-line-dd.ts +50 -50
- package/src/find-2-prong/find-equidistant-point-on-line.ts +27 -27
- package/src/find-2-prong/get-initial-bezier-pieces.ts +2 -2
- package/src/find-2-prong/reduce-radius.ts +5 -5
- package/src/find-3-prong.ts/calc-better-x.ts +3 -3
- package/src/find-3-prong.ts/calc-initial-3-prong-center.ts +3 -3
- package/src/find-3-prong.ts/find-3-prong-for-delta3s.ts +17 -17
- package/src/find-3-prong.ts/find-3-prong.ts +23 -23
- package/src/find-3-prong.ts/find-and-add-3-prong.ts +37 -37
- package/src/find-3-prong.ts/find-and-add-3-prongs.ts +30 -30
- package/src/find-3-prong.ts/get-closest-points.ts +4 -4
- package/src/find-mat/add-2-prongs-by-error.ts +8 -8
- package/src/find-mat/find-mats.ts +49 -49
- package/src/find-mat/fix-ordering.ts +2 -2
- package/src/find-mat/get-total-by.ts +12 -12
- package/src/geometry/get-closest-square-distance-to-rect.ts +37 -37
- package/src/geometry/get-closest-squared-distance-to-rotated-rect.ts +14 -14
- package/src/get-curve/get-curve-between.ts +1 -1
- package/src/index.ts +41 -4
- package/src/mat/cmp-cp-on-delta.ts +1 -1
- package/src/mat/create-new-cp-tree.ts +12 -12
- package/src/mat/get-boundary-piece-beziers.ts +7 -7
- package/src/mat/get-edges-as-array.ts +9 -9
- package/src/mat/get-largest-3-prong.ts +8 -8
- package/src/mat/get-largest-three-prong.ts +5 -5
- package/src/mat/get-largest-vertex.ts +6 -6
- package/src/mat/get-two-prong-type.ts +9 -9
- package/src/mat/trim-mat.ts +1 -1
- package/src/memoize-primitive.ts +14 -14
- package/src/sat/add-debug-info.ts +4 -4
- package/src/sat/cull-by-salience.ts +1 -1
- package/src/sat/cull.ts +10 -7
- package/src/sat/get-leaves.ts +0 -1
- package/src/sat/to-scale-axis.ts +18 -17
- package/src/svg/get-extreme.ts +8 -8
- package/src/svg/get-loop-bounds.ts +84 -84
- package/src/svg/get-min-y-pos.ts +1 -1
- package/src/sweep-line/sweep-line.ts +23 -23
- package/src/utils/bezier-piece-to-bezier.ts +7 -7
- package/__tests__/cp-node/fs/check-jsog-eql-calc.spec.ts +0 -30
- package/node/cp-node/fs/cp-nodes-to-boundary-beziers.d.ts +0 -3
- package/node/cp-node/fs/cp-nodes-to-boundary-beziers.js +0 -6
- package/node/cp-node/fs/cp-nodes-to-boundary-beziers.js.map +0 -1
- package/src/closest-boundary-point/get-closest-boundary-point-certified.ts +0 -70
- package/src/cp-node/fs/cp-nodes-to-boundary-beziers.ts +0 -10
|
@@ -3,11 +3,11 @@ import { Circle } from '../geometry/circle.js';
|
|
|
3
3
|
import { PointOnShape } from '../point-on-shape/point-on-shape.js';
|
|
4
4
|
import { getOsculatingCircle } from '../point-on-shape/get-osculating-circle.js';
|
|
5
5
|
import { findEquidistantPointOnLineDd } from './find-equidistant-point-on-line-dd.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getInitialCurvePieces } from './get-initial-bezier-pieces.js';
|
|
7
7
|
import { getCloseBoundaryPointsCertified } from '../closest-boundary-point/get-close-boundary-points-certified.js';
|
|
8
8
|
import { reduceRadius } from './reduce-radius.js';
|
|
9
9
|
import { squaredDistanceBetweenDd } from './squared-distance-between-dd.js';
|
|
10
|
-
import {
|
|
10
|
+
import { cullCurvePieces2 } from './cull-bezier-pieces.js';
|
|
11
11
|
import { add1Prong } from './add-1-prong.js';
|
|
12
12
|
import { createPos } from '../point-on-shape/create-pos.js';
|
|
13
13
|
import { MatMeta } from '../mat/mat-meta.js';
|
|
@@ -41,166 +41,166 @@ const { ceil, log2, max, sqrt, abs, sin, cos } = Math;
|
|
|
41
41
|
* @param loopIdx The loop array index
|
|
42
42
|
*/
|
|
43
43
|
function find2Prong(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
y: PointOnShape): { circle: Circle,
|
|
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
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
44
|
+
meta: MatMeta,
|
|
45
|
+
isHoleClosing: boolean,
|
|
46
|
+
for1Prong: boolean,
|
|
47
|
+
angle: number,
|
|
48
|
+
y: PointOnShape): { circle: Circle, zs: PointOnShape[] } | undefined {
|
|
49
|
+
|
|
50
|
+
const { loops, maxCoordinate, squaredDiagonalLength } = meta;
|
|
51
|
+
|
|
52
|
+
const loop = y.curve.loop;
|
|
53
|
+
|
|
54
|
+
const MAX_ITERATIONS = 25;
|
|
55
|
+
const minSquaredSeperationTolerance = ((2**-21)*maxCoordinate)**2;
|
|
56
|
+
const errorTolerance = (2**-46)*maxCoordinate;
|
|
57
|
+
// const errorTolerance = (2**-28)*maxCoordinate;
|
|
58
|
+
const maxOsculatingCircleRadius = sqrt(squaredDiagonalLength);
|
|
59
|
+
const minCurvature = 1/maxOsculatingCircleRadius;
|
|
60
|
+
const oneProngTolerance = (2**-16)*maxCoordinate;
|
|
61
|
+
|
|
62
|
+
const [xO,rO] = getO(
|
|
63
|
+
angle, isHoleClosing, maxOsculatingCircleRadius, minCurvature, y
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const p = y.p;
|
|
67
|
+
|
|
68
|
+
// The boundary piece that should contain the other point of
|
|
69
|
+
// the 2-prong circle. (Defined by start and end points).
|
|
70
|
+
let curvePieces = getInitialCurvePieces(
|
|
71
|
+
angle, isHoleClosing, loop, loops, meta, y, { center: xO, radius: rO }
|
|
72
|
+
);
|
|
73
|
+
// console.log(curvePieces.length);
|
|
74
|
+
|
|
75
|
+
/** The center of the two-prong (successively refined) */
|
|
76
|
+
let x = xO;
|
|
77
|
+
|
|
78
|
+
// The lines below is an optimization.
|
|
79
|
+
const r_ = sqrt(reduceRadius(maxCoordinate, curvePieces, p, xO));
|
|
80
|
+
if (rO > r_) {
|
|
81
|
+
x = interpolate(p, xO, r_/rO);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** The antipode of the two-prong (successively refined) */
|
|
85
|
+
let zs: PointOnShape[] = undefined!;
|
|
86
|
+
let z: PointOnShape = undefined!;
|
|
87
|
+
|
|
88
|
+
let i = 0;
|
|
89
|
+
while (i < MAX_ITERATIONS) {
|
|
90
|
+
const xy = squaredDistanceBetweenDd(x, y.p);
|
|
91
|
+
|
|
92
|
+
if (i < 2) { curvePieces = cullCurvePieces2(curvePieces, x, xy); }
|
|
93
|
+
const pow = max(0,ceil(log2(maxCoordinate/xy))) + 1; // determines accuracy
|
|
94
|
+
// console.log(pow);
|
|
95
|
+
const _zs = getCloseBoundaryPointsCertified(
|
|
96
|
+
pow, curvePieces, x, y.curve, y.t,
|
|
97
|
+
for1Prong && i == 0 && rO !== 1/minCurvature,
|
|
98
|
+
angle
|
|
99
|
+
).map(info => createPos(info.curve, info.t, false));
|
|
100
|
+
|
|
101
|
+
let maxD = Number.NEGATIVE_INFINITY;
|
|
102
|
+
let maxPos: PointOnShape = undefined!;
|
|
103
|
+
zs = [];
|
|
104
|
+
for (const z of _zs) {
|
|
105
|
+
if (z === undefined) { continue; }
|
|
106
|
+
const _yz = squaredDistanceBetweenDd(y.p, z.p);
|
|
107
|
+
if (_yz > maxD) {
|
|
108
|
+
maxD = _yz;
|
|
109
|
+
maxPos = z;
|
|
110
|
+
}
|
|
111
|
+
if (_yz !== 0) {
|
|
112
|
+
zs.push(z);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// z = zs[0];
|
|
116
|
+
const yz = maxD;
|
|
117
|
+
z = maxPos;
|
|
118
|
+
|
|
119
|
+
if (z === undefined || yz === 0) {
|
|
120
|
+
// addDebugInfo2(isHoleClosing);
|
|
121
|
+
return undefined;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const xz = squaredDistanceBetweenDd(x, z.p);
|
|
125
|
+
|
|
126
|
+
// if on first try
|
|
127
|
+
if (i === 0) {
|
|
128
|
+
if (rO < (1 - oneProngTolerance)*sqrt(xz)) {
|
|
129
|
+
// console.log('1prong');
|
|
130
|
+
add1Prong(meta, rO, xO, y);
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// if (typeof _debug_ !== 'undefined') { xs.push({ x, y, z: createPos(z.curve, z.t, false), t: y.t }); }
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if (!isHoleClosing) {
|
|
139
|
+
const squaredSeperationTolerance = max(calcSeperationTolerance(
|
|
140
|
+
rO, sqrt(xz), 2**2*errorTolerance
|
|
141
|
+
), minSquaredSeperationTolerance);
|
|
142
|
+
if (yz <= squaredSeperationTolerance) {
|
|
143
|
+
// if (typeof _debug_ !== 'undefined') { console.log(`failed: seperation too small - ${sqrt(yz)}`); }
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// Find the point on the line connecting y with x that is
|
|
149
|
+
// equidistant from y and z. This will be our next x.
|
|
150
|
+
const nextX = findEquidistantPointOnLineDd(x, y.p, z.p);
|
|
151
|
+
const error = abs(sqrt(xy) - sqrt(xz));
|
|
152
|
+
// if (xy < xz) { return undefined; }
|
|
153
|
+
|
|
154
|
+
x = nextX;
|
|
155
|
+
|
|
156
|
+
if (error < errorTolerance) {
|
|
157
|
+
break;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
i++;
|
|
161
|
+
|
|
162
|
+
if (i === MAX_ITERATIONS) {
|
|
163
|
+
// Convergence was too slow.
|
|
164
|
+
// if (typeof _debug_ !== 'undefined') { console.log('failed (slow): max iterations reached'); }
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const circle = { center: x, radius: distanceBetween(x, z.p) };
|
|
170
|
+
|
|
171
|
+
// if (typeof _debug_ !== 'undefined') { addDebugInfo(curvePieces, false, x, y, z, circle!, δ!, xs, isHoleClosing); }
|
|
172
|
+
|
|
173
|
+
// return { circle, zs };
|
|
174
|
+
// zs = zs.filter(z => z !== undefined)
|
|
175
|
+
return { circle, zs: [z] };
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
|
|
179
179
|
function getO(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
180
|
+
angle: number,
|
|
181
|
+
isHoleClosing: boolean,
|
|
182
|
+
maxOsculatingCircleRadius: number,
|
|
183
|
+
minCurvature: number,
|
|
184
|
+
y: PointOnShape) {
|
|
185
|
+
|
|
186
|
+
let xO: number[]; // the original x to mitigate drift
|
|
187
|
+
const p = y.p;
|
|
188
|
+
let rO: number;
|
|
189
|
+
if (isHoleClosing) {
|
|
190
|
+
xO = [p[0], p[1] - maxOsculatingCircleRadius];
|
|
191
|
+
rO = maxOsculatingCircleRadius;
|
|
192
|
+
} else {
|
|
193
|
+
if (angle === 0) {
|
|
194
|
+
({ center: xO, radius: rO } = getOsculatingCircle(minCurvature, y));
|
|
195
|
+
} else {
|
|
196
|
+
({ center: xO, radius: rO } = getOsculatingCircle(minCurvature, y, true));
|
|
197
|
+
const v = fromTo(y.p, xO);
|
|
198
|
+
const v_ = rotate(sin(angle), cos(angle))(v);
|
|
199
|
+
xO = translate(y.p)(v_);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
return [xO,rO] as [number[],number];
|
|
204
204
|
}
|
|
205
205
|
|
|
206
206
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
twoDiff, twoSum, twoProduct, doubleDivDouble, ddDivDd,
|
|
3
|
+
ddAddDd, ddDiffDd, ddMultDd, ddMultBy2, ddMultDouble1
|
|
4
4
|
} from "double-double";
|
|
5
5
|
|
|
6
6
|
|
|
@@ -20,57 +20,57 @@ const tp = twoProduct;
|
|
|
20
20
|
* @param z
|
|
21
21
|
*/
|
|
22
22
|
function findEquidistantPointOnLineDd(
|
|
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
|
-
|
|
23
|
+
x: number[],
|
|
24
|
+
y: number[],
|
|
25
|
+
z: number[]) {
|
|
26
|
+
// Some basic algebra (not shown) finds the required point.
|
|
27
|
+
|
|
28
|
+
// Swap axes if x and y are more aligned to y-axis than to x-axis.
|
|
29
|
+
const swapAxes = abs(x[1] - y[1]) > abs(x[0] - y[0]);
|
|
30
|
+
|
|
31
|
+
// Cache
|
|
32
|
+
let x1: number;
|
|
33
|
+
let x2: number;
|
|
34
|
+
let y1: number;
|
|
35
|
+
let y2: number;
|
|
36
|
+
let z1: number;
|
|
37
|
+
let z2: number;
|
|
38
|
+
|
|
39
|
+
if (swapAxes) {
|
|
40
|
+
x1 = x[1]; x2 = x[0];
|
|
41
|
+
y1 = y[1]; y2 = y[0];
|
|
42
|
+
z1 = z[1]; z2 = z[0];
|
|
43
|
+
} else {
|
|
44
|
+
x1 = x[0]; x2 = x[1];
|
|
45
|
+
y1 = y[0]; y2 = y[1];
|
|
46
|
+
z1 = z[0]; z2 = z[1];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// a <= 1 (due to swapped axes)
|
|
50
|
+
// const a = (x2 - y2) / (x1 - y1);
|
|
51
|
+
// const b = y2 - a*y1;
|
|
52
|
+
// const c = (y1*y1 + y2*y2 - z1*z1 - z2*z2) + 2*b*(z2 - y2);
|
|
53
|
+
// const d = y1 - z1 + a*(y2 - z2);
|
|
54
|
+
// const t1 = c/(2*d);
|
|
55
|
+
// const t2 = a*t1 + b;
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
|
|
58
|
+
const a = ddDivDd(td(x2,y2),td(x1,y1));
|
|
59
|
+
const b = ddDiffDd([0,y2], ddMultDouble1(y1,a));
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
const c = ddAddDd(
|
|
62
|
+
(ddDiffDd(
|
|
63
|
+
ddAddDd(tp(y1,y1), tp(y2,y2)),
|
|
64
|
+
ddAddDd(tp(z1,z1), tp(z2,z2))
|
|
65
|
+
)),
|
|
66
|
+
ddMultBy2(ddMultDd(b,(td(z2,y2))))
|
|
67
|
+
);
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
const d = ddAddDd(td(y1,z1), ddMultDd(a,td(y2,z2)));
|
|
70
|
+
const t1 = ddDivDd(c,ddMultBy2(d));
|
|
71
|
+
const t2 = ddAddDd(ddMultDd(a,t1), b);
|
|
72
|
+
|
|
73
|
+
return swapAxes ? [t2[1],t1[1]] : [t1[1],t2[1]];
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
|
|
@@ -7,33 +7,33 @@
|
|
|
7
7
|
* @returns The point on the line from y to x that is equidistant from y and z.
|
|
8
8
|
*/
|
|
9
9
|
function findEquidistantPointOnLine(x: number[], y: number[], z: number[]) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
10
|
+
// Some basic algebra (not shown) finds the required point.
|
|
11
|
+
|
|
12
|
+
// Swap axes if x and y are more aligned to y-axis than to x-axis.
|
|
13
|
+
const swapAxes = Math.abs((x[1] - y[1]) / (x[0] - y[0])) > 1;
|
|
14
|
+
|
|
15
|
+
// Cache
|
|
16
|
+
let x1, x2, y1, y2, z1, z2;
|
|
17
|
+
|
|
18
|
+
if (swapAxes) {
|
|
19
|
+
x1 = x[1]; x2 = x[0];
|
|
20
|
+
y1 = y[1]; y2 = y[0];
|
|
21
|
+
z1 = z[1]; z2 = z[0];
|
|
22
|
+
} else {
|
|
23
|
+
x1 = x[0]; x2 = x[1];
|
|
24
|
+
y1 = y[0]; y2 = y[1];
|
|
25
|
+
z1 = z[0]; z2 = z[1];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// a <= 1 (due to swapped axes)
|
|
29
|
+
const a = (x2 - y2) / (x1 - y1);
|
|
30
|
+
const b = y2 - a*y1;
|
|
31
|
+
const c = (y1*y1 + y2*y2 - z1*z1 - z2*z2) + 2*b*(z2 - y2);
|
|
32
|
+
const d = y1 - z1 + a*(y2 - z2);
|
|
33
|
+
const t1 = c/(2*d);
|
|
34
|
+
const t2 = a*t1 + b;
|
|
35
|
+
|
|
36
|
+
return swapAxes ? [t2,t1] : [t1,t2];
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
|
|
@@ -13,7 +13,7 @@ import { MatMeta } from '../index.js';
|
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
/** @internal */
|
|
16
|
-
function
|
|
16
|
+
function getInitialCurvePieces(
|
|
17
17
|
angle: number,
|
|
18
18
|
isHoleClosing: boolean,
|
|
19
19
|
loop: Loop,
|
|
@@ -54,4 +54,4 @@ function getInitialBezierPieces(
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
export {
|
|
57
|
+
export { getInitialCurvePieces }
|
|
@@ -10,22 +10,22 @@ import { CurvePiece } from '../mat/curve-piece.js';
|
|
|
10
10
|
*/
|
|
11
11
|
function reduceRadius(
|
|
12
12
|
extreme: number,
|
|
13
|
-
|
|
13
|
+
curvePieces: CurvePiece[],
|
|
14
14
|
p: number[],
|
|
15
15
|
x: number[]) {
|
|
16
16
|
|
|
17
17
|
const TOLERANCE = 1 + 2**-10;
|
|
18
18
|
|
|
19
19
|
let minRadius = Number.POSITIVE_INFINITY;
|
|
20
|
-
for (let i=0; i<
|
|
21
|
-
const
|
|
20
|
+
for (let i=0; i<curvePieces.length; i++) {
|
|
21
|
+
const curvePiece = curvePieces[i];
|
|
22
22
|
|
|
23
|
-
const ps =
|
|
23
|
+
const ps = curvePiece.curve.ps;
|
|
24
24
|
|
|
25
25
|
// let min = Number.POSITIVE_INFINITY;
|
|
26
26
|
const num = 2;
|
|
27
27
|
for (let j=0; j<(num + 1); j++) {
|
|
28
|
-
const p_ = evalDeCasteljau(ps,
|
|
28
|
+
const p_ = evalDeCasteljau(ps, curvePiece.ts[j/num]);
|
|
29
29
|
const cc = getCircleCenterFrom2PointsAndNormal(extreme, p, x, p_);
|
|
30
30
|
if (cc) {
|
|
31
31
|
let r = squaredDistanceBetween(p, cc);
|
|
@@ -9,14 +9,14 @@ import { getClosestPoints } from './get-closest-points.js';
|
|
|
9
9
|
* Find new x and ps that are a better estimate of the 3-prong circle.
|
|
10
10
|
* The potential function, V, is defined as the distance to the actual 3 prong
|
|
11
11
|
* circle center.
|
|
12
|
-
* @param
|
|
12
|
+
* @param curvePiece3s The three boundary pieces, each of which should contain
|
|
13
13
|
* a point of the 3-prong to be found.
|
|
14
14
|
* @param x The currently best guess at the center of the 3-prong circle.
|
|
15
15
|
* @param vectorToZeroV
|
|
16
16
|
* @param extreme
|
|
17
17
|
*/
|
|
18
18
|
function calcBetterX(
|
|
19
|
-
|
|
19
|
+
curvePiece3s: CurvePiece[][],
|
|
20
20
|
x: number[],
|
|
21
21
|
vectorToZeroV: number[]) {
|
|
22
22
|
|
|
@@ -33,7 +33,7 @@ function calcBetterX(
|
|
|
33
33
|
newX = translate(shift, x);
|
|
34
34
|
|
|
35
35
|
|
|
36
|
-
newPoss = getClosestPoints(newX,
|
|
36
|
+
newPoss = getClosestPoints(newX, curvePiece3s);
|
|
37
37
|
|
|
38
38
|
// Point of zero V
|
|
39
39
|
const newCircleCenter = circumCenter(newPoss.map(pos => pos!.p));
|
|
@@ -13,13 +13,13 @@ const { max, ceil, log2 } = Math;
|
|
|
13
13
|
* must be within the shape.
|
|
14
14
|
* @param δ3s - The three boundary pieces of which we need to find the three
|
|
15
15
|
* 3-prong points.
|
|
16
|
-
* @param
|
|
16
|
+
* @param curvePiece3s
|
|
17
17
|
* @param extreme
|
|
18
18
|
*/
|
|
19
19
|
function calcInitial3ProngCenter(
|
|
20
20
|
maxCoordinate: number,
|
|
21
21
|
δ3s: CpNode[][],
|
|
22
|
-
|
|
22
|
+
curvePiece3s: CurvePiece[][]) {
|
|
23
23
|
|
|
24
24
|
const circle = δ3s[0][0].cp.circle;
|
|
25
25
|
const twoProngCircleCenter = circle.center;
|
|
@@ -27,7 +27,7 @@ function calcInitial3ProngCenter(
|
|
|
27
27
|
const pow = max(0,ceil(log2(maxCoordinate/circle.radius))) + 1; // determines accuracy;
|
|
28
28
|
const pos = getCloseBoundaryPointsCertified(
|
|
29
29
|
pow,
|
|
30
|
-
|
|
30
|
+
curvePiece3s[1],
|
|
31
31
|
twoProngCircleCenter
|
|
32
32
|
)[0];
|
|
33
33
|
|