2015-01-08 04:11:09 +08:00
|
|
|
#![macro_use]
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! submat_impl(
|
|
|
|
($t: ident, $submat: ident) => (
|
|
|
|
impl<N> $t<N> {
|
|
|
|
#[inline]
|
|
|
|
pub fn submat<'r>(&'r self) -> &'r $submat<N> {
|
2014-07-05 16:24:43 +08:00
|
|
|
&self.submat
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! rotate_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident, $tp: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: BaseNum> Rotate<$tv<N>> for $t<N> {
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn rotate(&self, v: &$tv<N>) -> $tv<N> {
|
|
|
|
*self * *v
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn inv_rotate(&self, v: &$tv<N>) -> $tv<N> {
|
|
|
|
*v * *self
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: BaseNum> Rotate<$tp<N>> for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn rotate(&self, p: &$tp<N>) -> $tp<N> {
|
|
|
|
*self * *p
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn inv_rotate(&self, p: &$tp<N>) -> $tp<N> {
|
|
|
|
*p * *self
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! transform_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident, $tp: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: BaseNum> Transform<$tv<N>> for $t<N> {
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn transform(&self, v: &$tv<N>) -> $tv<N> {
|
|
|
|
self.rotate(v)
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn inv_transform(&self, v: &$tv<N>) -> $tv<N> {
|
|
|
|
self.inv_rotate(v)
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: BaseNum> Transform<$tp<N>> for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn transform(&self, p: &$tp<N>) -> $tp<N> {
|
|
|
|
self.rotate(p)
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2014-11-26 21:17:34 +08:00
|
|
|
fn inv_transform(&self, p: &$tp<N>) -> $tp<N> {
|
|
|
|
self.inv_rotate(p)
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! dim_impl(
|
|
|
|
($t: ident, $dim: expr) => (
|
|
|
|
impl<N> Dim for $t<N> {
|
|
|
|
#[inline]
|
2015-01-10 05:26:05 +08:00
|
|
|
fn dim(_: Option<$t<N>>) -> usize {
|
2013-10-06 22:54:09 +08:00
|
|
|
$dim
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! rotation_matrix_impl(
|
|
|
|
($t: ident, $tlv: ident, $tav: ident) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: Zero + BaseNum + Cast<f64> + BaseFloat> RotationMatrix<N, $tlv<N>, $tav<N>> for $t<N> {
|
|
|
|
type Output = $t<N>;
|
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
|
|
|
fn to_rot_mat(&self) -> $t<N> {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! one_impl(
|
|
|
|
($t: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: BaseNum> One for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
|
|
|
fn one() -> $t<N> {
|
2014-11-16 21:04:15 +08:00
|
|
|
$t { submat: ::one() }
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! rot_mul_rot_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: BaseNum> Mul<$t<N>> for $t<N> {
|
|
|
|
type Output = $t<N>;
|
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2014-12-18 06:28:32 +08:00
|
|
|
fn mul(self, right: $t<N>) -> $t<N> {
|
2014-11-26 21:17:34 +08:00
|
|
|
$t { submat: self.submat * right.submat }
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! rot_mul_vec_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: BaseNum> Mul<$tv<N>> for $t<N> {
|
|
|
|
type Output = $tv<N>;
|
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2014-12-18 06:28:32 +08:00
|
|
|
fn mul(self, right: $tv<N>) -> $tv<N> {
|
|
|
|
self.submat * right
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
2014-10-10 17:23:52 +08:00
|
|
|
macro_rules! rot_mul_pnt_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident) => (
|
2014-12-19 22:33:01 +08:00
|
|
|
rot_mul_vec_impl!($t, $tv);
|
2014-10-10 17:23:52 +08:00
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
macro_rules! vec_mul_rot_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: BaseNum> Mul<$t<N>> for $tv<N> {
|
|
|
|
type Output = $tv<N>;
|
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2014-12-18 06:28:32 +08:00
|
|
|
fn mul(self, right: $t<N>) -> $tv<N> {
|
|
|
|
self * right.submat
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
2014-10-10 17:23:52 +08:00
|
|
|
macro_rules! pnt_mul_rot_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident) => (
|
2014-12-19 22:33:01 +08:00
|
|
|
vec_mul_rot_impl!($t, $tv);
|
2014-10-10 17:23:52 +08:00
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
macro_rules! inv_impl(
|
|
|
|
($t: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: Copy> Inv for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2015-02-02 06:23:57 +08:00
|
|
|
fn inv_mut(&mut self) -> bool {
|
|
|
|
self.transpose_mut();
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
// always succeed
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2015-02-02 06:23:57 +08:00
|
|
|
fn inv(&self) -> Option<$t<N>> {
|
2013-10-06 22:54:09 +08:00
|
|
|
// always succeed
|
2015-02-02 06:23:57 +08:00
|
|
|
Some(self.transpose())
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! transpose_impl(
|
|
|
|
($t: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: Copy> Transpose for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2015-02-02 06:23:57 +08:00
|
|
|
fn transpose(&self) -> $t<N> {
|
|
|
|
$t { submat: Transpose::transpose(&self.submat) }
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2015-02-02 06:23:57 +08:00
|
|
|
fn transpose_mut(&mut self) {
|
|
|
|
self.submat.transpose_mut()
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! row_impl(
|
|
|
|
($t: ident, $tv: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: Copy + Zero> Row<$tv<N>> for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2015-01-10 05:26:05 +08:00
|
|
|
fn nrows(&self) -> usize {
|
2013-10-06 22:54:09 +08:00
|
|
|
self.submat.nrows()
|
|
|
|
}
|
|
|
|
#[inline]
|
2015-01-10 05:26:05 +08:00
|
|
|
fn row(&self, i: usize) -> $tv<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
self.submat.row(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2015-01-10 05:26:05 +08:00
|
|
|
fn set_row(&mut self, i: usize, row: $tv<N>) {
|
2013-10-06 22:54:09 +08:00
|
|
|
self.submat.set_row(i, row);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! col_impl(
|
|
|
|
($t: ident, $tv: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: Copy + Zero> Col<$tv<N>> for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2015-01-10 05:26:05 +08:00
|
|
|
fn ncols(&self) -> usize {
|
2013-10-06 22:54:09 +08:00
|
|
|
self.submat.ncols()
|
|
|
|
}
|
|
|
|
#[inline]
|
2015-01-10 05:26:05 +08:00
|
|
|
fn col(&self, i: usize) -> $tv<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
self.submat.col(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2015-01-10 05:26:05 +08:00
|
|
|
fn set_col(&mut self, i: usize, col: $tv<N>) {
|
2013-10-06 22:54:09 +08:00
|
|
|
self.submat.set_col(i, col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
2014-09-18 10:20:36 +08:00
|
|
|
macro_rules! index_impl(
|
2014-10-26 05:02:16 +08:00
|
|
|
($t: ident) => (
|
2015-01-10 05:26:05 +08:00
|
|
|
impl<N> Index<(usize, usize)> for $t<N> {
|
2015-01-05 02:03:28 +08:00
|
|
|
type Output = N;
|
|
|
|
|
2015-01-10 05:26:05 +08:00
|
|
|
fn index(&self, i: &(usize, usize)) -> &N {
|
2014-09-18 10:20:36 +08:00
|
|
|
&self.submat[*i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-09-18 10:20:36 +08:00
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
macro_rules! to_homogeneous_impl(
|
|
|
|
($t: ident, $tm: ident) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: BaseNum> ToHomogeneous<$tm<N>> for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2014-11-22 00:00:39 +08:00
|
|
|
fn to_homogeneous(&self) -> $tm<N> {
|
|
|
|
self.submat.to_homogeneous()
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! approx_eq_impl(
|
|
|
|
($t: ident) => (
|
|
|
|
impl<N: ApproxEq<N>> ApproxEq<N> for $t<N> {
|
|
|
|
#[inline]
|
2014-01-10 03:48:30 +08:00
|
|
|
fn approx_epsilon(_: Option<$t<N>>) -> N {
|
|
|
|
ApproxEq::approx_epsilon(None::<N>)
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
|
2015-01-01 05:08:42 +08:00
|
|
|
#[inline]
|
|
|
|
fn approx_ulps(_: Option<$t<N>>) -> u32 {
|
|
|
|
ApproxEq::approx_ulps(None::<N>)
|
|
|
|
}
|
|
|
|
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2014-12-02 01:50:11 +08:00
|
|
|
fn approx_eq(&self, other: &$t<N>) -> bool {
|
|
|
|
ApproxEq::approx_eq(&self.submat, &other.submat)
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2014-12-02 01:50:11 +08:00
|
|
|
fn approx_eq_eps(&self, other: &$t<N>, epsilon: &N) -> bool {
|
|
|
|
ApproxEq::approx_eq_eps(&self.submat, &other.submat, epsilon)
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
2015-01-01 05:08:42 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn approx_eq_ulps(&self, other: &$t<N>, ulps: u32) -> bool {
|
|
|
|
ApproxEq::approx_eq_ulps(&self.submat, &other.submat, ulps)
|
|
|
|
}
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2013-10-06 22:54:09 +08:00
|
|
|
|
|
|
|
macro_rules! absolute_impl(
|
|
|
|
($t: ident, $tm: ident) => (
|
2014-11-15 22:47:59 +08:00
|
|
|
impl<N: Absolute<N>> Absolute<$tm<N>> for $t<N> {
|
2013-10-06 22:54:09 +08:00
|
|
|
#[inline]
|
2013-10-17 03:44:33 +08:00
|
|
|
fn abs(m: &$t<N>) -> $tm<N> {
|
|
|
|
Absolute::abs(&m.submat)
|
2013-10-06 22:54:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|