flo-mat 4.0.2 → 4.1.0
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__/find-2-prong/get-medial/dd-get-medial-point-coeffs-same-curve.spec.ts +106 -0
- package/__tests__/find-2-prong/get-medial/dd-get-medial-point-coeffs.spec.ts +73 -0
- package/__tests__/find-2-prong/get-medial/get-closest-points.spec.ts +5 -2
- package/__tests__/helpers/close-to.ts +5 -5
- package/__tests__/specific-cases/load-svg/load-svg.ts +30 -0
- package/__tests__/specific-cases/specific-cases.spec.ts +170 -0
- package/__tests__/specific-cases/test-svgs/achispado.svg +5052 -0
- package/browser/index.js +5129 -8785
- package/browser/index.min.js +1 -1
- package/{jest.config.cjs → jest.config.ts} +8 -3
- package/node/closest-boundary-point/get-close-boundary-points-certified.js +3 -2
- package/node/closest-boundary-point/get-close-boundary-points-certified.js.map +1 -1
- package/node/corner/get-corner.js +1 -1
- package/node/corner/get-corner.js.map +1 -1
- package/node/cp-node/fs/get-all-on-loop-by-loop.d.ts +11 -0
- package/node/cp-node/fs/get-all-on-loop-by-loop.js +42 -0
- package/node/cp-node/fs/get-all-on-loop-by-loop.js.map +1 -0
- package/node/cp-node/fs/get-boundary-beziers-to-next.d.ts +1 -0
- package/node/cp-node/fs/get-boundary-beziers-to-next.js +1 -59
- package/node/cp-node/fs/get-boundary-beziers-to-next.js.map +1 -1
- package/node/cp-node/fs/get-edge-direction.d.ts +3 -1
- package/node/cp-node/fs/get-edge-direction.js +5 -3
- package/node/cp-node/fs/get-edge-direction.js.map +1 -1
- package/node/cp-node/fs/get-mat-curve-between.js +6 -6
- package/node/cp-node/fs/get-mat-curve-between.js.map +1 -1
- package/node/cp-node/fs/is-fully-terminating.js +12 -0
- package/node/cp-node/fs/is-fully-terminating.js.map +1 -1
- package/node/cp-node/fs/is-on-same-loop.d.ts +3 -0
- package/node/cp-node/fs/is-on-same-loop.js +6 -0
- package/node/cp-node/fs/is-on-same-loop.js.map +1 -0
- package/node/debug/debug.d.ts +8 -22
- package/node/debug/debug.js +12 -50
- package/node/debug/debug.js.map +1 -1
- package/node/find-2-prong/add-1-prong.js +1 -4
- package/node/find-2-prong/add-1-prong.js.map +1 -1
- package/node/find-2-prong/find-2-prong.js +24 -10
- package/node/find-2-prong/find-2-prong.js.map +1 -1
- package/node/find-2-prong/get-medial/get-antipodal-points.d.ts +1 -1
- package/node/find-2-prong/get-medial/get-antipodal-points.js +2 -2
- 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 +7 -1
- package/node/find-2-prong/get-medial/get-closest-points.js +60 -14
- package/node/find-2-prong/get-medial/get-closest-points.js.map +1 -1
- package/node/find-2-prong/reduce-radius.d.ts +3 -1
- package/node/find-2-prong/reduce-radius.js +8 -6
- package/node/find-2-prong/reduce-radius.js.map +1 -1
- package/node/find-3-prong/calc-better-x.js +1 -3
- package/node/find-3-prong/calc-better-x.js.map +1 -1
- package/node/find-3-prong/calc-initial-3-prong-center.js +1 -2
- package/node/find-3-prong/calc-initial-3-prong-center.js.map +1 -1
- package/node/find-3-prong/find-3-prong-for-delta3s.js +1 -4
- package/node/find-3-prong/find-3-prong-for-delta3s.js.map +1 -1
- package/node/find-3-prong/find-3-prong.js.map +1 -1
- package/node/find-3-prong/find-and-add-3-prong.js +0 -14
- package/node/find-3-prong/find-and-add-3-prong.js.map +1 -1
- package/node/find-mat/find-mat.js +2 -2
- package/node/find-mat/find-mat.js.map +1 -1
- package/node/find-mat/find-mats.js.map +1 -1
- package/node/find-mat/get-dull-corners-on-loop.js +3 -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 +6 -3
- package/node/find-mat/get-for-1-prongs-on-loop.js.map +1 -1
- package/node/find-mat/get-for-2-prongs-on-loop.js +5 -1
- package/node/find-mat/get-for-2-prongs-on-loop.js.map +1 -1
- package/node/find-mat/get-meta.d.ts +4 -6
- package/node/find-mat/get-meta.js +12 -26
- package/node/find-mat/get-meta.js.map +1 -1
- package/node/find-mat/get-sharp-corners.js +4 -2
- package/node/find-mat/get-sharp-corners.js.map +1 -1
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.d.ts +21 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.js +46 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.js.map +1 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.d.ts +28 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.js +97 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.js.map +1 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.d.ts +28 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.js +109 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.js.map +1 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.d.ts +29 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.js +123 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.js.map +1 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.d.ts +30 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.js +177 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.js.map +1 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.d.ts +29 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js +156 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.js.map +1 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.d.ts +28 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.js +40 -0
- package/node/get-medial-points/double-double/dd-get-medial-point-coeffs.js.map +1 -0
- package/node/index.d.ts +6 -10
- package/node/index.js +5 -6
- package/node/index.js.map +1 -1
- package/node/point-on-shape/point-on-shape.d.ts +2 -0
- package/node/point-on-shape/to-p.d.ts +1 -1
- package/node/point-on-shape/to-p.js +1 -1
- package/node/point-on-shape/to-p.js.map +1 -1
- package/node/reconstruct-from-mat/get-cp-nodess-for-sat.d.ts +4 -0
- package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js +15 -0
- package/node/reconstruct-from-mat/get-cp-nodess-for-sat.js.map +1 -0
- package/node/reconstruct-from-mat/reconstruct-from-mat.d.ts +10 -0
- package/node/reconstruct-from-mat/reconstruct-from-mat.js +160 -0
- package/node/reconstruct-from-mat/reconstruct-from-mat.js.map +1 -0
- package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.d.ts +12 -0
- package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js +46 -0
- package/node/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.js.map +1 -0
- package/node/sat/add-debug-info.js +1 -2
- package/node/sat/add-debug-info.js.map +1 -1
- package/node/svg/get-loop-bounds.js +6 -2
- package/node/svg/get-loop-bounds.js.map +1 -1
- package/node/utils/map-deep.d.ts +15 -0
- package/node/utils/map-deep.js +34 -0
- package/node/utils/map-deep.js.map +1 -0
- package/package.json +14 -8
- package/src/closest-boundary-point/get-close-boundary-points-certified.ts +3 -2
- package/src/corner/get-corner.ts +1 -1
- package/src/cp-node/fs/get-all-on-loop-by-loop.ts +56 -0
- package/src/cp-node/fs/get-all-on-loop.ts +1 -1
- package/src/cp-node/fs/get-boundary-beziers-to-next.ts +1 -72
- package/src/cp-node/fs/get-edge-direction.ts +8 -4
- package/src/cp-node/fs/get-mat-curve-between.ts +6 -6
- package/src/cp-node/fs/is-fully-terminating.ts +16 -0
- package/src/cp-node/fs/is-on-same-loop.ts +15 -0
- package/src/debug/debug.ts +27 -87
- package/src/find-2-prong/add-1-prong.ts +1 -5
- package/src/find-2-prong/find-2-prong.ts +37 -14
- package/src/find-2-prong/get-medial/get-antipodal-points.ts +3 -2
- package/src/find-2-prong/get-medial/get-closest-points-d.ts +213 -0
- package/src/find-2-prong/get-medial/get-closest-points.ts +74 -13
- package/src/find-2-prong/reduce-radius.ts +8 -5
- package/src/find-3-prong/calc-better-x.ts +1 -3
- package/src/find-3-prong/calc-initial-3-prong-center.ts +1 -2
- package/src/find-3-prong/find-3-prong-for-delta3s.ts +1 -4
- package/src/find-3-prong/find-3-prong.ts +0 -1
- package/src/find-3-prong/find-and-add-3-prong.ts +1 -15
- package/src/find-mat/find-mat.ts +3 -2
- package/src/find-mat/find-mats.ts +0 -1
- package/src/find-mat/get-dull-corners-on-loop.ts +4 -3
- package/src/find-mat/get-for-1-prongs-on-loop.ts +8 -3
- package/src/find-mat/get-for-2-prongs-on-loop.ts +6 -1
- package/src/find-mat/get-meta.ts +14 -38
- package/src/find-mat/get-sharp-corners.ts +5 -1
- package/src/get-medial-curve/__pycache__/get-cubic-self-medial-curve.cpython-313.pyc +0 -0
- package/src/get-medial-curve/get-cubic-self-medial-curve.py +419 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0-with-running-err.ts +76 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez0.ts +61 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez1.ts +116 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2-same-curve.ts +129 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez2.ts +142 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3-same-curve.ts +199 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs-bez3.ts +177 -0
- package/src/get-medial-points/double-double/dd-get-medial-point-coeffs.ts +48 -0
- package/src/get-medial-points/double-double/error-bound-calc.txt +72 -0
- package/src/index.ts +7 -11
- package/src/point-on-shape/point-on-shape.ts +3 -0
- package/src/point-on-shape/to-p.ts +2 -2
- package/src/reconstruct-from-mat/get-cp-nodess-for-sat.ts +24 -0
- package/src/reconstruct-from-mat/reconstruct-from-mat.ts +226 -0
- package/src/reconstruct-from-mat/remove-sat-induced-trivial-3prongs.ts +62 -0
- package/src/sat/add-debug-info.ts +1 -2
- package/src/svg/get-loop-bounds.ts +11 -3
- package/src/utils/clip.ts +13 -0
- package/src/utils/map-deep.ts +75 -0
- package/src/utils/map-map.ts +33 -0
- package/wallaby.mjs +4 -4
- package/node/debug/debug-elem-types.d.ts +0 -26
- package/node/debug/debug-elem-types.js +0 -22
- package/node/debug/debug-elem-types.js.map +0 -1
- package/node/debug/functions/draw/draw-beziers-as-single-path.d.ts +0 -2
- package/node/debug/functions/draw/draw-beziers-as-single-path.js +0 -30
- package/node/debug/functions/draw/draw-beziers-as-single-path.js.map +0 -1
- package/node/debug/functions/draw/xmlns.d.ts +0 -2
- package/node/debug/functions/draw/xmlns.js +0 -3
- package/node/debug/functions/draw/xmlns.js.map +0 -1
- package/node/debug/functions/draw-elem/bounding-hull.d.ts +0 -3
- package/node/debug/functions/draw-elem/bounding-hull.js +0 -8
- package/node/debug/functions/draw-elem/bounding-hull.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-branch.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-branch.js +0 -26
- package/node/debug/functions/draw-elem/draw-branch.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-circle-percent.d.ts +0 -3
- package/node/debug/functions/draw-elem/draw-circle-percent.js +0 -13
- package/node/debug/functions/draw-elem/draw-circle-percent.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-cp-node.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-cp-node.js +0 -26
- package/node/debug/functions/draw-elem/draw-cp-node.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-cull.d.ts +0 -3
- package/node/debug/functions/draw-elem/draw-cull.js +0 -9
- package/node/debug/functions/draw-elem/draw-cull.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-dull-corner.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-dull-corner.js +0 -10
- package/node/debug/functions/draw-elem/draw-dull-corner.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-elem.d.ts +0 -10
- package/node/debug/functions/draw-elem/draw-elem.js +0 -39
- package/node/debug/functions/draw-elem/draw-elem.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-leaves.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-leaves.js +0 -34
- package/node/debug/functions/draw-elem/draw-leaves.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-loop.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-loop.js +0 -11
- package/node/debug/functions/draw-elem/draw-loop.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-loops.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-loops.js +0 -6
- package/node/debug/functions/draw-elem/draw-loops.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-loose-bounding-box.d.ts +0 -3
- package/node/debug/functions/draw-elem/draw-loose-bounding-box.js +0 -10
- package/node/debug/functions/draw-elem/draw-loose-bounding-box.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-mat.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-mat.js +0 -34
- package/node/debug/functions/draw-elem/draw-mat.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-max-vertex.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-max-vertex.js +0 -9
- package/node/debug/functions/draw-elem/draw-max-vertex.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-min-y.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-min-y.js +0 -10
- package/node/debug/functions/draw-elem/draw-min-y.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js +0 -22
- package/node/debug/functions/draw-elem/draw-one-prong-at-dull-corner.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-one-prong.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-one-prong.js +0 -13
- package/node/debug/functions/draw-elem/draw-one-prong.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-sharp-corner.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-sharp-corner.js +0 -10
- package/node/debug/functions/draw-elem/draw-sharp-corner.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-three-prong.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-three-prong.js +0 -26
- package/node/debug/functions/draw-elem/draw-three-prong.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-tight-bounding-box.d.ts +0 -3
- package/node/debug/functions/draw-elem/draw-tight-bounding-box.js +0 -8
- package/node/debug/functions/draw-elem/draw-tight-bounding-box.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-two-prong.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-two-prong.js +0 -49
- package/node/debug/functions/draw-elem/draw-two-prong.js.map +0 -1
- package/node/debug/functions/draw-elem/draw-vertex.d.ts +0 -4
- package/node/debug/functions/draw-elem/draw-vertex.js +0 -13
- package/node/debug/functions/draw-elem/draw-vertex.js.map +0 -1
- package/node/debug/functions/general.d.ts +0 -48
- package/node/debug/functions/general.js +0 -53
- package/node/debug/functions/general.js.map +0 -1
- package/node/find-3-prong/timed-cc.d.ts +0 -3
- package/node/find-3-prong/timed-cc.js +0 -5
- package/node/find-3-prong/timed-cc.js.map +0 -1
- package/node/point-on-shape/pos-to-human-string.d.ts +0 -8
- package/node/point-on-shape/pos-to-human-string.js +0 -12
- package/node/point-on-shape/pos-to-human-string.js.map +0 -1
- package/node/utils/time-function-call.d.ts +0 -14
- package/node/utils/time-function-call.js +0 -32
- package/node/utils/time-function-call.js.map +0 -1
- package/src/debug/debug-elem-types.ts +0 -43
- package/src/debug/elem-type-two-prong.ts +0 -8
- package/src/debug/functions/cmp-cp-on-delta.ts +0 -54
- package/src/debug/functions/draw-elem/bounding-hull.ts +0 -18
- package/src/debug/functions/draw-elem/culls.ts +0 -39
- package/src/debug/functions/draw-elem/draw-branch.ts +0 -37
- package/src/debug/functions/draw-elem/draw-circle-percent.ts +0 -23
- package/src/debug/functions/draw-elem/draw-cp-node.ts +0 -46
- package/src/debug/functions/draw-elem/draw-cull.ts +0 -21
- package/src/debug/functions/draw-elem/draw-dull-corner.ts +0 -21
- package/src/debug/functions/draw-elem/draw-elem.ts +0 -64
- package/src/debug/functions/draw-elem/draw-leaves.ts +0 -51
- package/src/debug/functions/draw-elem/draw-loop.ts +0 -16
- package/src/debug/functions/draw-elem/draw-loops.ts +0 -10
- package/src/debug/functions/draw-elem/draw-loose-bounding-box.ts +0 -21
- package/src/debug/functions/draw-elem/draw-mat.ts +0 -43
- package/src/debug/functions/draw-elem/draw-max-vertex.ts +0 -15
- package/src/debug/functions/draw-elem/draw-min-y.ts +0 -18
- package/src/debug/functions/draw-elem/draw-one-prong-at-dull-corner.ts +0 -40
- package/src/debug/functions/draw-elem/draw-one-prong.ts +0 -25
- package/src/debug/functions/draw-elem/draw-sharp-corner.ts +0 -21
- package/src/debug/functions/draw-elem/draw-three-prong.ts +0 -44
- package/src/debug/functions/draw-elem/draw-tight-bounding-box.ts +0 -18
- package/src/debug/functions/draw-elem/draw-two-prong.ts +0 -68
- package/src/debug/functions/draw-elem/draw-vertex.ts +0 -27
- package/src/debug/functions/draw-elem/dull-corner.ts +0 -21
- package/src/debug/functions/draw-elem/leaves.ts +0 -20
- package/src/debug/functions/draw-elem/loop.ts +0 -16
- package/src/debug/functions/draw-elem/loops.ts +0 -10
- package/src/debug/functions/draw-elem/loose-bounding-box.ts +0 -21
- package/src/debug/functions/draw-elem/mat.ts +0 -47
- package/src/debug/functions/draw-elem/max-vertex.ts +0 -15
- package/src/debug/functions/draw-elem/min-y.ts +0 -18
- package/src/debug/functions/draw-elem/one-prong-at-dull-corner.ts +0 -26
- package/src/debug/functions/draw-elem/one-prong.ts +0 -23
- package/src/debug/functions/draw-elem/sharp-corner.ts +0 -20
- package/src/debug/functions/draw-elem/three-prong.ts +0 -30
- package/src/debug/functions/draw-elem/tight-bounding-box.ts +0 -18
- package/src/debug/functions/draw-elem/two-prong.ts +0 -50
- package/src/debug/functions/draw-elem/vertex.ts +0 -51
- package/src/debug/functions/general.ts +0 -79
- package/src/debug/functions/three-prong.ts +0 -249
- package/src/debug/functions/two-prong.ts +0 -203
- package/src/find-2-prong/add-debug-info.ts +0 -45
- package/src/find-3-prong/timed-cc.ts +0 -9
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
|
|
2
|
+
//--------------------------------------------------------------------------
|
|
3
|
+
// `var` -> a variable
|
|
4
|
+
// `$var` -> the double precision approximation to `var`
|
|
5
|
+
// `_var` -> the absolute value of $var (a prefix underscore on a variable means absolute value)
|
|
6
|
+
// `var_` -> the error in var (a postfix underscore means error bound but should still be multiplied by 3*γ²)
|
|
7
|
+
// `_var_` -> means both absolute value and absolute error bound
|
|
8
|
+
// recall: `a*b`, where both `a` and `b` have errors |a| and |b| we get for the
|
|
9
|
+
// * error bound of (a*b) === a_|b| + |a|b_ + |a*b| (when either of a and b is double)
|
|
10
|
+
// * error bound of (a*b) === a_|b| + |a|b_ + 2|a*b| (when both a and b is double-double)
|
|
11
|
+
// * error bound of (a+b) === a_ + b_ + |a+b| (when a and/or b is double or double-double)
|
|
12
|
+
// * the returned errors need to be multiplied by 3γ² to get the true error
|
|
13
|
+
// * can use either `$var` or `var[var.length-1]` (the approx value) in error calculations
|
|
14
|
+
// due to multiplication by 3*γ² and not 3*u²
|
|
15
|
+
//--------------------------------------------------------------------------
|
|
16
|
+
// examples: (all?)
|
|
17
|
+
// ----------------
|
|
18
|
+
// let qmd === ddMultDouble2, etc.
|
|
19
|
+
//
|
|
20
|
+
// ---------------
|
|
21
|
+
// 1. double-double X by double
|
|
22
|
+
// ---------------
|
|
23
|
+
// qmd(a,b); // both `a` and `b` is error-free
|
|
24
|
+
// use: error bound of (a*b) === a_|b| + |a|b_ + |a*b| (by definition)
|
|
25
|
+
// === 0|b| + |a|0 + |a*b|
|
|
26
|
+
// === |a*b|
|
|
27
|
+
//
|
|
28
|
+
// ---------------
|
|
29
|
+
// 2a. double-double +/- double-double
|
|
30
|
+
// ---------------
|
|
31
|
+
// qdq(a,b); // error in a === |a|, thus call the error _a_, same with b
|
|
32
|
+
// use: error bound of (a+b) === a_ + b_ + |a+b| (by definition)
|
|
33
|
+
// === _a_ + _b_ + |a+b|
|
|
34
|
+
//
|
|
35
|
+
// ---------------
|
|
36
|
+
// 2b. double-double +/- double-double
|
|
37
|
+
// ---------------
|
|
38
|
+
// qaq(a,b); // error in a === 2|a|, thus the error is 2*_a, same with b
|
|
39
|
+
// use: error bound of (a+b) === a_ + b_ + |a+b| (by definition)
|
|
40
|
+
// === 2*_a + 2*_b + |a+b|
|
|
41
|
+
// === 2*(_a + _b) + |a+b| OR
|
|
42
|
+
// === a_ + b_ + |a+b|
|
|
43
|
+
//
|
|
44
|
+
// ---------------
|
|
45
|
+
// 3a. double-double X double-double
|
|
46
|
+
// ---------------
|
|
47
|
+
// qmq(a,b); // both `a` and `b` error-free
|
|
48
|
+
// use: error bound of (a*b) === a_|b| + |a|b_ + |a*b| (by definition)
|
|
49
|
+
// === 0|b| + |a|0 + 2|a*b|
|
|
50
|
+
// === 2|a*b|
|
|
51
|
+
//
|
|
52
|
+
// ---------------
|
|
53
|
+
// 3b. double-double X double-double
|
|
54
|
+
// ---------------
|
|
55
|
+
// qmq(a,b); // both `a` and `b` not error-free
|
|
56
|
+
// use: error bound of (a*b) === a_|b| + |a|b_ + 2|a*b| (by definition)
|
|
57
|
+
//
|
|
58
|
+
// ---------------
|
|
59
|
+
// 3b. double-double X double-double
|
|
60
|
+
// ---------------
|
|
61
|
+
// qmq(a,b); // both `a` not error-free and `b` error-free
|
|
62
|
+
// use: error bound of (a*b) === a_|b| + |a|b_ + 2|a*b| (by definition)
|
|
63
|
+
// === a_|b| + 2|a*b|
|
|
64
|
+
//
|
|
65
|
+
// ---------------
|
|
66
|
+
// 4a. double-double +/- double
|
|
67
|
+
// ---------------
|
|
68
|
+
// qad(a,b); // both `a` and `b` error-free
|
|
69
|
+
// use: error bound of (a+b) === a_ + b_ + |a+b| (by definition)
|
|
70
|
+
// === 0 + 0 + |a+b|
|
|
71
|
+
// === |a+b|
|
|
72
|
+
//--------------------------------------------------------------------------
|
package/src/index.ts
CHANGED
|
@@ -7,14 +7,10 @@ export type { CpNode } from './cp-node/cp-node.js';
|
|
|
7
7
|
export type { PointOnShape } from './point-on-shape/point-on-shape.js';
|
|
8
8
|
export type { Circle } from './geometry/circle.js';
|
|
9
9
|
export type { CurvePiece } from './mat/curve-piece.js';
|
|
10
|
-
export type {
|
|
11
|
-
export type { ITiming } from './debug/debug.js';
|
|
12
|
-
export type { DebugElems } from './debug/debug-elem-types.js';
|
|
10
|
+
export type { Timing } from './debug/debug.js';
|
|
13
11
|
export type { Debug } from './debug/debug.js';
|
|
14
|
-
export type { DebugElemKey } from './debug/debug-elem-types.js';
|
|
15
12
|
export type { MatOptions } from './find-mat/mat-options.js';
|
|
16
13
|
|
|
17
|
-
export { drawBeziersAsSinglePath } from './debug/functions/draw/draw-beziers-as-single-path.js';
|
|
18
14
|
export { floydWarshall } from './floyd-warshall/floyd-warshall.js';
|
|
19
15
|
export { CpNodeFs } from './cp-node/cp-node-fs.js';
|
|
20
16
|
export { isVertexSpecial } from './cp-node/fs/is-vertex-special.js';
|
|
@@ -23,13 +19,9 @@ export { trimMat } from './mat/trim-mat.js';
|
|
|
23
19
|
export { toScaleAxis } from './sat/to-scale-axis.js';
|
|
24
20
|
export { getBranches } from './mat/get-branches.js';
|
|
25
21
|
export { enableDebugForMat } from './debug/debug.js';
|
|
26
|
-
export { drawBranch } from './debug/functions/draw-elem/draw-branch.js';
|
|
27
|
-
export { drawMat } from './debug/functions/draw-elem/draw-mat.js';
|
|
28
|
-
export { debugElemNames, emptyDebugElems } from './debug/debug-elem-types.js';
|
|
29
22
|
export { getShapeBounds } from './svg/get-shape-bounds.js';
|
|
30
23
|
export { getBoundaryPieceBeziers } from './mat/get-boundary-piece-beziers.js';
|
|
31
24
|
export { simplifyMat } from './mat/simplify-mat.js';
|
|
32
|
-
export { drawElemFs, drawElemFsDetailed } from './debug/functions/draw-elem/draw-elem.js';
|
|
33
25
|
export { sweepLine } from './sweep-line/sweep-line.js';
|
|
34
26
|
export { getClosestSquareDistanceToRect } from './geometry/get-closest-square-distance-to-rect.js';
|
|
35
27
|
export { getImpliedBoundaryBezierBetween } from './cp-node/fs/get-implied-boundary-bezier-between.js';
|
|
@@ -41,8 +33,10 @@ export { getSharpCornersOnLoop } from './find-mat/get-sharp-corners.js';
|
|
|
41
33
|
export { getFor2ProngsOnLoop } from './find-mat/get-for-2-prongs-on-loop.js';
|
|
42
34
|
export { getPotentialClosestPointsOnCurveCertified } from './closest-boundary-point/get-potential-closest-points-on-curve-certified.js';
|
|
43
35
|
export { getCloseBoundaryPointsCertified } from './closest-boundary-point/get-close-boundary-points-certified.js';
|
|
44
|
-
export { getPartialMeta
|
|
36
|
+
export { getPartialMeta } from './find-mat/get-meta.js';
|
|
45
37
|
export { findAndAddHoleClosing2Prongs } from './find-2-prong/find-and-add-hole-closing-2-prongs.js';
|
|
38
|
+
export { reconstructFromMats } from './reconstruct-from-mat/reconstruct-from-mat.js';
|
|
39
|
+
export { getOsculatingCircle } from './point-on-shape/get-osculating-circle.js';
|
|
46
40
|
|
|
47
41
|
|
|
48
42
|
// CpNodeFs functions
|
|
@@ -80,4 +74,6 @@ export { getHoleClosers } from './cp-node/fs/get-hole-closers.js';
|
|
|
80
74
|
export { getInitialDegAngleBetweenMatCurves } from './cp-node/fs/get-angle-between-mat-curves.js';
|
|
81
75
|
export { getAllVertices } from './cp-node/fs/get-all-vertices.js';
|
|
82
76
|
export { isTrivial } from './cp-node/fs/is-trivial.js';
|
|
83
|
-
export { scaleCircle } from './geometry/circle.js';
|
|
77
|
+
export { scaleCircle } from './geometry/circle.js';
|
|
78
|
+
export { isOnSameLoop } from './cp-node/fs/is-on-same-loop.js';
|
|
79
|
+
export { getAllOnLoop_ByLoop } from './cp-node/fs/get-all-on-loop-by-loop.js';
|
|
@@ -10,9 +10,9 @@ import { evalDeCasteljauDd } from "flo-bezier3";
|
|
|
10
10
|
*/
|
|
11
11
|
function toP(
|
|
12
12
|
ps: number[][],
|
|
13
|
-
t: number): number[] {
|
|
13
|
+
t: number): number[][] {
|
|
14
14
|
|
|
15
|
-
return evalDeCasteljauDd(ps, [0,t])
|
|
15
|
+
return evalDeCasteljauDd(ps, [0,t]);
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CpNode } from "../cp-node/cp-node.js";
|
|
2
|
+
import type { Mat } from '../mat/mat.js';
|
|
3
|
+
import { isOnSameLoop } from "../cp-node/fs/is-on-same-loop.js";
|
|
4
|
+
import { getAllOnLoop_ByLoop } from "../cp-node/fs/get-all-on-loop-by-loop.js";
|
|
5
|
+
import { isFullyTerminating } from "../cp-node/fs/is-fully-terminating.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
function getCpNodessForSat(
|
|
9
|
+
sat: Mat): CpNode[][] {
|
|
10
|
+
|
|
11
|
+
let { cpNode } = sat;
|
|
12
|
+
|
|
13
|
+
while (!isFullyTerminating(cpNode)) {
|
|
14
|
+
cpNode = cpNode.next;
|
|
15
|
+
}
|
|
16
|
+
if (!isOnSameLoop(cpNode, cpNode.next)) {
|
|
17
|
+
cpNode = cpNode.holeCloserTwin!;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return getAllOnLoop_ByLoop(cpNode);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
export { getCpNodessForSat }
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import type { BezierPiece } from 'flo-bezier3';
|
|
2
|
+
import type { Mat } from '../mat/mat.js';
|
|
3
|
+
import type { CpNode } from '../cp-node/cp-node.js';
|
|
4
|
+
import {
|
|
5
|
+
toUnitVector, distanceBetween, fromTo as fromToVec, dot, rotate90Degrees,
|
|
6
|
+
cross, interpolate, translate, lineLineIntersection
|
|
7
|
+
} from 'flo-vector2d';
|
|
8
|
+
import { tangent as getTangent } from 'flo-bezier3';
|
|
9
|
+
import { mapDeep } from '../utils/map-deep.js';
|
|
10
|
+
import { removeSatInducedTrivial3Prongs } from './remove-sat-induced-trivial-3prongs.js';
|
|
11
|
+
import { getCpNodessForSat } from './get-cp-nodess-for-sat.js';
|
|
12
|
+
import { getRealProngCount } from '../cp-node/fs/get-real-prong-count.js';
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
const { max, abs, round, log2 } = Math;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
// let ii = 0;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* * used for debugging only
|
|
23
|
+
*
|
|
24
|
+
* @param mats
|
|
25
|
+
*
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
function reconstructFromMats(
|
|
29
|
+
mats: Mat[],
|
|
30
|
+
minNumAccurateBits: number | undefined = undefined) {
|
|
31
|
+
|
|
32
|
+
const maxPO2 = max(...mats.map(mat => mat.meta.maxCoordPowerOf2));
|
|
33
|
+
const recoverBoundary_ = recoverBoundary(maxPO2, minNumAccurateBits);
|
|
34
|
+
|
|
35
|
+
// Really only required if getSats was called on the `Mat`s
|
|
36
|
+
const cpNodessPerSat = mats
|
|
37
|
+
.map(removeSatInducedTrivial3Prongs)
|
|
38
|
+
.map(getCpNodessForSat);
|
|
39
|
+
|
|
40
|
+
const r = mapDeep(3, cpNodessPerSat, recoverBoundary_, true);
|
|
41
|
+
// ii;//?
|
|
42
|
+
|
|
43
|
+
return r;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
const FROM = 0;
|
|
48
|
+
const TO = 1;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
*
|
|
52
|
+
* @param cpNode
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
function recoverBoundary(
|
|
57
|
+
maxPO2: number,
|
|
58
|
+
minNumAccurateBits: number | undefined) {
|
|
59
|
+
|
|
60
|
+
return function (cpNode: CpNode) {
|
|
61
|
+
const cpNode_ = cpNode.next;
|
|
62
|
+
|
|
63
|
+
const pos = cpNode.pointOnShape;
|
|
64
|
+
const pos_ = cpNode_.pointOnShape;
|
|
65
|
+
|
|
66
|
+
const { curve, circle, p } = pos;
|
|
67
|
+
const { curve: curve_, p: p_ } = pos_;
|
|
68
|
+
|
|
69
|
+
if (p[0] === p_[0] && p[1] === p_[1]) {
|
|
70
|
+
return undefined;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (curve.loop !== curve_.loop) {
|
|
74
|
+
// It is a hole-closer going over to the other loop
|
|
75
|
+
// return undefined;
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const d = distanceBetween(circle.center, p);
|
|
80
|
+
|
|
81
|
+
if (getRealProngCount(cpNode)) {
|
|
82
|
+
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// DON'T remove these - they tell us the accuracy of the algorithm
|
|
86
|
+
// if (!closeTo(2**34)(circle.radius, d) && getRealProngCount(cpNode) === 3) {
|
|
87
|
+
// ii++;
|
|
88
|
+
// circle.center;//?
|
|
89
|
+
// circle.radius;//?
|
|
90
|
+
// d; //?
|
|
91
|
+
// p;//?
|
|
92
|
+
// pos.isSource;//?
|
|
93
|
+
// getRealProngCount(cpNode);//?
|
|
94
|
+
// }
|
|
95
|
+
// if (!closeTo(2**28)(circle.radius, d) && getRealProngCount(cpNode) !== 3) {
|
|
96
|
+
// ii++;
|
|
97
|
+
// circle.center;//?
|
|
98
|
+
// circle.radius;//?
|
|
99
|
+
// d; //?
|
|
100
|
+
// p;//?
|
|
101
|
+
// pos.isSource;//?
|
|
102
|
+
// getRealProngCount(cpNode);//?
|
|
103
|
+
// }
|
|
104
|
+
if (minNumAccurateBits !== undefined) {
|
|
105
|
+
const TOL = 2**(maxPO2 - minNumAccurateBits);
|
|
106
|
+
|
|
107
|
+
if (abs(circle.radius - d) > TOL) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Medial circle radius must be about the same (2**${round(log2(TOL))}) ` +
|
|
110
|
+
`as distance from medial circle center to point on shape, ` +
|
|
111
|
+
`found: medial radius ${circle.radius}, distance: ${d}`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return getBoundaryPiece(cpNode);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
/** @internal */
|
|
122
|
+
const TOLERANCE_ADD_2PRONG = 0.01;
|
|
123
|
+
/** @internal */
|
|
124
|
+
const TOLERANCE_USE_LINE = 0.0001; // else cubic
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
function getBoundaryPiece(
|
|
128
|
+
cpNode: CpNode) {
|
|
129
|
+
|
|
130
|
+
const cpNode_ = cpNode.next;
|
|
131
|
+
|
|
132
|
+
const pos = cpNode.pointOnShape;
|
|
133
|
+
const pos_ = cpNode_.pointOnShape;
|
|
134
|
+
|
|
135
|
+
const { p } = pos;
|
|
136
|
+
const { p: p_ } = pos_;
|
|
137
|
+
|
|
138
|
+
const fromCc = p;
|
|
139
|
+
const fromL = getEdgeDirection(cpNode, FROM);
|
|
140
|
+
|
|
141
|
+
const toCc = p_;
|
|
142
|
+
const toL = getEdgeDirection(cpNode_, TO);
|
|
143
|
+
|
|
144
|
+
const mid = lineLineIntersection(fromL, toL);
|
|
145
|
+
|
|
146
|
+
const c = fromToVec(fromCc,toCc);
|
|
147
|
+
|
|
148
|
+
let twisted: boolean;
|
|
149
|
+
if (!mid) {
|
|
150
|
+
twisted = true;
|
|
151
|
+
} else {
|
|
152
|
+
const a = fromToVec(fromCc, mid);
|
|
153
|
+
const b = fromToVec(toCc, mid);
|
|
154
|
+
|
|
155
|
+
twisted = dot(a,c) < 0 || dot(b,c) > 0;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (!twisted) {
|
|
159
|
+
return [fromCc, mid!, toCc];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const r = rotate90Degrees(c);
|
|
163
|
+
const w1 = fromToVec(fromL[0], fromL[1]); // This is a unit vector
|
|
164
|
+
const w2 = fromToVec(toL[0], toL[1]); // This is a unit vector
|
|
165
|
+
|
|
166
|
+
const d1 = abs(cross(c, w1)) / (3*3);
|
|
167
|
+
const d2 = abs(cross(c, w2)) / (3*3);
|
|
168
|
+
|
|
169
|
+
if (d1 > TOLERANCE_ADD_2PRONG || d2 > TOLERANCE_ADD_2PRONG) {
|
|
170
|
+
// FUTURE - not within tolerance - must add additional 2-prong
|
|
171
|
+
return [fromCc, toCc];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (d1 > TOLERANCE_USE_LINE || d2 > TOLERANCE_USE_LINE) {
|
|
175
|
+
// approximate with cubic bezier
|
|
176
|
+
const m1 = interpolate(fromCc,toCc,1/3);
|
|
177
|
+
const m2 = interpolate(fromCc,toCc,2/3);
|
|
178
|
+
const v1 = translate(r, m1);
|
|
179
|
+
const v2 = translate(r, m2);
|
|
180
|
+
const l1 = [m1,v1];
|
|
181
|
+
const l2 = [m2,v2];
|
|
182
|
+
const mid1 = lineLineIntersection(fromL, l1)!;
|
|
183
|
+
const mid2 = lineLineIntersection(toL, l2)!;
|
|
184
|
+
|
|
185
|
+
return [fromCc, mid1, mid2, toCc];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Within tolerance - approximate with a straight line.
|
|
189
|
+
return [fromCc, toCc];
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Returns a line segment of unit length starting at the given point and
|
|
195
|
+
* being tangent to the shape boundary.
|
|
196
|
+
*
|
|
197
|
+
* @internal
|
|
198
|
+
*/
|
|
199
|
+
function getEdgeDirection(
|
|
200
|
+
cpNode: CpNode,
|
|
201
|
+
fromOrTo: typeof FROM | typeof TO) {
|
|
202
|
+
|
|
203
|
+
let { pointOnShape } = cpNode;
|
|
204
|
+
let { curve, t, p } = pointOnShape;
|
|
205
|
+
let { ps } = curve;
|
|
206
|
+
|
|
207
|
+
if (fromOrTo === FROM && t === 1) {
|
|
208
|
+
t = 0;
|
|
209
|
+
curve = curve.next;
|
|
210
|
+
ps = curve.ps;
|
|
211
|
+
}
|
|
212
|
+
if (fromOrTo === TO && t === 0 ) {
|
|
213
|
+
t = 1;
|
|
214
|
+
curve = curve.prev;
|
|
215
|
+
ps = curve.ps;
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const tangent = getTangent(ps, t);
|
|
219
|
+
|
|
220
|
+
const v = translate(p, tangent);
|
|
221
|
+
|
|
222
|
+
return [p,v];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
export { reconstructFromMats }
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Mutable } from '../utils/mutable.js';
|
|
2
|
+
import type { Mat } from '../mat/mat.js';
|
|
3
|
+
import { isFullyTerminating } from '../cp-node/fs/is-fully-terminating.js';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* In-place removes trivial 3-prongs from the SAT graph; just to simplify
|
|
8
|
+
* subsequent processing.
|
|
9
|
+
*
|
|
10
|
+
* These are 3-prongs that are induced by the SAT construction, and do
|
|
11
|
+
* not correspond to actual 3-prongs in the shape.
|
|
12
|
+
*
|
|
13
|
+
* @param sat the SAT
|
|
14
|
+
*/
|
|
15
|
+
function removeSatInducedTrivial3Prongs(
|
|
16
|
+
sat: Mat): Mat {
|
|
17
|
+
|
|
18
|
+
let { cpNode } = sat;
|
|
19
|
+
|
|
20
|
+
let cpStart = cpNode;
|
|
21
|
+
do {
|
|
22
|
+
if (isFullyTerminating(cpNode) ||
|
|
23
|
+
// cpNode.isHoleClosing || // hole-closers are fully terminating
|
|
24
|
+
cpNode.next !== cpNode.nextOnCircle) {
|
|
25
|
+
|
|
26
|
+
cpNode = cpNode.next;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
//-----------------------------
|
|
31
|
+
// Delete the trivial 3-prong
|
|
32
|
+
//-----------------------------
|
|
33
|
+
// console.log('Removing SAT-induced trivial 3-prong');
|
|
34
|
+
|
|
35
|
+
const next = cpNode.next;
|
|
36
|
+
const nextNext = next.next;
|
|
37
|
+
const nextNextOC = cpNode.next.nextOnCircle;
|
|
38
|
+
|
|
39
|
+
//-------------------------------------------------------------
|
|
40
|
+
// In-place update of links to remove the trivial 3-prong node
|
|
41
|
+
//-------------------------------------------------------------
|
|
42
|
+
(cpNode as Mutable<typeof cpNode>).next = nextNext;
|
|
43
|
+
(cpNode as Mutable<typeof cpNode>).nextOnCircle = nextNextOC;
|
|
44
|
+
(nextNext as Mutable<typeof nextNext>).prev = cpNode;
|
|
45
|
+
(nextNextOC as Mutable<typeof nextNextOC>).prevOnCircle = cpNode;
|
|
46
|
+
//-------------------------------------------------------------
|
|
47
|
+
|
|
48
|
+
if (cpStart === next) {
|
|
49
|
+
cpStart = cpNode; // ...otherwise the loop will never terminate
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
cpNode = cpNode.next;
|
|
53
|
+
} while (cpNode !== cpStart)
|
|
54
|
+
|
|
55
|
+
// ...otherwise the caller will have a reference to a node that has been removed from the graph
|
|
56
|
+
(sat as Mutable<Mat>).cpNode = cpNode;
|
|
57
|
+
|
|
58
|
+
return sat;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
export { removeSatInducedTrivial3Prongs }
|
|
@@ -12,12 +12,20 @@ type Extreme = {
|
|
|
12
12
|
};
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
function toPrePoint(
|
|
15
|
+
function toPrePoint(
|
|
16
|
+
extreme: Extreme): PrePointOnShape {
|
|
17
|
+
|
|
18
|
+
const { curve, t } = extreme;
|
|
19
|
+
const { ps } = curve;
|
|
20
|
+
|
|
21
|
+
const pDd = toP(ps, t);
|
|
22
|
+
const p = pDd.map(c => c[0] + c[1]);
|
|
23
|
+
|
|
16
24
|
return {
|
|
17
|
-
curve
|
|
25
|
+
curve,
|
|
18
26
|
t: extreme.t,
|
|
19
27
|
isSource: true,
|
|
20
|
-
p
|
|
28
|
+
p, pDd
|
|
21
29
|
};
|
|
22
30
|
}
|
|
23
31
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
type Depth = 1 | 2 | 3 | 4 | 5 | 6;
|
|
3
|
+
|
|
4
|
+
type NestedArray<T, D extends Depth> =
|
|
5
|
+
D extends 1 ? T[] :
|
|
6
|
+
D extends 2 ? T[][] :
|
|
7
|
+
D extends 3 ? T[][][] :
|
|
8
|
+
D extends 4 ? T[][][][] :
|
|
9
|
+
D extends 5 ? T[][][][][] :
|
|
10
|
+
T[][][][][][];
|
|
11
|
+
|
|
12
|
+
type PrevDepth<D extends Depth> =
|
|
13
|
+
D extends 6 ? 5 :
|
|
14
|
+
D extends 5 ? 4 :
|
|
15
|
+
D extends 4 ? 3 :
|
|
16
|
+
D extends 3 ? 2 :
|
|
17
|
+
D extends 2 ? 1 :
|
|
18
|
+
never;
|
|
19
|
+
|
|
20
|
+
type LeafAtDepth<A, D extends Depth> =
|
|
21
|
+
D extends 1
|
|
22
|
+
? A extends (infer T)[] ? T : never
|
|
23
|
+
: A extends (infer T)[] ? LeafAtDepth<T, PrevDepth<D>> : never;
|
|
24
|
+
|
|
25
|
+
type LeafValue<T, FilterUndefined extends boolean> =
|
|
26
|
+
FilterUndefined extends true ? Exclude<T, undefined> : T;
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns the result of mapping the array to the given depth and, optionally,
|
|
31
|
+
* filtering out `undefined` leaf values.
|
|
32
|
+
*
|
|
33
|
+
* @param tss
|
|
34
|
+
* @param f
|
|
35
|
+
* @param filterUndefined
|
|
36
|
+
*/
|
|
37
|
+
function mapDeep<D extends Depth, A extends NestedArray<unknown, D>, U, F extends boolean = false>(
|
|
38
|
+
depth: D,
|
|
39
|
+
tss: A,
|
|
40
|
+
f: (t: LeafAtDepth<A, D>) => U,
|
|
41
|
+
filterUndefined?: F): NestedArray<LeafValue<U, F>, D> {
|
|
42
|
+
|
|
43
|
+
if (!Number.isInteger(depth) || depth < 1) {
|
|
44
|
+
throw new Error('depth must be an integer >= 1');
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function mapRec(d: number, arr: unknown): unknown {
|
|
48
|
+
const a = arr as unknown[];
|
|
49
|
+
|
|
50
|
+
if (d === 1) {
|
|
51
|
+
const ts_: U[] = [];
|
|
52
|
+
for (let i=0; i<a.length; i++) {
|
|
53
|
+
const v = f(a[i] as LeafAtDepth<A, D>);
|
|
54
|
+
if (!filterUndefined || v !== undefined) {
|
|
55
|
+
ts_.push(v);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return ts_;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const tss_: unknown[] = [];
|
|
63
|
+
for (let i=0; i<a.length; i++) {
|
|
64
|
+
tss_.push(mapRec(d - 1, a[i]));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return tss_;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return mapRec(depth, tss as unknown) as NestedArray<LeafValue<U, F>, D>;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
export { mapDeep }
|
|
75
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Returns the result of mapping the array to depth 2 and applying a filter
|
|
4
|
+
* to the inner results which defaults to filtering out `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* @param tss
|
|
7
|
+
* @param f
|
|
8
|
+
* @param filter
|
|
9
|
+
*/
|
|
10
|
+
function mapmap<T,U>(
|
|
11
|
+
tss: T[][],
|
|
12
|
+
f: (t: T) => U,
|
|
13
|
+
filter: (u: U) => boolean = u => u !== undefined): U[][] {
|
|
14
|
+
|
|
15
|
+
const tss_: U[][] = [];
|
|
16
|
+
for (let i=0; i<tss.length; i++) {
|
|
17
|
+
const ts = tss[i];
|
|
18
|
+
const ts_: U[] = [];
|
|
19
|
+
for (let j=0; j<ts.length; j++) {
|
|
20
|
+
const v = f(ts[j]);
|
|
21
|
+
if (filter(v)) {
|
|
22
|
+
ts_.push(f(ts[j]));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
tss_.push(ts_);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return tss_;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
export { mapmap }
|
|
33
|
+
|
package/wallaby.mjs
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
|
|
2
2
|
export default function(wallaby) {
|
|
3
3
|
return {
|
|
4
|
+
autoDetect: ['jest'],
|
|
5
|
+
|
|
4
6
|
files: [
|
|
5
7
|
'package.json',
|
|
6
8
|
'src/**/*.ts',
|
|
7
|
-
'
|
|
9
|
+
'__tests__/helpers/*.ts'
|
|
8
10
|
],
|
|
9
11
|
|
|
10
12
|
tests: [
|
|
11
|
-
'
|
|
13
|
+
'__tests__/**/*.spec.ts'
|
|
12
14
|
],
|
|
13
15
|
|
|
14
|
-
testFramework: 'mocha',
|
|
15
|
-
|
|
16
16
|
compilers: {
|
|
17
17
|
"**/*.+(t)s?": wallaby.compilers.typeScript()
|
|
18
18
|
},
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { Mat } from '../mat/mat.js';
|
|
2
|
-
import { CpNode } from '../cp-node/cp-node.js';
|
|
3
|
-
type DebugElemKey = keyof typeof emptyDebugElems;
|
|
4
|
-
declare const emptyDebugElems: {
|
|
5
|
-
readonly oneProng: CpNode[];
|
|
6
|
-
readonly twoProng: CpNode[];
|
|
7
|
-
readonly threeProng: CpNode[];
|
|
8
|
-
readonly looseBoundingBox: number[][][];
|
|
9
|
-
readonly tightBoundingBox: number[][][];
|
|
10
|
-
readonly boundingHull: number[][][];
|
|
11
|
-
readonly vertex: CpNode[];
|
|
12
|
-
readonly mat: Mat[];
|
|
13
|
-
readonly maxVertex: CpNode[];
|
|
14
|
-
readonly leaves: CpNode[][];
|
|
15
|
-
readonly cull: number[][];
|
|
16
|
-
readonly cpNode: CpNode[];
|
|
17
|
-
readonly branch: CpNode[][];
|
|
18
|
-
readonly holeCloser: CpNode[];
|
|
19
|
-
};
|
|
20
|
-
declare const debugElemNames: Array<keyof typeof emptyDebugElems>;
|
|
21
|
-
/** @internal */
|
|
22
|
-
type DebugElems = typeof emptyDebugElems;
|
|
23
|
-
type DebugElem = {
|
|
24
|
-
[T in keyof DebugElems]: DebugElems[T][number];
|
|
25
|
-
};
|
|
26
|
-
export { DebugElems, DebugElemKey, DebugElem, emptyDebugElems, debugElemNames, };
|