Merge pull request #129 from sebcrozet/ncollide_fixes
Minor breaking changes needed by `ncollide`.
This commit is contained in:
commit
11bbf0ff11
@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "nalgebra"
|
||||
version = "0.2.14"
|
||||
version = "0.2.15"
|
||||
authors = [ "Sébastien Crozet <developer@crozet.re>" ] # FIXME: add the contributors.
|
||||
|
||||
description = "Linear algebra library for computer physics, computer graphics and general low-dimensional linear algebra for Rust."
|
||||
|
24
src/lib.rs
24
src/lib.rs
@ -92,7 +92,7 @@ extern crate num;
|
||||
extern crate quickcheck;
|
||||
|
||||
use std::cmp;
|
||||
use std::ops::{Neg, Mul};
|
||||
use std::ops::Neg;
|
||||
use num::{Zero, One};
|
||||
pub use traits::{
|
||||
Absolute,
|
||||
@ -132,6 +132,7 @@ pub use traits::{
|
||||
POrd,
|
||||
POrdering,
|
||||
PntAsVec,
|
||||
Repeat,
|
||||
Rotate, Rotation, RotationMatrix, RotationWithTranslation,
|
||||
Row,
|
||||
Shape,
|
||||
@ -575,9 +576,8 @@ pub fn append_rotation_wrt_center<LV: Neg<Output = LV> + Copy,
|
||||
/// Builds a rotation matrix from `r`.
|
||||
#[inline(always)]
|
||||
pub fn to_rot_mat<N, LV, AV, R, M>(r: &R) -> M
|
||||
where R: RotationMatrix<N, LV, AV, Output=M>,
|
||||
M: Mat<N, LV, AV> + Rotation<AV> + Col<LV> + Copy,
|
||||
LV: Mul<M, Output=LV> + Copy,
|
||||
where R: RotationMatrix<N, LV, AV, Output = M>,
|
||||
M: SquareMat<N, LV> + Rotation<AV> + Copy
|
||||
{
|
||||
// FIXME: rust-lang/rust#20413
|
||||
r.to_rot_mat()
|
||||
@ -678,7 +678,7 @@ pub fn det<M: Det<N>, N>(m: &M) -> N {
|
||||
|
||||
/// Computes the cross product of two vectors.
|
||||
#[inline(always)]
|
||||
pub fn cross<LV: Cross>(a: &LV, b: &LV) -> LV::Output {
|
||||
pub fn cross<LV: Cross>(a: &LV, b: &LV) -> LV::CrossProductType {
|
||||
Cross::cross(a, b)
|
||||
}
|
||||
|
||||
@ -785,7 +785,7 @@ pub fn transpose<M: Transpose>(m: &M) -> M {
|
||||
|
||||
/// Computes the outer product of two vectors.
|
||||
#[inline(always)]
|
||||
pub fn outer<V: Outer<M>, M>(a: &V, b: &V) -> M {
|
||||
pub fn outer<V: Outer>(a: &V, b: &V) -> V::OuterProductType {
|
||||
Outer::outer(a, b)
|
||||
}
|
||||
|
||||
@ -833,6 +833,18 @@ pub fn new_identity<M: Eye>(dim: usize) -> M {
|
||||
Eye::new_identity(dim)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Repeat
|
||||
*/
|
||||
/// Create an object by repeating a value.
|
||||
///
|
||||
/// Same as `Identity::new()`.
|
||||
#[inline(always)]
|
||||
pub fn repeat<N, T: Repeat<N>>(val: N) -> T {
|
||||
Repeat::repeat(val)
|
||||
}
|
||||
|
||||
/*
|
||||
* Basis
|
||||
*/
|
||||
|
@ -10,7 +10,7 @@ use rand::{self, Rand};
|
||||
use num::{Zero, One};
|
||||
use structs::dvec::DVec;
|
||||
use traits::operations::{ApproxEq, Inv, Transpose, Mean, Cov};
|
||||
use traits::structure::{Cast, ColSlice, RowSlice, Diag, Eye, Indexable, Shape, BaseNum};
|
||||
use traits::structure::{Cast, ColSlice, RowSlice, Diag, DiagMut, Eye, Indexable, Shape, BaseNum};
|
||||
#[cfg(feature="arbitrary")]
|
||||
use quickcheck::{Arbitrary, Gen};
|
||||
|
||||
@ -555,17 +555,6 @@ impl<N: Copy + Clone + Zero> Diag<DVec<N>> for DMat<N> {
|
||||
res
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_diag(&mut self, diag: &DVec<N>) {
|
||||
let smallest_dim = cmp::min(self.nrows, self.ncols);
|
||||
|
||||
assert!(diag.len() == smallest_dim);
|
||||
|
||||
for i in 0..smallest_dim {
|
||||
unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) }
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn diag(&self) -> DVec<N> {
|
||||
let smallest_dim = cmp::min(self.nrows, self.ncols);
|
||||
@ -580,6 +569,19 @@ impl<N: Copy + Clone + Zero> Diag<DVec<N>> for DMat<N> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Copy + Clone + Zero> DiagMut<DVec<N>> for DMat<N> {
|
||||
#[inline]
|
||||
fn set_diag(&mut self, diag: &DVec<N>) {
|
||||
let smallest_dim = cmp::min(self.nrows, self.ncols);
|
||||
|
||||
assert!(diag.len() == smallest_dim);
|
||||
|
||||
for i in 0..smallest_dim {
|
||||
unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> {
|
||||
#[inline]
|
||||
fn approx_epsilon(_: Option<DMat<N>>) -> N {
|
||||
|
@ -12,8 +12,8 @@ use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
|
||||
use structs::pnt::{Pnt1, Pnt4, Pnt5, Pnt6};
|
||||
use structs::dvec::{DVec1, DVec2, DVec3, DVec4, DVec5, DVec6};
|
||||
|
||||
use traits::structure::{Cast, Row, Col, Iterable, IterableMut, Dim, Indexable,
|
||||
Eye, ColSlice, RowSlice, Diag, Shape, BaseFloat, BaseNum};
|
||||
use traits::structure::{Cast, Row, Col, Iterable, IterableMut, Dim, Indexable, Eye, ColSlice,
|
||||
RowSlice, Diag, DiagMut, Shape, BaseFloat, BaseNum, Repeat};
|
||||
use traits::operations::{Absolute, Transpose, Inv, Outer, EigenQR};
|
||||
use traits::geometry::{ToHomogeneous, FromHomogeneous, Orig};
|
||||
use linalg;
|
||||
@ -23,7 +23,7 @@ use quickcheck::{Arbitrary, Gen};
|
||||
|
||||
/// Special identity matrix. All its operation are no-ops.
|
||||
#[repr(C)]
|
||||
#[derive(Eq, PartialEq, RustcDecodable, Clone, Debug, Copy)]
|
||||
#[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Debug, Copy)]
|
||||
pub struct Identity;
|
||||
|
||||
impl Identity {
|
||||
@ -44,6 +44,7 @@ pub struct Mat1<N> {
|
||||
eye_impl!(Mat1, 1, m11);
|
||||
|
||||
mat_impl!(Mat1, m11);
|
||||
repeat_impl!(Mat1, m11);
|
||||
as_array_impl!(Mat1, 1);
|
||||
mat_cast_impl!(Mat1, m11);
|
||||
add_impl!(Mat1, m11);
|
||||
@ -93,6 +94,8 @@ eye_impl!(Mat2, 2, m11, m22);
|
||||
|
||||
mat_impl!(Mat2, m11, m12,
|
||||
m21, m22);
|
||||
repeat_impl!(Mat2, m11, m12,
|
||||
m21, m22);
|
||||
as_array_impl!(Mat2, 2);
|
||||
mat_cast_impl!(Mat2, m11, m12,
|
||||
m21, m22);
|
||||
@ -146,6 +149,9 @@ eye_impl!(Mat3, 3, m11, m22, m33);
|
||||
mat_impl!(Mat3, m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
m31, m32, m33);
|
||||
repeat_impl!(Mat3, m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
m31, m32, m33);
|
||||
as_array_impl!(Mat3, 3);
|
||||
mat_cast_impl!(Mat3, m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
@ -243,6 +249,12 @@ mat_impl!(Mat4,
|
||||
m31, m32, m33, m34,
|
||||
m41, m42, m43, m44
|
||||
);
|
||||
repeat_impl!(Mat4,
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
m31, m32, m33, m34,
|
||||
m41, m42, m43, m44
|
||||
);
|
||||
as_array_impl!(Mat4, 4);
|
||||
mat_cast_impl!(Mat4,
|
||||
m11, m12, m13, m14,
|
||||
@ -358,6 +370,13 @@ mat_impl!(Mat5,
|
||||
m41, m42, m43, m44, m45,
|
||||
m51, m52, m53, m54, m55
|
||||
);
|
||||
repeat_impl!(Mat5,
|
||||
m11, m12, m13, m14, m15,
|
||||
m21, m22, m23, m24, m25,
|
||||
m31, m32, m33, m34, m35,
|
||||
m41, m42, m43, m44, m45,
|
||||
m51, m52, m53, m54, m55
|
||||
);
|
||||
as_array_impl!(Mat5, 5);
|
||||
mat_cast_impl!(Mat5,
|
||||
m11, m12, m13, m14, m15,
|
||||
@ -489,6 +508,14 @@ mat_impl!(Mat6,
|
||||
m51, m52, m53, m54, m55, m56,
|
||||
m61, m62, m63, m64, m65, m66
|
||||
);
|
||||
repeat_impl!(Mat6,
|
||||
m11, m12, m13, m14, m15, m16,
|
||||
m21, m22, m23, m24, m25, m26,
|
||||
m31, m32, m33, m34, m35, m36,
|
||||
m41, m42, m43, m44, m45, m46,
|
||||
m51, m52, m53, m54, m55, m56,
|
||||
m61, m62, m63, m64, m65, m66
|
||||
);
|
||||
as_array_impl!(Mat6, 6);
|
||||
mat_cast_impl!(Mat6,
|
||||
m11, m12, m13, m14, m15, m16,
|
||||
|
@ -164,6 +164,18 @@ macro_rules! eye_impl(
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! repeat_impl(
|
||||
($t: ident, $($compN: ident),+) => (
|
||||
impl<N: Copy> Repeat<N> for $t<N> {
|
||||
fn repeat(val: N) -> $t<N> {
|
||||
$t {
|
||||
$($compN: val ),+
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! mat_sub_scalar_impl(
|
||||
($t: ident, $($compN: ident),+) => (
|
||||
impl<N: Sub<N, Output = N> Sub<N> for $t<N> {
|
||||
@ -401,13 +413,6 @@ macro_rules! diag_impl(
|
||||
res
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn set_diag(&mut self, diag: &$tv<N>) {
|
||||
for i in 0..$dim {
|
||||
unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) }
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn diag(&self) -> $tv<N> {
|
||||
let mut diag: $tv<N> = ::zero();
|
||||
@ -419,6 +424,15 @@ macro_rules! diag_impl(
|
||||
diag
|
||||
}
|
||||
}
|
||||
|
||||
impl<N: Copy + Zero> DiagMut<$tv<N>> for $t<N> {
|
||||
#[inline]
|
||||
fn set_diag(&mut self, diag: &$tv<N>) {
|
||||
for i in 0..$dim {
|
||||
unsafe { self.unsafe_set((i, i), diag.unsafe_at(i)) }
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
@ -688,7 +702,9 @@ macro_rules! from_homogeneous_impl(
|
||||
|
||||
macro_rules! outer_impl(
|
||||
($t: ident, $m: ident) => (
|
||||
impl<N: Copy + Mul<N, Output = N> + Zero> Outer<$m<N>> for $t<N> {
|
||||
impl<N: Copy + Mul<N, Output = N> + Zero> Outer for $t<N> {
|
||||
type OuterProductType = $m<N>;
|
||||
|
||||
#[inline]
|
||||
fn outer(&self, other: &$t<N>) -> $m<N> {
|
||||
let mut res: $m<N> = ::zero();
|
||||
|
@ -11,7 +11,7 @@ use rand::{Rand, Rng};
|
||||
use num::{Zero, One};
|
||||
use traits::operations::{ApproxEq, POrd, POrdering, Axpy};
|
||||
use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec, Shape,
|
||||
NumPnt, FloatPnt, BaseFloat, BaseNum, Bounded};
|
||||
NumPnt, FloatPnt, BaseFloat, BaseNum, Bounded, Repeat};
|
||||
use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous};
|
||||
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
|
||||
#[cfg(feature="arbitrary")]
|
||||
@ -29,10 +29,11 @@ impl<N> Pnt0<N> {
|
||||
pub fn new() -> Pnt0<N> {
|
||||
Pnt0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new point. The parameter is not taken in account.
|
||||
impl<N> Repeat<N> for Pnt0<N> {
|
||||
#[inline]
|
||||
pub fn new_repeat(_: N) -> Pnt0<N> {
|
||||
fn repeat(_: N) -> Pnt0<N> {
|
||||
Pnt0(PhantomData)
|
||||
}
|
||||
}
|
||||
@ -57,7 +58,7 @@ as_array_impl!(Pnt1, 1);
|
||||
index_impl!(Pnt1);
|
||||
indexable_impl!(Pnt1, 1);
|
||||
at_fast_impl!(Pnt1, 1);
|
||||
new_repeat_impl!(Pnt1, val, x);
|
||||
repeat_impl!(Pnt1, val, x);
|
||||
dim_impl!(Pnt1, 1);
|
||||
container_impl!(Pnt1);
|
||||
pnt_as_vec_impl!(Pnt1, Vec1, x);
|
||||
@ -99,7 +100,7 @@ as_array_impl!(Pnt2, 2);
|
||||
index_impl!(Pnt2);
|
||||
indexable_impl!(Pnt2, 2);
|
||||
at_fast_impl!(Pnt2, 2);
|
||||
new_repeat_impl!(Pnt2, val, x, y);
|
||||
repeat_impl!(Pnt2, val, x, y);
|
||||
dim_impl!(Pnt2, 2);
|
||||
container_impl!(Pnt2);
|
||||
pnt_as_vec_impl!(Pnt2, Vec2, x, y);
|
||||
@ -143,7 +144,7 @@ as_array_impl!(Pnt3, 3);
|
||||
index_impl!(Pnt3);
|
||||
indexable_impl!(Pnt3, 3);
|
||||
at_fast_impl!(Pnt3, 3);
|
||||
new_repeat_impl!(Pnt3, val, x, y, z);
|
||||
repeat_impl!(Pnt3, val, x, y, z);
|
||||
dim_impl!(Pnt3, 3);
|
||||
container_impl!(Pnt3);
|
||||
pnt_as_vec_impl!(Pnt3, Vec3, x, y, z);
|
||||
@ -189,7 +190,7 @@ as_array_impl!(Pnt4, 4);
|
||||
index_impl!(Pnt4);
|
||||
indexable_impl!(Pnt4, 4);
|
||||
at_fast_impl!(Pnt4, 4);
|
||||
new_repeat_impl!(Pnt4, val, x, y, z, w);
|
||||
repeat_impl!(Pnt4, val, x, y, z, w);
|
||||
dim_impl!(Pnt4, 4);
|
||||
container_impl!(Pnt4);
|
||||
pnt_as_vec_impl!(Pnt4, Vec4, x, y, z, w);
|
||||
@ -237,7 +238,7 @@ as_array_impl!(Pnt5, 5);
|
||||
index_impl!(Pnt5);
|
||||
indexable_impl!(Pnt5, 5);
|
||||
at_fast_impl!(Pnt5, 5);
|
||||
new_repeat_impl!(Pnt5, val, x, y, z, w, a);
|
||||
repeat_impl!(Pnt5, val, x, y, z, w, a);
|
||||
dim_impl!(Pnt5, 5);
|
||||
container_impl!(Pnt5);
|
||||
pnt_as_vec_impl!(Pnt5, Vec5, x, y, z, w, a);
|
||||
@ -287,7 +288,7 @@ as_array_impl!(Pnt6, 6);
|
||||
index_impl!(Pnt6);
|
||||
indexable_impl!(Pnt6, 6);
|
||||
at_fast_impl!(Pnt6, 6);
|
||||
new_repeat_impl!(Pnt6, val, x, y, z, w, a, b);
|
||||
repeat_impl!(Pnt6, val, x, y, z, w, a, b);
|
||||
dim_impl!(Pnt6, 6);
|
||||
container_impl!(Pnt6);
|
||||
pnt_as_vec_impl!(Pnt6, Vec6, x, y, z, w, a, b);
|
||||
|
@ -11,7 +11,7 @@ use num::{Zero, One};
|
||||
use structs::{Vec3, Pnt3, Rot3, Mat3};
|
||||
use traits::operations::{ApproxEq, Inv, POrd, POrdering, Axpy};
|
||||
use traits::structure::{Cast, Indexable, Iterable, IterableMut, Dim, Shape, BaseFloat, BaseNum,
|
||||
Bounded};
|
||||
Bounded, Repeat};
|
||||
use traits::geometry::{Norm, Rotation, Rotate, Transform};
|
||||
|
||||
#[cfg(feature="arbitrary")]
|
||||
@ -495,7 +495,7 @@ as_array_impl!(Quat, 4);
|
||||
index_impl!(Quat);
|
||||
indexable_impl!(Quat, 4);
|
||||
at_fast_impl!(Quat, 4);
|
||||
new_repeat_impl!(Quat, val, w, i, j, k);
|
||||
repeat_impl!(Quat, val, w, i, j, k);
|
||||
dim_impl!(Quat, 3);
|
||||
container_impl!(Quat);
|
||||
add_impl!(Quat, w, i, j, k);
|
||||
|
@ -7,7 +7,7 @@ use rand::{Rand, Rng};
|
||||
use num::{Zero, One};
|
||||
use traits::geometry::{Rotate, Rotation, AbsoluteRotate, RotationMatrix, Transform, ToHomogeneous,
|
||||
Norm, Cross};
|
||||
use traits::structure::{Cast, Dim, Row, Col, BaseFloat, BaseNum, };
|
||||
use traits::structure::{Cast, Dim, Row, Col, BaseFloat, BaseNum, Eye, Diag};
|
||||
use traits::operations::{Absolute, Inv, Transpose, ApproxEq};
|
||||
use structs::vec::{Vec1, Vec2, Vec3, Vec4};
|
||||
use structs::pnt::{Pnt2, Pnt3, Pnt4};
|
||||
@ -408,6 +408,7 @@ vec_mul_rot_impl!(Rot2, Vec2);
|
||||
rot_mul_pnt_impl!(Rot2, Pnt2);
|
||||
pnt_mul_rot_impl!(Rot2, Pnt2);
|
||||
one_impl!(Rot2);
|
||||
eye_impl!(Rot2);
|
||||
rotation_matrix_impl!(Rot2, Vec2, Vec1);
|
||||
col_impl!(Rot2, Vec2);
|
||||
row_impl!(Rot2, Vec2);
|
||||
@ -417,6 +418,7 @@ to_homogeneous_impl!(Rot2, Mat3);
|
||||
inv_impl!(Rot2);
|
||||
transpose_impl!(Rot2);
|
||||
approx_eq_impl!(Rot2);
|
||||
diag_impl!(Rot2, Vec2);
|
||||
|
||||
submat_impl!(Rot3, Mat3);
|
||||
rotate_impl!(Rot3, Vec3, Pnt3);
|
||||
@ -428,6 +430,7 @@ vec_mul_rot_impl!(Rot3, Vec3);
|
||||
rot_mul_pnt_impl!(Rot3, Pnt3);
|
||||
pnt_mul_rot_impl!(Rot3, Pnt3);
|
||||
one_impl!(Rot3);
|
||||
eye_impl!(Rot3);
|
||||
rotation_matrix_impl!(Rot3, Vec3, Vec3);
|
||||
col_impl!(Rot3, Vec3);
|
||||
row_impl!(Rot3, Vec3);
|
||||
@ -437,6 +440,7 @@ to_homogeneous_impl!(Rot3, Mat4);
|
||||
inv_impl!(Rot3);
|
||||
transpose_impl!(Rot3);
|
||||
approx_eq_impl!(Rot3);
|
||||
diag_impl!(Rot3, Vec3);
|
||||
|
||||
submat_impl!(Rot4, Mat4);
|
||||
rotate_impl!(Rot4, Vec4, Pnt4);
|
||||
@ -448,6 +452,7 @@ vec_mul_rot_impl!(Rot4, Vec4);
|
||||
rot_mul_pnt_impl!(Rot4, Pnt4);
|
||||
pnt_mul_rot_impl!(Rot4, Pnt4);
|
||||
one_impl!(Rot4);
|
||||
eye_impl!(Rot4);
|
||||
rotation_matrix_impl!(Rot4, Vec4, Vec4);
|
||||
col_impl!(Rot4, Vec4);
|
||||
row_impl!(Rot4, Vec4);
|
||||
@ -457,3 +462,4 @@ to_homogeneous_impl!(Rot4, Mat5);
|
||||
inv_impl!(Rot4);
|
||||
transpose_impl!(Rot4);
|
||||
approx_eq_impl!(Rot4);
|
||||
diag_impl!(Rot4, Vec4);
|
||||
|
@ -102,6 +102,38 @@ macro_rules! one_impl(
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! eye_impl(
|
||||
($t: ident) => (
|
||||
impl<N: BaseNum> Eye for $t<N> {
|
||||
#[inline]
|
||||
fn new_identity(dim: usize) -> $t<N> {
|
||||
if dim != ::dim::<$t<N>>() {
|
||||
panic!("Dimension mismatch: should be {}, got {}.", ::dim::<$t<N>>(), dim);
|
||||
}
|
||||
else {
|
||||
::one()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! diag_impl(
|
||||
($t: ident, $tv: ident) => (
|
||||
impl<N: Copy + Zero> Diag<$tv<N>> for $t<N> {
|
||||
#[inline]
|
||||
fn from_diag(diag: &$tv<N>) -> $t<N> {
|
||||
$t { submat: Diag::from_diag(diag) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn diag(&self) -> $tv<N> {
|
||||
self.submat.diag()
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! rot_mul_rot_impl(
|
||||
($t: ident) => (
|
||||
impl<N: BaseNum> Mul<$t<N>> for $t<N> {
|
||||
|
@ -6,7 +6,7 @@ use structs::vec::{Vec1, Vec2, Vec3, Vec4};
|
||||
use structs::mat::Mat3;
|
||||
|
||||
impl<N: Copy + Mul<N, Output = N> + Sub<N, Output = N>> Cross for Vec2<N> {
|
||||
type Output = Vec1<N>;
|
||||
type CrossProductType = Vec1<N>;
|
||||
|
||||
#[inline]
|
||||
fn cross(&self, other: &Vec2<N>) -> Vec1<N> {
|
||||
@ -23,7 +23,7 @@ impl<N: Neg<Output = N> + Copy> CrossMatrix<Vec2<N>> for Vec2<N> {
|
||||
}
|
||||
|
||||
impl<N: Copy + Mul<N, Output = N> + Sub<N, Output = N>> Cross for Vec3<N> {
|
||||
type Output = Vec3<N>;
|
||||
type CrossProductType = Vec3<N>;
|
||||
|
||||
#[inline]
|
||||
fn cross(&self, other: &Vec3<N>) -> Vec3<N> {
|
||||
|
@ -13,7 +13,7 @@ use traits::operations::{ApproxEq, POrd, POrdering, Axpy, Absolute};
|
||||
use traits::geometry::{Transform, Rotate, FromHomogeneous, ToHomogeneous, Dot, Norm,
|
||||
Translation, Translate};
|
||||
use traits::structure::{Basis, Cast, Dim, Indexable, Iterable, IterableMut, Shape, NumVec,
|
||||
FloatVec, BaseFloat, BaseNum, Bounded};
|
||||
FloatVec, BaseFloat, BaseNum, Bounded, Repeat};
|
||||
use structs::pnt::{Pnt1, Pnt2, Pnt3, Pnt4, Pnt5, Pnt6};
|
||||
|
||||
#[cfg(feature="arbitrary")]
|
||||
@ -31,10 +31,11 @@ impl<N> Vec0<N> {
|
||||
pub fn new() -> Vec0<N> {
|
||||
Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new vector. The parameter is not taken in account.
|
||||
impl<N> Repeat<N> for Vec0<N> {
|
||||
#[inline]
|
||||
pub fn new_repeat(_: N) -> Vec0<N> {
|
||||
fn repeat(_: N) -> Vec0<N> {
|
||||
Vec0(PhantomData)
|
||||
}
|
||||
}
|
||||
@ -55,7 +56,7 @@ as_array_impl!(Vec1, 1);
|
||||
index_impl!(Vec1);
|
||||
indexable_impl!(Vec1, 1);
|
||||
at_fast_impl!(Vec1, 1);
|
||||
new_repeat_impl!(Vec1, val, x);
|
||||
repeat_impl!(Vec1, val, x);
|
||||
dim_impl!(Vec1, 1);
|
||||
container_impl!(Vec1);
|
||||
// (specialized); basis_impl!(Vec1, 1);
|
||||
@ -108,7 +109,7 @@ as_array_impl!(Vec2, 2);
|
||||
index_impl!(Vec2);
|
||||
indexable_impl!(Vec2, 2);
|
||||
at_fast_impl!(Vec2, 2);
|
||||
new_repeat_impl!(Vec2, val, x, y);
|
||||
repeat_impl!(Vec2, val, x, y);
|
||||
dim_impl!(Vec2, 2);
|
||||
container_impl!(Vec2);
|
||||
// (specialized); basis_impl!(Vec2, 1);
|
||||
@ -163,7 +164,7 @@ as_array_impl!(Vec3, 3);
|
||||
index_impl!(Vec3);
|
||||
indexable_impl!(Vec3, 3);
|
||||
at_fast_impl!(Vec3, 3);
|
||||
new_repeat_impl!(Vec3, val, x, y, z);
|
||||
repeat_impl!(Vec3, val, x, y, z);
|
||||
dim_impl!(Vec3, 3);
|
||||
container_impl!(Vec3);
|
||||
// (specialized); basis_impl!(Vec3, 1);
|
||||
@ -221,7 +222,7 @@ as_array_impl!(Vec4, 4);
|
||||
index_impl!(Vec4);
|
||||
indexable_impl!(Vec4, 4);
|
||||
at_fast_impl!(Vec4, 4);
|
||||
new_repeat_impl!(Vec4, val, x, y, z, w);
|
||||
repeat_impl!(Vec4, val, x, y, z, w);
|
||||
dim_impl!(Vec4, 4);
|
||||
container_impl!(Vec4);
|
||||
basis_impl!(Vec4, 4);
|
||||
@ -280,7 +281,7 @@ as_array_impl!(Vec5, 5);
|
||||
index_impl!(Vec5);
|
||||
indexable_impl!(Vec5, 5);
|
||||
at_fast_impl!(Vec5, 5);
|
||||
new_repeat_impl!(Vec5, val, x, y, z, w, a);
|
||||
repeat_impl!(Vec5, val, x, y, z, w, a);
|
||||
dim_impl!(Vec5, 5);
|
||||
container_impl!(Vec5);
|
||||
basis_impl!(Vec5, 5);
|
||||
@ -341,7 +342,7 @@ as_array_impl!(Vec6, 6);
|
||||
index_impl!(Vec6);
|
||||
indexable_impl!(Vec6, 6);
|
||||
at_fast_impl!(Vec6, 6);
|
||||
new_repeat_impl!(Vec6, val, x, y, z, w, a, b);
|
||||
repeat_impl!(Vec6, val, x, y, z, w, a, b);
|
||||
dim_impl!(Vec6, 6);
|
||||
container_impl!(Vec6);
|
||||
basis_impl!(Vec6, 6);
|
||||
|
@ -227,12 +227,12 @@ macro_rules! index_impl(
|
||||
)
|
||||
);
|
||||
|
||||
macro_rules! new_repeat_impl(
|
||||
macro_rules! repeat_impl(
|
||||
($t: ident, $param: ident, $($compN: ident),+) => (
|
||||
impl<N: Copy> $t<N> {
|
||||
impl<N: Copy> Repeat<N> for $t<N> {
|
||||
/// Creates a new vector with all its components equal to a given value.
|
||||
#[inline]
|
||||
pub fn new_repeat($param: N) -> $t<N> {
|
||||
fn repeat($param: N) -> $t<N> {
|
||||
$t{
|
||||
$($compN: $param ),+
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
//! Traits of operations having a well-known or explicit geometric meaning.
|
||||
|
||||
use std::ops::Neg;
|
||||
use traits::structure::{BaseFloat, Mat};
|
||||
use traits::structure::{BaseFloat, SquareMat};
|
||||
|
||||
/// Trait of object which represent a translation, and to wich new translation
|
||||
/// can be appended.
|
||||
@ -143,7 +143,7 @@ impl<LV: Neg<Output = LV> + Copy, AV, M: Rotation<AV> + Translation<LV>> Rotatio
|
||||
/// be implemented by quaternions to convert them to a rotation matrix.
|
||||
pub trait RotationMatrix<N, LV, AV> : Rotation<AV> {
|
||||
/// The output rotation matrix type.
|
||||
type Output: Mat<N, LV, LV> + Rotation<AV>;
|
||||
type Output: SquareMat<N, LV> + Rotation<AV>;
|
||||
|
||||
/// Gets the rotation matrix represented by `self`.
|
||||
fn to_rot_mat(&self) -> Self::Output;
|
||||
@ -232,10 +232,10 @@ pub trait Norm<N: BaseFloat> {
|
||||
*/
|
||||
pub trait Cross {
|
||||
/// The cross product output.
|
||||
type Output;
|
||||
type CrossProductType;
|
||||
|
||||
/// Computes the cross product between two elements (usually vectors).
|
||||
fn cross(&self, other: &Self) -> Self::Output;
|
||||
fn cross(&self, other: &Self) -> Self::CrossProductType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,7 +6,8 @@ pub use traits::geometry::{AbsoluteRotate, Cross, CrossMatrix, Dot, FromHomogene
|
||||
|
||||
pub use traits::structure::{FloatVec, FloatPnt, Basis, Cast, Col, Dim, Indexable, Iterable,
|
||||
IterableMut, Mat, SquareMat, Row, NumVec, NumPnt, PntAsVec, ColSlice,
|
||||
RowSlice, Diag, Eye, Shape, BaseFloat, BaseNum, Bounded};
|
||||
RowSlice, Diag, DiagMut, Eye, Repeat, Shape, BaseFloat, BaseNum,
|
||||
Bounded};
|
||||
|
||||
pub use traits::operations::{Absolute, ApproxEq, Axpy, Cov, Det, Inv, Mean, Outer, POrd, Transpose,
|
||||
EigenQR};
|
||||
|
@ -299,9 +299,12 @@ pub trait Transpose {
|
||||
}
|
||||
|
||||
/// Traits of objects having an outer product.
|
||||
pub trait Outer<M> {
|
||||
pub trait Outer {
|
||||
/// Result type of the outer product.
|
||||
type OuterProductType;
|
||||
|
||||
/// Computes the outer product: `a * b`
|
||||
fn outer(&self, other: &Self) -> M;
|
||||
fn outer(&self, other: &Self) -> Self::OuterProductType;
|
||||
}
|
||||
|
||||
/// Trait for computing the covariance of a set of data.
|
||||
|
@ -59,12 +59,14 @@ pub trait Cast<T> {
|
||||
/// Trait of matrices.
|
||||
///
|
||||
/// A matrix has rows and columns and are able to multiply them.
|
||||
pub trait Mat<N, R, C: Mul<Self>>: Row<R> + Col<C> + Mul<R> + Index<(usize, usize), Output = N> { }
|
||||
pub trait Mat<N, R, C: Mul<Self, Output = R>>: Row<R> + Col<C> + Mul<R, Output = C> +
|
||||
Index<(usize, usize), Output = N>
|
||||
{ }
|
||||
|
||||
impl<N, M, R, C> Mat<N, R, C> for M
|
||||
where M: Row<R> + Col<C> + Mul<R> + Index<(usize, usize), Output = N>,
|
||||
C: Mul<M>,
|
||||
{}
|
||||
where M: Row<R> + Col<C> + Mul<R, Output = C> + Index<(usize, usize), Output = N>,
|
||||
C: Mul<M, Output = R>,
|
||||
{ }
|
||||
|
||||
/// Trait implemented by square matrices.
|
||||
pub trait SquareMat<N, V>: Mat<N, V, V> +
|
||||
@ -81,6 +83,12 @@ pub trait Eye {
|
||||
fn new_identity(dim: usize) -> Self;
|
||||
}
|
||||
|
||||
/// Trait for constructiong an object repeating a value.
|
||||
pub trait Repeat<N> {
|
||||
/// Returns a value with filled by `val`.
|
||||
fn repeat(val: N) -> Self;
|
||||
}
|
||||
|
||||
/// Types that have maximum and minimum value.
|
||||
pub trait Bounded {
|
||||
/// The minimum value.
|
||||
@ -155,13 +163,16 @@ pub trait Diag<V> {
|
||||
/// Creates a new matrix with the given diagonal.
|
||||
fn from_diag(diag: &V) -> Self;
|
||||
|
||||
/// Sets the diagonal of this matrix.
|
||||
fn set_diag(&mut self, diag: &V);
|
||||
|
||||
/// The diagonal of this matrix.
|
||||
fn diag(&self) -> V;
|
||||
}
|
||||
|
||||
/// Trait to set the diagonal of square matrices.
|
||||
pub trait DiagMut<V>: Diag<V> {
|
||||
/// Sets the diagonal of this matrix.
|
||||
fn set_diag(&mut self, diag: &V);
|
||||
}
|
||||
|
||||
/// The shape of an indexable object.
|
||||
pub trait Shape<I>: Index<I> {
|
||||
/// Returns the shape of an indexable object.
|
||||
|
Loading…
Reference in New Issue
Block a user