2013-06-29 08:34:45 +08:00
|
|
|
#[macro_escape];
|
|
|
|
|
|
|
|
macro_rules! new_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N> $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
pub fn new($comp0: N $( , $compN: N )*) -> $t<N>
|
|
|
|
{
|
|
|
|
$t {
|
|
|
|
$comp0: $comp0
|
|
|
|
$(, $compN: $compN )*
|
|
|
|
}
|
|
|
|
}
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-06-29 19:40:31 +08:00
|
|
|
macro_rules! indexable_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $dim: expr) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Clone> Indexable<uint, N> for $t<N>
|
2013-06-29 19:40:31 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
pub fn at(&self, i: uint) -> N
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ unsafe { cast::transmute::<&$t<N>, &[N, ..$dim]>(self)[i].clone() } }
|
2013-06-29 19:40:31 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn set(&mut self, i: uint, val: N)
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ unsafe { cast::transmute::<&mut $t<N>, &mut [N, ..$dim]>(self)[i] = val } }
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn swap(&mut self, i1: uint, i2: uint)
|
|
|
|
{ unsafe { cast::transmute::<&mut $t<N>, &mut [N, ..$dim]>(self).swap(i1, i2) } }
|
2013-06-29 19:40:31 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-06-29 08:34:45 +08:00
|
|
|
macro_rules! new_repeat_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $param: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Clone> $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
pub fn new_repeat($param: N) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{
|
|
|
|
$t{
|
|
|
|
$comp0: $param.clone()
|
|
|
|
$(, $compN: $param.clone() )*
|
|
|
|
}
|
|
|
|
}
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! iterable_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $dim: expr) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N> Iterable<N> for $t<N>
|
|
|
|
{
|
|
|
|
fn iter<'l>(&'l self) -> VecIterator<'l, N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ unsafe { cast::transmute::<&'l $t<N>, &'l [N, ..$dim]>(self).iter() } }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! iterable_mut_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $dim: expr) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N> IterableMut<N> for $t<N>
|
|
|
|
{
|
|
|
|
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ unsafe { cast::transmute::<&'l mut $t<N>, &'l mut [N, ..$dim]>(self).mut_iter() } }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! dim_impl(
|
|
|
|
($t: ident, $dim: expr) => (
|
|
|
|
impl<N> Dim for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn dim() -> uint
|
|
|
|
{ $dim }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! basis_impl(
|
|
|
|
($t: ident, $dim: expr) => (
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
2013-07-02 00:33:22 +08:00
|
|
|
pub fn canonical_basis(f: &fn($t<N>))
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
for iterate(0u, $dim) |i|
|
|
|
|
{
|
|
|
|
let mut basis_element : $t<N> = Zero::zero();
|
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
basis_element.set(i, One::one());
|
2013-06-29 08:34:45 +08:00
|
|
|
|
2013-07-02 00:33:22 +08:00
|
|
|
f(basis_element);
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-02 00:33:22 +08:00
|
|
|
pub fn orthonormal_subspace_basis(&self, f: &fn($t<N>))
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
// compute the basis of the orthogonal subspace using Gram-Schmidt
|
|
|
|
// orthogonalization algorithm
|
2013-07-02 00:33:22 +08:00
|
|
|
let mut basis: ~[$t<N>] = ~[];
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
for iterate(0u, $dim) |i|
|
|
|
|
{
|
|
|
|
let mut basis_element : $t<N> = Zero::zero();
|
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
basis_element.set(i, One::one());
|
2013-06-29 08:34:45 +08:00
|
|
|
|
2013-07-02 00:33:22 +08:00
|
|
|
if basis.len() == $dim - 1
|
2013-06-29 08:34:45 +08:00
|
|
|
{ break; }
|
|
|
|
|
2013-07-04 22:23:08 +08:00
|
|
|
let mut elt = basis_element.clone();
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
elt = elt - self.scalar_mul(&basis_element.dot(self));
|
|
|
|
|
2013-07-02 00:33:22 +08:00
|
|
|
for basis.iter().advance |v|
|
2013-06-29 08:34:45 +08:00
|
|
|
{ elt = elt - v.scalar_mul(&elt.dot(v)) };
|
|
|
|
|
|
|
|
if !elt.sqnorm().approx_eq(&Zero::zero())
|
2013-07-02 00:33:22 +08:00
|
|
|
{
|
|
|
|
let new_element = elt.normalized();
|
|
|
|
|
2013-07-04 22:23:08 +08:00
|
|
|
f(new_element.clone());
|
2013-07-02 00:33:22 +08:00
|
|
|
|
|
|
|
basis.push(new_element);
|
|
|
|
}
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! add_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Clone + Add<N,N>> Add<$t<N>, $t<N>> for $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn add(&self, other: &$t<N>) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ $t::new(self.$comp0 + other.$comp0 $(, self.$compN + other.$compN)*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! sub_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Clone + Sub<N,N>> Sub<$t<N>, $t<N>> for $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn sub(&self, other: &$t<N>) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ $t::new(self.$comp0 - other.$comp0 $(, self.$compN - other.$compN)*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! neg_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: Neg<N>> Neg<$t<N>> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn neg(&self) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ $t::new(-self.$comp0 $(, -self.$compN )*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! dot_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: Ring> Dot<N> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn dot(&self, other: &$t<N>) -> N
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ self.$comp0 * other.$comp0 $(+ self.$compN * other.$compN )* }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! sub_dot_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: Ring> SubDot<N> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn sub_dot(&self, a: &$t<N>, b: &$t<N>) -> N
|
2013-07-20 21:18:44 +08:00
|
|
|
{ (self.$comp0 - a.$comp0) * b.$comp0 $(+ (self.$compN - a.$compN) * b.$compN )* }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! scalar_mul_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: Mul<N, N>> ScalarMul<N> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn scalar_mul(&self, s: &N) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ $t::new(self.$comp0 * *s $(, self.$compN * *s)*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn scalar_mul_inplace(&mut self, s: &N)
|
|
|
|
{
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
self.$comp0 = self.$comp0 * *s;
|
|
|
|
$(self.$compN = self.$compN * *s;)*
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! scalar_div_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: Div<N, N>> ScalarDiv<N> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn scalar_div(&self, s: &N) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ $t::new(self.$comp0 / *s $(, self.$compN / *s)*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn scalar_div_inplace(&mut self, s: &N)
|
|
|
|
{
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
self.$comp0 = self.$comp0 / *s;
|
|
|
|
$(self.$compN = self.$compN / *s;)*
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! scalar_add_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: Add<N, N>> ScalarAdd<N> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn scalar_add(&self, s: &N) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ $t::new(self.$comp0 + *s $(, self.$compN + *s)*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn scalar_add_inplace(&mut self, s: &N)
|
|
|
|
{
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
self.$comp0 = self.$comp0 + *s;
|
|
|
|
$(self.$compN = self.$compN + *s;)*
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! scalar_sub_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: Sub<N, N>> ScalarSub<N> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn scalar_sub(&self, s: &N) -> $t<N>
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ $t::new(self.$comp0 - *s $(, self.$compN - *s)*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn scalar_sub_inplace(&mut self, s: &N)
|
|
|
|
{
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
self.$comp0 = self.$comp0 - *s;
|
|
|
|
$(self.$compN = self.$compN - *s;)*
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! translation_impl(
|
|
|
|
($t: ident) => (
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
impl<N: Clone + Add<N, N> + Neg<N>> Translation<$t<N>> for $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn translation(&self) -> $t<N>
|
2013-07-04 22:23:08 +08:00
|
|
|
{ self.clone() }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn inv_translation(&self) -> $t<N>
|
|
|
|
{ -self }
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn translate_by(&mut self, t: &$t<N>)
|
|
|
|
{ *self = *self + *t; }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! translatable_impl(
|
|
|
|
($t: ident) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Add<N, N> + Neg<N> + Clone> Translatable<$t<N>, $t<N>> for $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn translated(&self, t: &$t<N>) -> $t<N>
|
|
|
|
{ self + *t }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! norm_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident) => (
|
|
|
|
impl<N: Clone + DivisionRing + Algebraic> Norm<N> for $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn sqnorm(&self) -> N
|
|
|
|
{ self.dot(self) }
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn norm(&self) -> N
|
|
|
|
{ self.sqnorm().sqrt() }
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn normalized(&self) -> $t<N>
|
|
|
|
{
|
2013-07-04 22:23:08 +08:00
|
|
|
let mut res : $t<N> = self.clone();
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
res.normalize();
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn normalize(&mut self) -> N
|
|
|
|
{
|
|
|
|
let l = self.norm();
|
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
self.scalar_div_inplace(&l);
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
l
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! approx_eq_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N>
|
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn approx_epsilon() -> N
|
|
|
|
{ ApproxEq::approx_epsilon::<N, N>() }
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn approx_eq(&self, other: &$t<N>) -> bool
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
{ self.$comp0.approx_eq(&other.$comp0) $(&& self.$compN.approx_eq(&other.$compN))* }
|
2013-06-29 08:34:45 +08:00
|
|
|
|
|
|
|
#[inline]
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
fn approx_eq_eps(&self, other: &$t<N>, eps: &N) -> bool
|
|
|
|
{ self.$comp0.approx_eq_eps(&other.$comp0, eps) $(&& self.$compN.approx_eq_eps(&other.$compN, eps))* }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-06-29 19:40:31 +08:00
|
|
|
macro_rules! one_impl(
|
|
|
|
($t: ident) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Clone + One> One for $t<N>
|
2013-06-29 19:40:31 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn one() -> $t<N>
|
|
|
|
{ $t::new_repeat(One::one()) }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2013-06-29 08:34:45 +08:00
|
|
|
macro_rules! from_iterator_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $param0: ident $(, $paramN: ident)*) => (
|
2013-06-29 08:34:45 +08:00
|
|
|
impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for $t<N>
|
|
|
|
{
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
fn from_iterator($param0: &mut Iter) -> $t<N>
|
|
|
|
{ $t::new($param0.next().unwrap() $(, $paramN.next().unwrap())*) }
|
2013-06-29 08:34:45 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! bounded_impl(
|
|
|
|
($t: ident) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Bounded + Clone> Bounded for $t<N>
|
2013-06-29 08:34:45 +08:00
|
|
|
{
|
|
|
|
#[inline]
|
|
|
|
fn max_value() -> $t<N>
|
|
|
|
{ $t::new_repeat(Bounded::max_value()) }
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn min_value() -> $t<N>
|
|
|
|
{ $t::new_repeat(Bounded::min_value()) }
|
|
|
|
}
|
|
|
|
)
|
|
|
|
)
|
2013-06-29 19:40:31 +08:00
|
|
|
|
|
|
|
macro_rules! to_homogeneous_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => (
|
|
|
|
impl<N: Clone + One + Zero> ToHomogeneous<$t2<N>> for $t<N>
|
2013-06-29 19:40:31 +08:00
|
|
|
{
|
|
|
|
fn to_homogeneous(&self) -> $t2<N>
|
|
|
|
{
|
|
|
|
let mut res: $t2<N> = One::one();
|
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
res.$comp0 = self.$comp0.clone();
|
|
|
|
$( res.$compN = self.$compN.clone(); )*
|
2013-06-29 19:40:31 +08:00
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
)
|
2013-06-29 19:40:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
macro_rules! from_homogeneous_impl(
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
($t: ident, $t2: ident, $extra: ident, $comp0: ident $(,$compN: ident)*) => (
|
2013-07-04 22:23:08 +08:00
|
|
|
impl<N: Clone + Div<N, N> + One + Zero> FromHomogeneous<$t2<N>> for $t<N>
|
2013-06-29 19:40:31 +08:00
|
|
|
{
|
|
|
|
fn from_homogeneous(v: &$t2<N>) -> $t<N>
|
|
|
|
{
|
|
|
|
let mut res: $t<N> = Zero::zero();
|
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
res.$comp0 = v.$comp0.clone();
|
|
|
|
$( res.$compN = v.$compN.clone(); )*
|
2013-06-29 19:40:31 +08:00
|
|
|
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
res.scalar_div(&v.$extra);
|
2013-06-29 19:40:31 +08:00
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
Removed occurences of copy/Copy + improved api.
Now, access to vector components are x, y, z, w, a, b, ... instead of at[i].
The method at(i) has the same (read only) effect as the old at[i].
Now, access to matrix components are m11, m12, ... instead of mij[offset(i, j)]...
The method at((i, j)) has the same effect as the old mij[offset(i, j)].
Automatic implementation of all traits the compiler supports has been added on the #[deriving]
clause for both matrices and vectors.
2013-07-20 21:07:49 +08:00
|
|
|
)
|
2013-06-29 19:40:31 +08:00
|
|
|
)
|