2015-01-10 06:01:46 +08:00
|
|
|
//! Points with dimensions known at compile-time.
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
#![allow(missing_docs)] // we allow missing to avoid having to document the point components.
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
use std::mem;
|
2014-12-24 02:01:49 +08:00
|
|
|
use std::slice::{Iter, IterMut};
|
2014-10-10 17:23:52 +08:00
|
|
|
use std::iter::{Iterator, FromIterator};
|
2015-01-04 16:37:56 +08:00
|
|
|
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut};
|
2014-11-19 19:11:32 +08:00
|
|
|
use traits::operations::{ApproxEq, POrd, POrdering, Axpy, ScalarAdd, ScalarSub, ScalarMul,
|
2014-10-29 02:17:04 +08:00
|
|
|
ScalarDiv};
|
2014-10-26 22:04:47 +08:00
|
|
|
use traits::structure::{Cast, Dim, Indexable, Iterable, IterableMut, PntAsVec, Shape,
|
2014-11-16 21:04:15 +08:00
|
|
|
NumPnt, FloatPnt, BaseFloat, BaseNum, Zero, One, Bounded};
|
2014-10-10 17:23:52 +08:00
|
|
|
use traits::geometry::{Orig, FromHomogeneous, ToHomogeneous};
|
|
|
|
use structs::vec::{Vec1, Vec2, Vec3, Vec4, Vec5, Vec6};
|
2015-01-10 08:36:13 +08:00
|
|
|
#[cfg(feature="arbitrary")]
|
|
|
|
use quickcheck::{Arbitrary, Gen};
|
2014-10-10 17:23:52 +08:00
|
|
|
|
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Point of dimension 0.
|
2015-02-01 23:15:55 +08:00
|
|
|
#[derive(Eq, PartialEq, RustcDecodable, Clone, Rand, Debug, Copy)]
|
2014-10-10 17:23:52 +08:00
|
|
|
pub struct Pnt0<N>;
|
|
|
|
|
|
|
|
impl<N> Pnt0<N> {
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Creates a new point.
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
|
|
|
pub fn new() -> Pnt0<N> {
|
|
|
|
Pnt0
|
|
|
|
}
|
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Creates a new point. The parameter is not taken in account.
|
2014-10-10 17:23:52 +08:00
|
|
|
#[inline]
|
|
|
|
pub fn new_repeat(_: N) -> Pnt0<N> {
|
|
|
|
Pnt0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Point of dimension 1.
|
2015-02-01 23:15:55 +08:00
|
|
|
#[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Rand, Debug, Copy)]
|
2014-10-10 17:23:52 +08:00
|
|
|
pub struct Pnt1<N> {
|
2015-01-10 06:01:46 +08:00
|
|
|
/// First component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub x: N
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:33:01 +08:00
|
|
|
new_impl!(Pnt1, x);
|
|
|
|
orig_impl!(Pnt1, x);
|
2015-01-10 05:34:57 +08:00
|
|
|
ord_impl!(Pnt1, x,);
|
2014-12-19 22:33:01 +08:00
|
|
|
scalar_mul_impl!(Pnt1, x);
|
|
|
|
scalar_div_impl!(Pnt1, x);
|
|
|
|
scalar_add_impl!(Pnt1, x);
|
|
|
|
scalar_sub_impl!(Pnt1, x);
|
|
|
|
vec_cast_impl!(Pnt1, x);
|
|
|
|
as_array_impl!(Pnt1, 1);
|
|
|
|
index_impl!(Pnt1);
|
|
|
|
indexable_impl!(Pnt1, 1);
|
|
|
|
at_fast_impl!(Pnt1, 1);
|
|
|
|
new_repeat_impl!(Pnt1, val, x);
|
|
|
|
dim_impl!(Pnt1, 1);
|
|
|
|
container_impl!(Pnt1);
|
|
|
|
pnt_as_vec_impl!(Pnt1, Vec1, x);
|
|
|
|
pnt_sub_impl!(Pnt1, Vec1);
|
|
|
|
neg_impl!(Pnt1, x);
|
|
|
|
pnt_add_vec_impl!(Pnt1, Vec1, x);
|
|
|
|
pnt_sub_vec_impl!(Pnt1, Vec1, x);
|
|
|
|
scalar_ops_impl!(Pnt1, x);
|
|
|
|
approx_eq_impl!(Pnt1, x);
|
|
|
|
from_iterator_impl!(Pnt1, iterator);
|
|
|
|
bounded_impl!(Pnt1, x);
|
|
|
|
axpy_impl!(Pnt1, x);
|
|
|
|
iterable_impl!(Pnt1, 1);
|
|
|
|
iterable_mut_impl!(Pnt1, 1);
|
|
|
|
pnt_to_homogeneous_impl!(Pnt1, Pnt2, y, x);
|
|
|
|
pnt_from_homogeneous_impl!(Pnt1, Pnt2, y, x);
|
|
|
|
num_float_pnt_impl!(Pnt1, Vec1);
|
2015-01-10 08:36:13 +08:00
|
|
|
arbitrary_pnt_impl!(Pnt1, x);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Point of dimension 2.
|
2015-02-01 23:15:55 +08:00
|
|
|
#[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Rand, Debug, Copy)]
|
2014-10-10 17:23:52 +08:00
|
|
|
pub struct Pnt2<N> {
|
2015-01-10 06:01:46 +08:00
|
|
|
/// First component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub x: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Second component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub y: N
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:33:01 +08:00
|
|
|
new_impl!(Pnt2, x, y);
|
|
|
|
orig_impl!(Pnt2, x, y);
|
|
|
|
ord_impl!(Pnt2, x, y);
|
|
|
|
scalar_mul_impl!(Pnt2, x, y);
|
|
|
|
scalar_div_impl!(Pnt2, x, y);
|
|
|
|
scalar_add_impl!(Pnt2, x, y);
|
|
|
|
scalar_sub_impl!(Pnt2, x, y);
|
|
|
|
vec_cast_impl!(Pnt2, x, y);
|
|
|
|
as_array_impl!(Pnt2, 2);
|
|
|
|
index_impl!(Pnt2);
|
|
|
|
indexable_impl!(Pnt2, 2);
|
|
|
|
at_fast_impl!(Pnt2, 2);
|
|
|
|
new_repeat_impl!(Pnt2, val, x, y);
|
|
|
|
dim_impl!(Pnt2, 2);
|
|
|
|
container_impl!(Pnt2);
|
|
|
|
pnt_as_vec_impl!(Pnt2, Vec2, x, y);
|
|
|
|
pnt_sub_impl!(Pnt2, Vec2);
|
|
|
|
neg_impl!(Pnt2, x, y);
|
|
|
|
pnt_add_vec_impl!(Pnt2, Vec2, x, y);
|
|
|
|
pnt_sub_vec_impl!(Pnt2, Vec2, x, y);
|
|
|
|
scalar_ops_impl!(Pnt2, x, y);
|
|
|
|
approx_eq_impl!(Pnt2, x, y);
|
|
|
|
from_iterator_impl!(Pnt2, iterator, iterator);
|
|
|
|
bounded_impl!(Pnt2, x, y);
|
|
|
|
axpy_impl!(Pnt2, x, y);
|
|
|
|
iterable_impl!(Pnt2, 2);
|
|
|
|
iterable_mut_impl!(Pnt2, 2);
|
|
|
|
pnt_to_homogeneous_impl!(Pnt2, Pnt3, z, x, y);
|
|
|
|
pnt_from_homogeneous_impl!(Pnt2, Pnt3, z, x, y);
|
|
|
|
num_float_pnt_impl!(Pnt2, Vec2);
|
2015-01-10 08:36:13 +08:00
|
|
|
arbitrary_pnt_impl!(Pnt2, x, y);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Point of dimension 3.
|
2015-02-01 23:15:55 +08:00
|
|
|
#[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Rand, Debug, Copy)]
|
2014-10-10 17:23:52 +08:00
|
|
|
pub struct Pnt3<N> {
|
2015-01-10 06:01:46 +08:00
|
|
|
/// First component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub x: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Second component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub y: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Third component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub z: N
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:33:01 +08:00
|
|
|
new_impl!(Pnt3, x, y, z);
|
|
|
|
orig_impl!(Pnt3, x, y, z);
|
|
|
|
ord_impl!(Pnt3, x, y, z);
|
|
|
|
scalar_mul_impl!(Pnt3, x, y, z);
|
|
|
|
scalar_div_impl!(Pnt3, x, y, z);
|
|
|
|
scalar_add_impl!(Pnt3, x, y, z);
|
|
|
|
scalar_sub_impl!(Pnt3, x, y, z);
|
|
|
|
vec_cast_impl!(Pnt3, x, y, z);
|
|
|
|
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);
|
|
|
|
dim_impl!(Pnt3, 3);
|
|
|
|
container_impl!(Pnt3);
|
|
|
|
pnt_as_vec_impl!(Pnt3, Vec3, x, y, z);
|
|
|
|
pnt_sub_impl!(Pnt3, Vec3);
|
|
|
|
neg_impl!(Pnt3, x, y, z);
|
|
|
|
pnt_add_vec_impl!(Pnt3, Vec3, x, y, z);
|
|
|
|
pnt_sub_vec_impl!(Pnt3, Vec3, x, y, z);
|
|
|
|
scalar_ops_impl!(Pnt3, x, y, z);
|
|
|
|
approx_eq_impl!(Pnt3, x, y, z);
|
|
|
|
from_iterator_impl!(Pnt3, iterator, iterator, iterator);
|
|
|
|
bounded_impl!(Pnt3, x, y, z);
|
|
|
|
axpy_impl!(Pnt3, x, y, z);
|
|
|
|
iterable_impl!(Pnt3, 3);
|
|
|
|
iterable_mut_impl!(Pnt3, 3);
|
|
|
|
pnt_to_homogeneous_impl!(Pnt3, Pnt4, w, x, y, z);
|
|
|
|
pnt_from_homogeneous_impl!(Pnt3, Pnt4, w, x, y, z);
|
|
|
|
num_float_pnt_impl!(Pnt3, Vec3);
|
2015-01-10 08:36:13 +08:00
|
|
|
arbitrary_pnt_impl!(Pnt3, x, y, z);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Point of dimension 4.
|
2015-02-01 23:15:55 +08:00
|
|
|
#[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Rand, Debug, Copy)]
|
2014-10-10 17:23:52 +08:00
|
|
|
pub struct Pnt4<N> {
|
2015-01-10 06:01:46 +08:00
|
|
|
/// First component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub x: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Second component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub y: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Third component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub z: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Fourth component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub w: N
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:33:01 +08:00
|
|
|
new_impl!(Pnt4, x, y, z, w);
|
|
|
|
orig_impl!(Pnt4, x, y, z, w);
|
|
|
|
ord_impl!(Pnt4, x, y, z, w);
|
|
|
|
scalar_mul_impl!(Pnt4, x, y, z, w);
|
|
|
|
scalar_div_impl!(Pnt4, x, y, z, w);
|
|
|
|
scalar_add_impl!(Pnt4, x, y, z, w);
|
|
|
|
scalar_sub_impl!(Pnt4, x, y, z, w);
|
|
|
|
vec_cast_impl!(Pnt4, x, y, z, w);
|
|
|
|
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);
|
|
|
|
dim_impl!(Pnt4, 4);
|
|
|
|
container_impl!(Pnt4);
|
|
|
|
pnt_as_vec_impl!(Pnt4, Vec4, x, y, z, w);
|
|
|
|
pnt_sub_impl!(Pnt4, Vec4);
|
|
|
|
neg_impl!(Pnt4, x, y, z, w);
|
|
|
|
pnt_add_vec_impl!(Pnt4, Vec4, x, y, z, w);
|
|
|
|
pnt_sub_vec_impl!(Pnt4, Vec4, x, y, z, w);
|
|
|
|
scalar_ops_impl!(Pnt4, x, y, z, w);
|
|
|
|
approx_eq_impl!(Pnt4, x, y, z, w);
|
|
|
|
from_iterator_impl!(Pnt4, iterator, iterator, iterator, iterator);
|
|
|
|
bounded_impl!(Pnt4, x, y, z, w);
|
|
|
|
axpy_impl!(Pnt4, x, y, z, w);
|
|
|
|
iterable_impl!(Pnt4, 4);
|
|
|
|
iterable_mut_impl!(Pnt4, 4);
|
|
|
|
pnt_to_homogeneous_impl!(Pnt4, Pnt5, a, x, y, z, w);
|
|
|
|
pnt_from_homogeneous_impl!(Pnt4, Pnt5, a, x, y, z, w);
|
|
|
|
num_float_pnt_impl!(Pnt4, Vec4);
|
2015-01-10 08:36:13 +08:00
|
|
|
arbitrary_pnt_impl!(Pnt4, x, y, z, w);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Point of dimension 5.
|
2015-02-01 23:15:55 +08:00
|
|
|
#[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Rand, Debug, Copy)]
|
2014-10-10 17:23:52 +08:00
|
|
|
pub struct Pnt5<N> {
|
2015-01-10 06:01:46 +08:00
|
|
|
/// First component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub x: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Second component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub y: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Third component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub z: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Fourth component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub w: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Fifth of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub a: N
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:33:01 +08:00
|
|
|
new_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
orig_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
ord_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
scalar_mul_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
scalar_div_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
scalar_add_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
scalar_sub_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
vec_cast_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
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);
|
|
|
|
dim_impl!(Pnt5, 5);
|
|
|
|
container_impl!(Pnt5);
|
|
|
|
pnt_as_vec_impl!(Pnt5, Vec5, x, y, z, w, a);
|
|
|
|
pnt_sub_impl!(Pnt5, Vec5);
|
|
|
|
neg_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
pnt_add_vec_impl!(Pnt5, Vec5, x, y, z, w, a);
|
|
|
|
pnt_sub_vec_impl!(Pnt5, Vec5, x, y, z, w, a);
|
|
|
|
scalar_ops_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
approx_eq_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
from_iterator_impl!(Pnt5, iterator, iterator, iterator, iterator, iterator);
|
|
|
|
bounded_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
axpy_impl!(Pnt5, x, y, z, w, a);
|
|
|
|
iterable_impl!(Pnt5, 5);
|
|
|
|
iterable_mut_impl!(Pnt5, 5);
|
|
|
|
pnt_to_homogeneous_impl!(Pnt5, Pnt6, b, x, y, z, w, a);
|
|
|
|
pnt_from_homogeneous_impl!(Pnt5, Pnt6, b, x, y, z, w, a);
|
|
|
|
num_float_pnt_impl!(Pnt5, Vec5);
|
2015-01-10 08:36:13 +08:00
|
|
|
arbitrary_pnt_impl!(Pnt5, x, y, z, w, a);
|
2014-10-10 17:23:52 +08:00
|
|
|
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Point of dimension 6.
|
2015-02-01 23:15:55 +08:00
|
|
|
#[derive(Eq, PartialEq, RustcEncodable, RustcDecodable, Clone, Hash, Rand, Debug, Copy)]
|
2014-10-10 17:23:52 +08:00
|
|
|
pub struct Pnt6<N> {
|
2015-01-10 06:01:46 +08:00
|
|
|
/// First component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub x: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Second component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub y: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Third component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub z: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Fourth component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub w: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Fifth of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub a: N,
|
2015-01-10 06:01:46 +08:00
|
|
|
/// Sixth component of the point.
|
2014-10-10 17:23:52 +08:00
|
|
|
pub b: N
|
|
|
|
}
|
|
|
|
|
2014-12-19 22:33:01 +08:00
|
|
|
new_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
orig_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
ord_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
scalar_mul_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
scalar_div_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
scalar_add_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
scalar_sub_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
vec_cast_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
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);
|
|
|
|
dim_impl!(Pnt6, 6);
|
|
|
|
container_impl!(Pnt6);
|
|
|
|
pnt_as_vec_impl!(Pnt6, Vec6, x, y, z, w, a, b);
|
|
|
|
pnt_sub_impl!(Pnt6, Vec6);
|
|
|
|
neg_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
pnt_add_vec_impl!(Pnt6, Vec6, x, y, z, w, a, b);
|
|
|
|
pnt_sub_vec_impl!(Pnt6, Vec6, x, y, z, w, a, b);
|
|
|
|
scalar_ops_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
approx_eq_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
from_iterator_impl!(Pnt6, iterator, iterator, iterator, iterator, iterator, iterator);
|
|
|
|
bounded_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
axpy_impl!(Pnt6, x, y, z, w, a, b);
|
|
|
|
iterable_impl!(Pnt6, 6);
|
|
|
|
iterable_mut_impl!(Pnt6, 6);
|
|
|
|
num_float_pnt_impl!(Pnt6, Vec6);
|
2015-01-10 08:36:13 +08:00
|
|
|
arbitrary_pnt_impl!(Pnt6, x, y, z, w, a, b);
|