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 deduplication of approximate vertices #74

Merged
merged 1 commit into from
Jan 21, 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
20 changes: 19 additions & 1 deletion src/kernel/topology/edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,25 @@ impl Cycle {

// As this is a cycle, the last vertex of an edge could be identical to
// the first vertex of the next. Let's remove those duplicates.
out.dedup();
out.dedup_by(|a, b| {
// We can't just compare those vertices directly, because vertices
// that are supposed to be the same could be slightly different due
// to floating point accuracy.
//
// So what we're doing here is to choose a somewhat arbitrary
// epsilon value that is some orders of magnitude larger than the
// inaccuracies I've been seeing, while still being smaller than
// any value we might reasonably see in a CAD model.
//
// This is hack-ish and might come back to bite us at some point.
// I'm fine with it for now, as I'm planning major changes to the
// architecture of the whole CAD kernel that will prevent these
// kinds of problems outright.
//
// - @hannobraun
let epsilon = 1e-12;
(*a - *b).magnitude() < epsilon
});
}

/// Compute segments to approximate the edges of this cycle
Expand Down