2015-01-08 04:11:09 +08:00
|
|
|
#![macro_use]
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
macro_rules! orig_impl(
|
2015-01-10 04:55:15 +08:00
|
|
|
($t: ident, $($compN: ident),+) => (
|
2014-10-10 17:23:52 +08:00
|
|
|
impl<N: Zero> Orig for $t<N> {
|
|
|
|
#[inline]
|
|
|
|
fn orig() -> $t<N> {
|
|
|
|
$t {
|
2015-01-10 04:55:15 +08:00
|
|
|
$($compN: ::zero() ),+
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn is_orig(&self) -> bool {
|
2015-01-10 04:55:15 +08:00
|
|
|
$(self.$compN.is_zero() )&&+
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
macro_rules! pnt_sub_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: Copy + Sub<N, Output = N>> Sub<$t<N>> for $t<N> {
|
|
|
|
type Output = $tv<N>;
|
|
|
|
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
2014-12-18 06:28:32 +08:00
|
|
|
fn sub(self, right: $t<N>) -> $tv<N> {
|
2014-11-26 21:17:34 +08:00
|
|
|
*self.as_vec() - *right.as_vec()
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
macro_rules! pnt_add_vec_impl(
|
2015-01-10 04:55:15 +08:00
|
|
|
($t: ident, $tv: ident, $($compN: ident),+) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: Copy + Add<N, Output = N>> Add<$tv<N>> for $t<N> {
|
|
|
|
type Output = $t<N>;
|
|
|
|
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
2014-12-18 06:28:32 +08:00
|
|
|
fn add(self, right: $tv<N>) -> $t<N> {
|
2015-01-10 04:55:15 +08:00
|
|
|
$t::new($(self.$compN + right.$compN),+)
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
macro_rules! pnt_sub_vec_impl(
|
2015-01-10 04:55:15 +08:00
|
|
|
($t: ident, $tv: ident, $($compN: ident),+) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: Copy + Sub<N, Output = N>> Sub<$tv<N>> for $t<N> {
|
|
|
|
type Output = $t<N>;
|
|
|
|
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
2014-12-18 06:28:32 +08:00
|
|
|
fn sub(self, right: $tv<N>) -> $t<N> {
|
2015-01-10 04:55:15 +08:00
|
|
|
$t::new($(self.$compN - right.$compN),+)
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
macro_rules! pnt_as_vec_impl(
|
2015-01-10 04:55:15 +08:00
|
|
|
($t: ident, $tv: ident, $($compN: ident),+) => (
|
2014-10-10 17:23:52 +08:00
|
|
|
impl<N> $t<N> {
|
2014-10-12 16:35:56 +08:00
|
|
|
/// Converts this point to its associated vector.
|
2014-10-10 18:19:37 +08:00
|
|
|
#[inline]
|
|
|
|
pub fn to_vec(self) -> $tv<N> {
|
|
|
|
$tv::new(
|
2015-01-10 04:55:15 +08:00
|
|
|
$(self.$compN),+
|
2014-10-10 18:19:37 +08:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2014-10-12 16:35:56 +08:00
|
|
|
/// Converts a reference to this point to a reference to its associated vector.
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
|
|
|
pub fn as_vec<'a>(&'a self) -> &'a $tv<N> {
|
|
|
|
unsafe {
|
|
|
|
mem::transmute(self)
|
|
|
|
}
|
|
|
|
}
|
2014-10-11 02:56:40 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn set_coords(&mut self, v: $tv<N>) {
|
2015-01-10 04:55:15 +08:00
|
|
|
$(self.$compN = v.$compN;)+
|
2014-10-11 02:56:40 +08:00
|
|
|
}
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<N> PntAsVec<$tv<N>> for $t<N> {
|
2014-10-10 18:19:37 +08:00
|
|
|
#[inline]
|
|
|
|
fn to_vec(self) -> $tv<N> {
|
|
|
|
self.to_vec()
|
|
|
|
}
|
|
|
|
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
|
|
|
fn as_vec<'a>(&'a self) -> &'a $tv<N> {
|
|
|
|
self.as_vec()
|
|
|
|
}
|
2014-10-11 02:56:40 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn set_coords(&mut self, v: $tv<N>) {
|
|
|
|
self.set_coords(v)
|
|
|
|
}
|
2014-10-10 17:23:52 +08:00
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
macro_rules! pnt_to_homogeneous_impl(
|
2015-01-10 04:55:15 +08:00
|
|
|
($t: ident, $t2: ident, $extra: ident, $($compN: ident),+) => (
|
2014-12-18 06:28:32 +08:00
|
|
|
impl<N: Copy + One + Zero> ToHomogeneous<$t2<N>> for $t<N> {
|
2014-11-22 00:00:39 +08:00
|
|
|
fn to_homogeneous(&self) -> $t2<N> {
|
2014-10-10 17:23:52 +08:00
|
|
|
let mut res: $t2<N> = Orig::orig();
|
|
|
|
|
2015-01-10 04:55:15 +08:00
|
|
|
$( res.$compN = self.$compN; )+
|
2014-11-16 21:04:15 +08:00
|
|
|
res.$extra = ::one();
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
macro_rules! pnt_from_homogeneous_impl(
|
2015-01-10 04:55:15 +08:00
|
|
|
($t: ident, $t2: ident, $extra: ident, $($compN: ident),+) => (
|
2015-01-05 02:03:28 +08:00
|
|
|
impl<N: Copy + Div<N, Output = N> + One + Zero> FromHomogeneous<$t2<N>> for $t<N> {
|
2014-10-10 17:23:52 +08:00
|
|
|
fn from(v: &$t2<N>) -> $t<N> {
|
|
|
|
let mut res: $t<N> = Orig::orig();
|
|
|
|
|
2015-01-10 04:55:15 +08:00
|
|
|
$( res.$compN = v.$compN / v.$extra; )+
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
res
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|
2014-10-26 22:04:47 +08:00
|
|
|
|
|
|
|
macro_rules! num_float_pnt_impl(
|
2014-11-26 21:17:34 +08:00
|
|
|
($t: ident, $tv: ident) => (
|
2014-10-26 22:04:47 +08:00
|
|
|
impl<N> NumPnt<N, $tv<N>> for $t<N>
|
2014-11-26 21:17:34 +08:00
|
|
|
where N: BaseNum {
|
2014-10-26 22:04:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<N> FloatPnt<N, $tv<N>> for $t<N>
|
2014-11-26 21:17:34 +08:00
|
|
|
where N: BaseFloat + ApproxEq<N> {
|
2014-10-26 22:04:47 +08:00
|
|
|
}
|
|
|
|
)
|
2014-12-19 22:33:01 +08:00
|
|
|
);
|