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

Update default validation config; compute values from each other, based on the tolerance #2449

Merged
merged 7 commits into from
Aug 12, 2024
Merged
48 changes: 31 additions & 17 deletions crates/fj-core/src/validation/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,34 +24,48 @@ pub struct ValidationConfig {
/// The tolerance value used for intermediate geometry representation
pub tolerance: Tolerance,

/// The minimum distance between distinct objects
///
/// Objects whose distance is less than the value defined in this field, are
/// considered identical.
pub distinct_min_distance: Scalar,

/// The maximum distance between identical objects
///
/// Objects that are considered identical might still have a distance
/// between them, due to inaccuracies of the numerical representation. If
/// that distance is less than the one defined in this field, can not be
/// considered identical.
pub identical_max_distance: Scalar,

/// The minimum distance between distinct objects
///
/// Objects whose distance is less than the value defined in this field, are
/// considered identical.
pub distinct_min_distance: Scalar,
}

impl Default for ValidationConfig {
fn default() -> Self {
impl ValidationConfig {
/// Compute validation config from a tolerance value
pub fn from_tolerance(tolerance: impl Into<Tolerance>) -> Self {
let tolerance = tolerance.into();

// This value can't be smaller than the tolerance. If it is, we'll get
// validation errors everywhere, just from numerical noise.
let identical_max_distance = tolerance.inner() * 10.;

// This value can't be smaller than `identical_max_distance`. Otherwise
// we can have distinct points that satisfy this constraint, but must be
// considered identical according to the other.
//
// This factor was chosen pretty arbitrarily and might need to be tuned.
let distinct_min_distance = identical_max_distance * 2.;

Self {
panic_on_error: false,
distinct_min_distance: Scalar::from_f64(5e-7), // 0.5 µm,
tolerance: Tolerance::from_scalar(0.001)
.expect("Tolerance provided is larger than zero"),

// This value was chosen pretty arbitrarily. Seems small enough to
// catch errors. If it turns out it's too small (because it produces
// false positives due to floating-point accuracy issues), we can
// adjust it.
identical_max_distance: Scalar::from_f64(5e-14),
tolerance,
identical_max_distance,
distinct_min_distance,
}
}
}

impl Default for ValidationConfig {
fn default() -> Self {
Self::from_tolerance(0.001)
}
}