Merge pull request #11 from luqmana/rescue-mission

Rescue mission
This commit is contained in:
Brendan Zabarauskas 2013-03-28 18:44:40 -07:00
commit 0285bf5098
9 changed files with 40 additions and 51 deletions

View file

@ -28,4 +28,4 @@ mod test {
#[path = "test_mat.rs" ] mod mat;
#[path = "test_quat.rs"] mod quat;
#[path = "test_vec.rs" ] mod vec;
}
}

View file

@ -300,4 +300,4 @@ pub trait MutableMatrix<T,V>: Matrix<T,V> {
* Sets the matrix to its transpose
*/
fn transpose_self(&mut self);
}
}

View file

@ -220,8 +220,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
#[inline(always)]
fn swap_cols(&mut self, a: uint, b: uint) {
swap(self.col_mut(a),
self.col_mut(b));
*self.col_mut(a) <-> *self.col_mut(b);
}
#[inline(always)]
@ -381,10 +380,10 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
#[inline(always)]
fn index(&self, i: &uint) -> Vec2<T> {
fn index(&self, i: uint) -> Vec2<T> {
unsafe { do buf_as_slice(
transmute::<*Mat2<T>, *Vec2<T>>(
to_unsafe_ptr(self)), 2) |slice| { slice[*i] }
to_unsafe_ptr(self)), 2) |slice| { slice[i] }
}
}
}

View file

@ -1,7 +1,6 @@
use core::cast::transmute;
use core::cmp::Eq;
use core::ptr::to_unsafe_ptr;
use core::util::swap;
use core::sys::size_of;
use core::vec::raw::buf_as_slice;
@ -488,8 +487,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
#[inline(always)]
fn swap_cols(&mut self, a: uint, b: uint) {
swap(self.col_mut(a),
self.col_mut(b));
*self.col_mut(a) <-> *self.col_mut(b);
}
#[inline(always)]
@ -545,23 +543,23 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
#[inline(always)]
fn transpose_self(&mut self) {
swap(self.col_mut(0).index_mut(1), self.col_mut(1).index_mut(0));
swap(self.col_mut(0).index_mut(2), self.col_mut(2).index_mut(0));
*self.col_mut(0).index_mut(1) <-> *self.col_mut(1).index_mut(0);
*self.col_mut(0).index_mut(2) <-> *self.col_mut(2).index_mut(0);
swap(self.col_mut(1).index_mut(0), self.col_mut(0).index_mut(1));
swap(self.col_mut(1).index_mut(2), self.col_mut(2).index_mut(1));
*self.col_mut(1).index_mut(0) <-> *self.col_mut(0).index_mut(1);
*self.col_mut(1).index_mut(2) <-> *self.col_mut(2).index_mut(1);
swap(self.col_mut(2).index_mut(0), self.col_mut(0).index_mut(2));
swap(self.col_mut(2).index_mut(1), self.col_mut(1).index_mut(2));
*self.col_mut(2).index_mut(0) <-> *self.col_mut(0).index_mut(2);
*self.col_mut(2).index_mut(1) <-> *self.col_mut(1).index_mut(2);
}
}
impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
#[inline(always)]
fn index(&self, i: &uint) -> Vec3<T> {
fn index(&self, i: uint) -> Vec3<T> {
unsafe { do buf_as_slice(
transmute::<*Mat3<T>, *Vec3<T>>(
to_unsafe_ptr(self)), 3) |slice| { slice[*i] }
to_unsafe_ptr(self)), 3) |slice| { slice[i] }
}
}
}

View file

@ -1,7 +1,6 @@
use core::cast::transmute;
use core::cmp::Eq;
use core::ptr::to_unsafe_ptr;
use core::util::swap;
use core::sys::size_of;
use core::vec::raw::buf_as_slice;
@ -413,8 +412,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
#[inline(always)]
fn swap_cols(&mut self, a: uint, b: uint) {
swap(self.col_mut(a),
self.col_mut(b));
*self.col_mut(a) <-> *self.col_mut(b);
}
#[inline(always)]
@ -474,21 +472,21 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
#[inline(always)]
fn transpose_self(&mut self) {
swap(self.col_mut(0).index_mut(1), self.col_mut(1).index_mut(0));
swap(self.col_mut(0).index_mut(2), self.col_mut(2).index_mut(0));
swap(self.col_mut(0).index_mut(3), self.col_mut(3).index_mut(0));
*self.col_mut(0).index_mut(1) <-> *self.col_mut(1).index_mut(0);
*self.col_mut(0).index_mut(2) <-> *self.col_mut(2).index_mut(0);
*self.col_mut(0).index_mut(3) <-> *self.col_mut(3).index_mut(0);
swap(self.col_mut(1).index_mut(0), self.col_mut(0).index_mut(1));
swap(self.col_mut(1).index_mut(2), self.col_mut(2).index_mut(1));
swap(self.col_mut(1).index_mut(3), self.col_mut(3).index_mut(1));
*self.col_mut(1).index_mut(0) <-> *self.col_mut(0).index_mut(1);
*self.col_mut(1).index_mut(2) <-> *self.col_mut(2).index_mut(1);
*self.col_mut(1).index_mut(3) <-> *self.col_mut(3).index_mut(1);
swap(self.col_mut(2).index_mut(0), self.col_mut(0).index_mut(2));
swap(self.col_mut(2).index_mut(1), self.col_mut(1).index_mut(2));
swap(self.col_mut(2).index_mut(3), self.col_mut(3).index_mut(2));
*self.col_mut(2).index_mut(0) <-> *self.col_mut(0).index_mut(2);
*self.col_mut(2).index_mut(1) <-> *self.col_mut(1).index_mut(2);
*self.col_mut(2).index_mut(3) <-> *self.col_mut(3).index_mut(2);
swap(self.col_mut(3).index_mut(0), self.col_mut(0).index_mut(3));
swap(self.col_mut(3).index_mut(1), self.col_mut(1).index_mut(3));
swap(self.col_mut(3).index_mut(2), self.col_mut(2).index_mut(3));
*self.col_mut(3).index_mut(0) <-> *self.col_mut(0).index_mut(3);
*self.col_mut(3).index_mut(1) <-> *self.col_mut(1).index_mut(3);
*self.col_mut(3).index_mut(2) <-> *self.col_mut(2).index_mut(3);
}
}
@ -501,10 +499,10 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
#[inline(always)]
fn index(&self, i: &uint) -> Vec4<T> {
fn index(&self, i: uint) -> Vec4<T> {
unsafe { do buf_as_slice(
transmute::<*Mat4<T>, *Vec4<T>>(
to_unsafe_ptr(self)), 4) |slice| { slice[*i] }
to_unsafe_ptr(self)), 4) |slice| { slice[i] }
}
}
}

View file

@ -391,10 +391,10 @@ pub impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T>
impl<T:Copy> Index<uint, T> for Quat<T> {
#[inline(always)]
fn index(&self, i: &uint) -> T {
fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Quat<T>, *T>(
to_unsafe_ptr(self)), 4) |slice| { slice[*i] }
to_unsafe_ptr(self)), 4) |slice| { slice[i] }
}
}
}

View file

@ -2,7 +2,6 @@ use core::cast::transmute;
use core::cmp::{Eq, Ord};
use core::ptr::to_unsafe_ptr;
use core::sys::size_of;
use core::util::swap;
use core::vec::raw::buf_as_slice;
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
@ -68,8 +67,8 @@ impl<T> Vector2<T> for Vec2<T> {
impl<T:Copy + Eq> Index<uint, T> for Vec2<T> {
#[inline(always)]
fn index(&self, i: &uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 2) |slice| { slice[*i] } }
fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 2) |slice| { slice[i] } }
}
}
@ -85,8 +84,7 @@ impl<T:Copy> MutableVector<T> for Vec2<T> {
#[inline(always)]
fn swap(&mut self, a: uint, b: uint) {
swap(self.index_mut(a),
self.index_mut(b));
*self.index_mut(a) <-> *self.index_mut(b);
}
}

View file

@ -2,7 +2,6 @@ use core::cast::transmute;
use core::cmp::{Eq, Ord};
use core::ptr::to_unsafe_ptr;
use core::sys::size_of;
use core::util::swap;
use core::vec::raw::buf_as_slice;
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
@ -70,8 +69,8 @@ impl<T> Vector3<T> for Vec3<T> {
impl<T:Copy + Eq> Index<uint, T> for Vec3<T> {
#[inline(always)]
fn index(&self, i: &uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[*i] } }
fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } }
}
}
@ -88,8 +87,7 @@ impl<T:Copy> MutableVector<T> for Vec3<T> {
#[inline(always)]
fn swap(&mut self, a: uint, b: uint) {
swap(self.index_mut(a),
self.index_mut(b));
*self.index_mut(a) <-> *self.index_mut(b);
}
}

View file

@ -2,7 +2,6 @@ use core::cast::transmute;
use core::cmp::{Eq, Ord};
use core::ptr::to_unsafe_ptr;
use core::sys::size_of;
use core::util::swap;
use core::vec::raw::buf_as_slice;
use std::cmp::{FuzzyEq, FUZZY_EPSILON};
@ -68,8 +67,8 @@ impl<T> Vector4<T> for Vec4<T> {
impl<T:Copy + Eq> Index<uint, T> for Vec4<T> {
#[inline(always)]
fn index(&self, i: &uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[*i] } }
fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
}
}
@ -87,8 +86,7 @@ impl<T:Copy> MutableVector<T> for Vec4<T> {
#[inline(always)]
fn swap(&mut self, a: uint, b: uint) {
swap(self.index_mut(a),
self.index_mut(b));
*self.index_mut(a) <-> *self.index_mut(b);
}
}