Merge pull request #196 from kvark/index

Fixed Index implementations
This commit is contained in:
Dzmitry Malyshau 2015-03-25 22:24:52 -04:00
commit 104742c8a4
8 changed files with 36 additions and 32 deletions

View file

@ -1,7 +1,7 @@
[package]
name = "cgmath"
version = "0.1.0"
version = "0.1.1"
authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>",
"Brian Heylin",
"Colin Sherratt",
@ -20,6 +20,8 @@ repository="https://github.com/bjz/cgmath-rs"
[lib]
name = "cgmath"
[dependencies.rustc-serialize]
rustc_serialize = "*"
[dependencies]
rustc-serialize="*"
rand = "*"

View file

@ -31,7 +31,7 @@
//! `look_at`, `from_angle`, `from_euler`, and `from_axis_angle` methods.
//! These are provided for convenience.
extern crate "rustc-serialize" as rustc_serialize;
extern crate rustc_serialize;
extern crate rand;
// Re-exports

View file

@ -545,15 +545,15 @@ impl<S> Index<usize> for Matrix2<S> {
type Output = Vector2<S>;
#[inline]
fn index<'a>(&'a self, i: &usize) -> &'a Vector2<S> {
FixedArray::from_fixed_ref(&self.as_fixed()[*i])
fn index<'a>(&'a self, i: usize) -> &'a Vector2<S> {
FixedArray::from_fixed_ref(&self.as_fixed()[i])
}
}
impl<S> IndexMut<usize> for Matrix2<S> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut Vector2<S> {
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[*i])
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vector2<S> {
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[i])
}
}
@ -627,15 +627,15 @@ impl<S> Index<usize> for Matrix3<S> {
type Output = Vector3<S>;
#[inline]
fn index<'a>(&'a self, i: &usize) -> &'a Vector3<S> {
FixedArray::from_fixed_ref(&self.as_fixed()[*i])
fn index<'a>(&'a self, i: usize) -> &'a Vector3<S> {
FixedArray::from_fixed_ref(&self.as_fixed()[i])
}
}
impl<S> IndexMut<usize> for Matrix3<S> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut Vector3<S> {
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[*i])
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vector3<S> {
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[i])
}
}
@ -714,15 +714,15 @@ impl<S> Index<usize> for Matrix4<S> {
type Output = Vector4<S>;
#[inline]
fn index<'a>(&'a self, i: &usize) -> &'a Vector4<S> {
FixedArray::from_fixed_ref(&self.as_fixed()[*i])
fn index<'a>(&'a self, i: usize) -> &'a Vector4<S> {
FixedArray::from_fixed_ref(&self.as_fixed()[i])
}
}
impl<S> IndexMut<usize> for Matrix4<S> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut Vector4<S> {
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[*i])
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vector4<S> {
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[i])
}
}

View file

@ -147,15 +147,15 @@ impl<S> FixedArray<[S; 2]> for Point2<S> {
impl<S: BaseNum> Index<usize> for Point2<S> {
type Output = S;
#[inline]
fn index<'a>(&'a self, i: &usize) -> &'a S {
&self.as_fixed()[*i]
fn index<'a>(&'a self, i: usize) -> &'a S {
&self.as_fixed()[i]
}
}
impl<S: BaseNum> IndexMut<usize> for Point2<S> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut S {
&mut self.as_mut_fixed()[*i]
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut S {
&mut self.as_mut_fixed()[i]
}
}
@ -303,15 +303,15 @@ impl<S: BaseNum> Index<usize> for Point3<S> {
type Output = S;
#[inline]
fn index<'a>(&'a self, i: &usize) -> &'a S {
&self.as_fixed()[*i]
fn index<'a>(&'a self, i: usize) -> &'a S {
&self.as_fixed()[i]
}
}
impl<S: BaseNum> IndexMut<usize> for Point3<S> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut S {
&mut self.as_mut_fixed()[*i]
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut S {
&mut self.as_mut_fixed()[i]
}
}

View file

@ -57,17 +57,17 @@ impl<S: BaseFloat> Index<usize> for Quaternion<S> {
type Output = S;
#[inline]
fn index<'a>(&'a self, i: &usize) -> &'a S {
fn index<'a>(&'a self, i: usize) -> &'a S {
let slice: &[S; 4] = unsafe { mem::transmute(self) };
&slice[*i]
&slice[i]
}
}
impl<S: BaseFloat> IndexMut<usize> for Quaternion<S> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut S {
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut S {
let slice: &'a mut [S; 4] = unsafe { mem::transmute(self) };
&mut slice[*i]
&mut slice[i]
}
}

View file

@ -133,6 +133,7 @@ pub trait Rotation3<S: BaseNum>: Rotation<S, Vector3<S>, Point3<S>>
/// matrix:
///
/// ```no_run
/// #![feature(core)]
/// use cgmath::rad;
/// use cgmath::Vector2;
/// use cgmath::{Matrix, ToMatrix2};

View file

@ -267,15 +267,15 @@ macro_rules! vec(
type Output = S;
#[inline]
fn index<'a>(&'a self, i: &usize) -> &'a $S {
&self.as_fixed()[*i]
fn index<'a>(&'a self, i: usize) -> &'a $S {
&self.as_fixed()[i]
}
}
impl<$S: Copy> IndexMut<usize> for $Self_<$S> {
#[inline]
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut $S {
&mut self.as_mut_fixed()[*i]
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut $S {
&mut self.as_mut_fixed()[i]
}
}

View file

@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#![feature(core)]
extern crate cgmath;