forked from M-Labs/nalgebra
Addesome traits and configuration file.
This commit is contained in:
parent
8b18310c3c
commit
4582492fda
92
src/dim2/rotmat2.rs
Normal file
92
src/dim2/rotmat2.rs
Normal file
@ -0,0 +1,92 @@
|
||||
use core::num::{One, Zero};
|
||||
use traits::workarounds::trigonometric::Trigonometric;
|
||||
use traits::dim::Dim;
|
||||
use dim2::mat2::Mat2;
|
||||
// use dim2::vec2::Vec2;
|
||||
|
||||
// FIXME: using a newtype did not compile (due a compiler bug)
|
||||
// pub type Rotmat2<T> = (Mat2<T>)
|
||||
#[deriving(Eq)]
|
||||
pub struct Rotmat2<T>
|
||||
{
|
||||
submat: Mat2<T>
|
||||
}
|
||||
|
||||
pub fn Rotmat2<T:Copy + Trigonometric + Neg<T>>(angle: T) -> Rotmat2<T>
|
||||
{
|
||||
let coa = angle.cos();
|
||||
let sia = angle.sin();
|
||||
|
||||
Rotmat2
|
||||
{ submat: Mat2(coa, -sia, sia, coa) }
|
||||
}
|
||||
|
||||
impl<T> Dim for Rotmat2<T>
|
||||
{
|
||||
fn dim() -> uint
|
||||
{ 2 }
|
||||
}
|
||||
|
||||
impl<T:Copy + One + Zero> One for Rotmat2<T>
|
||||
{
|
||||
fn one() -> Rotmat2<T>
|
||||
{ Rotmat2 { submat: One::one() } }
|
||||
}
|
||||
|
||||
impl<T:Copy + Mul<T, T> + Add<T, T>> Mul<Rotmat2<T>, Rotmat2<T>> for Rotmat2<T>
|
||||
{
|
||||
fn mul(&self, other: &Rotmat2<T>) -> Rotmat2<T>
|
||||
{ Rotmat2 { submat: self.submat.mul(&other.submat) } }
|
||||
}
|
||||
|
||||
// FIXME: implementation of the same classes for the same struct fails
|
||||
// with "internal compiler error: Asked to compute kind of a type variable".
|
||||
//
|
||||
// impl<T:Copy + Mul<T, T> + Add<T, T>> Mul<Vec2<T>, Vec2<T>> for Rotmat2<T>
|
||||
// {
|
||||
// fn mul(&self, v: &Vec2<T>) -> Vec2<T>
|
||||
// { Vec2(self.m11 * v.x + self.m12 * v.y, self.m21 * v.x + self.m22 * v.y) }
|
||||
// }
|
||||
|
||||
// FIXME: implementation of the same classes for the same struct (here Vec2<T>)
|
||||
// fails with "internal compiler error: Asked to compute kind of a type
|
||||
// variable".
|
||||
//
|
||||
// impl<T:Copy + Mul<T, T> + Add<T, T>> Mul<Rotmat2<T>, Vec2<T>> for Vec2<T>
|
||||
// {
|
||||
// fn mul(&self, m: &Rotmat2<T>) -> Vec2<T>
|
||||
// { self.mult(&m.submat) }
|
||||
// }
|
||||
|
||||
/*
|
||||
impl<T:Copy + Mul<T, T> + Div<T, T> + Sub<T, T> + Neg<T> + Eq + Zero>
|
||||
Inv<T> for Rotmat2<T>
|
||||
{
|
||||
fn inv(&self) -> Rotmat2<T>
|
||||
{
|
||||
// transpose
|
||||
Rotmat2(
|
||||
Mat2(
|
||||
self.submat.m11, self.submat.m21,
|
||||
self.submat.m12, self.submat.m22
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
impl<T:ToStr> ToStr for Rotmat2<T>
|
||||
{
|
||||
fn to_str(&self) -> ~str
|
||||
{
|
||||
~"Rotmat2 {"
|
||||
+ " m11: " + self.m11.to_str()
|
||||
+ " m12: " + self.m12.to_str()
|
||||
|
||||
+ " m21: " + self.m21.to_str()
|
||||
+ " m22: " + self.m22.to_str()
|
||||
+ " }"
|
||||
}
|
||||
}
|
||||
*/
|
55
src/nalgebra.rc
Normal file
55
src/nalgebra.rc
Normal file
@ -0,0 +1,55 @@
|
||||
#[link(name = "nalgebra"
|
||||
, vers = "0.0"
|
||||
, author = "Sébastien Crozet"
|
||||
, uuid = "1E96070F-4778-4EC1-B080-BF69F7048216")];
|
||||
#[crate_type = "lib"];
|
||||
#[warn(non_camel_case_types)]
|
||||
|
||||
extern mod std;
|
||||
|
||||
pub use dim2::vec2::Vec2;
|
||||
pub use dim3::vec3::Vec3;
|
||||
pub use dim2::mat2::Mat2;
|
||||
pub use dim2::rotmat2::Rotmat2;
|
||||
|
||||
pub use traits::dot::Dot;
|
||||
pub use traits::cross::Cross;
|
||||
pub use traits::dim::Dim;
|
||||
|
||||
pub use traits::workarounds::sqrt::Sqrt;
|
||||
pub use traits::workarounds::trigonometric::Trigonometric;
|
||||
|
||||
pub use traits::inv::Inv;
|
||||
pub use traits::transpose::Transpose;
|
||||
|
||||
mod dim2
|
||||
{
|
||||
mod vec2;
|
||||
mod mat2;
|
||||
mod rotmat2;
|
||||
}
|
||||
|
||||
mod dim3
|
||||
{
|
||||
mod vec3;
|
||||
mod mat3;
|
||||
}
|
||||
|
||||
mod ndim
|
||||
{
|
||||
}
|
||||
|
||||
mod traits
|
||||
{
|
||||
mod dot;
|
||||
mod cross;
|
||||
mod inv;
|
||||
mod transpose;
|
||||
mod dim;
|
||||
|
||||
mod workarounds
|
||||
{
|
||||
mod sqrt;
|
||||
mod trigonometric;
|
||||
}
|
||||
}
|
4
src/traits/cross.rs
Normal file
4
src/traits/cross.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub trait Cross<Result>
|
||||
{
|
||||
fn cross(&self, other : &Self) -> Result;
|
||||
}
|
4
src/traits/dim.rs
Normal file
4
src/traits/dim.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub trait Dim
|
||||
{
|
||||
fn dim() -> uint;
|
||||
}
|
6
src/traits/transpose.rs
Normal file
6
src/traits/transpose.rs
Normal file
@ -0,0 +1,6 @@
|
||||
// FIXME: valid only for square matrices…
|
||||
pub trait Transpose
|
||||
{
|
||||
fn transposed(&self) -> Self;
|
||||
fn transpose(&mut self);
|
||||
}
|
17
src/traits/workarounds/sqrt.rs
Normal file
17
src/traits/workarounds/sqrt.rs
Normal file
@ -0,0 +1,17 @@
|
||||
// FIXME: this does not seem to exist already
|
||||
// but it will surely be added someday.
|
||||
|
||||
pub trait Sqrt
|
||||
{
|
||||
fn sqrt(&self) -> Self;
|
||||
}
|
||||
|
||||
impl Sqrt for f64
|
||||
{
|
||||
fn sqrt(&self) -> f64 { f64::sqrt(*self) }
|
||||
}
|
||||
|
||||
impl Sqrt for f32
|
||||
{
|
||||
fn sqrt(&self) -> f32 { f32::sqrt(*self) }
|
||||
}
|
5
src/traits/workarounds/trigonometric.rs
Normal file
5
src/traits/workarounds/trigonometric.rs
Normal file
@ -0,0 +1,5 @@
|
||||
pub trait Trigonometric
|
||||
{
|
||||
fn sin(&self) -> Self;
|
||||
fn cos(&self) -> Self;
|
||||
}
|
Loading…
Reference in New Issue
Block a user