ink_stroke_modeler_rs/
results.rs

1/// result struct
2/// contains the position, time, presusre as well as the velocity and acceleration data
3#[derive(Debug, PartialEq)]
4pub struct ModelerResult {
5    pub pos: (f64, f64),
6    pub velocity: (f64, f64),
7    pub acceleration: (f64, f64),
8    pub time: f64,
9    pub pressure: f64,
10}
11
12/// A [ModelerResult] that does not have yet a pressure information
13#[derive(Clone, Debug)]
14pub(crate) struct ModelerPartial {
15    pub pos: (f64, f64),
16    pub velocity: (f64, f64),
17    pub acceleration: (f64, f64),
18    pub time: f64,
19}
20
21impl ModelerResult {
22    #[cfg(test)]
23    pub fn near(self, other: ModelerResult) -> bool {
24        let tol = 3.0 * 1e-3; //tolerance increased for f64
25        approx::abs_diff_eq!(self.pos.0, other.pos.0, epsilon = tol)
26            && approx::abs_diff_eq!(self.pos.1, other.pos.1, epsilon = tol)
27            && approx::abs_diff_eq!(self.time, other.time, epsilon = tol as f64)
28            && approx::abs_diff_eq!(self.acceleration.0, other.acceleration.0, epsilon = tol)
29            && approx::abs_diff_eq!(self.acceleration.1, other.acceleration.1, epsilon = tol)
30            && approx::abs_diff_eq!(self.velocity.0, other.velocity.0, epsilon = tol)
31            && approx::abs_diff_eq!(self.velocity.1, other.velocity.1, epsilon = tol)
32            && approx::abs_diff_eq!(self.pressure, other.pressure, epsilon = tol)
33    }
34}
35
36impl Default for ModelerResult {
37    fn default() -> Self {
38        Self {
39            pos: (0.0, 0.0),
40            velocity: (0.0, 0.0),
41            acceleration: (0.0, 0.0),
42            pressure: 1.0,
43            time: 0.0,
44        }
45    }
46}
47
48/// Utility to compare [ModelerResult] up to `tol =1e-4` (not settable for now)
49/// with printed output for debug purposes
50///
51/// Only used for testing purposes
52#[allow(unused)]
53#[cfg(test)]
54pub(crate) fn compare_results(left: Vec<ModelerResult>, right: Vec<ModelerResult>) -> bool {
55    if left.len() != right.len() {
56        println!("\n\nleft : {:?} right {:?}", left.len(), right.len());
57        //iterate
58        println!("left");
59        for el in left {
60            println!("{:?}", el);
61        }
62        println!("right");
63        for el in right {
64            println!("{:?}", el);
65        }
66        false
67    } else {
68        println!("\n\n\nleft : {:?} right {:?}", &left.len(), &right.len());
69        //iterate
70        println!("left");
71        for el in &left {
72            println!("{:?}", el);
73        }
74        println!("right");
75        for el in &right {
76            println!("{:?}", el);
77        }
78
79        left.into_iter().zip(right).all(|x| x.0.near(x.1))
80    }
81}