Skip to content

Commit d7ec364

Browse files
committed
fix(deep_causality_num): Minor fixes and lints.
Signed-off-by: Marvin Hansen <[email protected]>
1 parent 79ce74c commit d7ec364

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

deep_causality_num/src/quaternion/arithmetic.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ impl<F: Float> Mul for Quaternion<F> {
9797
/// assert_eq!(q_j * q_i, -q_k); // j * i = -k
9898
/// ```
9999
fn mul(self, other: Self) -> Self {
100+
let (w1, x1, y1, z1) = (self.w, self.x, self.y, self.z);
101+
let (w2, x2, y2, z2) = (other.w, other.x, other.y, other.z);
102+
100103
Quaternion {
101-
w: self.w * other.w - self.x * other.x - self.y * other.y - self.z * other.z,
102-
x: self.w * other.x + self.x * other.w + self.y * other.z - self.z * other.y,
103-
y: self.w * other.y - self.x * other.z + self.y * other.w + self.z * other.x,
104-
z: self.w * other.z + self.x * other.y - self.y * other.x + self.z * other.w,
104+
w: w1 * w2 - x1 * x2 - y1 * y2 - z1 * z2,
105+
x: w1 * x2 + x1 * w2 + y1 * z2 - z1 * y2,
106+
y: w1 * y2 - x1 * z2 + y1 * w2 + z1 * x2,
107+
z: w1 * z2 + x1 * y2 - y1 * x2 + z1 * w2,
105108
}
106109
}
107110
}

deep_causality_num/tests/quaternion/as_primitive_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use deep_causality_num::Quaternion;
55
fn test_as_primitive_f64() {
66
let q = Quaternion::new(1.23, 4.56, 7.89, 0.12);
77
let val: f64 = q.as_();
8-
assert_eq!(val, 1.23);
8+
assert!((val - 1.23).abs() < 1e-12);
99
}
1010

1111
#[test]
1212
fn test_as_primitive_f32() {
1313
let q = Quaternion::new(1.23f32, 4.56f32, 7.89f32, 0.12f32);
1414
let val: f32 = q.as_();
15-
assert_eq!(val, 1.23f32);
15+
assert!((val - 1.23f32).abs() < 1e-6);
1616
}
1717

1818
#[test]

deep_causality_num/tests/quaternion/display_tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ fn test_display_format() {
55
let q = Quaternion::new(1.0, 2.0, 3.0, 4.0);
66
let display_str = format!("{}", q);
77
assert_eq!(display_str, "1 + 2i + 3j + 4k");
8+
9+
let q_neg = Quaternion::new(1.0, -2.0, 3.0, -4.0);
10+
let display_str_neg = format!("{}", q_neg);
11+
assert_eq!(display_str_neg, "1 - 2i + 3j - 4k");
812
}

0 commit comments

Comments
 (0)