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")]
impl<S: Clone, A: Angle + Into<S>> Into<MintEuler<S>> for Euler<A> {
fn into(self) -> MintEuler<S> {
MintEuler::from([self.x.into(), self.y.into(), self.z.into()])
impl<S: Clone, A: Angle + Into<S>> From<Euler<A>> for MintEuler<S> {
fn from(v: Euler<A>) -> Self {
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> {
fn look_at(eye: Point3<S>, center: Point3<S>, up: Vector3<S>) -> Matrix4<S> {
Matrix4::look_at_rh(eye, center, up)
}
@ -1450,10 +1449,10 @@ where
macro_rules! fixed_array_conversions {
($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]
fn into(self) -> [[$S; $n]; $n] {
match self { $MatrixN { $($field),+ } => [$($field.into()),+] }
fn from(v: $MatrixN<$S>) -> Self {
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")]
macro_rules! mint_conversions {
($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]
fn into(self) -> mint::$MintN<S> {
mint::$MintN { $($field: self.$field.into()),+ }
fn from(v: $MatrixN<S>) -> Self {
mint::$MintN { $($field: v.$field.into()),+ }
}
}

View file

@ -106,7 +106,7 @@ impl<S: BaseFloat> Quaternion<S> {
}
/// Do a normalized linear interpolation with `other`, by `amount`.
///
///
/// This takes the shortest path, so if the quaternions have a negative
/// dot product, the interpolation will be between `self` and `-other`.
pub fn nlerp(self, mut other: Quaternion<S>, amount: S) -> Quaternion<S> {
@ -121,7 +121,7 @@ impl<S: BaseFloat> Quaternion<S> {
///
/// Return the spherical linear interpolation between the quaternion and
/// `other`. Both quaternions should be normalized first.
///
///
/// This takes the shortest path, so if the quaternions have a negative
/// dot product, the interpolation will be between `self` and `-other`.
///
@ -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]
fn into(self) -> [S; 4] {
match self.into() {
fn from(v: Quaternion<S>) -> Self {
match v.into() {
(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]
fn into(self) -> (S, S, S, S) {
match self {
fn from(v: Quaternion<S>) -> Self {
match v {
Quaternion {
s,
v: Vector3 { x, y, z },
@ -683,11 +683,11 @@ impl<S> From<mint::Quaternion<S>> for Quaternion<S> {
}
#[cfg(feature = "mint")]
impl<S: Clone> Into<mint::Quaternion<S>> for Quaternion<S> {
fn into(self) -> mint::Quaternion<S> {
impl<S: Clone> From<Quaternion<S>> for mint::Quaternion<S> {
fn from(v: Quaternion<S>) -> Self {
mint::Quaternion {
s: self.s,
v: self.v.into(),
s: v.s,
v: v.v.into(),
}
}
}
@ -933,7 +933,7 @@ mod tests {
-0.5576775358252053,
-0.5576775358252053,
-0.5576775358252053,
0.2588190451025208
0.2588190451025208,
]);
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]
fn into(self) -> Simdf32x4 {
let self_ref: &[f32; 4] = self.as_ref();
Simdf32x4::load(self_ref.as_ref(), 0 as usize)
fn from(v: Quaternion<f32>) -> Self {
let v_ref: &[f32; 4] = v.as_ref();
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]
fn into(self) -> Simdf32x4 {
let self_ref: &[f32; 4] = self.as_ref();
Simdf32x4::load(self_ref.as_ref(), 0 as usize)
fn from(v: Vector4<f32>) -> Self {
let v_ref: &[f32; 4] = v.as_ref();
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]
fn into(self) -> Simdi32x4 {
let self_ref: &[i32; 4] = self.as_ref();
Simdi32x4::load(self_ref.as_ref(), 0 as usize)
fn from(v: Vector4<i32>) -> Self {
let v_ref: &[i32; 4] = v.as_ref();
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]
fn into(self) -> Simdu32x4 {
let self_ref: &[u32; 4] = self.as_ref();
Simdu32x4::load(self_ref.as_ref(), 0 as usize)
fn from(v: Vector4<u32>) -> Self {
let v_ref: &[u32; 4] = v.as_ref();
Simdu32x4::load(v_ref.as_ref(), 0 as usize)
}
}