From a467bf7032fc4baa99155ce925ce19c071f6c7ea Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 28 Mar 2013 17:33:39 -0700 Subject: [PATCH 1/3] Update index impls. --- src/mat2.rs | 4 ++-- src/mat3.rs | 4 ++-- src/mat4.rs | 4 ++-- src/quat.rs | 4 ++-- src/vec2.rs | 4 ++-- src/vec3.rs | 4 ++-- src/vec4.rs | 4 ++-- 7 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/mat2.rs b/src/mat2.rs index 75efda0..e26db40 100644 --- a/src/mat2.rs +++ b/src/mat2.rs @@ -381,10 +381,10 @@ impl + Add + Sub + Mul + Div + N impl Index> for Mat2 { #[inline(always)] - fn index(&self, i: &uint) -> Vec2 { + fn index(&self, i: uint) -> Vec2 { unsafe { do buf_as_slice( transmute::<*Mat2, *Vec2>( - to_unsafe_ptr(self)), 2) |slice| { slice[*i] } + to_unsafe_ptr(self)), 2) |slice| { slice[i] } } } } diff --git a/src/mat3.rs b/src/mat3.rs index c2453f5..cbf37e9 100644 --- a/src/mat3.rs +++ b/src/mat3.rs @@ -558,10 +558,10 @@ impl + Add + Sub + Mul + Div + N impl Index> for Mat3 { #[inline(always)] - fn index(&self, i: &uint) -> Vec3 { + fn index(&self, i: uint) -> Vec3 { unsafe { do buf_as_slice( transmute::<*Mat3, *Vec3>( - to_unsafe_ptr(self)), 3) |slice| { slice[*i] } + to_unsafe_ptr(self)), 3) |slice| { slice[i] } } } } diff --git a/src/mat4.rs b/src/mat4.rs index 675da03..70bd87f 100644 --- a/src/mat4.rs +++ b/src/mat4.rs @@ -501,10 +501,10 @@ impl + Add + Sub + Mul + Div + N impl Index> for Mat4 { #[inline(always)] - fn index(&self, i: &uint) -> Vec4 { + fn index(&self, i: uint) -> Vec4 { unsafe { do buf_as_slice( transmute::<*Mat4, *Vec4>( - to_unsafe_ptr(self)), 4) |slice| { slice[*i] } + to_unsafe_ptr(self)), 4) |slice| { slice[i] } } } } diff --git a/src/quat.rs b/src/quat.rs index d1da1bd..aa81537 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -391,10 +391,10 @@ pub impl + Add + Sub + Mul + Div impl Index for Quat { #[inline(always)] - fn index(&self, i: &uint) -> T { + fn index(&self, i: uint) -> T { unsafe { do buf_as_slice( transmute::<*Quat, *T>( - to_unsafe_ptr(self)), 4) |slice| { slice[*i] } + to_unsafe_ptr(self)), 4) |slice| { slice[i] } } } } diff --git a/src/vec2.rs b/src/vec2.rs index 5f8dc26..7fa4ba5 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -68,8 +68,8 @@ impl Vector2 for Vec2 { impl Index for Vec2 { #[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] } } } } diff --git a/src/vec3.rs b/src/vec3.rs index 2318e94..c0bf8f7 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -70,8 +70,8 @@ impl Vector3 for Vec3 { impl Index for Vec3 { #[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] } } } } diff --git a/src/vec4.rs b/src/vec4.rs index 2825b46..2fae8c4 100644 --- a/src/vec4.rs +++ b/src/vec4.rs @@ -68,8 +68,8 @@ impl Vector4 for Vec4 { impl Index for Vec4 { #[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] } } } } From 062a5126e449dc4a9e61512b15535e08fe686b71 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 28 Mar 2013 18:24:35 -0700 Subject: [PATCH 2/3] Workaround conflicting loans when using util::swap. --- src/lmath.rc | 2 +- src/mat.rs | 2 +- src/mat2.rs | 3 +-- src/mat3.rs | 15 +++++++-------- src/mat4.rs | 27 +++++++++++++-------------- src/vec2.rs | 3 +-- src/vec3.rs | 3 +-- src/vec4.rs | 3 +-- 8 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/lmath.rc b/src/lmath.rc index f5d9b44..4c369a3 100644 --- a/src/lmath.rc +++ b/src/lmath.rc @@ -28,4 +28,4 @@ mod test { #[path = "test_mat.rs" ] mod mat; #[path = "test_quat.rs"] mod quat; #[path = "test_vec.rs" ] mod vec; -} \ No newline at end of file +} diff --git a/src/mat.rs b/src/mat.rs index 5db0a8f..24d0a43 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -300,4 +300,4 @@ pub trait MutableMatrix: Matrix { * Sets the matrix to its transpose */ fn transpose_self(&mut self); -} \ No newline at end of file +} diff --git a/src/mat2.rs b/src/mat2.rs index e26db40..1e4de51 100644 --- a/src/mat2.rs +++ b/src/mat2.rs @@ -220,8 +220,7 @@ impl + Add + Sub + Mul + Div + 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)] diff --git a/src/mat3.rs b/src/mat3.rs index cbf37e9..6837e69 100644 --- a/src/mat3.rs +++ b/src/mat3.rs @@ -488,8 +488,7 @@ impl + Add + Sub + Mul + Div + 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,14 +544,14 @@ impl + Add + Sub + Mul + Div + 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); } } diff --git a/src/mat4.rs b/src/mat4.rs index 70bd87f..5ea6ba0 100644 --- a/src/mat4.rs +++ b/src/mat4.rs @@ -413,8 +413,7 @@ impl + Add + Sub + Mul + Div + 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 +473,21 @@ impl + Add + Sub + Mul + Div + 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); } } diff --git a/src/vec2.rs b/src/vec2.rs index 7fa4ba5..771a774 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -85,8 +85,7 @@ impl MutableVector for Vec2 { #[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); } } diff --git a/src/vec3.rs b/src/vec3.rs index c0bf8f7..ac44969 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -88,8 +88,7 @@ impl MutableVector for Vec3 { #[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); } } diff --git a/src/vec4.rs b/src/vec4.rs index 2fae8c4..f9b5c4e 100644 --- a/src/vec4.rs +++ b/src/vec4.rs @@ -87,8 +87,7 @@ impl MutableVector for Vec4 { #[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); } } From 6b0711fe635058e333e02d732ca73f6bcb0f8373 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 28 Mar 2013 18:30:47 -0700 Subject: [PATCH 3/3] Unused imports. --- src/mat3.rs | 1 - src/mat4.rs | 1 - src/vec2.rs | 1 - src/vec3.rs | 1 - src/vec4.rs | 1 - 5 files changed, 5 deletions(-) diff --git a/src/mat3.rs b/src/mat3.rs index 6837e69..05b7ddf 100644 --- a/src/mat3.rs +++ b/src/mat3.rs @@ -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; diff --git a/src/mat4.rs b/src/mat4.rs index 5ea6ba0..be0bdb3 100644 --- a/src/mat4.rs +++ b/src/mat4.rs @@ -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; diff --git a/src/vec2.rs b/src/vec2.rs index 771a774..02efe4e 100644 --- a/src/vec2.rs +++ b/src/vec2.rs @@ -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}; diff --git a/src/vec3.rs b/src/vec3.rs index ac44969..42d898e 100644 --- a/src/vec3.rs +++ b/src/vec3.rs @@ -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}; diff --git a/src/vec4.rs b/src/vec4.rs index f9b5c4e..a183175 100644 --- a/src/vec4.rs +++ b/src/vec4.rs @@ -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};