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

Correct face orientation fixes #506 #628

Merged
merged 2 commits into from
May 24, 2022
Merged
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
31 changes: 24 additions & 7 deletions crates/fj-kernel/src/algorithms/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@ pub fn sweep_shape(
let translation = Transform::translation(path);

let (mut bottom, source_to_bottom) = source.clone_shape();
bottom
.update()
.update_all(|surface: &mut Surface| *surface = surface.reverse())
.validate()?;

let (mut top, source_to_top) = source.clone_shape();

if path.dot(&Vector::from([0., 0., 1.])) >= fj_math::Scalar::from_f64(0.) {
bottom
.update()
.update_all(|surface: &mut Surface| *surface = surface.reverse())
.validate()?;
} else {
top.update()
.update_all(|surface: &mut Surface| *surface = surface.reverse())
.validate()?;
}
transform_shape(&mut top, &translation);

let mut target = Shape::new();
Expand Down Expand Up @@ -118,11 +124,22 @@ pub fn sweep_shape(
let top_edge =
source_to_top.edges().get(&edge_source).unwrap().clone();

let surface =
let surface = if path.dot(&Vector::from([0., 0., 1.]))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nicer, if that check happened only once, and the result was stored into a variable with a descriptive name (sweep_along_negative_direction, or something like that).

With two separate checks, it becomes easy to miss one, once they need to change.

>= fj_math::Scalar::from_f64(0.)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that Scalar has some short-hands for often-used values, in this case Scalar::ZERO.

{
target.insert(Surface::SweptCurve(SweptCurve {
curve: bottom_edge.get().curve(),
path,
}))?;
}))?
} else {
target.insert(
Surface::SweptCurve(SweptCurve {
curve: bottom_edge.get().curve(),
path,
})
.reverse(), ////////////////////////////////////
Comment on lines +135 to +140
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be a bit nicer to reduce some duplication here. Something like this:

let mut surface = Surface::SweptCurve(...);

if sweep_along_negative_direction {
    surface = surface.reverse();
}

let surface = target.insert(surface)?;

)?
};

let cycle = target.merge(Cycle::new(vec![
bottom_edge,
Expand Down