@antv/util 3.0.2 → 3.1.2
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 -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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rect-path.js","sourceRoot":"src/","sources":["path/rect-path.ts"],"names":[],"mappings":";;;AAIA,SAAgB,QAAQ,CAAC,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAS,EAAE,CAAU;IAC7E,IAAI,CAAC,EAAE;QACL,OAAO;YACL,CAAC,GAAG,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;YACjB,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACnB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;YAC1B,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;YAC3B,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YACnB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;YAC5B,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACnB,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;YAC3B,CAAC,GAAG,CAAC;SACN,CAAC;KACH;IACD,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACpE,uCAAuC;AACzC,CAAC;AAjBD,4BAiBC"}
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { vec2 } from 'gl-matrix';
|
|
2
|
-
import type { PathCommand } from './types';
|
|
3
|
-
|
|
4
|
-
type Pos = [number, number];
|
|
5
|
-
|
|
6
|
-
function smoothBezier(points: Pos[], smooth: number, isLoop: boolean, constraint: Pos[]) {
|
|
7
|
-
const cps: vec2[] = [];
|
|
8
|
-
const hasConstraint = !!constraint;
|
|
9
|
-
|
|
10
|
-
let prevPoint: Pos;
|
|
11
|
-
let nextPoint: Pos;
|
|
12
|
-
let min: vec2;
|
|
13
|
-
let max: vec2;
|
|
14
|
-
let nextCp0: vec2;
|
|
15
|
-
let cp1: vec2;
|
|
16
|
-
let cp0: vec2;
|
|
17
|
-
|
|
18
|
-
if (hasConstraint) {
|
|
19
|
-
[min, max] = constraint;
|
|
20
|
-
for (let i = 0, l = points.length; i < l; i += 1) {
|
|
21
|
-
const point = points[i];
|
|
22
|
-
min = vec2.min([0, 0], min, point);
|
|
23
|
-
max = vec2.max([0, 0], max, point);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for (let i = 0, len = points.length; i < len; i += 1) {
|
|
28
|
-
const point = points[i];
|
|
29
|
-
if (i === 0 && !isLoop) {
|
|
30
|
-
cp0 = point;
|
|
31
|
-
} else if (i === len - 1 && !isLoop) {
|
|
32
|
-
cp1 = point;
|
|
33
|
-
cps.push(cp0);
|
|
34
|
-
cps.push(cp1);
|
|
35
|
-
} else {
|
|
36
|
-
const prevIdx = [i ? i - 1 : len - 1, i - 1][isLoop ? 0 : 1];
|
|
37
|
-
prevPoint = points[prevIdx];
|
|
38
|
-
nextPoint = points[isLoop ? (i + 1) % len : i + 1];
|
|
39
|
-
|
|
40
|
-
let v: vec2 = [0, 0];
|
|
41
|
-
v = vec2.sub(v, nextPoint, prevPoint);
|
|
42
|
-
v = vec2.scale(v, v, smooth);
|
|
43
|
-
|
|
44
|
-
let d0 = vec2.distance(point, prevPoint);
|
|
45
|
-
let d1 = vec2.distance(point, nextPoint);
|
|
46
|
-
|
|
47
|
-
const sum = d0 + d1;
|
|
48
|
-
if (sum !== 0) {
|
|
49
|
-
d0 /= sum;
|
|
50
|
-
d1 /= sum;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let v1 = vec2.scale([0, 0], v, -d0);
|
|
54
|
-
let v2 = vec2.scale([0, 0], v, d1);
|
|
55
|
-
|
|
56
|
-
cp1 = vec2.add([0, 0], point, v1);
|
|
57
|
-
nextCp0 = vec2.add([0, 0], point, v2);
|
|
58
|
-
|
|
59
|
-
// 下一个控制点必须在这个点和下一个点之间
|
|
60
|
-
nextCp0 = vec2.min([0, 0], nextCp0, vec2.max([0, 0], nextPoint, point));
|
|
61
|
-
nextCp0 = vec2.max([0, 0], nextCp0, vec2.min([0, 0], nextPoint, point));
|
|
62
|
-
|
|
63
|
-
// 重新计算 cp1 的值
|
|
64
|
-
v1 = vec2.sub([0, 0], nextCp0, point);
|
|
65
|
-
v1 = vec2.scale([0, 0], v1, -d0 / d1);
|
|
66
|
-
cp1 = vec2.add([0, 0], point, v1);
|
|
67
|
-
|
|
68
|
-
// 上一个控制点必须要在上一个点和这一个点之间
|
|
69
|
-
cp1 = vec2.min([0, 0], cp1, vec2.max([0, 0], prevPoint, point));
|
|
70
|
-
cp1 = vec2.max([0, 0], cp1, vec2.min([0, 0], prevPoint, point));
|
|
71
|
-
|
|
72
|
-
// 重新计算 nextCp0 的值
|
|
73
|
-
v2 = vec2.sub([0, 0], point, cp1);
|
|
74
|
-
v2 = vec2.scale([0, 0], v2, d1 / d0);
|
|
75
|
-
nextCp0 = vec2.add([0, 0], point, v2);
|
|
76
|
-
|
|
77
|
-
if (hasConstraint) {
|
|
78
|
-
cp1 = vec2.max([0, 0], cp1, min);
|
|
79
|
-
cp1 = vec2.min([0, 0], cp1, max);
|
|
80
|
-
nextCp0 = vec2.max([0, 0], nextCp0, min);
|
|
81
|
-
nextCp0 = vec2.min([0, 0], nextCp0, max);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
cps.push(cp0);
|
|
85
|
-
cps.push(cp1);
|
|
86
|
-
cp0 = nextCp0;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (isLoop) {
|
|
91
|
-
cps.push(cps.shift());
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return cps;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* create bezier spline from catmull rom spline
|
|
99
|
-
* @param {Array} crp Catmull Rom Points
|
|
100
|
-
* @param {boolean} z Spline is loop
|
|
101
|
-
* @param {Array} constraint Constraint
|
|
102
|
-
*/
|
|
103
|
-
export function catmullRom2Bezier(
|
|
104
|
-
crp: number[],
|
|
105
|
-
z = false,
|
|
106
|
-
constraint: Pos[] = [
|
|
107
|
-
[0, 0],
|
|
108
|
-
[1, 1],
|
|
109
|
-
],
|
|
110
|
-
): PathCommand[] {
|
|
111
|
-
const isLoop = !!z;
|
|
112
|
-
const pointList: Pos[] = [];
|
|
113
|
-
for (let i = 0, l = crp.length; i < l; i += 2) {
|
|
114
|
-
pointList.push([crp[i], crp[i + 1]]);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const controlPointList = smoothBezier(pointList, 0.4, isLoop, constraint);
|
|
118
|
-
const len = pointList.length;
|
|
119
|
-
const d1: PathCommand[] = [];
|
|
120
|
-
|
|
121
|
-
let cp1: vec2;
|
|
122
|
-
let cp2: vec2;
|
|
123
|
-
let p: Pos;
|
|
124
|
-
|
|
125
|
-
for (let i = 0; i < len - 1; i += 1) {
|
|
126
|
-
cp1 = controlPointList[i * 2];
|
|
127
|
-
cp2 = controlPointList[i * 2 + 1];
|
|
128
|
-
p = pointList[i + 1];
|
|
129
|
-
|
|
130
|
-
d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]]);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (isLoop) {
|
|
134
|
-
cp1 = controlPointList[len];
|
|
135
|
-
cp2 = controlPointList[len + 1];
|
|
136
|
-
[p] = pointList;
|
|
137
|
-
|
|
138
|
-
d1.push(['C', cp1[0], cp1[1], cp2[0], cp2[1], p[0], p[1]]);
|
|
139
|
-
}
|
|
140
|
-
return d1;
|
|
141
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import isEqual from 'fast-deep-equal';
|
|
2
|
-
|
|
3
|
-
export interface DiffType {
|
|
4
|
-
type: string;
|
|
5
|
-
min: number;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function getMinDiff(del: number, add: number, modify: number): DiffType {
|
|
9
|
-
let type = null;
|
|
10
|
-
let min = modify;
|
|
11
|
-
if (add < min) {
|
|
12
|
-
min = add;
|
|
13
|
-
type = 'add';
|
|
14
|
-
}
|
|
15
|
-
if (del < min) {
|
|
16
|
-
min = del;
|
|
17
|
-
type = 'del';
|
|
18
|
-
}
|
|
19
|
-
return {
|
|
20
|
-
type,
|
|
21
|
-
min,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/*
|
|
26
|
-
* https://en.wikipedia.org/wiki/Levenshtein_distance
|
|
27
|
-
* 计算两条path的编辑距离
|
|
28
|
-
*/
|
|
29
|
-
const levenshteinDistance = function (source: string, target: string): DiffType[][] {
|
|
30
|
-
const sourceLen = source.length;
|
|
31
|
-
const targetLen = target.length;
|
|
32
|
-
let sourceSegment, targetSegment;
|
|
33
|
-
let temp = 0;
|
|
34
|
-
if (sourceLen === 0 || targetLen === 0) {
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const dist = [];
|
|
38
|
-
for (let i = 0; i <= sourceLen; i++) {
|
|
39
|
-
dist[i] = [];
|
|
40
|
-
dist[i][0] = { min: i };
|
|
41
|
-
}
|
|
42
|
-
for (let j = 0; j <= targetLen; j++) {
|
|
43
|
-
dist[0][j] = { min: j };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
for (let i = 1; i <= sourceLen; i++) {
|
|
47
|
-
sourceSegment = source[i - 1];
|
|
48
|
-
for (let j = 1; j <= targetLen; j++) {
|
|
49
|
-
targetSegment = target[j - 1];
|
|
50
|
-
if (isEqual(sourceSegment, targetSegment)) {
|
|
51
|
-
temp = 0;
|
|
52
|
-
} else {
|
|
53
|
-
temp = 1;
|
|
54
|
-
}
|
|
55
|
-
const del = dist[i - 1][j].min + 1;
|
|
56
|
-
const add = dist[i][j - 1].min + 1;
|
|
57
|
-
const modify = dist[i - 1][j - 1].min + temp;
|
|
58
|
-
dist[i][j] = getMinDiff(del, add, modify);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return dist;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export function fillPathByDiff(source: string, target: string) {
|
|
65
|
-
const diffMatrix = levenshteinDistance(source, target);
|
|
66
|
-
let sourceLen = source.length;
|
|
67
|
-
const targetLen = target.length;
|
|
68
|
-
const changes = [];
|
|
69
|
-
let index = 1;
|
|
70
|
-
let minPos = 1;
|
|
71
|
-
// 如果source和target不是完全不相等
|
|
72
|
-
// @ts-ignore
|
|
73
|
-
if (diffMatrix[sourceLen][targetLen] !== sourceLen) {
|
|
74
|
-
// 获取从source到target所需改动
|
|
75
|
-
for (let i = 1; i <= sourceLen; i++) {
|
|
76
|
-
let min = diffMatrix[i][i].min;
|
|
77
|
-
minPos = i;
|
|
78
|
-
for (let j = index; j <= targetLen; j++) {
|
|
79
|
-
if (diffMatrix[i][j].min < min) {
|
|
80
|
-
min = diffMatrix[i][j].min;
|
|
81
|
-
minPos = j;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
index = minPos;
|
|
85
|
-
if (diffMatrix[i][index].type) {
|
|
86
|
-
changes.push({ index: i - 1, type: diffMatrix[i][index].type });
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// 对source进行增删path
|
|
90
|
-
for (let i = changes.length - 1; i >= 0; i--) {
|
|
91
|
-
index = changes[i].index;
|
|
92
|
-
if (changes[i].type === 'add') {
|
|
93
|
-
// @ts-ignore
|
|
94
|
-
source.splice(index, 0, [].concat(source[index]));
|
|
95
|
-
} else {
|
|
96
|
-
// @ts-ignore
|
|
97
|
-
source.splice(index, 1);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// source尾部补齐
|
|
103
|
-
sourceLen = source.length;
|
|
104
|
-
if (sourceLen < targetLen) {
|
|
105
|
-
for (let i = 0; i < targetLen - sourceLen; i++) {
|
|
106
|
-
if (source[sourceLen - 1][0] === 'z' || source[sourceLen - 1][0] === 'Z') {
|
|
107
|
-
// @ts-ignore
|
|
108
|
-
source.splice(sourceLen - 2, 0, source[sourceLen - 2]);
|
|
109
|
-
} else {
|
|
110
|
-
// @ts-ignore
|
|
111
|
-
source.push(source[sourceLen - 1]);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return source;
|
|
116
|
-
}
|
package/src/path/fill-path.ts
DELETED
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
function decasteljau(points, t) {
|
|
2
|
-
const left = [];
|
|
3
|
-
const right = [];
|
|
4
|
-
|
|
5
|
-
function recurse(points, t) {
|
|
6
|
-
if (points.length === 1) {
|
|
7
|
-
left.push(points[0]);
|
|
8
|
-
right.push(points[0]);
|
|
9
|
-
} else {
|
|
10
|
-
const middlePoints = [];
|
|
11
|
-
for (let i = 0; i < points.length - 1; i++) {
|
|
12
|
-
if (i === 0) {
|
|
13
|
-
left.push(points[0]);
|
|
14
|
-
}
|
|
15
|
-
if (i === points.length - 2) {
|
|
16
|
-
right.push(points[i + 1]);
|
|
17
|
-
}
|
|
18
|
-
middlePoints[i] = [
|
|
19
|
-
(1 - t) * points[i][0] + t * points[i + 1][0],
|
|
20
|
-
(1 - t) * points[i][1] + t * points[i + 1][1],
|
|
21
|
-
];
|
|
22
|
-
}
|
|
23
|
-
recurse(middlePoints, t);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (points.length) {
|
|
27
|
-
recurse(points, t);
|
|
28
|
-
}
|
|
29
|
-
return { left, right: right.reverse() };
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function splitCurve(start, end, count) {
|
|
33
|
-
const points = [[start[1], start[2]]];
|
|
34
|
-
count = count || 2;
|
|
35
|
-
const segments = [];
|
|
36
|
-
if (end[0] === 'A') {
|
|
37
|
-
points.push(end[6]);
|
|
38
|
-
points.push(end[7]);
|
|
39
|
-
} else if (end[0] === 'C') {
|
|
40
|
-
points.push([end[1], end[2]]);
|
|
41
|
-
points.push([end[3], end[4]]);
|
|
42
|
-
points.push([end[5], end[6]]);
|
|
43
|
-
} else if (end[0] === 'S' || end[0] === 'Q') {
|
|
44
|
-
points.push([end[1], end[2]]);
|
|
45
|
-
points.push([end[3], end[4]]);
|
|
46
|
-
} else {
|
|
47
|
-
points.push([end[1], end[2]]);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
let leftSegments = points;
|
|
51
|
-
const t = 1 / count;
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < count - 1; i++) {
|
|
54
|
-
const rt = t / (1 - t * i);
|
|
55
|
-
const split = decasteljau(leftSegments, rt);
|
|
56
|
-
segments.push(split.left);
|
|
57
|
-
leftSegments = split.right;
|
|
58
|
-
}
|
|
59
|
-
segments.push(leftSegments);
|
|
60
|
-
const result = segments.map((segment) => {
|
|
61
|
-
let cmd = [];
|
|
62
|
-
if (segment.length === 4) {
|
|
63
|
-
cmd.push('C');
|
|
64
|
-
cmd = cmd.concat(segment[2]);
|
|
65
|
-
}
|
|
66
|
-
if (segment.length >= 3) {
|
|
67
|
-
if (segment.length === 3) {
|
|
68
|
-
cmd.push('Q');
|
|
69
|
-
}
|
|
70
|
-
cmd = cmd.concat(segment[1]);
|
|
71
|
-
}
|
|
72
|
-
if (segment.length === 2) {
|
|
73
|
-
cmd.push('L');
|
|
74
|
-
}
|
|
75
|
-
cmd = cmd.concat(segment[segment.length - 1]);
|
|
76
|
-
return cmd;
|
|
77
|
-
});
|
|
78
|
-
return result;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function splitSegment(start, end, count) {
|
|
82
|
-
if (count === 1) {
|
|
83
|
-
return [[].concat(start)];
|
|
84
|
-
}
|
|
85
|
-
let segments = [];
|
|
86
|
-
if (end[0] === 'L' || end[0] === 'C' || end[0] === 'Q') {
|
|
87
|
-
segments = segments.concat(splitCurve(start, end, count));
|
|
88
|
-
} else {
|
|
89
|
-
const temp = [].concat(start);
|
|
90
|
-
if (temp[0] === 'M') {
|
|
91
|
-
temp[0] = 'L';
|
|
92
|
-
}
|
|
93
|
-
for (let i = 0; i <= count - 1; i++) {
|
|
94
|
-
segments.push(temp);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return segments;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function fillPath(source, target) {
|
|
101
|
-
if (source.length === 1) {
|
|
102
|
-
return source;
|
|
103
|
-
}
|
|
104
|
-
const sourceLen = source.length - 1;
|
|
105
|
-
const targetLen = target.length - 1;
|
|
106
|
-
const ratio = sourceLen / targetLen;
|
|
107
|
-
const segmentsToFill = [];
|
|
108
|
-
if (source.length === 1 && source[0][0] === 'M') {
|
|
109
|
-
for (let i = 0; i < targetLen - sourceLen; i++) {
|
|
110
|
-
source.push(source[0]);
|
|
111
|
-
}
|
|
112
|
-
return source;
|
|
113
|
-
}
|
|
114
|
-
for (let i = 0; i < targetLen; i++) {
|
|
115
|
-
const index = Math.floor(ratio * i);
|
|
116
|
-
segmentsToFill[index] = (segmentsToFill[index] || 0) + 1;
|
|
117
|
-
}
|
|
118
|
-
const filled = segmentsToFill.reduce((filled, count, i) => {
|
|
119
|
-
if (i === sourceLen) {
|
|
120
|
-
return filled.concat(source[sourceLen]);
|
|
121
|
-
}
|
|
122
|
-
return filled.concat(splitSegment(source[i], source[i + 1], count));
|
|
123
|
-
}, []);
|
|
124
|
-
filled.unshift(source[0]);
|
|
125
|
-
if (target[targetLen] === 'Z' || target[targetLen] === 'z') {
|
|
126
|
-
filled.push('Z');
|
|
127
|
-
}
|
|
128
|
-
return filled;
|
|
129
|
-
}
|
package/src/path/format-path.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* 抽取pathSegment中的关键点
|
|
3
|
-
* M,L,A,Q,H,V一个端点
|
|
4
|
-
* Q, S抽取一个端点,一个控制点
|
|
5
|
-
* C抽取一个端点,两个控制点
|
|
6
|
-
*/
|
|
7
|
-
function _getSegmentPoints(segment: any[]): number[][] {
|
|
8
|
-
const points = [];
|
|
9
|
-
switch (segment[0]) {
|
|
10
|
-
case 'M':
|
|
11
|
-
points.push([segment[1], segment[2]]);
|
|
12
|
-
break;
|
|
13
|
-
case 'L':
|
|
14
|
-
points.push([segment[1], segment[2]]);
|
|
15
|
-
break;
|
|
16
|
-
case 'A':
|
|
17
|
-
points.push([segment[6], segment[7]]);
|
|
18
|
-
break;
|
|
19
|
-
case 'Q':
|
|
20
|
-
points.push([segment[3], segment[4]]);
|
|
21
|
-
points.push([segment[1], segment[2]]);
|
|
22
|
-
break;
|
|
23
|
-
case 'T':
|
|
24
|
-
points.push([segment[1], segment[2]]);
|
|
25
|
-
break;
|
|
26
|
-
case 'C':
|
|
27
|
-
points.push([segment[5], segment[6]]);
|
|
28
|
-
points.push([segment[1], segment[2]]);
|
|
29
|
-
points.push([segment[3], segment[4]]);
|
|
30
|
-
break;
|
|
31
|
-
case 'S':
|
|
32
|
-
points.push([segment[3], segment[4]]);
|
|
33
|
-
points.push([segment[1], segment[2]]);
|
|
34
|
-
break;
|
|
35
|
-
case 'H':
|
|
36
|
-
points.push([segment[1], segment[1]]);
|
|
37
|
-
break;
|
|
38
|
-
case 'V':
|
|
39
|
-
points.push([segment[1], segment[1]]);
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
}
|
|
43
|
-
return points;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 将两个点均分成count个点
|
|
47
|
-
function _splitPoints(points: number[][], former: any[], count: number) {
|
|
48
|
-
const result = [].concat(points);
|
|
49
|
-
let index;
|
|
50
|
-
let t = 1 / (count + 1);
|
|
51
|
-
const formerEnd = _getSegmentPoints(former)[0];
|
|
52
|
-
for (let i = 1; i <= count; i++) {
|
|
53
|
-
t *= i;
|
|
54
|
-
index = Math.floor(points.length * t);
|
|
55
|
-
if (index === 0) {
|
|
56
|
-
result.unshift([formerEnd[0] * t + points[index][0] * (1 - t), formerEnd[1] * t + points[index][1] * (1 - t)]);
|
|
57
|
-
} else {
|
|
58
|
-
result.splice(index, 0, [
|
|
59
|
-
formerEnd[0] * t + points[index][0] * (1 - t),
|
|
60
|
-
formerEnd[1] * t + points[index][1] * (1 - t),
|
|
61
|
-
]);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return result;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
export function formatPath(fromPath: any[][], toPath: any[][]): any[][] {
|
|
68
|
-
if (fromPath.length <= 1) {
|
|
69
|
-
return fromPath;
|
|
70
|
-
}
|
|
71
|
-
let points;
|
|
72
|
-
for (let i = 0; i < toPath.length; i++) {
|
|
73
|
-
if (fromPath[i][0] !== toPath[i][0]) {
|
|
74
|
-
// 获取fromPath的pathSegment的端点,根据toPath的指令对其改造
|
|
75
|
-
points = _getSegmentPoints(fromPath[i]);
|
|
76
|
-
switch (toPath[i][0]) {
|
|
77
|
-
case 'M':
|
|
78
|
-
fromPath[i] = ['M'].concat(points[0]);
|
|
79
|
-
break;
|
|
80
|
-
case 'L':
|
|
81
|
-
fromPath[i] = ['L'].concat(points[0]);
|
|
82
|
-
break;
|
|
83
|
-
case 'A':
|
|
84
|
-
fromPath[i] = [].concat(toPath[i]);
|
|
85
|
-
fromPath[i][6] = points[0][0];
|
|
86
|
-
fromPath[i][7] = points[0][1];
|
|
87
|
-
break;
|
|
88
|
-
case 'Q':
|
|
89
|
-
if (points.length < 2) {
|
|
90
|
-
if (i > 0) {
|
|
91
|
-
points = _splitPoints(points, fromPath[i - 1], 1);
|
|
92
|
-
} else {
|
|
93
|
-
fromPath[i] = toPath[i];
|
|
94
|
-
break;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
fromPath[i] = ['Q'].concat(
|
|
98
|
-
points.reduce((arr, i) => {
|
|
99
|
-
return arr.concat(i);
|
|
100
|
-
}, []),
|
|
101
|
-
);
|
|
102
|
-
break;
|
|
103
|
-
case 'T':
|
|
104
|
-
fromPath[i] = ['T'].concat(points[0]);
|
|
105
|
-
break;
|
|
106
|
-
case 'C':
|
|
107
|
-
if (points.length < 3) {
|
|
108
|
-
if (i > 0) {
|
|
109
|
-
points = _splitPoints(points, fromPath[i - 1], 2);
|
|
110
|
-
} else {
|
|
111
|
-
fromPath[i] = toPath[i];
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
fromPath[i] = ['C'].concat(
|
|
116
|
-
points.reduce((arr, i) => {
|
|
117
|
-
return arr.concat(i);
|
|
118
|
-
}, []),
|
|
119
|
-
);
|
|
120
|
-
break;
|
|
121
|
-
case 'S':
|
|
122
|
-
if (points.length < 2) {
|
|
123
|
-
if (i > 0) {
|
|
124
|
-
points = _splitPoints(points, fromPath[i - 1], 1);
|
|
125
|
-
} else {
|
|
126
|
-
fromPath[i] = toPath[i];
|
|
127
|
-
break;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
fromPath[i] = ['S'].concat(
|
|
131
|
-
points.reduce((arr, i) => {
|
|
132
|
-
return arr.concat(i);
|
|
133
|
-
}, []),
|
|
134
|
-
);
|
|
135
|
-
break;
|
|
136
|
-
default:
|
|
137
|
-
fromPath[i] = toPath[i];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
return fromPath;
|
|
142
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { mod, toRadian } from '../helper';
|
|
2
|
-
|
|
3
|
-
// 向量长度
|
|
4
|
-
function vMag(v) {
|
|
5
|
-
return Math.sqrt(v[0] * v[0] + v[1] * v[1]);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// u.v/|u||v|,计算夹角的余弦值
|
|
9
|
-
function vRatio(u, v) {
|
|
10
|
-
// 当存在一个向量的长度为 0 时,夹角也为 0,即夹角的余弦值为 1
|
|
11
|
-
return vMag(u) * vMag(v) ? (u[0] * v[0] + u[1] * v[1]) / (vMag(u) * vMag(v)) : 1;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// 向量角度
|
|
15
|
-
function vAngle(u, v) {
|
|
16
|
-
return (u[0] * v[1] < u[1] * v[0] ? -1 : 1) * Math.acos(vRatio(u, v));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 判断两个点是否重合,点坐标的格式为 [x, y]
|
|
21
|
-
* @param {Array} point1 第一个点
|
|
22
|
-
* @param {Array} point2 第二个点
|
|
23
|
-
*/
|
|
24
|
-
export function isSamePoint(point1, point2) {
|
|
25
|
-
return point1[0] === point2[0] && point1[1] === point2[1];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// A 0:rx 1:ry 2:x-axis-rotation 3:large-arc-flag 4:sweep-flag 5: x 6: y
|
|
29
|
-
export function getArcParams(startPoint, params) {
|
|
30
|
-
let rx = params[1];
|
|
31
|
-
let ry = params[2];
|
|
32
|
-
const xRotation = mod(toRadian(params[3]), Math.PI * 2);
|
|
33
|
-
const arcFlag = params[4];
|
|
34
|
-
const sweepFlag = params[5];
|
|
35
|
-
// 弧形起点坐标
|
|
36
|
-
const x1 = startPoint[0];
|
|
37
|
-
const y1 = startPoint[1];
|
|
38
|
-
// 弧形终点坐标
|
|
39
|
-
const x2 = params[6];
|
|
40
|
-
const y2 = params[7];
|
|
41
|
-
const xp = (Math.cos(xRotation) * (x1 - x2)) / 2.0 + (Math.sin(xRotation) * (y1 - y2)) / 2.0;
|
|
42
|
-
const yp = (-1 * Math.sin(xRotation) * (x1 - x2)) / 2.0 + (Math.cos(xRotation) * (y1 - y2)) / 2.0;
|
|
43
|
-
const lambda = (xp * xp) / (rx * rx) + (yp * yp) / (ry * ry);
|
|
44
|
-
|
|
45
|
-
if (lambda > 1) {
|
|
46
|
-
rx *= Math.sqrt(lambda);
|
|
47
|
-
ry *= Math.sqrt(lambda);
|
|
48
|
-
}
|
|
49
|
-
const diff = rx * rx * (yp * yp) + ry * ry * (xp * xp);
|
|
50
|
-
|
|
51
|
-
let f = diff ? Math.sqrt((rx * rx * (ry * ry) - diff) / diff) : 1;
|
|
52
|
-
|
|
53
|
-
if (arcFlag === sweepFlag) {
|
|
54
|
-
f *= -1;
|
|
55
|
-
}
|
|
56
|
-
if (isNaN(f)) {
|
|
57
|
-
f = 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// 旋转前的起点坐标,且当长半轴和短半轴的长度为 0 时,坐标按 (0, 0) 处理
|
|
61
|
-
const cxp = ry ? (f * rx * yp) / ry : 0;
|
|
62
|
-
const cyp = rx ? (f * -ry * xp) / rx : 0;
|
|
63
|
-
|
|
64
|
-
// 椭圆圆心坐标
|
|
65
|
-
const cx = (x1 + x2) / 2.0 + Math.cos(xRotation) * cxp - Math.sin(xRotation) * cyp;
|
|
66
|
-
const cy = (y1 + y2) / 2.0 + Math.sin(xRotation) * cxp + Math.cos(xRotation) * cyp;
|
|
67
|
-
|
|
68
|
-
// 起始点的单位向量
|
|
69
|
-
const u = [(xp - cxp) / rx, (yp - cyp) / ry];
|
|
70
|
-
// 终止点的单位向量
|
|
71
|
-
const v = [(-1 * xp - cxp) / rx, (-1 * yp - cyp) / ry];
|
|
72
|
-
// 计算起始点和圆心的连线,与 x 轴正方向的夹角
|
|
73
|
-
const theta = vAngle([1, 0], u);
|
|
74
|
-
|
|
75
|
-
// 计算圆弧起始点和终止点与椭圆圆心连线的夹角
|
|
76
|
-
let dTheta = vAngle(u, v);
|
|
77
|
-
|
|
78
|
-
if (vRatio(u, v) <= -1) {
|
|
79
|
-
dTheta = Math.PI;
|
|
80
|
-
}
|
|
81
|
-
if (vRatio(u, v) >= 1) {
|
|
82
|
-
dTheta = 0;
|
|
83
|
-
}
|
|
84
|
-
if (sweepFlag === 0 && dTheta > 0) {
|
|
85
|
-
dTheta = dTheta - 2 * Math.PI;
|
|
86
|
-
}
|
|
87
|
-
if (sweepFlag === 1 && dTheta < 0) {
|
|
88
|
-
dTheta = dTheta + 2 * Math.PI;
|
|
89
|
-
}
|
|
90
|
-
return {
|
|
91
|
-
cx,
|
|
92
|
-
cy,
|
|
93
|
-
// 弧形的起点和终点相同时,长轴和短轴的长度按 0 处理
|
|
94
|
-
rx: isSamePoint(startPoint, [x2, y2]) ? 0 : rx,
|
|
95
|
-
ry: isSamePoint(startPoint, [x2, y2]) ? 0 : ry,
|
|
96
|
-
startAngle: theta,
|
|
97
|
-
endAngle: theta + dTheta,
|
|
98
|
-
xRotation,
|
|
99
|
-
arcFlag,
|
|
100
|
-
sweepFlag,
|
|
101
|
-
};
|
|
102
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
type Point = {
|
|
2
|
-
/**
|
|
3
|
-
* x 值
|
|
4
|
-
* @type {number}
|
|
5
|
-
*/
|
|
6
|
-
x: number;
|
|
7
|
-
/**
|
|
8
|
-
* y 值
|
|
9
|
-
* @type {number}
|
|
10
|
-
*/
|
|
11
|
-
y: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const isBetween = (value: number, min: number, max: number) => value >= min && value <= max;
|
|
15
|
-
|
|
16
|
-
export function getLineIntersect(p0: Point, p1: Point, p2: Point, p3: Point): Point | null {
|
|
17
|
-
const tolerance = 0.001;
|
|
18
|
-
const E: Point = {
|
|
19
|
-
x: p2.x - p0.x,
|
|
20
|
-
y: p2.y - p0.y,
|
|
21
|
-
};
|
|
22
|
-
const D0: Point = {
|
|
23
|
-
x: p1.x - p0.x,
|
|
24
|
-
y: p1.y - p0.y,
|
|
25
|
-
};
|
|
26
|
-
const D1: Point = {
|
|
27
|
-
x: p3.x - p2.x,
|
|
28
|
-
y: p3.y - p2.y,
|
|
29
|
-
};
|
|
30
|
-
const kross: number = D0.x * D1.y - D0.y * D1.x;
|
|
31
|
-
const sqrKross: number = kross * kross;
|
|
32
|
-
const sqrLen0: number = D0.x * D0.x + D0.y * D0.y;
|
|
33
|
-
const sqrLen1: number = D1.x * D1.x + D1.y * D1.y;
|
|
34
|
-
let point: Point | null = null;
|
|
35
|
-
if (sqrKross > tolerance * sqrLen0 * sqrLen1) {
|
|
36
|
-
const s = (E.x * D1.y - E.y * D1.x) / kross;
|
|
37
|
-
const t = (E.x * D0.y - E.y * D0.x) / kross;
|
|
38
|
-
if (isBetween(s, 0, 1) && isBetween(t, 0, 1)) {
|
|
39
|
-
point = {
|
|
40
|
-
x: p0.x + s * D0.x,
|
|
41
|
-
y: p0.y + s * D0.y,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return point;
|
|
46
|
-
}
|