Skip to content

format_path

Writes path commands back as SVG path data: letters glued to their first number, single spaces elsewhere, numbers rounded to precision decimals with the trailing zeros dropped (-0 is written 0).

use helpers4::geometry::format_path;

Cargo feature geometry (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features geometry

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.11", default-features = false, features = ["geometry"] }
pub fn format_path(commands: &[PathCommand], precision: usize) -> String
ParameterTypeDescription
commands&[PathCommand]The commands, as parse_path returns them.
precisionusizeDecimals kept per number; 6 is a good default.

String — The path data.

use helpers4::geometry::{format_path, PathCommand};

let d = format_path(
    &[
        PathCommand::new('M', vec![0.0, 0.5]),
        PathCommand::new('L', vec![10.0, 1.0 / 3.0]),
    ],
    6,
);
assert_eq!(d, "M0 0.5 L10 0.333333");

src/geometry/format_path.rs