514bf74efe
Those traits are not really removed since rust cannot handle those multiple operator overloading very well yet, making them sometimes unuseable on generic code.
223 lines
4.4 KiB
Rust
223 lines
4.4 KiB
Rust
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::iterable::{Iterable, IterableMut};
|
|
use traits::basis::Basis;
|
|
use traits::dim::Dim;
|
|
use traits::translation::Translation;
|
|
use traits::indexable::Indexable;
|
|
use traits::dot::Dot;
|
|
use traits::norm::Norm;
|
|
use vec;
|
|
|
|
impl<N> vec::Vec0<N> {
|
|
/// Creates a new vector.
|
|
#[inline]
|
|
pub fn new() -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N> Indexable<uint, N> for vec::Vec0<N> {
|
|
#[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<N> vec::Vec0<N> {
|
|
/// Creates a new vector. The parameter is not taken in account.
|
|
#[inline]
|
|
pub fn new_repeat(_: N) -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N> Iterable<N> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn iter<'l>(&'l self) -> VecIterator<'l, N> {
|
|
unsafe { cast::transmute::<&'l vec::Vec0<N>, &'l [N, ..0]>(self).iter() }
|
|
}
|
|
}
|
|
|
|
impl<N> IterableMut<N> for vec::Vec0<N> {
|
|
#[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() }
|
|
}
|
|
}
|
|
|
|
impl<N> Dim for vec::Vec0<N> {
|
|
#[inline]
|
|
fn dim(_: Option<vec::Vec0<N>>) -> uint {
|
|
0
|
|
}
|
|
}
|
|
|
|
impl<N> Basis for vec::Vec0<N> {
|
|
#[inline(always)]
|
|
fn canonical_basis(_: &fn(vec::Vec0<N>) -> bool) { }
|
|
|
|
#[inline(always)]
|
|
fn orthonormal_subspace_basis(&self, _: &fn(vec::Vec0<N>) -> bool) { }
|
|
}
|
|
|
|
impl<N, T> Add<T, vec::Vec0<N>> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn add(&self, _: &T) -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N, T> Sub<T, vec::Vec0<N>> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn sub(&self, _: &T) -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N: Neg<N>> Neg<vec::Vec0<N>> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn neg(&self) -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N: Num + Clone> Dot<N> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn dot(&self, _: &vec::Vec0<N>) -> N {
|
|
Zero::zero()
|
|
}
|
|
|
|
#[inline]
|
|
fn sub_dot(&self, _: &vec::Vec0<N>, _: &vec::Vec0<N>) -> N {
|
|
Zero::zero()
|
|
}
|
|
}
|
|
|
|
impl<N, T> Mul<T, vec::Vec0<N>> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn mul(&self, _: &T) -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N, T> Div<T, vec::Vec0<N>> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn div(&self, _: &T) -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N: Clone + Add<N, N> + Neg<N>> Translation<vec::Vec0<N>> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn translation(&self) -> vec::Vec0<N> {
|
|
self.clone()
|
|
}
|
|
|
|
#[inline]
|
|
fn inv_translation(&self) -> vec::Vec0<N> {
|
|
-self
|
|
}
|
|
|
|
#[inline]
|
|
fn translate_by(&mut self, t: &vec::Vec0<N>) {
|
|
*self = *self + *t;
|
|
}
|
|
|
|
#[inline]
|
|
fn translated(&self, t: &vec::Vec0<N>) -> vec::Vec0<N> {
|
|
self + *t
|
|
}
|
|
|
|
#[inline]
|
|
fn set_translation(&mut self, _: vec::Vec0<N>) {
|
|
}
|
|
}
|
|
|
|
impl<N: Clone + Num + Algebraic> Norm<N> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn sqnorm(&self) -> N {
|
|
self.dot(self)
|
|
}
|
|
|
|
#[inline]
|
|
fn norm(&self) -> N {
|
|
self.sqnorm().sqrt()
|
|
}
|
|
|
|
#[inline]
|
|
fn normalized(&self) -> vec::Vec0<N> {
|
|
let mut res : vec::Vec0<N> = self.clone();
|
|
|
|
res.normalize();
|
|
|
|
res
|
|
}
|
|
|
|
#[inline]
|
|
fn normalize(&mut self) -> N {
|
|
let l = self.norm();
|
|
|
|
*self = *self / l;
|
|
|
|
l
|
|
}
|
|
}
|
|
|
|
impl<N: ApproxEq<N>> ApproxEq<N> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn approx_epsilon() -> N {
|
|
fail!("approx_epsilon is broken since rust revision 8693943676487c01fa09f5f3daf0df6a1f71e24d.")
|
|
// ApproxEq::<N>::approx_epsilon()
|
|
}
|
|
|
|
#[inline]
|
|
fn approx_eq(&self, _: &vec::Vec0<N>) -> bool {
|
|
true
|
|
}
|
|
|
|
#[inline]
|
|
fn approx_eq_eps(&self, _: &vec::Vec0<N>, _: &N) -> bool {
|
|
true
|
|
}
|
|
}
|
|
|
|
impl<N: Clone + One> One for vec::Vec0<N> {
|
|
#[inline]
|
|
fn one() -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N> FromIterator<N> for vec::Vec0<N> {
|
|
#[inline]
|
|
fn from_iterator<I: Iterator<N>>(_: &mut I) -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|
|
|
|
impl<N: Bounded + Clone> Bounded for vec::Vec0<N> {
|
|
#[inline]
|
|
fn max_value() -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
|
|
#[inline]
|
|
fn min_value() -> vec::Vec0<N> {
|
|
vec::Vec0
|
|
}
|
|
}
|