2018-09-23 20:41:56 +08:00
|
|
|
use na::{Real, DefaultAllocator};
|
2018-09-21 01:54:12 +08:00
|
|
|
|
|
|
|
use traits::{Number, Dimension, Alloc};
|
2018-09-23 20:48:45 +08:00
|
|
|
use aliases::{TVec, TVec2, TVec3};
|
2018-09-21 01:54:12 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `true` if two vectors are collinear (up to an epsilon).
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`are_collinear2d`](fn.are_collinear2d.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn are_collinear<N: Number>(v0: &TVec3<N>, v1: &TVec3<N>, epsilon: N) -> bool {
|
2018-09-21 01:54:12 +08:00
|
|
|
is_null(&v0.cross(v1), epsilon)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `true` if two 2D vectors are collinear (up to an epsilon).
|
2018-10-08 10:30:16 +08:00
|
|
|
///
|
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`are_collinear`](fn.are_collinear.html)
|
2018-09-23 20:41:56 +08:00
|
|
|
pub fn are_collinear2d<N: Number>(v0: &TVec2<N>, v1: &TVec2<N>, epsilon: N) -> bool {
|
2018-09-21 01:54:12 +08:00
|
|
|
abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `true` if two vectors are orthogonal (up to an epsilon).
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn are_orthogonal<N: Number, D: Dimension>(v0: &TVec<N, D>, v1: &TVec<N, D>, epsilon: N) -> bool
|
2018-09-21 01:54:12 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
abs_diff_eq!(v0.dot(v1), N::zero(), epsilon = epsilon)
|
|
|
|
}
|
|
|
|
|
2018-09-23 20:48:45 +08:00
|
|
|
//pub fn are_orthonormal<N: Number, D: Dimension>(v0: &TVec<N, D>, v1: &TVec<N, D>, epsilon: N) -> bool
|
2018-09-22 19:18:59 +08:00
|
|
|
// where DefaultAllocator: Alloc<N, D> {
|
|
|
|
// unimplemented!()
|
|
|
|
//}
|
2018-09-21 01:54:12 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `true` if all the components of `v` are zero (up to an epsilon).
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn is_comp_null<N: Number, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
2018-09-21 01:54:12 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon))
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `true` if `v` has a magnitude of 1 (up to an epsilon).
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn is_normalized<N: Real, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> bool
|
2018-09-21 01:54:12 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Returns `true` if `v` is zero (up to an epsilon).
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn is_null<N: Number, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> bool
|
2018-09-21 01:54:12 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-23 20:48:45 +08:00
|
|
|
abs_diff_eq!(*v, TVec::<N, D>::zeros(), epsilon = epsilon)
|
2018-09-21 01:54:12 +08:00
|
|
|
}
|