nalgebra/nalgebra-glm/src/ext/vector_common.rs

157 lines
3.9 KiB
Rust
Raw Normal View History

2019-03-23 21:29:07 +08:00
use crate::aliases::TVec;
2021-04-11 17:00:38 +08:00
use crate::traits::Number;
2018-09-22 19:21:02 +08:00
/// Component-wise maximum between a vector and a scalar.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max2`](fn.max2.html)
/// * [`max3`](fn.max3.html)
/// * [`max4`](fn.max4.html)
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
2021-04-11 17:00:38 +08:00
pub fn max<T: Number, const D: usize>(a: &TVec<T, D>, b: T) -> TVec<T, D> {
a.map(|a| crate::max2_scalar(a, b))
}
2018-09-22 19:21:02 +08:00
/// Component-wise maximum between two vectors.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max`](fn.max.html)
/// * [`max3`](fn.max3.html)
/// * [`max4`](fn.max4.html)
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
2021-04-11 17:00:38 +08:00
pub fn max2<T: Number, const D: usize>(a: &TVec<T, D>, b: &TVec<T, D>) -> TVec<T, D> {
a.zip_map(b, |a, b| crate::max2_scalar(a, b))
}
2018-09-22 19:21:02 +08:00
/// Component-wise maximum between three vectors.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max`](fn.max.html)
/// * [`max2`](fn.max2.html)
/// * [`max4`](fn.max4.html)
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
2021-04-11 17:00:38 +08:00
pub fn max3<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
) -> TVec<T, D> {
max2(&max2(a, b), c)
}
2018-09-22 19:21:02 +08:00
/// Component-wise maximum between four vectors.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max`](fn.max.html)
/// * [`max2`](fn.max2.html)
/// * [`max3`](fn.max3.html)
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
2021-04-11 17:00:38 +08:00
pub fn max4<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
d: &TVec<T, D>,
) -> TVec<T, D> {
max2(&max2(a, b), &max2(c, d))
}
2018-09-23 00:11:51 +08:00
/// Component-wise minimum between a vector and a scalar.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max`](fn.max.html)
/// * [`max2`](fn.max2.html)
/// * [`max3`](fn.max3.html)
/// * [`max4`](fn.max4.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
2021-04-11 17:00:38 +08:00
pub fn min<T: Number, const D: usize>(x: &TVec<T, D>, y: T) -> TVec<T, D> {
x.map(|x| crate::min2_scalar(x, y))
}
2018-09-23 00:11:51 +08:00
/// Component-wise minimum between two vectors.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max`](fn.max.html)
/// * [`max2`](fn.max2.html)
/// * [`max3`](fn.max3.html)
/// * [`max4`](fn.max4.html)
/// * [`min`](fn.min.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
2021-04-11 17:00:38 +08:00
pub fn min2<T: Number, const D: usize>(x: &TVec<T, D>, y: &TVec<T, D>) -> TVec<T, D> {
x.zip_map(y, |a, b| crate::min2_scalar(a, b))
}
2018-09-23 00:11:51 +08:00
/// Component-wise minimum between three vectors.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max`](fn.max.html)
/// * [`max2`](fn.max2.html)
/// * [`max3`](fn.max3.html)
/// * [`max4`](fn.max4.html)
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min4`](fn.min4.html)
2021-04-11 17:00:38 +08:00
pub fn min3<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
) -> TVec<T, D> {
min2(&min2(a, b), c)
}
2018-09-23 00:11:51 +08:00
/// Component-wise minimum between four vectors.
2018-10-03 19:28:07 +08:00
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`max`](fn.max.html)
/// * [`max2`](fn.max2.html)
/// * [`max3`](fn.max3.html)
/// * [`max4`](fn.max4.html)
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
2021-04-11 17:00:38 +08:00
pub fn min4<T: Number, const D: usize>(
a: &TVec<T, D>,
b: &TVec<T, D>,
c: &TVec<T, D>,
d: &TVec<T, D>,
) -> TVec<T, D> {
min2(&min2(a, b), &min2(c, d))
}