3 releases (breaking)

0.5.0 Feb 13, 2023
0.4.0 Dec 4, 2022
0.2.0 Oct 25, 2022

#787 in Graphics APIs

Download history 43/week @ 2023-12-17 32/week @ 2023-12-24 31/week @ 2023-12-31 39/week @ 2024-01-07 24/week @ 2024-01-14 25/week @ 2024-01-21 22/week @ 2024-01-28 64/week @ 2024-02-04 44/week @ 2024-02-11 52/week @ 2024-02-18 138/week @ 2024-02-25 111/week @ 2024-03-03 107/week @ 2024-03-10 77/week @ 2024-03-17 122/week @ 2024-03-24 116/week @ 2024-03-31

449 downloads per month
Used in 3 crates (via roughr)

MIT license

45KB
1K SLoC

svg_path_ops

Crates.io Documentation License

This crate includes utility functions to work with svg paths. Works on types from svgtypes crate.

This package exposes functions to manipulate svg paths with simplification purposes.

📦 Cargo.toml

[dependencies]
svg_path_ops = "0.1"

🔧 Example

use svgtypes::{PathParser, PathSegment};

let path: String = "m 0 0 c 3 -0.6667 6 -1.3333 9 -2 a 1 1 0 0 0 -8 -1 a 1 1 0 0 0 -2 0 l 0 4 v 2 h 8 q 4 -10 9 -5 t -6 8 z".into();
let path_parser = PathParser::from(path.as_ref());
let path_segments: Vec<PathSegment> = path_parser.flatten().collect();
let mut absolute = absolutize(path_segments.iter());
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::MoveTo { abs: true, x: 0.0, y: 0.0 }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::CurveTo {
        abs: true,
        x1: 3.0,
        y1: -0.6667,
        x2: 6.0,
        y2: -1.3333,
        x: 9.0,
        y: -2.0
    }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::EllipticalArc {
        abs: true,
        rx: 1.0,
        ry: 1.0,
        x_axis_rotation: 0.0,
        large_arc: false,
        sweep: false,
        x: 1.0,
        y: -3.0
    }
);

assert_eq!(
    absolute.next().unwrap(),
    PathSegment::EllipticalArc {
        abs: true,
        rx: 1.0,
        ry: 1.0,
        x_axis_rotation: 0.0,
        large_arc: false,
        sweep: false,
        x: -1.0,
        y: -3.0
    }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::LineTo { abs: true, x: -1.0, y: 1.0 }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::VerticalLineTo { abs: true, y: 3.0 }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::HorizontalLineTo { abs: true, x: 7.0 }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::Quadratic { abs: true, x1: 11.0, y1: -7.0, x: 16.0, y: -2.0 }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::SmoothQuadratic { abs: true, x: 10.0, y: 6.0 }
);
assert_eq!(
    absolute.next().unwrap(),
    PathSegment::ClosePath { abs: true }
);

📝 License

Licensed under MIT License (LICENSE).

🚧 Contributions

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the MIT license, shall be licensed as above, without any additional terms or conditions.

Dependencies

~245KB