diff --git a/crates/fj-kernel/src/algorithms/mod.rs b/crates/fj-kernel/src/algorithms/mod.rs index 01928fca2c..5f4a319934 100644 --- a/crates/fj-kernel/src/algorithms/mod.rs +++ b/crates/fj-kernel/src/algorithms/mod.rs @@ -6,13 +6,13 @@ mod approx; mod sweep; mod transform; -mod triangulation; +mod triangulate; pub mod intersection; pub use self::{ approx::{CycleApprox, FaceApprox, InvalidTolerance, Tolerance}, sweep::sweep, - transform::transform, - triangulation::triangulate, + transform::transform_shape, + triangulate::triangulate, }; diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index 0645b2a85f..33ab653fcc 100644 --- a/crates/fj-kernel/src/algorithms/sweep.rs +++ b/crates/fj-kernel/src/algorithms/sweep.rs @@ -8,7 +8,7 @@ use crate::{ shape::LocalForm, }; -use super::{transform::transform_cycles, CycleApprox, Tolerance}; +use super::{transform::transform_face, CycleApprox, Tolerance}; /// Create a solid by sweeping a sketch pub fn sweep( @@ -88,18 +88,14 @@ fn create_top_face( is_sweep_along_negative_direction: bool, target: &mut Vec, ) { + let translation = Transform::translation(path); + let face = transform_face(face, &translation); + let mut surface = face.surface(); let mut exteriors = face.brep().exteriors.clone(); let mut interiors = face.brep().interiors.clone(); - let translation = Transform::translation(path); - - surface = surface.transform(&translation); - - exteriors = transform_cycles(&exteriors, &translation); - interiors = transform_cycles(&interiors, &translation); - if is_sweep_along_negative_direction { surface = surface.reverse(); diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index 11e88e4f3e..066a48e53c 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -6,41 +6,40 @@ use crate::{ }; /// Transform a shape -pub fn transform(faces: &[Face], transform: &Transform) -> Vec { - let mut target = Vec::new(); - +pub fn transform_shape(faces: &mut Vec, transform: &Transform) { for face in faces { - let face = match face { - Face::Face(face) => { - let surface = face.surface.transform(transform); + *face = transform_face(face, transform); + } +} - let exteriors = transform_cycles(&face.exteriors, transform); - let interiors = transform_cycles(&face.interiors, transform); +pub fn transform_face(face: &Face, transform: &Transform) -> Face { + match face { + Face::Face(face) => { + let surface = face.surface.transform(transform); - let color = face.color; + let exteriors = transform_cycles(&face.exteriors, transform); + let interiors = transform_cycles(&face.interiors, transform); - Face::Face(FaceBRep { - surface, - exteriors, - interiors, - color, - }) - } - Face::Triangles(triangles) => { - let mut target = Vec::new(); + let color = face.color; - for &(triangle, color) in triangles { - let triangle = transform.transform_triangle(&triangle); - target.push((triangle, color)); - } + Face::Face(FaceBRep { + surface, + exteriors, + interiors, + color, + }) + } + Face::Triangles(triangles) => { + let mut target = Vec::new(); - Face::Triangles(target) + for &(triangle, color) in triangles { + let triangle = transform.transform_triangle(&triangle); + target.push((triangle, color)); } - }; - target.push(face); - } - target + Face::Triangles(target) + } + } } pub fn transform_cycles( diff --git a/crates/fj-kernel/src/algorithms/triangulation/delaunay.rs b/crates/fj-kernel/src/algorithms/triangulate/delaunay.rs similarity index 100% rename from crates/fj-kernel/src/algorithms/triangulation/delaunay.rs rename to crates/fj-kernel/src/algorithms/triangulate/delaunay.rs diff --git a/crates/fj-kernel/src/algorithms/triangulation/mod.rs b/crates/fj-kernel/src/algorithms/triangulate/mod.rs similarity index 100% rename from crates/fj-kernel/src/algorithms/triangulation/mod.rs rename to crates/fj-kernel/src/algorithms/triangulate/mod.rs diff --git a/crates/fj-kernel/src/algorithms/triangulation/polygon.rs b/crates/fj-kernel/src/algorithms/triangulate/polygon.rs similarity index 100% rename from crates/fj-kernel/src/algorithms/triangulation/polygon.rs rename to crates/fj-kernel/src/algorithms/triangulate/polygon.rs diff --git a/crates/fj-kernel/src/algorithms/triangulation/ray.rs b/crates/fj-kernel/src/algorithms/triangulate/ray.rs similarity index 100% rename from crates/fj-kernel/src/algorithms/triangulation/ray.rs rename to crates/fj-kernel/src/algorithms/triangulate/ray.rs diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index 07f4868e79..6fbe0d0110 100644 --- a/crates/fj-operations/src/transform.rs +++ b/crates/fj-operations/src/transform.rs @@ -1,6 +1,6 @@ use fj_interop::debug::DebugInfo; use fj_kernel::{ - algorithms::{transform, Tolerance}, + algorithms::{transform_shape, Tolerance}, objects::Face, validation::{validate, Validated, ValidationConfig, ValidationError}, }; @@ -15,9 +15,14 @@ impl ToShape for fj::Transform { tolerance: Tolerance, debug_info: &mut DebugInfo, ) -> Result>, ValidationError> { - let shape = self.shape.to_shape(config, tolerance, debug_info)?; - let faces = transform(&shape.into_inner(), &make_transform(self)); - validate(faces, config) + let mut shape = self + .shape + .to_shape(config, tolerance, debug_info)? + .into_inner(); + + transform_shape(&mut shape, &make_transform(self)); + + validate(shape, config) } fn bounding_volume(&self) -> Aabb<3> {