use std::cast; use std::num::{Zero, One, Algebraic, Bounded}; use std::vec::{VecIterator, VecMutIterator}; use std::iter::{Iterator, FromIterator}; use std::cmp::ApproxEq; use traits::structure::{Iterable, IterableMut, Indexable, Basis, Dim}; use traits::geometry::{Translation, Dot, Norm}; use structs::vec; impl vec::Vec0 { /// Creates a new vector. #[inline] pub fn new() -> vec::Vec0 { vec::Vec0 } } impl Indexable for vec::Vec0 { #[inline] fn at(&self, _: uint) -> N { fail!("Cannot index a Vec0.") } #[inline] fn set(&mut self, _: uint, _: N) { } #[inline] fn swap(&mut self, _: uint, _: uint) { } } impl vec::Vec0 { /// Creates a new vector. The parameter is not taken in account. #[inline] pub fn new_repeat(_: N) -> vec::Vec0 { vec::Vec0 } } impl Iterable for vec::Vec0 { #[inline] fn iter<'l>(&'l self) -> VecIterator<'l, N> { unsafe { cast::transmute::<&'l vec::Vec0, &'l [N, ..0]>(self).iter() } } } impl IterableMut for vec::Vec0 { #[inline] fn mut_iter<'l>(&'l mut self) -> VecMutIterator<'l, N> { unsafe { cast::transmute::<&'l mut vec::Vec0, &'l mut [N, ..0]>(self).mut_iter() } } } impl Dim for vec::Vec0 { #[inline] fn dim(_: Option>) -> uint { 0 } } impl Basis for vec::Vec0 { #[inline(always)] fn canonical_basis(_: &fn(vec::Vec0) -> bool) { } #[inline(always)] fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0) -> bool) { } } impl Add> for vec::Vec0 { #[inline] fn add(&self, _: &T) -> vec::Vec0 { vec::Vec0 } } impl Sub> for vec::Vec0 { #[inline] fn sub(&self, _: &T) -> vec::Vec0 { vec::Vec0 } } impl> Neg> for vec::Vec0 { #[inline] fn neg(&self) -> vec::Vec0 { vec::Vec0 } } impl Dot for vec::Vec0 { #[inline] fn dot(&self, _: &vec::Vec0) -> N { Zero::zero() } #[inline] fn sub_dot(&self, _: &vec::Vec0, _: &vec::Vec0) -> N { Zero::zero() } } impl Mul> for vec::Vec0 { #[inline] fn mul(&self, _: &T) -> vec::Vec0 { vec::Vec0 } } impl Div> for vec::Vec0 { #[inline] fn div(&self, _: &T) -> vec::Vec0 { vec::Vec0 } } impl + Neg> Translation> for vec::Vec0 { #[inline] fn translation(&self) -> vec::Vec0 { self.clone() } #[inline] fn inv_translation(&self) -> vec::Vec0 { -self } #[inline] fn translate_by(&mut self, t: &vec::Vec0) { *self = *self + *t; } #[inline] fn translated(&self, t: &vec::Vec0) -> vec::Vec0 { self + *t } #[inline] fn set_translation(&mut self, _: vec::Vec0) { } } impl Norm for vec::Vec0 { #[inline] fn sqnorm(&self) -> N { self.dot(self) } #[inline] fn norm(&self) -> N { self.sqnorm().sqrt() } #[inline] fn normalized(&self) -> vec::Vec0 { let mut res : vec::Vec0 = self.clone(); res.normalize(); res } #[inline] fn normalize(&mut self) -> N { let l = self.norm(); *self = *self / l; l } } impl> ApproxEq for vec::Vec0 { #[inline] fn approx_epsilon() -> N { fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.") // ApproxEq::::approx_epsilon() } #[inline] fn approx_eq(&self, _: &vec::Vec0) -> bool { true } #[inline] fn approx_eq_eps(&self, _: &vec::Vec0, _: &N) -> bool { true } } impl One for vec::Vec0 { #[inline] fn one() -> vec::Vec0 { vec::Vec0 } } impl FromIterator for vec::Vec0 { #[inline] fn from_iterator>(_: &mut I) -> vec::Vec0 { vec::Vec0 } } impl Bounded for vec::Vec0 { #[inline] fn max_value() -> vec::Vec0 { vec::Vec0 } #[inline] fn min_value() -> vec::Vec0 { vec::Vec0 } }