use crate::Precision;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Tolerance {
pub linear: f64,
pub angular: f64,
}
impl Tolerance {
pub const fn new(linear: f64, angular: f64) -> Self {
Tolerance { linear, angular }
}
pub fn is_consistent(&self) -> bool {
self.linear.is_finite()
&& self.linear > 0.0
&& self.angular.is_finite()
&& self.angular > 0.0
}
}
impl Precision {
pub const fn tolerance(&self) -> Tolerance {
Tolerance::new(self.default_tolerance, self.angular_tolerance)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn default_precision_gives_a_consistent_tolerance() {
assert!(Precision::DEFAULT.tolerance().is_consistent());
assert!(!Tolerance::new(0.0, 1e-12).is_consistent());
assert!(!Tolerance::new(1e-7, f64::NAN).is_consistent());
}
}