removed potentially unsound unsafe code
This commit is contained in:
parent
5a1f9a5236
commit
3235751526
|
@ -113,7 +113,6 @@ where
|
||||||
#[inline]
|
#[inline]
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn slerp(&self, other: &Self, t: T) -> Self {
|
pub fn slerp(&self, other: &Self, t: T) -> Self {
|
||||||
use std::mem::transmute;
|
|
||||||
|
|
||||||
//The best option here would be to use #[feature(specialization)], but until
|
//The best option here would be to use #[feature(specialization)], but until
|
||||||
//that's stabilized, this is the best we can do. Theoretically, the compiler should
|
//that's stabilized, this is the best we can do. Theoretically, the compiler should
|
||||||
|
@ -124,21 +123,30 @@ where
|
||||||
//FIXME: this doesn't really work in 1D since we can't interp between -1 and 1
|
//FIXME: this doesn't really work in 1D since we can't interp between -1 and 1
|
||||||
1 => self.clone(),
|
1 => self.clone(),
|
||||||
|
|
||||||
//NOTE: Not pretty, but without refactoring the API, this is the best we can do
|
2 => {
|
||||||
//NOTE: This is safe because we directly check the dimension first
|
let self2d = Rotation2::from_matrix_unchecked(
|
||||||
2 => unsafe {
|
self.clone().into_inner().fixed_resize(T::zero())
|
||||||
let (self2d, other2d) = (
|
|
||||||
transmute::<&Self, &Rotation2<T>>(self),
|
|
||||||
transmute::<&Self, &Rotation2<T>>(other),
|
|
||||||
);
|
);
|
||||||
transmute::<&Rotation2<T>, &Self>(&self2d.slerp_2d(other2d, t)).clone()
|
let other2d = Rotation2::from_matrix_unchecked(
|
||||||
|
other.clone().into_inner().fixed_resize(T::zero())
|
||||||
|
);
|
||||||
|
|
||||||
|
Self::from_matrix_unchecked(
|
||||||
|
self2d.slerp_2d(&other2d, t).into_inner().fixed_resize(T::zero())
|
||||||
|
)
|
||||||
},
|
},
|
||||||
3 => unsafe {
|
|
||||||
let (self3d, other3d) = (
|
3 => {
|
||||||
transmute::<&Self, &Rotation3<T>>(self),
|
let self3d = Rotation3::from_matrix_unchecked(
|
||||||
transmute::<&Self, &Rotation3<T>>(other),
|
self.clone().into_inner().fixed_resize(T::zero())
|
||||||
);
|
);
|
||||||
transmute::<&Rotation3<T>, &Self>(&self3d.slerp_3d(other3d, t)).clone()
|
let other3d = Rotation3::from_matrix_unchecked(
|
||||||
|
other.clone().into_inner().fixed_resize(T::zero())
|
||||||
|
);
|
||||||
|
|
||||||
|
Self::from_matrix_unchecked(
|
||||||
|
self3d.slerp_3d(&other3d, t).into_inner().fixed_resize(T::zero())
|
||||||
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
//the multiplication order matters here
|
//the multiplication order matters here
|
||||||
|
|
Loading…
Reference in New Issue