@antv/util 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +36 -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 +40 -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/.DS_Store +0 -0
- package/src/path/.DS_Store +0 -0
- 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 +37 -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 -61
- 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 -65
- 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
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { isPointInPolygon } from './point-in-polygon';
|
|
2
|
-
import { getLineIntersect } from './get-line-intersect';
|
|
3
|
-
|
|
4
|
-
function parseToLines(points) {
|
|
5
|
-
const lines = [];
|
|
6
|
-
const count = points.length;
|
|
7
|
-
for (let i = 0; i < count - 1; i++) {
|
|
8
|
-
const point = points[i];
|
|
9
|
-
const next = points[i + 1];
|
|
10
|
-
lines.push({
|
|
11
|
-
from: {
|
|
12
|
-
x: point[0],
|
|
13
|
-
y: point[1],
|
|
14
|
-
},
|
|
15
|
-
to: {
|
|
16
|
-
x: next[0],
|
|
17
|
-
y: next[1],
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
if (lines.length > 1) {
|
|
22
|
-
const first = points[0];
|
|
23
|
-
const last = points[count - 1];
|
|
24
|
-
lines.push({
|
|
25
|
-
from: {
|
|
26
|
-
x: last[0],
|
|
27
|
-
y: last[1],
|
|
28
|
-
},
|
|
29
|
-
to: {
|
|
30
|
-
x: first[0],
|
|
31
|
-
y: first[1],
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return lines;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function lineIntersectPolygon(lines, line) {
|
|
39
|
-
for (let i = 0; i < lines.length; i++) {
|
|
40
|
-
const l = lines[i];
|
|
41
|
-
if (getLineIntersect(l.from, l.to, line.from, line.to)) {
|
|
42
|
-
return true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type BBox = {
|
|
49
|
-
minX: number;
|
|
50
|
-
minY: number;
|
|
51
|
-
maxX: number;
|
|
52
|
-
maxY: number;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
function getBBox(points): BBox {
|
|
56
|
-
const xArr = points.map((p) => p[0]);
|
|
57
|
-
const yArr = points.map((p) => p[1]);
|
|
58
|
-
return {
|
|
59
|
-
minX: Math.min.apply(null, xArr),
|
|
60
|
-
maxX: Math.max.apply(null, xArr),
|
|
61
|
-
minY: Math.min.apply(null, yArr),
|
|
62
|
-
maxY: Math.max.apply(null, yArr),
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function intersectBBox(box1: BBox, box2: BBox) {
|
|
67
|
-
return !(box2.minX > box1.maxX || box2.maxX < box1.minX || box2.minY > box1.maxY || box2.maxY < box1.minY);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export function isPolygonsIntersect(points1, points2) {
|
|
71
|
-
// 空数组,或者一个点返回 false
|
|
72
|
-
if (points1.length < 2 || points2.length < 2) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const bbox1 = getBBox(points1);
|
|
77
|
-
const bbox2 = getBBox(points2);
|
|
78
|
-
// 判定包围盒是否相交,比判定点是否在多边形内要快的多,可以筛选掉大多数情况
|
|
79
|
-
if (!intersectBBox(bbox1, bbox2)) {
|
|
80
|
-
return false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// 判定点是否在多边形内部,一旦有一个点在另一个多边形内,则返回
|
|
84
|
-
let hasOneIn = points2.some((point) => isPointInPolygon(points1, point[0], point[1]));
|
|
85
|
-
if (hasOneIn) return true;
|
|
86
|
-
|
|
87
|
-
// 两个多边形都需要判定
|
|
88
|
-
hasOneIn = points1.some((point) => isPointInPolygon(points2, point[0], point[1]));
|
|
89
|
-
if (hasOneIn) return true;
|
|
90
|
-
|
|
91
|
-
const lines1 = parseToLines(points1);
|
|
92
|
-
const lines2 = parseToLines(points2);
|
|
93
|
-
|
|
94
|
-
return lines2.some((line) => lineIntersectPolygon(lines1, line));
|
|
95
|
-
}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
const SPACES = '\\s';
|
|
2
|
-
const PATH_COMMAND = new RegExp(
|
|
3
|
-
'([a-z])[' + SPACES + ',]*((-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?[' + SPACES + ']*,?[' + SPACES + ']*)+)',
|
|
4
|
-
'ig',
|
|
5
|
-
);
|
|
6
|
-
const PATH_VALUES = new RegExp('(-?\\d*\\.?\\d*(?:e[\\-+]?\\d+)?)[' + SPACES + ']*,?[' + SPACES + ']*', 'ig');
|
|
7
|
-
|
|
8
|
-
// Parses given path string into an array of arrays of path segments
|
|
9
|
-
export function parsePathString(pathString: string | any[]) {
|
|
10
|
-
if (typeof pathString === 'string') {
|
|
11
|
-
if (pathString) {
|
|
12
|
-
const paramCounts = {
|
|
13
|
-
a: 7,
|
|
14
|
-
c: 6,
|
|
15
|
-
o: 2,
|
|
16
|
-
h: 1,
|
|
17
|
-
l: 2,
|
|
18
|
-
m: 2,
|
|
19
|
-
r: 4,
|
|
20
|
-
q: 4,
|
|
21
|
-
s: 4,
|
|
22
|
-
t: 2,
|
|
23
|
-
v: 1,
|
|
24
|
-
u: 3,
|
|
25
|
-
z: 0,
|
|
26
|
-
};
|
|
27
|
-
const data = [];
|
|
28
|
-
|
|
29
|
-
pathString.replace(PATH_COMMAND, function (a, b, c) {
|
|
30
|
-
const params = [];
|
|
31
|
-
let name = b.toLowerCase();
|
|
32
|
-
c.replace(PATH_VALUES, function (a, b) {
|
|
33
|
-
b && params.push(+b);
|
|
34
|
-
});
|
|
35
|
-
if (name === 'm' && params.length > 2) {
|
|
36
|
-
data.push([b].concat(params.splice(0, 2)));
|
|
37
|
-
name = 'l';
|
|
38
|
-
b = b === 'm' ? 'l' : 'L';
|
|
39
|
-
}
|
|
40
|
-
if (name === 'o' && params.length === 1) {
|
|
41
|
-
data.push([b, params[0]]);
|
|
42
|
-
}
|
|
43
|
-
if (name === 'r') {
|
|
44
|
-
data.push([b].concat(params));
|
|
45
|
-
} else {
|
|
46
|
-
while (params.length >= paramCounts[name]) {
|
|
47
|
-
data.push([b].concat(params.splice(0, paramCounts[name])));
|
|
48
|
-
if (!paramCounts[name]) {
|
|
49
|
-
break;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return '';
|
|
54
|
-
});
|
|
55
|
-
return data;
|
|
56
|
-
} else {
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
} else if (Array.isArray(pathString)) {
|
|
60
|
-
return pathString;
|
|
61
|
-
}
|
|
62
|
-
}
|
package/src/path/parse-path.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const regexTags = /[MLHVQTCSAZ]([^MLHVQTCSAZ]*)/gi;
|
|
2
|
-
const regexDot = /[^\s,]+/gi;
|
|
3
|
-
|
|
4
|
-
export function parsePath(p: string): string[] {
|
|
5
|
-
let path = p || ([] as string | string[]);
|
|
6
|
-
if (Array.isArray(path)) {
|
|
7
|
-
return path;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
if (typeof path === 'string') {
|
|
11
|
-
path = path.match(regexTags);
|
|
12
|
-
path.forEach((item, index) => {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
item = item.match(regexDot);
|
|
15
|
-
if (item[0].length > 1) {
|
|
16
|
-
const tag = item[0].charAt(0);
|
|
17
|
-
// @ts-ignore
|
|
18
|
-
item.splice(1, 0, item[0].substr(1));
|
|
19
|
-
// @ts-ignore
|
|
20
|
-
item[0] = tag;
|
|
21
|
-
}
|
|
22
|
-
// @ts-ignore
|
|
23
|
-
item.forEach(function (sub, i) {
|
|
24
|
-
if (!isNaN(sub)) {
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
item[i] = +sub;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
// @ts-ignore
|
|
30
|
-
path[index] = item;
|
|
31
|
-
});
|
|
32
|
-
return path;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { parsePathString } from './parse-path-string';
|
|
2
|
-
|
|
3
|
-
const REGEX_MD = /[a-z]/;
|
|
4
|
-
|
|
5
|
-
function toSymmetry(p, c) {
|
|
6
|
-
// 点对称
|
|
7
|
-
return [c[0] + (c[0] - p[0]), c[1] + (c[1] - p[1])];
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function path2Absolute(pathString: string) {
|
|
11
|
-
const pathArray = parsePathString(pathString);
|
|
12
|
-
|
|
13
|
-
if (!pathArray || !pathArray.length) {
|
|
14
|
-
return [['M', 0, 0]];
|
|
15
|
-
}
|
|
16
|
-
let needProcess = false; // 如果存在小写的命令或者 V,H,T,S 则需要处理
|
|
17
|
-
for (let i = 0; i < pathArray.length; i++) {
|
|
18
|
-
const cmd = pathArray[i][0];
|
|
19
|
-
// 如果存在相对位置的命令,则中断返回
|
|
20
|
-
if (REGEX_MD.test(cmd) || ['V', 'H', 'T', 'S'].indexOf(cmd) >= 0) {
|
|
21
|
-
needProcess = true;
|
|
22
|
-
break;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
// 如果不存在相对命令,则直接返回
|
|
26
|
-
// 如果在业务上都写绝对路径,这种方式最快,仅做了一次检测
|
|
27
|
-
if (!needProcess) {
|
|
28
|
-
return pathArray;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const res = [];
|
|
32
|
-
let x = 0;
|
|
33
|
-
let y = 0;
|
|
34
|
-
let mx = 0;
|
|
35
|
-
let my = 0;
|
|
36
|
-
let start = 0;
|
|
37
|
-
const first = pathArray[0];
|
|
38
|
-
if (first[0] === 'M' || first[0] === 'm') {
|
|
39
|
-
x = +first[1];
|
|
40
|
-
y = +first[2];
|
|
41
|
-
mx = x;
|
|
42
|
-
my = y;
|
|
43
|
-
start++;
|
|
44
|
-
res[0] = ['M', x, y];
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
for (let i = start, ii = pathArray.length; i < ii; i++) {
|
|
48
|
-
const pa = pathArray[i];
|
|
49
|
-
const preParams = res[i - 1]; // 取前一个已经处理后的节点,否则会出现问题
|
|
50
|
-
let r = [];
|
|
51
|
-
const cmd = pa[0];
|
|
52
|
-
const upCmd = cmd.toUpperCase();
|
|
53
|
-
if (cmd !== upCmd) {
|
|
54
|
-
r[0] = upCmd;
|
|
55
|
-
switch (upCmd) {
|
|
56
|
-
case 'A':
|
|
57
|
-
r[1] = pa[1];
|
|
58
|
-
r[2] = pa[2];
|
|
59
|
-
r[3] = pa[3];
|
|
60
|
-
r[4] = pa[4];
|
|
61
|
-
r[5] = pa[5];
|
|
62
|
-
r[6] = +pa[6] + x;
|
|
63
|
-
r[7] = +pa[7] + y;
|
|
64
|
-
break;
|
|
65
|
-
case 'V':
|
|
66
|
-
r[1] = +pa[1] + y;
|
|
67
|
-
break;
|
|
68
|
-
case 'H':
|
|
69
|
-
r[1] = +pa[1] + x;
|
|
70
|
-
break;
|
|
71
|
-
case 'M':
|
|
72
|
-
mx = +pa[1] + x;
|
|
73
|
-
my = +pa[2] + y;
|
|
74
|
-
r[1] = mx;
|
|
75
|
-
r[2] = my;
|
|
76
|
-
break; // for lint
|
|
77
|
-
default:
|
|
78
|
-
for (let j = 1, jj = pa.length; j < jj; j++) {
|
|
79
|
-
r[j] = +pa[j] + (j % 2 ? x : y);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
} else {
|
|
83
|
-
// 如果本来已经大写,则不处理
|
|
84
|
-
r = pathArray[i];
|
|
85
|
-
}
|
|
86
|
-
// 需要在外面统一做,同时处理 V,H,S,T 等特殊指令
|
|
87
|
-
switch (upCmd) {
|
|
88
|
-
case 'Z':
|
|
89
|
-
x = +mx;
|
|
90
|
-
y = +my;
|
|
91
|
-
break;
|
|
92
|
-
case 'H':
|
|
93
|
-
x = r[1];
|
|
94
|
-
r = ['L', x, y];
|
|
95
|
-
break;
|
|
96
|
-
case 'V':
|
|
97
|
-
y = r[1];
|
|
98
|
-
r = ['L', x, y];
|
|
99
|
-
break;
|
|
100
|
-
case 'T':
|
|
101
|
-
x = r[1];
|
|
102
|
-
y = r[2];
|
|
103
|
-
// 以 x, y 为中心的,上一个控制点的对称点
|
|
104
|
-
// 需要假设上一个节点的命令为 Q
|
|
105
|
-
const symetricT = toSymmetry([preParams[1], preParams[2]], [preParams[3], preParams[4]]);
|
|
106
|
-
r = ['Q', symetricT[0], symetricT[1], x, y];
|
|
107
|
-
break;
|
|
108
|
-
case 'S':
|
|
109
|
-
x = r[r.length - 2];
|
|
110
|
-
y = r[r.length - 1];
|
|
111
|
-
// 以 x,y 为中心,取上一个控制点,
|
|
112
|
-
// 需要假设上一个线段为 C 或者 S
|
|
113
|
-
const length = preParams.length;
|
|
114
|
-
const symetricS = toSymmetry(
|
|
115
|
-
[preParams[length - 4], preParams[length - 3]],
|
|
116
|
-
[preParams[length - 2], preParams[length - 1]],
|
|
117
|
-
);
|
|
118
|
-
r = ['C', symetricS[0], symetricS[1], r[1], r[2], x, y];
|
|
119
|
-
break;
|
|
120
|
-
case 'M':
|
|
121
|
-
mx = r[r.length - 2];
|
|
122
|
-
my = r[r.length - 1];
|
|
123
|
-
break; // for lint
|
|
124
|
-
default:
|
|
125
|
-
x = r[r.length - 2];
|
|
126
|
-
y = r[r.length - 1];
|
|
127
|
-
}
|
|
128
|
-
res.push(r);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
return res;
|
|
132
|
-
}
|
package/src/path/path-2-curve.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { path2Absolute } from './path-2-absolute';
|
|
2
|
-
import { segmentToCubic } from './process/segment-2-cubic';
|
|
3
|
-
import type { PathCommand, ProcessParams } from './types';
|
|
4
|
-
|
|
5
|
-
export function path2Curve(path: PathCommand[] | string, needZCommandIndexes = false) {
|
|
6
|
-
const pathArray = path2Absolute(path as string) as PathCommand[];
|
|
7
|
-
|
|
8
|
-
const params: ProcessParams = {
|
|
9
|
-
x1: 0,
|
|
10
|
-
y1: 0,
|
|
11
|
-
x2: 0,
|
|
12
|
-
y2: 0,
|
|
13
|
-
x: 0,
|
|
14
|
-
y: 0,
|
|
15
|
-
qx: null,
|
|
16
|
-
qy: null,
|
|
17
|
-
};
|
|
18
|
-
const allPathCommands = [];
|
|
19
|
-
let pathCommand = '';
|
|
20
|
-
let ii = pathArray.length;
|
|
21
|
-
let segment: PathCommand;
|
|
22
|
-
let seglen: number;
|
|
23
|
-
const zCommandIndexes: number[] = [];
|
|
24
|
-
|
|
25
|
-
for (let i = 0; i < ii; i += 1) {
|
|
26
|
-
if (pathArray[i]) [pathCommand] = pathArray[i];
|
|
27
|
-
|
|
28
|
-
allPathCommands[i] = pathCommand;
|
|
29
|
-
pathArray[i] = segmentToCubic(pathArray[i], params);
|
|
30
|
-
|
|
31
|
-
fixArc(pathArray, allPathCommands, i);
|
|
32
|
-
ii = pathArray.length; // solves curveArrays ending in Z
|
|
33
|
-
|
|
34
|
-
// keep Z command account for lineJoin
|
|
35
|
-
// @see https://github.com/antvis/util/issues/68
|
|
36
|
-
if (pathCommand === 'Z') {
|
|
37
|
-
zCommandIndexes.push(i);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
segment = pathArray[i];
|
|
41
|
-
seglen = segment.length;
|
|
42
|
-
|
|
43
|
-
params.x1 = +segment[seglen - 2];
|
|
44
|
-
params.y1 = +segment[seglen - 1];
|
|
45
|
-
params.x2 = +segment[seglen - 4] || params.x1;
|
|
46
|
-
params.y2 = +segment[seglen - 3] || params.y1;
|
|
47
|
-
}
|
|
48
|
-
if (needZCommandIndexes) {
|
|
49
|
-
return [pathArray, zCommandIndexes];
|
|
50
|
-
} else {
|
|
51
|
-
return pathArray;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function fixArc(pathArray: PathCommand[], allPathCommands: string[], i: number) {
|
|
56
|
-
if (pathArray[i].length > 7) {
|
|
57
|
-
pathArray[i].shift();
|
|
58
|
-
const pi = pathArray[i];
|
|
59
|
-
// const ni = i + 1;
|
|
60
|
-
let ni = i;
|
|
61
|
-
while (pi.length) {
|
|
62
|
-
// if created multiple C:s, their original seg is saved
|
|
63
|
-
allPathCommands[i] = 'A';
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
pathArray.splice((ni += 1), 0, ['C'].concat(pi.splice(0, 6)));
|
|
66
|
-
}
|
|
67
|
-
pathArray.splice(i, 1);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { getArcParams, isSamePoint } from './get-arc-params';
|
|
2
|
-
import { parsePath } from './parse-path';
|
|
3
|
-
|
|
4
|
-
// 点对称
|
|
5
|
-
function toSymmetry(point, center) {
|
|
6
|
-
return [center[0] + (center[0] - point[0]), center[1] + (center[1] - point[1])];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function path2Segments(path) {
|
|
10
|
-
path = parsePath(path);
|
|
11
|
-
const segments = [];
|
|
12
|
-
let currentPoint = null; // 当前图形
|
|
13
|
-
let nextParams = null; // 下一节点的 path 参数
|
|
14
|
-
let startMovePoint = null; // 开始 M 的点,可能会有多个
|
|
15
|
-
let lastStartMovePointIndex = 0; // 最近一个开始点 M 的索引
|
|
16
|
-
const count = path.length;
|
|
17
|
-
for (let i = 0; i < count; i++) {
|
|
18
|
-
const params = path[i];
|
|
19
|
-
nextParams = path[i + 1];
|
|
20
|
-
const command = params[0];
|
|
21
|
-
// 数学定义上的参数,便于后面的计算
|
|
22
|
-
const segment = {
|
|
23
|
-
command,
|
|
24
|
-
prePoint: currentPoint,
|
|
25
|
-
params,
|
|
26
|
-
startTangent: null,
|
|
27
|
-
endTangent: null,
|
|
28
|
-
};
|
|
29
|
-
switch (command) {
|
|
30
|
-
case 'M':
|
|
31
|
-
startMovePoint = [params[1], params[2]];
|
|
32
|
-
lastStartMovePointIndex = i;
|
|
33
|
-
break;
|
|
34
|
-
case 'A':
|
|
35
|
-
const arcParams = getArcParams(currentPoint, params);
|
|
36
|
-
segment['arcParams'] = arcParams;
|
|
37
|
-
break;
|
|
38
|
-
default:
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
if (command === 'Z') {
|
|
42
|
-
// 有了 Z 后,当前节点从开始 M 的点开始
|
|
43
|
-
currentPoint = startMovePoint;
|
|
44
|
-
// 如果当前点的命令为 Z,相当于当前点为最近一个 M 点,则下一个点直接指向最近一个 M 点的下一个点
|
|
45
|
-
nextParams = path[lastStartMovePointIndex + 1];
|
|
46
|
-
} else {
|
|
47
|
-
const len = params.length;
|
|
48
|
-
currentPoint = [params[len - 2], params[len - 1]];
|
|
49
|
-
}
|
|
50
|
-
if (nextParams && nextParams[0] === 'Z') {
|
|
51
|
-
// 如果下一个点的命令为 Z,则下一个点直接指向最近一个 M 点
|
|
52
|
-
nextParams = path[lastStartMovePointIndex];
|
|
53
|
-
if (segments[lastStartMovePointIndex]) {
|
|
54
|
-
// 如果下一个点的命令为 Z,则最近一个 M 点的前一个点为当前点
|
|
55
|
-
segments[lastStartMovePointIndex].prePoint = currentPoint;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
segment['currentPoint'] = currentPoint;
|
|
59
|
-
// 如果当前点与最近一个 M 点相同,则最近一个 M 点的前一个点为当前点的前一个点
|
|
60
|
-
if (
|
|
61
|
-
segments[lastStartMovePointIndex] &&
|
|
62
|
-
isSamePoint(currentPoint, segments[lastStartMovePointIndex].currentPoint)
|
|
63
|
-
) {
|
|
64
|
-
segments[lastStartMovePointIndex].prePoint = segment.prePoint;
|
|
65
|
-
}
|
|
66
|
-
const nextPoint = nextParams ? [nextParams[nextParams.length - 2], nextParams[nextParams.length - 1]] : null;
|
|
67
|
-
segment['nextPoint'] = nextPoint;
|
|
68
|
-
// Add startTangent and endTangent
|
|
69
|
-
const { prePoint } = segment;
|
|
70
|
-
if (['L', 'H', 'V'].includes(command)) {
|
|
71
|
-
segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
|
|
72
|
-
segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
|
|
73
|
-
} else if (command === 'Q') {
|
|
74
|
-
// 二次贝塞尔曲线只有一个控制点
|
|
75
|
-
const cp = [params[1], params[2]];
|
|
76
|
-
// 二次贝塞尔曲线的终点为 currentPoint
|
|
77
|
-
segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
|
|
78
|
-
segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
|
|
79
|
-
} else if (command === 'T') {
|
|
80
|
-
const preSegment = segments[i - 1];
|
|
81
|
-
const cp = toSymmetry(preSegment.currentPoint, prePoint);
|
|
82
|
-
if (preSegment.command === 'Q') {
|
|
83
|
-
segment.command = 'Q';
|
|
84
|
-
segment.startTangent = [prePoint[0] - cp[0], prePoint[1] - cp[1]];
|
|
85
|
-
segment.endTangent = [currentPoint[0] - cp[0], currentPoint[1] - cp[1]];
|
|
86
|
-
} else {
|
|
87
|
-
segment.command = 'TL';
|
|
88
|
-
segment.startTangent = [prePoint[0] - currentPoint[0], prePoint[1] - currentPoint[1]];
|
|
89
|
-
segment.endTangent = [currentPoint[0] - prePoint[0], currentPoint[1] - prePoint[1]];
|
|
90
|
-
}
|
|
91
|
-
} else if (command === 'C') {
|
|
92
|
-
// 三次贝塞尔曲线有两个控制点
|
|
93
|
-
const cp1 = [params[1], params[2]];
|
|
94
|
-
const cp2 = [params[3], params[4]];
|
|
95
|
-
segment.startTangent = [prePoint[0] - cp1[0], prePoint[1] - cp1[1]];
|
|
96
|
-
segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]];
|
|
97
|
-
|
|
98
|
-
// horizontal line, eg. ['C', 100, 100, 100, 100, 200, 200]
|
|
99
|
-
if (segment.startTangent[0] === 0 && segment.startTangent[1] === 0) {
|
|
100
|
-
segment.startTangent = [cp1[0] - cp2[0], cp1[1] - cp2[1]];
|
|
101
|
-
}
|
|
102
|
-
if (segment.endTangent[0] === 0 && segment.endTangent[1] === 0) {
|
|
103
|
-
segment.endTangent = [cp2[0] - cp1[0], cp2[1] - cp1[1]];
|
|
104
|
-
}
|
|
105
|
-
} else if (command === 'S') {
|
|
106
|
-
const preSegment = segments[i - 1];
|
|
107
|
-
const cp1 = toSymmetry(preSegment.currentPoint, prePoint);
|
|
108
|
-
const cp2 = [params[1], params[2]];
|
|
109
|
-
if (preSegment.command === 'C') {
|
|
110
|
-
segment.command = 'C'; // 将 S 命令变换为 C 命令
|
|
111
|
-
segment.startTangent = [prePoint[0] - cp1[0], prePoint[1] - cp1[1]];
|
|
112
|
-
segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]];
|
|
113
|
-
} else {
|
|
114
|
-
segment.command = 'SQ'; // 将 S 命令变换为 SQ 命令
|
|
115
|
-
segment.startTangent = [prePoint[0] - cp2[0], prePoint[1] - cp2[1]];
|
|
116
|
-
segment.endTangent = [currentPoint[0] - cp2[0], currentPoint[1] - cp2[1]];
|
|
117
|
-
}
|
|
118
|
-
} else if (command === 'A') {
|
|
119
|
-
let d = 0.001;
|
|
120
|
-
const {
|
|
121
|
-
cx = 0,
|
|
122
|
-
cy = 0,
|
|
123
|
-
rx = 0,
|
|
124
|
-
ry = 0,
|
|
125
|
-
sweepFlag = 0,
|
|
126
|
-
startAngle = 0,
|
|
127
|
-
endAngle = 0,
|
|
128
|
-
} = segment['arcParams'] || {};
|
|
129
|
-
if (sweepFlag === 0) {
|
|
130
|
-
d *= -1;
|
|
131
|
-
}
|
|
132
|
-
const dx1 = rx * Math.cos(startAngle - d) + cx;
|
|
133
|
-
const dy1 = ry * Math.sin(startAngle - d) + cy;
|
|
134
|
-
segment.startTangent = [dx1 - startMovePoint[0], dy1 - startMovePoint[1]];
|
|
135
|
-
const dx2 = rx * Math.cos(startAngle + endAngle + d) + cx;
|
|
136
|
-
const dy2 = ry * Math.sin(startAngle + endAngle - d) + cy;
|
|
137
|
-
segment.endTangent = [prePoint[0] - dx2, prePoint[1] - dy2];
|
|
138
|
-
}
|
|
139
|
-
segments.push(segment);
|
|
140
|
-
}
|
|
141
|
-
return segments;
|
|
142
|
-
}
|