Skip to content

Commit

Permalink
Merge pull request #1775 from hannobraun/operations
Browse files Browse the repository at this point in the history
Fix face orientation in `BuildShell::tetrahedron`
  • Loading branch information
hannobraun authored Apr 20, 2023
2 parents 74d611d + b9ded3b commit 9feabba
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
27 changes: 22 additions & 5 deletions crates/fj-kernel/src/operations/build/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ use super::{BuildFace, Triangle};
/// Build a [`Shell`]
pub trait BuildShell {
/// Build a tetrahedron from the provided points
///
/// Accepts 4 points, naturally. For the purposes of the following
/// discussion, let's call those `a`, `b`, `c`, and `d`, and assume that the
/// order they are listed in here matches the order they are provided in
/// within the array.
///
/// Assumes that `a`, `b`, and `c` form a triangle in counter-clockwise
/// order, when arranging the viewpoint such that it is on the opposite side
/// of the triangle from `d`. If this assumption is met, the orientation of
/// all faces of the tetrahedron will be valid, meaning their
/// counter-clockwise sides are outside.
///
/// # Implementation Note
///
/// In principle, this method doesn't need to make assumptions about the
/// order of the points provided. It could, given some extra effort, just
/// build a correct tetrahedron, regardless of that order.
fn tetrahedron(
points: [impl Into<Point<3>>; 4],
objects: &mut Service<Objects>,
Expand All @@ -24,14 +41,14 @@ pub trait BuildShell {
} = Face::triangle([a, b, c], [None, None, None], objects);
let Triangle {
face: face_abd,
edges: [_, bd, da],
} = Face::triangle([a, b, d], [Some(ab), None, None], objects);
edges: [_, ad, db],
} = Face::triangle([b, a, d], [Some(ab), None, None], objects);
let Triangle {
face: face_cad,
edges: [_, _, dc],
} = Face::triangle([c, a, d], [Some(ca), Some(da), None], objects);
edges: [_, _, cd],
} = Face::triangle([d, a, c], [Some(ad), Some(ca), None], objects);
let Triangle { face: face_bcd, .. } =
Face::triangle([b, c, d], [Some(bc), Some(dc), Some(bd)], objects);
Face::triangle([c, b, d], [Some(bc), Some(db), Some(cd)], objects);

let faces = [face_abc, face_abd, face_cad, face_bcd]
.map(|face| face.insert(objects));
Expand Down
4 changes: 2 additions & 2 deletions crates/fj-kernel/src/validate/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod tests {
let mut services = Services::new();

let valid = Shell::tetrahedron(
[[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]],
[[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]],
&mut services.objects,
);
let invalid = valid.shell.update_face(&valid.face_abc, |face| {
Expand Down Expand Up @@ -240,7 +240,7 @@ mod tests {
let mut services = Services::new();

let valid = Shell::tetrahedron(
[[0., 0., 0.], [1., 0., 0.], [0., 1., 0.], [0., 0., 1.]],
[[0., 0., 0.], [0., 1., 0.], [1., 0., 0.], [0., 0., 1.]],
&mut services.objects,
);
let invalid = valid.shell.remove_face(&valid.face_abc);
Expand Down

0 comments on commit 9feabba

Please sign in to comment.