nalgebra/src/traits/basis.rs

36 lines
914 B
Rust
Raw Normal View History

// FIXME: return an iterator instead
2013-07-24 22:50:40 +08:00
/// Traits of objecs which can form a basis.
2013-08-05 16:13:44 +08:00
pub trait Basis {
2013-08-05 15:44:56 +08:00
/// Iterate through the canonical basis of the space in which this object lives.
fn canonical_basis(&fn(Self) -> bool);
2013-07-24 22:50:40 +08:00
2013-08-05 15:44:56 +08:00
/// Iterate through a basis of the subspace orthogonal to `self`.
fn orthonormal_subspace_basis(&self, &fn(Self) -> bool);
2013-07-24 22:50:40 +08:00
2013-08-05 15:44:56 +08:00
/// Creates the canonical basis of the space in which this object lives.
2013-08-05 16:13:44 +08:00
fn canonical_basis_list() -> ~[Self] {
2013-08-05 15:44:56 +08:00
let mut res = ~[];
2013-07-24 22:50:40 +08:00
2013-08-05 16:13:44 +08:00
do Basis::canonical_basis::<Self> |elem| {
res.push(elem);
true
2013-08-05 16:13:44 +08:00
}
2013-07-24 22:50:40 +08:00
2013-08-05 15:44:56 +08:00
res
}
2013-07-24 22:50:40 +08:00
2013-08-05 15:44:56 +08:00
/// Creates a basis of the subspace orthogonal to `self`.
2013-08-05 16:13:44 +08:00
fn orthonormal_subspace_basis_list(&self) -> ~[Self] {
2013-08-05 15:44:56 +08:00
let mut res = ~[];
2013-07-24 22:50:40 +08:00
2013-08-05 16:13:44 +08:00
do self.orthonormal_subspace_basis |elem| {
res.push(elem);
true
2013-08-05 16:13:44 +08:00
}
2013-07-24 22:50:40 +08:00
2013-08-05 15:44:56 +08:00
res
}
2013-05-19 01:04:03 +08:00
}