From 1955f35aef680f3c6487b7dd982242aa1ef488a8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 Jun 2022 14:37:58 +0200 Subject: [PATCH 1/7] Rename `triangulation` module to `triangulate` The new name matches the name of the module's main function, and is also more consistent with the names of its sibling modules. --- crates/fj-kernel/src/algorithms/mod.rs | 4 ++-- .../src/algorithms/{triangulation => triangulate}/delaunay.rs | 0 .../src/algorithms/{triangulation => triangulate}/mod.rs | 0 .../src/algorithms/{triangulation => triangulate}/polygon.rs | 0 .../src/algorithms/{triangulation => triangulate}/ray.rs | 0 5 files changed, 2 insertions(+), 2 deletions(-) rename crates/fj-kernel/src/algorithms/{triangulation => triangulate}/delaunay.rs (100%) rename crates/fj-kernel/src/algorithms/{triangulation => triangulate}/mod.rs (100%) rename crates/fj-kernel/src/algorithms/{triangulation => triangulate}/polygon.rs (100%) rename crates/fj-kernel/src/algorithms/{triangulation => triangulate}/ray.rs (100%) diff --git a/crates/fj-kernel/src/algorithms/mod.rs b/crates/fj-kernel/src/algorithms/mod.rs index 01928fca2..625d77ce4 100644 --- a/crates/fj-kernel/src/algorithms/mod.rs +++ b/crates/fj-kernel/src/algorithms/mod.rs @@ -6,7 +6,7 @@ mod approx; mod sweep; mod transform; -mod triangulation; +mod triangulate; pub mod intersection; @@ -14,5 +14,5 @@ pub use self::{ approx::{CycleApprox, FaceApprox, InvalidTolerance, Tolerance}, sweep::sweep, transform::transform, - triangulation::triangulate, + triangulate::triangulate, }; 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 From 6dbe0c35da8776c071fc6c7da2feadf5bbbbf796 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 Jun 2022 15:01:32 +0200 Subject: [PATCH 2/7] Make function name more explicit --- crates/fj-kernel/src/algorithms/mod.rs | 2 +- crates/fj-kernel/src/algorithms/transform.rs | 2 +- crates/fj-operations/src/transform.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/mod.rs b/crates/fj-kernel/src/algorithms/mod.rs index 625d77ce4..5f4a31993 100644 --- a/crates/fj-kernel/src/algorithms/mod.rs +++ b/crates/fj-kernel/src/algorithms/mod.rs @@ -13,6 +13,6 @@ pub mod intersection; pub use self::{ approx::{CycleApprox, FaceApprox, InvalidTolerance, Tolerance}, sweep::sweep, - transform::transform, + transform::transform_shape, triangulate::triangulate, }; diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index 11e88e4f3..7733c5b34 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -6,7 +6,7 @@ use crate::{ }; /// Transform a shape -pub fn transform(faces: &[Face], transform: &Transform) -> Vec { +pub fn transform_shape(faces: &[Face], transform: &Transform) -> Vec { let mut target = Vec::new(); for face in faces { diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index 07f4868e7..bc4fbf2a5 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}, }; @@ -16,7 +16,7 @@ impl ToShape for fj::Transform { 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)); + let faces = transform_shape(&shape.into_inner(), &make_transform(self)); validate(faces, config) } From c80fb0315e082d05128cea82d5e139dfd37d3372 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 Jun 2022 15:03:13 +0200 Subject: [PATCH 3/7] Add `transform_face` --- crates/fj-kernel/src/algorithms/transform.rs | 52 +++++++++++--------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index 7733c5b34..968e2ceff 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -10,37 +10,41 @@ pub fn transform_shape(faces: &[Face], transform: &Transform) -> Vec { let mut target = Vec::new(); for face in faces { - let face = match face { - Face::Face(face) => { - let surface = face.surface.transform(transform); + let face = transform_face(face, transform); + target.push(face); + } + + target +} - 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( From e2192c571e7c00c87f3f742e55cefc620eb864fb Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 Jun 2022 15:04:44 +0200 Subject: [PATCH 4/7] Use `transform_face` in `sweep` --- crates/fj-kernel/src/algorithms/sweep.rs | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/sweep.rs b/crates/fj-kernel/src/algorithms/sweep.rs index 0645b2a85..33ab653fc 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(); From 4b0e7b96f91bf5adc8836e76aa0e993dab445782 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 Jun 2022 15:06:40 +0200 Subject: [PATCH 5/7] Refactor --- crates/fj-operations/src/transform.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index bc4fbf2a5..f1685ec0a 100644 --- a/crates/fj-operations/src/transform.rs +++ b/crates/fj-operations/src/transform.rs @@ -15,8 +15,13 @@ 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(&shape.into_inner(), &make_transform(self)); + let shape = self + .shape + .to_shape(config, tolerance, debug_info)? + .into_inner(); + + let faces = transform_shape(&shape, &make_transform(self)); + validate(faces, config) } From e5988810685c9294fd598103145e228681fedda8 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 Jun 2022 15:07:23 +0200 Subject: [PATCH 6/7] Rename variable --- crates/fj-operations/src/transform.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index f1685ec0a..d05cafe57 100644 --- a/crates/fj-operations/src/transform.rs +++ b/crates/fj-operations/src/transform.rs @@ -20,9 +20,9 @@ impl ToShape for fj::Transform { .to_shape(config, tolerance, debug_info)? .into_inner(); - let faces = transform_shape(&shape, &make_transform(self)); + let shape = transform_shape(&shape, &make_transform(self)); - validate(faces, config) + validate(shape, config) } fn bounding_volume(&self) -> Aabb<3> { From eedb67fd74302808d4fed3d31f1a997c74e2af9e Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 29 Jun 2022 15:08:09 +0200 Subject: [PATCH 7/7] Simplify interface of `transform_shape` --- crates/fj-kernel/src/algorithms/transform.rs | 9 ++------- crates/fj-operations/src/transform.rs | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/fj-kernel/src/algorithms/transform.rs b/crates/fj-kernel/src/algorithms/transform.rs index 968e2ceff..066a48e53 100644 --- a/crates/fj-kernel/src/algorithms/transform.rs +++ b/crates/fj-kernel/src/algorithms/transform.rs @@ -6,15 +6,10 @@ use crate::{ }; /// Transform a shape -pub fn transform_shape(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 = transform_face(face, transform); - target.push(face); + *face = transform_face(face, transform); } - - target } pub fn transform_face(face: &Face, transform: &Transform) -> Face { diff --git a/crates/fj-operations/src/transform.rs b/crates/fj-operations/src/transform.rs index d05cafe57..6fbe0d011 100644 --- a/crates/fj-operations/src/transform.rs +++ b/crates/fj-operations/src/transform.rs @@ -15,12 +15,12 @@ impl ToShape for fj::Transform { tolerance: Tolerance, debug_info: &mut DebugInfo, ) -> Result>, ValidationError> { - let shape = self + let mut shape = self .shape .to_shape(config, tolerance, debug_info)? .into_inner(); - let shape = transform_shape(&shape, &make_transform(self)); + transform_shape(&mut shape, &make_transform(self)); validate(shape, config) }