Add more see-also content to glm docs.

This commit is contained in:
Bruce Mitchener 2018-10-03 18:28:07 +07:00 committed by Sébastien Crozet
parent 12962c3c13
commit ca9b4e38dd
7 changed files with 421 additions and 2 deletions

View File

@ -3,18 +3,30 @@ use aliases::TVec;
use traits::{Alloc, Dimension}; use traits::{Alloc, Dimension};
/// Component-wise exponential. /// Component-wise exponential.
///
/// # See also:
///
/// * [`exp2`](fn.exp2.html)
pub fn exp<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D> pub fn exp<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
v.map(|x| x.exp()) v.map(|x| x.exp())
} }
/// Component-wise base-2 exponential. /// Component-wise base-2 exponential.
///
/// # See also:
///
/// * [`exp`](fn.exp.html)
pub fn exp2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D> pub fn exp2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
v.map(|x| x.exp2()) v.map(|x| x.exp2())
} }
/// Compute the inverse of the square root of each component of `v`. /// Compute the inverse of the square root of each component of `v`.
///
/// # See also:
///
/// * [`sqrt`](fn.sqrt.html)
pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D> pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
v.map(|x| N::one() / x.sqrt()) v.map(|x| N::one() / x.sqrt())
@ -22,12 +34,20 @@ pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
} }
/// Component-wise logarithm. /// Component-wise logarithm.
///
/// # See also:
///
/// * [`log2`](fn.log2.html)
pub fn log<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D> pub fn log<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
v.map(|x| x.ln()) v.map(|x| x.ln())
} }
/// Component-wise base-2 logarithm. /// Component-wise base-2 logarithm.
///
/// # See also:
///
/// * [`log`](fn.log.html)
pub fn log2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D> pub fn log2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
v.map(|x| x.log2()) v.map(|x| x.log2())
@ -40,6 +60,13 @@ pub fn pow<N: Real, D: Dimension>(base: &TVec<N, D>, exponent: &TVec<N, D>) -> T
} }
/// Component-wise square root. /// Component-wise square root.
///
/// # See also:
///
/// * [`exp`](fn.exp.html)
/// * [`exp2`](fn.exp2.html)
/// * [`inversesqrt`](fn.inversesqrt.html)
/// * [`pow`](fn.pow.html)
pub fn sqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D> pub fn sqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
v.map(|x| x.sqrt()) v.map(|x| x.sqrt())

View File

@ -7,6 +7,21 @@ pub fn epsilon<N: AbsDiffEq<Epsilon = N>>() -> N {
} }
/// The value of PI. /// The value of PI.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn pi<N: Real>() -> N { pub fn pi<N: Real>() -> N {
N::pi() N::pi()
} }

View File

@ -4,48 +4,144 @@ use traits::{Alloc, Number, Dimension};
use aliases::TVec; use aliases::TVec;
/// Component-wise maximum between a vector and a scalar. /// Component-wise maximum between a vector and a scalar.
///
/// # 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)
pub fn max<N: Number, D: Dimension>(a: &TVec<N, D>, b: N) -> TVec<N, D> pub fn max<N: Number, D: Dimension>(a: &TVec<N, D>, b: N) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
a.map(|a| na::sup(&a, &b)) a.map(|a| na::sup(&a, &b))
} }
/// Component-wise maximum between two vectors. /// Component-wise maximum between two vectors.
///
/// # 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)
pub fn max2<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>) -> TVec<N, D> pub fn max2<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
na::sup(a, b) na::sup(a, b)
} }
/// Component-wise maximum between three vectors. /// Component-wise maximum between three vectors.
///
/// # 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)
pub fn max3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D> pub fn max3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
max2(&max2(a, b), c) max2(&max2(a, b), c)
} }
/// Component-wise maximum between four vectors. /// Component-wise maximum between four vectors.
///
/// # 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)
pub fn max4<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>, d: &TVec<N, D>) -> TVec<N, D> pub fn max4<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>, d: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
max2(&max2(a, b), &max2(c, d)) max2(&max2(a, b), &max2(c, d))
} }
/// Component-wise minimum between a vector and a scalar. /// Component-wise minimum between a vector and a scalar.
///
/// # 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)
pub fn min<N: Number, D: Dimension>(x: &TVec<N, D>, y: N) -> TVec<N, D> pub fn min<N: Number, D: Dimension>(x: &TVec<N, D>, y: N) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
x.map(|x| na::inf(&x, &y)) x.map(|x| na::inf(&x, &y))
} }
/// Component-wise minimum between two vectors. /// Component-wise minimum between two vectors.
///
/// # 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)
pub fn min2<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<N, D> pub fn min2<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
na::inf(x, y) na::inf(x, y)
} }
/// Component-wise minimum between three vectors. /// Component-wise minimum between three vectors.
///
/// # 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)
pub fn min3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D> pub fn min3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
min2(&min2(a, b), c) min2(&min2(a, b), c)
} }
/// Component-wise minimum between four vectors. /// Component-wise minimum between four vectors.
///
/// # 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)
pub fn min4<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>, d: &TVec<N, D>) -> TVec<N, D> pub fn min4<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>, d: &TVec<N, D>) -> TVec<N, D>
where DefaultAllocator: Alloc<N, D> { where DefaultAllocator: Alloc<N, D> {
min2(&min2(a, b), &min2(c, d)) min2(&min2(a, b), &min2(c, d))

View File

@ -11,6 +11,21 @@ pub fn euler<N: Real>() -> N {
} }
/// Returns `4 / pi`. /// Returns `4 / pi`.
///
/// # See also:
///
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn four_over_pi<N: Real>() -> N { pub fn four_over_pi<N: Real>() -> N {
na::convert::<_, N>(4.0) / N::pi() na::convert::<_, N>(4.0) / N::pi()
} }
@ -21,21 +36,51 @@ pub fn golden_ratio<N: Real>() -> N {
} }
/// Returns `pi / 2`. /// Returns `pi / 2`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn half_pi<N: Real>() -> N { pub fn half_pi<N: Real>() -> N {
N::frac_pi_2() N::frac_pi_2()
} }
/// Returns `ln(ln(2))`. /// Returns `ln(ln(2))`.
///
/// # See also:
///
/// * [`ln_ten`](fn.ln_ten.html)
/// * [`ln_two`](fn.ln_two.html)
pub fn ln_ln_two<N: Real>() -> N { pub fn ln_ln_two<N: Real>() -> N {
N::ln_2().ln() N::ln_2().ln()
} }
/// Returns `ln(10)`. /// Returns `ln(10)`.
///
/// # See also:
///
/// * [`ln_ln_two`](fn.ln_ln_two.html)
/// * [`ln_two`](fn.ln_two.html)
pub fn ln_ten<N: Real>() -> N { pub fn ln_ten<N: Real>() -> N {
N::ln_10() N::ln_10()
} }
/// Returns `ln(2)`. /// Returns `ln(2)`.
///
/// # See also:
///
/// * [`ln_ln_two`](fn.ln_ln_two.html)
/// * [`ln_ten`](fn.ln_ten.html)
pub fn ln_two<N: Real>() -> N { pub fn ln_two<N: Real>() -> N {
N::ln_2() N::ln_2()
} }
@ -44,6 +89,21 @@ pub fn ln_two<N: Real>() -> N {
pub use na::one; pub use na::one;
/// Returns `1 / pi`. /// Returns `1 / pi`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn one_over_pi<N: Real>() -> N { pub fn one_over_pi<N: Real>() -> N {
N::frac_1_pi() N::frac_1_pi()
} }
@ -54,21 +114,71 @@ pub fn one_over_root_two<N: Real>() -> N {
} }
/// Returns `1 / (2pi)`. /// Returns `1 / (2pi)`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn one_over_two_pi<N: Real>() -> N { pub fn one_over_two_pi<N: Real>() -> N {
N::frac_1_pi() * na::convert(0.5) N::frac_1_pi() * na::convert(0.5)
} }
/// Returns `pi / 4`. /// Returns `pi / 4`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn quarter_pi<N: Real>() -> N { pub fn quarter_pi<N: Real>() -> N {
N::frac_pi_4() N::frac_pi_4()
} }
/// Returns `sqrt(5)`. /// Returns `sqrt(5)`.
///
/// # See also:
///
/// * [`root_three`](fn.root_three.html)
/// * [`root_two`](fn.root_two.html)
pub fn root_five<N: Real>() -> N { pub fn root_five<N: Real>() -> N {
na::convert::<_, N>(5.0).sqrt() na::convert::<_, N>(5.0).sqrt()
} }
/// Returns `sqrt(pi / 2)`. /// Returns `sqrt(pi / 2)`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn root_half_pi<N: Real>() -> N { pub fn root_half_pi<N: Real>() -> N {
(N::pi() / na::convert(2.0)).sqrt() (N::pi() / na::convert(2.0)).sqrt()
} }
@ -79,55 +189,162 @@ pub fn root_ln_four<N: Real>() -> N {
} }
/// Returns the square root of pi. /// Returns the square root of pi.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn root_pi<N: Real>() -> N { pub fn root_pi<N: Real>() -> N {
N::pi().sqrt() N::pi().sqrt()
} }
/// Returns the square root of 3. /// Returns the square root of 3.
///
/// # See also:
///
/// * [`root_five`](fn.root_five.html)
/// * [`root_two`](fn.root_two.html)
pub fn root_three<N: Real>() -> N { pub fn root_three<N: Real>() -> N {
na::convert::<_, N>(3.0).sqrt() na::convert::<_, N>(3.0).sqrt()
} }
/// Returns the square root of 2. /// Returns the square root of 2.
///
/// # See also:
///
/// * [`root_five`](fn.root_five.html)
/// * [`root_three`](fn.root_three.html)
pub fn root_two<N: Real>() -> N { pub fn root_two<N: Real>() -> N {
// FIXME: there should be a ::sqrt_2() on the Real trait. // FIXME: there should be a ::sqrt_2() on the Real trait.
na::convert::<_, N>(2.0).sqrt() na::convert::<_, N>(2.0).sqrt()
} }
/// Returns the square root of 2pi. /// Returns the square root of 2pi.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn root_two_pi<N: Real>() -> N { pub fn root_two_pi<N: Real>() -> N {
N::two_pi().sqrt() N::two_pi().sqrt()
} }
/// Returns `1 / 3`. /// Returns `1 / 3`.
///
/// # See also:
///
/// * [`two_thirds`](fn.two_thirds.html)
pub fn third<N: Real>() -> N { pub fn third<N: Real>() -> N {
na::convert(1.0 / 3.0) na::convert(1.0 / 3.0)
} }
/// Returns `3 / (2pi)`. /// Returns `3 / (2pi)`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn three_over_two_pi<N: Real>() -> N { pub fn three_over_two_pi<N: Real>() -> N {
na::convert::<_, N>(3.0) / N::two_pi() na::convert::<_, N>(3.0) / N::two_pi()
} }
/// Returns `2 / pi`. /// Returns `2 / pi`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn two_over_pi<N: Real>() -> N { pub fn two_over_pi<N: Real>() -> N {
N::frac_2_pi() N::frac_2_pi()
} }
/// Returns `2 / sqrt(pi)`. /// Returns `2 / sqrt(pi)`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_pi`](fn.two_pi.html)
pub fn two_over_root_pi<N: Real>() -> N { pub fn two_over_root_pi<N: Real>() -> N {
N::frac_2_sqrt_pi() N::frac_2_sqrt_pi()
} }
/// Returns `2pi`. /// Returns `2pi`.
///
/// # See also:
///
/// * [`four_over_pi`](fn.four_over_pi.html)
/// * [`half_pi`](fn.half_pi.html)
/// * [`one_over_pi`](fn.one_over_pi.html)
/// * [`one_over_two_pi`](fn.one_over_two_pi.html)
/// * [`pi`](fn.pi.html)
/// * [`quarter_pi`](fn.quarter_pi.html)
/// * [`root_half_pi`](fn.root_half_pi.html)
/// * [`root_pi`](fn.root_pi.html)
/// * [`root_two_pi`](fn.root_two_pi.html)
/// * [`three_over_two_pi`](fn.three_over_two_pi.html)
/// * [`two_over_pi`](fn.two_over_pi.html)
/// * [`two_over_root_pi`](fn.two_over_root_pi.html)
pub fn two_pi<N: Real>() -> N { pub fn two_pi<N: Real>() -> N {
N::two_pi() N::two_pi()
} }
/// Returns `2 / 3`. /// Returns `2 / 3`.
///
/// # See also:
///
/// * [`third`](fn.third.html)
pub fn two_thirds<N: Real>() -> N { pub fn two_thirds<N: Real>() -> N {
na::convert(2.0 / 3.0) na::convert(2.0 / 3.0)
} }
/// Returns `0`. /// Returns `0`.
pub use na::zero; pub use na::zero;

View File

@ -4,12 +4,24 @@ use traits::{Alloc, Dimension};
use aliases::{TVec, TMat}; use aliases::{TVec, TMat};
/// The `index`-th column of the matrix `m`. /// The `index`-th column of the matrix `m`.
///
/// # See also:
///
/// * [`row`](fn.row.html)
/// * [`set_column`](fn.set_column.html)
/// * [`set_row`](fn.set_row.html)
pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, R> pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, R>
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
m.column(index).into_owned() m.column(index).into_owned()
} }
/// Sets to `x` the `index`-th column of the matrix `m`. /// Sets to `x` the `index`-th column of the matrix `m`.
///
/// # See also:
///
/// * [`column`](fn.column.html)
/// * [`row`](fn.row.html)
/// * [`set_row`](fn.set_row.html)
pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize, x: &TVec<N, R>) -> TMat<N, R, C> pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize, x: &TVec<N, R>) -> TMat<N, R, C>
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
let mut res = m.clone(); let mut res = m.clone();
@ -18,12 +30,24 @@ pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, inde
} }
/// The `index`-th row of the matrix `m`. /// The `index`-th row of the matrix `m`.
///
/// # See also:
///
/// * [`column`](fn.column.html)
/// * [`set_column`](fn.set_column.html)
/// * [`set_row`](fn.set_row.html)
pub fn row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, C> pub fn row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, C>
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
m.row(index).into_owned().transpose() m.row(index).into_owned().transpose()
} }
/// Sets to `x` the `index`-th row of the matrix `m`. /// Sets to `x` the `index`-th row of the matrix `m`.
///
/// # See also:
///
/// * [`column`](fn.column.html)
/// * [`row`](fn.row.html)
/// * [`set_column`](fn.set_column.html)
pub fn set_row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize, x: &TVec<N, C>) -> TMat<N, R, C> pub fn set_row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize, x: &TVec<N, C>) -> TMat<N, R, C>
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
let mut res = m.clone(); let mut res = m.clone();

View File

@ -4,28 +4,60 @@ use traits::{Number, Alloc, Dimension};
use aliases::TMat; use aliases::TMat;
/// The sum of every components of the given matrix or vector. /// The sum of every components of the given matrix or vector.
///
/// # See also:
///
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
/// * [`comp_mul`](fn.comp_mul.html)
pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::zero(), |x, y| x + *y) m.iter().fold(N::zero(), |x, y| x + *y)
} }
/// The maximum of every components of the given matrix or vector. /// The maximum of every components of the given matrix or vector.
///
/// # See also:
///
/// * [`comp_add`](fn.comp_add.html)
/// * [`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)
pub fn comp_max<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N pub fn comp_max<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::min_value(), |x, y| na::sup(&x, y)) m.iter().fold(N::min_value(), |x, y| na::sup(&x, y))
} }
/// The minimum of every components of the given matrix or vector. /// The minimum of every components of the given matrix or vector.
///
/// # See also:
///
/// * [`comp_add`](fn.comp_add.html)
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_mul`](fn.comp_mul.html)
/// * [`min`](fn.min.html)
/// * [`min2`](fn.min2.html)
/// * [`min3`](fn.min3.html)
/// * [`min4`](fn.min4.html)
pub fn comp_min<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N pub fn comp_min<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::max_value(), |x, y| na::inf(&x, y)) m.iter().fold(N::max_value(), |x, y| na::inf(&x, y))
} }
/// The product of every components of the given matrix or vector. /// The product of every components of the given matrix or vector.
///
/// # See also:
///
/// * [`comp_add`](fn.comp_add.html)
/// * [`comp_max`](fn.comp_max.html)
/// * [`comp_min`](fn.comp_min.html)
pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
where DefaultAllocator: Alloc<N, R, C> { where DefaultAllocator: Alloc<N, R, C> {
m.iter().fold(N::one(), |x, y| x * *y) m.iter().fold(N::one(), |x, y| x * *y)
} }
//pub fn vec< L, floatType, Q > compNormalize (vec< L, T, Q > const &v) //pub fn vec< L, floatType, Q > compNormalize (vec< L, T, Q > const &v)
//pub fn vec< L, T, Q > compScale (vec< L, floatType, Q > const &v) //pub fn vec< L, T, Q > compScale (vec< L, floatType, Q > const &v)

View File

@ -4,12 +4,20 @@ use aliases::TVec;
use traits::{Number, Alloc, Dimension}; use traits::{Number, Alloc, Dimension};
/// Checks that all the vector components are `true`. /// Checks that all the vector components are `true`.
///
/// # See also:
///
/// * [`any`](fn.any.html)
pub fn all<D: Dimension>(v: &TVec<bool, D>) -> bool pub fn all<D: Dimension>(v: &TVec<bool, D>) -> bool
where DefaultAllocator: Alloc<bool, D> { where DefaultAllocator: Alloc<bool, D> {
v.iter().all(|x| *x) v.iter().all(|x| *x)
} }
/// Checks that at least one of the vector components is `true`. /// Checks that at least one of the vector components is `true`.
///
/// # See also:
///
/// * [`all`](fn.all.html)
pub fn any<D: Dimension>(v: &TVec<bool, D>) -> bool pub fn any<D: Dimension>(v: &TVec<bool, D>) -> bool
where DefaultAllocator: Alloc<bool, D> { where DefaultAllocator: Alloc<bool, D> {
v.iter().any(|x| *x) v.iter().any(|x| *x)