Skip to content

Commit

Permalink
Use lyon_path::Build trait for building paths (#268)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nilirad authored Dec 17, 2024
1 parent 0dacb38 commit ac109bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
23 changes: 7 additions & 16 deletions src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Types for defining and using geometries.
use lyon_algorithms::path::{builder::WithSvg, BuilderImpl};
use lyon_algorithms::path::{builder::WithSvg, traits::Build, BuilderImpl};
use lyon_tessellation::path::path::Builder;

use crate::{
Expand Down Expand Up @@ -144,21 +144,12 @@ impl<GenericBuilder> ShapeBuilderBase<GenericBuilder> for ReadyShapeBuilder<Gene
}
}

/// Generalizes the implementation of the `build` method
/// over multiple Lyon builders.
pub trait ReadyShapeBuilderTrait {
/// Builds a `Shape` according to the builder's settings.
fn build(self) -> Shape;
}

impl ReadyShapeBuilderTrait for ReadyShapeBuilder<Builder> {
fn build(self) -> Shape {
Shape::new(self.builder.build(), self.fill, self.stroke)
}
}

impl ReadyShapeBuilderTrait for ReadyShapeBuilder<WithSvg<BuilderImpl>> {
fn build(self) -> Shape {
impl<GenericBuilder> ReadyShapeBuilder<GenericBuilder>
where
GenericBuilder: Build<PathType = lyon_tessellation::path::Path>,
{
/// Builds the path according to builder settings.
pub fn build(self) -> Shape {
Shape::new(self.builder.build(), self.fill, self.stroke)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub mod prelude {
pub use crate::{
draw::{Fill, Stroke},
entity::Shape,
geometry::{Geometry, ReadyShapeBuilderTrait, ShapeBuilder, ShapeBuilderBase},
geometry::{Geometry, ShapeBuilder, ShapeBuilderBase},
path::ShapePath,
plugin::ShapePlugin,
shapes::{self, BorderRadii, RectangleOrigin, RegularPolygon, RegularPolygonFeature},
Expand Down

0 comments on commit ac109bd

Please sign in to comment.