2013-07-20 22:32:39 +08:00
|
|
|
use std::cast;
|
|
|
|
use std::num::{Zero, One, Algebraic, Bounded};
|
|
|
|
use std::vec::{VecIterator, VecMutIterator};
|
2013-08-01 15:18:21 +08:00
|
|
|
use std::iterator::{Iterator, FromIterator};
|
2013-07-20 22:32:39 +08:00
|
|
|
use std::cmp::ApproxEq;
|
|
|
|
use traits::iterable::{Iterable, IterableMut};
|
|
|
|
use traits::basis::Basis;
|
|
|
|
use traits::dim::Dim;
|
|
|
|
use traits::dot::Dot;
|
|
|
|
use traits::sub_dot::SubDot;
|
|
|
|
use traits::norm::Norm;
|
|
|
|
use traits::translation::{Translation, Translatable};
|
|
|
|
use traits::scalar_op::{ScalarMul, ScalarDiv, ScalarAdd, ScalarSub};
|
|
|
|
use traits::ring::Ring;
|
|
|
|
use traits::division_ring::DivisionRing;
|
|
|
|
use traits::indexable::Indexable;
|
|
|
|
use vec;
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N> vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
/// Creates a new vector.
|
|
|
|
#[inline]
|
|
|
|
pub fn new() -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone> Indexable<uint, N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
pub fn at(&self, _: uint) -> N {
|
|
|
|
fail!("Cannot index a Vec0.")
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
pub fn set(&mut self, _: uint, _: N) {
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
pub fn swap(&mut self, _: uint, _: uint) {
|
|
|
|
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone> vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
/// Creates a new vector. The parameter is not taken in account.
|
|
|
|
#[inline]
|
|
|
|
pub fn new_repeat(_: N) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N> Iterable<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn iter<'l>(&'l self) -> VecIterator<'l, N> {
|
|
|
|
unsafe { cast::transmute::<&'l vec::Vec0<N>, &'l [N, ..0]>(self).iter() }
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N> IterableMut<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> {
|
|
|
|
unsafe { cast::transmute::<&'l mut vec::Vec0<N>, &'l mut [N, ..0]>(self).mut_iter() }
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N> Dim for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn dim() -> uint {
|
|
|
|
0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone + DivisionRing + Algebraic + ApproxEq<N>> Basis for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline(always)]
|
|
|
|
pub fn canonical_basis(_: &fn(vec::Vec0<N>)) { }
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline(always)]
|
|
|
|
pub fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0<N>)) { }
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone + Add<N,N>> Add<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn add(&self, _: &vec::Vec0<N>) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone + Sub<N,N>> Sub<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn sub(&self, _: &vec::Vec0<N>) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Neg<N>> Neg<vec::Vec0<N>> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn neg(&self) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Ring> Dot<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn dot(&self, _: &vec::Vec0<N>) -> N {
|
|
|
|
Zero::zero()
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone + Ring> SubDot<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn sub_dot(&self, _: &vec::Vec0<N>, _: &vec::Vec0<N>) -> N {
|
|
|
|
Zero::zero()
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Mul<N, N>> ScalarMul<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_mul(&self, _: &N) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_mul_inplace(&mut self, _: &N) { }
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Div<N, N>> ScalarDiv<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_div(&self, _: &N) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_div_inplace(&mut self, _: &N) { }
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Add<N, N>> ScalarAdd<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_add(&self, _: &N) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_add_inplace(&mut self, _: &N) { }
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Sub<N, N>> ScalarSub<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_sub(&self, _: &N) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn scalar_sub_inplace(&mut self, _: &N) { }
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone + Add<N, N> + Neg<N>> Translation<vec::Vec0<N>> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn translation(&self) -> vec::Vec0<N> {
|
|
|
|
self.clone()
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn inv_translation(&self) -> vec::Vec0<N> {
|
|
|
|
-self
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn translate_by(&mut self, t: &vec::Vec0<N>) {
|
|
|
|
*self = *self + *t;
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Add<N, N> + Neg<N> + Clone> Translatable<vec::Vec0<N>, vec::Vec0<N>> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn translated(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
|
|
|
|
self + *t
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone + DivisionRing + Algebraic> Norm<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn sqnorm(&self) -> N {
|
|
|
|
self.dot(self)
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn norm(&self) -> N {
|
|
|
|
self.sqnorm().sqrt()
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn normalized(&self) -> vec::Vec0<N> {
|
|
|
|
let mut res : vec::Vec0<N> = self.clone();
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
res.normalize();
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
res
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn normalize(&mut self) -> N {
|
|
|
|
let l = self.norm();
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
self.scalar_div_inplace(&l);
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
l
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: ApproxEq<N>> ApproxEq<N> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn approx_epsilon() -> N {
|
|
|
|
ApproxEq::approx_epsilon::<N, N>()
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn approx_eq(&self, _: &vec::Vec0<N>) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn approx_eq_eps(&self, _: &vec::Vec0<N>, _: &N) -> bool {
|
|
|
|
true
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Clone + One> One for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn one() -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N, Iter: Iterator<N>> FromIterator<N, Iter> for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn from_iterator(_: &mut Iter) -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|
|
|
|
|
2013-08-05 16:13:44 +08:00
|
|
|
impl<N: Bounded + Clone> Bounded for vec::Vec0<N> {
|
2013-08-08 02:53:51 +08:00
|
|
|
#[inline]
|
|
|
|
fn max_value() -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn min_value() -> vec::Vec0<N> {
|
|
|
|
vec::Vec0
|
|
|
|
}
|
2013-07-20 22:32:39 +08:00
|
|
|
}
|