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

Remove use of old validation infrastructure from fj-operations #1329

Merged
merged 2 commits into from
Nov 9, 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
14 changes: 7 additions & 7 deletions crates/fj-operations/src/difference_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fj_kernel::{
algorithms::reverse::Reverse,
iter::ObjectIters,
objects::{Face, Objects, Sketch},
validate::{Validate, Validated, ValidationConfig, ValidationError},
validate::ValidationError,
};
use fj_math::Aabb;

Expand All @@ -16,10 +16,9 @@ impl Shape for fj::Difference2d {

fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
) -> Result<Self::Brep, ValidationError> {
// This method assumes that `b` is fully contained within `a`:
// https://github.com/hannobraun/Fornjot/issues/92

Expand All @@ -28,9 +27,10 @@ impl Shape for fj::Difference2d {
let mut exteriors = Vec::new();
let mut interiors = Vec::new();

let [a, b] = self.shapes().each_ref_ext().try_map_ext(|shape| {
shape.compute_brep(config, objects, debug_info)
})?;
let [a, b] = self
.shapes()
.each_ref_ext()
.try_map_ext(|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 @@ -87,7 +87,7 @@ impl Shape for fj::Difference2d {
}

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

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

Expand All @@ -12,19 +12,18 @@ impl Shape for fj::Group {

fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
) -> Result<Self::Brep, ValidationError> {
let mut faces = FaceSet::new();

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

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

faces.validate_with_config(config)
Ok(faces)
}

fn bounding_volume(&self) -> Aabb<3> {
Expand Down
42 changes: 13 additions & 29 deletions crates/fj-operations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod transform;
use fj_interop::debug::DebugInfo;
use fj_kernel::{
objects::{FaceSet, Objects, Sketch},
validate::{Validate, Validated, ValidationConfig, ValidationError},
validate::ValidationError,
};
use fj_math::Aabb;

Expand All @@ -39,10 +39,9 @@ pub trait Shape {
/// Compute the boundary representation of the shape
fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError>;
) -> Result<Self::Brep, ValidationError>;

/// Access the axis-aligned bounding box of a shape
///
Expand All @@ -56,34 +55,24 @@ impl Shape for fj::Shape {

fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
) -> Result<Self::Brep, ValidationError> {
match self {
Self::Shape2d(shape) => shape
.compute_brep(config, objects, debug_info)?
.into_inner()
.faces()
.clone()
.validate_with_config(config),
Self::Group(shape) => {
shape.compute_brep(config, objects, debug_info)
Self::Shape2d(shape) => {
Ok(shape.compute_brep(objects, debug_info)?.faces().clone())
}
Self::Sweep(shape) => shape
.compute_brep(config, objects, debug_info)?
.into_inner()
Self::Group(shape) => shape.compute_brep(objects, debug_info),
Self::Sweep(shape) => Ok(shape
.compute_brep(objects, debug_info)?
.shells()
.map(|shell| shell.faces().clone())
.reduce(|mut a, b| {
a.extend(b);
a
})
.unwrap_or_default()
.validate_with_config(config),
Self::Transform(shape) => {
shape.compute_brep(config, objects, debug_info)
}
.unwrap_or_default()),
Self::Transform(shape) => shape.compute_brep(objects, debug_info),
}
}

Expand All @@ -102,17 +91,12 @@ impl Shape for fj::Shape2d {

fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
) -> Result<Self::Brep, ValidationError> {
match self {
Self::Difference(shape) => {
shape.compute_brep(config, objects, debug_info)
}
Self::Sketch(shape) => {
shape.compute_brep(config, objects, debug_info)
}
Self::Difference(shape) => shape.compute_brep(objects, debug_info),
Self::Sketch(shape) => shape.compute_brep(objects, debug_info),
}
}

Expand Down
7 changes: 3 additions & 4 deletions crates/fj-operations/src/shape_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use fj_kernel::{
triangulate::Triangulate,
},
objects::Objects,
validate::{ValidationConfig, ValidationError},
validate::ValidationError,
};
use fj_math::Scalar;

Expand Down Expand Up @@ -42,11 +42,10 @@ impl ShapeProcessor {
Some(user_defined_tolerance) => user_defined_tolerance,
};

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

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

Expand All @@ -16,10 +16,9 @@ impl Shape for fj::Sketch {

fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
_: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
) -> Result<Self::Brep, ValidationError> {
let surface = objects.surfaces.xy_plane();

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

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

fn bounding_volume(&self) -> Aabb<3> {
Expand Down
11 changes: 5 additions & 6 deletions crates/fj-operations/src/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use fj_interop::debug::DebugInfo;
use fj_kernel::{
algorithms::sweep::Sweep,
objects::{Objects, Solid},
validate::{Validate, Validated, ValidationConfig, ValidationError},
validate::ValidationError,
};
use fj_math::{Aabb, Vector};

Expand All @@ -15,17 +15,16 @@ impl Shape for fj::Sweep {

fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
let sketch = self.shape().compute_brep(config, objects, debug_info)?;
let sketch = objects.sketches.insert(sketch.into_inner())?;
) -> Result<Self::Brep, ValidationError> {
let sketch = self.shape().compute_brep(objects, debug_info)?;
let sketch = objects.sketches.insert(sketch)?;

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

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

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

Expand All @@ -13,17 +13,15 @@ impl Shape for fj::Transform {

fn compute_brep(
&self,
config: &ValidationConfig,
objects: &Objects,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
) -> Result<Self::Brep, ValidationError> {
let faces = self
.shape
.compute_brep(config, objects, debug_info)?
.into_inner()
.compute_brep(objects, debug_info)?
.transform(&make_transform(self), objects)?;

faces.validate_with_config(config)
Ok(faces)
}

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