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

Add command line argument for user defined model tolerance #352

Merged
merged 1 commit into from
Mar 15, 2022
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
4 changes: 4 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ pub struct Args {
/// Parameters for the model, each in the form `key=value`
#[clap(short, long)]
pub parameters: Vec<String>,

// Model deviation tolerance
#[clap[short, long]]
pub tolerance: Option<f64>,
}

impl Args {
Expand Down
36 changes: 23 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,32 @@ 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 tolerance = match args.tolerance {
None => {
// 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
}
Some(user_defined_tolerance) => {
if user_defined_tolerance > 0.0 {
Scalar::from_f64(user_defined_tolerance)
} else {
anyhow::bail!("Invalid user defined model deviation tolerance: {}. Tolerance must be larger than zero",
user_defined_tolerance)
}
}
};

let mut debug_info = DebugInfo::new();
Expand Down