mirror of
https://github.com/hannobraun/Fornjot
synced 2025-02-12 18:26:00 +00:00
Use Tolerance
in Args
This commit is contained in:
parent
5f7ba6ae83
commit
d96a2bf16b
@ -1,4 +1,7 @@
|
|||||||
use std::path::PathBuf;
|
use std::{path::PathBuf, str::FromStr as _};
|
||||||
|
|
||||||
|
use fj_kernel::algorithms::Tolerance;
|
||||||
|
use fj_math::Scalar;
|
||||||
|
|
||||||
/// Fornjot - Experimental CAD System
|
/// Fornjot - Experimental CAD System
|
||||||
#[derive(clap::Parser)]
|
#[derive(clap::Parser)]
|
||||||
@ -16,8 +19,8 @@ pub struct Args {
|
|||||||
pub parameters: Vec<String>,
|
pub parameters: Vec<String>,
|
||||||
|
|
||||||
/// Model deviation tolerance
|
/// Model deviation tolerance
|
||||||
#[clap[short, long]]
|
#[clap[short, long, parse(try_from_str = parse_tolerance)]]
|
||||||
pub tolerance: Option<f64>,
|
pub tolerance: Option<Tolerance>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
@ -29,3 +32,11 @@ impl Args {
|
|||||||
<Self as clap::Parser>::parse()
|
<Self as clap::Parser>::parse()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn parse_tolerance(input: &str) -> anyhow::Result<Tolerance> {
|
||||||
|
let tolerance = f64::from_str(input)?;
|
||||||
|
let tolerance = Scalar::from_f64(tolerance);
|
||||||
|
let tolerance = Tolerance::from_scalar(tolerance)?;
|
||||||
|
|
||||||
|
Ok(tolerance)
|
||||||
|
}
|
||||||
|
@ -242,22 +242,7 @@ struct ShapeProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ShapeProcessor {
|
impl ShapeProcessor {
|
||||||
fn new(tolerance: Option<f64>) -> anyhow::Result<Self> {
|
fn new(tolerance: Option<Tolerance>) -> anyhow::Result<Self> {
|
||||||
if let Some(tolerance) = tolerance {
|
|
||||||
if tolerance <= 0. {
|
|
||||||
anyhow::bail!(
|
|
||||||
"Invalid user defined model deviation tolerance: {}.\n\
|
|
||||||
Tolerance must be larger than zero",
|
|
||||||
tolerance
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let tolerance = tolerance
|
|
||||||
.map(Scalar::from_f64)
|
|
||||||
.map(Tolerance::from_scalar)
|
|
||||||
.map(|result| result.unwrap());
|
|
||||||
|
|
||||||
Ok(Self { tolerance })
|
Ok(Self { tolerance })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user