From a01fde5699453ac57f62ea510e968bf06e88fa0d Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Thu, 4 Oct 2018 20:49:01 +0700 Subject: [PATCH] Add more doc linking and some doc tests. --- nalgebra-glm/src/aliases.rs | 132 +++++++++++++++++ nalgebra-glm/src/common.rs | 197 ++++++++++++++++++++++++- nalgebra-glm/src/constructors.rs | 9 ++ nalgebra-glm/src/gtx/component_wise.rs | 44 ++++++ nalgebra-glm/src/vector_relational.rs | 106 +++++++++++++ 5 files changed, 486 insertions(+), 2 deletions(-) diff --git a/nalgebra-glm/src/aliases.rs b/nalgebra-glm/src/aliases.rs index c90075ec..e09e68e1 100644 --- a/nalgebra-glm/src/aliases.rs +++ b/nalgebra-glm/src/aliases.rs @@ -5,19 +5,151 @@ use na::{MatrixMN, VectorN, Vector1, Vector2, Vector3, Vector4, Quaternion}; /// A matrix with components of type `N`. It has `R` rows, and `C` columns. +/// +/// # See also: +/// +/// * [`TMat2`](type.TMat2.html) +/// * [`TMat2x2`](type.TMat2x2.html) +/// * [`TMat2x3`](type.TMat2x3.html) +/// * [`TMat2x4`](type.TMat2x4.html) +/// * [`TMat3`](type.TMat3.html) +/// * [`TMat3x2`](type.TMat3x2.html) +/// * [`TMat3x3`](type.TMat3x3.html) +/// * [`TMat3x4`](type.TMat3x4.html) +/// * [`TMat4`](type.TMat4.html) +/// * [`TMat4x2`](type.TMat4x2.html) +/// * [`TMat4x3`](type.TMat4x3.html) +/// * [`TMat4x4`](type.TMat4x4.html) pub type TMat = MatrixMN; /// A column vector with components of type `N`. It has `D` rows (and one column). +/// +/// # See also: +/// +/// * [`TVec1`](type.TVec1.html) +/// * [`TVec2`](type.TVec2.html) +/// * [`TVec3`](type.TVec3.html) +/// * [`TVec4`](type.TVec4.html) pub type TVec = VectorN; /// A quaternion with components of type `N`. pub type Qua = Quaternion; /// A 1D vector with components of type `N`. +/// +/// # See also: +/// +/// ## Constructors: +/// +/// * [`make_vec1`](fn.make_vec1.html) +/// * [`vec1`](fn.vec1.html) +/// * [`vec2_to_vec1`](fn.vec2_to_vec1.html) +/// * [`vec3_to_vec1`](fn.vec3_to_vec1.html) +/// * [`vec4_to_vec1`](fn.vec4_to_vec1.html) +/// +/// ## Related types: +/// +/// * [`BVec1`](type.BVec1.html) +/// * [`DVec1`](type.DVec1.html) +/// * [`IVec1`](type.IVec1.html) +/// * [`I16Vec1`](type.I16Vec1.html) +/// * [`I32Vec1`](type.I32Vec1.html) +/// * [`I64Vec1`](type.I64Vec1.html) +/// * [`I8Vec1`](type.I8Vec1.html) +/// * [`TVec`](type.TVec.html) +/// * [`UVec1`](type.UVec1.html) +/// * [`U16Vec1`](type.U16Vec1.html) +/// * [`U32Vec1`](type.U32Vec1.html) +/// * [`U64Vec1`](type.U64Vec1.html) +/// * [`U8Vec1`](type.U8Vec1.html) +/// * [`Vec1`](type.Vec1.html) pub type TVec1 = Vector1; /// A 2D vector with components of type `N`. +/// +/// # See also: +/// +/// ## Constructors: +/// +/// * [`make_vec2`](fn.make_vec2.html) +/// * [`vec2`](fn.vec2.html) +/// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) +/// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) +/// * [`vec4_to_vec2`](fn.vec4_to_vec2.html) +/// +/// ## Related types: +/// +/// * [`vec2`](fn.vec2.html) +/// * [`BVec2`](type.BVec2.html) +/// * [`DVec2`](type.DVec2.html) +/// * [`IVec2`](type.IVec2.html) +/// * [`I16Vec2`](type.I16Vec2.html) +/// * [`I32Vec2`](type.I32Vec2.html) +/// * [`I64Vec2`](type.I64Vec2.html) +/// * [`I8Vec2`](type.I8Vec2.html) +/// * [`TVec`](type.TVec.html) +/// * [`UVec2`](type.UVec2.html) +/// * [`U16Vec2`](type.U16Vec2.html) +/// * [`U32Vec2`](type.U32Vec2.html) +/// * [`U64Vec2`](type.U64Vec2.html) +/// * [`U8Vec2`](type.U8Vec2.html) +/// * [`Vec2`](type.Vec2.html) pub type TVec2 = Vector2; /// A 3D vector with components of type `N`. +/// +/// # See also: +/// +/// ## Constructors: +/// +/// * [`make_vec3`](fn.make_vec3.html) +/// * [`vec3`](fn.vec3.html) +/// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) +/// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) +/// * [`vec4_to_vec3`](fn.vec4_to_vec3.html) +/// +/// ## Related types: +/// +/// * [`vec3`](fn.vec3.html) +/// * [`BVec3`](type.BVec3.html) +/// * [`DVec3`](type.DVec3.html) +/// * [`IVec3`](type.IVec3.html) +/// * [`I16Vec3`](type.I16Vec3.html) +/// * [`I32Vec3`](type.I32Vec3.html) +/// * [`I64Vec3`](type.I64Vec3.html) +/// * [`I8Vec3`](type.I8Vec3.html) +/// * [`TVec`](type.TVec.html) +/// * [`UVec3`](type.UVec3.html) +/// * [`U16Vec3`](type.U16Vec3.html) +/// * [`U32Vec3`](type.U32Vec3.html) +/// * [`U64Vec3`](type.U64Vec3.html) +/// * [`U8Vec3`](type.U8Vec3.html) +/// * [`Vec3`](type.Vec3.html) pub type TVec3 = Vector3; /// A 4D vector with components of type `N`. +/// +/// # See also: +/// +/// ## Constructors: +/// +/// * [`make_vec4`](fn.make_vec4.html) +/// * [`vec4`](fn.vec4.html) +/// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) +/// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) +/// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) +/// +/// ## Related types: +/// +/// * [`vec4`](fn.vec4.html) +/// * [`BVec4`](type.BVec4.html) +/// * [`DVec4`](type.DVec4.html) +/// * [`IVec4`](type.IVec4.html) +/// * [`I16Vec4`](type.I16Vec4.html) +/// * [`I32Vec4`](type.I32Vec4.html) +/// * [`I64Vec4`](type.I64Vec4.html) +/// * [`I8Vec4`](type.I8Vec4.html) +/// * [`UVec4`](type.UVec4.html) +/// * [`U16Vec4`](type.U16Vec4.html) +/// * [`U32Vec4`](type.U32Vec4.html) +/// * [`U64Vec4`](type.U64Vec4.html) +/// * [`U8Vec4`](type.U8Vec4.html) +/// * [`Vec4`](type.Vec4.html) pub type TVec4 = Vector4; /// A 1D vector with boolean components. pub type BVec1 = Vector1; diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index 15c55990..09812ebe 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -6,30 +6,75 @@ use aliases::{TVec, TMat}; use traits::{Number, Dimension, Alloc}; /// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`. +/// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec3(-1.0, 0.0, 2.0); +/// assert_eq!(glm::vec3(1.0, 0.0, 2.0), glm::abs(&vec)); +/// +/// let mat = glm::mat2(-0.0, 1.0, -3.0, 2.0); +/// assert_eq!(glm::mat2(0.0, 1.0, 3.0, 2.0), glm::abs(&mat)); +/// ``` +/// +/// # See also: +/// +/// * [`sign`](fn.sign.html) pub fn abs(x: &TMat) -> TMat where DefaultAllocator: Alloc { x.abs() } /// For each matrix or vector component returns a value equal to the nearest integer that is greater than or equal to `x`. +/// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec3(-1.5, 0.5, 2.8); +/// assert_eq!(glm::vec3(-1.0, 1.0, 3.0), glm::ceil(&vec)); +/// ``` +/// +/// # See also: +/// +/// * [`ceil`](fn.ceil.html) +/// * [`floor`](fn.floor.html) +/// * [`fract`](fn.fract.html) +/// * [`round`](fn.round.html) +/// * [`trunc`](fn.trunc.html) pub fn ceil(x: &TVec) -> TVec where DefaultAllocator: Alloc { x.map(|x| x.ceil()) } - /// Returns `min(max(x, min_val), max_val)`. +/// +/// # See also: +/// +/// * [`clamp`](fn.clamp.html) +/// * [`clamp_vec`](fn.clamp_vec.html) pub fn clamp_scalar(x: N, min_val: N, max_val: N) -> N { na::clamp(x, min_val, max_val) } /// Returns `min(max(x[i], min_val), max_val)` for each component in `x` using the floating-point values `min_val and `max_val`. +/// +/// # See also: +/// +/// * [`clamp_scalar`](fn.clamp_scalar.html) +/// * [`clamp_vec`](fn.clamp_vec.html) pub fn clamp(x: &TVec, min_val: N, max_val: N) -> TVec where DefaultAllocator: Alloc { x.map(|x| na::clamp(x, min_val, max_val)) } /// Returns `min(max(x[i], min_val[i]), max_val[i])` for each component in `x` using the components of `min_val` and `max_val` as bounds. +/// +/// # See also: +/// +/// * [`clamp_scalar`](fn.clamp_scalar.html) +/// * [`clamp`](fn.clamp.html) pub fn clamp_vec(x: &TVec, min_val: &TVec, max_val: &TVec) -> TVec where DefaultAllocator: Alloc { na::clamp(x.clone(), min_val.clone(), max_val.clone()) @@ -38,6 +83,16 @@ pub fn clamp_vec(x: &TVec, min_val: &TVec, /// Returns a signed integer value representing the encoding of a floating-point value. /// /// The floating-point value's bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int_vec`](fn.float_bits_to_int_vec.html) +/// * [`float_bits_to_uint`](fn.float_bits_to_uint.html) +/// * [`float_bits_to_uint_vec`](fn.float_bits_to_uint_vec.html) +/// * [`int_bits_to_float`](fn.int_bits_to_float.html) +/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) +/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) +/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_int(v: f32) -> i32 { unsafe { mem::transmute(v) } } @@ -45,6 +100,16 @@ pub fn float_bits_to_int(v: f32) -> i32 { /// Returns a signed integer value representing the encoding of each component of `v`. /// /// The floating point value's bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int`](fn.float_bits_to_int.html) +/// * [`float_bits_to_uint`](fn.float_bits_to_uint.html) +/// * [`float_bits_to_uint_vec`](fn.float_bits_to_uint_vec.html) +/// * [`int_bits_to_float`](fn.int_bits_to_float.html) +/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) +/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) +/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_int_vec(v: &TVec) -> TVec where DefaultAllocator: Alloc { v.map(|v| float_bits_to_int(v)) @@ -53,6 +118,16 @@ pub fn float_bits_to_int_vec(v: &TVec) -> TVec /// Returns an unsigned integer value representing the encoding of a floating-point value. /// /// The floating-point value's bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int`](fn.float_bits_to_int.html) +/// * [`float_bits_to_int_vec`](fn.float_bits_to_int_vec.html) +/// * [`float_bits_to_uint_vec`](fn.float_bits_to_uint_vec.html) +/// * [`int_bits_to_float`](fn.int_bits_to_float.html) +/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) +/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) +/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_uint(v: f32) -> u32 { unsafe { mem::transmute(v) } } @@ -60,12 +135,37 @@ pub fn float_bits_to_uint(v: f32) -> u32 { /// Returns an unsigned integer value representing the encoding of each component of `v`. /// /// The floating point value's bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int`](fn.float_bits_to_int.html) +/// * [`float_bits_to_int_vec`](fn.float_bits_to_int_vec.html) +/// * [`float_bits_to_uint`](fn.float_bits_to_uint.html) +/// * [`int_bits_to_float`](fn.int_bits_to_float.html) +/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) +/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) +/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_uint_vec(v: &TVec) -> TVec where DefaultAllocator: Alloc { v.map(|v| float_bits_to_uint(v)) } /// Returns componentwise a value equal to the nearest integer that is less then or equal to `x`. +/// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec3(-1.5, 0.5, 2.8); +/// assert_eq!(glm::vec3(-2.0, 0.0, 2.0), glm::floor(&vec)); +/// ``` +/// +/// # See also: +/// +/// * [`ceil`](fn.ceil.html) +/// * [`fract`](fn.fract.html) +/// * [`round`](fn.round.html) +/// * [`trunc`](fn.trunc.html) pub fn floor(x: &TVec) -> TVec where DefaultAllocator: Alloc { x.map(|x| x.floor()) @@ -78,6 +178,21 @@ pub fn floor(x: &TVec) -> TVec //} /// Returns the fractional part of each component of `x`. +/// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec3(-1.5, 0.5, 2.25); +/// assert_eq!(glm::vec3(-0.5, 0.5, 0.25), glm::fract(&vec)); +/// ``` +/// +/// # See also: +/// +/// * [`ceil`](fn.ceil.html) +/// * [`floor`](fn.floor.html) +/// * [`round`](fn.round.html) +/// * [`trunc`](fn.trunc.html) pub fn fract(x: &TVec) -> TVec where DefaultAllocator: Alloc { x.map(|x| x.fract()) @@ -94,6 +209,16 @@ pub fn fract(x: &TVec) -> TVec /// Returns a floating-point value corresponding to a signed integer encoding of a floating-point value. /// /// If an inf or NaN is passed in, it will not signal, and the resulting floating point value is unspecified. Otherwise, the bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int`](fn.float_bits_to_int.html) +/// * [`float_bits_to_int_vec`](fn.float_bits_to_int_vec.html) +/// * [`float_bits_to_uint`](fn.float_bits_to_uint.html) +/// * [`float_bits_to_uint_vec`](fn.float_bits_to_uint_vec.html) +/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) +/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) +/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn int_bits_to_float(v: i32) -> f32 { unsafe { mem::transmute(v) } @@ -102,6 +227,16 @@ pub fn int_bits_to_float(v: i32) -> f32 { /// For each components of `v`, returns a floating-point value corresponding to a signed integer encoding of a floating-point value. /// /// If an inf or NaN is passed in, it will not signal, and the resulting floating point value is unspecified. Otherwise, the bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int`](fn.float_bits_to_int.html) +/// * [`float_bits_to_int_vec`](fn.float_bits_to_int_vec.html) +/// * [`float_bits_to_uint`](fn.float_bits_to_uint.html) +/// * [`float_bits_to_uint_vec`](fn.float_bits_to_uint_vec.html) +/// * [`int_bits_to_float`](fn.int_bits_to_float.html) +/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) +/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn int_bits_to_float_vec(v: &TVec) -> TVec where DefaultAllocator: Alloc { v.map(|v| int_bits_to_float(v)) @@ -135,12 +270,20 @@ pub fn mix(x: N, y: N, a: N) -> N { /// Component-wise modulus. /// /// Returns `x - y * floor(x / y)` for each component in `x` using the corresponding component of `y`. +/// +/// # See also: +/// +/// * [`modf`](fn.modf.html) pub fn modf_vec(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x % y) } /// Modulus between two values. +/// +/// # See also: +/// +/// * [`modf_vec`](fn.modf_vec.html) pub fn modf(x: N, i: N) -> N { x % i } @@ -148,6 +291,21 @@ pub fn modf(x: N, i: N) -> N { /// Component-wise rounding. /// /// Values equal to `0.5` are rounded away from `0.0`. +/// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec4(-1.5, 0.6, 1.5, -3.2); +/// assert_eq!(glm::vec4(-2.0, 1.0, 2.0, -3.0), glm::round(&vec)); +/// ``` +/// +/// # See also: +/// +/// * [`ceil`](fn.ceil.html) +/// * [`floor`](fn.floor.html) +/// * [`fract`](fn.fract.html) +/// * [`trunc`](fn.trunc.html) pub fn round(x: &TVec) -> TVec where DefaultAllocator: Alloc { x.map(|x| x.round()) @@ -198,6 +356,21 @@ pub fn step_vec(edge: &TVec, x: &TVec) -> T } /// Returns a value equal to the nearest integer to `x` whose absolute value is not larger than the absolute value of `x`. +/// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec3(-1.5, 0.5, 2.8); +/// assert_eq!(glm::vec3(-1.0, 0.0, 2.0), glm::trunc(&vec)); +/// ``` +/// +/// # See also: +/// +/// * [`ceil`](fn.ceil.html) +/// * [`floor`](fn.floor.html) +/// * [`fract`](fn.fract.html) +/// * [`round`](fn.round.html) pub fn trunc(x: &TVec) -> TVec where DefaultAllocator: Alloc { x.map(|x| x.trunc()) @@ -206,6 +379,16 @@ pub fn trunc(x: &TVec) -> TVec /// Returns a floating-point value corresponding to a unsigned integer encoding of a floating-point value. /// /// If an `inf` or `NaN` is passed in, it will not signal, and the resulting floating point value is unspecified. Otherwise, the bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int`](fn.float_bits_to_int.html) +/// * [`float_bits_to_int_vec`](fn.float_bits_to_int_vec.html) +/// * [`float_bits_to_uint`](fn.float_bits_to_uint.html) +/// * [`float_bits_to_uint_vec`](fn.float_bits_to_uint_vec.html) +/// * [`int_bits_to_float`](fn.int_bits_to_float.html) +/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) +/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) pub fn uint_bits_to_float_scalar(v: u32) -> f32 { unsafe { mem::transmute(v) } @@ -214,7 +397,17 @@ pub fn uint_bits_to_float_scalar(v: u32) -> f32 { /// For each component of `v`, returns a floating-point value corresponding to a unsigned integer encoding of a floating-point value. /// /// If an inf or NaN is passed in, it will not signal, and the resulting floating point value is unspecified. Otherwise, the bit-level representation is preserved. +/// +/// # See also: +/// +/// * [`float_bits_to_int`](fn.float_bits_to_int.html) +/// * [`float_bits_to_int_vec`](fn.float_bits_to_int_vec.html) +/// * [`float_bits_to_uint`](fn.float_bits_to_uint.html) +/// * [`float_bits_to_uint_vec`](fn.float_bits_to_uint_vec.html) +/// * [`int_bits_to_float`](fn.int_bits_to_float.html) +/// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) +/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn uint_bits_to_float(v: &TVec) -> TVec where DefaultAllocator: Alloc { v.map(|v| uint_bits_to_float_scalar(v)) -} \ No newline at end of file +} diff --git a/nalgebra-glm/src/constructors.rs b/nalgebra-glm/src/constructors.rs index 25a3432f..f19ae534 100644 --- a/nalgebra-glm/src/constructors.rs +++ b/nalgebra-glm/src/constructors.rs @@ -4,6 +4,15 @@ use aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TM /// Creates a new 1D vector. +/// +/// # Examples: +/// +/// Construct a vector of `bool`s: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let v = glm::vec1(true); +/// ``` pub fn vec1(x: N) -> TVec1 { TVec1::new(x) } diff --git a/nalgebra-glm/src/gtx/component_wise.rs b/nalgebra-glm/src/gtx/component_wise.rs index 1adec08c..56d4cff4 100644 --- a/nalgebra-glm/src/gtx/component_wise.rs +++ b/nalgebra-glm/src/gtx/component_wise.rs @@ -5,6 +5,17 @@ use aliases::TMat; /// The sum of every component of the given matrix or vector. /// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec2(3.0, 4.0); +/// assert_eq!(7.0, glm::comp_add(&vec)); +/// +/// let mat = glm::mat2(0.0, 1.0, -3.0, 3.0); +/// assert_eq!(1.0, glm::comp_add(&mat)); +/// ``` +/// /// # See also: /// /// * [`comp_max`](fn.comp_max.html) @@ -17,6 +28,17 @@ pub fn comp_add(m: &TMat) -> N /// The maximum of every component of the given matrix or vector. /// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec2(3.0, 4.0); +/// assert_eq!(4.0, glm::comp_max(&vec)); +/// +/// let mat = glm::mat2(0.0, 1.0, -3.0, 3.0); +/// assert_eq!(3.0, glm::comp_max(&mat)); +/// ``` +/// /// # See also: /// /// * [`comp_add`](fn.comp_add.html) @@ -33,6 +55,17 @@ pub fn comp_max(m: &TMat) -> N /// The minimum of every component of the given matrix or vector. /// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec2(3.0, 4.0); +/// assert_eq!(3.0, glm::comp_min(&vec)); +/// +/// let mat = glm::mat2(0.0, 1.0, -3.0, 3.0); +/// assert_eq!(-3.0, glm::comp_min(&mat)); +/// ``` +/// /// # See also: /// /// * [`comp_add`](fn.comp_add.html) @@ -49,6 +82,17 @@ pub fn comp_min(m: &TMat) -> N /// The product of every component of the given matrix or vector. /// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec2(3.0, 4.0); +/// assert_eq!(12.0, glm::comp_mul(&vec)); +/// +/// let mat = glm::mat2(1.0, 1.0, -3.0, 3.0); +/// assert_eq!(-9.0, glm::comp_mul(&mat)); +/// ``` +/// /// # See also: /// /// * [`comp_add`](fn.comp_add.html) diff --git a/nalgebra-glm/src/vector_relational.rs b/nalgebra-glm/src/vector_relational.rs index 1d24f59b..fe5d4b2d 100644 --- a/nalgebra-glm/src/vector_relational.rs +++ b/nalgebra-glm/src/vector_relational.rs @@ -5,9 +5,21 @@ use traits::{Number, Alloc, Dimension}; /// Checks that all the vector components are `true`. /// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec2(true, false); +/// assert_eq!(false, glm::all(&vec)); +/// +/// let vec = glm::vec2(true, true); +/// assert_eq!(true, glm::all(&vec)); +/// ``` +/// /// # See also: /// /// * [`any`](fn.any.html) +/// * [`not`](fn.not.html) pub fn all(v: &TVec) -> bool where DefaultAllocator: Alloc { v.iter().all(|x| *x) @@ -15,51 +27,145 @@ pub fn all(v: &TVec) -> bool /// Checks that at least one of the vector components is `true`. /// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec2(true, false); +/// assert_eq!(true, glm::any(&vec)); +/// +/// let vec = glm::vec2(true, true); +/// assert_eq!(true, glm::any(&vec)); +/// +/// let vec = glm::vec2(false, false); +/// assert_eq!(false, glm::any(&vec)); +/// ``` +/// /// # See also: /// /// * [`all`](fn.all.html) +/// * [`not`](fn.not.html) pub fn any(v: &TVec) -> bool where DefaultAllocator: Alloc { v.iter().any(|x| *x) } /// Component-wise equality comparison. +/// +/// See also: +/// +/// * [`equal`](fn.equal.html) +/// * [`greater_than`](fn.greater_than.html) +/// * [`greater_than_equal`](fn.greater_than_equal.html) +/// * [`less_than`](fn.less_than.html) +/// * [`less_than_equal`](fn.less_than_equal.html) +/// * [`not`](fn.not.html) +/// * [`not_equal`](fn.not_equal.html) pub fn equal(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x == y) } /// Component-wise `>` comparison. +/// +/// See also: +/// +/// * [`equal`](fn.equal.html) +/// * [`greater_than`](fn.greater_than.html) +/// * [`greater_than_equal`](fn.greater_than_equal.html) +/// * [`less_than`](fn.less_than.html) +/// * [`less_than_equal`](fn.less_than_equal.html) +/// * [`not`](fn.not.html) +/// * [`not_equal`](fn.not_equal.html) pub fn greater_than(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x > y) } /// Component-wise `>=` comparison. +/// +/// See also: +/// +/// * [`equal`](fn.equal.html) +/// * [`greater_than`](fn.greater_than.html) +/// * [`greater_than_equal`](fn.greater_than_equal.html) +/// * [`less_than`](fn.less_than.html) +/// * [`less_than_equal`](fn.less_than_equal.html) +/// * [`not`](fn.not.html) +/// * [`not_equal`](fn.not_equal.html) pub fn greater_than_equal(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x >= y) } /// Component-wise `<` comparison. +/// +/// See also: +/// +/// * [`equal`](fn.equal.html) +/// * [`greater_than`](fn.greater_than.html) +/// * [`greater_than_equal`](fn.greater_than_equal.html) +/// * [`less_than`](fn.less_than.html) +/// * [`less_than_equal`](fn.less_than_equal.html) +/// * [`not`](fn.not.html) +/// * [`not_equal`](fn.not_equal.html) pub fn less_than(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x < y) } /// Component-wise `>=` comparison. +/// +/// See also: +/// +/// * [`equal`](fn.equal.html) +/// * [`greater_than`](fn.greater_than.html) +/// * [`greater_than_equal`](fn.greater_than_equal.html) +/// * [`less_than`](fn.less_than.html) +/// * [`less_than_equal`](fn.less_than_equal.html) +/// * [`not`](fn.not.html) +/// * [`not_equal`](fn.not_equal.html) pub fn less_than_equal(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x <= y) } /// Component-wise not `!`. +/// +/// # Examples: +/// +/// ``` +/// # use nalgebra_glm as glm; +/// let vec = glm::vec2(true, false); +/// assert_eq!(glm::vec2(false, true), glm::not(&vec)); +/// ``` +/// +/// See also: +/// +/// * [`all`](fn.all.html) +/// * [`any`](fn.any.html) +/// * [`equal`](fn.equal.html) +/// * [`greater_than`](fn.greater_than.html) +/// * [`greater_than_equal`](fn.greater_than_equal.html) +/// * [`less_than`](fn.less_than.html) +/// * [`less_than_equal`](fn.less_than_equal.html) +/// * [`not`](fn.not.html) +/// * [`not_equal`](fn.not_equal.html) pub fn not(v: &TVec) -> TVec where DefaultAllocator: Alloc { v.map(|x| !x) } /// Component-wise not-equality `!=`. +/// +/// See also: +/// +/// * [`equal`](fn.equal.html) +/// * [`greater_than`](fn.greater_than.html) +/// * [`greater_than_equal`](fn.greater_than_equal.html) +/// * [`less_than`](fn.less_than.html) +/// * [`less_than_equal`](fn.less_than_equal.html) +/// * [`not_equal`](fn.not_equal.html) pub fn not_equal(x: &TVec, y: &TVec) -> TVec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x != y)