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

Fix face orientation in BuildShell::tetrahedron #1775

Merged
merged 6 commits into from
Apr 20, 2023
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
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