int to isize
This commit is contained in:
parent
b7328f57b8
commit
e064ea0e59
10 changed files with 66 additions and 66 deletions
|
@ -17,7 +17,7 @@ macro_rules! bench_binop(
|
||||||
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
||||||
#[bench]
|
#[bench]
|
||||||
fn $name(bh: &mut Bencher) {
|
fn $name(bh: &mut Bencher) {
|
||||||
const LEN: uint = 1 << 13;
|
const LEN: usize = 1 << 13;
|
||||||
|
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ macro_rules! bench_binop_deref(
|
||||||
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
($name: ident, $t1: ty, $t2: ty, $binop: ident) => {
|
||||||
#[bench]
|
#[bench]
|
||||||
fn $name(bh: &mut Bencher) {
|
fn $name(bh: &mut Bencher) {
|
||||||
const LEN: uint = 1 << 13;
|
const LEN: usize = 1 << 13;
|
||||||
|
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ macro_rules! bench_unop(
|
||||||
($name: ident, $t: ty, $unop: ident) => {
|
($name: ident, $t: ty, $unop: ident) => {
|
||||||
#[bench]
|
#[bench]
|
||||||
fn $name(bh: &mut Bencher) {
|
fn $name(bh: &mut Bencher) {
|
||||||
const LEN: uint = 1 << 13;
|
const LEN: usize = 1 << 13;
|
||||||
|
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ macro_rules! bench_construction(
|
||||||
($name: ident, $t: ty, $constructor: path [ $($args: ident: $types: ty),+ ]) => {
|
($name: ident, $t: ty, $constructor: path [ $($args: ident: $types: ty),+ ]) => {
|
||||||
#[bench]
|
#[bench]
|
||||||
fn $name(bh: &mut Bencher) {
|
fn $name(bh: &mut Bencher) {
|
||||||
const LEN: uint = 1 << 13;
|
const LEN: usize = 1 << 13;
|
||||||
|
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ use cgmath::{Quaternion, Basis2, Basis3, Vector3, Rotation2, Rotation3, Rad};
|
||||||
#[macro_use] mod macros;
|
#[macro_use] mod macros;
|
||||||
|
|
||||||
fn bench_from_axis_angle<T: Rotation3<f32>>(bh: &mut Bencher) {
|
fn bench_from_axis_angle<T: Rotation3<f32>>(bh: &mut Bencher) {
|
||||||
const LEN: uint = 1 << 13;
|
const LEN: usize = 1 << 13;
|
||||||
|
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
|
|
||||||
|
|
10
src/angle.rs
10
src/angle.rs
|
@ -150,10 +150,10 @@ pub trait Angle
|
||||||
|
|
||||||
fn full_turn() -> Self;
|
fn full_turn() -> Self;
|
||||||
|
|
||||||
#[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2i).unwrap()) }
|
#[inline] fn turn_div_2() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(2i8).unwrap()) }
|
||||||
#[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3i).unwrap()) }
|
#[inline] fn turn_div_3() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(3i8).unwrap()) }
|
||||||
#[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4i).unwrap()) }
|
#[inline] fn turn_div_4() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(4i8).unwrap()) }
|
||||||
#[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6i).unwrap()) }
|
#[inline] fn turn_div_6() -> Self { let full_turn: Self = Angle::full_turn(); full_turn.div_s(cast(6i8).unwrap()) }
|
||||||
|
|
||||||
#[inline] fn equiv(&self, other: &Self) -> bool { self.normalize() == other.normalize() }
|
#[inline] fn equiv(&self, other: &Self) -> bool { self.normalize() == other.normalize() }
|
||||||
}
|
}
|
||||||
|
@ -264,7 +264,7 @@ Angle<S> for Rad<S> {
|
||||||
impl<S: BaseFloat>
|
impl<S: BaseFloat>
|
||||||
Angle<S> for Deg<S> {
|
Angle<S> for Deg<S> {
|
||||||
#[inline] fn from<A: Angle<S>>(theta: A) -> Deg<S> { theta.to_deg() }
|
#[inline] fn from<A: Angle<S>>(theta: A) -> Deg<S> { theta.to_deg() }
|
||||||
#[inline] fn full_turn() -> Deg<S> { deg(cast(360i).unwrap()) }
|
#[inline] fn full_turn() -> Deg<S> { deg(cast(360i32).unwrap()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline] pub fn sin<S: BaseFloat>(theta: Rad<S>) -> S { theta.s.sin() }
|
#[inline] pub fn sin<S: BaseFloat>(theta: Rad<S>) -> S { theta.s.sin() }
|
||||||
|
|
18
src/array.rs
18
src/array.rs
|
@ -18,7 +18,7 @@ use std::ptr;
|
||||||
use std::ops::*;
|
use std::ops::*;
|
||||||
|
|
||||||
/// An array containing elements of type `Element`
|
/// An array containing elements of type `Element`
|
||||||
pub trait Array1<Element: Copy>: Index<uint, Output=Element> + IndexMut<uint, Output=Element> {
|
pub trait Array1<Element: Copy>: Index<usize, Output=Element> + IndexMut<usize, Output=Element> {
|
||||||
/// Get the pointer to the first element of the array.
|
/// Get the pointer to the first element of the array.
|
||||||
fn ptr<'a>(&'a self) -> &'a Element {
|
fn ptr<'a>(&'a self) -> &'a Element {
|
||||||
&(*self)[0]
|
&(*self)[0]
|
||||||
|
@ -31,14 +31,14 @@ pub trait Array1<Element: Copy>: Index<uint, Output=Element> + IndexMut<uint, Ou
|
||||||
|
|
||||||
/// Swap the elements at indices `i` and `j` in-place.
|
/// Swap the elements at indices `i` and `j` in-place.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_elems(&mut self, i: uint, j: uint) {
|
fn swap_elems(&mut self, i: usize, j: usize) {
|
||||||
// Yeah, ok borrow checker – I know what I'm doing here
|
// Yeah, ok borrow checker – I know what I'm doing here
|
||||||
unsafe { ptr::swap(&mut (*self)[i], &mut (*self)[j]) };
|
unsafe { ptr::swap(&mut (*self)[i], &mut (*self)[j]) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replace an element in the array.
|
/// Replace an element in the array.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn replace_elem(&mut self, i: uint, src: Element) -> Element {
|
fn replace_elem(&mut self, i: usize, src: Element) -> Element {
|
||||||
mem::replace(&mut (*self)[i], src)
|
mem::replace(&mut (*self)[i], src)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ pub trait Array1<Element: Copy>: Index<uint, Output=Element> + IndexMut<uint, Ou
|
||||||
|
|
||||||
/// A column-major array
|
/// A column-major array
|
||||||
pub trait Array2<Column: Array1<Element>+'static, Row: Array1<Element>, Element: Copy>:
|
pub trait Array2<Column: Array1<Element>+'static, Row: Array1<Element>, Element: Copy>:
|
||||||
Index<uint, Output=Column> + IndexMut<uint, Output=Column> {
|
Index<usize, Output=Column> + IndexMut<usize, Output=Column> {
|
||||||
/// Get the pointer to the first element of the array.
|
/// Get the pointer to the first element of the array.
|
||||||
fn ptr<'a>(&'a self) -> &'a Element {
|
fn ptr<'a>(&'a self) -> &'a Element {
|
||||||
&(*self)[0][0]
|
&(*self)[0][0]
|
||||||
|
@ -62,25 +62,25 @@ pub trait Array2<Column: Array1<Element>+'static, Row: Array1<Element>, Element:
|
||||||
|
|
||||||
/// Swap two columns of this array.
|
/// Swap two columns of this array.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_cols(&mut self, a: uint, b: uint) {
|
fn swap_cols(&mut self, a: usize, b: usize) {
|
||||||
unsafe { ptr::swap(&mut (*self)[a], &mut (*self)[b]) };
|
unsafe { ptr::swap(&mut (*self)[a], &mut (*self)[b]) };
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Replace a column in the array.
|
/// Replace a column in the array.
|
||||||
#[inline]
|
#[inline]
|
||||||
fn replace_col(&mut self, c: uint, src: Column) -> Column {
|
fn replace_col(&mut self, c: usize, src: Column) -> Column {
|
||||||
mem::replace(&mut (*self)[c], src)
|
mem::replace(&mut (*self)[c], src)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a row from this array by-value.
|
/// Get a row from this array by-value.
|
||||||
fn row(&self, r: uint) -> Row;
|
fn row(&self, r: usize) -> Row;
|
||||||
|
|
||||||
/// Swap two rows of this array.
|
/// Swap two rows of this array.
|
||||||
fn swap_rows(&mut self, a: uint, b: uint);
|
fn swap_rows(&mut self, a: usize, b: usize);
|
||||||
|
|
||||||
/// Swap the values at index `a` and `b`
|
/// Swap the values at index `a` and `b`
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_elems(&mut self, a: (uint, uint), b: (uint, uint)) {
|
fn swap_elems(&mut self, a: (usize, usize), b: (usize, usize)) {
|
||||||
let (ac, ar) = a;
|
let (ac, ar) = a;
|
||||||
let (bc, br) = b;
|
let (bc, br) = b;
|
||||||
unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) };
|
unsafe { ptr::swap(&mut (*self)[ac][ar], &mut (*self)[bc][br]) };
|
||||||
|
|
|
@ -531,33 +531,33 @@ impl<S> FixedArray<[[S; 2]; 2]> for Matrix2<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Index<uint> for Matrix2<S> {
|
impl<S> Index<usize> for Matrix2<S> {
|
||||||
type Output = Vector2<S>;
|
type Output = Vector2<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &uint) -> &'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<uint> for Matrix2<S> {
|
impl<S> IndexMut<usize> for Matrix2<S> {
|
||||||
type Output = Vector2<S>;
|
type Output = Vector2<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'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])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Copy + 'static> Array2<Vector2<S>, Vector2<S>, S> for Matrix2<S> {
|
impl<S: Copy + 'static> Array2<Vector2<S>, Vector2<S>, S> for Matrix2<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn row(&self, r: uint) -> Vector2<S> {
|
fn row(&self, r: usize) -> Vector2<S> {
|
||||||
Vector2::new(self[0][r],
|
Vector2::new(self[0][r],
|
||||||
self[1][r])
|
self[1][r])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_rows(&mut self, a: uint, b: uint) {
|
fn swap_rows(&mut self, a: usize, b: usize) {
|
||||||
(&mut self[0]).swap_elems(a, b);
|
(&mut self[0]).swap_elems(a, b);
|
||||||
(&mut self[1]).swap_elems(a, b);
|
(&mut self[1]).swap_elems(a, b);
|
||||||
}
|
}
|
||||||
|
@ -615,34 +615,34 @@ impl<S> FixedArray<[[S; 3]; 3]> for Matrix3<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Index<uint> for Matrix3<S> {
|
impl<S> Index<usize> for Matrix3<S> {
|
||||||
type Output = Vector3<S>;
|
type Output = Vector3<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &uint) -> &'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<uint> for Matrix3<S> {
|
impl<S> IndexMut<usize> for Matrix3<S> {
|
||||||
type Output = Vector3<S>;
|
type Output = Vector3<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'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])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Copy + 'static> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> {
|
impl<S: Copy + 'static> Array2<Vector3<S>, Vector3<S>, S> for Matrix3<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn row(&self, r: uint) -> Vector3<S> {
|
fn row(&self, r: usize) -> Vector3<S> {
|
||||||
Vector3::new(self[0][r],
|
Vector3::new(self[0][r],
|
||||||
self[1][r],
|
self[1][r],
|
||||||
self[2][r])
|
self[2][r])
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_rows(&mut self, a: uint, b: uint) {
|
fn swap_rows(&mut self, a: usize, b: usize) {
|
||||||
(&mut self[0]).swap_elems(a, b);
|
(&mut self[0]).swap_elems(a, b);
|
||||||
(&mut self[1]).swap_elems(a, b);
|
(&mut self[1]).swap_elems(a, b);
|
||||||
(&mut self[2]).swap_elems(a, b);
|
(&mut self[2]).swap_elems(a, b);
|
||||||
|
@ -704,27 +704,27 @@ impl<S> FixedArray<[[S; 4]; 4]> for Matrix4<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> Index<uint> for Matrix4<S> {
|
impl<S> Index<usize> for Matrix4<S> {
|
||||||
type Output = Vector4<S>;
|
type Output = Vector4<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &uint) -> &'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<uint> for Matrix4<S> {
|
impl<S> IndexMut<usize> for Matrix4<S> {
|
||||||
type Output = Vector4<S>;
|
type Output = Vector4<S>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'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])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: Copy + 'static> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
|
impl<S: Copy + 'static> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn row(&self, r: uint) -> Vector4<S> {
|
fn row(&self, r: usize) -> Vector4<S> {
|
||||||
Vector4::new(self[0][r],
|
Vector4::new(self[0][r],
|
||||||
self[1][r],
|
self[1][r],
|
||||||
self[2][r],
|
self[2][r],
|
||||||
|
@ -732,7 +732,7 @@ impl<S: Copy + 'static> Array2<Vector4<S>, Vector4<S>, S> for Matrix4<S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn swap_rows(&mut self, a: uint, b: uint) {
|
fn swap_rows(&mut self, a: usize, b: usize) {
|
||||||
(&mut self[0]).swap_elems(a, b);
|
(&mut self[0]).swap_elems(a, b);
|
||||||
(&mut self[1]).swap_elems(a, b);
|
(&mut self[1]).swap_elems(a, b);
|
||||||
(&mut self[2]).swap_elems(a, b);
|
(&mut self[2]).swap_elems(a, b);
|
||||||
|
|
12
src/num.rs
12
src/num.rs
|
@ -35,12 +35,12 @@ macro_rules! partial_ord_int (
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
partial_ord_int!(int);
|
partial_ord_int!(isize);
|
||||||
partial_ord_int!(i8);
|
partial_ord_int!(i8);
|
||||||
partial_ord_int!(i16);
|
partial_ord_int!(i16);
|
||||||
partial_ord_int!(i32);
|
partial_ord_int!(i32);
|
||||||
partial_ord_int!(i64);
|
partial_ord_int!(i64);
|
||||||
partial_ord_int!(uint);
|
partial_ord_int!(usize);
|
||||||
partial_ord_int!(u8);
|
partial_ord_int!(u8);
|
||||||
partial_ord_int!(u16);
|
partial_ord_int!(u16);
|
||||||
partial_ord_int!(u32);
|
partial_ord_int!(u32);
|
||||||
|
@ -106,8 +106,8 @@ impl_basenum_int!(u8);
|
||||||
impl_basenum_int!(u16);
|
impl_basenum_int!(u16);
|
||||||
impl_basenum_int!(u32);
|
impl_basenum_int!(u32);
|
||||||
impl_basenum_int!(u64);
|
impl_basenum_int!(u64);
|
||||||
impl_basenum_int!(int);
|
impl_basenum_int!(isize);
|
||||||
impl_basenum_int!(uint);
|
impl_basenum_int!(usize);
|
||||||
|
|
||||||
|
|
||||||
macro_rules! impl_basenum_float (
|
macro_rules! impl_basenum_float (
|
||||||
|
@ -150,12 +150,12 @@ impl BaseInt for i8 {}
|
||||||
impl BaseInt for i16 {}
|
impl BaseInt for i16 {}
|
||||||
impl BaseInt for i32 {}
|
impl BaseInt for i32 {}
|
||||||
impl BaseInt for i64 {}
|
impl BaseInt for i64 {}
|
||||||
impl BaseInt for int {}
|
impl BaseInt for isize {}
|
||||||
impl BaseInt for u8 {}
|
impl BaseInt for u8 {}
|
||||||
impl BaseInt for u16 {}
|
impl BaseInt for u16 {}
|
||||||
impl BaseInt for u32 {}
|
impl BaseInt for u32 {}
|
||||||
impl BaseInt for u64 {}
|
impl BaseInt for u64 {}
|
||||||
impl BaseInt for uint {}
|
impl BaseInt for usize {}
|
||||||
|
|
||||||
/// Base floating point types
|
/// Base floating point types
|
||||||
pub trait BaseFloat : BaseNum + Float + ApproxEq<Self> {}
|
pub trait BaseFloat : BaseNum + Float + ApproxEq<Self> {}
|
||||||
|
|
16
src/point.rs
16
src/point.rs
|
@ -135,18 +135,18 @@ impl<S> FixedArray<[S; 2]> for Point2<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseNum> Index<uint> 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: &uint) -> &'a S {
|
fn index<'a>(&'a self, i: &usize) -> &'a S {
|
||||||
&self.as_fixed()[*i]
|
&self.as_fixed()[*i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseNum> IndexMut<uint> for Point2<S> {
|
impl<S: BaseNum> IndexMut<usize> for Point2<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'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]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -291,20 +291,20 @@ impl<S> FixedArray<[S; 3]> for Point3<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseNum> Index<uint> for Point3<S> {
|
impl<S: BaseNum> Index<usize> for Point3<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &uint) -> &'a S {
|
fn index<'a>(&'a self, i: &usize) -> &'a S {
|
||||||
&self.as_fixed()[*i]
|
&self.as_fixed()[*i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseNum> IndexMut<uint> for Point3<S> {
|
impl<S: BaseNum> IndexMut<usize> for Point3<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'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]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,7 +79,7 @@ pub struct PerspectiveFov<S, A> {
|
||||||
|
|
||||||
impl<S: BaseFloat, A: Angle<S>> PerspectiveFov<S, A> {
|
impl<S: BaseFloat, A: Angle<S>> PerspectiveFov<S, A> {
|
||||||
pub fn to_perspective(&self) -> Perspective<S> {
|
pub fn to_perspective(&self) -> Perspective<S> {
|
||||||
let angle = self.fovy.div_s(cast(2i).unwrap());
|
let angle = self.fovy.div_s(cast(2i8).unwrap());
|
||||||
let ymax = self.near * tan(angle.to_rad());
|
let ymax = self.near * tan(angle.to_rad());
|
||||||
let xmax = ymax * self.aspect;
|
let xmax = ymax * self.aspect;
|
||||||
|
|
||||||
|
@ -112,8 +112,8 @@ impl<S: BaseFloat, A: Angle<S>> ToMatrix4<S> for PerspectiveFov<S, A> {
|
||||||
assert!(self.far > zero(), "The far plane distance cannot be below zero, found: {:?}", self.far);
|
assert!(self.far > zero(), "The far plane distance cannot be below zero, found: {:?}", self.far);
|
||||||
assert!(self.far > self.near, "The far plane cannot be closer than the near plane, found: far: {:?}, near: {:?}", self.far, self.near);
|
assert!(self.far > self.near, "The far plane cannot be closer than the near plane, found: far: {:?}, near: {:?}", self.far, self.near);
|
||||||
|
|
||||||
let f = cot(self.fovy.div_s(cast(2i).unwrap()).to_rad());
|
let f = cot(self.fovy.div_s(cast(2i8).unwrap()).to_rad());
|
||||||
let two: S = cast(2i).unwrap();
|
let two: S = cast(2i8).unwrap();
|
||||||
|
|
||||||
let c0r0 = f / self.aspect;
|
let c0r0 = f / self.aspect;
|
||||||
let c0r1 = zero();
|
let c0r1 = zero();
|
||||||
|
@ -163,7 +163,7 @@ impl<S: BaseFloat + 'static> ToMatrix4<S> for Perspective<S> {
|
||||||
assert!(self.bottom <= self.top, "`bottom` cannot be greater than `top`, found: bottom: {:?} top: {:?}", self.bottom, self.top);
|
assert!(self.bottom <= self.top, "`bottom` cannot be greater than `top`, found: bottom: {:?} top: {:?}", self.bottom, self.top);
|
||||||
assert!(self.near <= self.far, "`near` cannot be greater than `far`, found: near: {:?} far: {:?}", self.near, self.far);
|
assert!(self.near <= self.far, "`near` cannot be greater than `far`, found: near: {:?} far: {:?}", self.near, self.far);
|
||||||
|
|
||||||
let two: S = cast(2i).unwrap();
|
let two: S = cast(2i8).unwrap();
|
||||||
|
|
||||||
let c0r0 = (two * self.near) / (self.right - self.left);
|
let c0r0 = (two * self.near) / (self.right - self.left);
|
||||||
let c0r1 = zero();
|
let c0r1 = zero();
|
||||||
|
@ -215,7 +215,7 @@ impl<S: BaseFloat> Projection<S> for Ortho<S> {
|
||||||
|
|
||||||
impl<S: BaseFloat> ToMatrix4<S> for Ortho<S> {
|
impl<S: BaseFloat> ToMatrix4<S> for Ortho<S> {
|
||||||
fn to_matrix4(&self) -> Matrix4<S> {
|
fn to_matrix4(&self) -> Matrix4<S> {
|
||||||
let two: S = cast(2i).unwrap();
|
let two: S = cast(2i8).unwrap();
|
||||||
|
|
||||||
let c0r0 = two / (self.right - self.left);
|
let c0r0 = two / (self.right - self.left);
|
||||||
let c0r1 = zero();
|
let c0r1 = zero();
|
||||||
|
|
|
@ -50,21 +50,21 @@ impl<S: Copy + BaseFloat> Array1<S> for Quaternion<S> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S: BaseFloat> Index<uint> for Quaternion<S> {
|
impl<S: BaseFloat> Index<usize> for Quaternion<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &uint) -> &'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<uint> for Quaternion<S> {
|
impl<S: BaseFloat> IndexMut<usize> for Quaternion<S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'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]
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ impl<S: BaseFloat> Quaternion<S> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn mul_v(&self, vec: &Vector3<S>) -> Vector3<S> {
|
pub fn mul_v(&self, vec: &Vector3<S>) -> Vector3<S> {
|
||||||
let tmp = self.v.cross(vec).add_v(&vec.mul_s(self.s.clone()));
|
let tmp = self.v.cross(vec).add_v(&vec.mul_s(self.s.clone()));
|
||||||
self.v.cross(&tmp).mul_s(cast(2i).unwrap()).add_v(vec)
|
self.v.cross(&tmp).mul_s(cast(2i8).unwrap()).add_v(vec)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The sum of this quaternion and `other`
|
/// The sum of this quaternion and `other`
|
||||||
|
|
|
@ -251,20 +251,20 @@ macro_rules! vec(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$S: Copy> Index<uint> for $Self<$S> {
|
impl<$S: Copy> Index<usize> for $Self<$S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index<'a>(&'a self, i: &uint) -> &'a $S {
|
fn index<'a>(&'a self, i: &usize) -> &'a $S {
|
||||||
&self.as_fixed()[*i]
|
&self.as_fixed()[*i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<$S: Copy> IndexMut<uint> for $Self<$S> {
|
impl<$S: Copy> IndexMut<usize> for $Self<$S> {
|
||||||
type Output = S;
|
type Output = S;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn index_mut<'a>(&'a mut self, i: &uint) -> &'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]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -451,7 +451,7 @@ impl<S: BaseNum> Vector4<S> {
|
||||||
|
|
||||||
/// Create a `Vector3`, dropping the nth element
|
/// Create a `Vector3`, dropping the nth element
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn truncate_n(&self, n: int)-> Vector3<S> {
|
pub fn truncate_n(&self, n: isize)-> Vector3<S> {
|
||||||
match n {
|
match n {
|
||||||
0 => Vector3::new(self.y, self.z, self.w),
|
0 => Vector3::new(self.y, self.z, self.w),
|
||||||
1 => Vector3::new(self.x, self.z, self.w),
|
1 => Vector3::new(self.x, self.z, self.w),
|
||||||
|
|
Loading…
Reference in a new issue