use std::fmt::{self, Debug};
#[derive(Clone, Copy)]
pub struct Tolerance {
pub distance: f64,
pub time: f64,
pub velocity: f64,
}
const EPSILON_DEFAULT: f64 = 1e-3;
impl Tolerance {
pub const fn new(distance: f64, time: f64, velocity: f64) -> Tolerance {
Tolerance {
distance,
time,
velocity,
}
}
pub const DEFAULT_TOLERANCE: Tolerance = Tolerance {
distance: EPSILON_DEFAULT,
time: EPSILON_DEFAULT,
velocity: EPSILON_DEFAULT,
};
}
impl Default for Tolerance {
fn default() -> Tolerance {
Tolerance::DEFAULT_TOLERANCE
}
}
impl Debug for Tolerance {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Tolerance(distance: ±{}, time: ±{}, velocity: ±{})",
self.distance, self.time, self.velocity
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn tolerance_control_test() {
let text = format!("{:?}", Tolerance::DEFAULT_TOLERANCE);
assert!(!text.contains('\n'));
assert!(!text.is_empty());
}
}