-
-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1501 from hannobraun/builder
Simplify `SketchBuilder`
- Loading branch information
Showing
2 changed files
with
34 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,18 @@ | ||
use fj_math::Point; | ||
|
||
use crate::{ | ||
objects::Surface, | ||
partial::{Partial, PartialFace, PartialSketch}, | ||
objects::Face, | ||
partial::{Partial, PartialSketch}, | ||
}; | ||
|
||
use super::CycleBuilder; | ||
|
||
/// Builder API for [`PartialSketch`] | ||
pub trait SketchBuilder { | ||
/// Add a polygon to the sketch, created from the provided points | ||
fn add_polygon_from_points( | ||
&mut self, | ||
surface: impl Into<Partial<Surface>>, | ||
points: impl IntoIterator<Item = impl Into<Point<2>>>, | ||
); | ||
/// Add a face to the sketch | ||
fn add_face(&mut self) -> Partial<Face>; | ||
} | ||
|
||
impl SketchBuilder for PartialSketch { | ||
fn add_polygon_from_points( | ||
&mut self, | ||
surface: impl Into<Partial<Surface>>, | ||
points: impl IntoIterator<Item = impl Into<Point<2>>>, | ||
) { | ||
let mut face = PartialFace::default(); | ||
face.exterior.write().surface = surface.into(); | ||
face.exterior.write().update_as_polygon_from_points(points); | ||
|
||
self.faces.extend([Partial::from_partial(face)]); | ||
fn add_face(&mut self) -> Partial<Face> { | ||
let face = Partial::default(); | ||
self.faces.extend([face.clone()]); | ||
face | ||
} | ||
} |