@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,221 +1,338 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
centerx: number,
|
|
10
|
-
centery: number,
|
|
11
|
-
) => {
|
|
12
|
-
x *= rx;
|
|
13
|
-
y *= ry;
|
|
14
|
-
|
|
15
|
-
const xp = cosphi * x - sinphi * y;
|
|
16
|
-
const yp = sinphi * x + cosphi * y;
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
x: xp + centerx,
|
|
20
|
-
y: yp + centery,
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const approxUnitArc = (ang1: number, ang2: number) => {
|
|
25
|
-
// If 90 degree circular arc, use a constant
|
|
26
|
-
// as derived from http://spencermortensen.com/articles/bezier-circle
|
|
27
|
-
const a =
|
|
28
|
-
ang2 === 1.5707963267948966
|
|
29
|
-
? 0.551915024494
|
|
30
|
-
: ang2 === -1.5707963267948966
|
|
31
|
-
? -0.551915024494
|
|
32
|
-
: (4 / 3) * Math.tan(ang2 / 4);
|
|
33
|
-
|
|
34
|
-
const x1 = Math.cos(ang1);
|
|
35
|
-
const y1 = Math.sin(ang1);
|
|
36
|
-
const x2 = Math.cos(ang1 + ang2);
|
|
37
|
-
const y2 = Math.sin(ang1 + ang2);
|
|
38
|
-
|
|
39
|
-
return [
|
|
40
|
-
{
|
|
41
|
-
x: x1 - y1 * a,
|
|
42
|
-
y: y1 + x1 * a,
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
x: x2 + y2 * a,
|
|
46
|
-
y: y2 - x2 * a,
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
x: x2,
|
|
50
|
-
y: y2,
|
|
51
|
-
},
|
|
52
|
-
];
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const vectorAngle = (ux: number, uy: number, vx: number, vy: number) => {
|
|
56
|
-
const sign = ux * vy - uy * vx < 0 ? -1 : 1;
|
|
57
|
-
|
|
58
|
-
let dot = ux * vx + uy * vy;
|
|
59
|
-
|
|
60
|
-
if (dot > 1) {
|
|
61
|
-
dot = 1;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
if (dot < -1) {
|
|
65
|
-
dot = -1;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return sign * Math.acos(dot);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const getArcCenter = (
|
|
72
|
-
px: any,
|
|
73
|
-
py: any,
|
|
74
|
-
cx: any,
|
|
75
|
-
cy: any,
|
|
76
|
-
rx: number,
|
|
77
|
-
ry: number,
|
|
78
|
-
largeArcFlag: number,
|
|
79
|
-
sweepFlag: number,
|
|
80
|
-
sinphi: number,
|
|
81
|
-
cosphi: number,
|
|
82
|
-
pxp: number,
|
|
83
|
-
pyp: number,
|
|
84
|
-
) => {
|
|
85
|
-
const rxsq = Math.pow(rx, 2);
|
|
86
|
-
const rysq = Math.pow(ry, 2);
|
|
87
|
-
const pxpsq = Math.pow(pxp, 2);
|
|
88
|
-
const pypsq = Math.pow(pyp, 2);
|
|
89
|
-
|
|
90
|
-
let radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
|
|
91
|
-
|
|
92
|
-
if (radicant < 0) {
|
|
93
|
-
radicant = 0;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
radicant /= rxsq * pypsq + rysq * pxpsq;
|
|
97
|
-
radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
|
|
98
|
-
|
|
99
|
-
const centerxp = ((radicant * rx) / ry) * pyp;
|
|
100
|
-
const centeryp = ((radicant * -ry) / rx) * pxp;
|
|
101
|
-
|
|
102
|
-
const centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
|
|
103
|
-
const centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
|
|
104
|
-
|
|
105
|
-
const vx1 = (pxp - centerxp) / rx;
|
|
106
|
-
const vy1 = (pyp - centeryp) / ry;
|
|
107
|
-
const vx2 = (-pxp - centerxp) / rx;
|
|
108
|
-
const vy2 = (-pyp - centeryp) / ry;
|
|
109
|
-
|
|
110
|
-
const ang1 = vectorAngle(1, 0, vx1, vy1);
|
|
111
|
-
let ang2 = vectorAngle(vx1, vy1, vx2, vy2);
|
|
112
|
-
|
|
113
|
-
if (sweepFlag === 0 && ang2 > 0) {
|
|
114
|
-
ang2 -= TAU;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (sweepFlag === 1 && ang2 < 0) {
|
|
118
|
-
ang2 += TAU;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
return [centerx, centery, ang1, ang2];
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
const arcToBezier = ({ px, py, cx, cy, rx, ry, xAxisRotation = 0, largeArcFlag = 0, sweepFlag = 0 }) => {
|
|
125
|
-
const curves = [];
|
|
126
|
-
|
|
127
|
-
if (rx === 0 || ry === 0) {
|
|
128
|
-
return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
const sinphi = Math.sin((xAxisRotation * TAU) / 360);
|
|
132
|
-
const cosphi = Math.cos((xAxisRotation * TAU) / 360);
|
|
133
|
-
|
|
134
|
-
const pxp = (cosphi * (px - cx)) / 2 + (sinphi * (py - cy)) / 2;
|
|
135
|
-
const pyp = (-sinphi * (px - cx)) / 2 + (cosphi * (py - cy)) / 2;
|
|
136
|
-
|
|
137
|
-
if (pxp === 0 && pyp === 0) {
|
|
138
|
-
return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
rx = Math.abs(rx);
|
|
142
|
-
ry = Math.abs(ry);
|
|
143
|
-
|
|
144
|
-
const lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
|
|
145
|
-
|
|
146
|
-
if (lambda > 1) {
|
|
147
|
-
rx *= Math.sqrt(lambda);
|
|
148
|
-
ry *= Math.sqrt(lambda);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
let [centerx, centery, ang1, ang2] = getArcCenter(
|
|
152
|
-
px,
|
|
153
|
-
py,
|
|
154
|
-
cx,
|
|
155
|
-
cy,
|
|
156
|
-
rx,
|
|
157
|
-
ry,
|
|
158
|
-
largeArcFlag,
|
|
159
|
-
sweepFlag,
|
|
160
|
-
sinphi,
|
|
161
|
-
cosphi,
|
|
162
|
-
pxp,
|
|
163
|
-
pyp,
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
// If 'ang2' == 90.0000000001, then `ratio` will evaluate to
|
|
167
|
-
// 1.0000000001. This causes `segments` to be greater than one, which is an
|
|
168
|
-
// unecessary split, and adds extra points to the bezier curve. To alleviate
|
|
169
|
-
// this issue, we round to 1.0 when the ratio is close to 1.0.
|
|
170
|
-
let ratio = Math.abs(ang2) / (TAU / 4);
|
|
171
|
-
if (Math.abs(1.0 - ratio) < 0.0000001) {
|
|
172
|
-
ratio = 1.0;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const segments = Math.max(Math.ceil(ratio), 1);
|
|
176
|
-
|
|
177
|
-
ang2 /= segments;
|
|
178
|
-
|
|
179
|
-
for (let i = 0; i < segments; i++) {
|
|
180
|
-
curves.push(approxUnitArc(ang1, ang2));
|
|
181
|
-
ang1 += ang2;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return curves.map((curve) => {
|
|
185
|
-
const { x: x1, y: y1 } = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery);
|
|
186
|
-
const { x: x2, y: y2 } = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery);
|
|
187
|
-
const { x, y } = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery);
|
|
188
|
-
|
|
189
|
-
return { x1, y1, x2, y2, x, y };
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
|
|
1
|
+
import { rotateVector } from '../util/rotate-vector';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Converts A (arc-to) segments to C (cubic-bezier-to).
|
|
5
|
+
*
|
|
6
|
+
* For more information of where this math came from visit:
|
|
7
|
+
* http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
|
|
8
|
+
*/
|
|
193
9
|
export function arcToCubic(
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
10
|
+
X1: number,
|
|
11
|
+
Y1: number,
|
|
12
|
+
RX: number,
|
|
13
|
+
RY: number,
|
|
198
14
|
angle: number,
|
|
199
15
|
LAF: number,
|
|
200
16
|
SF: number,
|
|
201
|
-
|
|
202
|
-
|
|
17
|
+
X2: number,
|
|
18
|
+
Y2: number,
|
|
19
|
+
recursive: number[],
|
|
203
20
|
) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
21
|
+
let x1 = X1;
|
|
22
|
+
let y1 = Y1;
|
|
23
|
+
let rx = RX;
|
|
24
|
+
let ry = RY;
|
|
25
|
+
let x2 = X2;
|
|
26
|
+
let y2 = Y2;
|
|
27
|
+
// for more information of where this Math came from visit:
|
|
28
|
+
// http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes
|
|
29
|
+
const d120 = (Math.PI * 120) / 180;
|
|
30
|
+
|
|
31
|
+
const rad = (Math.PI / 180) * (+angle || 0);
|
|
32
|
+
/** @type {number[]} */
|
|
33
|
+
let res = [];
|
|
34
|
+
let xy;
|
|
35
|
+
let f1;
|
|
36
|
+
let f2;
|
|
37
|
+
let cx;
|
|
38
|
+
let cy;
|
|
39
|
+
|
|
40
|
+
if (!recursive) {
|
|
41
|
+
xy = rotateVector(x1, y1, -rad);
|
|
42
|
+
x1 = xy.x;
|
|
43
|
+
y1 = xy.y;
|
|
44
|
+
xy = rotateVector(x2, y2, -rad);
|
|
45
|
+
x2 = xy.x;
|
|
46
|
+
y2 = xy.y;
|
|
47
|
+
|
|
48
|
+
const x = (x1 - x2) / 2;
|
|
49
|
+
const y = (y1 - y2) / 2;
|
|
50
|
+
let h = (x * x) / (rx * rx) + (y * y) / (ry * ry);
|
|
51
|
+
if (h > 1) {
|
|
52
|
+
h = Math.sqrt(h);
|
|
53
|
+
rx *= h;
|
|
54
|
+
ry *= h;
|
|
55
|
+
}
|
|
56
|
+
const rx2 = rx * rx;
|
|
57
|
+
const ry2 = ry * ry;
|
|
58
|
+
|
|
59
|
+
const k =
|
|
60
|
+
(LAF === SF ? -1 : 1) *
|
|
61
|
+
Math.sqrt(Math.abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x)));
|
|
62
|
+
|
|
63
|
+
cx = (k * rx * y) / ry + (x1 + x2) / 2;
|
|
64
|
+
cy = (k * -ry * x) / rx + (y1 + y2) / 2;
|
|
65
|
+
// eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
|
|
66
|
+
f1 = Math.asin(((((y1 - cy) / ry) * 10 ** 9) >> 0) / 10 ** 9);
|
|
67
|
+
// eslint-disable-next-line no-bitwise -- Impossible to satisfy no-bitwise
|
|
68
|
+
f2 = Math.asin(((((y2 - cy) / ry) * 10 ** 9) >> 0) / 10 ** 9);
|
|
69
|
+
|
|
70
|
+
f1 = x1 < cx ? Math.PI - f1 : f1;
|
|
71
|
+
f2 = x2 < cx ? Math.PI - f2 : f2;
|
|
72
|
+
if (f1 < 0) f1 = Math.PI * 2 + f1;
|
|
73
|
+
if (f2 < 0) f2 = Math.PI * 2 + f2;
|
|
74
|
+
if (SF && f1 > f2) {
|
|
75
|
+
f1 -= Math.PI * 2;
|
|
76
|
+
}
|
|
77
|
+
if (!SF && f2 > f1) {
|
|
78
|
+
f2 -= Math.PI * 2;
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
[f1, f2, cx, cy] = recursive;
|
|
82
|
+
}
|
|
83
|
+
let df = f2 - f1;
|
|
84
|
+
if (Math.abs(df) > d120) {
|
|
85
|
+
const f2old = f2;
|
|
86
|
+
const x2old = x2;
|
|
87
|
+
const y2old = y2;
|
|
88
|
+
f2 = f1 + d120 * (SF && f2 > f1 ? 1 : -1);
|
|
89
|
+
x2 = cx + rx * Math.cos(f2);
|
|
90
|
+
y2 = cy + ry * Math.sin(f2);
|
|
91
|
+
res = arcToCubic(x2, y2, rx, ry, angle, 0, SF, x2old, y2old, [f2, f2old, cx, cy]);
|
|
92
|
+
}
|
|
93
|
+
df = f2 - f1;
|
|
94
|
+
const c1 = Math.cos(f1);
|
|
95
|
+
const s1 = Math.sin(f1);
|
|
96
|
+
const c2 = Math.cos(f2);
|
|
97
|
+
const s2 = Math.sin(f2);
|
|
98
|
+
const t = Math.tan(df / 4);
|
|
99
|
+
const hx = (4 / 3) * rx * t;
|
|
100
|
+
const hy = (4 / 3) * ry * t;
|
|
101
|
+
const m1 = [x1, y1];
|
|
102
|
+
const m2 = [x1 + hx * s1, y1 - hy * c1];
|
|
103
|
+
const m3 = [x2 + hx * s2, y2 - hy * c2];
|
|
104
|
+
const m4 = [x2, y2];
|
|
105
|
+
m2[0] = 2 * m1[0] - m2[0];
|
|
106
|
+
m2[1] = 2 * m1[1] - m2[1];
|
|
107
|
+
if (recursive) {
|
|
108
|
+
return [...m2, ...m3, ...m4, ...res];
|
|
109
|
+
}
|
|
110
|
+
res = [...m2, ...m3, ...m4, ...res];
|
|
111
|
+
const newres = [];
|
|
112
|
+
for (let i = 0, ii = res.length; i < ii; i += 1) {
|
|
113
|
+
newres[i] = i % 2 ? rotateVector(res[i - 1], res[i], rad).y : rotateVector(res[i], res[i + 1], rad).x;
|
|
114
|
+
}
|
|
115
|
+
return newres;
|
|
221
116
|
}
|
|
117
|
+
|
|
118
|
+
// const TAU = Math.PI * 2;
|
|
119
|
+
|
|
120
|
+
// const mapToEllipse = (
|
|
121
|
+
// { x, y }: { x: number; y: number },
|
|
122
|
+
// rx: number,
|
|
123
|
+
// ry: number,
|
|
124
|
+
// cosphi: number,
|
|
125
|
+
// sinphi: number,
|
|
126
|
+
// centerx: number,
|
|
127
|
+
// centery: number,
|
|
128
|
+
// ) => {
|
|
129
|
+
// x *= rx;
|
|
130
|
+
// y *= ry;
|
|
131
|
+
|
|
132
|
+
// const xp = cosphi * x - sinphi * y;
|
|
133
|
+
// const yp = sinphi * x + cosphi * y;
|
|
134
|
+
|
|
135
|
+
// return {
|
|
136
|
+
// x: xp + centerx,
|
|
137
|
+
// y: yp + centery,
|
|
138
|
+
// };
|
|
139
|
+
// };
|
|
140
|
+
|
|
141
|
+
// const approxUnitArc = (ang1: number, ang2: number) => {
|
|
142
|
+
// // If 90 degree circular arc, use a constant
|
|
143
|
+
// // as derived from http://spencermortensen.com/articles/bezier-circle
|
|
144
|
+
// const a =
|
|
145
|
+
// ang2 === 1.5707963267948966
|
|
146
|
+
// ? 0.551915024494
|
|
147
|
+
// : ang2 === -1.5707963267948966
|
|
148
|
+
// ? -0.551915024494
|
|
149
|
+
// : (4 / 3) * Math.tan(ang2 / 4);
|
|
150
|
+
|
|
151
|
+
// const x1 = Math.cos(ang1);
|
|
152
|
+
// const y1 = Math.sin(ang1);
|
|
153
|
+
// const x2 = Math.cos(ang1 + ang2);
|
|
154
|
+
// const y2 = Math.sin(ang1 + ang2);
|
|
155
|
+
|
|
156
|
+
// return [
|
|
157
|
+
// {
|
|
158
|
+
// x: x1 - y1 * a,
|
|
159
|
+
// y: y1 + x1 * a,
|
|
160
|
+
// },
|
|
161
|
+
// {
|
|
162
|
+
// x: x2 + y2 * a,
|
|
163
|
+
// y: y2 - x2 * a,
|
|
164
|
+
// },
|
|
165
|
+
// {
|
|
166
|
+
// x: x2,
|
|
167
|
+
// y: y2,
|
|
168
|
+
// },
|
|
169
|
+
// ];
|
|
170
|
+
// };
|
|
171
|
+
|
|
172
|
+
// const vectorAngle = (ux: number, uy: number, vx: number, vy: number) => {
|
|
173
|
+
// const sign = ux * vy - uy * vx < 0 ? -1 : 1;
|
|
174
|
+
|
|
175
|
+
// let dot = ux * vx + uy * vy;
|
|
176
|
+
|
|
177
|
+
// if (dot > 1) {
|
|
178
|
+
// dot = 1;
|
|
179
|
+
// }
|
|
180
|
+
|
|
181
|
+
// if (dot < -1) {
|
|
182
|
+
// dot = -1;
|
|
183
|
+
// }
|
|
184
|
+
|
|
185
|
+
// return sign * Math.acos(dot);
|
|
186
|
+
// };
|
|
187
|
+
|
|
188
|
+
// const getArcCenter = (
|
|
189
|
+
// px: any,
|
|
190
|
+
// py: any,
|
|
191
|
+
// cx: any,
|
|
192
|
+
// cy: any,
|
|
193
|
+
// rx: number,
|
|
194
|
+
// ry: number,
|
|
195
|
+
// largeArcFlag: number,
|
|
196
|
+
// sweepFlag: number,
|
|
197
|
+
// sinphi: number,
|
|
198
|
+
// cosphi: number,
|
|
199
|
+
// pxp: number,
|
|
200
|
+
// pyp: number,
|
|
201
|
+
// ) => {
|
|
202
|
+
// const rxsq = Math.pow(rx, 2);
|
|
203
|
+
// const rysq = Math.pow(ry, 2);
|
|
204
|
+
// const pxpsq = Math.pow(pxp, 2);
|
|
205
|
+
// const pypsq = Math.pow(pyp, 2);
|
|
206
|
+
|
|
207
|
+
// let radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq;
|
|
208
|
+
|
|
209
|
+
// if (radicant < 0) {
|
|
210
|
+
// radicant = 0;
|
|
211
|
+
// }
|
|
212
|
+
|
|
213
|
+
// radicant /= rxsq * pypsq + rysq * pxpsq;
|
|
214
|
+
// radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1);
|
|
215
|
+
|
|
216
|
+
// const centerxp = ((radicant * rx) / ry) * pyp;
|
|
217
|
+
// const centeryp = ((radicant * -ry) / rx) * pxp;
|
|
218
|
+
|
|
219
|
+
// const centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2;
|
|
220
|
+
// const centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2;
|
|
221
|
+
|
|
222
|
+
// const vx1 = (pxp - centerxp) / rx;
|
|
223
|
+
// const vy1 = (pyp - centeryp) / ry;
|
|
224
|
+
// const vx2 = (-pxp - centerxp) / rx;
|
|
225
|
+
// const vy2 = (-pyp - centeryp) / ry;
|
|
226
|
+
|
|
227
|
+
// const ang1 = vectorAngle(1, 0, vx1, vy1);
|
|
228
|
+
// let ang2 = vectorAngle(vx1, vy1, vx2, vy2);
|
|
229
|
+
|
|
230
|
+
// if (sweepFlag === 0 && ang2 > 0) {
|
|
231
|
+
// ang2 -= TAU;
|
|
232
|
+
// }
|
|
233
|
+
|
|
234
|
+
// if (sweepFlag === 1 && ang2 < 0) {
|
|
235
|
+
// ang2 += TAU;
|
|
236
|
+
// }
|
|
237
|
+
|
|
238
|
+
// return [centerx, centery, ang1, ang2];
|
|
239
|
+
// };
|
|
240
|
+
|
|
241
|
+
// const arcToBezier = ({ px, py, cx, cy, rx, ry, xAxisRotation = 0, largeArcFlag = 0, sweepFlag = 0 }) => {
|
|
242
|
+
// const curves = [];
|
|
243
|
+
|
|
244
|
+
// if (rx === 0 || ry === 0) {
|
|
245
|
+
// return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
|
|
246
|
+
// }
|
|
247
|
+
|
|
248
|
+
// const sinphi = Math.sin((xAxisRotation * TAU) / 360);
|
|
249
|
+
// const cosphi = Math.cos((xAxisRotation * TAU) / 360);
|
|
250
|
+
|
|
251
|
+
// const pxp = (cosphi * (px - cx)) / 2 + (sinphi * (py - cy)) / 2;
|
|
252
|
+
// const pyp = (-sinphi * (px - cx)) / 2 + (cosphi * (py - cy)) / 2;
|
|
253
|
+
|
|
254
|
+
// if (pxp === 0 && pyp === 0) {
|
|
255
|
+
// return [{ x1: 0, y1: 0, x2: 0, y2: 0, x: cx, y: cy }];
|
|
256
|
+
// }
|
|
257
|
+
|
|
258
|
+
// rx = Math.abs(rx);
|
|
259
|
+
// ry = Math.abs(ry);
|
|
260
|
+
|
|
261
|
+
// const lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2);
|
|
262
|
+
|
|
263
|
+
// if (lambda > 1) {
|
|
264
|
+
// rx *= Math.sqrt(lambda);
|
|
265
|
+
// ry *= Math.sqrt(lambda);
|
|
266
|
+
// }
|
|
267
|
+
|
|
268
|
+
// let [centerx, centery, ang1, ang2] = getArcCenter(
|
|
269
|
+
// px,
|
|
270
|
+
// py,
|
|
271
|
+
// cx,
|
|
272
|
+
// cy,
|
|
273
|
+
// rx,
|
|
274
|
+
// ry,
|
|
275
|
+
// largeArcFlag,
|
|
276
|
+
// sweepFlag,
|
|
277
|
+
// sinphi,
|
|
278
|
+
// cosphi,
|
|
279
|
+
// pxp,
|
|
280
|
+
// pyp,
|
|
281
|
+
// );
|
|
282
|
+
|
|
283
|
+
// // If 'ang2' == 90.0000000001, then `ratio` will evaluate to
|
|
284
|
+
// // 1.0000000001. This causes `segments` to be greater than one, which is an
|
|
285
|
+
// // unecessary split, and adds extra points to the bezier curve. To alleviate
|
|
286
|
+
// // this issue, we round to 1.0 when the ratio is close to 1.0.
|
|
287
|
+
// let ratio = Math.abs(ang2) / (TAU / 4);
|
|
288
|
+
// if (Math.abs(1.0 - ratio) < 0.0000001) {
|
|
289
|
+
// ratio = 1.0;
|
|
290
|
+
// }
|
|
291
|
+
|
|
292
|
+
// const segments = Math.max(Math.ceil(ratio), 1);
|
|
293
|
+
|
|
294
|
+
// ang2 /= segments;
|
|
295
|
+
|
|
296
|
+
// for (let i = 0; i < segments; i++) {
|
|
297
|
+
// curves.push(approxUnitArc(ang1, ang2));
|
|
298
|
+
// ang1 += ang2;
|
|
299
|
+
// }
|
|
300
|
+
|
|
301
|
+
// return curves.map((curve) => {
|
|
302
|
+
// const { x: x1, y: y1 } = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery);
|
|
303
|
+
// const { x: x2, y: y2 } = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery);
|
|
304
|
+
// const { x, y } = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery);
|
|
305
|
+
|
|
306
|
+
// return { x1, y1, x2, y2, x, y };
|
|
307
|
+
// });
|
|
308
|
+
// };
|
|
309
|
+
|
|
310
|
+
// export function arcToCubic(
|
|
311
|
+
// x1: number,
|
|
312
|
+
// y1: number,
|
|
313
|
+
// rx: number,
|
|
314
|
+
// ry: number,
|
|
315
|
+
// angle: number,
|
|
316
|
+
// LAF: number,
|
|
317
|
+
// SF: number,
|
|
318
|
+
// x2: number,
|
|
319
|
+
// y2: number,
|
|
320
|
+
// ) {
|
|
321
|
+
// const curves = arcToBezier({
|
|
322
|
+
// px: x1,
|
|
323
|
+
// py: y1,
|
|
324
|
+
// cx: x2,
|
|
325
|
+
// cy: y2,
|
|
326
|
+
// rx,
|
|
327
|
+
// ry,
|
|
328
|
+
// xAxisRotation: angle,
|
|
329
|
+
// largeArcFlag: LAF,
|
|
330
|
+
// sweepFlag: SF,
|
|
331
|
+
// });
|
|
332
|
+
|
|
333
|
+
// return curves.reduce((prev, cur) => {
|
|
334
|
+
// const { x1, y1, x2, y2, x, y } = cur;
|
|
335
|
+
// prev.push(x1, y1, x2, y2, x, y);
|
|
336
|
+
// return prev;
|
|
337
|
+
// }, [] as number[]);
|
|
338
|
+
// }
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PathArray } from '../types';
|
|
2
|
+
|
|
3
|
+
export function fixArc(pathArray: PathArray, allPathCommands: string[], i: number) {
|
|
4
|
+
if (pathArray[i].length > 7) {
|
|
5
|
+
pathArray[i].shift();
|
|
6
|
+
const pi = pathArray[i];
|
|
7
|
+
// const ni = i + 1;
|
|
8
|
+
let ni = i;
|
|
9
|
+
while (pi.length) {
|
|
10
|
+
// if created multiple C:s, their original seg is saved
|
|
11
|
+
allPathCommands[i] = 'A';
|
|
12
|
+
// @ts-ignore
|
|
13
|
+
pathArray.splice((ni += 1), 0, ['C'].concat(pi.splice(0, 6)));
|
|
14
|
+
}
|
|
15
|
+
pathArray.splice(i, 1);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,37 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
// return {
|
|
4
|
-
// x: (t1 ** 3) * p1x
|
|
5
|
-
// + t1 * t1 * 3 * t * c1x
|
|
6
|
-
// + t1 * 3 * t * t * c2x
|
|
7
|
-
// + (t ** 3) * p2x,
|
|
8
|
-
// y: (t1 ** 3) * p1y
|
|
9
|
-
// + t1 * t1 * 3 * t * c1y
|
|
10
|
-
// + t1 * 3 * t * t * c2y
|
|
11
|
-
// + (t ** 3) * p2y,
|
|
12
|
-
// };
|
|
13
|
-
// }
|
|
14
|
-
|
|
15
|
-
// export function midPoint(a: number[], b: number[], t: number) {
|
|
16
|
-
// const ax = a[0];
|
|
17
|
-
// const ay = a[1];
|
|
18
|
-
// const bx = b[0];
|
|
19
|
-
// const by = b[1];
|
|
20
|
-
// return [ax + (bx - ax) * t, ay + (by - ay) * t];
|
|
21
|
-
// }
|
|
1
|
+
import { segmentLineFactory } from '../util/segment-line-factory';
|
|
2
|
+
import { midPoint } from '../util/mid-point';
|
|
22
3
|
|
|
23
4
|
export function lineToCubic(x1: number, y1: number, x2: number, y2: number) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
|
|
5
|
+
const t = 0.5;
|
|
6
|
+
const p0 = [x1, y1];
|
|
7
|
+
const p1 = [x2, y2];
|
|
8
|
+
const p2 = midPoint(p0, p1, t);
|
|
9
|
+
const p3 = midPoint(p1, p2, t);
|
|
10
|
+
const p4 = midPoint(p2, p3, t);
|
|
11
|
+
const p5 = midPoint(p3, p4, t);
|
|
12
|
+
const p6 = midPoint(p4, p5, t);
|
|
13
|
+
const seg1 = [...p0, ...p2, ...p4, ...p6, t];
|
|
14
|
+
// @ts-ignore
|
|
15
|
+
const cp1 = segmentLineFactory(...seg1).point;
|
|
16
|
+
const seg2 = [...p6, ...p5, ...p3, ...p1, 0];
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
const cp2 = segmentLineFactory(...seg2).point;
|
|
35
19
|
|
|
36
|
-
|
|
20
|
+
return [cp1.x, cp1.y, cp2.x, cp2.y, x2, y2];
|
|
37
21
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { isNormalizedArray } from '../util/is-normalized-array';
|
|
2
|
+
import { paramsParser } from '../parser/params-parser';
|
|
3
|
+
import { path2Absolute } from '../convert/path-2-absolute';
|
|
4
|
+
import type { PathArray, NormalArray } from '../types';
|
|
5
|
+
import { clonePath } from './clone-path';
|
|
6
|
+
import { normalizeSegment } from './normalize-segment';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @example
|
|
10
|
+
* const path = 'M0 0 H50';
|
|
11
|
+
* const normalizedPath = SVGPathCommander.normalizePath(path);
|
|
12
|
+
* // result => [['M', 0, 0], ['L', 50, 0]]
|
|
13
|
+
*/
|
|
14
|
+
export function normalizePath(pathInput: string | PathArray): NormalArray {
|
|
15
|
+
if (isNormalizedArray(pathInput)) {
|
|
16
|
+
return clonePath(pathInput) as NormalArray;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const path = path2Absolute(pathInput);
|
|
20
|
+
const params = { ...paramsParser };
|
|
21
|
+
const allPathCommands = [];
|
|
22
|
+
const ii = path.length;
|
|
23
|
+
let pathCommand = '';
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i < ii; i += 1) {
|
|
26
|
+
[pathCommand] = path[i];
|
|
27
|
+
|
|
28
|
+
// Save current path command
|
|
29
|
+
allPathCommands[i] = pathCommand;
|
|
30
|
+
path[i] = normalizeSegment(path[i], params);
|
|
31
|
+
|
|
32
|
+
const segment = path[i];
|
|
33
|
+
const seglen = segment.length;
|
|
34
|
+
|
|
35
|
+
params.x1 = +segment[seglen - 2];
|
|
36
|
+
params.y1 = +segment[seglen - 1];
|
|
37
|
+
params.x2 = +segment[seglen - 4] || params.x1;
|
|
38
|
+
params.y2 = +segment[seglen - 3] || params.y1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return path as NormalArray;
|
|
42
|
+
}
|