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

80 lines
1.9 KiB
Rust
Raw Normal View History

2018-09-21 01:54:12 +08:00
use na;
2018-09-21 01:54:12 +08:00
use traits::Number;
2018-09-22 23:36:08 +08:00
/// Returns the maximum among three values.
///
/// # Examples:
///
/// ```
/// # use nalgebra_glm as glm;
/// assert_eq!(3.0, glm::max3_scalar(1.0, 2.0, 3.0));
/// assert_eq!(2, glm::max3_scalar(0, 1, 2));
/// ```
///
/// # See also:
///
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
2018-09-22 23:36:08 +08:00
pub fn max3_scalar<N: Number>(a: N, b: N, c: N) -> N {
2018-09-21 01:54:12 +08:00
na::sup(&na::sup(&a, &b), &c)
}
2018-09-22 23:36:08 +08:00
/// Returns the maximum among four values.
///
/// # Examples:
///
/// ```
/// # use nalgebra_glm as glm;
/// assert_eq!(4.0, glm::max4_scalar(2.0, 4.0, 1.0, 3.0));
/// assert_eq!(7, glm::max4_scalar(1, 0, 7, 2));
/// ```
///
/// # See also:
///
/// * [`max3_scalar`](fn.max3_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
2018-09-22 23:36:08 +08:00
pub fn max4_scalar<N: Number>(a: N, b: N, c: N, d: N) -> N {
2018-09-21 01:54:12 +08:00
na::sup(&na::sup(&a, &b), &na::sup(&c, &d))
}
2018-09-23 21:59:24 +08:00
/// Returns the minimum among three values.
///
/// # Examples:
///
/// ```
/// # use nalgebra_glm as glm;
/// assert_eq!(1.0, glm::min3_scalar(1.0, 2.0, 3.0));
/// assert_eq!(0, glm::min3_scalar(0, 1, 2));
/// ```
///
/// # See also:
///
/// * [`max3_scalar`](fn.max3_scalar.html)
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min4_scalar`](fn.min4_scalar.html)
2018-09-22 23:36:08 +08:00
pub fn min3_scalar<N: Number>(a: N, b: N, c: N) -> N {
2018-09-21 01:54:12 +08:00
na::inf(&na::inf(&a, &b), &c)
}
2018-09-23 21:59:24 +08:00
/// Returns the minimum among four values.
///
/// # Examples:
///
/// ```
/// # use nalgebra_glm as glm;
/// assert_eq!(1.0, glm::min4_scalar(2.0, 4.0, 1.0, 3.0));
/// assert_eq!(0, glm::min4_scalar(1, 0, 7, 2));
/// ```
///
/// # See also:
///
/// * [`max3_scalar`](fn.max3_scalar.html)
/// * [`max4_scalar`](fn.max4_scalar.html)
/// * [`min3_scalar`](fn.min3_scalar.html)
2018-09-22 23:36:08 +08:00
pub fn min4_scalar<N: Number>(a: N, b: N, c: N, d: N) -> N {
2018-09-21 01:54:12 +08:00
na::inf(&na::inf(&a, &b), &na::inf(&c, &d))
}