nalgebra/nalgebra-glm/src/vector_relational.rs

59 lines
1.8 KiB
Rust
Raw Normal View History

use na::{DefaultAllocator};
use aliases::Vec;
use traits::{Number, Alloc, Dimension};
/// Checks that all the vector components are `true`.
pub fn all<D: Dimension>(v: &Vec<bool, D>) -> bool
where DefaultAllocator: Alloc<bool, D> {
v.iter().all(|x| *x)
}
/// Checks that at least one of the vector components is `true`.
pub fn any<D: Dimension>(v: &Vec<bool, D>) -> bool
where DefaultAllocator: Alloc<bool, D> {
v.iter().any(|x| *x)
}
2018-09-22 19:21:02 +08:00
/// Component-wise equality comparison.
pub fn equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
where DefaultAllocator: Alloc<N, D> {
x.zip_map(y, |x, y| x == y)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `>` comparison.
pub fn greater_than<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
where DefaultAllocator: Alloc<N, D> {
x.zip_map(y, |x, y| x > y)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `>=` comparison.
pub fn greater_than_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
where DefaultAllocator: Alloc<N, D> {
x.zip_map(y, |x, y| x >= y)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `<` comparison.
pub fn less_than<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
where DefaultAllocator: Alloc<N, D> {
x.zip_map(y, |x, y| x < y)
}
2018-09-22 19:21:02 +08:00
/// Component-wise `>=` comparison.
pub fn less_than_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
where DefaultAllocator: Alloc<N, D> {
x.zip_map(y, |x, y| x <= y)
}
2018-09-22 19:21:02 +08:00
/// Component-wise not `!`.
pub fn not<D: Dimension>(v: &Vec<bool, D>) -> Vec<bool, D>
where DefaultAllocator: Alloc<bool, D> {
v.map(|x| !x)
}
2018-09-22 19:21:02 +08:00
/// Component-wise not-equality `!=`.
pub fn not_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
where DefaultAllocator: Alloc<N, D> {
x.zip_map(y, |x, y| x != y)
}