Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify return value of Shape::compute_brep #1394

Merged
merged 1 commit into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions crates/fj-operations/src/difference_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use fj_kernel::{
objects::{Face, Objects, Sketch},
partial::HasPartial,
services::Service,
validate::ValidationError,
};
use fj_math::Aabb;

Expand All @@ -21,7 +20,7 @@ impl Shape for fj::Difference2d {
&self,
objects: &mut Service<Objects>,
debug_info: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError> {
) -> Self::Brep {
// This method assumes that `b` is fully contained within `a`:
// https://github.com/hannobraun/Fornjot/issues/92

Expand All @@ -33,7 +32,7 @@ impl Shape for fj::Difference2d {
let [a, b] = self
.shapes()
.each_ref_ext()
.try_map_ext(|shape| shape.compute_brep(objects, debug_info))?;
.map(|shape| shape.compute_brep(objects, debug_info));

if let Some(face) = a.face_iter().next() {
// If there's at least one face to subtract from, we can proceed.
Expand Down Expand Up @@ -91,7 +90,7 @@ impl Shape for fj::Difference2d {
}

let difference = Sketch::builder().with_faces(faces).build(objects);
Ok(difference.deref().clone())
difference.deref().clone()
}

fn bounding_volume(&self) -> Aabb<3> {
Expand Down
9 changes: 4 additions & 5 deletions crates/fj-operations/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use fj_interop::debug::DebugInfo;
use fj_kernel::{
objects::{FaceSet, Objects},
services::Service,
validate::ValidationError,
};
use fj_math::Aabb;

Expand All @@ -15,16 +14,16 @@ impl Shape for fj::Group {
&self,
objects: &mut Service<Objects>,
debug_info: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError> {
) -> Self::Brep {
let mut faces = FaceSet::new();

let a = self.a.compute_brep(objects, debug_info)?;
let b = self.b.compute_brep(objects, debug_info)?;
let a = self.a.compute_brep(objects, debug_info);
let b = self.b.compute_brep(objects, debug_info);

faces.extend(a);
faces.extend(b);

Ok(faces)
faces
}

fn bounding_volume(&self) -> Aabb<3> {
Expand Down
15 changes: 7 additions & 8 deletions crates/fj-operations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use fj_interop::debug::DebugInfo;
use fj_kernel::{
objects::{FaceSet, Objects, Sketch},
services::Service,
validate::ValidationError,
};
use fj_math::Aabb;

Expand All @@ -47,7 +46,7 @@ pub trait Shape {
&self,
objects: &mut Service<Objects>,
debug_info: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError>;
) -> Self::Brep;

/// Access the axis-aligned bounding box of a shape
///
Expand All @@ -63,21 +62,21 @@ impl Shape for fj::Shape {
&self,
objects: &mut Service<Objects>,
debug_info: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError> {
) -> Self::Brep {
match self {
Self::Shape2d(shape) => {
Ok(shape.compute_brep(objects, debug_info)?.faces().clone())
shape.compute_brep(objects, debug_info).faces().clone()
}
Self::Group(shape) => shape.compute_brep(objects, debug_info),
Self::Sweep(shape) => Ok(shape
.compute_brep(objects, debug_info)?
Self::Sweep(shape) => shape
.compute_brep(objects, debug_info)
.shells()
.map(|shell| shell.faces().clone())
.reduce(|mut a, b| {
a.extend(b);
a
})
.unwrap_or_default()),
.unwrap_or_default(),
Self::Transform(shape) => shape.compute_brep(objects, debug_info),
}
}
Expand All @@ -99,7 +98,7 @@ impl Shape for fj::Shape2d {
&self,
objects: &mut Service<Objects>,
debug_info: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError> {
) -> Self::Brep {
match self {
Self::Difference(shape) => shape.compute_brep(objects, debug_info),
Self::Sketch(shape) => shape.compute_brep(objects, debug_info),
Expand Down
2 changes: 1 addition & 1 deletion crates/fj-operations/src/shape_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl ShapeProcessor {

let mut objects = Objects::new().into_service();
let mut debug_info = DebugInfo::new();
let shape = shape.compute_brep(&mut objects, &mut debug_info)?;
let shape = shape.compute_brep(&mut objects, &mut debug_info);
let mesh = (&shape, tolerance).triangulate();

Ok(ProcessedShape {
Expand Down
5 changes: 2 additions & 3 deletions crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use fj_kernel::{
objects::{Cycle, Face, HalfEdge, Objects, Sketch},
partial::{HasPartial, Replace},
services::Service,
validate::ValidationError,
};
use fj_math::{Aabb, Point};

Expand All @@ -20,7 +19,7 @@ impl Shape for fj::Sketch {
&self,
objects: &mut Service<Objects>,
_: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError> {
) -> Self::Brep {
let surface = objects.surfaces.xy_plane();

let face = match self.chain() {
Expand Down Expand Up @@ -61,7 +60,7 @@ impl Shape for fj::Sketch {
};

let sketch = Sketch::builder().with_faces([face]).build(objects);
Ok(sketch.deref().clone())
sketch.deref().clone()
}

fn bounding_volume(&self) -> Aabb<3> {
Expand Down
7 changes: 3 additions & 4 deletions crates/fj-operations/src/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use fj_kernel::{
insert::Insert,
objects::{Objects, Solid},
services::Service,
validate::ValidationError,
};
use fj_math::{Aabb, Vector};

Expand All @@ -19,14 +18,14 @@ impl Shape for fj::Sweep {
&self,
objects: &mut Service<Objects>,
debug_info: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError> {
let sketch = self.shape().compute_brep(objects, debug_info)?;
) -> Self::Brep {
let sketch = self.shape().compute_brep(objects, debug_info);
let sketch = sketch.insert(objects);

let path = Vector::from(self.path());

let solid = sketch.sweep(path, objects);
Ok(solid.deref().clone())
solid.deref().clone()
}

fn bounding_volume(&self) -> Aabb<3> {
Expand Down
12 changes: 4 additions & 8 deletions crates/fj-operations/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use fj_kernel::{
algorithms::transform::TransformObject,
objects::{FaceSet, Objects},
services::Service,
validate::ValidationError,
};
use fj_math::{Aabb, Transform, Vector};

Expand All @@ -16,13 +15,10 @@ impl Shape for fj::Transform {
&self,
objects: &mut Service<Objects>,
debug_info: &mut DebugInfo,
) -> Result<Self::Brep, ValidationError> {
let faces = self
.shape
.compute_brep(objects, debug_info)?
.transform(&make_transform(self), objects);

Ok(faces)
) -> Self::Brep {
self.shape
.compute_brep(objects, debug_info)
.transform(&make_transform(self), objects)
}

fn bounding_volume(&self) -> Aabb<3> {
Expand Down