2018-09-20 20:23:31 +08:00
|
|
|
use na::{self, DefaultAllocator};
|
2018-09-20 16:50:34 +08:00
|
|
|
|
2018-09-20 20:23:31 +08:00
|
|
|
use traits::{Alloc, Number, Dimension};
|
2018-09-20 16:50:34 +08:00
|
|
|
use aliases::Vec;
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise maximum between a vector and a scalar.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn max<N: Number, D: Dimension>(a: &Vec<N, D>, b: N) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
a.map(|a| na::sup(&a, &b))
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise maximum between two vectors.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn max2<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
na::sup(a, b)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise maximum between three vectors.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn max3<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
max2(&max2(a, b), c)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-22 19:21:02 +08:00
|
|
|
/// Component-wise maximum between four vectors.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn max4<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>, d: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
max2(&max2(a, b), &max2(c, d))
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-23 00:11:51 +08:00
|
|
|
/// Component-wise minimum between a vector and a scalar.
|
2018-09-22 19:18:59 +08:00
|
|
|
pub fn min<N: Number, D: Dimension>(x: &Vec<N, D>, y: N) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
x.map(|x| na::inf(&x, &y))
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-23 00:11:51 +08:00
|
|
|
/// Component-wise minimum between two vectors.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn min2<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
na::inf(x, y)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-23 00:11:51 +08:00
|
|
|
/// Component-wise minimum between three vectors.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn min3<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
min2(&min2(a, b), c)
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|
|
|
|
|
2018-09-23 00:11:51 +08:00
|
|
|
/// Component-wise minimum between four vectors.
|
2018-09-20 20:23:31 +08:00
|
|
|
pub fn min4<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>, d: &Vec<N, D>) -> Vec<N, D>
|
2018-09-20 16:50:34 +08:00
|
|
|
where DefaultAllocator: Alloc<N, D> {
|
2018-09-20 20:23:31 +08:00
|
|
|
min2(&min2(a, b), &min2(c, d))
|
2018-09-20 16:50:34 +08:00
|
|
|
}
|