2018-09-22 19:18:59 +08:00
|
|
|
use na::{DefaultAllocator};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-23 20:48:45 +08:00
|
|
|
use aliases::TVec;
|
2018-09-20 20:23:31 +08:00
|
|
|
use traits::{Number, Alloc, Dimension};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Checks that all the vector components are `true`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
2018-10-04 21:49:01 +08:00
|
|
|
/// # Examples:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// # use nalgebra_glm as glm;
|
|
|
|
/// let vec = glm::vec2(true, false);
|
|
|
|
/// assert_eq!(false, glm::all(&vec));
|
|
|
|
///
|
|
|
|
/// let vec = glm::vec2(true, true);
|
|
|
|
/// assert_eq!(true, glm::all(&vec));
|
|
|
|
/// ```
|
|
|
|
///
|
2018-10-03 19:28:07 +08:00
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`any`](fn.any.html)
|
2018-10-04 21:49:01 +08:00
|
|
|
/// * [`not`](fn.not.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn all<D: Dimension>(v: &TVec<bool, D>) -> bool
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<bool, D> {
|
|
|
|
v.iter().all(|x| *x)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:18:59 +08:00
|
|
|
/// Checks that at least one of the vector components is `true`.
|
2018-10-03 19:28:07 +08:00
|
|
|
///
|
2018-10-04 21:49:01 +08:00
|
|
|
/// # Examples:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// # use nalgebra_glm as glm;
|
|
|
|
/// let vec = glm::vec2(true, false);
|
|
|
|
/// assert_eq!(true, glm::any(&vec));
|
|
|
|
///
|
|
|
|
/// let vec = glm::vec2(true, true);
|
|
|
|
/// assert_eq!(true, glm::any(&vec));
|
|
|
|
///
|
|
|
|
/// let vec = glm::vec2(false, false);
|
|
|
|
/// assert_eq!(false, glm::any(&vec));
|
|
|
|
/// ```
|
|
|
|
///
|
2018-10-03 19:28:07 +08:00
|
|
|
/// # See also:
|
|
|
|
///
|
|
|
|
/// * [`all`](fn.all.html)
|
2018-10-04 21:49:01 +08:00
|
|
|
/// * [`not`](fn.not.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn any<D: Dimension>(v: &TVec<bool, D>) -> bool
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<bool, D> {
|
|
|
|
v.iter().any(|x| *x)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise equality comparison.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
///
|
|
|
|
/// * [`equal`](fn.equal.html)
|
|
|
|
/// * [`greater_than`](fn.greater_than.html)
|
|
|
|
/// * [`greater_than_equal`](fn.greater_than_equal.html)
|
|
|
|
/// * [`less_than`](fn.less_than.html)
|
|
|
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
|
|
|
/// * [`not`](fn.not.html)
|
|
|
|
/// * [`not_equal`](fn.not_equal.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
x.zip_map(y, |x, y| x == y)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `>` comparison.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
///
|
|
|
|
/// * [`equal`](fn.equal.html)
|
|
|
|
/// * [`greater_than`](fn.greater_than.html)
|
|
|
|
/// * [`greater_than_equal`](fn.greater_than_equal.html)
|
|
|
|
/// * [`less_than`](fn.less_than.html)
|
|
|
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
|
|
|
/// * [`not`](fn.not.html)
|
|
|
|
/// * [`not_equal`](fn.not_equal.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn greater_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
x.zip_map(y, |x, y| x > y)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `>=` comparison.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
///
|
|
|
|
/// * [`equal`](fn.equal.html)
|
|
|
|
/// * [`greater_than`](fn.greater_than.html)
|
|
|
|
/// * [`greater_than_equal`](fn.greater_than_equal.html)
|
|
|
|
/// * [`less_than`](fn.less_than.html)
|
|
|
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
|
|
|
/// * [`not`](fn.not.html)
|
|
|
|
/// * [`not_equal`](fn.not_equal.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn greater_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
x.zip_map(y, |x, y| x >= y)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `<` comparison.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
///
|
|
|
|
/// * [`equal`](fn.equal.html)
|
|
|
|
/// * [`greater_than`](fn.greater_than.html)
|
|
|
|
/// * [`greater_than_equal`](fn.greater_than_equal.html)
|
|
|
|
/// * [`less_than`](fn.less_than.html)
|
|
|
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
|
|
|
/// * [`not`](fn.not.html)
|
|
|
|
/// * [`not_equal`](fn.not_equal.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn less_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
x.zip_map(y, |x, y| x < y)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise `>=` comparison.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
///
|
|
|
|
/// * [`equal`](fn.equal.html)
|
|
|
|
/// * [`greater_than`](fn.greater_than.html)
|
|
|
|
/// * [`greater_than_equal`](fn.greater_than_equal.html)
|
|
|
|
/// * [`less_than`](fn.less_than.html)
|
|
|
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
|
|
|
/// * [`not`](fn.not.html)
|
|
|
|
/// * [`not_equal`](fn.not_equal.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn less_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
x.zip_map(y, |x, y| x <= y)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise not `!`.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// # Examples:
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// # use nalgebra_glm as glm;
|
|
|
|
/// let vec = glm::vec2(true, false);
|
|
|
|
/// assert_eq!(glm::vec2(false, true), glm::not(&vec));
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
///
|
|
|
|
/// * [`all`](fn.all.html)
|
|
|
|
/// * [`any`](fn.any.html)
|
|
|
|
/// * [`equal`](fn.equal.html)
|
|
|
|
/// * [`greater_than`](fn.greater_than.html)
|
|
|
|
/// * [`greater_than_equal`](fn.greater_than_equal.html)
|
|
|
|
/// * [`less_than`](fn.less_than.html)
|
|
|
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
|
|
|
/// * [`not`](fn.not.html)
|
|
|
|
/// * [`not_equal`](fn.not_equal.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn not<D: Dimension>(v: &TVec<bool, D>) -> TVec<bool, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<bool, D> {
|
|
|
|
v.map(|x| !x)
|
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise not-equality `!=`.
|
2018-10-04 21:49:01 +08:00
|
|
|
///
|
|
|
|
/// See also:
|
|
|
|
///
|
|
|
|
/// * [`equal`](fn.equal.html)
|
|
|
|
/// * [`greater_than`](fn.greater_than.html)
|
|
|
|
/// * [`greater_than_equal`](fn.greater_than_equal.html)
|
|
|
|
/// * [`less_than`](fn.less_than.html)
|
|
|
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
|
|
|
/// * [`not_equal`](fn.not_equal.html)
|
2018-09-23 20:48:45 +08:00
|
|
|
pub fn not_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
|
|
|
x.zip_map(y, |x, y| x != y)
|
|
|
|
}
|