| 1 |
|
| 2 |
#[derive(Debug, Clone, PartialEq, PartialOrd, Copy)] |
| 3 |
pub struct ModelerParams { |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
> |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
pub wobble_smoother_timeout: f64, |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
pub wobble_smoother_speed_floor: f64, |
| 33 |
pub wobble_smoother_speed_ceiling: f64, |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
pub position_modeler_spring_mass_constant: f64, |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
pub position_modeler_drag_constant: f64, |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
pub sampling_min_output_rate: f64, |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
pub sampling_end_of_stroke_stopping_distance: f64, |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
pub sampling_end_of_stroke_max_iterations: usize, |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
pub sampling_max_outputs_per_call: usize, |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
pub stylus_state_modeler_max_input_samples: usize, |
| 75 |
} |
| 76 |
|
| 77 |
impl ModelerParams { |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
pub fn suggested() -> Self { |
| 89 |
Self { |
| 90 |
wobble_smoother_timeout: 0.04, |
| 91 |
wobble_smoother_speed_floor: 1.31, |
| 92 |
wobble_smoother_speed_ceiling: 1.44, |
| 93 |
position_modeler_spring_mass_constant: 11.0 / 32400.0, |
| 94 |
position_modeler_drag_constant: 72.0, |
| 95 |
sampling_min_output_rate: 180.0, |
| 96 |
sampling_end_of_stroke_stopping_distance: 0.001, |
| 97 |
sampling_end_of_stroke_max_iterations: 20, |
| 98 |
sampling_max_outputs_per_call: 20, |
| 99 |
stylus_state_modeler_max_input_samples: 10, |
| 100 |
} |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
pub fn validate(self) -> Result<Self, String> { |
| 106 |
let parameter_tests = [ |
| 107 |
self.position_modeler_spring_mass_constant > 0.0, |
| 108 |
self.position_modeler_drag_constant > 0.0, |
| 109 |
self.sampling_min_output_rate > 0.0, |
| 110 |
self.sampling_end_of_stroke_stopping_distance > 0.0, |
| 111 |
self.sampling_end_of_stroke_max_iterations > 0, |
| 112 |
self.sampling_end_of_stroke_max_iterations < 1000, |
| 113 |
self.sampling_max_outputs_per_call > 0, |
| 114 |
self.wobble_smoother_timeout > 0.0, |
| 115 |
self.wobble_smoother_speed_floor > 0.0, |
| 116 |
self.wobble_smoother_speed_ceiling > 0.0, |
| 117 |
self.wobble_smoother_speed_floor < self.wobble_smoother_speed_ceiling, |
| 118 |
]; |
| 119 |
|
| 120 |
let errors = vec![ |
| 121 |
"`position_modeler_spring_mass_constant` is not positive; ", |
| 122 |
"`position_modeler_drag_constant` is not positive; ", |
| 123 |
"`sampling_min_output_rate` is not positive; ", |
| 124 |
"`sampling_end_of_stroke_stopping_distance` is not positive; ", |
| 125 |
"`sampling_end_of_stroke_max_iterations` is not positive; ", |
| 126 |
"`sampling_end_of_stroke_max_iterations` is too large (>1000); ", |
| 127 |
"`sampling_max_outputs_per_call` is not positive; ", |
| 128 |
"`wobble_smoother_timeout` is not positive; ", |
| 129 |
"`wobble_smoother_speed_floor` is not positive; ", |
| 130 |
"`wobble_smoother_speed_ceiling` is not positive; ", |
| 131 |
"`wobble_smoother_speed_floor` should be strictly smaller than `wobble_smoother_speed_ceiling`", |
| 132 |
]; |
| 133 |
|
| 134 |
let tests_passed = parameter_tests.iter().fold(true, |acc, x| acc & x); |
| 135 |
|
| 136 |
if tests_passed { |
| 137 |
Ok(self) |
| 138 |
} else { |
| 139 |
|
| 140 |
let error_acc = parameter_tests.iter().zip(errors).filter(|x| !*(x.0)).fold( |
| 141 |
String::from("the following errors occurred : "), |
| 142 |
|acc, x| acc + x.1, |
| 143 |
); |
| 144 |
|
| 145 |
Err(error_acc) |
| 146 |
} |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
#[cfg(test)] |
| 151 |
mod test_params { |
| 152 |
|
| 153 |
use super::super::*; |
| 154 |
#[test] |
| 155 |
fn validation_modeler_params() { |
| 156 |
let s = (ModelerParams { |
| 157 |
wobble_smoother_timeout: -1.0, |
| 158 |
wobble_smoother_speed_floor: -1.0, |
| 159 |
wobble_smoother_speed_ceiling: -1.0, |
| 160 |
position_modeler_spring_mass_constant: -1.0, |
| 161 |
position_modeler_drag_constant: -1.0, |
| 162 |
sampling_min_output_rate: -1.0, |
| 163 |
sampling_end_of_stroke_stopping_distance: -1.0, |
| 164 |
sampling_end_of_stroke_max_iterations: 0, |
| 165 |
sampling_max_outputs_per_call: 0, |
| 166 |
stylus_state_modeler_max_input_samples: 0, |
| 167 |
}) |
| 168 |
.validate(); |
| 169 |
match s { |
| 170 |
Ok(_) => assert!(false), |
| 171 |
Err(_) => assert!(true), |
| 172 |
} |
| 173 |
} |
| 174 |
} |