forked from M-Labs/nalgebra
84212f1449
Everything changed, hopefully for the best. * everything is accessible from the `na` module. It re-export everything and provides free functions (i-e: na::dot(a, b) instead of a.dot(b)) for most functionalities. * matrix/vector adaptors (Rotmat, Transform) are replaced by plain types: Rot{2, 3, 4} for rotation matrices and Iso{2, 3, 4} for isometries (rotation + translation). This old adaptors system was to hard to understand and to document. * each file related to data structures moved to the `structs` folder. This makes the doc a lot more readable and make people prefer the `na` module instead of individual small modules. * Because `na` exists now, the modules `structs::vec` and `structs::mat` dont re-export anything now. As a side effect, this makes the documentation more readable.
111 lines
2.2 KiB
Rust
111 lines
2.2 KiB
Rust
/// Implement nalgebra traits for complex numbers from `extra::complex::Cmplex`.
|
|
|
|
use std::num::Zero;
|
|
use extra::complex::Cmplx;
|
|
use traits::operations::{Absolute, Inv};
|
|
use traits::structure::{Dim};
|
|
|
|
impl<N: Clone + Num> Absolute<Cmplx<N>> for Cmplx<N> {
|
|
#[inline]
|
|
fn absolute(&self) -> Cmplx<N> {
|
|
Cmplx::new(self.re.clone(), self.im.clone())
|
|
}
|
|
}
|
|
|
|
impl<N: Clone + Num + NumCast + Zero> Inv for Cmplx<N> {
|
|
#[inline]
|
|
fn inverse(&self) -> Option<Cmplx<N>> {
|
|
if self.is_zero() {
|
|
None
|
|
}
|
|
else {
|
|
let _1: N = NumCast::from(1.0);
|
|
let divisor = _1 / (self.re * self.re - self.im * self.im);
|
|
|
|
Some(Cmplx::new(self.re * divisor, -self.im * divisor))
|
|
}
|
|
}
|
|
|
|
#[inline]
|
|
fn inplace_inverse(&mut self) -> bool {
|
|
if self.is_zero() {
|
|
false
|
|
}
|
|
else {
|
|
let _1: N = NumCast::from(1.0);
|
|
let divisor = _1 / (self.re * self.re - self.im * self.im);
|
|
|
|
self.re = self.re * divisor;
|
|
self.im = -self.im * divisor;
|
|
|
|
true
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<N> Dim for Cmplx<N> {
|
|
#[inline]
|
|
fn dim(unsused_self: Option<Cmplx<N>>) -> uint {
|
|
2
|
|
}
|
|
}
|
|
|
|
impl<N> Rotation<Vec2<N>> for Cmplx<N> {
|
|
#[inline]
|
|
fn rotation(&self) -> Vec2<N> {
|
|
}
|
|
|
|
#[inline]
|
|
fn inv_rotation(&self) -> Vec2<N> {
|
|
-self.rotation();
|
|
}
|
|
|
|
#[inline]
|
|
fn rotate_by(&mut self, rotation: &Vec2<N>) {
|
|
}
|
|
|
|
#[inline]
|
|
fn rotated(&self, rotation: &Vec2<N>) -> Cmplx<N> {
|
|
}
|
|
|
|
#[inline]
|
|
fn set_rotation(&mut self, rotation: Vec2<N>) {
|
|
}
|
|
}
|
|
|
|
impl<N> Rotate<Vec2<N>> for Cmplx<N> {
|
|
#[inline]
|
|
fn rotate(&self, rotation: &V) -> V {
|
|
}
|
|
|
|
#[inline]
|
|
fn inv_rotate(&self, rotation: &V) -> V {
|
|
}
|
|
}
|
|
|
|
impl<N> RotationMatrix<Vec2<N>, Vec2<N>, Rotmat<Mat2<N>>> for Cmplx<N> {
|
|
#[inline]
|
|
fn to_rot_mat(&self) -> Rotmat<Mat2<N>> {
|
|
}
|
|
}
|
|
|
|
impl<N> Norm<N> for Cmplx<N> {
|
|
#[inline]
|
|
fn sqnorm(&self) -> N {
|
|
}
|
|
|
|
#[inline]
|
|
fn normalized(&self) -> Self {
|
|
}
|
|
|
|
#[inline]
|
|
fn normalize(&mut self) -> N {
|
|
}
|
|
}
|
|
|
|
impl<N> AbsoluteRotate<V> {
|
|
#[inline]
|
|
fn absolute_rotate(&elf, v: &V) -> V {
|
|
}
|
|
}
|