Skip to content

Commit

Permalink
Merge pull request #1201 from hannobraun/planes
Browse files Browse the repository at this point in the history
Remove redundant argument from `Shape::compute_brep`
  • Loading branch information
hannobraun authored Oct 11, 2022
2 parents 4ba6a22 + ab112e9 commit 3de8030
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 91 deletions.
8 changes: 2 additions & 6 deletions crates/fj-operations/src/difference_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ use fj_kernel::{
};
use fj_math::Aabb;

use crate::planes::Planes;

use super::Shape;

impl Shape for fj::Difference2d {
Expand All @@ -20,7 +18,6 @@ impl Shape for fj::Difference2d {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
// This method assumes that `b` is fully contained within `a`:
Expand All @@ -35,9 +32,8 @@ impl Shape for fj::Difference2d {
// - https://doc.rust-lang.org/std/primitive.array.html#method.each_ref
// - https://doc.rust-lang.org/std/primitive.array.html#method.try_map
let [a, b] = self.shapes();
let [a, b] = [a, b].map(|shape| {
shape.compute_brep(config, objects, planes, debug_info)
});
let [a, b] =
[a, b].map(|shape| shape.compute_brep(config, objects, debug_info));
let [a, b] = [a?, b?];

if let Some(face) = a.face_iter().next() {
Expand Down
7 changes: 2 additions & 5 deletions crates/fj-operations/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use fj_kernel::{
};
use fj_math::Aabb;

use crate::planes::Planes;

use super::Shape;

impl Shape for fj::Group {
Expand All @@ -18,13 +16,12 @@ impl Shape for fj::Group {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
let mut faces = Faces::new();

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

faces.extend(a.into_inner());
faces.extend(b.into_inner());
Expand Down
18 changes: 6 additions & 12 deletions crates/fj-operations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ pub mod shape_processor;

mod difference_2d;
mod group;
mod planes;
mod sketch;
mod sweep;
mod transform;

pub use self::planes::Planes;

use fj_interop::debug::DebugInfo;
use fj_kernel::{
algorithms::validate::{
Expand All @@ -46,7 +43,6 @@ pub trait Shape {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError>;

Expand All @@ -64,20 +60,19 @@ impl Shape for fj::Shape {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
match self {
Self::Shape2d(shape) => shape
.compute_brep(config, objects, planes, debug_info)?
.compute_brep(config, objects, debug_info)?
.into_inner()
.into_faces()
.validate_with_config(config),
Self::Group(shape) => {
shape.compute_brep(config, objects, planes, debug_info)
shape.compute_brep(config, objects, debug_info)
}
Self::Sweep(shape) => shape
.compute_brep(config, objects, planes, debug_info)?
.compute_brep(config, objects, debug_info)?
.into_inner()
.into_shells()
.map(|shell| shell.into_faces())
Expand All @@ -88,7 +83,7 @@ impl Shape for fj::Shape {
.unwrap_or_default()
.validate_with_config(config),
Self::Transform(shape) => {
shape.compute_brep(config, objects, planes, debug_info)
shape.compute_brep(config, objects, debug_info)
}
}
}
Expand All @@ -110,15 +105,14 @@ impl Shape for fj::Shape2d {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
match self {
Self::Difference(shape) => {
shape.compute_brep(config, objects, planes, debug_info)
shape.compute_brep(config, objects, debug_info)
}
Self::Sketch(shape) => {
shape.compute_brep(config, objects, planes, debug_info)
shape.compute_brep(config, objects, debug_info)
}
}
}
Expand Down
50 changes: 0 additions & 50 deletions crates/fj-operations/src/planes.rs

This file was deleted.

6 changes: 2 additions & 4 deletions crates/fj-operations/src/shape_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use fj_kernel::{
};
use fj_math::Scalar;

use crate::{planes::Planes, Shape as _};
use crate::Shape as _;

/// Processes an [`fj::Shape`] into a [`ProcessedShape`]
pub struct ShapeProcessor {
Expand Down Expand Up @@ -44,10 +44,8 @@ impl ShapeProcessor {

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

Ok(ProcessedShape {
Expand Down
5 changes: 1 addition & 4 deletions crates/fj-operations/src/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use fj_kernel::{
};
use fj_math::{Aabb, Point};

use crate::planes::Planes;

use super::Shape;

impl Shape for fj::Sketch {
Expand All @@ -19,10 +17,9 @@ impl Shape for fj::Sketch {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
_: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
let surface = planes.xy();
let surface = objects.surfaces.xy_plane();

let face = match self.chain() {
fj::Chain::Circle(circle) => {
Expand Down
7 changes: 1 addition & 6 deletions crates/fj-operations/src/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use fj_kernel::{
};
use fj_math::{Aabb, Vector};

use crate::planes::Planes;

use super::Shape;

impl Shape for fj::Sweep {
Expand All @@ -19,12 +17,9 @@ impl Shape for fj::Sweep {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
let sketch = self
.shape()
.compute_brep(config, objects, planes, debug_info)?;
let sketch = self.shape().compute_brep(config, objects, debug_info)?;
let path = Vector::from(self.path());

let solid = sketch.into_inner().sweep(path, objects);
Expand Down
5 changes: 1 addition & 4 deletions crates/fj-operations/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ use fj_kernel::{
};
use fj_math::{Aabb, Transform, Vector};

use crate::planes::Planes;

use super::Shape;

impl Shape for fj::Transform {
Expand All @@ -19,12 +17,11 @@ impl Shape for fj::Transform {
&self,
config: &ValidationConfig,
objects: &Objects,
planes: &Planes,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
let faces = self
.shape
.compute_brep(config, objects, planes, debug_info)?
.compute_brep(config, objects, debug_info)?
.into_inner()
.transform(&make_transform(self), objects);

Expand Down

0 comments on commit 3de8030

Please sign in to comment.