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

Make use of Faces in fj-operations #1052

Merged
merged 3 commits into from
Sep 7, 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
19 changes: 10 additions & 9 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use fj_math::{Transform, Vector};

use crate::objects::{
Curve, Cycle, Edge, Face, GlobalCurve, GlobalVertex, Shell, Sketch, Solid,
Surface, SurfaceVertex, Vertex,
Curve, Cycle, Edge, Face, Faces, GlobalCurve, GlobalVertex, Shell, Sketch,
Solid, Surface, SurfaceVertex, Vertex,
};

/// Transform an object
Expand Down Expand Up @@ -90,6 +90,14 @@ impl TransformObject for Face {
}
}

impl TransformObject for Faces {
fn transform(self, transform: &Transform) -> Self {
let mut faces = Faces::new();
faces.extend(self.into_iter().map(|face| face.transform(transform)));
faces
}
}

impl TransformObject for GlobalCurve {
fn transform(self, transform: &Transform) -> Self {
let kind = self.kind().transform(transform);
Expand Down Expand Up @@ -162,13 +170,6 @@ impl TransformObject for Vertex {
}
}

/// Transform a shape
pub fn transform_faces(faces: &mut Vec<Face>, transform: &Transform) {
for face in faces {
*face = face.clone().transform(transform);
}
}

fn transform_cycles<'a>(
cycles: impl IntoIterator<Item = &'a Cycle> + 'a,
transform: &'a Transform,
Expand Down
6 changes: 3 additions & 3 deletions crates/fj-operations/src/group.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ use fj_kernel::{
approx::Tolerance,
validate::{Validate, Validated, ValidationConfig, ValidationError},
},
objects::Face,
objects::Faces,
};
use fj_math::Aabb;

use super::Shape;

impl Shape for fj::Group {
type Brep = Vec<Face>;
type Brep = Faces;

fn compute_brep(
&self,
config: &ValidationConfig,
tolerance: Tolerance,
debug_info: &mut DebugInfo,
) -> Result<Validated<Self::Brep>, ValidationError> {
let mut faces = Vec::new();
let mut faces = Faces::new();

let a = self.a.compute_brep(config, tolerance, debug_info)?;
let b = self.b.compute_brep(config, tolerance, debug_info)?;
Expand Down
14 changes: 8 additions & 6 deletions crates/fj-operations/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use fj_kernel::{
approx::Tolerance,
validate::{Validate, Validated, ValidationConfig, ValidationError},
},
objects::{Face, Sketch},
objects::{Faces, Sketch},
};
use fj_math::Aabb;

Expand All @@ -55,7 +55,7 @@ pub trait Shape {
}

impl Shape for fj::Shape {
type Brep = Vec<Face>;
type Brep = Faces;

fn compute_brep(
&self,
Expand All @@ -68,8 +68,6 @@ impl Shape for fj::Shape {
.compute_brep(config, tolerance, debug_info)?
.into_inner()
.into_faces()
.into_iter()
.collect::<Vec<_>>()
.validate_with_config(config),
Self::Group(shape) => {
shape.compute_brep(config, tolerance, debug_info)
Expand All @@ -78,8 +76,12 @@ impl Shape for fj::Shape {
.compute_brep(config, tolerance, debug_info)?
.into_inner()
.into_shells()
.flat_map(|shell| shell.into_faces())
.collect::<Vec<_>>()
.map(|shell| shell.into_faces())
.reduce(|mut a, b| {
a.extend(b);
a
})
.unwrap_or_default()
.validate_with_config(config),
Self::Transform(shape) => {
shape.compute_brep(config, tolerance, debug_info)
Expand Down
13 changes: 6 additions & 7 deletions crates/fj-operations/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@ use fj_interop::debug::DebugInfo;
use fj_kernel::{
algorithms::{
approx::Tolerance,
transform::transform_faces,
transform::TransformObject,
validate::{Validate, Validated, ValidationConfig, ValidationError},
},
objects::Face,
objects::Faces,
};
use fj_math::{Aabb, Transform, Vector};

use super::Shape;

impl Shape for fj::Transform {
type Brep = Vec<Face>;
type Brep = Faces;

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

transform_faces(&mut faces, &make_transform(self));
.into_inner()
.transform(&make_transform(self));

faces.validate_with_config(config)
}
Expand Down