Fixed Index implementations
This commit is contained in:
parent
182f7b41dc
commit
05c4147cec
6 changed files with 34 additions and 32 deletions
|
@ -1,7 +1,7 @@
|
||||||
[package]
|
[package]
|
||||||
|
|
||||||
name = "cgmath"
|
name = "cgmath"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>",
|
authors = ["Brendan Zabarauskas <bjzaba@yahoo.com.au>",
|
||||||
"Brian Heylin",
|
"Brian Heylin",
|
||||||
"Colin Sherratt",
|
"Colin Sherratt",
|
||||||
|
@ -20,6 +20,8 @@ repository="https://github.com/bjz/cgmath-rs"
|
||||||
[lib]
|
[lib]
|
||||||
name = "cgmath"
|
name = "cgmath"
|
||||||
|
|
||||||
|
[dependencies.rustc-serialize]
|
||||||
|
rustc_serialize = "*"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rustc-serialize="*"
|
rand = "*"
|
||||||
rand="*"
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
//! `look_at`, `from_angle`, `from_euler`, and `from_axis_angle` methods.
|
//! `look_at`, `from_angle`, `from_euler`, and `from_axis_angle` methods.
|
||||||
//! These are provided for convenience.
|
//! These are provided for convenience.
|
||||||
|
|
||||||
extern crate "rustc-serialize" as rustc_serialize;
|
extern crate rustc_serialize;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
|
|
||||||
// Re-exports
|
// Re-exports
|
||||||
|
|
|
@ -545,15 +545,15 @@ impl<S> Index<usize> for Matrix2<S> {
|
||||||
type Output = Vector2<S>;
|
type Output = Vector2<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &usize) -> &'a Vector2<S> {
|
fn index<'a>(&'a self, i: usize) -> &'a Vector2<S> {
|
||||||
FixedArray::from_fixed_ref(&self.as_fixed()[*i])
|
FixedArray::from_fixed_ref(&self.as_fixed()[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> IndexMut<usize> for Matrix2<S> {
|
impl<S> IndexMut<usize> for Matrix2<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut Vector2<S> {
|
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vector2<S> {
|
||||||
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[*i])
|
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>;
|
type Output = Vector3<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &usize) -> &'a Vector3<S> {
|
fn index<'a>(&'a self, i: usize) -> &'a Vector3<S> {
|
||||||
FixedArray::from_fixed_ref(&self.as_fixed()[*i])
|
FixedArray::from_fixed_ref(&self.as_fixed()[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> IndexMut<usize> for Matrix3<S> {
|
impl<S> IndexMut<usize> for Matrix3<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut Vector3<S> {
|
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vector3<S> {
|
||||||
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[*i])
|
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>;
|
type Output = Vector4<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &usize) -> &'a Vector4<S> {
|
fn index<'a>(&'a self, i: usize) -> &'a Vector4<S> {
|
||||||
FixedArray::from_fixed_ref(&self.as_fixed()[*i])
|
FixedArray::from_fixed_ref(&self.as_fixed()[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> IndexMut<usize> for Matrix4<S> {
|
impl<S> IndexMut<usize> for Matrix4<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &usize) -> &'a mut Vector4<S> {
|
fn index_mut<'a>(&'a mut self, i: usize) -> &'a mut Vector4<S> {
|
||||||
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[*i])
|
FixedArray::from_fixed_mut(&mut self.as_mut_fixed()[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/point.rs
16
src/point.rs
|
@ -147,15 +147,15 @@ impl<S> FixedArray<[S; 2]> for Point2<S> {
|
||||||
impl<S: BaseNum> Index<usize> for Point2<S> {
|
impl<S: BaseNum> Index<usize> for Point2<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &usize) -> &'a S {
|
fn index<'a>(&'a self, i: usize) -> &'a S {
|
||||||
&self.as_fixed()[*i]
|
&self.as_fixed()[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseNum> IndexMut<usize> for Point2<S> {
|
impl<S: BaseNum> IndexMut<usize> for Point2<S> {
|
||||||
#[inline]
|
#[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 {
|
||||||
&mut self.as_mut_fixed()[*i]
|
&mut self.as_mut_fixed()[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -303,15 +303,15 @@ impl<S: BaseNum> Index<usize> for Point3<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &usize) -> &'a S {
|
fn index<'a>(&'a self, i: usize) -> &'a S {
|
||||||
&self.as_fixed()[*i]
|
&self.as_fixed()[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseNum> IndexMut<usize> for Point3<S> {
|
impl<S: BaseNum> IndexMut<usize> for Point3<S> {
|
||||||
#[inline]
|
#[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 {
|
||||||
&mut self.as_mut_fixed()[*i]
|
&mut self.as_mut_fixed()[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,17 +57,17 @@ impl<S: BaseFloat> Index<usize> for Quaternion<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[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) };
|
let slice: &[S; 4] = unsafe { mem::transmute(self) };
|
||||||
&slice[*i]
|
&slice[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> IndexMut<usize> for Quaternion<S> {
|
impl<S: BaseFloat> IndexMut<usize> for Quaternion<S> {
|
||||||
#[inline]
|
#[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) };
|
let slice: &'a mut [S; 4] = unsafe { mem::transmute(self) };
|
||||||
&mut slice[*i]
|
&mut slice[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -267,15 +267,15 @@ macro_rules! vec(
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &usize) -> &'a $S {
|
fn index<'a>(&'a self, i: usize) -> &'a $S {
|
||||||
&self.as_fixed()[*i]
|
&self.as_fixed()[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$S: Copy> IndexMut<usize> for $Self_<$S> {
|
impl<$S: Copy> IndexMut<usize> for $Self_<$S> {
|
||||||
#[inline]
|
#[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 {
|
||||||
&mut self.as_mut_fixed()[*i]
|
&mut self.as_mut_fixed()[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue