Skip to content

Commit

Permalink
Replace Sweep implementation of Sketch
Browse files Browse the repository at this point in the history
  • Loading branch information
hannobraun committed Nov 23, 2023
1 parent 8b2ee27 commit 2bf1a55
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 19 deletions.
2 changes: 1 addition & 1 deletion crates/fj-core/src/operations/sweep/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ mod vertex;

pub use self::{
face::SweepFace, half_edge::SweepHalfEdge, path::SweepSurfacePath,
vertex::SweepVertex,
sketch::SweepSketch, vertex::SweepVertex,
};

use std::collections::BTreeMap;
Expand Down
34 changes: 24 additions & 10 deletions crates/fj-core/src/operations/sweep/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,39 @@ use crate::{
storage::Handle,
};

use super::{face::SweepFace, Sweep, SweepCache};
use super::{face::SweepFace, SweepCache};

impl Sweep for (&Sketch, Handle<Surface>) {
type Swept = Solid;
/// # Sweep a [`Sketch`]
///
/// See [module documentation] for more information.
///
/// [module documentation]: super
pub trait SweepSketch {
/// # Sweep the [`Sketch`]
fn sweep_sketch(
&self,
surface: Handle<Surface>,
path: impl Into<Vector<3>>,
services: &mut Services,
) -> Solid;
}

fn sweep_with_cache(
self,
impl SweepSketch for Sketch {
fn sweep_sketch(
&self,
surface: Handle<Surface>,
path: impl Into<Vector<3>>,
cache: &mut SweepCache,
services: &mut Services,
) -> Self::Swept {
let (sketch, surface) = self;
) -> Solid {
let path = path.into();
let mut cache = SweepCache::default();

let mut shells = Vec::new();
for region in sketch.regions() {
for region in self.regions() {
let face =
Face::new(surface.clone(), region.clone()).insert(services);
let shell = face.sweep_face(path, cache, services).insert(services);
let shell =
face.sweep_face(path, &mut cache, services).insert(services);
shells.push(shell);
}

Expand Down
6 changes: 4 additions & 2 deletions models/cuboid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj::{
operations::{
build::{BuildRegion, BuildSketch},
insert::Insert,
sweep::Sweep,
sweep::SweepSketch,
update::UpdateSketch,
},
services::Services,
Expand All @@ -29,5 +29,7 @@ pub fn model(x: f64, y: f64, z: f64, services: &mut Services) -> Handle<Solid> {

let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., z]);
(&sketch, surface).sweep(path, services).insert(services)
sketch
.sweep_sketch(surface, path, services)
.insert(services)
}
6 changes: 4 additions & 2 deletions models/spacer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fj::{
build::{BuildCycle, BuildRegion, BuildSketch},
insert::Insert,
reverse::Reverse,
sweep::Sweep,
sweep::SweepSketch,
update::{UpdateRegion, UpdateSketch},
},
services::Services,
Expand All @@ -30,5 +30,7 @@ pub fn model(

let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., height]);
(&sketch, surface).sweep(path, services).insert(services)
sketch
.sweep_sketch(surface, path, services)
.insert(services)
}
4 changes: 2 additions & 2 deletions models/split/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fj::{
build::{BuildRegion, BuildSketch},
insert::Insert,
split::SplitFace,
sweep::Sweep,
sweep::SweepSketch,
update::{UpdateSketch, UpdateSolid},
},
services::Services,
Expand Down Expand Up @@ -34,7 +34,7 @@ pub fn model(

let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., size]);
let solid = (&sketch, surface).sweep(path, services);
let solid = sketch.sweep_sketch(surface, path, services);

solid
.update_shell(solid.shells().only(), |shell| {
Expand Down
6 changes: 4 additions & 2 deletions models/star/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fj::{
build::{BuildCycle, BuildRegion, BuildSketch},
insert::Insert,
reverse::Reverse,
sweep::Sweep,
sweep::SweepSketch,
update::{UpdateRegion, UpdateSketch},
},
services::Services,
Expand Down Expand Up @@ -53,5 +53,7 @@ pub fn model(

let surface = services.objects.surfaces.xy_plane();
let path = Vector::from([0., 0., h]);
(&sketch, surface).sweep(path, services).insert(services)
sketch
.sweep_sketch(surface, path, services)
.insert(services)
}

0 comments on commit 2bf1a55

Please sign in to comment.