@antv/util 3.0.1 → 3.1.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/README.md +167 -4
- package/dist/util.min.js +1 -1
- package/esm/color/arr2rgb.js +3 -3
- package/esm/color/arr2rgb.js.map +1 -1
- package/esm/color/gradient.js +9 -9
- package/esm/color/gradient.js.map +1 -1
- package/esm/color/tocssgradient.js +18 -18
- package/esm/color/tocssgradient.js.map +1 -1
- package/esm/color/torgb.js +6 -6
- package/esm/color/torgb.js.map +1 -1
- package/esm/helper/to-radian.js +1 -1
- package/esm/helper/to-radian.js.map +1 -1
- package/esm/matrix/index.js +8 -8
- package/esm/matrix/index.js.map +1 -1
- package/esm/path/convert/path-2-absolute.d.ts +2 -0
- package/esm/path/convert/path-2-absolute.js +83 -0
- package/esm/path/convert/path-2-absolute.js.map +1 -0
- package/esm/path/convert/path-2-curve.d.ts +2 -0
- package/esm/path/convert/path-2-curve.js +56 -0
- package/esm/path/convert/path-2-curve.js.map +1 -0
- package/esm/path/convert/path-2-string.d.ts +6 -0
- package/esm/path/convert/path-2-string.js +11 -0
- package/esm/path/convert/path-2-string.js.map +1 -0
- package/esm/path/index.d.ts +17 -16
- package/esm/path/index.js +17 -16
- package/esm/path/index.js.map +1 -1
- package/esm/path/parser/finalize-segment.d.ts +5 -0
- package/esm/path/parser/finalize-segment.js +27 -0
- package/esm/path/parser/finalize-segment.js.map +1 -0
- package/esm/path/parser/is-arc-command.d.ts +4 -0
- package/esm/path/parser/is-arc-command.js +7 -0
- package/esm/path/parser/is-arc-command.js.map +1 -0
- package/esm/path/parser/is-digit-start.d.ts +6 -0
- package/esm/path/parser/is-digit-start.js +11 -0
- package/esm/path/parser/is-digit-start.js.map +1 -0
- package/esm/path/parser/is-path-command.d.ts +4 -0
- package/esm/path/parser/is-path-command.js +23 -0
- package/esm/path/parser/is-path-command.js.map +1 -0
- package/esm/path/parser/is-space.d.ts +4 -0
- package/esm/path/parser/is-space.js +22 -0
- package/esm/path/parser/is-space.js.map +1 -0
- package/esm/path/parser/params-count.d.ts +13 -0
- package/esm/path/parser/params-count.js +14 -0
- package/esm/path/parser/params-count.js.map +1 -0
- package/esm/path/parser/params-parser.d.ts +10 -0
- package/esm/path/parser/params-parser.js +11 -0
- package/esm/path/parser/params-parser.js.map +1 -0
- package/esm/path/parser/parse-path-string.d.ts +6 -0
- package/esm/path/parser/parse-path-string.js +21 -0
- package/esm/path/parser/parse-path-string.js.map +1 -0
- package/esm/path/parser/path-parser.d.ts +16 -0
- package/esm/path/parser/path-parser.js +18 -0
- package/esm/path/parser/path-parser.js.map +1 -0
- package/esm/path/parser/scan-flag.d.ts +6 -0
- package/esm/path/parser/scan-flag.js +20 -0
- package/esm/path/parser/scan-flag.js.map +1 -0
- package/esm/path/parser/scan-param.d.ts +6 -0
- package/esm/path/parser/scan-param.js +83 -0
- package/esm/path/parser/scan-param.js.map +1 -0
- package/esm/path/parser/scan-segment.d.ts +6 -0
- package/esm/path/parser/scan-segment.js +57 -0
- package/esm/path/parser/scan-segment.js.map +1 -0
- package/esm/path/parser/skip-spaces.d.ts +7 -0
- package/esm/path/parser/skip-spaces.js +13 -0
- package/esm/path/parser/skip-spaces.js.map +1 -0
- package/esm/path/process/arc-2-cubic.d.ts +7 -1
- package/esm/path/process/arc-2-cubic.js +276 -133
- package/esm/path/process/arc-2-cubic.js.map +1 -1
- package/esm/path/process/clone-path.d.ts +2 -0
- package/esm/path/process/clone-path.js +4 -0
- package/esm/path/process/clone-path.js.map +1 -0
- package/esm/path/process/fix-arc.d.ts +2 -0
- package/esm/path/process/fix-arc.js +16 -0
- package/esm/path/process/fix-arc.js.map +1 -0
- package/esm/path/process/line-2-cubic.js +17 -32
- package/esm/path/process/line-2-cubic.js.map +1 -1
- package/esm/path/process/normalize-path.d.ts +8 -0
- package/esm/path/process/normalize-path.js +35 -0
- package/esm/path/process/normalize-path.js.map +1 -0
- package/esm/path/process/normalize-segment.d.ts +6 -0
- package/esm/path/process/normalize-segment.js +42 -0
- package/esm/path/process/normalize-segment.js.map +1 -0
- package/esm/path/process/quad-2-cubic.js +2 -2
- package/esm/path/process/quad-2-cubic.js.map +1 -1
- package/esm/path/process/reverse-curve.d.ts +2 -0
- package/esm/path/process/reverse-curve.js +13 -0
- package/esm/path/process/reverse-curve.js.map +1 -0
- package/esm/path/process/round-path.d.ts +6 -0
- package/esm/path/process/round-path.js +20 -0
- package/esm/path/process/round-path.js.map +1 -0
- package/esm/path/process/segment-2-cubic.d.ts +2 -2
- package/esm/path/process/segment-2-cubic.js +23 -19
- package/esm/path/process/segment-2-cubic.js.map +1 -1
- package/esm/path/types.d.ts +114 -17
- package/esm/path/util/distance-square-root.d.ts +1 -0
- package/esm/path/util/distance-square-root.js +4 -0
- package/esm/path/util/distance-square-root.js.map +1 -0
- package/esm/path/util/equalize-segments.d.ts +2 -0
- package/esm/path/util/equalize-segments.js +68 -0
- package/esm/path/util/equalize-segments.js.map +1 -0
- package/esm/path/util/get-draw-direction.d.ts +2 -0
- package/esm/path/util/get-draw-direction.js +5 -0
- package/esm/path/util/get-draw-direction.js.map +1 -0
- package/esm/path/util/get-path-area.d.ts +8 -0
- package/esm/path/util/get-path-area.js +68 -0
- package/esm/path/util/get-path-area.js.map +1 -0
- package/esm/path/util/get-path-bbox-total-length.d.ts +5 -0
- package/esm/path/util/get-path-bbox-total-length.js +37 -0
- package/esm/path/util/get-path-bbox-total-length.js.map +1 -0
- package/esm/path/util/get-path-bbox.d.ts +5 -0
- package/esm/path/util/get-path-bbox.js +35 -0
- package/esm/path/util/get-path-bbox.js.map +1 -0
- package/esm/path/util/get-point-at-length.d.ts +5 -0
- package/esm/path/util/get-point-at-length.js +8 -0
- package/esm/path/util/get-point-at-length.js.map +1 -0
- package/esm/path/util/get-properties-at-length.d.ts +6 -0
- package/esm/path/util/get-properties-at-length.js +58 -0
- package/esm/path/util/get-properties-at-length.js.map +1 -0
- package/esm/path/util/get-properties-at-point.d.ts +7 -0
- package/esm/path/util/get-properties-at-point.js +69 -0
- package/esm/path/util/get-properties-at-point.js.map +1 -0
- package/esm/path/util/get-rotated-curve.d.ts +2 -0
- package/esm/path/util/get-rotated-curve.js +34 -0
- package/esm/path/util/get-rotated-curve.js.map +1 -0
- package/esm/path/util/get-total-length.d.ts +8 -0
- package/esm/path/util/get-total-length.js +11 -0
- package/esm/path/util/get-total-length.js.map +1 -0
- package/esm/path/util/is-absolute-array.d.ts +6 -0
- package/esm/path/util/is-absolute-array.js +11 -0
- package/esm/path/util/is-absolute-array.js.map +1 -0
- package/esm/path/util/is-curve-array.d.ts +9 -0
- package/esm/path/util/is-curve-array.js +12 -0
- package/esm/path/util/is-curve-array.js.map +1 -0
- package/esm/path/util/is-normalized-array.d.ts +7 -0
- package/esm/path/util/is-normalized-array.js +10 -0
- package/esm/path/util/is-normalized-array.js.map +1 -0
- package/esm/path/util/is-path-array.d.ts +5 -0
- package/esm/path/util/is-path-array.js +12 -0
- package/esm/path/util/is-path-array.js.map +1 -0
- package/esm/path/util/is-point-in-stroke.d.ts +5 -0
- package/esm/path/util/is-point-in-stroke.js +9 -0
- package/esm/path/util/is-point-in-stroke.js.map +1 -0
- package/esm/path/util/mid-point.d.ts +1 -0
- package/esm/path/util/mid-point.js +8 -0
- package/esm/path/util/mid-point.js.map +1 -0
- package/esm/path/util/path-length-factory.d.ts +7 -0
- package/esm/path/util/path-length-factory.js +94 -0
- package/esm/path/util/path-length-factory.js.map +1 -0
- package/esm/path/util/rotate-vector.d.ts +4 -0
- package/esm/path/util/rotate-vector.js +6 -0
- package/esm/path/util/rotate-vector.js.map +1 -0
- package/esm/path/util/segment-arc-factory.d.ts +6 -0
- package/esm/path/util/segment-arc-factory.js +135 -0
- package/esm/path/util/segment-arc-factory.js.map +1 -0
- package/esm/path/util/segment-cubic-factory.d.ts +6 -0
- package/esm/path/util/segment-cubic-factory.js +63 -0
- package/esm/path/util/segment-cubic-factory.js.map +1 -0
- package/esm/path/util/segment-line-factory.d.ts +6 -0
- package/esm/path/util/segment-line-factory.js +35 -0
- package/esm/path/util/segment-line-factory.js.map +1 -0
- package/esm/path/util/segment-quad-factory.d.ts +6 -0
- package/esm/path/util/segment-quad-factory.js +65 -0
- package/esm/path/util/segment-quad-factory.js.map +1 -0
- package/lib/color/arr2rgb.js +3 -3
- package/lib/color/arr2rgb.js.map +1 -1
- package/lib/color/gradient.js +12 -12
- package/lib/color/gradient.js.map +1 -1
- package/lib/color/tocssgradient.js +18 -18
- package/lib/color/tocssgradient.js.map +1 -1
- package/lib/color/torgb.js +7 -7
- package/lib/color/torgb.js.map +1 -1
- package/lib/helper/to-radian.js +1 -1
- package/lib/helper/to-radian.js.map +1 -1
- package/lib/matrix/index.js +9 -9
- package/lib/matrix/index.js.map +1 -1
- package/lib/path/convert/path-2-absolute.d.ts +2 -0
- package/lib/path/convert/path-2-absolute.js +87 -0
- package/lib/path/convert/path-2-absolute.js.map +1 -0
- package/lib/path/convert/path-2-curve.d.ts +2 -0
- package/lib/path/convert/path-2-curve.js +60 -0
- package/lib/path/convert/path-2-curve.js.map +1 -0
- package/lib/path/convert/path-2-string.d.ts +6 -0
- package/lib/path/convert/path-2-string.js +15 -0
- package/lib/path/convert/path-2-string.js.map +1 -0
- package/lib/path/index.d.ts +17 -16
- package/lib/path/index.js +42 -31
- package/lib/path/index.js.map +1 -1
- package/lib/path/parser/finalize-segment.d.ts +5 -0
- package/lib/path/parser/finalize-segment.js +31 -0
- package/lib/path/parser/finalize-segment.js.map +1 -0
- package/lib/path/parser/is-arc-command.d.ts +4 -0
- package/lib/path/parser/is-arc-command.js +11 -0
- package/lib/path/parser/is-arc-command.js.map +1 -0
- package/lib/path/parser/is-digit-start.d.ts +6 -0
- package/lib/path/parser/is-digit-start.js +16 -0
- package/lib/path/parser/is-digit-start.js.map +1 -0
- package/lib/path/parser/is-path-command.d.ts +4 -0
- package/lib/path/parser/is-path-command.js +27 -0
- package/lib/path/parser/is-path-command.js.map +1 -0
- package/lib/path/parser/is-space.d.ts +4 -0
- package/lib/path/parser/is-space.js +26 -0
- package/lib/path/parser/is-space.js.map +1 -0
- package/lib/path/parser/params-count.d.ts +13 -0
- package/lib/path/parser/params-count.js +17 -0
- package/lib/path/parser/params-count.js.map +1 -0
- package/lib/path/parser/params-parser.d.ts +10 -0
- package/lib/path/parser/params-parser.js +14 -0
- package/lib/path/parser/params-parser.js.map +1 -0
- package/lib/path/parser/parse-path-string.d.ts +6 -0
- package/lib/path/parser/parse-path-string.js +25 -0
- package/lib/path/parser/parse-path-string.js.map +1 -0
- package/lib/path/parser/path-parser.d.ts +16 -0
- package/lib/path/parser/path-parser.js +22 -0
- package/lib/path/parser/path-parser.js.map +1 -0
- package/lib/path/parser/scan-flag.d.ts +6 -0
- package/lib/path/parser/scan-flag.js +24 -0
- package/lib/path/parser/scan-flag.js.map +1 -0
- package/lib/path/parser/scan-param.d.ts +6 -0
- package/lib/path/parser/scan-param.js +87 -0
- package/lib/path/parser/scan-param.js.map +1 -0
- package/lib/path/parser/scan-segment.d.ts +6 -0
- package/lib/path/parser/scan-segment.js +61 -0
- package/lib/path/parser/scan-segment.js.map +1 -0
- package/lib/path/parser/skip-spaces.d.ts +7 -0
- package/lib/path/parser/skip-spaces.js +17 -0
- package/lib/path/parser/skip-spaces.js.map +1 -0
- package/lib/path/process/arc-2-cubic.d.ts +7 -1
- package/lib/path/process/arc-2-cubic.js +276 -133
- package/lib/path/process/arc-2-cubic.js.map +1 -1
- package/lib/path/process/clone-path.d.ts +2 -0
- package/lib/path/process/clone-path.js +8 -0
- package/lib/path/process/clone-path.js.map +1 -0
- package/lib/path/process/fix-arc.d.ts +2 -0
- package/lib/path/process/fix-arc.js +20 -0
- package/lib/path/process/fix-arc.js.map +1 -0
- package/lib/path/process/line-2-cubic.js +17 -32
- package/lib/path/process/line-2-cubic.js.map +1 -1
- package/lib/path/process/normalize-path.d.ts +8 -0
- package/lib/path/process/normalize-path.js +39 -0
- package/lib/path/process/normalize-path.js.map +1 -0
- package/lib/path/process/normalize-segment.d.ts +6 -0
- package/lib/path/process/normalize-segment.js +46 -0
- package/lib/path/process/normalize-segment.js.map +1 -0
- package/lib/path/process/quad-2-cubic.js +2 -2
- package/lib/path/process/quad-2-cubic.js.map +1 -1
- package/lib/path/process/reverse-curve.d.ts +2 -0
- package/lib/path/process/reverse-curve.js +17 -0
- package/lib/path/process/reverse-curve.js.map +1 -0
- package/lib/path/process/round-path.d.ts +6 -0
- package/lib/path/process/round-path.js +24 -0
- package/lib/path/process/round-path.js.map +1 -0
- package/lib/path/process/segment-2-cubic.d.ts +2 -2
- package/lib/path/process/segment-2-cubic.js +26 -22
- package/lib/path/process/segment-2-cubic.js.map +1 -1
- package/lib/path/types.d.ts +114 -17
- package/lib/path/util/distance-square-root.d.ts +1 -0
- package/lib/path/util/distance-square-root.js +8 -0
- package/lib/path/util/distance-square-root.js.map +1 -0
- package/lib/path/util/equalize-segments.d.ts +2 -0
- package/lib/path/util/equalize-segments.js +72 -0
- package/lib/path/util/equalize-segments.js.map +1 -0
- package/lib/path/util/get-draw-direction.d.ts +2 -0
- package/lib/path/util/get-draw-direction.js +9 -0
- package/lib/path/util/get-draw-direction.js.map +1 -0
- package/lib/path/util/get-path-area.d.ts +8 -0
- package/lib/path/util/get-path-area.js +72 -0
- package/lib/path/util/get-path-area.js.map +1 -0
- package/lib/path/util/get-path-bbox-total-length.d.ts +5 -0
- package/lib/path/util/get-path-bbox-total-length.js +41 -0
- package/lib/path/util/get-path-bbox-total-length.js.map +1 -0
- package/lib/path/util/get-path-bbox.d.ts +5 -0
- package/lib/path/util/get-path-bbox.js +39 -0
- package/lib/path/util/get-path-bbox.js.map +1 -0
- package/lib/path/util/get-point-at-length.d.ts +5 -0
- package/lib/path/util/get-point-at-length.js +12 -0
- package/lib/path/util/get-point-at-length.js.map +1 -0
- package/lib/path/util/get-properties-at-length.d.ts +6 -0
- package/lib/path/util/get-properties-at-length.js +62 -0
- package/lib/path/util/get-properties-at-length.js.map +1 -0
- package/lib/path/util/get-properties-at-point.d.ts +7 -0
- package/lib/path/util/get-properties-at-point.js +73 -0
- package/lib/path/util/get-properties-at-point.js.map +1 -0
- package/lib/path/util/get-rotated-curve.d.ts +2 -0
- package/lib/path/util/get-rotated-curve.js +38 -0
- package/lib/path/util/get-rotated-curve.js.map +1 -0
- package/lib/path/util/get-total-length.d.ts +8 -0
- package/lib/path/util/get-total-length.js +15 -0
- package/lib/path/util/get-total-length.js.map +1 -0
- package/lib/path/util/is-absolute-array.d.ts +6 -0
- package/lib/path/util/is-absolute-array.js +15 -0
- package/lib/path/util/is-absolute-array.js.map +1 -0
- package/lib/path/util/is-curve-array.d.ts +9 -0
- package/lib/path/util/is-curve-array.js +16 -0
- package/lib/path/util/is-curve-array.js.map +1 -0
- package/lib/path/util/is-normalized-array.d.ts +7 -0
- package/lib/path/util/is-normalized-array.js +14 -0
- package/lib/path/util/is-normalized-array.js.map +1 -0
- package/lib/path/util/is-path-array.d.ts +5 -0
- package/lib/path/util/is-path-array.js +16 -0
- package/lib/path/util/is-path-array.js.map +1 -0
- package/lib/path/util/is-point-in-stroke.d.ts +5 -0
- package/lib/path/util/is-point-in-stroke.js +13 -0
- package/lib/path/util/is-point-in-stroke.js.map +1 -0
- package/lib/path/util/mid-point.d.ts +1 -0
- package/lib/path/util/mid-point.js +12 -0
- package/lib/path/util/mid-point.js.map +1 -0
- package/lib/path/util/path-length-factory.d.ts +7 -0
- package/lib/path/util/path-length-factory.js +98 -0
- package/lib/path/util/path-length-factory.js.map +1 -0
- package/lib/path/util/rotate-vector.d.ts +4 -0
- package/lib/path/util/rotate-vector.js +10 -0
- package/lib/path/util/rotate-vector.js.map +1 -0
- package/lib/path/util/segment-arc-factory.d.ts +6 -0
- package/lib/path/util/segment-arc-factory.js +139 -0
- package/lib/path/util/segment-arc-factory.js.map +1 -0
- package/lib/path/util/segment-cubic-factory.d.ts +6 -0
- package/lib/path/util/segment-cubic-factory.js +67 -0
- package/lib/path/util/segment-cubic-factory.js.map +1 -0
- package/lib/path/util/segment-line-factory.d.ts +6 -0
- package/lib/path/util/segment-line-factory.js +39 -0
- package/lib/path/util/segment-line-factory.js.map +1 -0
- package/lib/path/util/segment-quad-factory.d.ts +6 -0
- package/lib/path/util/segment-quad-factory.js +69 -0
- package/lib/path/util/segment-quad-factory.js.map +1 -0
- package/package.json +1 -1
- package/src/path/convert/path-2-absolute.ts +90 -0
- package/src/path/convert/path-2-curve.ts +68 -0
- package/src/path/convert/path-2-string.ts +12 -0
- package/src/path/index.ts +18 -16
- package/src/path/parser/finalize-segment.ts +30 -0
- package/src/path/parser/is-arc-command.ts +6 -0
- package/src/path/parser/is-digit-start.ts +13 -0
- package/src/path/parser/is-path-command.ts +22 -0
- package/src/path/parser/is-space.ts +23 -0
- package/src/path/parser/params-count.ts +13 -0
- package/src/path/parser/params-parser.ts +10 -0
- package/src/path/parser/parse-path-string.ts +26 -0
- package/src/path/parser/path-parser.ts +35 -0
- package/src/path/parser/scan-flag.ts +24 -0
- package/src/path/parser/scan-param.ts +98 -0
- package/src/path/parser/scan-segment.ts +68 -0
- package/src/path/parser/skip-spaces.ts +14 -0
- package/src/path/process/arc-2-cubic.ts +332 -215
- package/src/path/process/clone-path.ts +5 -0
- package/src/path/process/fix-arc.ts +17 -0
- package/src/path/process/line-2-cubic.ts +17 -33
- package/src/path/process/normalize-path.ts +42 -0
- package/src/path/process/normalize-segment.ts +42 -0
- package/src/path/process/reverse-curve.ts +18 -0
- package/src/path/process/round-path.ts +22 -0
- package/src/path/process/segment-2-cubic.ts +28 -27
- package/src/path/types.ts +190 -17
- package/src/path/util/distance-square-root.ts +3 -0
- package/src/path/util/equalize-segments.ts +79 -0
- package/src/path/util/get-draw-direction.ts +6 -0
- package/src/path/util/get-path-area.ts +83 -0
- package/src/path/util/get-path-bbox-total-length.ts +45 -0
- package/src/path/util/get-path-bbox.ts +42 -0
- package/src/path/util/get-point-at-length.ts +9 -0
- package/src/path/util/get-properties-at-length.ts +65 -0
- package/src/path/util/get-properties-at-point.ts +73 -0
- package/src/path/util/get-rotated-curve.ts +42 -0
- package/src/path/util/get-total-length.ts +12 -0
- package/src/path/util/is-absolute-array.ts +14 -0
- package/src/path/util/is-curve-array.ts +13 -0
- package/src/path/util/is-normalized-array.ts +11 -0
- package/src/path/util/is-path-array.ts +15 -0
- package/src/path/util/is-point-in-stroke.ts +10 -0
- package/src/path/util/mid-point.ts +7 -0
- package/src/path/util/path-length-factory.ts +98 -0
- package/src/path/util/rotate-vector.ts +5 -0
- package/src/path/util/segment-arc-factory.ts +186 -0
- package/src/path/util/segment-cubic-factory.ts +92 -0
- package/src/path/util/segment-line-factory.ts +36 -0
- package/src/path/util/segment-quad-factory.ts +90 -0
- package/esm/path/catmull-rom-2-bezier.d.ts +0 -10
- package/esm/path/catmull-rom-2-bezier.js +0 -115
- package/esm/path/catmull-rom-2-bezier.js.map +0 -1
- package/esm/path/fill-path-by-diff.d.ts +0 -5
- package/esm/path/fill-path-by-diff.js +0 -110
- package/esm/path/fill-path-by-diff.js.map +0 -1
- package/esm/path/fill-path.d.ts +0 -1
- package/esm/path/fill-path.js +0 -129
- package/esm/path/fill-path.js.map +0 -1
- package/esm/path/format-path.d.ts +0 -1
- package/esm/path/format-path.js +0 -139
- package/esm/path/format-path.js.map +0 -1
- package/esm/path/get-arc-params.d.ts +0 -17
- package/esm/path/get-arc-params.js +0 -90
- package/esm/path/get-arc-params.js.map +0 -1
- package/esm/path/get-line-intersect.d.ts +0 -14
- package/esm/path/get-line-intersect.js +0 -33
- package/esm/path/get-line-intersect.js.map +0 -1
- package/esm/path/is-polygons-intersect.d.ts +0 -1
- package/esm/path/is-polygons-intersect.js +0 -81
- package/esm/path/is-polygons-intersect.js.map +0 -1
- package/esm/path/parse-path-array.d.ts +0 -1
- package/esm/path/parse-path-array.js +0 -5
- package/esm/path/parse-path-array.js.map +0 -1
- package/esm/path/parse-path-string.d.ts +0 -1
- package/esm/path/parse-path-string.js +0 -57
- package/esm/path/parse-path-string.js.map +0 -1
- package/esm/path/parse-path.d.ts +0 -1
- package/esm/path/parse-path.js +0 -33
- package/esm/path/parse-path.js.map +0 -1
- package/esm/path/path-2-absolute.d.ts +0 -1
- package/esm/path/path-2-absolute.js +0 -124
- package/esm/path/path-2-absolute.js.map +0 -1
- package/esm/path/path-2-curve.d.ts +0 -2
- package/esm/path/path-2-curve.js +0 -63
- package/esm/path/path-2-curve.js.map +0 -1
- package/esm/path/path-2-segments.d.ts +0 -1
- package/esm/path/path-2-segments.js +0 -138
- package/esm/path/path-2-segments.js.map +0 -1
- package/esm/path/path-intersection.d.ts +0 -9
- package/esm/path/path-intersection.js +0 -366
- package/esm/path/path-intersection.js.map +0 -1
- package/esm/path/point-in-polygon.d.ts +0 -5
- package/esm/path/point-in-polygon.js +0 -49
- package/esm/path/point-in-polygon.js.map +0 -1
- package/esm/path/rect-path.d.ts +0 -4
- package/esm/path/rect-path.js +0 -19
- package/esm/path/rect-path.js.map +0 -1
- package/lib/path/catmull-rom-2-bezier.d.ts +0 -10
- package/lib/path/catmull-rom-2-bezier.js +0 -119
- package/lib/path/catmull-rom-2-bezier.js.map +0 -1
- package/lib/path/fill-path-by-diff.d.ts +0 -5
- package/lib/path/fill-path-by-diff.js +0 -117
- package/lib/path/fill-path-by-diff.js.map +0 -1
- package/lib/path/fill-path.d.ts +0 -1
- package/lib/path/fill-path.js +0 -133
- package/lib/path/fill-path.js.map +0 -1
- package/lib/path/format-path.d.ts +0 -1
- package/lib/path/format-path.js +0 -143
- package/lib/path/format-path.js.map +0 -1
- package/lib/path/get-arc-params.d.ts +0 -17
- package/lib/path/get-arc-params.js +0 -95
- package/lib/path/get-arc-params.js.map +0 -1
- package/lib/path/get-line-intersect.d.ts +0 -14
- package/lib/path/get-line-intersect.js +0 -37
- package/lib/path/get-line-intersect.js.map +0 -1
- package/lib/path/is-polygons-intersect.d.ts +0 -1
- package/lib/path/is-polygons-intersect.js +0 -85
- package/lib/path/is-polygons-intersect.js.map +0 -1
- package/lib/path/parse-path-array.d.ts +0 -1
- package/lib/path/parse-path-array.js +0 -9
- package/lib/path/parse-path-array.js.map +0 -1
- package/lib/path/parse-path-string.d.ts +0 -1
- package/lib/path/parse-path-string.js +0 -61
- package/lib/path/parse-path-string.js.map +0 -1
- package/lib/path/parse-path.d.ts +0 -1
- package/lib/path/parse-path.js +0 -37
- package/lib/path/parse-path.js.map +0 -1
- package/lib/path/path-2-absolute.d.ts +0 -1
- package/lib/path/path-2-absolute.js +0 -128
- package/lib/path/path-2-absolute.js.map +0 -1
- package/lib/path/path-2-curve.d.ts +0 -2
- package/lib/path/path-2-curve.js +0 -67
- package/lib/path/path-2-curve.js.map +0 -1
- package/lib/path/path-2-segments.d.ts +0 -1
- package/lib/path/path-2-segments.js +0 -142
- package/lib/path/path-2-segments.js.map +0 -1
- package/lib/path/path-intersection.d.ts +0 -9
- package/lib/path/path-intersection.js +0 -370
- package/lib/path/path-intersection.js.map +0 -1
- package/lib/path/point-in-polygon.d.ts +0 -5
- package/lib/path/point-in-polygon.js +0 -53
- package/lib/path/point-in-polygon.js.map +0 -1
- package/lib/path/rect-path.d.ts +0 -4
- package/lib/path/rect-path.js +0 -23
- package/lib/path/rect-path.js.map +0 -1
- package/src/path/catmull-rom-2-bezier.ts +0 -141
- package/src/path/fill-path-by-diff.ts +0 -116
- package/src/path/fill-path.ts +0 -129
- package/src/path/format-path.ts +0 -142
- package/src/path/get-arc-params.ts +0 -102
- package/src/path/get-line-intersect.ts +0 -46
- package/src/path/is-polygons-intersect.ts +0 -95
- package/src/path/parse-path-array.ts +0 -5
- package/src/path/parse-path-string.ts +0 -62
- package/src/path/parse-path.ts +0 -34
- package/src/path/path-2-absolute.ts +0 -132
- package/src/path/path-2-curve.ts +0 -69
- package/src/path/path-2-segments.ts +0 -142
- package/src/path/path-intersection.ts +0 -419
- package/src/path/point-in-polygon.ts +0 -56
- package/src/path/rect-path.ts +0 -22
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { PathArray, PathSegment, SegmentProperties } from '../types';
|
|
2
|
+
import { parsePathString } from '../parser/parse-path-string';
|
|
3
|
+
import { getTotalLength } from './get-total-length';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the segment, its index and length as well as
|
|
7
|
+
* the length to that segment at a given length in a path.
|
|
8
|
+
*/
|
|
9
|
+
export function getPropertiesAtLength(pathInput: string | PathArray, distance?: number): SegmentProperties {
|
|
10
|
+
const pathArray = parsePathString(pathInput);
|
|
11
|
+
|
|
12
|
+
if (typeof pathArray === 'string') {
|
|
13
|
+
throw TypeError(pathArray);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let pathTemp: PathArray = [...pathArray];
|
|
17
|
+
let pathLength = getTotalLength(pathTemp);
|
|
18
|
+
let index = pathTemp.length - 1;
|
|
19
|
+
let lengthAtSegment = 0;
|
|
20
|
+
let length = 0;
|
|
21
|
+
let segment: PathSegment = pathArray[0];
|
|
22
|
+
const [x, y] = segment.slice(-2);
|
|
23
|
+
const point = { x, y };
|
|
24
|
+
|
|
25
|
+
// If the path is empty, return 0.
|
|
26
|
+
if (index <= 0 || !distance || !Number.isFinite(distance)) {
|
|
27
|
+
return {
|
|
28
|
+
segment,
|
|
29
|
+
index: 0,
|
|
30
|
+
length,
|
|
31
|
+
point,
|
|
32
|
+
lengthAtSegment,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (distance >= pathLength) {
|
|
37
|
+
pathTemp = pathArray.slice(0, -1) as PathArray;
|
|
38
|
+
lengthAtSegment = getTotalLength(pathTemp);
|
|
39
|
+
length = pathLength - lengthAtSegment;
|
|
40
|
+
return {
|
|
41
|
+
segment: pathArray[index],
|
|
42
|
+
index,
|
|
43
|
+
length,
|
|
44
|
+
lengthAtSegment,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const segments = [];
|
|
49
|
+
while (index > 0) {
|
|
50
|
+
segment = pathTemp[index];
|
|
51
|
+
pathTemp = pathTemp.slice(0, -1) as PathArray;
|
|
52
|
+
lengthAtSegment = getTotalLength(pathTemp);
|
|
53
|
+
length = pathLength - lengthAtSegment;
|
|
54
|
+
pathLength = lengthAtSegment;
|
|
55
|
+
segments.push({
|
|
56
|
+
segment,
|
|
57
|
+
index,
|
|
58
|
+
length,
|
|
59
|
+
lengthAtSegment,
|
|
60
|
+
});
|
|
61
|
+
index -= 1;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return segments.find(({ lengthAtSegment: l }) => l <= distance);
|
|
65
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import type { Point, PathArray, PointProperties } from '../types';
|
|
2
|
+
import { parsePathString } from '../parser/parse-path-string';
|
|
3
|
+
import { normalizePath } from '../process/normalize-path';
|
|
4
|
+
import { getPointAtLength } from './get-point-at-length';
|
|
5
|
+
import { getPropertiesAtLength } from './get-properties-at-length';
|
|
6
|
+
import { getTotalLength } from './get-total-length';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns the point and segment in path closest to a given point as well as
|
|
10
|
+
* the distance to the path stroke.
|
|
11
|
+
* @see https://bl.ocks.org/mbostock/8027637
|
|
12
|
+
*/
|
|
13
|
+
export function getPropertiesAtPoint(pathInput: string | PathArray, point: Point): PointProperties {
|
|
14
|
+
const path = parsePathString(pathInput);
|
|
15
|
+
const normalPath = normalizePath(path);
|
|
16
|
+
const pathLength = getTotalLength(path);
|
|
17
|
+
const distanceTo = (p: Point) => {
|
|
18
|
+
const dx = p.x - point.x;
|
|
19
|
+
const dy = p.y - point.y;
|
|
20
|
+
return dx * dx + dy * dy;
|
|
21
|
+
};
|
|
22
|
+
let precision = 8;
|
|
23
|
+
let scan: Point;
|
|
24
|
+
let scanDistance = 0;
|
|
25
|
+
let closest: Point;
|
|
26
|
+
let bestLength = 0;
|
|
27
|
+
let bestDistance = Infinity;
|
|
28
|
+
|
|
29
|
+
// linear scan for coarse approximation
|
|
30
|
+
for (let scanLength = 0; scanLength <= pathLength; scanLength += precision) {
|
|
31
|
+
scan = getPointAtLength(normalPath, scanLength);
|
|
32
|
+
scanDistance = distanceTo(scan);
|
|
33
|
+
if (scanDistance < bestDistance) {
|
|
34
|
+
closest = scan;
|
|
35
|
+
bestLength = scanLength;
|
|
36
|
+
bestDistance = scanDistance;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// binary search for precise estimate
|
|
41
|
+
precision /= 2;
|
|
42
|
+
let before: Point;
|
|
43
|
+
let after: Point;
|
|
44
|
+
let beforeLength = 0;
|
|
45
|
+
let afterLength = 0;
|
|
46
|
+
let beforeDistance = 0;
|
|
47
|
+
let afterDistance = 0;
|
|
48
|
+
|
|
49
|
+
while (precision > 0.5) {
|
|
50
|
+
beforeLength = bestLength - precision;
|
|
51
|
+
before = getPointAtLength(normalPath, beforeLength);
|
|
52
|
+
beforeDistance = distanceTo(before);
|
|
53
|
+
afterLength = bestLength + precision;
|
|
54
|
+
after = getPointAtLength(normalPath, afterLength);
|
|
55
|
+
afterDistance = distanceTo(after);
|
|
56
|
+
if (beforeLength >= 0 && beforeDistance < bestDistance) {
|
|
57
|
+
closest = before;
|
|
58
|
+
bestLength = beforeLength;
|
|
59
|
+
bestDistance = beforeDistance;
|
|
60
|
+
} else if (afterLength <= pathLength && afterDistance < bestDistance) {
|
|
61
|
+
closest = after;
|
|
62
|
+
bestLength = afterLength;
|
|
63
|
+
bestDistance = afterDistance;
|
|
64
|
+
} else {
|
|
65
|
+
precision /= 2;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const segment = getPropertiesAtLength(path, bestLength);
|
|
70
|
+
const distance = Math.sqrt(bestDistance);
|
|
71
|
+
|
|
72
|
+
return { closest, distance, segment };
|
|
73
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { CurveArray } from '../types';
|
|
2
|
+
import { distanceSquareRoot } from './distance-square-root';
|
|
3
|
+
|
|
4
|
+
function getRotations(a: CurveArray) {
|
|
5
|
+
const segCount = a.length;
|
|
6
|
+
const pointCount = segCount - 1;
|
|
7
|
+
|
|
8
|
+
return a.map((f, idx) =>
|
|
9
|
+
a.map((p, i) => {
|
|
10
|
+
let oldSegIdx = idx + i;
|
|
11
|
+
let seg;
|
|
12
|
+
|
|
13
|
+
if (i === 0 || (a[oldSegIdx] && a[oldSegIdx][0] === 'M')) {
|
|
14
|
+
seg = a[oldSegIdx];
|
|
15
|
+
return ['M'].concat(seg.slice(-2));
|
|
16
|
+
}
|
|
17
|
+
if (oldSegIdx >= segCount) oldSegIdx -= pointCount;
|
|
18
|
+
return a[oldSegIdx];
|
|
19
|
+
}),
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function getRotatedCurve(a: CurveArray, b: CurveArray) {
|
|
24
|
+
const segCount = a.length - 1;
|
|
25
|
+
const lineLengths: number[] = [];
|
|
26
|
+
let computedIndex = 0;
|
|
27
|
+
let sumLensSqrd = 0;
|
|
28
|
+
const rotations = getRotations(a);
|
|
29
|
+
|
|
30
|
+
rotations.forEach((r, i) => {
|
|
31
|
+
a.slice(1).forEach((s, j) => {
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
sumLensSqrd += distanceSquareRoot(a[(i + j) % segCount].slice(-2), b[j % segCount].slice(-2));
|
|
34
|
+
});
|
|
35
|
+
lineLengths[i] = sumLensSqrd;
|
|
36
|
+
sumLensSqrd = 0;
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
computedIndex = lineLengths.indexOf(Math.min.apply(null, lineLengths));
|
|
40
|
+
|
|
41
|
+
return rotations[computedIndex];
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PathArray } from '../types';
|
|
2
|
+
import { pathLengthFactory } from './path-length-factory';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the shape total length, or the equivalent to `shape.getTotalLength()`.
|
|
6
|
+
*
|
|
7
|
+
* The `normalizePath` version is lighter, faster, more efficient and more accurate
|
|
8
|
+
* with paths that are not `curveArray`.
|
|
9
|
+
*/
|
|
10
|
+
export function getTotalLength(pathInput: string | PathArray) {
|
|
11
|
+
return pathLengthFactory(pathInput).length;
|
|
12
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PathArray, AbsoluteArray } from '../types';
|
|
2
|
+
import { isPathArray } from './is-path-array';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Iterates an array to check if it's a `PathArray`
|
|
6
|
+
* with all absolute values.
|
|
7
|
+
*/
|
|
8
|
+
export function isAbsoluteArray(path: string | PathArray): path is AbsoluteArray {
|
|
9
|
+
return (
|
|
10
|
+
isPathArray(path) &&
|
|
11
|
+
// @ts-ignore -- `isPathArray` also checks if it's `Array`
|
|
12
|
+
path.every(([x]) => x === x.toUpperCase())
|
|
13
|
+
);
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { PathArray } from '../types';
|
|
2
|
+
import { isNormalizedArray } from './is-normalized-array';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Iterates an array to check if it's a `PathArray`
|
|
6
|
+
* with all C (cubic bezier) segments.
|
|
7
|
+
*
|
|
8
|
+
* @param {string | PathArray} path the `Array` to be checked
|
|
9
|
+
* @returns {boolean} iteration result
|
|
10
|
+
*/
|
|
11
|
+
export function isCurveArray(path: string | PathArray): path is PathArray {
|
|
12
|
+
return isNormalizedArray(path) && (path as PathArray).every(([pc]) => 'MC'.includes(pc));
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PathArray } from '../types';
|
|
2
|
+
import { isAbsoluteArray } from './is-absolute-array';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Iterates an array to check if it's a `PathArray`
|
|
6
|
+
* with all segments are in non-shorthand notation
|
|
7
|
+
* with absolute values.
|
|
8
|
+
*/
|
|
9
|
+
export function isNormalizedArray(path: string | PathArray): path is PathArray {
|
|
10
|
+
return isAbsoluteArray(path) && path.every(([pc]) => 'ACLMQZ'.includes(pc));
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { paramsCount } from '../parser/params-count';
|
|
2
|
+
import type { PathArray } from '../types';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Iterates an array to check if it's an actual `PathArray`.
|
|
6
|
+
*/
|
|
7
|
+
export function isPathArray(path: string | PathArray): path is PathArray {
|
|
8
|
+
return (
|
|
9
|
+
Array.isArray(path) &&
|
|
10
|
+
path.every((seg) => {
|
|
11
|
+
const lk = seg[0].toLowerCase();
|
|
12
|
+
return paramsCount[lk] === seg.length - 1 && 'achlmqstvz'.includes(lk);
|
|
13
|
+
})
|
|
14
|
+
);
|
|
15
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Point, PathArray } from '../types';
|
|
2
|
+
import { getPropertiesAtPoint } from './get-properties-at-point';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Checks if a given point is in the stroke of a path.
|
|
6
|
+
*/
|
|
7
|
+
export function isPointInStroke(pathInput: string | PathArray, point: Point) {
|
|
8
|
+
const { distance } = getPropertiesAtPoint(pathInput, point);
|
|
9
|
+
return Math.abs(distance) < 0.001; // 0.01 might be more permissive
|
|
10
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { normalizePath } from '../process/normalize-path';
|
|
2
|
+
import type { PathCommand, PathArray, LengthFactory } from '../types';
|
|
3
|
+
import { segmentLineFactory } from './segment-line-factory';
|
|
4
|
+
import { segmentArcFactory } from './segment-arc-factory';
|
|
5
|
+
import { segmentCubicFactory } from './segment-cubic-factory';
|
|
6
|
+
import { segmentQuadFactory } from './segment-quad-factory';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Returns a {x,y} point at a given length
|
|
10
|
+
* of a shape, the shape total length and
|
|
11
|
+
* the shape minimum and maximum {x,y} coordinates.
|
|
12
|
+
*/
|
|
13
|
+
export function pathLengthFactory(pathInput: string | PathArray, distance?: number): LengthFactory {
|
|
14
|
+
const path = normalizePath(pathInput);
|
|
15
|
+
const distanceIsNumber = typeof distance === 'number';
|
|
16
|
+
let isM: boolean;
|
|
17
|
+
let data: number[] = [];
|
|
18
|
+
let pathCommand: PathCommand;
|
|
19
|
+
let x = 0;
|
|
20
|
+
let y = 0;
|
|
21
|
+
let mx = 0;
|
|
22
|
+
let my = 0;
|
|
23
|
+
let seg;
|
|
24
|
+
let MIN = [];
|
|
25
|
+
let MAX = [];
|
|
26
|
+
let length = 0;
|
|
27
|
+
let min = { x: 0, y: 0 };
|
|
28
|
+
let max = min;
|
|
29
|
+
let point = min;
|
|
30
|
+
let POINT = min;
|
|
31
|
+
let LENGTH = 0;
|
|
32
|
+
|
|
33
|
+
for (let i = 0, ll = path.length; i < ll; i += 1) {
|
|
34
|
+
seg = path[i];
|
|
35
|
+
[pathCommand] = seg;
|
|
36
|
+
isM = pathCommand === 'M';
|
|
37
|
+
data = !isM ? [x, y, ...seg.slice(1)] : data;
|
|
38
|
+
|
|
39
|
+
// this segment is always ZERO
|
|
40
|
+
/* istanbul ignore else */
|
|
41
|
+
if (isM) {
|
|
42
|
+
// remember mx, my for Z
|
|
43
|
+
[, mx, my] = seg;
|
|
44
|
+
min = { x: mx, y: my };
|
|
45
|
+
max = min;
|
|
46
|
+
length = 0;
|
|
47
|
+
|
|
48
|
+
if (distanceIsNumber && distance < 0.001) {
|
|
49
|
+
POINT = min;
|
|
50
|
+
}
|
|
51
|
+
} else if (pathCommand === 'L') {
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
({ length, min, max, point } = segmentLineFactory(...data, (distance || 0) - LENGTH));
|
|
54
|
+
} else if (pathCommand === 'A') {
|
|
55
|
+
// @ts-ignore
|
|
56
|
+
({ length, min, max, point } = segmentArcFactory(...data, (distance || 0) - LENGTH));
|
|
57
|
+
} else if (pathCommand === 'C') {
|
|
58
|
+
// @ts-ignore
|
|
59
|
+
({ length, min, max, point } = segmentCubicFactory(...data, (distance || 0) - LENGTH));
|
|
60
|
+
} else if (pathCommand === 'Q') {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
({ length, min, max, point } = segmentQuadFactory(...data, (distance || 0) - LENGTH));
|
|
63
|
+
} else if (pathCommand === 'Z') {
|
|
64
|
+
data = [x, y, mx, my];
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
({ length, min, max, point } = segmentLineFactory(...data, (distance || 0) - LENGTH));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (distanceIsNumber && LENGTH < distance && LENGTH + length >= distance) {
|
|
70
|
+
POINT = point;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
MAX = [...MAX, max];
|
|
74
|
+
MIN = [...MIN, min];
|
|
75
|
+
LENGTH += length;
|
|
76
|
+
|
|
77
|
+
[x, y] = pathCommand !== 'Z' ? seg.slice(-2) : [mx, my];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// native `getPointAtLength` behavior when the given distance
|
|
81
|
+
// is higher than total length
|
|
82
|
+
if (distanceIsNumber && distance >= LENGTH) {
|
|
83
|
+
POINT = { x, y };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
length: LENGTH,
|
|
88
|
+
point: POINT,
|
|
89
|
+
min: {
|
|
90
|
+
x: Math.min(...MIN.map((n) => n.x)),
|
|
91
|
+
y: Math.min(...MIN.map((n) => n.y)),
|
|
92
|
+
},
|
|
93
|
+
max: {
|
|
94
|
+
x: Math.max(...MAX.map((n) => n.x)),
|
|
95
|
+
y: Math.max(...MAX.map((n) => n.y)),
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import type { Point, LengthFactory } from '../types';
|
|
2
|
+
import { segmentLineFactory } from './segment-line-factory';
|
|
3
|
+
import { distanceSquareRoot } from './distance-square-root';
|
|
4
|
+
|
|
5
|
+
function angleBetween(v0: Point, v1: Point) {
|
|
6
|
+
const { x: v0x, y: v0y } = v0;
|
|
7
|
+
const { x: v1x, y: v1y } = v1;
|
|
8
|
+
const p = v0x * v1x + v0y * v1y;
|
|
9
|
+
const n = Math.sqrt((v0x ** 2 + v0y ** 2) * (v1x ** 2 + v1y ** 2));
|
|
10
|
+
const sign = v0x * v1y - v0y * v1x < 0 ? -1 : 1;
|
|
11
|
+
const angle = sign * Math.acos(p / n);
|
|
12
|
+
|
|
13
|
+
return angle;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Returns a {x,y} point at a given length, the total length and
|
|
18
|
+
* the minimum and maximum {x,y} coordinates of a C (cubic-bezier) segment.
|
|
19
|
+
* @see https://github.com/MadLittleMods/svg-curve-lib/blob/master/src/js/svg-curve-lib.js
|
|
20
|
+
*/
|
|
21
|
+
function getPointAtArcSegmentLength(
|
|
22
|
+
x1: number,
|
|
23
|
+
y1: number,
|
|
24
|
+
RX: number,
|
|
25
|
+
RY: number,
|
|
26
|
+
angle: number,
|
|
27
|
+
LAF: number,
|
|
28
|
+
SF: number,
|
|
29
|
+
x: number,
|
|
30
|
+
y: number,
|
|
31
|
+
t: number,
|
|
32
|
+
) {
|
|
33
|
+
const { abs, sin, cos, sqrt, PI } = Math;
|
|
34
|
+
let rx = abs(RX);
|
|
35
|
+
let ry = abs(RY);
|
|
36
|
+
const xRot = ((angle % 360) + 360) % 360;
|
|
37
|
+
const xRotRad = xRot * (PI / 180);
|
|
38
|
+
|
|
39
|
+
if (x1 === x && y1 === y) {
|
|
40
|
+
return { x: x1, y: y1 };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (rx === 0 || ry === 0) {
|
|
44
|
+
return segmentLineFactory(x1, y1, x, y, t).point;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const dx = (x1 - x) / 2;
|
|
48
|
+
const dy = (y1 - y) / 2;
|
|
49
|
+
|
|
50
|
+
const transformedPoint = {
|
|
51
|
+
x: cos(xRotRad) * dx + sin(xRotRad) * dy,
|
|
52
|
+
y: -sin(xRotRad) * dx + cos(xRotRad) * dy,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const radiiCheck = transformedPoint.x ** 2 / rx ** 2 + transformedPoint.y ** 2 / ry ** 2;
|
|
56
|
+
|
|
57
|
+
if (radiiCheck > 1) {
|
|
58
|
+
rx *= sqrt(radiiCheck);
|
|
59
|
+
ry *= sqrt(radiiCheck);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const cSquareNumerator = rx ** 2 * ry ** 2 - rx ** 2 * transformedPoint.y ** 2 - ry ** 2 * transformedPoint.x ** 2;
|
|
63
|
+
|
|
64
|
+
const cSquareRootDenom = rx ** 2 * transformedPoint.y ** 2 + ry ** 2 * transformedPoint.x ** 2;
|
|
65
|
+
|
|
66
|
+
let cRadicand = cSquareNumerator / cSquareRootDenom;
|
|
67
|
+
cRadicand = cRadicand < 0 ? 0 : cRadicand;
|
|
68
|
+
const cCoef = (LAF !== SF ? 1 : -1) * sqrt(cRadicand);
|
|
69
|
+
const transformedCenter = {
|
|
70
|
+
x: cCoef * ((rx * transformedPoint.y) / ry),
|
|
71
|
+
y: cCoef * (-(ry * transformedPoint.x) / rx),
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const center = {
|
|
75
|
+
x: cos(xRotRad) * transformedCenter.x - sin(xRotRad) * transformedCenter.y + (x1 + x) / 2,
|
|
76
|
+
y: sin(xRotRad) * transformedCenter.x + cos(xRotRad) * transformedCenter.y + (y1 + y) / 2,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const startVector = {
|
|
80
|
+
x: (transformedPoint.x - transformedCenter.x) / rx,
|
|
81
|
+
y: (transformedPoint.y - transformedCenter.y) / ry,
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const startAngle = angleBetween({ x: 1, y: 0 }, startVector);
|
|
85
|
+
|
|
86
|
+
const endVector = {
|
|
87
|
+
x: (-transformedPoint.x - transformedCenter.x) / rx,
|
|
88
|
+
y: (-transformedPoint.y - transformedCenter.y) / ry,
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
let sweepAngle = angleBetween(startVector, endVector);
|
|
92
|
+
if (!SF && sweepAngle > 0) {
|
|
93
|
+
sweepAngle -= 2 * PI;
|
|
94
|
+
} else if (SF && sweepAngle < 0) {
|
|
95
|
+
sweepAngle += 2 * PI;
|
|
96
|
+
}
|
|
97
|
+
sweepAngle %= 2 * PI;
|
|
98
|
+
|
|
99
|
+
const alpha = startAngle + sweepAngle * t;
|
|
100
|
+
const ellipseComponentX = rx * cos(alpha);
|
|
101
|
+
const ellipseComponentY = ry * sin(alpha);
|
|
102
|
+
|
|
103
|
+
const point = {
|
|
104
|
+
x: cos(xRotRad) * ellipseComponentX - sin(xRotRad) * ellipseComponentY + center.x,
|
|
105
|
+
y: sin(xRotRad) * ellipseComponentX + cos(xRotRad) * ellipseComponentY + center.y,
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
// to be used later
|
|
109
|
+
// point.ellipticalArcStartAngle = startAngle;
|
|
110
|
+
// point.ellipticalArcEndAngle = startAngle + sweepAngle;
|
|
111
|
+
// point.ellipticalArcAngle = alpha;
|
|
112
|
+
|
|
113
|
+
// point.ellipticalArcCenter = center;
|
|
114
|
+
// point.resultantRx = rx;
|
|
115
|
+
// point.resultantRy = ry;
|
|
116
|
+
|
|
117
|
+
return point;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Returns a {x,y} point at a given length, the total length and
|
|
122
|
+
* the shape minimum and maximum {x,y} coordinates of an A (arc-to) segment.
|
|
123
|
+
*/
|
|
124
|
+
export function segmentArcFactory(
|
|
125
|
+
X1: number,
|
|
126
|
+
Y1: number,
|
|
127
|
+
RX: number,
|
|
128
|
+
RY: number,
|
|
129
|
+
angle: number,
|
|
130
|
+
LAF: number,
|
|
131
|
+
SF: number,
|
|
132
|
+
X2: number,
|
|
133
|
+
Y2: number,
|
|
134
|
+
distance: number,
|
|
135
|
+
): LengthFactory {
|
|
136
|
+
const distanceIsNumber = typeof distance === 'number';
|
|
137
|
+
let x = X1;
|
|
138
|
+
let y = Y1;
|
|
139
|
+
let LENGTH = 0;
|
|
140
|
+
let prev = [x, y, LENGTH];
|
|
141
|
+
let cur: [number, number] = [x, y];
|
|
142
|
+
let t = 0;
|
|
143
|
+
let POINT = { x: 0, y: 0 };
|
|
144
|
+
let POINTS = [{ x, y }];
|
|
145
|
+
|
|
146
|
+
if (distanceIsNumber && distance === 0) {
|
|
147
|
+
POINT = { x, y };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const sampleSize = 300;
|
|
151
|
+
for (let j = 0; j <= sampleSize; j += 1) {
|
|
152
|
+
t = j / sampleSize;
|
|
153
|
+
|
|
154
|
+
({ x, y } = getPointAtArcSegmentLength(X1, Y1, RX, RY, angle, LAF, SF, X2, Y2, t));
|
|
155
|
+
POINTS = [...POINTS, { x, y }];
|
|
156
|
+
LENGTH += distanceSquareRoot(cur, [x, y]);
|
|
157
|
+
cur = [x, y];
|
|
158
|
+
|
|
159
|
+
if (distanceIsNumber && LENGTH > distance && distance > prev[2]) {
|
|
160
|
+
const dv = (LENGTH - distance) / (LENGTH - prev[2]);
|
|
161
|
+
|
|
162
|
+
POINT = {
|
|
163
|
+
x: cur[0] * (1 - dv) + prev[0] * dv,
|
|
164
|
+
y: cur[1] * (1 - dv) + prev[1] * dv,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
prev = [x, y, LENGTH];
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (distanceIsNumber && distance >= LENGTH) {
|
|
171
|
+
POINT = { x: X2, y: Y2 };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return {
|
|
175
|
+
length: LENGTH,
|
|
176
|
+
point: POINT,
|
|
177
|
+
min: {
|
|
178
|
+
x: Math.min(...POINTS.map((n) => n.x)),
|
|
179
|
+
y: Math.min(...POINTS.map((n) => n.y)),
|
|
180
|
+
},
|
|
181
|
+
max: {
|
|
182
|
+
x: Math.max(...POINTS.map((n) => n.x)),
|
|
183
|
+
y: Math.max(...POINTS.map((n) => n.y)),
|
|
184
|
+
},
|
|
185
|
+
};
|
|
186
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { LengthFactory } from '../types';
|
|
2
|
+
import { distanceSquareRoot } from './distance-square-root';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns a {x,y} point at a given length, the total length and
|
|
6
|
+
* the minimum and maximum {x,y} coordinates of a C (cubic-bezier) segment.
|
|
7
|
+
*/
|
|
8
|
+
function getPointAtCubicSegmentLength(
|
|
9
|
+
x1: number,
|
|
10
|
+
y1: number,
|
|
11
|
+
c1x: number,
|
|
12
|
+
c1y: number,
|
|
13
|
+
c2x: number,
|
|
14
|
+
c2y: number,
|
|
15
|
+
x2: number,
|
|
16
|
+
y2: number,
|
|
17
|
+
t: number,
|
|
18
|
+
) {
|
|
19
|
+
const t1 = 1 - t;
|
|
20
|
+
return {
|
|
21
|
+
x: t1 ** 3 * x1 + 3 * t1 ** 2 * t * c1x + 3 * t1 * t ** 2 * c2x + t ** 3 * x2,
|
|
22
|
+
y: t1 ** 3 * y1 + 3 * t1 ** 2 * t * c1y + 3 * t1 * t ** 2 * c2y + t ** 3 * y2,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Returns the length of a C (cubic-bezier) segment
|
|
28
|
+
* or an {x,y} point at a given length.
|
|
29
|
+
*/
|
|
30
|
+
export function segmentCubicFactory(
|
|
31
|
+
x1: number,
|
|
32
|
+
y1: number,
|
|
33
|
+
c1x: number,
|
|
34
|
+
c1y: number,
|
|
35
|
+
c2x: number,
|
|
36
|
+
c2y: number,
|
|
37
|
+
x2: number,
|
|
38
|
+
y2: number,
|
|
39
|
+
distance: number,
|
|
40
|
+
): LengthFactory {
|
|
41
|
+
const distanceIsNumber = typeof distance === 'number';
|
|
42
|
+
let x = x1;
|
|
43
|
+
let y = y1;
|
|
44
|
+
let LENGTH = 0;
|
|
45
|
+
let prev = [x, y, LENGTH];
|
|
46
|
+
let cur: [number, number] = [x, y];
|
|
47
|
+
let t = 0;
|
|
48
|
+
let POINT = { x: 0, y: 0 };
|
|
49
|
+
let POINTS = [{ x, y }];
|
|
50
|
+
|
|
51
|
+
if (distanceIsNumber && distance === 0) {
|
|
52
|
+
POINT = { x, y };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// bad perf when size = 300
|
|
56
|
+
const sampleSize = 20;
|
|
57
|
+
for (let j = 0; j <= sampleSize; j += 1) {
|
|
58
|
+
t = j / sampleSize;
|
|
59
|
+
|
|
60
|
+
({ x, y } = getPointAtCubicSegmentLength(x1, y1, c1x, c1y, c2x, c2y, x2, y2, t));
|
|
61
|
+
POINTS = [...POINTS, { x, y }];
|
|
62
|
+
LENGTH += distanceSquareRoot(cur, [x, y]);
|
|
63
|
+
cur = [x, y];
|
|
64
|
+
|
|
65
|
+
if (distanceIsNumber && LENGTH > distance && distance > prev[2]) {
|
|
66
|
+
const dv = (LENGTH - distance) / (LENGTH - prev[2]);
|
|
67
|
+
|
|
68
|
+
POINT = {
|
|
69
|
+
x: cur[0] * (1 - dv) + prev[0] * dv,
|
|
70
|
+
y: cur[1] * (1 - dv) + prev[1] * dv,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
prev = [x, y, LENGTH];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (distanceIsNumber && distance >= LENGTH) {
|
|
77
|
+
POINT = { x: x2, y: y2 };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
length: LENGTH,
|
|
82
|
+
point: POINT,
|
|
83
|
+
min: {
|
|
84
|
+
x: Math.min(...POINTS.map((n) => n.x)),
|
|
85
|
+
y: Math.min(...POINTS.map((n) => n.y)),
|
|
86
|
+
},
|
|
87
|
+
max: {
|
|
88
|
+
x: Math.max(...POINTS.map((n) => n.x)),
|
|
89
|
+
y: Math.max(...POINTS.map((n) => n.y)),
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { LengthFactory } from '../types';
|
|
2
|
+
import { midPoint } from './mid-point';
|
|
3
|
+
import { distanceSquareRoot } from './distance-square-root';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns a {x,y} point at a given length, the total length and
|
|
7
|
+
* the minimum and maximum {x,y} coordinates of a line (L,V,H,Z) segment.
|
|
8
|
+
*/
|
|
9
|
+
export function segmentLineFactory(x1: number, y1: number, x2: number, y2: number, distance: number): LengthFactory {
|
|
10
|
+
const length = distanceSquareRoot([x1, y1], [x2, y2]);
|
|
11
|
+
let point = { x: 0, y: 0 };
|
|
12
|
+
|
|
13
|
+
if (typeof distance === 'number') {
|
|
14
|
+
if (distance <= 0) {
|
|
15
|
+
point = { x: x1, y: y1 };
|
|
16
|
+
} else if (distance >= length) {
|
|
17
|
+
point = { x: x2, y: y2 };
|
|
18
|
+
} else {
|
|
19
|
+
const [x, y] = midPoint([x1, y1], [x2, y2], distance / length);
|
|
20
|
+
point = { x, y };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
length,
|
|
26
|
+
point,
|
|
27
|
+
min: {
|
|
28
|
+
x: Math.min(x1, x2),
|
|
29
|
+
y: Math.min(y1, y2),
|
|
30
|
+
},
|
|
31
|
+
max: {
|
|
32
|
+
x: Math.max(x1, x2),
|
|
33
|
+
y: Math.max(y1, y2),
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|