flo-mat 4.1.4 → 5.0.1
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__/closest-boundary-point/get-endpoint-info.spec.ts +140 -0
- package/__tests__/closest-boundary-point/root-interval-to-distance-squared-interval.spec.ts +87 -0
- package/__tests__/cp-node/circle-identity.spec.ts +56 -0
- package/__tests__/cp-node/fs/get-all-on-loop-by-loop.spec.ts +55 -0
- package/__tests__/cp-node/fs/get-angle-between-mat-curves.spec.ts +39 -3
- package/__tests__/cp-node/fs/get-boundary-bezier-parts-to-next.spec.ts +87 -3
- package/__tests__/cp-node/fs/get-boundary-beziers-between.spec.ts +68 -3
- package/__tests__/cp-node/fs/get-boundary-beziers-to-next.spec.ts +41 -3
- package/__tests__/cp-node/fs/get-boundary-distance-to-next.spec.ts +20 -3
- package/__tests__/cp-node/fs/get-branch-beziers.spec.ts +42 -3
- package/__tests__/cp-node/fs/get-branch.spec.ts +60 -3
- package/__tests__/cp-node/fs/get-cp-node-ordering.spec.ts +19 -3
- package/__tests__/cp-node/fs/get-distance-to-next.spec.ts +37 -4
- package/__tests__/cp-node/fs/get-edge-direction.spec.ts +50 -3
- package/__tests__/cp-node/fs/get-first-exit.spec.ts +78 -3
- package/__tests__/cp-node/fs/get-hole-closers.spec.ts +32 -3
- package/__tests__/cp-node/fs/get-implied-boundary-bezier-between.spec.ts +48 -3
- package/__tests__/cp-node/fs/get-mat-curve-between.spec.ts +77 -3
- package/__tests__/cp-node/fs/get-mat-curve-to-next.spec.ts +17 -4
- package/__tests__/cp-node/fs/get-mat-curves-between.spec.ts +38 -3
- package/__tests__/cp-node/fs/get-salience.spec.ts +68 -3
- package/__tests__/cp-node/fs/get-vertex-forward-children.spec.ts +40 -3
- package/__tests__/cp-node/fs/insert-cp-node.spec.ts +87 -3
- package/__tests__/cp-node/fs/is-special.spec.ts +1 -1
- package/__tests__/cp-node/fs/remove-cp-node.spec.ts +42 -3
- package/__tests__/find-2-prong/calc-seperation-tolerance.spec.ts +46 -0
- package/__tests__/find-2-prong/get-medial/dd-get-medial-point-coeffs-same-curve.spec.ts +7 -5
- package/__tests__/find-2-prong/get-medial/dd-get-medial-point-coeffs.spec.ts +4 -2
- package/__tests__/find-2-prong/get-medial/get-closest-points.spec.ts +1 -1
- package/__tests__/floyd-warshall/get-graph.spec.ts +100 -0
- package/__tests__/get-mats-with-hole.ts +28 -0
- package/__tests__/get-mats1.spec.ts +61 -0
- package/__tests__/get-mats1.ts +75 -67
- package/__tests__/helpers/cp-node-by-id.ts +27 -0
- package/__tests__/helpers/expect-point-close.ts +42 -0
- package/__tests__/mat/hausdorff-distance-one-sided-exceeds.spec.ts +129 -0
- package/__tests__/mat/simplify-mat.spec.ts +85 -0
- package/__tests__/reconstruct-from-mat/reconstruct-from-mat.spec.ts +39 -0
- package/__tests__/specific-cases/test-svgs/achispado.svg +14 -0
- package/__tests__/utils/get-beziers-from-tangents.spec.ts +142 -0
- package/browser/index.js +17882 -13800
- package/browser/index.min.js +1 -1
- package/node/add-n-prong.ts/join-spokes.js +3 -2
- package/node/add-n-prong.ts/join-spokes.js.map +1 -1
- package/node/closest-boundary-point/cull-curve-pieces.d.ts +21 -0
- package/node/closest-boundary-point/cull-curve-pieces.js +40 -0
- package/node/closest-boundary-point/cull-curve-pieces.js.map +1 -0
- package/node/closest-boundary-point/get-close-boundary-points-certified.js +5 -2
- package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
- package/node/closest-boundary-point/get-endpoint-info.d.ts +39 -0
- package/node/closest-boundary-point/get-endpoint-info.js +78 -0
- package/node/closest-boundary-point/get-endpoint-info.js.map +1 -0
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js +5 -19
- package/node/closest-boundary-point/get-potential-closest-points-on-curve-certified.js.map +1 -1
- package/node/closest-boundary-point/root-interval-to-distance-squared-interval.d.ts +17 -5
- package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js +37 -50
- package/node/closest-boundary-point/root-interval-to-distance-squared-interval.js.map +1 -1
- package/node/corner/get-corner.d.ts +18 -1
- package/node/corner/get-corner.js +8 -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.d.ts +4 -3
- package/node/cp-node/fs/enhance-cp-node.d.ts +9 -9
- package/node/cp-node/fs/get-all-on-loop-by-loop.js +0 -4
- package/node/cp-node/fs/get-all-on-loop-by-loop.js.map +1 -1
- package/node/cp-node/fs/get-angle-between-mat-curves.d.ts +1 -1
- package/node/cp-node/fs/get-angle-between-mat-curves.js +7 -4
- package/node/cp-node/fs/get-angle-between-mat-curves.js.map +1 -1
- package/node/cp-node/fs/get-boundary-beziers-between.d.ts +6 -4
- package/node/cp-node/fs/get-boundary-beziers-between.js +6 -4
- package/node/cp-node/fs/get-boundary-beziers-between.js.map +1 -1
- package/node/cp-node/fs/get-branch-beziers.d.ts +2 -1
- package/node/cp-node/fs/get-branch-beziers.js +3 -2
- package/node/cp-node/fs/get-branch-beziers.js.map +1 -1
- package/node/cp-node/fs/get-branch.js +1 -2
- package/node/cp-node/fs/get-branch.js.map +1 -1
- package/node/cp-node/fs/get-distance-to-next.js +4 -2
- package/node/cp-node/fs/get-distance-to-next.js.map +1 -1
- package/node/cp-node/fs/get-edge-direction.js +3 -2
- package/node/cp-node/fs/get-edge-direction.js.map +1 -1
- package/node/cp-node/fs/get-first-exit.d.ts +7 -3
- package/node/cp-node/fs/get-first-exit.js +13 -11
- package/node/cp-node/fs/get-first-exit.js.map +1 -1
- package/node/cp-node/fs/get-implied-boundary-bezier-between.d.ts +10 -2
- package/node/cp-node/fs/get-implied-boundary-bezier-between.js +11 -54
- package/node/cp-node/fs/get-implied-boundary-bezier-between.js.map +1 -1
- package/node/cp-node/fs/get-mat-curve-between.d.ts +5 -3
- package/node/cp-node/fs/get-mat-curve-between.js +6 -49
- package/node/cp-node/fs/get-mat-curve-between.js.map +1 -1
- package/node/cp-node/fs/get-mat-curve-to-next.d.ts +1 -1
- package/node/cp-node/fs/get-mat-curves-between.d.ts +8 -0
- package/node/cp-node/fs/get-mat-curves-between.js +9 -2
- package/node/cp-node/fs/get-mat-curves-between.js.map +1 -1
- package/node/cp-node/fs/get-real-prong-count.d.ts +2 -1
- package/node/cp-node/fs/get-real-prong-count.js +11 -5
- package/node/cp-node/fs/get-real-prong-count.js.map +1 -1
- package/node/cp-node/fs/get-salience.d.ts +10 -0
- package/node/cp-node/fs/get-salience.js +17 -1
- package/node/cp-node/fs/get-salience.js.map +1 -1
- package/node/cp-node/fs/is-fully-terminating.d.ts +4 -2
- package/node/cp-node/fs/is-fully-terminating.js +6 -17
- package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
- package/node/cp-node/fs/is-on-same-circle.d.ts +3 -0
- package/node/cp-node/fs/is-on-same-circle.js +4 -4
- package/node/cp-node/fs/is-on-same-circle.js.map +1 -1
- package/node/cp-node/fs/is-on-same-loop.d.ts +1 -1
- package/node/cp-node/fs/is-special.d.ts +7 -0
- package/node/cp-node/fs/is-special.js +9 -2
- package/node/cp-node/fs/is-special.js.map +1 -1
- package/node/cp-node/fs/is-vertex.d.ts +1 -1
- package/node/cp-node/fs/traverse-edges.d.ts +7 -3
- package/node/cp-node/fs/traverse-edges.js +7 -3
- package/node/cp-node/fs/traverse-edges.js.map +1 -1
- package/node/cp-node/stringification/from-stringifyable.d.ts +2 -2
- package/node/cp-node/stringification/from-stringifyable.js +17 -1
- package/node/cp-node/stringification/from-stringifyable.js.map +1 -1
- package/node/cp-node/stringification/to-stringifyable.d.ts +3 -3
- package/node/cp-node/stringification/to-stringifyable.js +3 -3
- package/node/debug/debug.d.ts +26 -3
- package/node/debug/debug.js +16 -5
- package/node/debug/debug.js.map +1 -1
- package/node/find-2-prong/add-2-prong.js +7 -9
- package/node/find-2-prong/add-2-prong.js.map +1 -1
- package/node/find-2-prong/calc-seperation-tolerance.d.ts +28 -5
- package/node/find-2-prong/calc-seperation-tolerance.js +32 -89
- package/node/find-2-prong/calc-seperation-tolerance.js.map +1 -1
- package/node/find-2-prong/find-2-prong.js +8 -10
- package/node/find-2-prong/find-2-prong.js.map +1 -1
- package/node/find-2-prong/find-and-add-2-prongs.js +2 -2
- package/node/find-2-prong/find-and-add-2-prongs.js.map +1 -1
- package/node/find-2-prong/get-medial/get-antipodal-points.d.ts +1 -2
- package/node/find-2-prong/get-medial/get-antipodal-points.js +2 -3
- package/node/find-2-prong/get-medial/get-antipodal-points.js.map +1 -1
- package/node/find-2-prong/get-medial/get-closest-points.d.ts +1 -8
- package/node/find-2-prong/get-medial/get-closest-points.js +4 -40
- package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -1
- package/node/find-2-prong/reduce-radius.d.ts +1 -1
- package/node/find-2-prong/reduce-radius.js +6 -3
- package/node/find-2-prong/reduce-radius.js.map +1 -1
- package/node/find-3-prong/calc-better-x.js +1 -1
- package/node/find-3-prong/calc-better-x.js.map +1 -1
- package/node/find-3-prong/find-3-prong-for-delta3s.d.ts +3 -2
- package/node/find-3-prong/find-3-prong-for-delta3s.js +36 -42
- package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
- package/node/find-3-prong/find-3-prong.js +3 -1
- package/node/find-3-prong/find-3-prong.js.map +1 -1
- package/node/find-3-prong/find-and-add-3-prongs.js +16 -0
- package/node/find-3-prong/find-and-add-3-prongs.js.map +1 -1
- package/node/find-mat/create-initial-cp-tree.js +2 -2
- package/node/find-mat/create-initial-cp-tree.js.map +1 -1
- package/node/find-mat/find-mat.js +3 -4
- package/node/find-mat/find-mat.js.map +1 -1
- package/node/find-mat/find-mats.d.ts +6 -12
- package/node/find-mat/find-mats.js +10 -27
- package/node/find-mat/find-mats.js.map +1 -1
- package/node/find-mat/get-dull-corners-on-loop.js +2 -2
- package/node/find-mat/get-dull-corners-on-loop.js.map +1 -1
- package/node/find-mat/get-for-1-prongs-on-loop.js +36 -8
- package/node/find-mat/get-for-1-prongs-on-loop.js.map +1 -1
- package/node/find-mat/get-meta.d.ts +14 -4
- package/node/find-mat/get-meta.js +30 -24
- package/node/find-mat/get-meta.js.map +1 -1
- package/node/find-mat/get-sharp-corners.js +2 -2
- package/node/find-mat/get-sharp-corners.js.map +1 -1
- package/node/find-mat/mat-options.d.ts +2 -2
- package/node/floyd-warshall/get-graph.d.ts +12 -1
- package/node/floyd-warshall/get-graph.js +41 -38
- package/node/floyd-warshall/get-graph.js.map +1 -1
- package/node/geometry/get-bounding-box-.d.ts +16 -2
- package/node/geometry/get-bounding-box-.js +5 -2
- package/node/geometry/get-bounding-box-.js.map +1 -1
- package/node/geometry/get-closest-square-distance-to-rect.d.ts +3 -0
- package/node/geometry/get-closest-square-distance-to-rect.js +7 -5
- package/node/geometry/get-closest-square-distance-to-rect.js.map +1 -1
- package/node/geometry/get-closest-squared-distance-to-rotated-rect.d.ts +4 -0
- package/node/geometry/get-closest-squared-distance-to-rotated-rect.js +12 -5
- package/node/geometry/get-closest-squared-distance-to-rotated-rect.js.map +1 -1
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js +1 -2
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js.map +1 -1
- package/node/index.d.ts +3 -2
- package/node/index.js +2 -1
- package/node/index.js.map +1 -1
- package/node/mat/clone-mat.d.ts +9 -0
- package/node/mat/clone-mat.js +17 -0
- package/node/mat/clone-mat.js.map +1 -0
- package/node/mat/clone-meta.d.ts +12 -0
- package/node/mat/clone-meta.js +24 -0
- package/node/mat/clone-meta.js.map +1 -0
- package/node/mat/get-boundary-piece-beziers.d.ts +5 -0
- package/node/mat/get-boundary-piece-beziers.js +7 -93
- package/node/mat/get-boundary-piece-beziers.js.map +1 -1
- package/node/mat/get-closeby-cp-if-exist.js +2 -1
- package/node/mat/get-closeby-cp-if-exist.js.map +1 -1
- package/node/mat/get-largest-3-prong.d.ts +6 -0
- package/node/mat/get-largest-3-prong.js +8 -5
- package/node/mat/get-largest-3-prong.js.map +1 -1
- package/node/mat/get-largest-vertex.d.ts +15 -1
- package/node/mat/get-largest-vertex.js +20 -7
- package/node/mat/get-largest-vertex.js.map +1 -1
- package/node/mat/hausdorff-distance-one-sided-exceeds.d.ts +79 -0
- package/node/mat/hausdorff-distance-one-sided-exceeds.js +251 -0
- package/node/mat/hausdorff-distance-one-sided-exceeds.js.map +1 -0
- package/node/mat/mat-meta.d.ts +0 -6
- package/node/mat/simplify-mat.d.ts +25 -8
- package/node/mat/simplify-mat.js +182 -53
- package/node/mat/simplify-mat.js.map +1 -1
- package/node/mat/trim-mat.d.ts +4 -2
- package/node/mat/trim-mat.js +3 -1
- package/node/mat/trim-mat.js.map +1 -1
- package/node/point-on-shape/get-boundary-tangent-line.d.ts +19 -0
- package/node/point-on-shape/get-boundary-tangent-line.js +33 -0
- package/node/point-on-shape/get-boundary-tangent-line.js.map +1 -0
- package/node/point-on-shape/get-osculating-circle.d.ts +6 -4
- package/node/point-on-shape/get-osculating-circle.js +6 -4
- package/node/point-on-shape/get-osculating-circle.js.map +1 -1
- package/node/point-on-shape/get-pos-corner.js +2 -2
- package/node/point-on-shape/get-pos-corner.js.map +1 -1
- package/node/point-on-shape/point-on-shape.d.ts +5 -0
- package/node/reconstruct-from-mat/reconstruct-from-mat.js +20 -80
- package/node/reconstruct-from-mat/reconstruct-from-mat.js.map +1 -1
- package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.d.ts +4 -0
- package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js +4 -0
- package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js.map +1 -1
- package/node/sat/cull.d.ts +7 -6
- package/node/sat/cull.js +13 -16
- package/node/sat/cull.js.map +1 -1
- package/node/sat/get-sat-culls.d.ts +12 -2
- package/node/sat/get-sat-culls.js +21 -16
- package/node/sat/get-sat-culls.js.map +1 -1
- package/node/svg/get-shape-bounds.d.ts +1 -12
- package/node/svg/get-shape-bounds.js +2 -3
- package/node/svg/get-shape-bounds.js.map +1 -1
- package/node/sweep-line/sweep-line.js.map +1 -1
- package/node/utils/get-beziers-from-tangents.d.ts +28 -0
- package/node/utils/get-beziers-from-tangents.js +92 -0
- package/node/utils/get-beziers-from-tangents.js.map +1 -0
- package/node/vertex/remove-vertex.d.ts +5 -3
- package/node/vertex/remove-vertex.js +5 -3
- package/node/vertex/remove-vertex.js.map +1 -1
- package/package.json +16 -16
- package/qv-infinite-loop.md +120 -0
- package/src/add-n-prong.ts/join-spokes.ts +4 -2
- package/src/closest-boundary-point/cull-curve-pieces.ts +49 -0
- package/src/closest-boundary-point/get-close-boundary-points-certified.ts +5 -2
- package/src/closest-boundary-point/get-endpoint-info.ts +96 -0
- package/src/closest-boundary-point/get-potential-closest-points-on-curve-certified.ts +5 -23
- package/src/closest-boundary-point/root-interval-to-distance-squared-interval.ts +42 -60
- package/src/corner/get-corner.ts +10 -1
- package/src/corner/get-interface-ccw.ts +2 -2
- package/src/cp-node/cp-node.ts +4 -3
- package/src/cp-node/fs/get-all-on-loop-by-loop.ts +0 -4
- package/src/cp-node/fs/get-angle-between-mat-curves.ts +9 -5
- package/src/cp-node/fs/get-boundary-beziers-between.ts +10 -8
- package/src/cp-node/fs/get-branch-beziers.ts +3 -2
- package/src/cp-node/fs/get-branch.ts +1 -2
- package/src/cp-node/fs/get-distance-to-next.ts +4 -2
- package/src/cp-node/fs/get-edge-direction.ts +4 -2
- package/src/cp-node/fs/get-first-exit.ts +15 -14
- package/src/cp-node/fs/get-implied-boundary-bezier-between.ts +18 -70
- package/src/cp-node/fs/get-mat-curve-between.ts +10 -67
- package/src/cp-node/fs/get-mat-curves-between.ts +9 -2
- package/src/cp-node/fs/get-real-prong-count.ts +11 -7
- package/src/cp-node/fs/get-salience.ts +15 -2
- package/src/cp-node/fs/is-fully-terminating.ts +6 -22
- package/src/cp-node/fs/is-on-same-circle.ts +6 -7
- package/src/cp-node/fs/is-on-same-loop.ts +2 -2
- package/src/cp-node/fs/is-special.ts +11 -6
- package/src/cp-node/fs/is-vertex.ts +1 -1
- package/src/cp-node/fs/traverse-edges.ts +8 -4
- package/src/cp-node/stringification/from-stringifyable.ts +75 -58
- package/src/cp-node/stringification/to-stringifyable.ts +3 -3
- package/src/debug/debug.ts +44 -8
- package/src/find-2-prong/add-2-prong.ts +9 -11
- package/src/find-2-prong/calc-seperation-tolerance.ts +34 -115
- package/src/find-2-prong/find-2-prong.ts +9 -11
- package/src/find-2-prong/find-and-add-2-prongs.ts +2 -2
- package/src/find-2-prong/get-medial/get-antipodal-points.ts +1 -3
- package/src/find-2-prong/get-medial/get-closest-points.ts +6 -51
- package/src/find-2-prong/reduce-radius.ts +6 -4
- package/src/find-3-prong/calc-better-x.ts +2 -2
- package/src/find-3-prong/find-3-prong-for-delta3s.ts +197 -214
- package/src/find-3-prong/find-3-prong.ts +54 -51
- package/src/find-3-prong/find-and-add-3-prongs.ts +20 -1
- package/src/find-mat/create-initial-cp-tree.ts +2 -2
- package/src/find-mat/find-mat.ts +4 -6
- package/src/find-mat/find-mats.ts +83 -105
- package/src/find-mat/get-dull-corners-on-loop.ts +2 -2
- package/src/find-mat/get-for-1-prongs-on-loop.ts +40 -8
- package/src/find-mat/get-meta.ts +34 -39
- package/src/find-mat/get-sharp-corners.ts +2 -2
- package/src/find-mat/mat-options.ts +2 -2
- package/src/floyd-warshall/get-graph.ts +46 -47
- package/src/geometry/get-bounding-box-.ts +5 -2
- package/src/geometry/get-closest-square-distance-to-rect.ts +7 -7
- package/src/geometry/get-closest-squared-distance-to-rotated-rect.ts +15 -13
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.ts +1 -2
- package/src/index.ts +3 -2
- package/src/mat/clone-mat.ts +9 -3
- package/src/mat/clone-meta.ts +8 -0
- package/src/mat/get-boundary-piece-beziers.ts +16 -117
- package/src/mat/get-closeby-cp-if-exist.ts +3 -1
- package/src/mat/get-largest-3-prong.ts +9 -6
- package/src/mat/get-largest-vertex.ts +25 -9
- package/src/mat/hausdorff-distance-one-sided-exceeds.ts +314 -0
- package/src/mat/mat-meta.ts +0 -9
- package/src/mat/simplify-mat.ts +254 -116
- package/src/mat/trim-mat.ts +6 -4
- package/src/point-on-shape/get-boundary-tangent-line.ts +36 -0
- package/src/point-on-shape/get-osculating-circle.ts +7 -5
- package/src/point-on-shape/get-pos-corner.ts +2 -2
- package/src/point-on-shape/point-on-shape.ts +5 -0
- package/src/reconstruct-from-mat/reconstruct-from-mat.ts +22 -111
- package/src/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.ts +4 -0
- package/src/sat/cull.ts +16 -20
- package/src/sat/get-sat-culls.ts +28 -23
- package/src/svg/get-shape-bounds.ts +2 -3
- package/src/sweep-line/sweep-line.ts +1 -1
- package/src/utils/deg-to-rad.ts +4 -2
- package/src/utils/get-beziers-from-tangents.ts +110 -0
- package/src/utils/map-map.ts +1 -1
- package/src/utils/rad-to-deg.ts +4 -1
- package/src/vertex/remove-vertex.ts +5 -3
- package/webpack.config.cjs +7 -2
- package/__tests__/cp-node/fs/get-distance-between.spec.ts +0 -7
- package/__tests__/cp-node/fs/get-terminating-on-circle.spec.ts +0 -24
- package/__tests__/cp-node/fs/is-single-3-prong.spec.ts +0 -17
- package/__tests__/cp-node/fs/iterate-all-on-loop.spec.ts +0 -17
- package/__tests__/cp-node/fs/traverse-all-forward.spec.ts +0 -14
- package/node/closest-boundary-point/cull-bezier-pieces-1.d.ts +0 -9
- package/node/closest-boundary-point/cull-bezier-pieces-1.js +0 -17
- package/node/closest-boundary-point/cull-bezier-pieces-1.js.map +0 -1
- package/node/closest-boundary-point/cull-by-loose-bounding-box.d.ts +0 -13
- package/node/closest-boundary-point/cull-by-loose-bounding-box.js +0 -27
- package/node/closest-boundary-point/cull-by-loose-bounding-box.js.map +0 -1
- package/node/closest-boundary-point/cull-by-tight-boundary-box.d.ts +0 -11
- package/node/closest-boundary-point/cull-by-tight-boundary-box.js +0 -27
- package/node/closest-boundary-point/cull-by-tight-boundary-box.js.map +0 -1
- package/node/cp-node/fs/find-first.d.ts +0 -10
- package/node/cp-node/fs/find-first.js +0 -19
- package/node/cp-node/fs/find-first.js.map +0 -1
- package/node/debug/functions/check-ordering.d.ts +0 -4
- package/node/debug/functions/check-ordering.js +0 -43
- package/node/debug/functions/check-ordering.js.map +0 -1
- package/node/find-2-prong/cull-bezier-pieces.d.ts +0 -13
- package/node/find-2-prong/cull-bezier-pieces.js +0 -43
- package/node/find-2-prong/cull-bezier-pieces.js.map +0 -1
- package/node/floyd-warshall/get-hole-closer-pairs.d.ts +0 -8
- package/node/floyd-warshall/get-hole-closer-pairs.js +0 -27
- package/node/floyd-warshall/get-hole-closer-pairs.js.map +0 -1
- package/node/utils/dual-set.d.ts +0 -27
- package/node/utils/dual-set.js +0 -55
- package/node/utils/dual-set.js.map +0 -1
- package/node/utils/tri-map.d.ts +0 -27
- package/node/utils/tri-map.js +0 -49
- package/node/utils/tri-map.js.map +0 -1
- package/src/closest-boundary-point/cull-bezier-pieces-1.ts +0 -36
- package/src/closest-boundary-point/cull-by-loose-bounding-box.ts +0 -42
- package/src/closest-boundary-point/cull-by-tight-boundary-box.ts +0 -43
- package/src/closest-boundary-point/get-p-from-box.ts +0 -14
- package/src/cp-node/fs/add-distance-from.ts +0 -49
- package/src/cp-node/fs/get-distance-between.ts +0 -16
- package/src/cp-node/fs/get-terminating-on-circle.ts +0 -24
- package/src/cp-node/fs/is-single-3-prong.ts +0 -15
- package/src/cp-node/fs/iterate-all-on-loop.ts +0 -15
- package/src/cp-node/fs/traverse-all-forward.ts +0 -24
- package/src/debug/functions/draw/draw-beziers-as-single-path.ts +0 -40
- package/src/debug/functions/draw/draw-disk.ts +0 -34
- package/src/debug/functions/draw/xmlns.ts +0 -5
- package/src/find-2-prong/cull-bezier-pieces.ts +0 -61
- package/src/find-2-prong/find-and-add-2-prong.ts +0 -30
- package/src/find-2-prong/get-medial/get-closest-points-d.ts +0 -213
- package/src/find-2-prong/x-for-debugging.ts +0 -13
- package/src/floyd-warshall/get-hole-closer-pairs.ts +0 -35
- package/src/mat/get-two-prong-type.ts +0 -13
- package/src/point-on-shape/is-pos-dull-corner.ts +0 -18
- package/src/point-on-shape/is-pos-quite-dull-corner.ts +0 -18
- package/src/point-on-shape/is-pos-quite-sharp-corner.ts +0 -18
- package/src/point-on-shape/pos-to-human-string.ts +0 -18
- package/src/sweep-line/are-boxes-intersecting.ts +0 -37
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { closestPointOnBezier, controlPointLinesLength, evalDeCasteljau, fromTo } from 'flo-bezier3';
|
|
2
|
+
const { max, sqrt } = Math;
|
|
3
|
+
/**
|
|
4
|
+
* Returns the closest point on the piecewise bezier curve given by `curves`
|
|
5
|
+
* to the point `p` (as a `Foot`), i.e. the piece-wise minimum of the
|
|
6
|
+
* (certified) `closestPointOnBezier` of `flo-bezier3`.
|
|
7
|
+
*
|
|
8
|
+
* @param p the point
|
|
9
|
+
* @param curves the pieces of the piecewise bezier curve
|
|
10
|
+
*
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
function closestPointOnCurves(p, curves) {
|
|
14
|
+
let best = { d: Infinity, q: p, k: 0, t: 0 };
|
|
15
|
+
for (let k = 0; k < curves.length; k++) {
|
|
16
|
+
const c = closestPointOnBezier(curves[k], p);
|
|
17
|
+
if (c.d < best.d) {
|
|
18
|
+
best = { d: c.d, q: c.p, k, t: c.t };
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return best;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Returns the distance from the point `p` to the piecewise bezier curve given
|
|
25
|
+
* by `curves` (i.e. the minimum over the pieces of the distance to the piece).
|
|
26
|
+
*
|
|
27
|
+
* @param p the point
|
|
28
|
+
* @param curves the pieces of the piecewise bezier curve
|
|
29
|
+
*
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
function distanceToCurves(p, curves) {
|
|
33
|
+
return closestPointOnCurves(p, curves).d;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Evaluates the bezier curve `ps` (of order 1, 2 or 3) and its first two
|
|
37
|
+
* derivatives at `t`, returned as `[B, B', B'']`.
|
|
38
|
+
*
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
function evalWithDerivatives(ps, t) {
|
|
42
|
+
const [p0, p1] = ps;
|
|
43
|
+
if (ps.length === 2) {
|
|
44
|
+
return [
|
|
45
|
+
[p0[0] + t * (p1[0] - p0[0]), p0[1] + t * (p1[1] - p0[1])],
|
|
46
|
+
[p1[0] - p0[0], p1[1] - p0[1]],
|
|
47
|
+
[0, 0]
|
|
48
|
+
];
|
|
49
|
+
}
|
|
50
|
+
const s = 1 - t;
|
|
51
|
+
if (ps.length === 3) {
|
|
52
|
+
const p2 = ps[2];
|
|
53
|
+
return [
|
|
54
|
+
[s * s * p0[0] + 2 * s * t * p1[0] + t * t * p2[0],
|
|
55
|
+
s * s * p0[1] + 2 * s * t * p1[1] + t * t * p2[1]],
|
|
56
|
+
[2 * (s * (p1[0] - p0[0]) + t * (p2[0] - p1[0])),
|
|
57
|
+
2 * (s * (p1[1] - p0[1]) + t * (p2[1] - p1[1]))],
|
|
58
|
+
[2 * (p2[0] - 2 * p1[0] + p0[0]),
|
|
59
|
+
2 * (p2[1] - 2 * p1[1] + p0[1])]
|
|
60
|
+
];
|
|
61
|
+
}
|
|
62
|
+
const p2 = ps[2];
|
|
63
|
+
const p3 = ps[3];
|
|
64
|
+
return [
|
|
65
|
+
[s * s * s * p0[0] + 3 * s * s * t * p1[0] + 3 * s * t * t * p2[0] + t * t * t * p3[0],
|
|
66
|
+
s * s * s * p0[1] + 3 * s * s * t * p1[1] + 3 * s * t * t * p2[1] + t * t * t * p3[1]],
|
|
67
|
+
[3 * (s * s * (p1[0] - p0[0]) + 2 * s * t * (p2[0] - p1[0]) + t * t * (p3[0] - p2[0])),
|
|
68
|
+
3 * (s * s * (p1[1] - p0[1]) + 2 * s * t * (p2[1] - p1[1]) + t * t * (p3[1] - p2[1]))],
|
|
69
|
+
[6 * (s * (p2[0] - 2 * p1[0] + p0[0]) + t * (p3[0] - 2 * p2[0] + p1[0])),
|
|
70
|
+
6 * (s * (p2[1] - 2 * p1[1] + p0[1]) + t * (p3[1] - 2 * p2[1] + p1[1]))]
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Returns a point on piece `k` of `curves` close to `p` found by a few Newton
|
|
75
|
+
* iterations on the squared distance starting from parameter `t0`, as a
|
|
76
|
+
* `Foot`.
|
|
77
|
+
*
|
|
78
|
+
* * the returned distance is thus an *upper bound* on the distance from `p`
|
|
79
|
+
* to the piecewise curve (any point on the curve gives one) - it is not
|
|
80
|
+
* certified to be the minimum
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
83
|
+
*/
|
|
84
|
+
function newtonFoot(p, curves, k, t0) {
|
|
85
|
+
const ps = curves[k];
|
|
86
|
+
if (ps.length === 1) {
|
|
87
|
+
const q = ps[0];
|
|
88
|
+
return { d: sqrt((q[0] - p[0]) ** 2 + (q[1] - p[1]) ** 2), q, k, t: 0 };
|
|
89
|
+
}
|
|
90
|
+
let t = t0;
|
|
91
|
+
let [q, dq, ddq] = evalWithDerivatives(ps, t);
|
|
92
|
+
let rx = q[0] - p[0];
|
|
93
|
+
let ry = q[1] - p[1];
|
|
94
|
+
let best = { d: sqrt(rx * rx + ry * ry), q, k, t };
|
|
95
|
+
for (let i = 0; i < 4; i++) {
|
|
96
|
+
// minimize g(t) = |B(t) - p|²/2: g' = r·B', g'' = B'·B' + r·B''
|
|
97
|
+
const g1 = rx * dq[0] + ry * dq[1];
|
|
98
|
+
const g2 = dq[0] * dq[0] + dq[1] * dq[1] + rx * ddq[0] + ry * ddq[1];
|
|
99
|
+
if (g2 <= 0) {
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
let t_ = t - g1 / g2;
|
|
103
|
+
if (t_ < 0) {
|
|
104
|
+
t_ = 0;
|
|
105
|
+
}
|
|
106
|
+
else if (t_ > 1) {
|
|
107
|
+
t_ = 1;
|
|
108
|
+
}
|
|
109
|
+
if (t_ === t) {
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
t = t_;
|
|
113
|
+
[q, dq, ddq] = evalWithDerivatives(ps, t);
|
|
114
|
+
rx = q[0] - p[0];
|
|
115
|
+
ry = q[1] - p[1];
|
|
116
|
+
const d = sqrt(rx * rx + ry * ry);
|
|
117
|
+
if (d < best.d) {
|
|
118
|
+
best = { d, q, k, t };
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return best;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Returns the maximum distance from the point `q` to the control points of
|
|
125
|
+
* `ps` - an upper bound on the distance from `q` to any point on the bezier
|
|
126
|
+
* curve `ps` (which lies within the convex hull of its control points).
|
|
127
|
+
*
|
|
128
|
+
* @internal
|
|
129
|
+
*/
|
|
130
|
+
function maxDistanceToControlPoints(ps, q) {
|
|
131
|
+
let m = 0;
|
|
132
|
+
for (let i = 0; i < ps.length; i++) {
|
|
133
|
+
const c = ps[i];
|
|
134
|
+
const dd = (c[0] - q[0]) ** 2 + (c[1] - q[1]) ** 2;
|
|
135
|
+
if (dd > m) {
|
|
136
|
+
m = dd;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return sqrt(m);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Returns `true` if the one-sided Hausdorff distance from the bezier curve `A`
|
|
143
|
+
* to the piecewise bezier curve `B` exceeds `tolerance` and `false` otherwise.
|
|
144
|
+
*
|
|
145
|
+
* * this is a *decision procedure* and is thus much cheaper than computing the
|
|
146
|
+
* distance (e.g. via `hausdorffDistanceOneSided` from `flo-bezier3`) and then
|
|
147
|
+
* comparing it: it stops as soon as either a point on `A` further than
|
|
148
|
+
* `tolerance` from `B` is found (a certified *lower* bound exceeding the
|
|
149
|
+
* tolerance) or every piece of `A` is certified to be within `tolerance`
|
|
150
|
+
* (a certified *upper* bound)
|
|
151
|
+
* * `A` is bisected into parameter intervals; the upper bound on an interval
|
|
152
|
+
* `[tS,tE]` is the smaller of
|
|
153
|
+
* * `(hS + hE + L)/2` where `hS`, `hE` are (upper bounds on) the
|
|
154
|
+
* distances from its endpoints to `B` and `L` is the control polygon
|
|
155
|
+
* length of `A` restricted to the interval (an upper bound on its arc
|
|
156
|
+
* length): any point on the interval is within `L` of both endpoints so
|
|
157
|
+
* its distance to `B` is at most `min(hS + l, hE + (L - l))` with `l`
|
|
158
|
+
* the arc length from the start, maximized at `(hS + hE + L)/2`
|
|
159
|
+
* * the maximum distance from the foot (on `B`) of either endpoint to the
|
|
160
|
+
* control points of `A` restricted to the interval (the sub-curve lies
|
|
161
|
+
* within the convex hull of its control points, within which the
|
|
162
|
+
* distance to a fixed point is maximized at a vertex)
|
|
163
|
+
* * the distances from sample points on `A` to `B` are found cheaply by
|
|
164
|
+
* Newton iteration from the feet of the neighboring samples - these are upper
|
|
165
|
+
* bounds (any point on `B` gives one) which suffice for certifying the
|
|
166
|
+
* acceptance of an interval; only when such a bound exceeds the tolerance is
|
|
167
|
+
* the certified (and expensive) closest point computed to decide whether the
|
|
168
|
+
* tolerance is really exceeded
|
|
169
|
+
* * `B` need not be smooth, nor need its pieces be connected
|
|
170
|
+
* * the result is approximate only to the extent that the floating point
|
|
171
|
+
* evaluations are, i.e. a decision is only taken once it is certain up to
|
|
172
|
+
* roundoff
|
|
173
|
+
*
|
|
174
|
+
* @param A the 'from' bezier curve given by its control points
|
|
175
|
+
* @param B the 'to' piecewise bezier curve given as an array of bezier curves
|
|
176
|
+
* @param tolerance the distance to compare against
|
|
177
|
+
* @param maxIterations the maximum number of interval bisections (each
|
|
178
|
+
* costing one cheap closest point calculation) before giving up, in which
|
|
179
|
+
* case `true` is returned (the conservative answer for simplification
|
|
180
|
+
* purposes); defaults to `1000` (curves only just within tolerance may
|
|
181
|
+
* need many bisections, especially where they run nearly parallel to `B`)
|
|
182
|
+
*
|
|
183
|
+
* @internal
|
|
184
|
+
*/
|
|
185
|
+
function hausdorffDistanceOneSidedExceeds(A, B, tolerance, maxIterations = 1000) {
|
|
186
|
+
const fS = closestPointOnCurves(A[0], B);
|
|
187
|
+
if (fS.d > tolerance) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
const fE = closestPointOnCurves(A[A.length - 1], B);
|
|
191
|
+
if (fE.d > tolerance) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
if (A.length <= 2) {
|
|
195
|
+
// A point or a line: if `B` is a single line (a convex set) the
|
|
196
|
+
// distance is convex along `A` and thus maximal at an endpoint.
|
|
197
|
+
if (A.length === 1 || (B.length === 1 && B[0].length <= 2)) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
// Depth first; the stack never holds more than about `2*log2(iterations)`
|
|
202
|
+
// intervals.
|
|
203
|
+
const stack = [{ tS: 0, tE: 1, fS, fE }];
|
|
204
|
+
let iterations = 0;
|
|
205
|
+
while (stack.length > 0) {
|
|
206
|
+
const { tS, tE, fS, fE } = stack.pop();
|
|
207
|
+
const ps = tS === 0 && tE === 1 ? A : fromTo(A, tS, tE);
|
|
208
|
+
// the entire interval is certified within tolerance if either upper
|
|
209
|
+
// bound says so
|
|
210
|
+
if ((fS.d + fE.d + controlPointLinesLength(ps)) / 2 <= tolerance) {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (maxDistanceToControlPoints(ps, fS.q) <= tolerance ||
|
|
214
|
+
maxDistanceToControlPoints(ps, fE.q) <= tolerance) {
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (iterations++ >= maxIterations) {
|
|
218
|
+
return true; // undecided - be conservative
|
|
219
|
+
}
|
|
220
|
+
const tM = (tS + tE) / 2;
|
|
221
|
+
const pM = evalDeCasteljau(A, tM);
|
|
222
|
+
// a cheap upper bound on the distance from `pM` to `B` - by Newton
|
|
223
|
+
// iteration from the feet of the endpoints
|
|
224
|
+
let fM = newtonFoot(pM, B, fS.k, fS.k === fE.k ? (fS.t + fE.t) / 2 : fS.t);
|
|
225
|
+
if (fS.k !== fE.k) {
|
|
226
|
+
const fM_ = newtonFoot(pM, B, fE.k, fE.t);
|
|
227
|
+
if (fM_.d < fM.d) {
|
|
228
|
+
fM = fM_;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (fM.d > tolerance) {
|
|
232
|
+
// possibly exceeds - now get the certified closest point
|
|
233
|
+
fM = closestPointOnCurves(pM, B);
|
|
234
|
+
if (fM.d > tolerance) {
|
|
235
|
+
return true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
// push the half with the larger lower bound last so it is tried first
|
|
239
|
+
if (max(fS.d, fM.d) >= max(fM.d, fE.d)) {
|
|
240
|
+
stack.push({ tS: tM, tE, fS: fM, fE });
|
|
241
|
+
stack.push({ tS, tE: tM, fS, fE: fM });
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
stack.push({ tS, tE: tM, fS, fE: fM });
|
|
245
|
+
stack.push({ tS: tM, tE, fS: fM, fE });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
export { hausdorffDistanceOneSidedExceeds, distanceToCurves, closestPointOnCurves };
|
|
251
|
+
//# sourceMappingURL=hausdorff-distance-one-sided-exceeds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hausdorff-distance-one-sided-exceeds.js","sourceRoot":"","sources":["../../src/mat/hausdorff-distance-one-sided-exceeds.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErG,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;AAiB3B;;;;;;;;;GASG;AACH,SAAS,oBAAoB,CACrB,CAAW,EACX,MAAoB;IAExB,IAAI,IAAI,GAAS,EAAE,CAAC,EAA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
2
2
|
import type { CpNode } from '../cp-node/cp-node.js';
|
|
3
|
-
import type { Curve } from 'flo-boolean';
|
|
4
3
|
import { RbTree } from 'flo-ll-rb-tree';
|
|
5
4
|
interface MatMeta {
|
|
6
5
|
/** The minimum power of 2 such that `2**maxCoordPowerOf2 >= "the max coordinate"` */
|
|
7
6
|
readonly maxCoordPowerOf2: number;
|
|
8
7
|
readonly squaredDiagonalLength: number;
|
|
9
|
-
readonly looseBoundingBoxes: number[][][];
|
|
10
|
-
readonly tightBoundingBoxes: number[][][];
|
|
11
|
-
readonly boundingHulls: number[][][];
|
|
12
|
-
readonly sharpCorners: Curve[];
|
|
13
|
-
readonly dullCorners: Curve[];
|
|
14
8
|
readonly loops: Loop[];
|
|
15
9
|
/**
|
|
16
10
|
* Primarily for internal use. A tree structure storing the
|
|
@@ -3,14 +3,31 @@ import type { Mat } from './mat.js';
|
|
|
3
3
|
* Returns a new simplified MAT of the given one by replacing the piecewise
|
|
4
4
|
* quad beziers composing the MAT with fewer ones to within a given tolerance.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
6
|
+
* * the vertices of the simplified MAT are a subset of those of the given one
|
|
7
|
+
* (so the endpoints of each new curve are endpoints of existing ones) and all
|
|
8
|
+
* 'special' vertices (leaves, 3-prongs and higher, hole-closers) are kept
|
|
9
|
+
* * each branch is simplified Douglas-Peucker style: the single curve from the
|
|
10
|
+
* start to the end of a span of edges is tried and, if some edge deviates from
|
|
11
|
+
* it by more than the tolerance, the span is split at the vertex of worst
|
|
12
|
+
* deviation and both halves are tried in turn; this is `O(n log n)` (in the
|
|
13
|
+
* number of edges `n` of a branch) Hausdorff distance checks as opposed to the
|
|
14
|
+
* `O(n²)` of greedily extending spans one vertex at a time
|
|
15
|
+
* * the deviation of an edge from the single curve is checked first by cheap
|
|
16
|
+
* sampled *lower* bounds (which already find most splits) and only then by
|
|
17
|
+
* the certified `hausdorffDistanceOneSidedExceeds`
|
|
18
|
+
* * the tolerance is a certified upper bound on the one-sided Hausdorff
|
|
19
|
+
* distance from the original MAT curves to the simplified ones (up to
|
|
20
|
+
* floating point roundoff)
|
|
21
|
+
*
|
|
22
|
+
* @param mat the MAT to simplify (it is not modified)
|
|
23
|
+
* @param hausdorffTolerance the maximum one-sided Hausdorff distance (in
|
|
24
|
+
* coordinate units) from the original to the simplified MAT - defaults to
|
|
25
|
+
* `2**-3`
|
|
26
|
+
* @param maxIterations the max bisections of each Hausdorff distance check
|
|
27
|
+
* (see `hausdorffDistanceOneSidedExceeds`) after which the check conservatively
|
|
28
|
+
* fails (so that the span is split rather than accepted) - defaults to `1000`;
|
|
29
|
+
* lower values trade simplification quality for a bound on the time spent on
|
|
30
|
+
* curves that are only just within tolerance
|
|
14
31
|
*/
|
|
15
32
|
declare function simplifyMat(mat: Mat, hausdorffTolerance?: number, maxIterations?: number): Mat;
|
|
16
33
|
export { simplifyMat };
|
package/node/mat/simplify-mat.js
CHANGED
|
@@ -1,84 +1,213 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { evalDeCasteljau } from 'flo-bezier3';
|
|
2
2
|
import { removeVertex } from '../vertex/remove-vertex.js';
|
|
3
3
|
import { getBranches } from './get-branches.js';
|
|
4
4
|
import { getMatCurveToNext } from '../cp-node/fs/get-mat-curve-to-next.js';
|
|
5
5
|
import { getMatCurveBetween } from '../cp-node/fs/get-mat-curve-between.js';
|
|
6
6
|
import { createNewCpTrees } from './create-new-cp-trees.js';
|
|
7
7
|
import { clone } from '../cp-node/fs/clone.js';
|
|
8
|
-
import { findFirst } from '../cp-node/fs/find-first.js';
|
|
9
8
|
import { isTerminating } from '../cp-node/fs/is-terminating.js';
|
|
10
|
-
import {
|
|
9
|
+
import { isSpecial } from '../cp-node/fs/is-special.js';
|
|
11
10
|
import { getProngCount } from '../cp-node/fs/get-prong-count.js';
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
import { distanceToCurves, hausdorffDistanceOneSidedExceeds } from './hausdorff-distance-one-sided-exceeds.js';
|
|
12
|
+
const { abs } = Math;
|
|
13
|
+
/**
|
|
14
|
+
* Spans of at least this many edges whose worst vertex lies within
|
|
15
|
+
* `END_FRACTION` of either end are additionally split at their middle - this
|
|
16
|
+
* guards against the degenerate case where each split peels off only a few
|
|
17
|
+
* edges at an end (making the recursion depth, and the total work, quadratic
|
|
18
|
+
* in the branch length) at the cost of at most one extra curve per occurrence.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
const MIN_EDGES_FOR_BALANCED_SPLIT = 32;
|
|
23
|
+
/** @internal */
|
|
24
|
+
const END_FRACTION = 1 / 8;
|
|
14
25
|
/**
|
|
15
26
|
* Returns a new simplified MAT of the given one by replacing the piecewise
|
|
16
27
|
* quad beziers composing the MAT with fewer ones to within a given tolerance.
|
|
17
28
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
29
|
+
* * the vertices of the simplified MAT are a subset of those of the given one
|
|
30
|
+
* (so the endpoints of each new curve are endpoints of existing ones) and all
|
|
31
|
+
* 'special' vertices (leaves, 3-prongs and higher, hole-closers) are kept
|
|
32
|
+
* * each branch is simplified Douglas-Peucker style: the single curve from the
|
|
33
|
+
* start to the end of a span of edges is tried and, if some edge deviates from
|
|
34
|
+
* it by more than the tolerance, the span is split at the vertex of worst
|
|
35
|
+
* deviation and both halves are tried in turn; this is `O(n log n)` (in the
|
|
36
|
+
* number of edges `n` of a branch) Hausdorff distance checks as opposed to the
|
|
37
|
+
* `O(n²)` of greedily extending spans one vertex at a time
|
|
38
|
+
* * the deviation of an edge from the single curve is checked first by cheap
|
|
39
|
+
* sampled *lower* bounds (which already find most splits) and only then by
|
|
40
|
+
* the certified `hausdorffDistanceOneSidedExceeds`
|
|
41
|
+
* * the tolerance is a certified upper bound on the one-sided Hausdorff
|
|
42
|
+
* distance from the original MAT curves to the simplified ones (up to
|
|
43
|
+
* floating point roundoff)
|
|
44
|
+
*
|
|
45
|
+
* @param mat the MAT to simplify (it is not modified)
|
|
46
|
+
* @param hausdorffTolerance the maximum one-sided Hausdorff distance (in
|
|
47
|
+
* coordinate units) from the original to the simplified MAT - defaults to
|
|
48
|
+
* `2**-3`
|
|
49
|
+
* @param maxIterations the max bisections of each Hausdorff distance check
|
|
50
|
+
* (see `hausdorffDistanceOneSidedExceeds`) after which the check conservatively
|
|
51
|
+
* fails (so that the span is split rather than accepted) - defaults to `1000`;
|
|
52
|
+
* lower values trade simplification quality for a bound on the time spent on
|
|
53
|
+
* curves that are only just within tolerance
|
|
26
54
|
*/
|
|
27
|
-
function simplifyMat(mat, hausdorffTolerance = 2 ** -3, maxIterations =
|
|
55
|
+
function simplifyMat(mat, hausdorffTolerance = 2 ** -3, maxIterations = 1000) {
|
|
28
56
|
let cpNode = clone(mat.cpNode);
|
|
29
|
-
//
|
|
57
|
+
// The clone gets its own `cpTrees` (removing vertices below must not
|
|
58
|
+
// touch the trees of the given `mat`) - they are kept up to date by
|
|
59
|
+
// `removeVertex`.
|
|
60
|
+
const meta = { ...mat.meta, cpTrees: createNewCpTrees(cpNode) };
|
|
61
|
+
// Start from a leaf (which is never removed so it can be returned)
|
|
30
62
|
while (!isTerminating(cpNode)) {
|
|
31
63
|
cpNode = cpNode.next;
|
|
32
64
|
}
|
|
33
65
|
const branches = getBranches(cpNode);
|
|
34
|
-
const
|
|
66
|
+
const toRemove = [];
|
|
35
67
|
for (let k = 0; k < branches.length; k++) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
68
|
+
simplifyBranch(branches[k], hausdorffTolerance, maxIterations, toRemove);
|
|
69
|
+
}
|
|
70
|
+
for (const cpNode of toRemove) {
|
|
71
|
+
removeVertex(cpNode, meta);
|
|
72
|
+
}
|
|
73
|
+
return { cpNode, meta };
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Simplifies the given branch by adding the `CpNode`s of the vertices that
|
|
77
|
+
* can be removed to `toRemove`.
|
|
78
|
+
*
|
|
79
|
+
* * edge `k` of the branch runs from `branch[k]` to `branch[k].next`; vertex
|
|
80
|
+
* `k` (for `0 < k < branch.length`) is the interior vertex `branch[k]` between
|
|
81
|
+
* edges `k-1` and `k`
|
|
82
|
+
* * a span of edges `i..j` is simplified to the single curve from the start
|
|
83
|
+
* of edge `i` to the end of edge `j`, removing the interior vertices `i+1..j`
|
|
84
|
+
*
|
|
85
|
+
* @internal
|
|
86
|
+
*/
|
|
87
|
+
function simplifyBranch(branch, tolerance, maxIterations, toRemove) {
|
|
88
|
+
const n = branch.length; // the number of edges
|
|
89
|
+
if (n < 2) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
// the MAT curves of the edges of the branch - computed once per branch
|
|
93
|
+
const curves = branch.map(getMatCurveToNext);
|
|
94
|
+
const vertexPoints = branch.map(cpNode => cpNode.pointOnShape.circle.center);
|
|
95
|
+
// The spans still to be processed; interior vertices that cannot be
|
|
96
|
+
// removed must be kept so the branch is pre-split there: the 'special'
|
|
97
|
+
// ones (e.g. hole-closers) and those whose circle carries more than 2
|
|
98
|
+
// `CpNode`s (e.g. a 2-prong having a terminating sharp corner contact,
|
|
99
|
+
// which `getBranch` passes through but `removeVertex` cannot remove).
|
|
100
|
+
const spans = [];
|
|
101
|
+
let a = 0;
|
|
102
|
+
for (let k = 1; k < n; k++) {
|
|
103
|
+
if (isSpecial(branch[k]) || getProngCount(branch[k]) !== 2) {
|
|
104
|
+
spans.push([a, k - 1]);
|
|
105
|
+
a = k;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
spans.push([a, n - 1]);
|
|
109
|
+
while (spans.length > 0) {
|
|
110
|
+
const [i, j] = spans.pop();
|
|
111
|
+
if (j <= i) {
|
|
112
|
+
continue;
|
|
113
|
+
} // a single edge - nothing to remove
|
|
114
|
+
const longCurves = getMatCurveBetween(branch[i], branch[j].next);
|
|
115
|
+
//------------------------------------------------------------------
|
|
116
|
+
// 1. Cheap pass: sampled lower bounds on the deviation of each edge -
|
|
117
|
+
// the interior vertices and the piece midpoints.
|
|
118
|
+
//------------------------------------------------------------------
|
|
119
|
+
let worstD = 0;
|
|
120
|
+
let worstV = -1;
|
|
121
|
+
for (let k = i; k <= j; k++) {
|
|
122
|
+
if (k > i) {
|
|
123
|
+
const d = distanceToCurves(vertexPoints[k], longCurves);
|
|
124
|
+
if (d > worstD) {
|
|
125
|
+
worstD = d;
|
|
126
|
+
worstV = k;
|
|
49
127
|
}
|
|
50
|
-
|
|
51
|
-
|
|
128
|
+
}
|
|
129
|
+
const pieces = curves[k];
|
|
130
|
+
for (let m = 0; m < pieces.length; m++) {
|
|
131
|
+
const d = distanceToCurves(evalDeCasteljau(pieces[m], 0.5), longCurves);
|
|
132
|
+
if (d > worstD) {
|
|
133
|
+
worstD = d;
|
|
134
|
+
worstV = getSplitVertexForEdge(i, j, k, m, pieces.length);
|
|
52
135
|
}
|
|
53
136
|
}
|
|
54
|
-
|
|
55
|
-
|
|
137
|
+
}
|
|
138
|
+
if (worstD > tolerance) {
|
|
139
|
+
split(spans, i, j, worstV);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
//------------------------------------------------------------------
|
|
143
|
+
// 2. Certified pass - split at the first edge found to exceed the
|
|
144
|
+
// tolerance.
|
|
145
|
+
//------------------------------------------------------------------
|
|
146
|
+
let splitV = -1;
|
|
147
|
+
outer: for (let k = i; k <= j; k++) {
|
|
148
|
+
const pieces = curves[k];
|
|
149
|
+
for (let m = 0; m < pieces.length; m++) {
|
|
150
|
+
if (hausdorffDistanceOneSidedExceeds(pieces[m], longCurves, tolerance, maxIterations)) {
|
|
151
|
+
splitV = getSplitVertexForEdge(i, j, k, m, pieces.length);
|
|
152
|
+
break outer;
|
|
153
|
+
}
|
|
56
154
|
}
|
|
57
155
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
for (const cpNode of canDeletes) {
|
|
62
|
-
if (!isVertex(cpNode => (getProngCount(cpNode) !== 2) &&
|
|
63
|
-
!cpNode.isHoleClosing)(cpNode)) {
|
|
64
|
-
removeVertex(cpNode, mat.meta);
|
|
156
|
+
if (splitV !== -1) {
|
|
157
|
+
split(spans, i, j, splitV);
|
|
158
|
+
continue;
|
|
65
159
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
cpTrees: createNewCpTrees(cpNode)
|
|
160
|
+
//------------------------------------------------------------------
|
|
161
|
+
// 3. Accept the span.
|
|
162
|
+
//------------------------------------------------------------------
|
|
163
|
+
for (let k = i + 1; k <= j; k++) {
|
|
164
|
+
toRemove.push(branch[k]);
|
|
72
165
|
}
|
|
73
|
-
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Returns the vertex (in `(i,j]`) at which to split the span of edges `i..j`
|
|
170
|
+
* given that piece `m` (of `numPieces`) of edge `k` deviates too much: one of
|
|
171
|
+
* the edge's two endpoint vertices - the one on the side of the piece if the
|
|
172
|
+
* edge has 2 pieces, else the one nearer the middle of the span (for a more
|
|
173
|
+
* balanced recursion).
|
|
174
|
+
*
|
|
175
|
+
* @internal
|
|
176
|
+
*/
|
|
177
|
+
function getSplitVertexForEdge(i, j, k, m, numPieces) {
|
|
178
|
+
const canUseStart = k > i;
|
|
179
|
+
const canUseEnd = k + 1 <= j;
|
|
180
|
+
if (!canUseStart) {
|
|
181
|
+
return k + 1;
|
|
182
|
+
}
|
|
183
|
+
if (!canUseEnd) {
|
|
184
|
+
return k;
|
|
185
|
+
}
|
|
186
|
+
if (numPieces === 2) {
|
|
187
|
+
return m === 0 ? k : k + 1;
|
|
188
|
+
}
|
|
189
|
+
const mid = (i + 1 + j) / 2; // middle of the interior vertices `i+1..j`
|
|
190
|
+
return abs(k - mid) <= abs(k + 1 - mid) ? k : k + 1;
|
|
74
191
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Splits the span of edges `i..j` at the vertex `v` (in `(i,j]`) and pushes
|
|
194
|
+
* the resulting spans (for very long spans with `v` near an end also split at
|
|
195
|
+
* the middle - see `MIN_EDGES_FOR_BALANCED_SPLIT`).
|
|
196
|
+
*
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
199
|
+
function split(spans, i, j, v) {
|
|
200
|
+
const numEdges = j - i + 1;
|
|
201
|
+
if (numEdges >= MIN_EDGES_FOR_BALANCED_SPLIT) {
|
|
202
|
+
const margin = numEdges * END_FRACTION;
|
|
203
|
+
if (v - i < margin || j + 1 - v < margin) {
|
|
204
|
+
const vMid = (i + j + 1) >>> 1; // an interior vertex near the middle
|
|
205
|
+
const [v1, v2] = v < vMid ? [v, vMid] : [vMid, v];
|
|
206
|
+
spans.push([v2, j], [v1, v2 - 1], [i, v1 - 1]);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
80
209
|
}
|
|
81
|
-
|
|
210
|
+
spans.push([v, j], [i, v - 1]);
|
|
82
211
|
}
|
|
83
212
|
export { simplifyMat };
|
|
84
213
|
//# sourceMappingURL=simplify-mat.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simplify-mat.js","sourceRoot":"","sources":["../../src/mat/simplify-mat.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"simplify-mat.js","sourceRoot":"","sources":["../../src/mat/simplify-mat.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4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QACrC,IAAI,CAAC,GAAG,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC;YACvC,MAAM,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,qCAAqC;YACtE,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;YAClD,KAAK,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,GAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,GAAC,CAAC,CAAC,CAAC,CAAC;YAC3C,OAAO;QACX,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAC,CAAC,CAAC,CAAC,CAAC;AACjC,CAAC;AAGD,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
package/node/mat/trim-mat.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ import type { Mat } from './mat.js';
|
|
|
3
3
|
* Trims the given Medial Axis Transform so that only cycles remain. Similar to
|
|
4
4
|
* toScaleAxis(mat, Infinity).
|
|
5
5
|
*
|
|
6
|
-
*
|
|
6
|
+
* * returns `undefined` if the MAT has no cycles (i.e. the shape has no holes)
|
|
7
|
+
*
|
|
8
|
+
* @param mat The MAT to trim (it is not modified).
|
|
7
9
|
*/
|
|
8
|
-
declare function trimMat(mat: Mat): Mat;
|
|
10
|
+
declare function trimMat(mat: Mat): Mat | undefined;
|
|
9
11
|
export { trimMat };
|
package/node/mat/trim-mat.js
CHANGED
|
@@ -5,7 +5,9 @@ import { clone } from '../cp-node/fs/clone.js';
|
|
|
5
5
|
* Trims the given Medial Axis Transform so that only cycles remain. Similar to
|
|
6
6
|
* toScaleAxis(mat, Infinity).
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* * returns `undefined` if the MAT has no cycles (i.e. the shape has no holes)
|
|
9
|
+
*
|
|
10
|
+
* @param mat The MAT to trim (it is not modified).
|
|
9
11
|
*/
|
|
10
12
|
function trimMat(mat) {
|
|
11
13
|
// FUTURE - clone entire `Mat` instead (the function already exists)
|