More Into impls converted to From (#529)

* More Into impls converted to From

* Update quaternion.rs
This commit is contained in:
Adam Gausmann 2021-04-20 21:17:06 -05:00 committed by GitHub
parent 81583b2f57
commit ada4add5a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 39 deletions

View file

@ -219,8 +219,8 @@ impl<S, A: Angle + From<S>> From<MintEuler<S>> for Euler<A> {
} }
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
impl<S: Clone, A: Angle + Into<S>> Into<MintEuler<S>> for Euler<A> { impl<S: Clone, A: Angle + Into<S>> From<Euler<A>> for MintEuler<S> {
fn into(self) -> MintEuler<S> { fn from(v: Euler<A>) -> Self {
MintEuler::from([self.x.into(), self.y.into(), self.z.into()]) MintEuler::from([v.x.into(), v.y.into(), v.z.into()])
} }
} }

View file

@ -1153,7 +1153,6 @@ impl<S: BaseFloat> Transform<Point3<S>> for Matrix3<S> {
} }
impl<S: BaseFloat> Transform<Point3<S>> for Matrix4<S> { impl<S: BaseFloat> Transform<Point3<S>> for Matrix4<S> {
fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> { fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
Matrix4::look_at_rh(eye, center, up) Matrix4::look_at_rh(eye, center, up)
} }
@ -1450,10 +1449,10 @@ where
macro_rules! fixed_array_conversions { macro_rules! fixed_array_conversions {
($MatrixN:ident <$S:ident> { $($field:ident : $index:expr),+ }, $n:expr) => { ($MatrixN:ident <$S:ident> { $($field:ident : $index:expr),+ }, $n:expr) => {
impl<$S> Into<[[$S; $n]; $n]> for $MatrixN<$S> { impl<$S> From<$MatrixN<$S>> for [[$S; $n]; $n] {
#[inline] #[inline]
fn into(self) -> [[$S; $n]; $n] { fn from(v: $MatrixN<$S>) -> Self {
match self { $MatrixN { $($field),+ } => [$($field.into()),+] } match v { $MatrixN { $($field),+ } => [$($field.into()),+] }
} }
} }
@ -1546,10 +1545,10 @@ fixed_array_conversions!(Matrix4<S> { x:0, y:1, z:2, w:3 }, 4);
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
macro_rules! mint_conversions { macro_rules! mint_conversions {
($MatrixN:ident { $($field:ident),+ }, $MintN:ident) => { ($MatrixN:ident { $($field:ident),+ }, $MintN:ident) => {
impl<S: Clone> Into<mint::$MintN<S>> for $MatrixN<S> { impl<S: Clone> From<$MatrixN<S>> for mint::$MintN<S> {
#[inline] #[inline]
fn into(self) -> mint::$MintN<S> { fn from(v: $MatrixN<S>) -> Self {
mint::$MintN { $($field: self.$field.into()),+ } mint::$MintN { $($field: v.$field.into()),+ }
} }
} }

View file

@ -538,10 +538,10 @@ impl<S: BaseFloat> Rotation3 for Quaternion<S> {
} }
} }
impl<S: BaseFloat> Into<[S; 4]> for Quaternion<S> { impl<S: BaseFloat> From<Quaternion<S>> for [S; 4] {
#[inline] #[inline]
fn into(self) -> [S; 4] { fn from(v: Quaternion<S>) -> Self {
match self.into() { match v.into() {
(xi, yj, zk, w) => [xi, yj, zk, w], (xi, yj, zk, w) => [xi, yj, zk, w],
} }
} }
@ -582,10 +582,10 @@ impl<'a, S: BaseFloat> From<&'a mut [S; 4]> for &'a mut Quaternion<S> {
} }
} }
impl<S: BaseFloat> Into<(S, S, S, S)> for Quaternion<S> { impl<S: BaseFloat> From<Quaternion<S>> for (S, S, S, S) {
#[inline] #[inline]
fn into(self) -> (S, S, S, S) { fn from(v: Quaternion<S>) -> Self {
match self { match v {
Quaternion { Quaternion {
s, s,
v: Vector3 { x, y, z }, v: Vector3 { x, y, z },
@ -683,11 +683,11 @@ impl<S> From<mint::Quaternion<S>> for Quaternion<S> {
} }
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
impl<S: Clone> Into<mint::Quaternion<S>> for Quaternion<S> { impl<S: Clone> From<Quaternion<S>> for mint::Quaternion<S> {
fn into(self) -> mint::Quaternion<S> { fn from(v: Quaternion<S>) -> Self {
mint::Quaternion { mint::Quaternion {
s: self.s, s: v.s,
v: self.v.into(), v: v.v.into(),
} }
} }
} }
@ -933,7 +933,7 @@ mod tests {
-0.5576775358252053, -0.5576775358252053,
-0.5576775358252053, -0.5576775358252053,
-0.5576775358252053, -0.5576775358252053,
0.2588190451025208 0.2588190451025208,
]); ]);
assert_ulps_eq!(expected, q.slerp(r, 0.25)); assert_ulps_eq!(expected, q.slerp(r, 0.25));
} }

View file

@ -36,11 +36,11 @@ impl From<Simdf32x4> for Quaternion<f32> {
} }
} }
impl Into<Simdf32x4> for Quaternion<f32> { impl From<Quaternion<f32>> for Simdf32x4 {
#[inline] #[inline]
fn into(self) -> Simdf32x4 { fn from(v: Quaternion<f32>) -> Self {
let self_ref: &[f32; 4] = self.as_ref(); let v_ref: &[f32; 4] = v.as_ref();
Simdf32x4::load(self_ref.as_ref(), 0 as usize) Simdf32x4::load(v_ref.as_ref(), 0 as usize)
} }
} }

View file

@ -61,11 +61,11 @@ impl Vector4<f32> {
} }
} }
impl Into<Simdf32x4> for Vector4<f32> { impl From<Vector4<f32>> for Simdf32x4 {
#[inline] #[inline]
fn into(self) -> Simdf32x4 { fn from(v: Vector4<f32>) -> Self {
let self_ref: &[f32; 4] = self.as_ref(); let v_ref: &[f32; 4] = v.as_ref();
Simdf32x4::load(self_ref.as_ref(), 0 as usize) Simdf32x4::load(v_ref.as_ref(), 0 as usize)
} }
} }
@ -254,11 +254,11 @@ impl From<Simdi32x4> for Vector4<i32> {
} }
} }
impl Into<Simdi32x4> for Vector4<i32> { impl From<Vector4<i32>> for Simdi32x4 {
#[inline] #[inline]
fn into(self) -> Simdi32x4 { fn from(v: Vector4<i32>) -> Self {
let self_ref: &[i32; 4] = self.as_ref(); let v_ref: &[i32; 4] = v.as_ref();
Simdi32x4::load(self_ref.as_ref(), 0 as usize) Simdi32x4::load(v_ref.as_ref(), 0 as usize)
} }
} }
@ -334,11 +334,11 @@ impl From<Simdu32x4> for Vector4<u32> {
} }
} }
impl Into<Simdu32x4> for Vector4<u32> { impl From<Vector4<u32>> for Simdu32x4 {
#[inline] #[inline]
fn into(self) -> Simdu32x4 { fn from(v: Vector4<u32>) -> Self {
let self_ref: &[u32; 4] = self.as_ref(); let v_ref: &[u32; 4] = v.as_ref();
Simdu32x4::load(self_ref.as_ref(), 0 as usize) Simdu32x4::load(v_ref.as_ref(), 0 as usize)
} }
} }