diff --git a/src/args.rs b/src/args.rs index 42084065cf..034f40fce1 100644 --- a/src/args.rs +++ b/src/args.rs @@ -14,6 +14,10 @@ pub struct Args { /// Parameters for the model, each in the form `key=value` #[clap(short, long)] pub parameters: Vec, + + // Model deviation tolerance + #[clap[short, long, default_value = "0.0"]] + pub tolerance: f64, } impl Args { diff --git a/src/main.rs b/src/main.rs index da88179ea6..e3a705d206 100644 --- a/src/main.rs +++ b/src/main.rs @@ -81,22 +81,27 @@ fn main() -> anyhow::Result<()> { let mut aabb = shape.bounding_volume(); - // Compute a reasonable default for the tolerance value. To do this, we just - // look at the smallest non-zero extent of the bounding box and divide that - // by some value. - let tolerance = { - let mut min_extent = Scalar::MAX; - for extent in aabb.size().components() { - if extent > Scalar::ZERO && extent < min_extent { - min_extent = extent; + let user_defined_tolerance = Scalar::from_f64(args.tolerance); + + let tolerance = match user_defined_tolerance { + m if m <= Scalar::ZERO => { + // Compute a reasonable default for the tolerance value. To do this, we just + // look at the smallest non-zero extent of the bounding box and divide that + // by some value. + let mut min_extent = Scalar::MAX; + for extent in aabb.size().components() { + if extent > Scalar::ZERO && extent < min_extent { + min_extent = extent; + } } - } - // `tolerance` must not be zero, or we'll run into trouble. - let tolerance = min_extent / Scalar::from_f64(1000.); - assert!(tolerance > Scalar::ZERO); + // `tolerance` must not be zero, or we'll run into trouble. + let tolerance = min_extent / Scalar::from_f64(1000.); + assert!(tolerance > Scalar::ZERO); - tolerance + tolerance + } + _ => user_defined_tolerance, }; let mut debug_info = DebugInfo::new();