Fix to_ptr method impls and use in the index methods where appropriate

This commit is contained in:
Brendan Zabarauskas 2012-12-04 17:50:15 +10:00
parent f9778adf17
commit 969e57591d
3 changed files with 39 additions and 23 deletions

View file

@ -425,7 +425,11 @@ pub impl<T:Copy> Mat2<T>: Index<uint, Vec2<T>> {
pub impl<T:Copy> Mat2<T>: ToPtr<T> {
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
unsafe {
transmute::<*Mat2<T>, *T>(
to_unsafe_ptr(&*self)
)
}
}
}
@ -818,7 +822,11 @@ pub impl<T:Copy> Mat3<T>: Index<uint, Vec3<T>> {
pub impl<T:Copy> Mat3<T>: ToPtr<T> {
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
unsafe {
transmute::<*Mat3<T>, *T>(
to_unsafe_ptr(&*self)
)
}
}
}
@ -1270,7 +1278,11 @@ pub impl<T:Copy> Mat4<T>: Index<uint, Vec4<T>> {
pub impl<T:Copy> Mat4<T>: ToPtr<T> {
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
unsafe {
transmute::<*Mat4<T>, *T>(
to_unsafe_ptr(&*self)
)
}
}
}

View file

@ -142,17 +142,18 @@ pub impl<T> Quat<T>: Dimensional<T> {
pub impl<T:Copy> Quat<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Quat<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
}
}
pub impl<T:Copy> Quat<T>: ToPtr<T> {
#[inline(always)]
pure fn to_ptr(&self) -> *T {
to_unsafe_ptr(&self[0])
unsafe {
transmute::<*Quat<T>, *T>(
to_unsafe_ptr(&*self)
)
}
}
}

View file

@ -180,17 +180,18 @@ pub impl<T> Vec2<T>: Dimensional<T> {
pub impl<T:Copy> Vec2<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Vec2<T>, *T>(
to_unsafe_ptr(&self)), 2) |slice| { slice[i] }
}
unsafe { do buf_as_slice(self.to_ptr(), 2) |slice| { slice[i] } }
}
}
pub impl<T:Copy> Vec2<T>: ToPtr<T> {
#[inline(always)]
pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0])
unsafe {
transmute::<*Vec2<T>, *T>(
to_unsafe_ptr(&*self)
)
}
}
}
@ -342,17 +343,18 @@ pub impl<T> Vec3<T>: Dimensional<T> {
pub impl<T:Copy> Vec3<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Vec3<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } }
}
}
pub impl<T:Copy> Vec3<T>: ToPtr<T> {
#[inline(always)]
pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0])
unsafe {
transmute::<*Vec3<T>, *T>(
to_unsafe_ptr(&*self)
)
}
}
}
@ -522,17 +524,18 @@ pub impl<T> Vec4<T>: Dimensional<T> {
pub impl<T:Copy> Vec4<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Vec4<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
}
}
pub impl<T:Copy> Vec4<T>: ToPtr<T> {
#[inline(always)]
pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0])
unsafe {
transmute::<*Vec4<T>, *T>(
to_unsafe_ptr(&*self)
)
}
}
}