Skip to content

Commit

Permalink
Merge pull request #1408 from hannobraun/builder
Browse files Browse the repository at this point in the history
Remove redundant field in `SketchBuilder`
  • Loading branch information
hannobraun authored Nov 30, 2022
2 parents 1ced108 + eca37a7 commit ddf9161
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
14 changes: 10 additions & 4 deletions crates/fj-kernel/src/algorithms/sweep/face.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ mod tests {

let surface = services.objects.surfaces.xy_plane();
let solid = Sketch::builder()
.with_surface(surface.clone())
.with_polygon_from_points(TRIANGLE, &mut services.objects)
.with_polygon_from_points(
surface.clone(),
TRIANGLE,
&mut services.objects,
)
.build(&mut services.objects)
.sweep(UP, &mut services.objects);

Expand Down Expand Up @@ -148,8 +151,11 @@ mod tests {

let surface = services.objects.surfaces.xy_plane();
let solid = Sketch::builder()
.with_surface(surface.clone())
.with_polygon_from_points(TRIANGLE, &mut services.objects)
.with_polygon_from_points(
surface.clone(),
TRIANGLE,
&mut services.objects,
)
.build(&mut services.objects)
.sweep(DOWN, &mut services.objects);

Expand Down
16 changes: 2 additions & 14 deletions crates/fj-kernel/src/builder/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@ use super::FaceBuilder;
///
/// Also see [`Sketch::builder`].
pub struct SketchBuilder {
/// The surface that the [`Sketch`] is defined in
pub surface: Option<Handle<Surface>>,

/// The faces that make up the [`Sketch`]
pub faces: FaceSet,
}

impl SketchBuilder {
/// Build the [`Sketch`] with the provided [`Surface`]
pub fn with_surface(mut self, surface: Handle<Surface>) -> Self {
self.surface = Some(surface);
self
}

/// Build the [`Sketch`] with the provided faces
pub fn with_faces(
mut self,
Expand All @@ -40,15 +31,12 @@ impl SketchBuilder {
/// Construct a polygon from a list of points
pub fn with_polygon_from_points(
mut self,
surface: Handle<Surface>,
points: impl IntoIterator<Item = impl Into<Point<2>>>,
objects: &mut Service<Objects>,
) -> Self {
let surface = self
.surface
.as_ref()
.expect("Can't build `Sketch` without `Surface`");
self.faces.extend([Face::partial()
.with_exterior_polygon_from_points(surface.clone(), points)
.with_exterior_polygon_from_points(surface, points)
.build(objects)
.insert(objects)]);
self
Expand Down
1 change: 0 additions & 1 deletion crates/fj-kernel/src/objects/full/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ impl Sketch {
/// Build a `Sketch` using [`SketchBuilder`]
pub fn builder() -> SketchBuilder {
SketchBuilder {
surface: None,
faces: FaceSet::new(),
}
}
Expand Down

0 comments on commit ddf9161

Please sign in to comment.