rootvg_tessellation/path.rs
1// The following code was copied and modified from
2// https://github.com/iced-rs/iced/blob/31d1d5fecbef50fa319cabd5d4194f1e4aaefa21/graphics/src/geometry/path.rs
3// Iced license (MIT): https://github.com/iced-rs/iced/blob/31d1d5fecbef50fa319cabd5d4194f1e4aaefa21/LICENSE
4
5mod arc;
6mod builder;
7
8#[doc(no_inline)]
9pub use arc::{ArcPath, EllipticalArcPath};
10pub use builder::PathBuilder;
11
12//pub use lyon::path as lyon_path;
13
14use rootvg_core::math::{Point, Size};
15
16/// An immutable set of points that may or may not be connected.
17///
18/// A single [`Path`] can represent different kinds of 2D shapes!
19#[derive(Debug, Clone)]
20pub struct Path {
21 pub raw: lyon::path::Path,
22}
23
24impl Path {
25 pub fn builder() -> PathBuilder {
26 PathBuilder::new()
27 }
28
29 /// Creates a new [`Path`] representing a line segment given its starting
30 /// and end points.
31 pub fn line(from: Point, to: Point) -> Self {
32 PathBuilder::new().move_to(from).line_to(to).build()
33 }
34
35 /// Creates a new [`Path`] representing a rectangle given its top-left
36 /// corner coordinate and its `Size`.
37 pub fn rectangle(top_left: Point, size: Size) -> Self {
38 PathBuilder::new().rectangle(top_left, size).build()
39 }
40
41 /// Creates a new [`Path`] representing a circle given its center
42 /// coordinate and its radius.
43 pub fn circle(center: Point, radius: f32) -> Self {
44 PathBuilder::new().circle(center, radius).build()
45 }
46
47 /// Returns the current [`Path`] with the given transform applied to it.
48 pub fn transform(&self, transform: &lyon::path::math::Transform) -> Path {
49 Path {
50 raw: self.raw.clone().transformed(transform),
51 }
52 }
53}