3个版本 (破坏性更新)

0.5.0 2023年2月13日
0.4.0 2022年12月4日
0.2.0 2022年10月25日

725图形API

Download history 99/week @ 2024-03-11 75/week @ 2024-03-18 118/week @ 2024-03-25 129/week @ 2024-04-01 52/week @ 2024-04-08 40/week @ 2024-04-15 56/week @ 2024-04-22 56/week @ 2024-04-29 37/week @ 2024-05-06 47/week @ 2024-05-13 35/week @ 2024-05-20 41/week @ 2024-05-27 49/week @ 2024-06-03 185/week @ 2024-06-10 58/week @ 2024-06-17 37/week @ 2024-06-24

334 每月下载次数
3 个crate中使用 (via roughr)

MIT 许可证

45KB
1K SLoC

svg_path_ops

Crates.io Documentation License

此crate包括用于处理svg路径的实用函数。适用于来自svgtypes crate的类型。

此包公开了用于简化目的操作svg路径的函数。

📦 Cargo.toml

[dependencies]
svg_path_ops = "0.1"

🔧 示例

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 }
);

📝 许可证

许可协议为MIT许可证 (LICENSE).

🚧 贡献

除非您明确声明,否则您提交给本项目以供包含的贡献,根据MIT许可证定义,应按上述方式许可,不附加任何额外条款或条件。

依赖关系

~245KB