flo-mat 2.0.2 → 2.0.3
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/browser/index.js +8230 -8229
- package/browser/index.min.js +1 -1
- package/node/circle.d.ts +20 -20
- package/node/circle.js +31 -31
- package/node/compare-curvatures-at-interface.d.ts +19 -19
- package/node/compare-curvatures-at-interface.js +124 -124
- package/node/contact-point.d.ts +26 -26
- package/node/contact-point.js +25 -25
- package/node/cp-node/clone.d.ts +8 -8
- package/node/cp-node/clone.js +31 -31
- package/node/cp-node/remove.d.ts +9 -9
- package/node/cp-node/remove.js +19 -19
- package/node/cp-node.d.ts +202 -202
- package/node/cp-node.js +320 -320
- package/node/curve.d.ts +46 -46
- package/node/curve.js +88 -88
- package/node/debug/cp-node-for-debugging.d.ts +11 -11
- package/node/debug/cp-node-for-debugging.js +1 -1
- package/node/debug/debug-elem-types.d.ts +32 -32
- package/node/debug/debug-elem-types.js +1 -1
- package/node/debug/debug.d.ts +50 -50
- package/node/debug/debug.js +75 -75
- package/node/debug/functions/draw-elem/bounding-hull.d.ts +3 -3
- package/node/debug/functions/draw-elem/bounding-hull.js +7 -7
- package/node/debug/functions/draw-elem/branch.d.ts +4 -4
- package/node/debug/functions/draw-elem/branch.js +22 -22
- package/node/debug/functions/draw-elem/culls.d.ts +4 -4
- package/node/debug/functions/draw-elem/culls.js +21 -21
- package/node/debug/functions/draw-elem/draw-circle-percent.d.ts +3 -3
- package/node/debug/functions/draw-elem/draw-circle-percent.js +12 -12
- package/node/debug/functions/draw-elem/draw-elem.d.ts +8 -8
- package/node/debug/functions/draw-elem/draw-elem.js +45 -45
- package/node/debug/functions/draw-elem/dull-corner.d.ts +4 -4
- package/node/debug/functions/draw-elem/dull-corner.js +10 -10
- package/node/debug/functions/draw-elem/leaves.d.ts +4 -4
- package/node/debug/functions/draw-elem/leaves.js +12 -12
- package/node/debug/functions/draw-elem/loop.d.ts +4 -4
- package/node/debug/functions/draw-elem/loop.js +11 -11
- package/node/debug/functions/draw-elem/loops.d.ts +4 -4
- package/node/debug/functions/draw-elem/loops.js +6 -6
- package/node/debug/functions/draw-elem/loose-bounding-box.d.ts +3 -3
- package/node/debug/functions/draw-elem/loose-bounding-box.js +9 -9
- package/node/debug/functions/draw-elem/mat.d.ts +4 -4
- package/node/debug/functions/draw-elem/mat.js +30 -30
- package/node/debug/functions/draw-elem/max-vertex.d.ts +4 -4
- package/node/debug/functions/draw-elem/max-vertex.js +8 -8
- package/node/debug/functions/draw-elem/min-y.d.ts +4 -4
- package/node/debug/functions/draw-elem/min-y.js +13 -13
- package/node/debug/functions/draw-elem/one-prong-at-dull-corner.d.ts +4 -4
- package/node/debug/functions/draw-elem/one-prong-at-dull-corner.js +12 -12
- package/node/debug/functions/draw-elem/one-prong.d.ts +4 -4
- package/node/debug/functions/draw-elem/one-prong.js +16 -16
- package/node/debug/functions/draw-elem/sharp-corner.d.ts +4 -4
- package/node/debug/functions/draw-elem/sharp-corner.js +9 -9
- package/node/debug/functions/draw-elem/three-prong.d.ts +4 -4
- package/node/debug/functions/draw-elem/three-prong.js +16 -16
- package/node/debug/functions/draw-elem/tight-bounding-box.d.ts +3 -3
- package/node/debug/functions/draw-elem/tight-bounding-box.js +7 -7
- package/node/debug/functions/draw-elem/two-prong.d.ts +4 -4
- package/node/debug/functions/draw-elem/two-prong.js +36 -36
- package/node/debug/functions/draw-elem/vertex.d.ts +4 -4
- package/node/debug/functions/draw-elem/vertex.js +27 -27
- package/node/debug/functions/general.d.ts +48 -48
- package/node/debug/functions/general.js +52 -52
- package/node/debug/functions/three-prong.d.ts +11 -11
- package/node/debug/functions/three-prong.js +184 -184
- package/node/debug/functions/two-prong.d.ts +13 -13
- package/node/debug/functions/two-prong.js +117 -117
- package/node/debug/three-prong-for-debugging.d.ts +31 -31
- package/node/debug/three-prong-for-debugging.js +20 -20
- package/node/debug/two-prong-for-debugging.d.ts +26 -26
- package/node/debug/two-prong-for-debugging.js +1 -1
- package/node/find-mats.d.ts +26 -26
- package/node/find-mats.js +122 -122
- package/node/get-boundary-bezier-parts-to-next.d.ts +9 -9
- package/node/get-boundary-bezier-parts-to-next.js +42 -42
- package/node/get-boundary-beziers-to-next.d.ts +8 -8
- package/node/get-boundary-beziers-to-next.js +44 -44
- package/node/get-bounding-box-.d.ts +2 -2
- package/node/get-bounding-box-.js +4 -4
- package/node/get-branches.d.ts +12 -12
- package/node/get-branches.js +68 -68
- package/node/get-curve/get-curve-between.d.ts +9 -9
- package/node/get-curve/get-curve-between.js +56 -56
- package/node/get-curve/get-edge-direction.d.ts +9 -9
- package/node/get-curve/get-edge-direction.js +53 -53
- package/node/get-curve-to-next.d.ts +9 -9
- package/node/get-curve-to-next.js +11 -11
- package/node/get-interface-ccw.d.ts +24 -24
- package/node/get-interface-ccw.js +97 -97
- package/node/index.d.ts +36 -36
- package/node/index.js +32 -32
- package/node/loop/get-max-coordinate.d.ts +10 -10
- package/node/loop/get-max-coordinate.js +43 -43
- package/node/loop.d.ts +16 -16
- package/node/loop.js +34 -34
- package/node/mat/add-to-cp-graph.d.ts +16 -16
- package/node/mat/add-to-cp-graph.js +30 -30
- package/node/mat/bezier-piece.d.ts +12 -12
- package/node/mat/bezier-piece.js +1 -1
- package/node/mat/closest-boundary-point/closest-points-on-curve.d.ts +14 -14
- package/node/mat/closest-boundary-point/closest-points-on-curve.js +72 -72
- package/node/mat/closest-boundary-point/cull-bezier-pieces.d.ts +9 -9
- package/node/mat/closest-boundary-point/cull-bezier-pieces.js +19 -19
- package/node/mat/closest-boundary-point/cull-by-loose-bounding-box.d.ts +11 -11
- package/node/mat/closest-boundary-point/cull-by-loose-bounding-box.js +24 -24
- package/node/mat/closest-boundary-point/cull-by-tight-boundary-box.d.ts +11 -11
- package/node/mat/closest-boundary-point/cull-by-tight-boundary-box.js +26 -26
- package/node/mat/closest-boundary-point/get-best-distance-squared.d.ts +8 -8
- package/node/mat/closest-boundary-point/get-best-distance-squared.js +24 -24
- package/node/mat/closest-boundary-point/get-close-boundary-points.d.ts +17 -17
- package/node/mat/closest-boundary-point/get-close-boundary-points.js +80 -80
- package/node/mat/closest-boundary-point/get-closest-boundary-point.d.ts +18 -18
- package/node/mat/closest-boundary-point/get-closest-boundary-point.js +40 -40
- package/node/mat/corner.d.ts +37 -37
- package/node/mat/corner.js +1 -1
- package/node/mat/create-new-cp-tree.d.ts +9 -9
- package/node/mat/create-new-cp-tree.js +23 -23
- package/node/mat/elem-type-two-prong.d.ts +3 -3
- package/node/mat/elem-type-two-prong.js +1 -1
- package/node/mat/find-mat/add-1-prong.d.ts +12 -12
- package/node/mat/find-mat/add-1-prong.js +42 -42
- package/node/mat/find-mat/add-2-prong.d.ts +21 -21
- package/node/mat/find-mat/add-2-prong.js +192 -192
- package/node/mat/find-mat/add-3-prong.d.ts +19 -19
- package/node/mat/find-mat/add-3-prong.js +54 -54
- package/node/mat/find-mat/add-debug-info.d.ts +9 -9
- package/node/mat/find-mat/add-debug-info.js +67 -67
- package/node/mat/find-mat/create-get-interesting-points-on-loop.d.ts +11 -11
- package/node/mat/find-mat/create-get-interesting-points-on-loop.js +51 -51
- package/node/mat/find-mat/create-initial-cp-graph.d.ts +12 -12
- package/node/mat/find-mat/create-initial-cp-graph.js +40 -40
- package/node/mat/find-mat/find-2-prong/add-debug-info.d.ts +8 -8
- package/node/mat/find-mat/find-2-prong/add-debug-info.js +21 -21
- package/node/mat/find-mat/find-2-prong/cull-bezier-pieces.d.ts +11 -11
- package/node/mat/find-mat/find-2-prong/cull-bezier-pieces.js +29 -29
- package/node/mat/find-mat/find-2-prong/find-2-prong.d.ts +37 -37
- package/node/mat/find-mat/find-2-prong/find-2-prong.js +232 -232
- package/node/mat/find-mat/find-2-prong/find-equidistant-point-on-line.d.ts +9 -9
- package/node/mat/find-mat/find-2-prong/find-equidistant-point-on-line.js +39 -39
- package/node/mat/find-mat/find-2-prong/get-initial-bezier-pieces.d.ts +11 -11
- package/node/mat/find-mat/find-2-prong/get-initial-bezier-pieces.js +37 -37
- package/node/mat/find-mat/find-2-prong/x-for-debugging.d.ts +9 -9
- package/node/mat/find-mat/find-2-prong/x-for-debugging.js +1 -1
- package/node/mat/find-mat/find-3-prong/calc-better-x.d.ts +19 -19
- package/node/mat/find-mat/find-3-prong/calc-better-x.js +36 -36
- package/node/mat/find-mat/find-3-prong/calc-initial-3-prong-center.d.ts +13 -13
- package/node/mat/find-mat/find-3-prong/calc-initial-3-prong-center.js +25 -25
- package/node/mat/find-mat/find-3-prong/find-3-prong-for-delta3s.d.ts +22 -22
- package/node/mat/find-mat/find-3-prong/find-3-prong-for-delta3s.js +159 -159
- package/node/mat/find-mat/find-3-prong/find-3-prong.d.ts +16 -16
- package/node/mat/find-mat/find-3-prong/find-3-prong.js +76 -76
- package/node/mat/find-mat/find-3-prong/get-closest-points.d.ts +9 -9
- package/node/mat/find-mat/find-3-prong/get-closest-points.js +16 -16
- package/node/mat/find-mat/find-and-add-2-prongs-on-all-paths.d.ts +15 -15
- package/node/mat/find-mat/find-and-add-2-prongs-on-all-paths.js +20 -20
- package/node/mat/find-mat/find-and-add-2-prongs.d.ts +16 -16
- package/node/mat/find-mat/find-and-add-2-prongs.js +73 -73
- package/node/mat/find-mat/find-and-add-3-prongs.d.ts +13 -13
- package/node/mat/find-mat/find-and-add-3-prongs.js +146 -146
- package/node/mat/find-mat/find-and-add-hole-closing-2-prongs.d.ts +14 -14
- package/node/mat/find-mat/find-and-add-hole-closing-2-prongs.js +33 -33
- package/node/mat/find-mat/get-potential-2-prongs.d.ts +4 -4
- package/node/mat/find-mat/get-potential-2-prongs.js +16 -16
- package/node/mat/find-mat/get-sharp-corners.d.ts +4 -4
- package/node/mat/find-mat/get-sharp-corners.js +17 -17
- package/node/mat/geometry/get-closest-square-distance-to-rect.d.ts +5 -5
- package/node/mat/geometry/get-closest-square-distance-to-rect.js +49 -49
- package/node/mat/geometry/get-closest-squared-distance-to-rotated-rect.d.ts +5 -5
- package/node/mat/geometry/get-closest-squared-distance-to-rotated-rect.js +15 -15
- package/node/mat/get-boundary-piece-beziers.d.ts +11 -11
- package/node/mat/get-boundary-piece-beziers.js +58 -58
- package/node/mat/get-contact-circles-at-interface.d.ts +8 -8
- package/node/mat/get-contact-circles-at-interface.js +20 -20
- package/node/mat/get-largest-vertex.d.ts +4 -4
- package/node/mat/get-largest-vertex.js +9 -9
- package/node/mat/get-leaves.d.ts +4 -4
- package/node/mat/get-leaves.js +12 -12
- package/node/mat/get-neighboring-cps.d.ts +14 -14
- package/node/mat/get-neighboring-cps.js +30 -30
- package/node/mat/get-two-prong-type.d.ts +5 -5
- package/node/mat/get-two-prong-type.js +8 -8
- package/node/mat/is-another-cp-closeby.d.ts +20 -20
- package/node/mat/is-another-cp-closeby.js +55 -55
- package/node/mat/simplify-mat-map-only.d.ts +23 -23
- package/node/mat/simplify-mat-map-only.js +80 -80
- package/node/mat/to-scale-axis/add-debug-info.d.ts +7 -7
- package/node/mat/to-scale-axis/add-debug-info.js +13 -13
- package/node/mat/to-scale-axis/cull-non-cycles.d.ts +9 -9
- package/node/mat/to-scale-axis/cull-non-cycles.js +51 -51
- package/node/mat/to-scale-axis/cull.d.ts +12 -12
- package/node/mat/to-scale-axis/cull.js +132 -132
- package/node/mat/trim-mat.d.ts +8 -8
- package/node/mat/trim-mat.js +16 -16
- package/node/mat.d.ts +22 -22
- package/node/mat.js +1 -1
- package/node/point-on-shape.d.ts +73 -73
- package/node/point-on-shape.js +167 -167
- package/node/simplify-mat.d.ts +16 -16
- package/node/simplify-mat.js +71 -71
- package/node/svg/get-loop-bounds.d.ts +12 -12
- package/node/svg/get-loop-bounds.js +80 -80
- package/node/svg/get-min-y-pos.d.ts +8 -8
- package/node/svg/get-min-y-pos.js +9 -9
- package/node/svg/get-shape-bounds.d.ts +9 -9
- package/node/svg/get-shape-bounds.js +35 -35
- package/node/sweep-line/sweep-line.d.ts +18 -18
- package/node/sweep-line/sweep-line.js +72 -72
- package/node/to-scale-axis.d.ts +16 -16
- package/node/to-scale-axis.js +74 -74
- package/node/traverse-edges.d.ts +10 -10
- package/node/traverse-edges.js +21 -21
- package/node/traverse-vertices.d.ts +12 -12
- package/node/traverse-vertices.js +27 -27
- package/package.json +11 -11
- package/tsconfig.json +0 -1
package/node/point-on-shape.js
CHANGED
|
@@ -1,168 +1,168 @@
|
|
|
1
|
-
import { dot, fromTo, toUnitVector, rotateNeg90Degrees } from 'flo-vector2d';
|
|
2
|
-
import { memoize } from 'flo-memoize';
|
|
3
|
-
import { curvature, evalDeCasteljau, tangent } from 'flo-bezier3';
|
|
4
|
-
import { getCornerAtEnd } from './curve.js';
|
|
5
|
-
/**
|
|
6
|
-
* Represents a point on the shape boundary for which MAT vertex information
|
|
7
|
-
* has not *necessarily* been calculated.
|
|
8
|
-
*/
|
|
9
|
-
class PointOnShape {
|
|
10
|
-
/**
|
|
11
|
-
* @param curve The [[ICurve]] on the shape boundary this points belong to.
|
|
12
|
-
* @param t The bezier parameter value on the curve to identify the point
|
|
13
|
-
* coordinates.
|
|
14
|
-
*/
|
|
15
|
-
constructor(curve, t) {
|
|
16
|
-
this.curve = curve;
|
|
17
|
-
this.t = t;
|
|
18
|
-
// Cache
|
|
19
|
-
this.p_ = undefined;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* The planar point coordinates of this [[PointOnShape]].
|
|
23
|
-
*/
|
|
24
|
-
get p() {
|
|
25
|
-
return this.p_ === undefined
|
|
26
|
-
? this.p_ = evalDeCasteljau(this.curve.ps, this.t)
|
|
27
|
-
: this.p_;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @hidden
|
|
32
|
-
*/
|
|
33
|
-
function isPosCorner(pos) {
|
|
34
|
-
return (pos.t === 0 || pos.t === 1);
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* @hidden
|
|
38
|
-
*/
|
|
39
|
-
function getPosCorner(pos) {
|
|
40
|
-
return getCornerAtEnd(pos.t === 1 ? pos.curve : pos.curve.prev);
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* @hidden
|
|
44
|
-
*/
|
|
45
|
-
const isPosSharpCorner = memoize((pos) => {
|
|
46
|
-
if (!isPosCorner(pos)) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
return getPosCorner(pos).isSharp;
|
|
50
|
-
});
|
|
51
|
-
/**
|
|
52
|
-
* @hidden
|
|
53
|
-
*/
|
|
54
|
-
const isPosDullCorner = memoize((pos) => {
|
|
55
|
-
if (!isPosCorner(pos)) {
|
|
56
|
-
return false;
|
|
57
|
-
}
|
|
58
|
-
return getPosCorner(pos).isDull;
|
|
59
|
-
});
|
|
60
|
-
/**
|
|
61
|
-
* @hidden
|
|
62
|
-
*/
|
|
63
|
-
const isPosQuiteSharpCorner = memoize((pos) => {
|
|
64
|
-
if (!isPosCorner(pos)) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
return getPosCorner(pos).isQuiteSharp;
|
|
68
|
-
});
|
|
69
|
-
/**
|
|
70
|
-
* @hidden
|
|
71
|
-
*/
|
|
72
|
-
const isPosQuiteDullCorner = memoize((pos) => {
|
|
73
|
-
if (!isPosCorner(pos)) {
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
return getPosCorner(pos).isQuiteDull;
|
|
77
|
-
});
|
|
78
|
-
/**
|
|
79
|
-
* Returns a human-readable string of the given [[PointOnShape]].
|
|
80
|
-
* For debugging only.
|
|
81
|
-
* @hidden
|
|
82
|
-
*/
|
|
83
|
-
function posToHumanString(pos) {
|
|
84
|
-
return '' + pos.p[0] + ', ' + pos.p[1] +
|
|
85
|
-
' | bz: ' + pos.curve.idx +
|
|
86
|
-
' | t: ' + pos.t;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* @hidden
|
|
90
|
-
* Calculates the order (to distinguish between points lying on top of each
|
|
91
|
-
* other) of the contact point if it is a dull corner.
|
|
92
|
-
* @param pos
|
|
93
|
-
*/
|
|
94
|
-
function calcPosOrder(circle, pos) {
|
|
95
|
-
if (!isPosCorner(pos)) {
|
|
96
|
-
return 0;
|
|
97
|
-
}
|
|
98
|
-
if (!isPosDullCorner(pos)) {
|
|
99
|
-
return 0;
|
|
100
|
-
}
|
|
101
|
-
//if (!isPosDullCorner(pos)) { return 0; }
|
|
102
|
-
const corner = getPosCorner(pos);
|
|
103
|
-
const n = rotateNeg90Degrees(corner.tangents[0]);
|
|
104
|
-
const v = toUnitVector(fromTo(pos.p, circle.center));
|
|
105
|
-
return -dot(n, v);
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Compares two [[PointOnShape]]s according to their cyclic ordering imposed
|
|
109
|
-
* by their relative positions on the shape boundary.
|
|
110
|
-
* @param a The first [[PointOnShape]].
|
|
111
|
-
* @param b The second [[PointOnShape]].
|
|
112
|
-
* @hidden
|
|
113
|
-
*/
|
|
114
|
-
function comparePoss(a, b) {
|
|
115
|
-
if (a === undefined || b === undefined) {
|
|
116
|
-
return undefined;
|
|
117
|
-
}
|
|
118
|
-
let res;
|
|
119
|
-
res = a.curve.idx - b.curve.idx;
|
|
120
|
-
if (res !== 0) {
|
|
121
|
-
return res;
|
|
122
|
-
}
|
|
123
|
-
res = a.t - b.t;
|
|
124
|
-
return res;
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Calculates and returns the osculating circle radius of the bezier at a
|
|
128
|
-
* specific t. If it is found to have negative or nearly zero radius
|
|
129
|
-
* it is clipped to have positive radius so it can point into the shape.
|
|
130
|
-
* @param ps
|
|
131
|
-
* @param t
|
|
132
|
-
* @hidden
|
|
133
|
-
*/
|
|
134
|
-
const calcOsculatingCircleRadius = memoize((pos) => {
|
|
135
|
-
const ps = pos.curve.ps;
|
|
136
|
-
const t = pos.t;
|
|
137
|
-
const c = -curvature(ps, t);
|
|
138
|
-
// c > 0 => bending inwards
|
|
139
|
-
return 1 / c;
|
|
140
|
-
});
|
|
141
|
-
/**
|
|
142
|
-
* Returns the osculating circle at this point of the curve.
|
|
143
|
-
* @param maxOsculatingCircleRadius If not Number.POSITIVE_INFINITY then the
|
|
144
|
-
* circle radius will be limited to this value.
|
|
145
|
-
* @param pos The [[PointOnShape]] identifying the point.
|
|
146
|
-
*/
|
|
147
|
-
function getOsculatingCircle(maxOsculatingCircleRadius, pos) {
|
|
148
|
-
if (isPosSharpCorner(pos)) {
|
|
149
|
-
return { center: pos.p, radius: 0 };
|
|
150
|
-
}
|
|
151
|
-
let radius = calcOsculatingCircleRadius(pos);
|
|
152
|
-
if (radius < 0) {
|
|
153
|
-
radius = Number.POSITIVE_INFINITY;
|
|
154
|
-
}
|
|
155
|
-
radius = Math.min(radius, maxOsculatingCircleRadius);
|
|
156
|
-
const ps = pos.curve.ps;
|
|
157
|
-
const t = pos.t;
|
|
158
|
-
const tangent_ = tangent(ps, t);
|
|
159
|
-
const normal_ = toUnitVector([-tangent_[1], tangent_[0]]);
|
|
160
|
-
const p = evalDeCasteljau(ps, t);
|
|
161
|
-
const circleCenter = [
|
|
162
|
-
p[0] - normal_[0] * radius,
|
|
163
|
-
p[1] - normal_[1] * radius
|
|
164
|
-
];
|
|
165
|
-
return { center: circleCenter, radius };
|
|
166
|
-
}
|
|
167
|
-
export { PointOnShape, getOsculatingCircle, comparePoss, calcPosOrder, posToHumanString, isPosSharpCorner, isPosDullCorner, isPosQuiteSharpCorner, isPosQuiteDullCorner };
|
|
1
|
+
import { dot, fromTo, toUnitVector, rotateNeg90Degrees } from 'flo-vector2d';
|
|
2
|
+
import { memoize } from 'flo-memoize';
|
|
3
|
+
import { curvature, evalDeCasteljau, tangent } from 'flo-bezier3';
|
|
4
|
+
import { getCornerAtEnd } from './curve.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a point on the shape boundary for which MAT vertex information
|
|
7
|
+
* has not *necessarily* been calculated.
|
|
8
|
+
*/
|
|
9
|
+
class PointOnShape {
|
|
10
|
+
/**
|
|
11
|
+
* @param curve The [[ICurve]] on the shape boundary this points belong to.
|
|
12
|
+
* @param t The bezier parameter value on the curve to identify the point
|
|
13
|
+
* coordinates.
|
|
14
|
+
*/
|
|
15
|
+
constructor(curve, t) {
|
|
16
|
+
this.curve = curve;
|
|
17
|
+
this.t = t;
|
|
18
|
+
// Cache
|
|
19
|
+
this.p_ = undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The planar point coordinates of this [[PointOnShape]].
|
|
23
|
+
*/
|
|
24
|
+
get p() {
|
|
25
|
+
return this.p_ === undefined
|
|
26
|
+
? this.p_ = evalDeCasteljau(this.curve.ps, this.t)
|
|
27
|
+
: this.p_;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* @hidden
|
|
32
|
+
*/
|
|
33
|
+
function isPosCorner(pos) {
|
|
34
|
+
return (pos.t === 0 || pos.t === 1);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @hidden
|
|
38
|
+
*/
|
|
39
|
+
function getPosCorner(pos) {
|
|
40
|
+
return getCornerAtEnd(pos.t === 1 ? pos.curve : pos.curve.prev);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @hidden
|
|
44
|
+
*/
|
|
45
|
+
const isPosSharpCorner = memoize((pos) => {
|
|
46
|
+
if (!isPosCorner(pos)) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return getPosCorner(pos).isSharp;
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* @hidden
|
|
53
|
+
*/
|
|
54
|
+
const isPosDullCorner = memoize((pos) => {
|
|
55
|
+
if (!isPosCorner(pos)) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
return getPosCorner(pos).isDull;
|
|
59
|
+
});
|
|
60
|
+
/**
|
|
61
|
+
* @hidden
|
|
62
|
+
*/
|
|
63
|
+
const isPosQuiteSharpCorner = memoize((pos) => {
|
|
64
|
+
if (!isPosCorner(pos)) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
return getPosCorner(pos).isQuiteSharp;
|
|
68
|
+
});
|
|
69
|
+
/**
|
|
70
|
+
* @hidden
|
|
71
|
+
*/
|
|
72
|
+
const isPosQuiteDullCorner = memoize((pos) => {
|
|
73
|
+
if (!isPosCorner(pos)) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return getPosCorner(pos).isQuiteDull;
|
|
77
|
+
});
|
|
78
|
+
/**
|
|
79
|
+
* Returns a human-readable string of the given [[PointOnShape]].
|
|
80
|
+
* For debugging only.
|
|
81
|
+
* @hidden
|
|
82
|
+
*/
|
|
83
|
+
function posToHumanString(pos) {
|
|
84
|
+
return '' + pos.p[0] + ', ' + pos.p[1] +
|
|
85
|
+
' | bz: ' + pos.curve.idx +
|
|
86
|
+
' | t: ' + pos.t;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* @hidden
|
|
90
|
+
* Calculates the order (to distinguish between points lying on top of each
|
|
91
|
+
* other) of the contact point if it is a dull corner.
|
|
92
|
+
* @param pos
|
|
93
|
+
*/
|
|
94
|
+
function calcPosOrder(circle, pos) {
|
|
95
|
+
if (!isPosCorner(pos)) {
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
if (!isPosDullCorner(pos)) {
|
|
99
|
+
return 0;
|
|
100
|
+
}
|
|
101
|
+
//if (!isPosDullCorner(pos)) { return 0; }
|
|
102
|
+
const corner = getPosCorner(pos);
|
|
103
|
+
const n = rotateNeg90Degrees(corner.tangents[0]);
|
|
104
|
+
const v = toUnitVector(fromTo(pos.p, circle.center));
|
|
105
|
+
return -dot(n, v);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Compares two [[PointOnShape]]s according to their cyclic ordering imposed
|
|
109
|
+
* by their relative positions on the shape boundary.
|
|
110
|
+
* @param a The first [[PointOnShape]].
|
|
111
|
+
* @param b The second [[PointOnShape]].
|
|
112
|
+
* @hidden
|
|
113
|
+
*/
|
|
114
|
+
function comparePoss(a, b) {
|
|
115
|
+
if (a === undefined || b === undefined) {
|
|
116
|
+
return undefined;
|
|
117
|
+
}
|
|
118
|
+
let res;
|
|
119
|
+
res = a.curve.idx - b.curve.idx;
|
|
120
|
+
if (res !== 0) {
|
|
121
|
+
return res;
|
|
122
|
+
}
|
|
123
|
+
res = a.t - b.t;
|
|
124
|
+
return res;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Calculates and returns the osculating circle radius of the bezier at a
|
|
128
|
+
* specific t. If it is found to have negative or nearly zero radius
|
|
129
|
+
* it is clipped to have positive radius so it can point into the shape.
|
|
130
|
+
* @param ps
|
|
131
|
+
* @param t
|
|
132
|
+
* @hidden
|
|
133
|
+
*/
|
|
134
|
+
const calcOsculatingCircleRadius = memoize((pos) => {
|
|
135
|
+
const ps = pos.curve.ps;
|
|
136
|
+
const t = pos.t;
|
|
137
|
+
const c = -curvature(ps, t);
|
|
138
|
+
// c > 0 => bending inwards
|
|
139
|
+
return 1 / c;
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* Returns the osculating circle at this point of the curve.
|
|
143
|
+
* @param maxOsculatingCircleRadius If not Number.POSITIVE_INFINITY then the
|
|
144
|
+
* circle radius will be limited to this value.
|
|
145
|
+
* @param pos The [[PointOnShape]] identifying the point.
|
|
146
|
+
*/
|
|
147
|
+
function getOsculatingCircle(maxOsculatingCircleRadius, pos) {
|
|
148
|
+
if (isPosSharpCorner(pos)) {
|
|
149
|
+
return { center: pos.p, radius: 0 };
|
|
150
|
+
}
|
|
151
|
+
let radius = calcOsculatingCircleRadius(pos);
|
|
152
|
+
if (radius < 0) {
|
|
153
|
+
radius = Number.POSITIVE_INFINITY;
|
|
154
|
+
}
|
|
155
|
+
radius = Math.min(radius, maxOsculatingCircleRadius);
|
|
156
|
+
const ps = pos.curve.ps;
|
|
157
|
+
const t = pos.t;
|
|
158
|
+
const tangent_ = tangent(ps, t);
|
|
159
|
+
const normal_ = toUnitVector([-tangent_[1], tangent_[0]]);
|
|
160
|
+
const p = evalDeCasteljau(ps, t);
|
|
161
|
+
const circleCenter = [
|
|
162
|
+
p[0] - normal_[0] * radius,
|
|
163
|
+
p[1] - normal_[1] * radius
|
|
164
|
+
];
|
|
165
|
+
return { center: circleCenter, radius };
|
|
166
|
+
}
|
|
167
|
+
export { PointOnShape, getOsculatingCircle, comparePoss, calcPosOrder, posToHumanString, isPosSharpCorner, isPosDullCorner, isPosQuiteSharpCorner, isPosQuiteDullCorner };
|
|
168
168
|
//# sourceMappingURL=point-on-shape.js.map
|
package/node/simplify-mat.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { Mat } from './mat.js';
|
|
2
|
-
/**
|
|
3
|
-
* Simplifies the given MAT by replacing the piecewise quad beziers composing
|
|
4
|
-
* the MAT with fewer ones to within a given tolerance.
|
|
5
|
-
* @param cpNode A representation of the MAT
|
|
6
|
-
* @param anlgeTolerance Tolerance given as the degrees difference of the unit
|
|
7
|
-
* direction vectors at the interface between curves. A tolerance of zero means
|
|
8
|
-
* perfect smoothness is required - defaults to 15.
|
|
9
|
-
* TODO - the next two params are wrong??
|
|
10
|
-
* @param hausdorffTolerance The approximate maximum Hausdorff Distance tolerance -
|
|
11
|
-
* defaults to 0.1
|
|
12
|
-
* @param maxIterations The spacing on the curves used to calculate the Hausdorff
|
|
13
|
-
* Distance - defaults to 1
|
|
14
|
-
*/
|
|
15
|
-
declare function simplifyMat(mat: Mat, anlgeTolerance?: number, hausdorffTolerance?: number, maxIterations?: number): Mat;
|
|
16
|
-
export { simplifyMat };
|
|
1
|
+
import { Mat } from './mat.js';
|
|
2
|
+
/**
|
|
3
|
+
* Simplifies the given MAT by replacing the piecewise quad beziers composing
|
|
4
|
+
* the MAT with fewer ones to within a given tolerance.
|
|
5
|
+
* @param cpNode A representation of the MAT
|
|
6
|
+
* @param anlgeTolerance Tolerance given as the degrees difference of the unit
|
|
7
|
+
* direction vectors at the interface between curves. A tolerance of zero means
|
|
8
|
+
* perfect smoothness is required - defaults to 15.
|
|
9
|
+
* TODO - the next two params are wrong??
|
|
10
|
+
* @param hausdorffTolerance The approximate maximum Hausdorff Distance tolerance -
|
|
11
|
+
* defaults to 0.1
|
|
12
|
+
* @param maxIterations The spacing on the curves used to calculate the Hausdorff
|
|
13
|
+
* Distance - defaults to 1
|
|
14
|
+
*/
|
|
15
|
+
declare function simplifyMat(mat: Mat, anlgeTolerance?: number, hausdorffTolerance?: number, maxIterations?: number): Mat;
|
|
16
|
+
export { simplifyMat };
|
package/node/simplify-mat.js
CHANGED
|
@@ -1,72 +1,72 @@
|
|
|
1
|
-
import { hausdorffDistance } from 'flo-bezier3';
|
|
2
|
-
import { CpNode } from './cp-node.js';
|
|
3
|
-
import { getBranches } from './get-branches.js';
|
|
4
|
-
import { getCurveToNext } from './get-curve-to-next.js';
|
|
5
|
-
import { getCurveBetween } from './get-curve/get-curve-between.js';
|
|
6
|
-
/**
|
|
7
|
-
* Simplifies the given MAT by replacing the piecewise quad beziers composing
|
|
8
|
-
* the MAT with fewer ones to within a given tolerance.
|
|
9
|
-
* @param cpNode A representation of the MAT
|
|
10
|
-
* @param anlgeTolerance Tolerance given as the degrees difference of the unit
|
|
11
|
-
* direction vectors at the interface between curves. A tolerance of zero means
|
|
12
|
-
* perfect smoothness is required - defaults to 15.
|
|
13
|
-
* TODO - the next two params are wrong??
|
|
14
|
-
* @param hausdorffTolerance The approximate maximum Hausdorff Distance tolerance -
|
|
15
|
-
* defaults to 0.1
|
|
16
|
-
* @param maxIterations The spacing on the curves used to calculate the Hausdorff
|
|
17
|
-
* Distance - defaults to 1
|
|
18
|
-
*/
|
|
19
|
-
function simplifyMat(mat, anlgeTolerance = 15, hausdorffTolerance = 2 ** -3, maxIterations = 50) {
|
|
20
|
-
let cpNode = mat.cpNode;
|
|
21
|
-
// Start from a leaf
|
|
22
|
-
while (!cpNode.isTerminating()) {
|
|
23
|
-
cpNode = cpNode.next;
|
|
24
|
-
}
|
|
25
|
-
const branches = getBranches(cpNode, anlgeTolerance);
|
|
26
|
-
const canDeletes = [];
|
|
27
|
-
for (let k = 0; k < branches.length; k++) {
|
|
28
|
-
const branch = branches[k];
|
|
29
|
-
// Try to remove some
|
|
30
|
-
let j = 0;
|
|
31
|
-
while (j < branch.length) {
|
|
32
|
-
const i = j;
|
|
33
|
-
while (true) {
|
|
34
|
-
j++;
|
|
35
|
-
if (j === branch.length) {
|
|
36
|
-
break;
|
|
37
|
-
}
|
|
38
|
-
const hd = getTotalHausdorffDistance(i, j, branch, maxIterations);
|
|
39
|
-
if (hd > hausdorffTolerance) {
|
|
40
|
-
break;
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
canDeletes.push(branch[j]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (i + 1 === j) {
|
|
47
|
-
// no simplification occured
|
|
48
|
-
break;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
for (const cpNode of canDeletes) {
|
|
53
|
-
const isTerminating = cpNode.isTerminating();
|
|
54
|
-
const onCircleCount = cpNode.getCpNodesOnCircle().length;
|
|
55
|
-
if (isTerminating || onCircleCount !== 2) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
CpNode.remove(cpNode);
|
|
59
|
-
}
|
|
60
|
-
//return { cpNode, cpTrees: createNewCpTree(cpNode) };
|
|
61
|
-
return { cpNode, cpTrees: undefined };
|
|
62
|
-
}
|
|
63
|
-
function getTotalHausdorffDistance(i, j, branch, hausdorffSpacing) {
|
|
64
|
-
const hds = [];
|
|
65
|
-
const longCurve = getCurveBetween(branch[i], branch[j].next);
|
|
66
|
-
for (; i < j + 1; i++) {
|
|
67
|
-
hds.push(hausdorffDistance(getCurveToNext(branch[i]), longCurve, hausdorffSpacing));
|
|
68
|
-
}
|
|
69
|
-
return Math.max(...hds);
|
|
70
|
-
}
|
|
71
|
-
export { simplifyMat };
|
|
1
|
+
import { hausdorffDistance } from 'flo-bezier3';
|
|
2
|
+
import { CpNode } from './cp-node.js';
|
|
3
|
+
import { getBranches } from './get-branches.js';
|
|
4
|
+
import { getCurveToNext } from './get-curve-to-next.js';
|
|
5
|
+
import { getCurveBetween } from './get-curve/get-curve-between.js';
|
|
6
|
+
/**
|
|
7
|
+
* Simplifies the given MAT by replacing the piecewise quad beziers composing
|
|
8
|
+
* the MAT with fewer ones to within a given tolerance.
|
|
9
|
+
* @param cpNode A representation of the MAT
|
|
10
|
+
* @param anlgeTolerance Tolerance given as the degrees difference of the unit
|
|
11
|
+
* direction vectors at the interface between curves. A tolerance of zero means
|
|
12
|
+
* perfect smoothness is required - defaults to 15.
|
|
13
|
+
* TODO - the next two params are wrong??
|
|
14
|
+
* @param hausdorffTolerance The approximate maximum Hausdorff Distance tolerance -
|
|
15
|
+
* defaults to 0.1
|
|
16
|
+
* @param maxIterations The spacing on the curves used to calculate the Hausdorff
|
|
17
|
+
* Distance - defaults to 1
|
|
18
|
+
*/
|
|
19
|
+
function simplifyMat(mat, anlgeTolerance = 15, hausdorffTolerance = 2 ** -3, maxIterations = 50) {
|
|
20
|
+
let cpNode = mat.cpNode;
|
|
21
|
+
// Start from a leaf
|
|
22
|
+
while (!cpNode.isTerminating()) {
|
|
23
|
+
cpNode = cpNode.next;
|
|
24
|
+
}
|
|
25
|
+
const branches = getBranches(cpNode, anlgeTolerance);
|
|
26
|
+
const canDeletes = [];
|
|
27
|
+
for (let k = 0; k < branches.length; k++) {
|
|
28
|
+
const branch = branches[k];
|
|
29
|
+
// Try to remove some
|
|
30
|
+
let j = 0;
|
|
31
|
+
while (j < branch.length) {
|
|
32
|
+
const i = j;
|
|
33
|
+
while (true) {
|
|
34
|
+
j++;
|
|
35
|
+
if (j === branch.length) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const hd = getTotalHausdorffDistance(i, j, branch, maxIterations);
|
|
39
|
+
if (hd > hausdorffTolerance) {
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
canDeletes.push(branch[j]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (i + 1 === j) {
|
|
47
|
+
// no simplification occured
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
for (const cpNode of canDeletes) {
|
|
53
|
+
const isTerminating = cpNode.isTerminating();
|
|
54
|
+
const onCircleCount = cpNode.getCpNodesOnCircle().length;
|
|
55
|
+
if (isTerminating || onCircleCount !== 2) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
CpNode.remove(cpNode);
|
|
59
|
+
}
|
|
60
|
+
//return { cpNode, cpTrees: createNewCpTree(cpNode) };
|
|
61
|
+
return { cpNode, cpTrees: undefined };
|
|
62
|
+
}
|
|
63
|
+
function getTotalHausdorffDistance(i, j, branch, hausdorffSpacing) {
|
|
64
|
+
const hds = [];
|
|
65
|
+
const longCurve = getCurveBetween(branch[i], branch[j].next);
|
|
66
|
+
for (; i < j + 1; i++) {
|
|
67
|
+
hds.push(hausdorffDistance(getCurveToNext(branch[i]), longCurve, hausdorffSpacing));
|
|
68
|
+
}
|
|
69
|
+
return Math.max(...hds);
|
|
70
|
+
}
|
|
71
|
+
export { simplifyMat };
|
|
72
72
|
//# sourceMappingURL=simplify-mat.js.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Loop } from '../loop.js';
|
|
2
|
-
import { IPointOnShape } from '../point-on-shape.js';
|
|
3
|
-
/**
|
|
4
|
-
* @hidden
|
|
5
|
-
*/
|
|
6
|
-
declare const getLoopBounds: (a: Loop) => {
|
|
7
|
-
minX: IPointOnShape;
|
|
8
|
-
minY: IPointOnShape;
|
|
9
|
-
maxX: IPointOnShape;
|
|
10
|
-
maxY: IPointOnShape;
|
|
11
|
-
};
|
|
12
|
-
export { getLoopBounds };
|
|
1
|
+
import { Loop } from '../loop.js';
|
|
2
|
+
import { IPointOnShape } from '../point-on-shape.js';
|
|
3
|
+
/**
|
|
4
|
+
* @hidden
|
|
5
|
+
*/
|
|
6
|
+
declare const getLoopBounds: (a: Loop) => {
|
|
7
|
+
minX: IPointOnShape;
|
|
8
|
+
minY: IPointOnShape;
|
|
9
|
+
maxX: IPointOnShape;
|
|
10
|
+
maxY: IPointOnShape;
|
|
11
|
+
};
|
|
12
|
+
export { getLoopBounds };
|