-
-
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 #1452 from hannobraun/builder
Update old-style builder APIs
- Loading branch information
Showing
12 changed files
with
128 additions
and
202 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
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
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,50 +1,31 @@ | ||
use fj_math::Point; | ||
|
||
use crate::{ | ||
insert::Insert, | ||
objects::{Face, FaceSet, Objects, Sketch, Surface}, | ||
partial::{PartialFace, PartialObject}, | ||
services::Service, | ||
storage::Handle, | ||
objects::Surface, | ||
partial::{Partial, PartialFace, PartialSketch}, | ||
}; | ||
|
||
use super::FaceBuilder; | ||
|
||
/// API for building a [`Sketch`] | ||
/// | ||
/// Also see [`Sketch::builder`]. | ||
pub struct SketchBuilder { | ||
/// The faces that make up the [`Sketch`] | ||
pub faces: FaceSet, | ||
/// 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>>>, | ||
); | ||
} | ||
|
||
impl SketchBuilder { | ||
/// Build the [`Sketch`] with the provided faces | ||
pub fn with_faces( | ||
mut self, | ||
faces: impl IntoIterator<Item = Handle<Face>>, | ||
) -> Self { | ||
self.faces.extend(faces); | ||
self | ||
} | ||
|
||
/// Construct a polygon from a list of points | ||
pub fn with_polygon_from_points( | ||
mut self, | ||
surface: Handle<Surface>, | ||
impl SketchBuilder for PartialSketch { | ||
fn add_polygon_from_points( | ||
&mut self, | ||
surface: impl Into<Partial<Surface>>, | ||
points: impl IntoIterator<Item = impl Into<Point<2>>>, | ||
objects: &mut Service<Objects>, | ||
) -> Self { | ||
) { | ||
let mut face = PartialFace::default(); | ||
face.with_exterior_polygon_from_points(surface, points); | ||
let face = face.build(objects).insert(objects); | ||
|
||
self.faces.extend([face]); | ||
self | ||
} | ||
|
||
/// Build the [`Sketch`] | ||
pub fn build(self, objects: &mut Service<Objects>) -> Handle<Sketch> { | ||
Sketch::new(self.faces).insert(objects) | ||
self.faces.extend([Partial::from_partial(face)]); | ||
} | ||
} |
Oops, something went wrong.