diff --git a/src/stick.rs b/src/stick.rs index b02028a..ea3cedc 100644 --- a/src/stick.rs +++ b/src/stick.rs @@ -19,7 +19,7 @@ pub const NO_OF_CALIBRATION_POINTS: usize = 32; const MAX_ORDER: usize = 20; /// 28 degrees; this is the max angular deflection of the stick. -const MAX_STICK_ANGLE: f32 = 0.4886921906; +const MAX_STICK_ANGLE: f32 = 0.488_692_2; #[rustfmt::skip] // right notch 1 up right notch 2 up notch 3 up left notch 4 left notch 5 down left notch 6 down notch 7 down right notch 8 @@ -263,7 +263,7 @@ impl LinearizedCalibration { fit_points_x[1] = (in_x[6 + 1] + in_x[10 + 1]) / 2.0f64; fit_points_x[2] = in_x[0]; fit_points_x[3] = (in_x[2 + 1] + in_x[14 + 1]) / 2.0f64; - fit_points_x[4] = in_x[0 + 1]; + fit_points_x[4] = in_x[1]; fit_points_y[0] = in_y[12 + 1]; fit_points_y[1] = (in_y[10 + 1] + in_y[14 + 1]) / 2.0f64; @@ -282,8 +282,8 @@ impl LinearizedCalibration { let x_zero_error = linearize(fit_points_x[2] as f32, &fit_coeffs_x.map(|e| e as f32)); let y_zero_error = linearize(fit_points_y[2] as f32, &fit_coeffs_y.map(|e| e as f32)); - fit_coeffs_x[3] = fit_coeffs_x[3] - x_zero_error as f64; - fit_coeffs_y[3] = fit_coeffs_y[3] - y_zero_error as f64; + fit_coeffs_x[3] -= x_zero_error as f64; + fit_coeffs_y[3] -= y_zero_error as f64; let mut linearized_points_x = [0f32; NO_OF_NOTCHES + 1]; let mut linearized_points_y = [0f32; NO_OF_NOTCHES + 1]; @@ -798,9 +798,7 @@ fn trianglize(matrix: &mut [[f64; N]; N]) -> i32 { } if max > 0 { sign = -sign; - let tmp = matrix[i]; - matrix[i] = matrix[max]; - matrix[max] = tmp; + matrix.swap(i, max); } if matrix[i][i] == 0. { return 0;