Skip to content

Commit

Permalink
Merge pull request #743 from hannobraun/transform
Browse files Browse the repository at this point in the history
Clean up transform code
  • Loading branch information
hannobraun authored Jun 29, 2022
2 parents c8a51ac + eedb67f commit 6556a18
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 42 deletions.
6 changes: 3 additions & 3 deletions crates/fj-kernel/src/algorithms/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
12 changes: 4 additions & 8 deletions crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -88,18 +88,14 @@ fn create_top_face(
is_sweep_along_negative_direction: bool,
target: &mut Vec<Face>,
) {
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();

Expand Down
53 changes: 26 additions & 27 deletions crates/fj-kernel/src/algorithms/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,40 @@ use crate::{
};

/// Transform a shape
pub fn transform(faces: &[Face], transform: &Transform) -> Vec<Face> {
let mut target = Vec::new();

pub fn transform_shape(faces: &mut Vec<Face>, 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(
Expand Down
13 changes: 9 additions & 4 deletions crates/fj-operations/src/transform.rs
Original file line number Diff line number Diff line change
@@ -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},
};
Expand All @@ -15,9 +15,14 @@ impl ToShape for fj::Transform {
tolerance: Tolerance,
debug_info: &mut DebugInfo,
) -> Result<Validated<Vec<Face>>, 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> {
Expand Down

0 comments on commit 6556a18

Please sign in to comment.