@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,42 @@
|
|
|
1
|
+
import type { PathSegment, NormalSegment, CSegment, QSegment } from '../types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Normalizes a single segment of a `PathArray` object.
|
|
5
|
+
* eg. H/V -> L, T -> Q
|
|
6
|
+
*/
|
|
7
|
+
export function normalizeSegment(segment: PathSegment, params: any): NormalSegment {
|
|
8
|
+
const [pathCommand] = segment;
|
|
9
|
+
const { x1: px1, y1: py1, x2: px2, y2: py2 } = params;
|
|
10
|
+
const values = segment.slice(1).map(Number);
|
|
11
|
+
let result = segment;
|
|
12
|
+
|
|
13
|
+
if (!'TQ'.includes(pathCommand)) {
|
|
14
|
+
// optional but good to be cautious
|
|
15
|
+
params.qx = null;
|
|
16
|
+
params.qy = null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (pathCommand === 'H') {
|
|
20
|
+
result = ['L', segment[1], py1];
|
|
21
|
+
} else if (pathCommand === 'V') {
|
|
22
|
+
result = ['L', px1, segment[1]];
|
|
23
|
+
} else if (pathCommand === 'S') {
|
|
24
|
+
const x1 = px1 * 2 - px2;
|
|
25
|
+
const y1 = py1 * 2 - py2;
|
|
26
|
+
params.x1 = x1;
|
|
27
|
+
params.y1 = y1;
|
|
28
|
+
result = ['C', x1, y1, ...values] as CSegment;
|
|
29
|
+
} else if (pathCommand === 'T') {
|
|
30
|
+
const qx = px1 * 2 - params.qx;
|
|
31
|
+
const qy = py1 * 2 - params.qy;
|
|
32
|
+
params.qx = qx;
|
|
33
|
+
params.qy = qy;
|
|
34
|
+
result = ['Q', qx, qy, ...values] as QSegment;
|
|
35
|
+
} else if (pathCommand === 'Q') {
|
|
36
|
+
const [nqx, nqy] = values;
|
|
37
|
+
params.qx = nqx;
|
|
38
|
+
params.qy = nqy;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return result as NormalSegment;
|
|
42
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CurveArray } from '../types';
|
|
2
|
+
|
|
3
|
+
// reverse CURVE based pathArray segments only
|
|
4
|
+
export function reverseCurve(pathArray: CurveArray): CurveArray {
|
|
5
|
+
const rotatedCurve = pathArray
|
|
6
|
+
.slice(1)
|
|
7
|
+
.map((x, i, curveOnly) =>
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
!i ? pathArray[0].slice(1).concat(x.slice(1)) : curveOnly[i - 1].slice(-2).concat(x.slice(1)),
|
|
10
|
+
)
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
.map((x) => x.map((y, i) => x[x.length - i - 2 * (1 - (i % 2))]))
|
|
13
|
+
.reverse();
|
|
14
|
+
|
|
15
|
+
return [['M'].concat(rotatedCurve[0].slice(0, 2))].concat(
|
|
16
|
+
rotatedCurve.map((x) => ['C'].concat(x.slice(2))),
|
|
17
|
+
) as CurveArray;
|
|
18
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { PathArray } from '../types';
|
|
2
|
+
import { clonePath } from './clone-path';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Rounds the values of a `PathArray` instance to
|
|
6
|
+
* a specified amount of decimals and returns it.
|
|
7
|
+
*/
|
|
8
|
+
export function roundPath(path: PathArray, round: number | 'off'): PathArray {
|
|
9
|
+
if (round === 'off') return clonePath(path) as PathArray;
|
|
10
|
+
|
|
11
|
+
// to round values to the power
|
|
12
|
+
// the `round` value must be integer
|
|
13
|
+
const pow = typeof round === 'number' && round >= 1 ? 10 ** round : 1;
|
|
14
|
+
|
|
15
|
+
return path.map((pi) => {
|
|
16
|
+
const values = pi
|
|
17
|
+
.slice(1)
|
|
18
|
+
.map(Number)
|
|
19
|
+
.map((n) => (round ? Math.round(n * pow) / pow : Math.round(n)));
|
|
20
|
+
return [pi[0], ...values];
|
|
21
|
+
}) as PathArray;
|
|
22
|
+
}
|
|
@@ -1,44 +1,45 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PathSegment, ParserParams, CSegment, MSegment } from '../types';
|
|
2
2
|
import { arcToCubic } from './arc-2-cubic';
|
|
3
3
|
import { quadToCubic } from './quad-2-cubic';
|
|
4
4
|
import { lineToCubic } from './line-2-cubic';
|
|
5
5
|
|
|
6
|
-
export function segmentToCubic(segment:
|
|
7
|
-
|
|
6
|
+
export function segmentToCubic(segment: PathSegment, params: ParserParams): CSegment | MSegment {
|
|
7
|
+
const [pathCommand] = segment;
|
|
8
|
+
const values = segment.slice(1).map(Number);
|
|
9
|
+
const [x, y] = values;
|
|
10
|
+
let args: any[];
|
|
11
|
+
const { x1: px1, y1: py1, x: px, y: py } = params;
|
|
12
|
+
|
|
13
|
+
if (!'TQ'.includes(pathCommand)) {
|
|
8
14
|
params.qx = null;
|
|
9
15
|
params.qy = null;
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
switch (segment[0]) {
|
|
18
|
+
switch (pathCommand) {
|
|
15
19
|
case 'M':
|
|
16
|
-
params.x =
|
|
17
|
-
params.y =
|
|
20
|
+
params.x = x;
|
|
21
|
+
params.y = y;
|
|
18
22
|
return segment;
|
|
19
23
|
case 'A':
|
|
20
|
-
|
|
21
|
-
arcToCubic.apply(0, [params.x1, params.y1].concat(segment.slice(1) as number[])),
|
|
22
|
-
) as PathCommand;
|
|
23
|
-
case 'Q':
|
|
24
|
-
params.qx = s1 as number;
|
|
25
|
-
params.qy = s2 as number;
|
|
26
|
-
return ['C'].concat(
|
|
27
|
-
quadToCubic.apply(0, [params.x1, params.y1].concat(segment.slice(1) as number[])),
|
|
28
|
-
) as PathCommand;
|
|
29
|
-
case 'L':
|
|
30
|
-
// @ts-ignore
|
|
31
|
-
return ['C'].concat(lineToCubic(params.x1, params.y1, segment[1], segment[2])) as PathCommand;
|
|
32
|
-
case 'H':
|
|
24
|
+
args = [px1, py1, ...values];
|
|
33
25
|
// @ts-ignore
|
|
34
|
-
return ['C'
|
|
35
|
-
case '
|
|
26
|
+
return ['C', ...arcToCubic(...args)] as CubicSegment;
|
|
27
|
+
case 'Q':
|
|
28
|
+
params.qx = x;
|
|
29
|
+
params.qy = y;
|
|
30
|
+
args = [px1, py1, ...values];
|
|
36
31
|
// @ts-ignore
|
|
37
|
-
return ['C'
|
|
32
|
+
return ['C', ...quadToCubic(...args)] as CubicSegment;
|
|
33
|
+
case 'L':
|
|
34
|
+
return ['C', ...lineToCubic(px1, py1, x, y)] as CSegment;
|
|
38
35
|
case 'Z':
|
|
39
|
-
//
|
|
40
|
-
|
|
36
|
+
// prevent NaN from divide 0
|
|
37
|
+
if (px1 === px && py1 === py) {
|
|
38
|
+
return ['C', px1, py1, px, py, px, py];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return ['C', ...lineToCubic(px1, py1, px, py)] as CSegment;
|
|
41
42
|
default:
|
|
42
43
|
}
|
|
43
|
-
return segment;
|
|
44
|
+
return segment as CSegment;
|
|
44
45
|
}
|
package/src/path/types.ts
CHANGED
|
@@ -1,19 +1,157 @@
|
|
|
1
|
-
type
|
|
2
|
-
type
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
type
|
|
7
|
-
|
|
8
|
-
type
|
|
9
|
-
type
|
|
10
|
-
|
|
11
|
-
type
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
export type
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
export type Point = { x: number; y: number };
|
|
2
|
+
export type MCommand = 'M';
|
|
3
|
+
export type mCommand = 'm';
|
|
4
|
+
|
|
5
|
+
export type LCommand = 'L';
|
|
6
|
+
export type lCommand = 'l';
|
|
7
|
+
|
|
8
|
+
export type VCommand = 'V';
|
|
9
|
+
export type vCommand = 'v';
|
|
10
|
+
|
|
11
|
+
export type HCommand = 'H';
|
|
12
|
+
export type hCommand = 'h';
|
|
13
|
+
|
|
14
|
+
export type ZCommand = 'Z';
|
|
15
|
+
export type zCommand = 'z';
|
|
16
|
+
|
|
17
|
+
export type CCommand = 'C';
|
|
18
|
+
export type cCommand = 'c';
|
|
19
|
+
|
|
20
|
+
export type SCommand = 'S';
|
|
21
|
+
export type sCommand = 's';
|
|
22
|
+
|
|
23
|
+
export type QCommand = 'Q';
|
|
24
|
+
export type qCommand = 'q';
|
|
25
|
+
|
|
26
|
+
export type TCommand = 'T';
|
|
27
|
+
export type tCommand = 't';
|
|
28
|
+
|
|
29
|
+
export type ACommand = 'A';
|
|
30
|
+
export type aCommand = 'a';
|
|
31
|
+
|
|
32
|
+
export type AbsoluteCommand =
|
|
33
|
+
| MCommand
|
|
34
|
+
| LCommand
|
|
35
|
+
| VCommand
|
|
36
|
+
| HCommand
|
|
37
|
+
| ZCommand
|
|
38
|
+
| CCommand
|
|
39
|
+
| SCommand
|
|
40
|
+
| QCommand
|
|
41
|
+
| TCommand
|
|
42
|
+
| ACommand;
|
|
43
|
+
export type RelativeCommand =
|
|
44
|
+
| mCommand
|
|
45
|
+
| lCommand
|
|
46
|
+
| vCommand
|
|
47
|
+
| hCommand
|
|
48
|
+
| zCommand
|
|
49
|
+
| cCommand
|
|
50
|
+
| sCommand
|
|
51
|
+
| qCommand
|
|
52
|
+
| tCommand
|
|
53
|
+
| aCommand;
|
|
54
|
+
|
|
55
|
+
export type PathCommand = AbsoluteCommand | RelativeCommand;
|
|
56
|
+
|
|
57
|
+
export type MSegment = [MCommand, number, number];
|
|
58
|
+
export type mSegment = [mCommand, number, number];
|
|
59
|
+
export type MoveSegment = MSegment | mSegment;
|
|
60
|
+
|
|
61
|
+
export type LSegment = [LCommand, number, number];
|
|
62
|
+
export type lSegment = [lCommand, number, number];
|
|
63
|
+
export type LineSegment = LSegment | lSegment;
|
|
64
|
+
|
|
65
|
+
export type VSegment = [VCommand, number];
|
|
66
|
+
export type vSegment = [vCommand, number];
|
|
67
|
+
export type VertLineSegment = vSegment | VSegment;
|
|
68
|
+
|
|
69
|
+
export type HSegment = [HCommand, number];
|
|
70
|
+
export type hSegment = [hCommand, number];
|
|
71
|
+
export type HorLineSegment = HSegment | hSegment;
|
|
72
|
+
|
|
73
|
+
export type ZSegment = [ZCommand];
|
|
74
|
+
export type zSegment = [zCommand];
|
|
75
|
+
export type CloseSegment = ZSegment | zSegment;
|
|
76
|
+
|
|
77
|
+
export type CSegment = [CCommand, number, number, number, number, number, number];
|
|
78
|
+
export type cSegment = [cCommand, number, number, number, number, number, number];
|
|
79
|
+
export type CubicSegment = CSegment | cSegment;
|
|
80
|
+
|
|
81
|
+
export type SSegment = [SCommand, number, number, number, number];
|
|
82
|
+
export type sSegment = [sCommand, number, number, number, number];
|
|
83
|
+
export type ShortCubicSegment = SSegment | sSegment;
|
|
84
|
+
|
|
85
|
+
export type QSegment = [QCommand, number, number, number, number];
|
|
86
|
+
export type qSegment = [qCommand, number, number, number, number];
|
|
87
|
+
export type QuadSegment = QSegment | qSegment;
|
|
88
|
+
|
|
89
|
+
export type TSegment = [TCommand, number, number];
|
|
90
|
+
export type tSegment = [tCommand, number, number];
|
|
91
|
+
export type ShortQuadSegment = TSegment | tSegment;
|
|
92
|
+
|
|
93
|
+
export type ASegment = [ACommand, number, number, number, number, number, number, number];
|
|
94
|
+
export type aSegment = [aCommand, number, number, number, number, number, number, number];
|
|
95
|
+
export type ArcSegment = ASegment | aSegment;
|
|
96
|
+
|
|
97
|
+
export type PathSegment =
|
|
98
|
+
| MoveSegment
|
|
99
|
+
| LineSegment
|
|
100
|
+
| VertLineSegment
|
|
101
|
+
| HorLineSegment
|
|
102
|
+
| CloseSegment
|
|
103
|
+
| CubicSegment
|
|
104
|
+
| ShortCubicSegment
|
|
105
|
+
| QuadSegment
|
|
106
|
+
| ShortQuadSegment
|
|
107
|
+
| ArcSegment;
|
|
108
|
+
|
|
109
|
+
export interface SegmentProperties {
|
|
110
|
+
/** the segment */
|
|
111
|
+
segment: PathSegment;
|
|
112
|
+
/** the segment index */
|
|
113
|
+
index: number;
|
|
114
|
+
/** the segment length */
|
|
115
|
+
length: number;
|
|
116
|
+
/** the length including the segment length */
|
|
117
|
+
lengthAtSegment: number;
|
|
118
|
+
[key: string]: any;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export type ShortSegment = VertLineSegment | HorLineSegment | ShortCubicSegment | ShortQuadSegment | CloseSegment;
|
|
122
|
+
export type AbsoluteSegment =
|
|
123
|
+
| MSegment
|
|
124
|
+
| LSegment
|
|
125
|
+
| VSegment
|
|
126
|
+
| HSegment
|
|
127
|
+
| CSegment
|
|
128
|
+
| SSegment
|
|
129
|
+
| QSegment
|
|
130
|
+
| TSegment
|
|
131
|
+
| ASegment
|
|
132
|
+
| ZSegment;
|
|
133
|
+
export type RelativeSegment =
|
|
134
|
+
| mSegment
|
|
135
|
+
| lSegment
|
|
136
|
+
| vSegment
|
|
137
|
+
| hSegment
|
|
138
|
+
| cSegment
|
|
139
|
+
| sSegment
|
|
140
|
+
| qSegment
|
|
141
|
+
| tSegment
|
|
142
|
+
| aSegment
|
|
143
|
+
| zSegment;
|
|
144
|
+
export type NormalSegment = MSegment | LSegment | CSegment | QSegment | ASegment | ZSegment;
|
|
145
|
+
|
|
146
|
+
export type PathArray = [MSegment | mSegment, ...PathSegment[]];
|
|
147
|
+
export type AbsoluteArray = [MSegment, ...AbsoluteSegment[]];
|
|
148
|
+
export type RelativeArray = [MSegment, ...RelativeSegment[]];
|
|
149
|
+
export type NormalArray = [MSegment, ...NormalSegment[]];
|
|
150
|
+
export type CurveArray = [MSegment, ...CSegment[]];
|
|
151
|
+
export type PolygonArray = [MSegment, ...LSegment[], ZSegment];
|
|
152
|
+
export type PolylineArray = [MSegment, ...LSegment[]];
|
|
153
|
+
|
|
154
|
+
export interface ParserParams {
|
|
17
155
|
x1: number;
|
|
18
156
|
y1: number;
|
|
19
157
|
x2: number;
|
|
@@ -22,4 +160,39 @@ export type ProcessParams = {
|
|
|
22
160
|
y: number;
|
|
23
161
|
qx: number | null;
|
|
24
162
|
qy: number | null;
|
|
25
|
-
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface PathBBox {
|
|
166
|
+
width: number;
|
|
167
|
+
height: number;
|
|
168
|
+
x: number;
|
|
169
|
+
y: number;
|
|
170
|
+
x2: number;
|
|
171
|
+
y2: number;
|
|
172
|
+
cx: number;
|
|
173
|
+
cy: number;
|
|
174
|
+
cz: number;
|
|
175
|
+
}
|
|
176
|
+
export interface PathBBoxTotalLength extends PathBBox {
|
|
177
|
+
length: number;
|
|
178
|
+
}
|
|
179
|
+
export interface SegmentLimits {
|
|
180
|
+
min: Point;
|
|
181
|
+
max: Point;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export interface PointProperties {
|
|
185
|
+
closest: {
|
|
186
|
+
x: number;
|
|
187
|
+
y: number;
|
|
188
|
+
};
|
|
189
|
+
distance: number;
|
|
190
|
+
segment?: SegmentProperties;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface LengthFactory {
|
|
194
|
+
length: number;
|
|
195
|
+
point: Point;
|
|
196
|
+
min: Point;
|
|
197
|
+
max: Point;
|
|
198
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { CurveArray, PathArray } from '../types';
|
|
2
|
+
import { midPoint } from './mid-point';
|
|
3
|
+
import { segmentCubicFactory } from './segment-cubic-factory';
|
|
4
|
+
|
|
5
|
+
function splitCubic(
|
|
6
|
+
pts: [number, number, number, number, number, number, number, number],
|
|
7
|
+
t = 0.5,
|
|
8
|
+
): [CurveArray, CurveArray] {
|
|
9
|
+
const p0 = pts.slice(0, 2) as [number, number];
|
|
10
|
+
const p1 = pts.slice(2, 4) as [number, number];
|
|
11
|
+
const p2 = pts.slice(4, 6) as [number, number];
|
|
12
|
+
const p3 = pts.slice(6, 8) as [number, number];
|
|
13
|
+
const p4 = midPoint(p0, p1, t);
|
|
14
|
+
const p5 = midPoint(p1, p2, t);
|
|
15
|
+
const p6 = midPoint(p2, p3, t);
|
|
16
|
+
const p7 = midPoint(p4, p5, t);
|
|
17
|
+
const p8 = midPoint(p5, p6, t);
|
|
18
|
+
const p9 = midPoint(p7, p8, t);
|
|
19
|
+
|
|
20
|
+
return [
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
['C'].concat(p4, p7, p9),
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
['C'].concat(p8, p6, p3),
|
|
25
|
+
];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getCurveArray(segments: PathArray) {
|
|
29
|
+
return segments.map((segment, i, pathArray) => {
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
const segmentData = i && pathArray[i - 1].slice(-2).concat(segment.slice(1));
|
|
32
|
+
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
const curveLength = i ? segmentCubicFactory(...segmentData).length : 0;
|
|
35
|
+
|
|
36
|
+
let subsegs;
|
|
37
|
+
if (i) {
|
|
38
|
+
// must be [segment,segment]
|
|
39
|
+
subsegs = curveLength ? splitCubic(segmentData) : [segment, segment];
|
|
40
|
+
} else {
|
|
41
|
+
subsegs = [segment];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
s: segment,
|
|
46
|
+
ss: subsegs,
|
|
47
|
+
l: curveLength,
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function equalizeSegments(path1: PathArray, path2: PathArray, TL?: number): CurveArray[] {
|
|
53
|
+
const c1 = getCurveArray(path1);
|
|
54
|
+
const c2 = getCurveArray(path2);
|
|
55
|
+
const L1 = c1.length;
|
|
56
|
+
const L2 = c2.length;
|
|
57
|
+
const l1 = c1.filter((x) => x.l).length;
|
|
58
|
+
const l2 = c2.filter((x) => x.l).length;
|
|
59
|
+
const m1 = c1.filter((x) => x.l).reduce((a, { l }) => a + l, 0) / l1 || 0;
|
|
60
|
+
const m2 = c2.filter((x) => x.l).reduce((a, { l }) => a + l, 0) / l2 || 0;
|
|
61
|
+
const tl = TL || Math.max(L1, L2);
|
|
62
|
+
const mm = [m1, m2];
|
|
63
|
+
const dif = [tl - L1, tl - L2];
|
|
64
|
+
let canSplit: number | boolean = 0;
|
|
65
|
+
const result = [c1, c2].map((x, i) =>
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
x.l === tl
|
|
68
|
+
? x.map((y) => y.s)
|
|
69
|
+
: x
|
|
70
|
+
.map((y, j) => {
|
|
71
|
+
canSplit = j && dif[i] && y.l >= mm[i];
|
|
72
|
+
dif[i] -= canSplit ? 1 : 0;
|
|
73
|
+
return canSplit ? y.ss : [y.s];
|
|
74
|
+
})
|
|
75
|
+
.flat(),
|
|
76
|
+
) as CurveArray[];
|
|
77
|
+
|
|
78
|
+
return result[0].length === result[1].length ? result : equalizeSegments(result[0], result[1], tl);
|
|
79
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { PathArray } from '../types';
|
|
2
|
+
import { path2Curve } from '../convert/path-2-curve';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the area of a single cubic-bezier segment.
|
|
6
|
+
*
|
|
7
|
+
* http://objectmix.com/graphics/133553-area-closed-bezier-curve.html
|
|
8
|
+
*/
|
|
9
|
+
function getCubicSegArea(
|
|
10
|
+
x1: number,
|
|
11
|
+
y1: number,
|
|
12
|
+
c1x: number,
|
|
13
|
+
c1y: number,
|
|
14
|
+
c2x: number,
|
|
15
|
+
c2y: number,
|
|
16
|
+
x2: number,
|
|
17
|
+
y2: number,
|
|
18
|
+
) {
|
|
19
|
+
// https://stackoverflow.com/a/15845996
|
|
20
|
+
return (
|
|
21
|
+
(3 *
|
|
22
|
+
((y2 - y1) * (c1x + c2x) -
|
|
23
|
+
(x2 - x1) * (c1y + c2y) +
|
|
24
|
+
c1y * (x1 - c2x) -
|
|
25
|
+
c1x * (y1 - c2y) +
|
|
26
|
+
y2 * (c2x + x1 / 3) -
|
|
27
|
+
x2 * (c2y + y1 / 3))) /
|
|
28
|
+
20
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Returns the area of a shape.
|
|
34
|
+
* @author Jürg Lehni & Jonathan Puckey
|
|
35
|
+
*
|
|
36
|
+
* @see https://github.com/paperjs/paper.js/blob/develop/src/path/Path.js
|
|
37
|
+
*/
|
|
38
|
+
export function getPathArea(path: PathArray) {
|
|
39
|
+
let x = 0;
|
|
40
|
+
let y = 0;
|
|
41
|
+
let len = 0;
|
|
42
|
+
|
|
43
|
+
return path2Curve(path)
|
|
44
|
+
.map((seg) => {
|
|
45
|
+
switch (seg[0]) {
|
|
46
|
+
case 'M':
|
|
47
|
+
[, x, y] = seg;
|
|
48
|
+
return 0;
|
|
49
|
+
default:
|
|
50
|
+
// @ts-ignore
|
|
51
|
+
len = getCubicSegArea(x, y, ...seg.slice(1));
|
|
52
|
+
[x, y] = seg.slice(-2);
|
|
53
|
+
return len;
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
.reduce((a, b) => a + b, 0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// export function getPathArea(pathArray: AbsoluteArray) {
|
|
60
|
+
// let x = 0;
|
|
61
|
+
// let y = 0;
|
|
62
|
+
// let mx = 0;
|
|
63
|
+
// let my = 0;
|
|
64
|
+
// let len = 0;
|
|
65
|
+
// return pathArray
|
|
66
|
+
// .map((seg) => {
|
|
67
|
+
// switch (seg[0]) {
|
|
68
|
+
// case 'M':
|
|
69
|
+
// case 'Z':
|
|
70
|
+
// mx = seg[0] === 'M' ? seg[1] : mx;
|
|
71
|
+
// my = seg[0] === 'M' ? seg[2] : my;
|
|
72
|
+
// x = mx;
|
|
73
|
+
// y = my;
|
|
74
|
+
// return 0;
|
|
75
|
+
// default:
|
|
76
|
+
// // @ts-ignore
|
|
77
|
+
// len = getCubicSegArea.apply(0, [x, y].concat(seg.slice(1)));
|
|
78
|
+
// [x, y] = seg.slice(-2) as [number, number];
|
|
79
|
+
// return len;
|
|
80
|
+
// }
|
|
81
|
+
// })
|
|
82
|
+
// .reduce((a, b) => a + b, 0);
|
|
83
|
+
// }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { PathArray, PathBBoxTotalLength } from '../types';
|
|
2
|
+
import { pathLengthFactory } from './path-length-factory';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the bounding box of a shape.
|
|
6
|
+
*/
|
|
7
|
+
export function getPathBBoxTotalLength(path: PathArray): PathBBoxTotalLength {
|
|
8
|
+
if (!path) {
|
|
9
|
+
return {
|
|
10
|
+
length: 0,
|
|
11
|
+
x: 0,
|
|
12
|
+
y: 0,
|
|
13
|
+
width: 0,
|
|
14
|
+
height: 0,
|
|
15
|
+
x2: 0,
|
|
16
|
+
y2: 0,
|
|
17
|
+
cx: 0,
|
|
18
|
+
cy: 0,
|
|
19
|
+
cz: 0,
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
length,
|
|
25
|
+
min: { x: xMin, y: yMin },
|
|
26
|
+
max: { x: xMax, y: yMax },
|
|
27
|
+
} = pathLengthFactory(path);
|
|
28
|
+
|
|
29
|
+
const width = xMax - xMin;
|
|
30
|
+
const height = yMax - yMin;
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
length,
|
|
34
|
+
width,
|
|
35
|
+
height,
|
|
36
|
+
x: xMin,
|
|
37
|
+
y: yMin,
|
|
38
|
+
x2: xMax,
|
|
39
|
+
y2: yMax,
|
|
40
|
+
cx: xMin + width / 2,
|
|
41
|
+
cy: yMin + height / 2,
|
|
42
|
+
// an estimted guess
|
|
43
|
+
cz: Math.max(width, height) + Math.min(width, height) / 2,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { PathArray, PathBBox } from '../types';
|
|
2
|
+
import { pathLengthFactory } from './path-length-factory';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the bounding box of a shape.
|
|
6
|
+
*/
|
|
7
|
+
export function getPathBBox(path: string | PathArray): PathBBox {
|
|
8
|
+
if (!path) {
|
|
9
|
+
return {
|
|
10
|
+
x: 0,
|
|
11
|
+
y: 0,
|
|
12
|
+
width: 0,
|
|
13
|
+
height: 0,
|
|
14
|
+
x2: 0,
|
|
15
|
+
y2: 0,
|
|
16
|
+
cx: 0,
|
|
17
|
+
cy: 0,
|
|
18
|
+
cz: 0,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
min: { x: xMin, y: yMin },
|
|
24
|
+
max: { x: xMax, y: yMax },
|
|
25
|
+
} = pathLengthFactory(path);
|
|
26
|
+
|
|
27
|
+
const width = xMax - xMin;
|
|
28
|
+
const height = yMax - yMin;
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
width,
|
|
32
|
+
height,
|
|
33
|
+
x: xMin,
|
|
34
|
+
y: yMin,
|
|
35
|
+
x2: xMax,
|
|
36
|
+
y2: yMax,
|
|
37
|
+
cx: xMin + width / 2,
|
|
38
|
+
cy: yMin + height / 2,
|
|
39
|
+
// an estimted guess
|
|
40
|
+
cz: Math.max(width, height) + Math.min(width, height) / 2,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PathArray } from '../types';
|
|
2
|
+
import { pathLengthFactory } from './path-length-factory';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns [x,y] coordinates of a point at a given length of a shape.
|
|
6
|
+
*/
|
|
7
|
+
export function getPointAtLength(pathInput: string | PathArray, distance: number) {
|
|
8
|
+
return pathLengthFactory(pathInput, distance).point;
|
|
9
|
+
}
|