diff --git a/benches/mat.rs b/benches/mat.rs index 9d94a72..88efab9 100644 --- a/benches/mat.rs +++ b/benches/mat.rs @@ -60,4 +60,4 @@ bench_unop!(_bench_matrix2_transpose, Matrix2, transpose); bench_unop!(_bench_matrix3_transpose, Matrix3, transpose); bench_unop!(_bench_matrix4_transpose, Matrix4, transpose); -bench_unop!(_bench_matrix4_determinant, Matrix4, determinant); \ No newline at end of file +bench_unop!(_bench_matrix4_determinant, Matrix4, determinant); diff --git a/src/matrix.rs b/src/matrix.rs index 397d2ba..e900c66 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1372,4 +1372,4 @@ unsafe fn det_sub_proc_unsafe(m: &Matrix4, x: usize, y: usize, tmp -= d.mul_element_wise(h.mul_element_wise(c)); tmp -= g.mul_element_wise(b.mul_element_wise(f)); tmp -} \ No newline at end of file +} diff --git a/src/quaternion.rs b/src/quaternion.rs index c97aea6..384bf1e 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -30,6 +30,8 @@ use point::Point3; use rotation::{Rotation, Rotation3, Basis3}; use vector::Vector3; +#[cfg(feature = "use_simd")] +use simd::f32x4 as Simdf32x4; /// A [quaternion](https://en.wikipedia.org/wiki/Quaternion) in scalar/vector /// form. @@ -46,6 +48,30 @@ pub struct Quaternion { pub v: Vector3, } +#[cfg(feature = "use_simd")] +impl From for Quaternion { + #[inline] + fn from(f: Simdf32x4) -> Self { + unsafe { + let mut ret: Self = mem::uninitialized(); + { + let ret_mut: &mut [f32; 4] = ret.as_mut(); + f.store(ret_mut.as_mut(), 0 as usize); + } + ret + } + } +} + +#[cfg(feature = "use_simd")] +impl Into for Quaternion { + #[inline] + fn into(self) -> Simdf32x4 { + let self_ref: &[f32; 4] = self.as_ref(); + Simdf32x4::load(self_ref.as_ref(), 0 as usize) + } +} + impl Quaternion { /// Construct a new quaternion from one scalar component and three /// imaginary components @@ -73,7 +99,7 @@ impl Quaternion { let mag_avg = (src.magnitude2() * dst.magnitude2()).sqrt(); let dot = src.dot(dst); if ulps_eq!(dot, &mag_avg) { - Quaternion::one() + Quaternion::::one() } else if ulps_eq!(dot, &-mag_avg) { let axis = fallback.unwrap_or_else(|| { let mut v = Vector3::unit_x().cross(src); @@ -151,7 +177,7 @@ impl Zero for Quaternion { #[inline] fn is_zero(&self) -> bool { - ulps_eq!(self, &Quaternion::zero()) + ulps_eq!(self, &Quaternion::::zero()) } } @@ -175,6 +201,7 @@ impl MetricSpace for Quaternion { } } +#[cfg(not(feature = "use_simd"))] impl InnerSpace for Quaternion { #[inline] fn dot(self, other: Quaternion) -> S { @@ -182,6 +209,25 @@ impl InnerSpace for Quaternion { } } +#[cfg(feature = "use_simd")] +impl InnerSpace for Quaternion { + #[inline] + default fn dot(self, other: Quaternion) -> S { + self.s * other.s + self.v.dot(other.v) + } +} + +#[cfg(feature = "use_simd")] +impl InnerSpace for Quaternion { + #[inline] + fn dot(self, other: Quaternion) -> f32 { + let lhs: Simdf32x4 = self.into(); + let rhs: Simdf32x4 = other.into(); + let r = lhs * rhs; + r.extract(0) + r.extract(1) + r.extract(2) + r.extract(3) + } +} + impl From> for Quaternion<::Unitless> where A: Angle + Into::Unitless>>, { @@ -203,35 +249,119 @@ impl From> for Quaternion<::Unitless> where } } +#[cfg(not(feature = "use_simd"))] impl_operator!( Neg for Quaternion { fn neg(quat) -> Quaternion { Quaternion::from_sv(-quat.s, -quat.v) } }); +#[cfg(feature = "use_simd")] +impl_operator_default!( Neg for Quaternion { + fn neg(quat) -> Quaternion { + Quaternion::from_sv(-quat.s, -quat.v) + } +}); + +#[cfg(feature = "use_simd")] +impl_operator_simd!{ + [Simdf32x4]; Neg for Quaternion { + fn neg(lhs) -> Quaternion { + (-lhs).into() + } + } +} + +#[cfg(not(feature = "use_simd"))] impl_operator!( Mul for Quaternion { fn mul(lhs, rhs) -> Quaternion { Quaternion::from_sv(lhs.s * rhs, lhs.v * rhs) } }); + +#[cfg(feature = "use_simd")] +impl_operator_default!( Mul for Quaternion { + fn mul(lhs, rhs) -> Quaternion { + Quaternion::from_sv(lhs.s * rhs, lhs.v * rhs) + } +}); + +#[cfg(feature = "use_simd")] +impl_operator_simd!{@rs + [Simdf32x4]; Mul for Quaternion { + fn mul(lhs, rhs) -> Quaternion { + (lhs * rhs).into() + } + } +} + +#[cfg(not(feature = "use_simd"))] impl_assignment_operator!( MulAssign for Quaternion { fn mul_assign(&mut self, scalar) { self.s *= scalar; self.v *= scalar; } }); +#[cfg(feature = "use_simd")] +impl_assignment_operator_default!( MulAssign for Quaternion { + fn mul_assign(&mut self, scalar) { self.s *= scalar; self.v *= scalar; } +}); + +#[cfg(feature = "use_simd")] +impl MulAssign for Quaternion { + fn mul_assign(&mut self, other: f32) { + let s: Simdf32x4 = (*self).into(); + let other = Simdf32x4::splat(other); + *self = (s * other).into(); + } +} + +#[cfg(not(feature = "use_simd"))] impl_operator!( Div for Quaternion { fn div(lhs, rhs) -> Quaternion { Quaternion::from_sv(lhs.s / rhs, lhs.v / rhs) } }); + +#[cfg(feature = "use_simd")] +impl_operator_default!( Div for Quaternion { + fn div(lhs, rhs) -> Quaternion { + Quaternion::from_sv(lhs.s / rhs, lhs.v / rhs) + } +}); + +#[cfg(feature = "use_simd")] +impl_operator_simd!{@rs + [Simdf32x4]; Div for Quaternion { + fn div(lhs, rhs) -> Quaternion { + (lhs / rhs).into() + } + } +} + +#[cfg(not(feature = "use_simd"))] impl_assignment_operator!( DivAssign for Quaternion { fn div_assign(&mut self, scalar) { self.s /= scalar; self.v /= scalar; } }); +#[cfg(feature = "use_simd")] +impl_assignment_operator_default!( DivAssign for Quaternion { + fn div_assign(&mut self, scalar) { self.s /= scalar; self.v /= scalar; } +}); + +#[cfg(feature = "use_simd")] +impl DivAssign for Quaternion { + fn div_assign(&mut self, other: f32) { + let s: Simdf32x4 = (*self).into(); + let other = Simdf32x4::splat(other); + *self = (s / other).into(); + } +} + impl_operator!( Rem for Quaternion { fn rem(lhs, rhs) -> Quaternion { Quaternion::from_sv(lhs.s % rhs, lhs.v % rhs) } }); + impl_assignment_operator!( RemAssign for Quaternion { fn rem_assign(&mut self, scalar) { self.s %= scalar; self.v %= scalar; } }); @@ -245,24 +375,93 @@ impl_operator!( Mul > for Quaternion { }} }); +#[cfg(not(feature = "use_simd"))] impl_operator!( Add > for Quaternion { fn add(lhs, rhs) -> Quaternion { Quaternion::from_sv(lhs.s + rhs.s, lhs.v + rhs.v) } }); + +#[cfg(feature = "use_simd")] +impl_operator_default!( Add > for Quaternion { + fn add(lhs, rhs) -> Quaternion { + Quaternion::from_sv(lhs.s + rhs.s, lhs.v + rhs.v) + } +}); + +#[cfg(feature = "use_simd")] +impl_operator_simd!{ + [Simdf32x4]; Add> for Quaternion { + fn add(lhs, rhs) -> Quaternion { + (lhs + rhs).into() + } + } +} + +#[cfg(not(feature = "use_simd"))] impl_assignment_operator!( AddAssign > for Quaternion { fn add_assign(&mut self, other) { self.s += other.s; self.v += other.v; } }); +#[cfg(feature = "use_simd")] +impl_assignment_operator_default!( AddAssign > for Quaternion { + fn add_assign(&mut self, other) { self.s += other.s; self.v += other.v; } +}); + +#[cfg(feature = "use_simd")] +impl AddAssign for Quaternion { + #[inline] + fn add_assign(&mut self, rhs: Self) { + let s: Simdf32x4 = (*self).into(); + let rhs: Simdf32x4 = rhs.into(); + *self = (s + rhs).into(); + } +} + +#[cfg(not(feature = "use_simd"))] impl_operator!( Sub > for Quaternion { fn sub(lhs, rhs) -> Quaternion { Quaternion::from_sv(lhs.s - rhs.s, lhs.v - rhs.v) } }); + +#[cfg(feature = "use_simd")] +impl_operator_default!( Sub > for Quaternion { + fn sub(lhs, rhs) -> Quaternion { + Quaternion::from_sv(lhs.s - rhs.s, lhs.v - rhs.v) + } +}); + +#[cfg(feature = "use_simd")] +impl_operator_simd!{ + [Simdf32x4]; Sub> for Quaternion { + fn sub(lhs, rhs) -> Quaternion { + (lhs - rhs).into() + } + } +} + +#[cfg(not(feature = "use_simd"))] impl_assignment_operator!( SubAssign > for Quaternion { fn sub_assign(&mut self, other) { self.s -= other.s; self.v -= other.v; } }); +#[cfg(feature = "use_simd")] +impl_assignment_operator_default!( SubAssign > for Quaternion { + fn sub_assign(&mut self, other) { self.s -= other.s; self.v -= other.v; } +}); + +#[cfg(feature = "use_simd")] +impl SubAssign for Quaternion { + #[inline] + fn sub_assign(&mut self, rhs: Self) { + let s: Simdf32x4 = (*self).into(); + let rhs: Simdf32x4 = rhs.into(); + *self = (s - rhs).into(); + } +} + +#[cfg(not(feature = "use_simd"))] impl_operator!( Mul > for Quaternion { fn mul(lhs, rhs) -> Quaternion { Quaternion::new(lhs.s * rhs.s - lhs.v.x * rhs.v.x - lhs.v.y * rhs.v.y - lhs.v.z * rhs.v.z, @@ -272,6 +471,37 @@ impl_operator!( Mul > for Quaternion { } }); +#[cfg(feature = "use_simd")] +impl_operator_default!( Mul > for Quaternion { + fn mul(lhs, rhs) -> Quaternion { + Quaternion::new(lhs.s * rhs.s - lhs.v.x * rhs.v.x - lhs.v.y * rhs.v.y - lhs.v.z * rhs.v.z, + lhs.s * rhs.v.x + lhs.v.x * rhs.s + lhs.v.y * rhs.v.z - lhs.v.z * rhs.v.y, + lhs.s * rhs.v.y + lhs.v.y * rhs.s + lhs.v.z * rhs.v.x - lhs.v.x * rhs.v.z, + lhs.s * rhs.v.z + lhs.v.z * rhs.s + lhs.v.x * rhs.v.y - lhs.v.y * rhs.v.x) + } +}); + +#[cfg(feature = "use_simd")] +impl_operator_simd!{ + [Simdf32x4]; Mul> for Quaternion { + fn mul(lhs, rhs) -> Quaternion { + { + let p0 = Simdf32x4::splat(lhs.extract(0)) * rhs; + let p1 = Simdf32x4::splat(lhs.extract(1)) * Simdf32x4::new( + -rhs.extract(1), rhs.extract(0), -rhs.extract(3), rhs.extract(2) + ); + let p2 = Simdf32x4::splat(lhs.extract(2)) * Simdf32x4::new( + -rhs.extract(2), rhs.extract(3), rhs.extract(0), -rhs.extract(1) + ); + let p3 = Simdf32x4::splat(lhs.extract(3)) * Simdf32x4::new( + -rhs.extract(3), -rhs.extract(2), rhs.extract(1), rhs.extract(0) + ); + (p0 + p1 + p2 + p3).into() + } + } + } +} + macro_rules! impl_scalar_mul { ($S:ident) => { impl_operator!(Mul> for $S { diff --git a/src/vector.rs b/src/vector.rs index f3828a6..a289614 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -802,6 +802,14 @@ impl Into for Vector4 { } } +#[cfg(feature = "use_simd")] +impl_operator_simd!{ + [Simdf32x4]; Add> for Vector4 { + fn add(lhs, rhs) -> Vector4 { + (lhs + rhs).into() + } + } +} #[cfg(feature = "use_simd")] impl_operator_simd!{ @@ -1050,7 +1058,6 @@ impl Into for Vector4 { } } - #[cfg(feature = "use_simd")] impl_operator_simd!{ [Simdu32x4]; Add> for Vector4 { @@ -1060,15 +1067,6 @@ impl_operator_simd!{ } } -#[cfg(feature = "use_simd")] -impl_operator_simd!{ - [Simdf32x4]; Add> for Vector4 { - fn add(lhs, rhs) -> Vector4 { - (lhs + rhs).into() - } - } -} - #[cfg(feature = "use_simd")] impl_operator_simd!{ [Simdu32x4]; Sub> for Vector4 { diff --git a/tests/vectorf32.rs b/tests/vector4f32.rs similarity index 58% rename from tests/vectorf32.rs rename to tests/vector4f32.rs index fd930e8..b860d76 100644 --- a/tests/vectorf32.rs +++ b/tests/vector4f32.rs @@ -23,15 +23,11 @@ use std::f32; #[test] fn test_constructor() { - assert_eq!(vec2(1f32, 2f32), Vector2::new(1f32, 2f32)); - assert_eq!(vec3(1f32, 2f32, 3f32), Vector3::new(1f32, 2f32, 3f32)); assert_eq!(vec4(1f32, 2f32, 3f32, 4f32), Vector4::new(1f32, 2f32, 3f32, 4f32)); } #[test] fn test_from_value() { - assert_eq!(Vector2::from_value(102f32), Vector2::new(102f32, 102f32)); - assert_eq!(Vector3::from_value(22f32), Vector3::new(22f32, 22f32, 22f32)); assert_eq!(Vector4::from_value(76.5f32), Vector4::new(76.5f32, 76.5f32, 76.5f32, 76.5f32)); } @@ -95,94 +91,58 @@ fn test_add() { #[test] fn test_sub() { impl_test_sub!(Vector4 { x, y, z, w }, 2.0f32, vec4(2.0f32, 4.0f32, 6.0f32, 8.0f32)); - impl_test_sub!(Vector3 { x, y, z }, 2.0f32, vec3(2.0f32, 4.0f32, 6.0f32)); - impl_test_sub!(Vector2 { x, y }, 2.0f32, vec2(2.0f32, 4.0f32)); } #[test] fn test_mul() { impl_test_mul!(Vector4 { x, y, z, w }, 2.0f32, vec4(2.0f32, 4.0f32, 6.0f32, 8.0f32)); - impl_test_mul!(Vector3 { x, y, z }, 2.0f32, vec3(2.0f32, 4.0f32, 6.0f32)); - impl_test_mul!(Vector2 { x, y }, 2.0f32, vec2(2.0f32, 4.0f32)); } #[test] fn test_div() { impl_test_div!(Vector4 { x, y, z, w }, 2.0f32, vec4(2.0f32, 4.0f32, 6.0f32, 8.0f32)); - impl_test_div!(Vector3 { x, y, z }, 2.0f32, vec3(2.0f32, 4.0f32, 6.0f32)); - impl_test_div!(Vector2 { x, y }, 2.0f32, vec2(2.0f32, 4.0f32)); } #[test] fn test_rem() { impl_test_rem!(Vector4 { x, y, z, w }, 2.0f32, vec4(2.0f32, 4.0f32, 6.0f32, 8.0f32)); - impl_test_rem!(Vector3 { x, y, z }, 2.0f32, vec3(2.0f32, 4.0f32, 6.0f32)); - impl_test_rem!(Vector2 { x, y }, 2.0f32, vec2(2.0f32, 4.0f32)); } #[test] fn test_dot() { - assert_eq!(Vector2::new(1.0f32, 2.0f32).dot(Vector2::new(3.0f32, 4.0f32)), 11.0f32); - assert_eq!(Vector3::new(1.0f32, 2.0f32, 3.0f32).dot(Vector3::new(4.0f32, 5.0f32, 6.0f32)), 32.0f32); assert_eq!(Vector4::new(1.0f32, 2.0f32, 3.0f32, 4.0f32).dot(Vector4::new(5.0f32, 6.0f32, 7.0f32, 8.0f32)), 70.0f32); } #[test] fn test_sum() { - assert_eq!(Vector2::new(1f32, 2f32).sum(), 3f32); - assert_eq!(Vector3::new(1f32, 2f32, 3f32).sum(), 6f32); assert_eq!(Vector4::new(1f32, 2f32, 3f32, 4f32).sum(), 10f32); - assert_eq!(Vector2::new(3.0f32, 4.0f32).sum(), 7.0f32); - assert_eq!(Vector3::new(4.0f32, 5.0f32, 6.0f32).sum(), 15.0f32); assert_eq!(Vector4::new(5.0f32, 6.0f32, 7.0f32, 8.0f32).sum(), 26.0f32); } #[test] fn test_product() { - assert_eq!(Vector2::new(1f32, 2f32).product(), 2f32); - assert_eq!(Vector3::new(1f32, 2f32, 3f32).product(), 6f32); assert_eq!(Vector4::new(1f32, 2f32, 3f32, 4f32).product(), 24f32); - assert_eq!(Vector2::new(3.0f32, 4.0f32).product(), 12.0f32); - assert_eq!(Vector3::new(4.0f32, 5.0f32, 6.0f32).product(), 120.0f32); assert_eq!(Vector4::new(5.0f32, 6.0f32, 7.0f32, 8.0f32).product(), 1680.0f32); } #[test] fn test_min() { - assert_eq!(Vector2::new(1f32, 2f32).min(), 1f32); - assert_eq!(Vector3::new(1f32, 2f32, 3f32).min(), 1f32); assert_eq!(Vector4::new(1f32, 2f32, 3f32, 4f32).min(), 1f32); - assert_eq!(Vector2::new(3.0f32, 4.0f32).min(), 3.0f32); - assert_eq!(Vector3::new(4.0f32, 5.0f32, 6.0f32).min(), 4.0f32); assert_eq!(Vector4::new(5.0f32, 6.0f32, 7.0f32, 8.0f32).min(), 5.0f32); } #[test] fn test_max() { - assert_eq!(Vector2::new(1f32, 2f32).max(), 2f32); - assert_eq!(Vector3::new(1f32, 2f32, 3f32).max(), 3f32); assert_eq!(Vector4::new(1f32, 2f32, 3f32, 4f32).max(), 4f32); - assert_eq!(Vector2::new(3.0f32, 4.0f32).max(), 4.0f32); - assert_eq!(Vector3::new(4.0f32, 5.0f32, 6.0f32).max(), 6.0f32); assert_eq!(Vector4::new(5.0f32, 6.0f32, 7.0f32, 8.0f32).max(), 8.0f32); } -#[test] -fn test_cross() { - let a = Vector3::new(1f32, 2f32, 3f32); - let b = Vector3::new(4f32, 5f32, 6f32); - let r = Vector3::new(-3f32, 6f32, -3f32); - assert_eq!(a.cross(b), r); -} - #[test] fn test_is_perpendicular() { - assert!(Vector2::new(1.0f32, 0.0f32).is_perpendicular(Vector2::new(0.0f32, 1.0f32))); - assert!(Vector3::new(0.0f32, 1.0f32, 0.0f32).is_perpendicular(Vector3::new(0.0f32, 0.0f32, 1.0f32))); assert!(Vector4::new(1.0f32, 0.0f32, 0.0f32, 0.0f32).is_perpendicular(Vector4::new(0.0f32, 0.0f32, 0.0f32, 1.0f32))); } @@ -190,30 +150,6 @@ fn test_is_perpendicular() { mod test_magnitude { use cgmath::*; - #[test] - fn test_vector2(){ - let (a, a_res) = (Vector2::new(3.0f32, 4.0f32), 5.0f32); // (3, 4, 5) Pythagorean triple - let (b, b_res) = (Vector2::new(5.0f32, 12.0f32), 13.0f32); // (5, 12, 13) Pythagorean triple - - assert_eq!(a.magnitude2(), a_res * a_res); - assert_eq!(b.magnitude2(), b_res * b_res); - - assert_eq!(a.magnitude(), a_res); - assert_eq!(b.magnitude(), b_res); - } - - #[test] - fn test_vector3(){ - let (a, a_res) = (Vector3::new(2.0f32, 3.0f32, 6.0f32), 7.0f32); // (2, 3, 6, 7) Pythagorean quadruple - let (b, b_res) = (Vector3::new(1.0f32, 4.0f32, 8.0f32), 9.0f32); // (1, 4, 8, 9) Pythagorean quadruple - - assert_eq!(a.magnitude2(), a_res * a_res); - assert_eq!(b.magnitude2(), b_res * b_res); - - assert_eq!(a.magnitude(), a_res); - assert_eq!(b.magnitude(), b_res); - } - #[test] fn test_vector4(){ let (a, a_res) = (Vector4::new(1.0f32, 2.0f32, 4.0f32, 10.0f32), 11.0f32); // (1, 2, 4, 10, 11) Pythagorean quintuple @@ -238,14 +174,6 @@ mod test_magnitude { #[test] fn test_angle() { - assert_ulps_eq!(Vector2::new(1.0f32, 0.0f32).angle(Vector2::new(0.0f32, 1.0f32)), &Rad(f32::consts::FRAC_PI_2)); - assert_ulps_eq!(Vector2::new(10.0f32, 0.0f32).angle(Vector2::new(0.0f32, 5.0f32)), &Rad(f32::consts::FRAC_PI_2)); - assert_ulps_eq!(Vector2::new(-1.0f32, 0.0f32).angle(Vector2::new(0.0f32, 1.0f32)), &-Rad(f32::consts::FRAC_PI_2)); - - assert_ulps_eq!(Vector3::new(1.0f32, 0.0f32, 1.0f32).angle(Vector3::new(1.0f32, 1.0f32, 0.0f32)), &Rad(f32::consts::FRAC_PI_3)); - assert_ulps_eq!(Vector3::new(10.0f32, 0.0f32, 10.0f32).angle(Vector3::new(5.0f32, 5.0f32, 0.0f32)), &Rad(f32::consts::FRAC_PI_3)); - assert_ulps_eq!(Vector3::new(-1.0f32, 0.0f32, -1.0f32).angle(Vector3::new(1.0f32, -1.0f32, 0.0f32)), &Rad(2.0f32 * f32::consts::FRAC_PI_3)); - assert_ulps_eq!(Vector4::new(1.0f32, 0.0f32, 1.0f32, 0.0f32).angle(Vector4::new(0.0f32, 1.0f32, 0.0f32, 1.0f32)), &Rad(f32::consts::FRAC_PI_2)); assert_ulps_eq!(Vector4::new(10.0f32, 0.0f32, 10.0f32, 0.0f32).angle(Vector4::new(0.0f32, 5.0f32, 0.0f32, 5.0f32)), &Rad(f32::consts::FRAC_PI_2)); assert_ulps_eq!(Vector4::new(-1.0f32, 0.0f32, -1.0f32, 0.0f32).angle(Vector4::new(0.0f32, 1.0f32, 0.0f32, 1.0f32)), &Rad(f32::consts::FRAC_PI_2)); @@ -254,14 +182,10 @@ fn test_angle() { #[test] fn test_normalize() { // TODO: test normalize_to, normalize_sel.0f32, and normalize_self_to - assert_ulps_eq!(Vector2::new(3.0f32, 4.0f32).normalize(), &Vector2::new(3.0f32/5.0f32, 4.0f32/5.0f32)); - assert_ulps_eq!(Vector3::new(2.0f32, 3.0f32, 6.0f32).normalize(), &Vector3::new(2.0f32/7.0f32, 3.0f32/7.0f32, 6.0f32/7.0f32)); assert_ulps_eq!(Vector4::new(1.0f32, 2.0f32, 4.0f32, 10.0f32).normalize(), &Vector4::new(1.0f32/11.0f32, 2.0f32/11.0f32, 4.0f32/11.0f32, 10.0f32/11.0f32)); } #[test] fn test_cast() { - assert_ulps_eq!(Vector2::new(0.9f32, 1.5).cast(), Vector2::new(0.9f32, 1.5)); - assert_ulps_eq!(Vector3::new(1.0f32, 2.4, -3.13).cast(), Vector3::new(1.0f32, 2.4, -3.13)); assert_ulps_eq!(Vector4::new(13.5f32, -4.6, -8.3, 2.41).cast(), Vector4::new(13.5f32, -4.6, -8.3, 2.41)); }