From 85074398d08b201c90ee91406ae4b1db5b538e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 8 Aug 2021 12:59:40 +0200 Subject: [PATCH] Fix nalgebra-glm --- nalgebra-glm/Cargo.toml | 2 +- nalgebra-glm/src/common.rs | 22 ++-- nalgebra-glm/src/constructors.rs | 5 +- nalgebra-glm/src/exponential.rs | 16 +-- nalgebra-glm/src/ext/matrix_clip_space.rs | 120 +++++++++++------- nalgebra-glm/src/ext/matrix_projection.rs | 17 +-- nalgebra-glm/src/ext/matrix_transform.rs | 18 +-- nalgebra-glm/src/ext/quaternion_common.rs | 17 +-- nalgebra-glm/src/ext/quaternion_geometric.rs | 12 +- nalgebra-glm/src/ext/quaternion_relational.rs | 11 +- nalgebra-glm/src/ext/quaternion_transform.rs | 13 +- .../src/ext/quaternion_trigonometric.rs | 9 +- nalgebra-glm/src/ext/scalar_constants.rs | 4 +- nalgebra-glm/src/geometric.rs | 12 +- nalgebra-glm/src/gtc/constants.rs | 55 ++++---- nalgebra-glm/src/gtc/matrix_inverse.rs | 6 +- nalgebra-glm/src/gtc/packing.rs | 10 +- nalgebra-glm/src/gtc/quaternion.rs | 27 ++-- nalgebra-glm/src/gtc/round.rs | 2 +- nalgebra-glm/src/gtc/type_ptr.rs | 6 +- nalgebra-glm/src/gtx/euler_angles.rs | 82 ++++++------ nalgebra-glm/src/gtx/matrix_cross_product.rs | 7 +- nalgebra-glm/src/gtx/norm.rs | 21 ++- nalgebra-glm/src/gtx/normal.rs | 4 +- nalgebra-glm/src/gtx/normalize_dot.rs | 6 +- nalgebra-glm/src/gtx/quaternion.rs | 37 +++--- .../src/gtx/rotate_normalized_axis.rs | 7 +- nalgebra-glm/src/gtx/rotate_vector.rs | 25 ++-- nalgebra-glm/src/gtx/transform.rs | 8 +- nalgebra-glm/src/gtx/transform2.rs | 4 +- nalgebra-glm/src/gtx/transform2d.rs | 6 +- nalgebra-glm/src/gtx/vector_angle.rs | 8 +- nalgebra-glm/src/gtx/vector_query.rs | 4 +- nalgebra-glm/src/integer.rs | 2 +- nalgebra-glm/src/lib.rs | 4 +- nalgebra-glm/src/matrix.rs | 8 +- nalgebra-glm/src/traits.rs | 15 ++- nalgebra-glm/src/trigonometric.rs | 33 ++--- 38 files changed, 353 insertions(+), 312 deletions(-) diff --git a/nalgebra-glm/Cargo.toml b/nalgebra-glm/Cargo.toml index bebacab8..6a2651bb 100644 --- a/nalgebra-glm/Cargo.toml +++ b/nalgebra-glm/Cargo.toml @@ -26,5 +26,5 @@ abomonation-serialize = [ "nalgebra/abomonation-serialize" ] [dependencies] num-traits = { version = "0.2", default-features = false } approx = { version = "0.5", default-features = false } -simba = { version = "0.5", default-features = false } +simba = { version = "0.6", default-features = false } nalgebra = { path = "..", version = "0.28", default-features = false } diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index 1efa80a3..6a7aa8bf 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -1,9 +1,9 @@ use core::mem; -use na::{self, RealField}; -use num::FromPrimitive; +use na; use crate::aliases::{TMat, TVec}; use crate::traits::Number; +use crate::RealNumber; /// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`. /// @@ -42,7 +42,7 @@ pub fn abs(x: &TMat) -> TMat /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) -pub fn ceil(x: &TVec) -> TVec { +pub fn ceil(x: &TVec) -> TVec { x.map(|x| x.ceil()) } @@ -214,7 +214,7 @@ pub fn float_bits_to_uint_vec(v: &TVec) -> TVec /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) -pub fn floor(x: &TVec) -> TVec { +pub fn floor(x: &TVec) -> TVec { x.map(|x| x.floor()) } @@ -240,13 +240,13 @@ pub fn floor(x: &TVec) -> TVec { /// * [`floor`](fn.floor.html) /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) -pub fn fract(x: &TVec) -> TVec { +pub fn fract(x: &TVec) -> TVec { x.map(|x| x.fract()) } //// TODO: should be implemented for TVec/TMat? ///// Returns the (significant, exponent) of this float number. -//pub fn frexp(x: T, exp: T) -> (T, T) { +//pub fn frexp(x: T, exp: T) -> (T, T) { // // TODO: is there a better approach? // let e = x.log2().ceil(); // (x * (-e).exp2(), e) @@ -297,7 +297,7 @@ pub fn int_bits_to_float_vec(v: &TVec) -> TVec { //} ///// Returns the (significant, exponent) of this float number. -//pub fn ldexp(x: T, exp: T) -> T { +//pub fn ldexp(x: T, exp: T) -> T { // // TODO: is there a better approach? // x * (exp).exp2() //} @@ -477,7 +477,7 @@ pub fn modf(x: T, i: T) -> T { /// * [`floor`](fn.floor.html) /// * [`fract`](fn.fract.html) /// * [`trunc`](fn.trunc.html) -pub fn round(x: &TVec) -> TVec { +pub fn round(x: &TVec) -> TVec { x.map(|x| x.round()) } @@ -508,8 +508,8 @@ pub fn sign(x: &TVec) -> TVec { /// This is useful in cases where you would want a threshold function with a smooth transition. /// This is equivalent to: `let result = clamp((x - edge0) / (edge1 - edge0), 0, 1); return t * t * (3 - 2 * t);` Results are undefined if `edge0 >= edge1`. pub fn smoothstep(edge0: T, edge1: T, x: T) -> T { - let _3: T = FromPrimitive::from_f64(3.0).unwrap(); - let _2: T = FromPrimitive::from_f64(2.0).unwrap(); + let _3 = T::from_subset(&3.0f64); + let _2 = T::from_subset(&2.0f64); let t = na::clamp((x - edge0) / (edge1 - edge0), T::zero(), T::one()); t * t * (_3 - t * _2) } @@ -549,7 +549,7 @@ pub fn step_vec(edge: &TVec, x: &TVec) -> /// * [`floor`](fn.floor.html) /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) -pub fn trunc(x: &TVec) -> TVec { +pub fn trunc(x: &TVec) -> TVec { x.map(|x| x.trunc()) } diff --git a/nalgebra-glm/src/constructors.rs b/nalgebra-glm/src/constructors.rs index c6641c6e..e998dd23 100644 --- a/nalgebra-glm/src/constructors.rs +++ b/nalgebra-glm/src/constructors.rs @@ -2,7 +2,8 @@ use crate::aliases::{ Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1, TVec2, TVec3, TVec4, }; -use na::{RealField, Scalar}; +use crate::RealNumber; +use na::Scalar; /// Creates a new 1D vector. /// @@ -178,6 +179,6 @@ pub fn mat4(m11: T, m12: T, m13: T, m14: T, } /// Creates a new quaternion. -pub fn quat(x: T, y: T, z: T, w: T) -> Qua { +pub fn quat(x: T, y: T, z: T, w: T) -> Qua { Qua::new(w, x, y, z) } diff --git a/nalgebra-glm/src/exponential.rs b/nalgebra-glm/src/exponential.rs index 54502123..6de9fc59 100644 --- a/nalgebra-glm/src/exponential.rs +++ b/nalgebra-glm/src/exponential.rs @@ -1,12 +1,12 @@ use crate::aliases::TVec; -use na::RealField; +use crate::RealNumber; /// Component-wise exponential. /// /// # See also: /// /// * [`exp2`](fn.exp2.html) -pub fn exp(v: &TVec) -> TVec { +pub fn exp(v: &TVec) -> TVec { v.map(|x| x.exp()) } @@ -15,7 +15,7 @@ pub fn exp(v: &TVec) -> TVec { /// # See also: /// /// * [`exp`](fn.exp.html) -pub fn exp2(v: &TVec) -> TVec { +pub fn exp2(v: &TVec) -> TVec { v.map(|x| x.exp2()) } @@ -24,7 +24,7 @@ pub fn exp2(v: &TVec) -> TVec { /// # See also: /// /// * [`sqrt`](fn.sqrt.html) -pub fn inversesqrt(v: &TVec) -> TVec { +pub fn inversesqrt(v: &TVec) -> TVec { v.map(|x| T::one() / x.sqrt()) } @@ -33,7 +33,7 @@ pub fn inversesqrt(v: &TVec) -> TVec { /// # See also: /// /// * [`log2`](fn.log2.html) -pub fn log(v: &TVec) -> TVec { +pub fn log(v: &TVec) -> TVec { v.map(|x| x.ln()) } @@ -42,12 +42,12 @@ pub fn log(v: &TVec) -> TVec { /// # See also: /// /// * [`log`](fn.log.html) -pub fn log2(v: &TVec) -> TVec { +pub fn log2(v: &TVec) -> TVec { v.map(|x| x.log2()) } /// Component-wise power. -pub fn pow(base: &TVec, exponent: &TVec) -> TVec { +pub fn pow(base: &TVec, exponent: &TVec) -> TVec { base.zip_map(exponent, |b, e| b.powf(e)) } @@ -59,6 +59,6 @@ pub fn pow(base: &TVec, exponent: &TVec(v: &TVec) -> TVec { +pub fn sqrt(v: &TVec) -> TVec { v.map(|x| x.sqrt()) } diff --git a/nalgebra-glm/src/ext/matrix_clip_space.rs b/nalgebra-glm/src/ext/matrix_clip_space.rs index bb268a54..5ea39d23 100644 --- a/nalgebra-glm/src/ext/matrix_clip_space.rs +++ b/nalgebra-glm/src/ext/matrix_clip_space.rs @@ -1,51 +1,51 @@ use crate::aliases::TMat4; -use na::RealField; +use crate::RealNumber; -//pub fn frustum(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} -//pub fn frustum_lh(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_lh(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_lr_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_lr_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_lh_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_lh_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_rh(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_rh_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_rh_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { +//pub fn frustum_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} -//pub fn infinite_perspective(fovy: T, aspect: T, near: T) -> TMat4 { +//pub fn infinite_perspective(fovy: T, aspect: T, near: T) -> TMat4 { // unimplemented!() //} // -//pub fn infinite_perspective_lh(fovy: T, aspect: T, near: T) -> TMat4 { +//pub fn infinite_perspective_lh(fovy: T, aspect: T, near: T) -> TMat4 { // unimplemented!() //} // -//pub fn infinite_ortho(left: T, right: T, bottom: T, top: T) -> TMat4 { +//pub fn infinite_ortho(left: T, right: T, bottom: T, top: T) -> TMat4 { // unimplemented!() //} @@ -60,7 +60,7 @@ use na::RealField; /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { +pub fn ortho(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { ortho_rh_no(left, right, bottom, top, znear, zfar) } @@ -75,7 +75,14 @@ pub fn ortho(left: T, right: T, bottom: T, top: T, znear: T, zfar: /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { +pub fn ortho_lh( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { ortho_lh_no(left, right, bottom, top, znear, zfar) } @@ -90,7 +97,7 @@ pub fn ortho_lh(left: T, right: T, bottom: T, top: T, znear: T, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh_no( +pub fn ortho_lh_no( left: T, right: T, bottom: T, @@ -122,7 +129,7 @@ pub fn ortho_lh_no( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh_zo( +pub fn ortho_lh_zo( left: T, right: T, bottom: T, @@ -155,7 +162,14 @@ pub fn ortho_lh_zo( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_no(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { +pub fn ortho_no( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { ortho_rh_no(left, right, bottom, top, znear, zfar) } @@ -170,7 +184,14 @@ pub fn ortho_no(left: T, right: T, bottom: T, top: T, znear: T, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { +pub fn ortho_rh( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { ortho_rh_no(left, right, bottom, top, znear, zfar) } @@ -185,7 +206,7 @@ pub fn ortho_rh(left: T, right: T, bottom: T, top: T, znear: T, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh_no( +pub fn ortho_rh_no( left: T, right: T, bottom: T, @@ -217,7 +238,7 @@ pub fn ortho_rh_no( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh_zo( +pub fn ortho_rh_zo( left: T, right: T, bottom: T, @@ -250,7 +271,14 @@ pub fn ortho_rh_zo( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_zo(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { +pub fn ortho_zo( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { ortho_rh_zo(left, right, bottom, top, znear, zfar) } @@ -264,7 +292,7 @@ pub fn ortho_zo(left: T, right: T, bottom: T, top: T, znear: T, zf /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { +pub fn perspective_fov(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_no(fov, width, height, near, far) } @@ -278,7 +306,7 @@ pub fn perspective_fov(fov: T, width: T, height: T, near: T, far: /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { +pub fn perspective_fov_lh(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_lh_no(fov, width, height, near, far) } @@ -292,7 +320,7 @@ pub fn perspective_fov_lh(fov: T, width: T, height: T, near: T, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh_no( +pub fn perspective_fov_lh_no( fov: T, width: T, height: T, @@ -328,7 +356,7 @@ pub fn perspective_fov_lh_no( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh_zo( +pub fn perspective_fov_lh_zo( fov: T, width: T, height: T, @@ -364,7 +392,7 @@ pub fn perspective_fov_lh_zo( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_no(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { +pub fn perspective_fov_no(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_no(fov, width, height, near, far) } @@ -378,7 +406,7 @@ pub fn perspective_fov_no(fov: T, width: T, height: T, near: T, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { +pub fn perspective_fov_rh(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_no(fov, width, height, near, far) } @@ -392,7 +420,7 @@ pub fn perspective_fov_rh(fov: T, width: T, height: T, near: T, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh_no( +pub fn perspective_fov_rh_no( fov: T, width: T, height: T, @@ -428,7 +456,7 @@ pub fn perspective_fov_rh_no( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh_zo( +pub fn perspective_fov_rh_zo( fov: T, width: T, height: T, @@ -464,7 +492,7 @@ pub fn perspective_fov_rh_zo( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_zo(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { +pub fn perspective_fov_zo(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_zo(fov, width, height, near, far) } @@ -479,7 +507,7 @@ pub fn perspective_fov_zo(fov: T, width: T, height: T, near: T, fa /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective(aspect: T, fovy: T, near: T, far: T) -> TMat4 { // TODO: Breaking change - revert back to proper glm conventions? // // Prior to changes to support configuring the behaviour of this function it was simply @@ -508,7 +536,7 @@ pub fn perspective(aspect: T, fovy: T, near: T, far: T) -> TMat4(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_lh(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_lh_no(aspect, fovy, near, far) } @@ -523,7 +551,7 @@ pub fn perspective_lh(aspect: T, fovy: T, near: T, far: T) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_lh_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_lh_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." @@ -559,7 +587,7 @@ pub fn perspective_lh_no(aspect: T, fovy: T, near: T, far: T) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_lh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_lh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." @@ -595,7 +623,7 @@ pub fn perspective_lh_zo(aspect: T, fovy: T, near: T, far: T) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_rh_no(aspect, fovy, near, far) } @@ -610,7 +638,7 @@ pub fn perspective_no(aspect: T, fovy: T, near: T, far: T) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_rh(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_rh(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_rh_no(aspect, fovy, near, far) } @@ -625,7 +653,7 @@ pub fn perspective_rh(aspect: T, fovy: T, near: T, far: T) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_rh_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_rh_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." @@ -662,7 +690,7 @@ pub fn perspective_rh_no(aspect: T, fovy: T, near: T, far: T) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_rh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_rh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." @@ -699,7 +727,7 @@ pub fn perspective_rh_zo(aspect: T, fovy: T, near: T, far: T) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn perspective_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_rh_zo(aspect, fovy, near, far) } @@ -713,7 +741,7 @@ pub fn perspective_zo(aspect: T, fovy: T, near: T, far: T) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn infinite_perspective_rh_no(aspect: T, fovy: T, near: T) -> TMat4 { +pub fn infinite_perspective_rh_no(aspect: T, fovy: T, near: T) -> TMat4 { let f = T::one() / (fovy * na::convert(0.5)).tan(); let mut mat = TMat4::zeros(); @@ -738,7 +766,7 @@ pub fn infinite_perspective_rh_no(aspect: T, fovy: T, near: T) -> /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. /// // https://discourse.nphysics.org/t/reversed-z-and-infinite-zfar-in-projections/341/2 -pub fn infinite_perspective_rh_zo(aspect: T, fovy: T, near: T) -> TMat4 { +pub fn infinite_perspective_rh_zo(aspect: T, fovy: T, near: T) -> TMat4 { let f = T::one() / (fovy * na::convert(0.5)).tan(); let mut mat = TMat4::zeros(); @@ -763,7 +791,7 @@ pub fn infinite_perspective_rh_zo(aspect: T, fovy: T, near: T) -> /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. // NOTE: The variants `_no` of reversed perspective are not useful. -pub fn reversed_perspective_rh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { +pub fn reversed_perspective_rh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { let one = T::one(); let two = crate::convert(2.0); let mut mat = TMat4::zeros(); @@ -791,7 +819,7 @@ pub fn reversed_perspective_rh_zo(aspect: T, fovy: T, near: T, far /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. // Credit: https://discourse.nphysics.org/t/reversed-z-and-infinite-zfar-in-projections/341/2 // NOTE: The variants `_no` of reversed perspective are not useful. -pub fn reversed_infinite_perspective_rh_zo(aspect: T, fovy: T, near: T) -> TMat4 { +pub fn reversed_infinite_perspective_rh_zo(aspect: T, fovy: T, near: T) -> TMat4 { let f = T::one() / (fovy * na::convert(0.5)).tan(); let mut mat = TMat4::zeros(); @@ -803,10 +831,10 @@ pub fn reversed_infinite_perspective_rh_zo(aspect: T, fovy: T, nea mat } -//pub fn tweaked_infinite_perspective(fovy: T, aspect: T, near: T) -> TMat4 { +//pub fn tweaked_infinite_perspective(fovy: T, aspect: T, near: T) -> TMat4 { // unimplemented!() //} // -//pub fn tweaked_infinite_perspective_ep(fovy: T, aspect: T, near: T, ep: T) -> TMat4 { +//pub fn tweaked_infinite_perspective_ep(fovy: T, aspect: T, near: T, ep: T) -> TMat4 { // unimplemented!() //} diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index b9d8f045..ad925a91 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -1,6 +1,7 @@ -use na::{self, RealField}; +use na; use crate::aliases::{TMat4, TVec2, TVec3, TVec4}; +use crate::RealNumber; /// Define a picking region. /// @@ -9,7 +10,7 @@ use crate::aliases::{TMat4, TVec2, TVec3, TVec4}; /// * `center` - Specify the center of a picking region in window coordinates. /// * `delta` - Specify the width and height, respectively, of the picking region in window coordinates. /// * `viewport` - Rendering viewport. -pub fn pick_matrix( +pub fn pick_matrix( center: &TVec2, delta: &TVec2, viewport: &TVec4, @@ -45,7 +46,7 @@ pub fn pick_matrix( /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn project( +pub fn project( obj: &TVec3, model: &TMat4, proj: &TMat4, @@ -72,7 +73,7 @@ pub fn project( /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn project_no( +pub fn project_no( obj: &TVec3, model: &TMat4, proj: &TMat4, @@ -100,7 +101,7 @@ pub fn project_no( /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn project_zo( +pub fn project_zo( obj: &TVec3, model: &TMat4, proj: &TMat4, @@ -133,7 +134,7 @@ pub fn project_zo( /// * [`project_zo`](fn.project_zo.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn unproject( +pub fn unproject( win: &TVec3, model: &TMat4, proj: &TMat4, @@ -160,7 +161,7 @@ pub fn unproject( /// * [`project_zo`](fn.project_zo.html) /// * [`unproject`](fn.unproject.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn unproject_no( +pub fn unproject_no( win: &TVec3, model: &TMat4, proj: &TMat4, @@ -197,7 +198,7 @@ pub fn unproject_no( /// * [`project_zo`](fn.project_zo.html) /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) -pub fn unproject_zo( +pub fn unproject_zo( win: &TVec3, model: &TMat4, proj: &TMat4, diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index 821b585a..793593b5 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -1,7 +1,7 @@ -use na::{Point3, RealField, Rotation3, Unit}; +use na::{Point3, Rotation3, Unit}; use crate::aliases::{TMat, TMat4, TVec, TVec3}; -use crate::traits::Number; +use crate::traits::{Number, RealNumber}; /// The identity matrix. pub fn identity() -> TMat { @@ -20,7 +20,7 @@ pub fn identity() -> TMat { /// /// * [`look_at_lh`](fn.look_at_lh.html) /// * [`look_at_rh`](fn.look_at_rh.html) -pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { +pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { look_at_rh(eye, center, up) } @@ -36,7 +36,7 @@ pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) - /// /// * [`look_at`](fn.look_at.html) /// * [`look_at_rh`](fn.look_at_rh.html) -pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { +pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { TMat::look_at_lh(&Point3::from(*eye), &Point3::from(*center), up) } @@ -52,7 +52,7 @@ pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3 /// /// * [`look_at`](fn.look_at.html) /// * [`look_at_lh`](fn.look_at_lh.html) -pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { +pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { TMat::look_at_rh(&Point3::from(*eye), &Point3::from(*center), up) } @@ -71,7 +71,7 @@ pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3 /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate(m: &TMat4, angle: T, axis: &TVec3) -> TMat4 { +pub fn rotate(m: &TMat4, angle: T, axis: &TVec3) -> TMat4 { m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous() } @@ -89,7 +89,7 @@ pub fn rotate(m: &TMat4, angle: T, axis: &TVec3) -> TMat4 /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate_x(m: &TMat4, angle: T) -> TMat4 { +pub fn rotate_x(m: &TMat4, angle: T) -> TMat4 { rotate(m, angle, &TVec::x()) } @@ -107,7 +107,7 @@ pub fn rotate_x(m: &TMat4, angle: T) -> TMat4 { /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate_y(m: &TMat4, angle: T) -> TMat4 { +pub fn rotate_y(m: &TMat4, angle: T) -> TMat4 { rotate(m, angle, &TVec::y()) } @@ -125,7 +125,7 @@ pub fn rotate_y(m: &TMat4, angle: T) -> TMat4 { /// * [`rotate_y`](fn.rotate_y.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate_z(m: &TMat4, angle: T) -> TMat4 { +pub fn rotate_z(m: &TMat4, angle: T) -> TMat4 { rotate(m, angle, &TVec::z()) } diff --git a/nalgebra-glm/src/ext/quaternion_common.rs b/nalgebra-glm/src/ext/quaternion_common.rs index fd3dbc2b..44b4a5bf 100644 --- a/nalgebra-glm/src/ext/quaternion_common.rs +++ b/nalgebra-glm/src/ext/quaternion_common.rs @@ -1,36 +1,37 @@ -use na::{self, RealField, Unit}; +use na::{self, Unit}; use crate::aliases::Qua; +use crate::RealNumber; /// The conjugate of `q`. -pub fn quat_conjugate(q: &Qua) -> Qua { +pub fn quat_conjugate(q: &Qua) -> Qua { q.conjugate() } /// The inverse of `q`. -pub fn quat_inverse(q: &Qua) -> Qua { +pub fn quat_inverse(q: &Qua) -> Qua { q.try_inverse().unwrap_or_else(na::zero) } -//pub fn quat_isinf(x: &Qua) -> TVec { +//pub fn quat_isinf(x: &Qua) -> TVec { // x.coords.map(|e| e.is_inf()) //} -//pub fn quat_isnan(x: &Qua) -> TVec { +//pub fn quat_isnan(x: &Qua) -> TVec { // x.coords.map(|e| e.is_nan()) //} /// Interpolate linearly between `x` and `y`. -pub fn quat_lerp(x: &Qua, y: &Qua, a: T) -> Qua { +pub fn quat_lerp(x: &Qua, y: &Qua, a: T) -> Qua { x.lerp(y, a) } -//pub fn quat_mix(x: &Qua, y: &Qua, a: T) -> Qua { +//pub fn quat_mix(x: &Qua, y: &Qua, a: T) -> Qua { // x * (T::one() - a) + y * a //} /// Interpolate spherically between `x` and `y`. -pub fn quat_slerp(x: &Qua, y: &Qua, a: T) -> Qua { +pub fn quat_slerp(x: &Qua, y: &Qua, a: T) -> Qua { Unit::new_normalize(*x) .slerp(&Unit::new_normalize(*y), a) .into_inner() diff --git a/nalgebra-glm/src/ext/quaternion_geometric.rs b/nalgebra-glm/src/ext/quaternion_geometric.rs index 7930a8da..c688b15d 100644 --- a/nalgebra-glm/src/ext/quaternion_geometric.rs +++ b/nalgebra-glm/src/ext/quaternion_geometric.rs @@ -1,28 +1,28 @@ -use na::RealField; +use crate::RealNumber; use crate::aliases::Qua; /// Multiplies two quaternions. -pub fn quat_cross(q1: &Qua, q2: &Qua) -> Qua { +pub fn quat_cross(q1: &Qua, q2: &Qua) -> Qua { q1 * q2 } /// The scalar product of two quaternions. -pub fn quat_dot(x: &Qua, y: &Qua) -> T { +pub fn quat_dot(x: &Qua, y: &Qua) -> T { x.dot(y) } /// The magnitude of the quaternion `q`. -pub fn quat_length(q: &Qua) -> T { +pub fn quat_length(q: &Qua) -> T { q.norm() } /// The magnitude of the quaternion `q`. -pub fn quat_magnitude(q: &Qua) -> T { +pub fn quat_magnitude(q: &Qua) -> T { q.norm() } /// Normalizes the quaternion `q`. -pub fn quat_normalize(q: &Qua) -> Qua { +pub fn quat_normalize(q: &Qua) -> Qua { q.normalize() } diff --git a/nalgebra-glm/src/ext/quaternion_relational.rs b/nalgebra-glm/src/ext/quaternion_relational.rs index 282a3614..b9f6eaf5 100644 --- a/nalgebra-glm/src/ext/quaternion_relational.rs +++ b/nalgebra-glm/src/ext/quaternion_relational.rs @@ -1,23 +1,22 @@ -use na::RealField; - use crate::aliases::{Qua, TVec}; +use crate::RealNumber; /// Component-wise equality comparison between two quaternions. -pub fn quat_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_equal(x: &Qua, y: &Qua) -> TVec { crate::equal(&x.coords, &y.coords) } /// Component-wise approximate equality comparison between two quaternions. -pub fn quat_equal_eps(x: &Qua, y: &Qua, epsilon: T) -> TVec { +pub fn quat_equal_eps(x: &Qua, y: &Qua, epsilon: T) -> TVec { crate::equal_eps(&x.coords, &y.coords, epsilon) } /// Component-wise non-equality comparison between two quaternions. -pub fn quat_not_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_not_equal(x: &Qua, y: &Qua) -> TVec { crate::not_equal(&x.coords, &y.coords) } /// Component-wise approximate non-equality comparison between two quaternions. -pub fn quat_not_equal_eps(x: &Qua, y: &Qua, epsilon: T) -> TVec { +pub fn quat_not_equal_eps(x: &Qua, y: &Qua, epsilon: T) -> TVec { crate::not_equal_eps(&x.coords, &y.coords, epsilon) } diff --git a/nalgebra-glm/src/ext/quaternion_transform.rs b/nalgebra-glm/src/ext/quaternion_transform.rs index 34689cb4..17566c17 100644 --- a/nalgebra-glm/src/ext/quaternion_transform.rs +++ b/nalgebra-glm/src/ext/quaternion_transform.rs @@ -1,27 +1,28 @@ -use na::{RealField, Unit, UnitQuaternion}; +use na::{Unit, UnitQuaternion}; use crate::aliases::{Qua, TVec3}; +use crate::RealNumber; /// Computes the quaternion exponential. -pub fn quat_exp(q: &Qua) -> Qua { +pub fn quat_exp(q: &Qua) -> Qua { q.exp() } /// Computes the quaternion logarithm. -pub fn quat_log(q: &Qua) -> Qua { +pub fn quat_log(q: &Qua) -> Qua { q.ln() } /// Raises the quaternion `q` to the power `y`. -pub fn quat_pow(q: &Qua, y: T) -> Qua { +pub fn quat_pow(q: &Qua, y: T) -> Qua { q.powf(y) } /// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`. -pub fn quat_rotate(q: &Qua, angle: T, axis: &TVec3) -> Qua { +pub fn quat_rotate(q: &Qua, angle: T, axis: &TVec3) -> Qua { q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner() } -//pub fn quat_sqrt(q: &Qua) -> Qua { +//pub fn quat_sqrt(q: &Qua) -> Qua { // unimplemented!() //} diff --git a/nalgebra-glm/src/ext/quaternion_trigonometric.rs b/nalgebra-glm/src/ext/quaternion_trigonometric.rs index fdd21250..59d37e03 100644 --- a/nalgebra-glm/src/ext/quaternion_trigonometric.rs +++ b/nalgebra-glm/src/ext/quaternion_trigonometric.rs @@ -1,19 +1,20 @@ -use na::{RealField, Unit, UnitQuaternion}; +use na::{Unit, UnitQuaternion}; use crate::aliases::{Qua, TVec3}; +use crate::RealNumber; /// The rotation angle of this quaternion assumed to be normalized. -pub fn quat_angle(x: &Qua) -> T { +pub fn quat_angle(x: &Qua) -> T { UnitQuaternion::from_quaternion(*x).angle() } /// Creates a quaternion from an axis and an angle. -pub fn quat_angle_axis(angle: T, axis: &TVec3) -> Qua { +pub fn quat_angle_axis(angle: T, axis: &TVec3) -> Qua { UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner() } /// The rotation axis of a quaternion assumed to be normalized. -pub fn quat_axis(x: &Qua) -> TVec3 { +pub fn quat_axis(x: &Qua) -> TVec3 { if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() { a.into_inner() } else { diff --git a/nalgebra-glm/src/ext/scalar_constants.rs b/nalgebra-glm/src/ext/scalar_constants.rs index 89d6f969..8ae418f2 100644 --- a/nalgebra-glm/src/ext/scalar_constants.rs +++ b/nalgebra-glm/src/ext/scalar_constants.rs @@ -1,5 +1,5 @@ +use crate::RealNumber; use approx::AbsDiffEq; -use na::RealField; /// Default epsilon value used for approximate comparison. pub fn epsilon>() -> T { @@ -22,6 +22,6 @@ pub fn epsilon>() -> T { /// * [`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() -> T { +pub fn pi() -> T { T::pi() } diff --git a/nalgebra-glm/src/geometric.rs b/nalgebra-glm/src/geometric.rs index 3942756d..95b78c96 100644 --- a/nalgebra-glm/src/geometric.rs +++ b/nalgebra-glm/src/geometric.rs @@ -1,4 +1,4 @@ -use na::RealField; +use crate::RealNumber; use crate::aliases::{TVec, TVec3}; use crate::traits::Number; @@ -13,7 +13,7 @@ pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { /// # See also: /// /// * [`distance2`](fn.distance2.html) -pub fn distance(p0: &TVec, p1: &TVec) -> T { +pub fn distance(p0: &TVec, p1: &TVec) -> T { (p1 - p0).norm() } @@ -44,7 +44,7 @@ pub fn faceforward( /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn length(x: &TVec) -> T { +pub fn length(x: &TVec) -> T { x.norm() } @@ -57,12 +57,12 @@ pub fn length(x: &TVec) -> T { /// * [`length`](fn.length.html) /// * [`magnitude2`](fn.magnitude2.html) /// * [`nalgebra::norm`](../nalgebra/fn.norm.html) -pub fn magnitude(x: &TVec) -> T { +pub fn magnitude(x: &TVec) -> T { x.norm() } /// Normalizes a vector. -pub fn normalize(x: &TVec) -> TVec { +pub fn normalize(x: &TVec) -> TVec { x.normalize() } @@ -73,7 +73,7 @@ pub fn reflect_vec(i: &TVec, n: &TVec) -> } /// For the incident vector `i` and surface normal `n`, and the ratio of indices of refraction `eta`, return the refraction vector. -pub fn refract_vec( +pub fn refract_vec( i: &TVec, n: &TVec, eta: T, diff --git a/nalgebra-glm/src/gtc/constants.rs b/nalgebra-glm/src/gtc/constants.rs index 545d6b17..b08be4a9 100644 --- a/nalgebra-glm/src/gtc/constants.rs +++ b/nalgebra-glm/src/gtc/constants.rs @@ -1,14 +1,15 @@ -use na::{self, RealField}; +use crate::RealNumber; +use na; /// The Euler constant. /// /// This is a shorthand alias for [`euler`](fn.euler.html). -pub fn e() -> T { +pub fn e() -> T { T::e() } /// The Euler constant. -pub fn euler() -> T { +pub fn euler() -> T { T::e() } @@ -28,12 +29,12 @@ pub fn euler() -> T { /// * [`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() -> T { +pub fn four_over_pi() -> T { na::convert::<_, T>(4.0) / T::pi() } /// Returns the golden ratio. -pub fn golden_ratio() -> T { +pub fn golden_ratio() -> T { (T::one() + root_five()) / na::convert(2.0) } @@ -53,7 +54,7 @@ pub fn golden_ratio() -> T { /// * [`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() -> T { +pub fn half_pi() -> T { T::frac_pi_2() } @@ -63,7 +64,7 @@ pub fn half_pi() -> T { /// /// * [`ln_ten`](fn.ln_ten.html) /// * [`ln_two`](fn.ln_two.html) -pub fn ln_ln_two() -> T { +pub fn ln_ln_two() -> T { T::ln_2().ln() } @@ -73,7 +74,7 @@ pub fn ln_ln_two() -> T { /// /// * [`ln_ln_two`](fn.ln_ln_two.html) /// * [`ln_two`](fn.ln_two.html) -pub fn ln_ten() -> T { +pub fn ln_ten() -> T { T::ln_10() } @@ -83,7 +84,7 @@ pub fn ln_ten() -> T { /// /// * [`ln_ln_two`](fn.ln_ln_two.html) /// * [`ln_ten`](fn.ln_ten.html) -pub fn ln_two() -> T { +pub fn ln_two() -> T { T::ln_2() } @@ -106,12 +107,12 @@ pub use na::one; /// * [`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() -> T { +pub fn one_over_pi() -> T { T::frac_1_pi() } /// Returns `1 / sqrt(2)`. -pub fn one_over_root_two() -> T { +pub fn one_over_root_two() -> T { T::one() / root_two() } @@ -131,7 +132,7 @@ pub fn one_over_root_two() -> T { /// * [`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() -> T { +pub fn one_over_two_pi() -> T { T::frac_1_pi() * na::convert(0.5) } @@ -151,7 +152,7 @@ pub fn one_over_two_pi() -> T { /// * [`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() -> T { +pub fn quarter_pi() -> T { T::frac_pi_4() } @@ -161,7 +162,7 @@ pub fn quarter_pi() -> T { /// /// * [`root_three`](fn.root_three.html) /// * [`root_two`](fn.root_two.html) -pub fn root_five() -> T { +pub fn root_five() -> T { na::convert::<_, T>(5.0).sqrt() } @@ -181,12 +182,12 @@ pub fn root_five() -> T { /// * [`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() -> T { +pub fn root_half_pi() -> T { (T::pi() / na::convert(2.0)).sqrt() } /// Returns `sqrt(ln(4))`. -pub fn root_ln_four() -> T { +pub fn root_ln_four() -> T { na::convert::<_, T>(4.0).ln().sqrt() } @@ -206,7 +207,7 @@ pub fn root_ln_four() -> T { /// * [`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() -> T { +pub fn root_pi() -> T { T::pi().sqrt() } @@ -216,7 +217,7 @@ pub fn root_pi() -> T { /// /// * [`root_five`](fn.root_five.html) /// * [`root_two`](fn.root_two.html) -pub fn root_three() -> T { +pub fn root_three() -> T { na::convert::<_, T>(3.0).sqrt() } @@ -226,8 +227,8 @@ pub fn root_three() -> T { /// /// * [`root_five`](fn.root_five.html) /// * [`root_three`](fn.root_three.html) -pub fn root_two() -> T { - // TODO: there should be a crate::sqrt_2() on the RealField trait. +pub fn root_two() -> T { + // TODO: there should be a crate::sqrt_2() on the RealNumber trait. na::convert::<_, T>(2.0).sqrt() } @@ -247,7 +248,7 @@ pub fn root_two() -> T { /// * [`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() -> T { +pub fn root_two_pi() -> T { T::two_pi().sqrt() } @@ -256,7 +257,7 @@ pub fn root_two_pi() -> T { /// # See also: /// /// * [`two_thirds`](fn.two_thirds.html) -pub fn third() -> T { +pub fn third() -> T { na::convert(1.0 / 3.0) } @@ -276,7 +277,7 @@ pub fn third() -> T { /// * [`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() -> T { +pub fn three_over_two_pi() -> T { na::convert::<_, T>(3.0) / T::two_pi() } @@ -295,7 +296,7 @@ pub fn three_over_two_pi() -> T { /// * [`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() -> T { +pub fn two_over_pi() -> T { T::frac_2_pi() } @@ -315,7 +316,7 @@ pub fn two_over_pi() -> T { /// * [`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() -> T { +pub fn two_over_root_pi() -> T { T::frac_2_sqrt_pi() } @@ -335,7 +336,7 @@ pub fn two_over_root_pi() -> T { /// * [`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() -> T { +pub fn two_pi() -> T { T::two_pi() } @@ -344,7 +345,7 @@ pub fn two_pi() -> T { /// # See also: /// /// * [`third`](fn.third.html) -pub fn two_thirds() -> T { +pub fn two_thirds() -> T { na::convert(2.0 / 3.0) } diff --git a/nalgebra-glm/src/gtc/matrix_inverse.rs b/nalgebra-glm/src/gtc/matrix_inverse.rs index c0df4486..571b44a7 100644 --- a/nalgebra-glm/src/gtc/matrix_inverse.rs +++ b/nalgebra-glm/src/gtc/matrix_inverse.rs @@ -1,15 +1,15 @@ -use na::RealField; +use crate::RealNumber; use crate::aliases::TMat; /// Fast matrix inverse for affine matrix. -pub fn affine_inverse(m: TMat) -> TMat { +pub fn affine_inverse(m: TMat) -> TMat { // TODO: this should be optimized. m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros) } /// Compute the transpose of the inverse of a matrix. -pub fn inverse_transpose(m: TMat) -> TMat { +pub fn inverse_transpose(m: TMat) -> TMat { m.try_inverse() .unwrap_or_else(TMat::<_, D, D>::zeros) .transpose() diff --git a/nalgebra-glm/src/gtc/packing.rs b/nalgebra-glm/src/gtc/packing.rs index 9635bdf9..4ef4f396 100644 --- a/nalgebra-glm/src/gtc/packing.rs +++ b/nalgebra-glm/src/gtc/packing.rs @@ -1,4 +1,4 @@ -use na::{DefaultAllocator, RealField, Scalar, U3, U4}; +use na::{DefaultAllocator, RealNumber, Scalar, U3, U4}; use crate::aliases::*; @@ -53,7 +53,7 @@ pub fn packRGBM(rgb: &TVec3) -> TVec4 { unimplemented!() } -pub fn packSnorm(v: TVec) -> TVec +pub fn packSnorm(v: TVec) -> TVec where DefaultAllocator: Alloc + Alloc, { @@ -104,7 +104,7 @@ pub fn packUint4x8(v: &U8Vec4) -> i32 { unimplemented!() } -pub fn packUnorm(v: &TVec) -> TVec +pub fn packUnorm(v: &TVec) -> TVec where DefaultAllocator: Alloc + Alloc, { @@ -199,7 +199,7 @@ pub fn unpackRGBM(rgbm: &TVec4) -> TVec3 { unimplemented!() } -pub fn unpackSnorm(v: &TVec) -> TVec +pub fn unpackSnorm(v: &TVec) -> TVec where DefaultAllocator: Alloc + Alloc, { @@ -250,7 +250,7 @@ pub fn unpackUint4x8(p: i32) -> U8Vec4 { unimplemented!() } -pub fn unpackUnorm(v: &TVec) -> TVec +pub fn unpackUnorm(v: &TVec) -> TVec where DefaultAllocator: Alloc + Alloc, { diff --git a/nalgebra-glm/src/gtc/quaternion.rs b/nalgebra-glm/src/gtc/quaternion.rs index 6d483fe5..c145e121 100644 --- a/nalgebra-glm/src/gtc/quaternion.rs +++ b/nalgebra-glm/src/gtc/quaternion.rs @@ -1,36 +1,37 @@ -use na::{RealField, UnitQuaternion}; +use na::UnitQuaternion; use crate::aliases::{Qua, TMat4, TVec, TVec3}; +use crate::RealNumber; /// Euler angles of the quaternion `q` as (pitch, yaw, roll). -pub fn quat_euler_angles(x: &Qua) -> TVec3 { +pub fn quat_euler_angles(x: &Qua) -> TVec3 { let q = UnitQuaternion::new_unchecked(*x); let a = q.euler_angles(); TVec3::new(a.2, a.1, a.0) } /// Component-wise `>` comparison between two quaternions. -pub fn quat_greater_than(x: &Qua, y: &Qua) -> TVec { +pub fn quat_greater_than(x: &Qua, y: &Qua) -> TVec { crate::greater_than(&x.coords, &y.coords) } /// Component-wise `>=` comparison between two quaternions. -pub fn quat_greater_than_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_greater_than_equal(x: &Qua, y: &Qua) -> TVec { crate::greater_than_equal(&x.coords, &y.coords) } /// Component-wise `<` comparison between two quaternions. -pub fn quat_less_than(x: &Qua, y: &Qua) -> TVec { +pub fn quat_less_than(x: &Qua, y: &Qua) -> TVec { crate::less_than(&x.coords, &y.coords) } /// Component-wise `<=` comparison between two quaternions. -pub fn quat_less_than_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_less_than_equal(x: &Qua, y: &Qua) -> TVec { crate::less_than_equal(&x.coords, &y.coords) } /// Convert a quaternion to a rotation matrix in homogeneous coordinates. -pub fn quat_cast(x: &Qua) -> TMat4 { +pub fn quat_cast(x: &Qua) -> TMat4 { crate::quat_to_mat4(x) } @@ -41,34 +42,34 @@ pub fn quat_cast(x: &Qua) -> TMat4 { /// * `direction` - Direction vector point at where to look /// * `up` - Object up vector /// -pub fn quat_look_at(direction: &TVec3, up: &TVec3) -> Qua { +pub fn quat_look_at(direction: &TVec3, up: &TVec3) -> Qua { quat_look_at_rh(direction, up) } /// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix). -pub fn quat_look_at_lh(direction: &TVec3, up: &TVec3) -> Qua { +pub fn quat_look_at_lh(direction: &TVec3, up: &TVec3) -> Qua { UnitQuaternion::look_at_lh(direction, up).into_inner() } /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). -pub fn quat_look_at_rh(direction: &TVec3, up: &TVec3) -> Qua { +pub fn quat_look_at_rh(direction: &TVec3, up: &TVec3) -> Qua { UnitQuaternion::look_at_rh(direction, up).into_inner() } /// The "roll" Euler angle of the quaternion `x` assumed to be normalized. -pub fn quat_roll(x: &Qua) -> T { +pub fn quat_roll(x: &Qua) -> T { // TODO: optimize this. quat_euler_angles(x).z } /// The "yaw" Euler angle of the quaternion `x` assumed to be normalized. -pub fn quat_yaw(x: &Qua) -> T { +pub fn quat_yaw(x: &Qua) -> T { // TODO: optimize this. quat_euler_angles(x).y } /// The "pitch" Euler angle of the quaternion `x` assumed to be normalized. -pub fn quat_pitch(x: &Qua) -> T { +pub fn quat_pitch(x: &Qua) -> T { // TODO: optimize this. quat_euler_angles(x).x } diff --git a/nalgebra-glm/src/gtc/round.rs b/nalgebra-glm/src/gtc/round.rs index 5cf75936..832a1a61 100644 --- a/nalgebra-glm/src/gtc/round.rs +++ b/nalgebra-glm/src/gtc/round.rs @@ -1,4 +1,4 @@ -use na::{DefaultAllocator, RealField, Scalar, U3}; +use na::{DefaultAllocator, RealNumber, Scalar, U3}; use crate::aliases::TVec; use crate::traits::{Alloc, Dimension, Number}; diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 3a0a8f43..cc8bb2a1 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -1,10 +1,10 @@ -use na::{Quaternion, RealField, Scalar}; +use na::{Quaternion, Scalar}; use crate::aliases::{ Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1, TVec2, TVec3, TVec4, }; -use crate::traits::Number; +use crate::traits::{Number, RealNumber}; /// Creates a 2x2 matrix from a slice arranged in column-major order. pub fn make_mat2(ptr: &[T]) -> TMat2 { @@ -120,7 +120,7 @@ pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { } /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. -pub fn make_quat(ptr: &[T]) -> Qua { +pub fn make_quat(ptr: &[T]) -> Qua { Quaternion::from(TVec4::from_column_slice(ptr)) } diff --git a/nalgebra-glm/src/gtx/euler_angles.rs b/nalgebra-glm/src/gtx/euler_angles.rs index 4dc9f9d1..cf04b19d 100644 --- a/nalgebra-glm/src/gtx/euler_angles.rs +++ b/nalgebra-glm/src/gtx/euler_angles.rs @@ -1,163 +1,163 @@ -use na::{RealField, U3, U4}; +use na::{RealNumber, U3, U4}; use crate::aliases::{TMat, TVec}; -pub fn derivedEulerAngleX(angleX: T, angularVelocityX: T) -> TMat4 { +pub fn derivedEulerAngleX(angleX: T, angularVelocityX: T) -> TMat4 { unimplemented!() } -pub fn derivedEulerAngleY(angleY: T, angularVelocityY: T) -> TMat4 { +pub fn derivedEulerAngleY(angleY: T, angularVelocityY: T) -> TMat4 { unimplemented!() } -pub fn derivedEulerAngleZ(angleZ: T, angularVelocityZ: T) -> TMat4 { +pub fn derivedEulerAngleZ(angleZ: T, angularVelocityZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleX(angleX: T) -> TMat4 { +pub fn eulerAngleX(angleX: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXY(angleX: T, angleY: T) -> TMat4 { +pub fn eulerAngleXY(angleX: T, angleY: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXYX(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleXYX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXYZ(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleXYZ(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZ(angleX: T, angleZ: T) -> TMat4 { +pub fn eulerAngleXZ(angleX: T, angleZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZX(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleXZX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZY(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleXZY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleY(angleY: T) -> TMat4 { +pub fn eulerAngleY(angleY: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYX(angleY: T, angleX: T) -> TMat4 { +pub fn eulerAngleYX(angleY: T, angleX: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYXY(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleYXY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYXZ(yaw: T, pitch: T, roll: T) -> TMat4 { +pub fn eulerAngleYXZ(yaw: T, pitch: T, roll: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZ(angleY: T, angleZ: T) -> TMat4 { +pub fn eulerAngleYZ(angleY: T, angleZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZX(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleYZX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZY(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleYZY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZ(angleZ: T) -> TMat4 { +pub fn eulerAngleZ(angleZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZX(angle: T, angleX: T) -> TMat4 { +pub fn eulerAngleZX(angle: T, angleX: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZXY(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleZXY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZXZ(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleZXZ(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZY(angleZ: T, angleY: T) -> TMat4 { +pub fn eulerAngleZY(angleZ: T, angleY: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZYX(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleZYX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZYZ(t1: T, t2: T, t3: T) -> TMat4 { +pub fn eulerAngleZYZ(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn extractEulerAngleXYX(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleXYX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleXYZ(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleXYZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleXZX(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleXZX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleXZY(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleXZY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYXY(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleYXY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYXZ(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleYXZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYZX(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleYZX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYZY(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleYZY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZXY(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleZXY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZXZ(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleZXZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZYX(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleZYX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZYZ(M: &TMat4) -> (T, T, T) { +pub fn extractEulerAngleZYZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn orientate2(angle: T) -> TMat3x3 { +pub fn orientate2(angle: T) -> TMat3x3 { unimplemented!() } -pub fn orientate3(angles: TVec3) -> TMat3x3 { +pub fn orientate3(angles: TVec3) -> TMat3x3 { unimplemented!() } -pub fn orientate4(angles: TVec3) -> TMat4 { +pub fn orientate4(angles: TVec3) -> TMat4 { unimplemented!() } -pub fn yawPitchRoll(yaw: T, pitch: T, roll: T) -> TMat4 { +pub fn yawPitchRoll(yaw: T, pitch: T, roll: T) -> TMat4 { unimplemented!() } diff --git a/nalgebra-glm/src/gtx/matrix_cross_product.rs b/nalgebra-glm/src/gtx/matrix_cross_product.rs index 83ac881e..383bbdc0 100644 --- a/nalgebra-glm/src/gtx/matrix_cross_product.rs +++ b/nalgebra-glm/src/gtx/matrix_cross_product.rs @@ -1,13 +1,12 @@ -use na::RealField; - use crate::aliases::{TMat3, TMat4, TVec3}; +use crate::RealNumber; /// Builds a 3x3 matrix `m` such that for any `v`: `m * v == cross(x, v)`. /// /// # See also: /// /// * [`matrix_cross`](fn.matrix_cross.html) -pub fn matrix_cross3(x: &TVec3) -> TMat3 { +pub fn matrix_cross3(x: &TVec3) -> TMat3 { x.cross_matrix() } @@ -16,6 +15,6 @@ pub fn matrix_cross3(x: &TVec3) -> TMat3 { /// # See also: /// /// * [`matrix_cross3`](fn.matrix_cross3.html) -pub fn matrix_cross(x: &TVec3) -> TMat4 { +pub fn matrix_cross(x: &TVec3) -> TMat4 { crate::mat3_to_mat4(&x.cross_matrix()) } diff --git a/nalgebra-glm/src/gtx/norm.rs b/nalgebra-glm/src/gtx/norm.rs index 8da6ab13..cf7f541a 100644 --- a/nalgebra-glm/src/gtx/norm.rs +++ b/nalgebra-glm/src/gtx/norm.rs @@ -1,13 +1,12 @@ -use na::RealField; - use crate::aliases::TVec; +use crate::RealNumber; /// The squared distance between two points. /// /// # See also: /// /// * [`distance`](fn.distance.html) -pub fn distance2(p0: &TVec, p1: &TVec) -> T { +pub fn distance2(p0: &TVec, p1: &TVec) -> T { (p1 - p0).norm_squared() } @@ -18,7 +17,7 @@ pub fn distance2(p0: &TVec, p1: &TVec) /// * [`l1_norm`](fn.l1_norm.html) /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) -pub fn l1_distance(x: &TVec, y: &TVec) -> T { +pub fn l1_distance(x: &TVec, y: &TVec) -> T { l1_norm(&(y - x)) } @@ -32,7 +31,7 @@ pub fn l1_distance(x: &TVec, y: &TVec) /// * [`l1_distance`](fn.l1_distance.html) /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) -pub fn l1_norm(v: &TVec) -> T { +pub fn l1_norm(v: &TVec) -> T { crate::comp_add(&v.abs()) } @@ -50,7 +49,7 @@ pub fn l1_norm(v: &TVec) -> T { /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn l2_distance(x: &TVec, y: &TVec) -> T { +pub fn l2_distance(x: &TVec, y: &TVec) -> T { l2_norm(&(y - x)) } @@ -70,7 +69,7 @@ pub fn l2_distance(x: &TVec, y: &TVec) /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn l2_norm(x: &TVec) -> T { +pub fn l2_norm(x: &TVec) -> T { x.norm() } @@ -85,7 +84,7 @@ pub fn l2_norm(x: &TVec) -> T { /// * [`length`](fn.length.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn length2(x: &TVec) -> T { +pub fn length2(x: &TVec) -> T { x.norm_squared() } @@ -100,14 +99,14 @@ pub fn length2(x: &TVec) -> T { /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`nalgebra::norm_squared`](../nalgebra/fn.norm_squared.html) -pub fn magnitude2(x: &TVec) -> T { +pub fn magnitude2(x: &TVec) -> T { x.norm_squared() } -//pub fn lxNorm(x: &TVec, y: &TVec, unsigned int Depth) -> T { +//pub fn lxNorm(x: &TVec, y: &TVec, unsigned int Depth) -> T { // unimplemented!() //} // -//pub fn lxNorm(x: &TVec, unsigned int Depth) -> T { +//pub fn lxNorm(x: &TVec, unsigned int Depth) -> T { // unimplemented!() //} diff --git a/nalgebra-glm/src/gtx/normal.rs b/nalgebra-glm/src/gtx/normal.rs index 0686b787..35ea7faf 100644 --- a/nalgebra-glm/src/gtx/normal.rs +++ b/nalgebra-glm/src/gtx/normal.rs @@ -1,10 +1,10 @@ -use na::RealField; +use crate::RealNumber; use crate::aliases::TVec3; /// The normal vector of the given triangle. /// /// The normal is computed as the normalized vector `cross(p2 - p1, p3 - p1)`. -pub fn triangle_normal(p1: &TVec3, p2: &TVec3, p3: &TVec3) -> TVec3 { +pub fn triangle_normal(p1: &TVec3, p2: &TVec3, p3: &TVec3) -> TVec3 { (p2 - p1).cross(&(p3 - p1)).normalize() } diff --git a/nalgebra-glm/src/gtx/normalize_dot.rs b/nalgebra-glm/src/gtx/normalize_dot.rs index 7305ee2b..41146d7e 100644 --- a/nalgebra-glm/src/gtx/normalize_dot.rs +++ b/nalgebra-glm/src/gtx/normalize_dot.rs @@ -1,4 +1,4 @@ -use na::RealField; +use crate::RealNumber; use crate::aliases::TVec; @@ -9,7 +9,7 @@ use crate::aliases::TVec; /// # See also: /// /// * [`normalize_dot`](fn.normalize_dot.html`) -pub fn fast_normalize_dot(x: &TVec, y: &TVec) -> T { +pub fn fast_normalize_dot(x: &TVec, y: &TVec) -> T { // XXX: improve those. x.normalize().dot(&y.normalize()) } @@ -19,7 +19,7 @@ pub fn fast_normalize_dot(x: &TVec, y: &TVec /// # See also: /// /// * [`fast_normalize_dot`](fn.fast_normalize_dot.html`) -pub fn normalize_dot(x: &TVec, y: &TVec) -> T { +pub fn normalize_dot(x: &TVec, y: &TVec) -> T { // XXX: improve those. x.normalize().dot(&y.normalize()) } diff --git a/nalgebra-glm/src/gtx/quaternion.rs b/nalgebra-glm/src/gtx/quaternion.rs index 3f256e64..f912c409 100644 --- a/nalgebra-glm/src/gtx/quaternion.rs +++ b/nalgebra-glm/src/gtx/quaternion.rs @@ -1,97 +1,98 @@ -use na::{RealField, Rotation3, Unit, UnitQuaternion}; +use na::{Rotation3, Unit, UnitQuaternion}; use crate::aliases::{Qua, TMat3, TMat4, TVec3, TVec4}; +use crate::RealNumber; /// Rotate the vector `v` by the quaternion `q` assumed to be normalized. -pub fn quat_cross_vec(q: &Qua, v: &TVec3) -> TVec3 { +pub fn quat_cross_vec(q: &Qua, v: &TVec3) -> TVec3 { UnitQuaternion::new_unchecked(*q) * v } /// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized. -pub fn quat_inv_cross_vec(v: &TVec3, q: &Qua) -> TVec3 { +pub fn quat_inv_cross_vec(v: &TVec3, q: &Qua) -> TVec3 { UnitQuaternion::new_unchecked(*q).inverse() * v } /// The quaternion `w` component. -pub fn quat_extract_real_component(q: &Qua) -> T { +pub fn quat_extract_real_component(q: &Qua) -> T { q.w } /// Normalized linear interpolation between two quaternions. -pub fn quat_fast_mix(x: &Qua, y: &Qua, a: T) -> Qua { +pub fn quat_fast_mix(x: &Qua, y: &Qua, a: T) -> Qua { Unit::new_unchecked(*x) .nlerp(&Unit::new_unchecked(*y), a) .into_inner() } -//pub fn quat_intermediate(prev: &Qua, curr: &Qua, next: &Qua) -> Qua { +//pub fn quat_intermediate(prev: &Qua, curr: &Qua, next: &Qua) -> Qua { // unimplemented!() //} /// The squared magnitude of a quaternion `q`. -pub fn quat_length2(q: &Qua) -> T { +pub fn quat_length2(q: &Qua) -> T { q.norm_squared() } /// The squared magnitude of a quaternion `q`. -pub fn quat_magnitude2(q: &Qua) -> T { +pub fn quat_magnitude2(q: &Qua) -> T { q.norm_squared() } /// The quaternion representing the identity rotation. -pub fn quat_identity() -> Qua { +pub fn quat_identity() -> Qua { UnitQuaternion::identity().into_inner() } /// Rotates a vector by a quaternion assumed to be normalized. -pub fn quat_rotate_vec3(q: &Qua, v: &TVec3) -> TVec3 { +pub fn quat_rotate_vec3(q: &Qua, v: &TVec3) -> TVec3 { UnitQuaternion::new_unchecked(*q) * v } /// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized. -pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { +pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<3>(0); TVec4::new(rotated.x, rotated.y, rotated.z, v.w) } /// The rotation required to align `orig` to `dest`. -pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { +pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { UnitQuaternion::rotation_between(orig, dest) .unwrap_or_else(UnitQuaternion::identity) .into_inner() } /// The spherical linear interpolation between two quaternions. -pub fn quat_short_mix(x: &Qua, y: &Qua, a: T) -> Qua { +pub fn quat_short_mix(x: &Qua, y: &Qua, a: T) -> Qua { Unit::new_normalize(*x) .slerp(&Unit::new_normalize(*y), a) .into_inner() } -//pub fn quat_squad(q1: &Qua, q2: &Qua, s1: &Qua, s2: &Qua, h: T) -> Qua { +//pub fn quat_squad(q1: &Qua, q2: &Qua, s1: &Qua, s2: &Qua, h: T) -> Qua { // unimplemented!() //} /// Converts a quaternion to a rotation matrix. -pub fn quat_to_mat3(x: &Qua) -> TMat3 { +pub fn quat_to_mat3(x: &Qua) -> TMat3 { UnitQuaternion::new_unchecked(*x) .to_rotation_matrix() .into_inner() } /// Converts a quaternion to a rotation matrix in homogenous coordinates. -pub fn quat_to_mat4(x: &Qua) -> TMat4 { +pub fn quat_to_mat4(x: &Qua) -> TMat4 { UnitQuaternion::new_unchecked(*x).to_homogeneous() } /// Converts a rotation matrix to a quaternion. -pub fn mat3_to_quat(x: &TMat3) -> Qua { +pub fn mat3_to_quat(x: &TMat3) -> Qua { let r = Rotation3::from_matrix_unchecked(*x); UnitQuaternion::from_rotation_matrix(&r).into_inner() } /// Converts a rotation matrix in homogeneous coordinates to a quaternion. -pub fn to_quat(x: &TMat4) -> Qua { +pub fn to_quat(x: &TMat4) -> Qua { let rot = x.fixed_slice::<3, 3>(0, 0).into_owned(); mat3_to_quat(&rot) } diff --git a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs index e403864c..a5788e94 100644 --- a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs +++ b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs @@ -1,6 +1,7 @@ -use na::{RealField, Rotation3, Unit, UnitQuaternion}; +use na::{Rotation3, Unit, UnitQuaternion}; use crate::aliases::{Qua, TMat4, TVec3}; +use crate::RealNumber; /// Builds a rotation 4 * 4 matrix created from a normalized axis and an angle. /// @@ -9,7 +10,7 @@ use crate::aliases::{Qua, TMat4, TVec3}; /// * `m` - Input matrix multiplied by this rotation matrix. /// * `angle` - Rotation angle expressed in radians. /// * `axis` - Rotation axis, must be normalized. -pub fn rotate_normalized_axis(m: &TMat4, angle: T, axis: &TVec3) -> TMat4 { +pub fn rotate_normalized_axis(m: &TMat4, angle: T, axis: &TVec3) -> TMat4 { m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous() } @@ -20,6 +21,6 @@ pub fn rotate_normalized_axis(m: &TMat4, angle: T, axis: &TVec3 /// * `q` - Source orientation. /// * `angle` - Angle expressed in radians. /// * `axis` - Normalized axis of the rotation, must be normalized. -pub fn quat_rotate_normalized_axis(q: &Qua, angle: T, axis: &TVec3) -> Qua { +pub fn quat_rotate_normalized_axis(q: &Qua, angle: T, axis: &TVec3) -> Qua { q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).into_inner() } diff --git a/nalgebra-glm/src/gtx/rotate_vector.rs b/nalgebra-glm/src/gtx/rotate_vector.rs index 30101c30..213adb55 100644 --- a/nalgebra-glm/src/gtx/rotate_vector.rs +++ b/nalgebra-glm/src/gtx/rotate_vector.rs @@ -1,9 +1,10 @@ -use na::{RealField, Rotation3, Unit, UnitComplex}; +use na::{Rotation3, Unit, UnitComplex}; use crate::aliases::{TMat4, TVec2, TVec3, TVec4}; +use crate::RealNumber; /// Build the rotation matrix needed to align `normal` and `up`. -pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { +pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { if let Some(r) = Rotation3::rotation_between(normal, up) { r.to_homogeneous() } else { @@ -12,52 +13,52 @@ pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { } /// Rotate a two dimensional vector. -pub fn rotate_vec2(v: &TVec2, angle: T) -> TVec2 { +pub fn rotate_vec2(v: &TVec2, angle: T) -> TVec2 { UnitComplex::new(angle) * v } /// Rotate a three dimensional vector around an axis. -pub fn rotate_vec3(v: &TVec3, angle: T, normal: &TVec3) -> TVec3 { +pub fn rotate_vec3(v: &TVec3, angle: T, normal: &TVec3) -> TVec3 { Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v } /// Rotate a thee dimensional vector in homogeneous coordinates around an axis. -pub fn rotate_vec4(v: &TVec4, angle: T, normal: &TVec3) -> TVec4 { +pub fn rotate_vec4(v: &TVec4, angle: T, normal: &TVec3) -> TVec4 { Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `X` axis. -pub fn rotate_x_vec3(v: &TVec3, angle: T) -> TVec3 { +pub fn rotate_x_vec3(v: &TVec3, angle: T) -> TVec3 { Rotation3::from_axis_angle(&TVec3::x_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `X` axis. -pub fn rotate_x_vec4(v: &TVec4, angle: T) -> TVec4 { +pub fn rotate_x_vec4(v: &TVec4, angle: T) -> TVec4 { Rotation3::from_axis_angle(&TVec3::x_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Y` axis. -pub fn rotate_y_vec3(v: &TVec3, angle: T) -> TVec3 { +pub fn rotate_y_vec3(v: &TVec3, angle: T) -> TVec3 { Rotation3::from_axis_angle(&TVec3::y_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Y` axis. -pub fn rotate_y_vec4(v: &TVec4, angle: T) -> TVec4 { +pub fn rotate_y_vec4(v: &TVec4, angle: T) -> TVec4 { Rotation3::from_axis_angle(&TVec3::y_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Z` axis. -pub fn rotate_z_vec3(v: &TVec3, angle: T) -> TVec3 { +pub fn rotate_z_vec3(v: &TVec3, angle: T) -> TVec3 { Rotation3::from_axis_angle(&TVec3::z_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Z` axis. -pub fn rotate_z_vec4(v: &TVec4, angle: T) -> TVec4 { +pub fn rotate_z_vec4(v: &TVec4, angle: T) -> TVec4 { Rotation3::from_axis_angle(&TVec3::z_axis(), angle).to_homogeneous() * v } /// Computes a spherical linear interpolation between the vectors `x` and `y` assumed to be normalized. -pub fn slerp(x: &TVec3, y: &TVec3, a: T) -> TVec3 { +pub fn slerp(x: &TVec3, y: &TVec3, a: T) -> TVec3 { Unit::new_unchecked(*x) .slerp(&Unit::new_unchecked(*y), a) .into_inner() diff --git a/nalgebra-glm/src/gtx/transform.rs b/nalgebra-glm/src/gtx/transform.rs index b1f14952..3587eb0f 100644 --- a/nalgebra-glm/src/gtx/transform.rs +++ b/nalgebra-glm/src/gtx/transform.rs @@ -1,7 +1,7 @@ -use na::{RealField, Rotation2, Rotation3, Unit}; +use na::{Rotation2, Rotation3, Unit}; use crate::aliases::{TMat3, TMat4, TVec2, TVec3}; -use crate::traits::Number; +use crate::traits::{Number, RealNumber}; /// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians. /// @@ -12,7 +12,7 @@ use crate::traits::Number; /// * [`rotation2d`](fn.rotation2d.html) /// * [`scaling2d`](fn.scaling2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn rotation(angle: T, v: &TVec3) -> TMat4 { +pub fn rotation(angle: T, v: &TVec3) -> TMat4 { Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous() } @@ -51,7 +51,7 @@ pub fn translation(v: &TVec3) -> TMat4 { /// * [`translation`](fn.translation.html) /// * [`scaling2d`](fn.scaling2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn rotation2d(angle: T) -> TMat3 { +pub fn rotation2d(angle: T) -> TMat3 { Rotation2::new(angle).to_homogeneous() } diff --git a/nalgebra-glm/src/gtx/transform2.rs b/nalgebra-glm/src/gtx/transform2.rs index 9fcf95c7..36d6fc73 100644 --- a/nalgebra-glm/src/gtx/transform2.rs +++ b/nalgebra-glm/src/gtx/transform2.rs @@ -31,7 +31,7 @@ pub fn reflect2d(m: &TMat3, normal: &TVec2) -> TMat3 { { let mut part = res.fixed_slice_mut::<2, 2>(0, 0); - part -= (normal * T::from_f64(2.0).unwrap()) * normal.transpose(); + part -= (normal * T::from_subset(&2.0)) * normal.transpose(); } m * res @@ -43,7 +43,7 @@ pub fn reflect(m: &TMat4, normal: &TVec3) -> TMat4 { { let mut part = res.fixed_slice_mut::<3, 3>(0, 0); - part -= (normal * T::from_f64(2.0).unwrap()) * normal.transpose(); + part -= (normal * T::from_subset(&2.0)) * normal.transpose(); } m * res diff --git a/nalgebra-glm/src/gtx/transform2d.rs b/nalgebra-glm/src/gtx/transform2d.rs index c320628e..98d5205c 100644 --- a/nalgebra-glm/src/gtx/transform2d.rs +++ b/nalgebra-glm/src/gtx/transform2d.rs @@ -1,7 +1,7 @@ -use na::{RealField, UnitComplex}; +use na::UnitComplex; use crate::aliases::{TMat3, TVec2}; -use crate::traits::Number; +use crate::traits::{Number, RealNumber}; /// Builds a 2D rotation matrix from an angle and right-multiply it to `m`. /// @@ -12,7 +12,7 @@ use crate::traits::Number; /// * [`scaling2d`](fn.scaling2d.html) /// * [`translate2d`](fn.translate2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn rotate2d(m: &TMat3, angle: T) -> TMat3 { +pub fn rotate2d(m: &TMat3, angle: T) -> TMat3 { m * UnitComplex::new(angle).to_homogeneous() } diff --git a/nalgebra-glm/src/gtx/vector_angle.rs b/nalgebra-glm/src/gtx/vector_angle.rs index 5b61932f..9b41e95b 100644 --- a/nalgebra-glm/src/gtx/vector_angle.rs +++ b/nalgebra-glm/src/gtx/vector_angle.rs @@ -1,16 +1,16 @@ -use na::RealField; +use crate::RealNumber; use crate::aliases::TVec; /// The angle between two vectors. -pub fn angle(x: &TVec, y: &TVec) -> T { +pub fn angle(x: &TVec, y: &TVec) -> T { x.angle(y) } -//pub fn oriented_angle(x: &TVec2, y: &TVec2) -> T { +//pub fn oriented_angle(x: &TVec2, y: &TVec2) -> T { // unimplemented!() //} // -//pub fn oriented_angle_ref(x: &TVec3, y: &TVec3, refv: &TVec3) -> T { +//pub fn oriented_angle_ref(x: &TVec3, y: &TVec3, refv: &TVec3) -> T { // unimplemented!() //} diff --git a/nalgebra-glm/src/gtx/vector_query.rs b/nalgebra-glm/src/gtx/vector_query.rs index 1e739e24..d85d64a6 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -1,4 +1,4 @@ -use na::RealField; +use crate::RealNumber; use crate::aliases::{TVec, TVec2, TVec3}; use crate::traits::Number; @@ -40,7 +40,7 @@ pub fn is_comp_null(v: &TVec, epsilon: T) -> TV } /// Returns `true` if `v` has a magnitude of 1 (up to an epsilon). -pub fn is_normalized(v: &TVec, epsilon: T) -> bool { +pub fn is_normalized(v: &TVec, epsilon: T) -> bool { abs_diff_eq!(v.norm_squared(), T::one(), epsilon = epsilon * epsilon) } diff --git a/nalgebra-glm/src/integer.rs b/nalgebra-glm/src/integer.rs index 93aa4847..c94ae61a 100644 --- a/nalgebra-glm/src/integer.rs +++ b/nalgebra-glm/src/integer.rs @@ -1,4 +1,4 @@ -use na::{DefaultAllocator, RealField, Scalar, U3}; +use na::{DefaultAllocator, RealNumber, Scalar, U3}; use crate::aliases::TVec; use crate::traits::{Alloc, Dimension, Number}; diff --git a/nalgebra-glm/src/lib.rs b/nalgebra-glm/src/lib.rs index 9ca3856f..0a6da334 100644 --- a/nalgebra-glm/src/lib.rs +++ b/nalgebra-glm/src/lib.rs @@ -129,7 +129,7 @@ extern crate approx; extern crate nalgebra as na; pub use crate::aliases::*; -pub use crate::traits::Number; +pub use crate::traits::{Number, RealNumber}; pub use common::{ abs, ceil, clamp, clamp_scalar, clamp_vec, float_bits_to_int, float_bits_to_int_vec, float_bits_to_uint, float_bits_to_uint_vec, floor, fract, int_bits_to_float, @@ -201,7 +201,7 @@ pub use gtx::{ pub use na::{ convert, convert_ref, convert_ref_unchecked, convert_unchecked, try_convert, try_convert_ref, }; -pub use na::{DefaultAllocator, RealField, Scalar, U1, U2, U3, U4}; +pub use na::{DefaultAllocator, Scalar, U1, U2, U3, U4}; mod aliases; mod common; diff --git a/nalgebra-glm/src/matrix.rs b/nalgebra-glm/src/matrix.rs index 23485247..79a69d03 100644 --- a/nalgebra-glm/src/matrix.rs +++ b/nalgebra-glm/src/matrix.rs @@ -1,10 +1,10 @@ -use na::{Const, DimMin, RealField, Scalar}; +use na::{Const, DimMin, Scalar}; use crate::aliases::{TMat, TVec}; -use crate::traits::Number; +use crate::traits::{Number, RealNumber}; /// The determinant of the matrix `m`. -pub fn determinant(m: &TMat) -> T +pub fn determinant(m: &TMat) -> T where Const: DimMin, Output = Const>, { @@ -12,7 +12,7 @@ where } /// The inverse of the matrix `m`. -pub fn inverse(m: &TMat) -> TMat { +pub fn inverse(m: &TMat) -> TMat { m.clone() .try_inverse() .unwrap_or_else(TMat::::zeros) diff --git a/nalgebra-glm/src/traits.rs b/nalgebra-glm/src/traits.rs index 04d192c9..3d33fd1e 100644 --- a/nalgebra-glm/src/traits.rs +++ b/nalgebra-glm/src/traits.rs @@ -1,8 +1,8 @@ use approx::AbsDiffEq; -use num::{Bounded, FromPrimitive, Signed}; +use num::{Bounded, Signed}; use na::Scalar; -use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub}; +use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub, RealField, SupersetOf}; use std::cmp::PartialOrd; /// A number that can either be an integer or a float. @@ -15,8 +15,8 @@ pub trait Number: + ClosedMul + AbsDiffEq + Signed - + FromPrimitive + Bounded + + SupersetOf { } @@ -29,8 +29,13 @@ impl< + ClosedMul + AbsDiffEq + Signed - + FromPrimitive - + Bounded, + + Bounded + + SupersetOf, > Number for T { } + +/// A number that can be any float type. +pub trait RealNumber: Number + RealField {} + +impl RealNumber for T {} diff --git a/nalgebra-glm/src/trigonometric.rs b/nalgebra-glm/src/trigonometric.rs index 257218d3..90227a8d 100644 --- a/nalgebra-glm/src/trigonometric.rs +++ b/nalgebra-glm/src/trigonometric.rs @@ -1,78 +1,79 @@ -use na::{self, RealField}; +use na; use crate::aliases::TVec; +use crate::RealNumber; /// Component-wise arc-cosinus. -pub fn acos(x: &TVec) -> TVec { +pub fn acos(x: &TVec) -> TVec { x.map(|e| e.acos()) } /// Component-wise hyperbolic arc-cosinus. -pub fn acosh(x: &TVec) -> TVec { +pub fn acosh(x: &TVec) -> TVec { x.map(|e| e.acosh()) } /// Component-wise arc-sinus. -pub fn asin(x: &TVec) -> TVec { +pub fn asin(x: &TVec) -> TVec { x.map(|e| e.asin()) } /// Component-wise hyperbolic arc-sinus. -pub fn asinh(x: &TVec) -> TVec { +pub fn asinh(x: &TVec) -> TVec { x.map(|e| e.asinh()) } /// Component-wise arc-tangent of `y / x`. -pub fn atan2(y: &TVec, x: &TVec) -> TVec { +pub fn atan2(y: &TVec, x: &TVec) -> TVec { y.zip_map(x, |y, x| y.atan2(x)) } /// Component-wise arc-tangent. -pub fn atan(y_over_x: &TVec) -> TVec { +pub fn atan(y_over_x: &TVec) -> TVec { y_over_x.map(|e| e.atan()) } /// Component-wise hyperbolic arc-tangent. -pub fn atanh(x: &TVec) -> TVec { +pub fn atanh(x: &TVec) -> TVec { x.map(|e| e.atanh()) } /// Component-wise cosinus. -pub fn cos(angle: &TVec) -> TVec { +pub fn cos(angle: &TVec) -> TVec { angle.map(|e| e.cos()) } /// Component-wise hyperbolic cosinus. -pub fn cosh(angle: &TVec) -> TVec { +pub fn cosh(angle: &TVec) -> TVec { angle.map(|e| e.cosh()) } /// Component-wise conversion from radians to degrees. -pub fn degrees(radians: &TVec) -> TVec { +pub fn degrees(radians: &TVec) -> TVec { radians.map(|e| e * na::convert(180.0) / T::pi()) } /// Component-wise conversion fro degrees to radians. -pub fn radians(degrees: &TVec) -> TVec { +pub fn radians(degrees: &TVec) -> TVec { degrees.map(|e| e * T::pi() / na::convert(180.0)) } /// Component-wise sinus. -pub fn sin(angle: &TVec) -> TVec { +pub fn sin(angle: &TVec) -> TVec { angle.map(|e| e.sin()) } /// Component-wise hyperbolic sinus. -pub fn sinh(angle: &TVec) -> TVec { +pub fn sinh(angle: &TVec) -> TVec { angle.map(|e| e.sinh()) } /// Component-wise tangent. -pub fn tan(angle: &TVec) -> TVec { +pub fn tan(angle: &TVec) -> TVec { angle.map(|e| e.tan()) } /// Component-wise hyperbolic tangent. -pub fn tanh(angle: &TVec) -> TVec { +pub fn tanh(angle: &TVec) -> TVec { angle.map(|e| e.tanh()) }