Skip to content

Commit

Permalink
Merge pull request #1501 from hannobraun/builder
Browse files Browse the repository at this point in the history
Simplify `SketchBuilder`
  • Loading branch information
hannobraun authored Jan 11, 2023
2 parents cce774f + 18d280b commit d8a6dad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 26 deletions.
30 changes: 26 additions & 4 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,19 @@ mod tests {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut sketch = PartialSketch::default();
sketch.add_polygon_from_points(surface.clone(), TRIANGLE);
let sketch = {
let mut sketch = PartialSketch::default();

let mut face = sketch.add_face();
face.write().exterior.write().surface =
Partial::from(surface.clone());
face.write()
.exterior
.write()
.update_as_polygon_from_points(TRIANGLE);

sketch
};
let solid = sketch
.build(&mut services.objects)
.insert(&mut services.objects)
Expand Down Expand Up @@ -161,8 +172,19 @@ mod tests {
let mut services = Services::new();

let surface = services.objects.surfaces.xy_plane();
let mut sketch = PartialSketch::default();
sketch.add_polygon_from_points(surface.clone(), TRIANGLE);
let sketch = {
let mut sketch = PartialSketch::default();

let mut face = sketch.add_face();
face.write().exterior.write().surface =
Partial::from(surface.clone());
face.write()
.exterior
.write()
.update_as_polygon_from_points(TRIANGLE);

sketch
};
let solid = sketch
.build(&mut services.objects)
.insert(&mut services.objects)
Expand Down
30 changes: 8 additions & 22 deletions crates/fj-kernel/src/builder/sketch.rs
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
}
}

0 comments on commit d8a6dad

Please sign in to comment.