flo-mat 3.0.13 → 3.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__tests__/cp-node/check-clone-eql-calc.spec.ts +58 -0
- package/__tests__/cp-node/compare-cp-nodes-by-value.ts +35 -0
- package/__tests__/cp-node/compare-loops-by-value.ts +40 -0
- package/__tests__/cp-node/compare-poss-by-value.ts +25 -0
- package/__tests__/cp-node/fs/clone.spec.ts +19 -3
- package/__tests__/cp-node/fs/find-first.spec.ts +13 -3
- package/__tests__/cp-node/fs/get-all-between.spec.ts +20 -3
- package/__tests__/cp-node/fs/get-all-on-circle.spec.ts +2 -2
- package/__tests__/cp-node/fs/get-all-on-loop.spec.ts +16 -3
- package/__tests__/cp-node/fs/get-all-vertices.spec.ts +14 -3
- package/__tests__/cp-node/fs/get-children.spec.ts +18 -3
- package/__tests__/cp-node/fs/get-non-terminating-on-circle.spec.ts +14 -3
- package/__tests__/cp-node/fs/get-prong-count.spec.ts +16 -3
- package/__tests__/cp-node/fs/get-real-prong-count.spec.ts +11 -3
- package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +20 -3
- package/__tests__/cp-node/fs/is-fully-terminating.spec.ts +16 -3
- package/__tests__/cp-node/fs/is-on-same-circle.spec.ts +20 -3
- package/__tests__/cp-node/fs/is-one-prong.spec.ts +16 -3
- package/__tests__/cp-node/fs/is-sharp.spec.ts +10 -3
- package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +13 -3
- package/__tests__/cp-node/fs/is-special.spec.ts +12 -3
- package/__tests__/cp-node/fs/is-terminating.spec.ts +15 -3
- package/__tests__/cp-node/fs/is-trivial.spec.ts +13 -3
- package/__tests__/cp-node/fs/is-two-prong.spec.ts +11 -3
- package/__tests__/cp-node/fs/is-vertex-special.spec.ts +13 -3
- package/__tests__/cp-node/fs/is-vertex.spec.ts +14 -3
- package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +13 -3
- package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +10 -3
- package/__tests__/cp-node/fs/traverse-cp.spec.ts +9 -3
- package/__tests__/cp-node/fs/traverse-edges.spec.ts +13 -3
- package/__tests__/cp-node/fs/traverse-vertices.spec.ts +12 -3
- package/__tests__/cp-node/random-walk.ts +33 -0
- package/__tests__/cp-node/stringification/from-stringifyable.spec.ts +3 -0
- package/__tests__/cp-node/stringification/loop-from-stringifyable.spec.ts +4 -0
- package/__tests__/cp-node/stringification/loop-to-stringifyable.spec.ts +19 -0
- package/__tests__/cp-node/stringification/to-stringifyable.spec.ts +34 -0
- package/__tests__/get-mats1.ts +125 -0
- package/__tests__/jsog/check-jsog-eql-calc.spec.ts +47 -67
- package/__tests__/jsog/decode-jsog.ts +88 -85
- package/__tests__/jsog/mat-dummy-1.ts +19 -0
- package/__tests__/jsog/mat-dummys.ts +6197 -6195
- package/__tests__/jsog/to-jsog-breath-first.ts +110 -107
- package/__tests__/jsog/to-jsog-depth-first.ts +58 -55
- package/browser/index.js +7002 -6298
- package/browser/index.min.js +1 -1
- package/jest.config.cjs +1 -0
- package/node/closest-boundary-point/foot-and-endpoint-info.d.ts +1 -1
- package/node/closest-boundary-point/get-close-boundary-points-certified.d.ts +3 -3
- package/node/closest-boundary-point/get-close-boundary-points-certified.js +1 -1
- package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.d.ts +2 -2
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +7 -7
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
- package/node/cp-node/cp-node.d.ts +2 -2
- package/node/cp-node/fs/clone.d.ts +1 -1
- package/node/cp-node/fs/clone.js +17 -13
- package/node/cp-node/fs/clone.js.map +1 -1
- package/node/cp-node/fs/enhance-cp-node.d.ts +2 -2
- package/node/cp-node/fs/find-first.d.ts +9 -2
- package/node/cp-node/fs/find-first.js +12 -9
- package/node/cp-node/fs/find-first.js.map +1 -1
- package/node/cp-node/fs/get-all-on-loop.js +5 -6
- package/node/cp-node/fs/get-all-on-loop.js.map +1 -1
- package/node/cp-node/fs/get-edge-direction.d.ts +1 -1
- package/node/cp-node/fs/get-edge-direction.js.map +1 -1
- package/node/cp-node/fs/is-on-same-circle.d.ts +1 -0
- package/node/cp-node/fs/is-on-same-circle.js +1 -0
- package/node/cp-node/fs/is-on-same-circle.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.d.ts +1 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.js +1 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.js.map +1 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.d.ts +1 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.js +2 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +1 -1
- package/node/find-mat/find-mats.js +7 -2
- package/node/find-mat/find-mats.js.map +1 -1
- package/node/find-mat/get-meta.d.ts +4 -4
- package/node/find-mat/get-meta.js +1 -1
- package/node/find-mat/get-meta.js.map +1 -1
- package/node/geometry/circle.d.ts +4 -3
- package/node/geometry/circle.js +0 -7
- package/node/geometry/circle.js.map +1 -1
- package/node/index.d.ts +2 -2
- package/node/index.js +1 -0
- package/node/index.js.map +1 -1
- package/node/mat/curve-piece.d.ts +3 -3
- package/node/mat/get-boundary-piece-beziers.d.ts +2 -2
- package/node/mat/mat-meta.d.ts +4 -4
- package/node/mat/simplify-mat.d.ts +10 -8
- package/node/mat/simplify-mat.js +12 -10
- package/node/mat/simplify-mat.js.map +1 -1
- package/node/point-on-shape/create-pos.d.ts +2 -2
- package/node/point-on-shape/create-pos.js.map +1 -1
- package/node/point-on-shape/point-on-shape.d.ts +6 -6
- package/node/svg/get-loop-bounds.d.ts +2 -2
- package/node/svg/get-loop-bounds.js +1 -1
- package/node/svg/get-loop-bounds.js.map +1 -1
- package/package.json +10 -10
- package/src/closest-boundary-point/foot-and-endpoint-info.ts +1 -1
- package/src/closest-boundary-point/get-close-boundary-points-certified.ts +5 -5
- package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +9 -9
- package/src/cp-node/cp-node.ts +8 -3
- package/src/cp-node/fs/add-distance-from.ts +37 -37
- package/src/cp-node/fs/clone.ts +23 -17
- package/src/cp-node/fs/find-first.ts +14 -11
- package/src/cp-node/fs/get-all-on-loop.ts +5 -6
- package/src/cp-node/fs/get-boundary-bezier-parts-to-next.ts +1 -1
- package/src/cp-node/fs/get-edge-direction.ts +3 -5
- package/src/cp-node/fs/is-on-same-circle.ts +1 -0
- package/src/cp-node/stringification/cp-node-stringifyable.ts +68 -0
- package/src/cp-node/stringification/from-stringifyable.ts +57 -0
- package/src/cp-node/stringification/loop-from-stringifyable.ts +15 -0
- package/src/cp-node/stringification/loop-stringifyable.ts +8 -0
- package/src/cp-node/stringification/loop-to-stringifyable.ts +14 -0
- package/src/cp-node/stringification/to-stringifyable.ts +71 -0
- package/src/curve/curve.ts +31 -33
- package/src/debug/functions/draw-elem/draw-dull-corner.ts +2 -2
- package/src/debug/functions/draw-elem/draw-sharp-corner.ts +4 -3
- package/src/find-mat/find-mats.ts +8 -2
- package/src/find-mat/get-meta.ts +7 -6
- package/src/geometry/circle.ts +5 -12
- package/src/index.ts +3 -4
- package/src/mat/curve-piece.ts +3 -3
- package/src/mat/get-boundary-piece-beziers.ts +3 -3
- package/src/mat/mat-meta.ts +4 -4
- package/src/mat/simplify-mat-map-only.ts +110 -110
- package/src/mat/simplify-mat.ts +15 -13
- package/src/point-on-shape/create-pos.ts +3 -3
- package/src/point-on-shape/point-on-shape.ts +6 -6
- package/src/svg/get-loop-bounds.ts +4 -5
- package/__tests__/cp-node/fs/add-distance-from.spec.ts +0 -7
- package/__tests__/cp-node/fs/cp-nodes-to-boundary-beziers.spec.ts +0 -7
- package/__tests__/cp-node/fs/create-cp-node.spec.ts +0 -7
- package/__tests__/cp-node/fs/enhance-cp-node.spec.ts +0 -7
- package/__tests__/jsog/get-mats1.ts +0 -41
- package/node/curve/curve.d.ts +0 -33
- package/node/curve/curve.js +0 -2
- package/node/curve/curve.js.map +0 -1
package/src/mat/simplify-mat.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import type { Mat } from './mat.js';
|
|
2
|
+
import type { CpNode } from '../cp-node/cp-node.js';
|
|
1
3
|
import { hausdorffDistanceOneSided } from 'flo-bezier3';
|
|
2
|
-
import { CpNode } from '../cp-node/cp-node.js';
|
|
3
4
|
import { removeVertex } from '../vertex/remove-vertex.js';
|
|
4
5
|
import { getBranches } from './get-branches.js';
|
|
5
6
|
import { getMatCurveToNext } from '../cp-node/fs/get-mat-curve-to-next.js';
|
|
6
7
|
import { getMatCurveBetween } from '../cp-node/fs/get-mat-curve-between.js';
|
|
7
|
-
import { Mat } from './mat.js';
|
|
8
8
|
import { createNewCpTree } from './create-new-cp-tree.js';
|
|
9
9
|
import { clone } from '../cp-node/fs/clone.js';
|
|
10
10
|
import { findFirst } from '../cp-node/fs/find-first.js';
|
|
@@ -16,15 +16,17 @@ import { getProngCount } from '../cp-node/fs/get-prong-count.js';
|
|
|
16
16
|
|
|
17
17
|
// TODO2 could be made faster by binary "search" on hausdorff curves
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
20
|
-
* the MAT with fewer ones to within a given tolerance.
|
|
21
|
-
*
|
|
22
|
-
* @param
|
|
19
|
+
* Returns a new simplified MAT of the given one by replacing the piecewise
|
|
20
|
+
* quad beziers composing the MAT with fewer ones to within a given tolerance.
|
|
21
|
+
*
|
|
22
|
+
* @param cpNode a representation of the MAT
|
|
23
|
+
* @param anlgeTolerance tolerance given as the degrees difference of the unit
|
|
23
24
|
* direction vectors at the interface between curves. A tolerance of zero means
|
|
24
|
-
* perfect smoothness is required - defaults to 15
|
|
25
|
-
* @param hausdorffTolerance
|
|
25
|
+
* perfect smoothness is required - defaults to 15
|
|
26
|
+
* @param hausdorffTolerance the approximate maximum Hausdorff Distance tolerance -
|
|
26
27
|
* defaults to `2**-3`
|
|
27
|
-
* @param maxIterations
|
|
28
|
+
* @param maxIterations the max iterations of the Hausdorff Distance calculation,
|
|
29
|
+
* defaults to `50`
|
|
28
30
|
*/
|
|
29
31
|
function simplifyMat(
|
|
30
32
|
mat: Mat,
|
|
@@ -60,14 +62,14 @@ function simplifyMat(
|
|
|
60
62
|
}
|
|
61
63
|
}
|
|
62
64
|
|
|
63
|
-
if (i+1 === j) {
|
|
64
|
-
// no simplification occured
|
|
65
|
-
continue;
|
|
65
|
+
if (i+1 === j) {
|
|
66
|
+
continue; // no simplification occured
|
|
66
67
|
}
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
cpNode = findFirst(cpNode_ => isTerminating(cpNode_) ? cpNode_ : undefined, cpNode)!;
|
|
71
|
+
// cpNode = findFirst(cpNode_ => isTerminating(cpNode_) ? cpNode_ : undefined, cpNode)!;
|
|
72
|
+
cpNode = findFirst(isTerminating, cpNode)!;
|
|
71
73
|
|
|
72
74
|
for (const cpNode of canDeletes) {
|
|
73
75
|
if (!isVertex(cpNode =>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { Curve } from "flo-boolean";
|
|
2
|
+
import type { PointOnShape } from "./point-on-shape.js";
|
|
3
|
+
import { evalDeCasteljauDd } from "flo-bezier3";
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
function createPos(
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { Curve } from '
|
|
1
|
+
import type { Curve } from 'flo-boolean';
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
interface PointOnShape {
|
|
5
5
|
/** The `Curve` on the shape boundary this points belong to. */
|
|
6
|
-
curve: Curve;
|
|
6
|
+
readonly curve: Curve;
|
|
7
7
|
/** The bezier parameter value on the curve identifying the point coordinates. */
|
|
8
|
-
t: number;
|
|
9
|
-
p: number[];
|
|
8
|
+
readonly t: number;
|
|
9
|
+
readonly p: number[];
|
|
10
10
|
/** just for debugging */
|
|
11
|
-
isSource?: boolean;
|
|
11
|
+
readonly isSource?: boolean;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
export { PointOnShape }
|
|
15
|
+
export type { PointOnShape }
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { Curve, Loop } from 'flo-boolean';
|
|
2
|
+
import type { PointOnShape } from '../point-on-shape/point-on-shape.js';
|
|
2
3
|
import { memoize } from 'flo-memoize';
|
|
3
|
-
import {
|
|
4
|
-
import { Curve } from '../curve/curve.js';
|
|
5
|
-
import { PointOnShape } from '../point-on-shape/point-on-shape.js';
|
|
4
|
+
import { getBounds } from 'flo-bezier3';
|
|
6
5
|
import { createPos } from '../point-on-shape/create-pos.js';
|
|
7
6
|
|
|
8
7
|
|
|
@@ -17,7 +16,7 @@ const getLoopBounds = memoize(function(loop: Loop): {
|
|
|
17
16
|
minX: PointOnShape;
|
|
18
17
|
minY: PointOnShape;
|
|
19
18
|
maxX: PointOnShape;
|
|
20
|
-
maxY: PointOnShape } {
|
|
19
|
+
maxY: PointOnShape } {
|
|
21
20
|
|
|
22
21
|
const extremes: {
|
|
23
22
|
bezier: Curve,
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Mat } from "../../src/mat/mat.js";
|
|
2
|
-
import { findMats } from "../../src/find-mat/find-mats.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/** mat-demo: "achispado" font, "comma" glyph */
|
|
6
|
-
const loops1 = [
|
|
7
|
-
[
|
|
8
|
-
[[139, 8], [82, -101]],
|
|
9
|
-
[[82, -101], [24, 8]],
|
|
10
|
-
[[24, 8], [46, 8]],
|
|
11
|
-
[[46, 8], [46, 54]],
|
|
12
|
-
[[46, 54], [117, 54]],
|
|
13
|
-
[[117, 54], [117, 8]],
|
|
14
|
-
[[117, 8], [139, 8]],
|
|
15
|
-
[[139, 8], [139, 8]]
|
|
16
|
-
]
|
|
17
|
-
];
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
// Cache
|
|
21
|
-
let mats1: Mat[] | undefined = undefined;
|
|
22
|
-
function getMats1() {
|
|
23
|
-
if (mats1) { return mats1; }
|
|
24
|
-
|
|
25
|
-
mats1 = findMats(loops1, {
|
|
26
|
-
applySat: false,
|
|
27
|
-
simplify: true,
|
|
28
|
-
satScale: 1.675,
|
|
29
|
-
maxCurviness: 0.05,
|
|
30
|
-
maxLength: 40,
|
|
31
|
-
// maxCurviness: 5,
|
|
32
|
-
// maxLength: 4000,
|
|
33
|
-
angleIncrement: 15,
|
|
34
|
-
simplifyTolerance: 2**-1
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return mats1;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export { getMats1 }
|
package/node/curve/curve.d.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { Loop } from 'flo-boolean';
|
|
2
|
-
/**
|
|
3
|
-
* Represents a bezier curve on the shape boundary / loop.
|
|
4
|
-
*/
|
|
5
|
-
interface Curve {
|
|
6
|
-
/**
|
|
7
|
-
* The closed loop of bezier curves representing the shape
|
|
8
|
-
* boundary this curve belongs to.
|
|
9
|
-
*/
|
|
10
|
-
loop: Loop;
|
|
11
|
-
/**
|
|
12
|
-
* The bezier control points.
|
|
13
|
-
*/
|
|
14
|
-
ps: number[][];
|
|
15
|
-
/**
|
|
16
|
-
* The previous curve (when going in a negative direction around
|
|
17
|
-
* the shape boundary, i.e. clockwise for the outer shape and anti-clockwise
|
|
18
|
-
* for the holes (if any))
|
|
19
|
-
*/
|
|
20
|
-
prev: Curve;
|
|
21
|
-
/**
|
|
22
|
-
* The next curve (when going in a positive direction around
|
|
23
|
-
* the shape boundary, i.e. anti-clockwise for the outer shape and clockwise
|
|
24
|
-
* for the holes (if any))
|
|
25
|
-
*/
|
|
26
|
-
next: Curve;
|
|
27
|
-
/**
|
|
28
|
-
* The curve's ordered index in the loop. This imposes a cycling
|
|
29
|
-
* ordering of the curves in the loop
|
|
30
|
-
*/
|
|
31
|
-
idx: number;
|
|
32
|
-
}
|
|
33
|
-
export { Curve };
|
package/node/curve/curve.js
DELETED
package/node/curve/curve.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"curve.js","sourceRoot":"","sources":["../../src/curve/curve.ts"],"names":[],"mappings":""}
|