#svg #polyline #path #convert #chains #drawing

svg2polylines

Convert SVG data to a list of polylines (aka polygonal chains or polygonal paths)

12 releases (7 breaking)

0.8.1 Aug 28, 2022
0.7.0 Jun 21, 2022
0.6.0 Sep 13, 2021
0.5.2 Aug 11, 2019
0.4.0 Jun 25, 2017

#99 in Robotics

Download history 2/week @ 2024-07-04 6/week @ 2024-07-11 8/week @ 2024-07-18 81/week @ 2024-07-25 24/week @ 2024-08-01 13/week @ 2024-08-08 14/week @ 2024-08-15 10/week @ 2024-08-22 20/week @ 2024-08-29 30/week @ 2024-09-05 46/week @ 2024-09-12 46/week @ 2024-09-19 48/week @ 2024-09-26 27/week @ 2024-10-03 3/week @ 2024-10-10 9/week @ 2024-10-17

99 downloads per month
Used in spiropath

MIT/Apache

60KB
1K SLoC

svg2polylines

CircleCI Crates.io

Convert SVG data to a list of polylines (aka polygonal chains or polygonal paths).

This can be used e.g. for simple drawing robot that just support drawing straight lines and liftoff / drop pen commands.

Flattening of Bézier curves is done using the Lyon library. SVG files are preprocessed / simplified using usvg.

Note: Currently the path style is completely ignored. Only the path itself is returned.

Preview

There is a small preview tool to view the generated polylines. It's simple and hacky, but helps to debug stuff.

cargo run --release --example preview path/to/file.svg

The --release parameter is important, otherwise it's going to be very slow.

Use the mouse to drag / zoom the image and the Esc key to close the window.

Usage: Rust

Signature:

fn svg2polylines::parse(svg: &str, tol: f64, preprocess: bool) -> Result<Vec<Polyline>, String>;

See examples/basic.rs for a full usage example.

FFI

This crate used to contain FFI bindings. These have been dropped as of version 0.8.0. If you need them, open an issue on GitHub and I might bring them back.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~6MB
~122K SLoC