From 1b2fc74f3384394be478422f038815cdf858702f Mon Sep 17 00:00:00 2001 From: sebcrozet Date: Sat, 22 Sep 2018 17:36:08 +0200 Subject: [PATCH] Resolve some name conflicts. --- nalgebra-glm/README | 5 +- nalgebra-glm/src/common.rs | 37 +++++------- nalgebra-glm/src/ext/matrix_transform.rs | 6 +- nalgebra-glm/src/ext/scalar_common.rs | 16 +++--- nalgebra-glm/src/gtc/constants.rs | 6 +- nalgebra-glm/src/gtc/epsilon.rs | 4 ++ nalgebra-glm/src/gtc/quaternion.rs | 19 +------ nalgebra-glm/src/gtc/type_ptr.rs | 60 ++++++-------------- nalgebra-glm/src/gtx/exterior_product.rs | 2 +- nalgebra-glm/src/gtx/matrix_cross_product.rs | 2 +- nalgebra-glm/src/gtx/quaternion.rs | 10 ++-- nalgebra-glm/src/gtx/rotate_vector.rs | 18 +++--- nalgebra-glm/src/gtx/transform.rs | 8 +-- nalgebra-glm/src/gtx/transform2.rs | 24 ++++---- nalgebra-glm/src/gtx/transform2d.rs | 32 +---------- nalgebra-glm/src/gtx/vector_query.rs | 2 +- 16 files changed, 92 insertions(+), 159 deletions(-) diff --git a/nalgebra-glm/README b/nalgebra-glm/README index dbbb8896..5b5a8619 100644 --- a/nalgebra-glm/README +++ b/nalgebra-glm/README @@ -8,4 +8,7 @@ * Function overload: the methods taking an epsilon as suffixed by _eps * L1Norm and L2Norm between two vectors have been renamed: l1_distance, l2_distance * Matrix columnwise comparisons suffixed by _columns, e.g., `equal` -> `equal_columns` -* All quaternion functions are prefixed by quat_ \ No newline at end of file +* All quaternion functions are prefixed by quat_ +* min(Vec, Vec) -> min_vec +* 2D cross is namepd perp +* quat_cross(vec, quat) -> quat_inv_cross \ No newline at end of file diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index d072a4da..6e0e5e4d 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -130,36 +130,26 @@ pub fn int_bits_to_float_vec(v: &Vec) -> Vec // x * (exp).exp2() //} -/// The maximum between two numbers. -pub fn max(x: N, y: N) -> N { - na::sup(&x, &y) -} - /// The maximum between each component of `x` and `y`. -pub fn max2(x: &Vec, y: N) -> Vec +pub fn max(x: &Vec, y: N) -> Vec where DefaultAllocator: Alloc { x.map(|x| na::sup(&x, &y)) } /// Component-wise maximum between `x` and `y`. -pub fn max3(x: &Vec, y: &Vec) -> Vec +pub fn max_vec(x: &Vec, y: &Vec) -> Vec where DefaultAllocator: Alloc { na::sup(x, y) } -/// The minimum between two numbers. -pub fn min(x: N, y: N) -> N { - na::inf(&x, &y) -} - /// The minimum between each component of `x` and `y`. -pub fn min2(x: &Vec,y: N) -> Vec +pub fn min(x: &Vec, y: N) -> Vec where DefaultAllocator: Alloc { x.map(|x| na::inf(&x, &y)) } /// Component-wise minimum between `x` and `y`. -pub fn min3(x: &Vec, y: &Vec) -> Vec +pub fn min_vec(x: &Vec, y: &Vec) -> Vec where DefaultAllocator: Alloc { na::inf(x, y) } @@ -174,7 +164,7 @@ 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`. -pub fn mod_(x: &Vec, y: &Vec) -> Vec +pub fn modf_vec(x: &Vec, y: &Vec) -> Vec where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x % y) } @@ -216,23 +206,24 @@ pub fn smoothstep(edge0: N, edge1: N, x: N) -> N { } /// Returns 0.0 if `x < edge`, otherwise it returns 1.0. -pub fn step(edge: N, x: N) -> N { +pub fn step_scalar(edge: N, x: N) -> N { if edge > x { N::zero() } else { N::one() } } + /// Returns 0.0 if `x[i] < edge`, otherwise it returns 1.0. -pub fn step2(edge: N, x: &Vec) -> Vec +pub fn step(edge: N, x: &Vec) -> Vec where DefaultAllocator: Alloc { - x.map(|x| step(edge, x)) + x.map(|x| step_scalar(edge, x)) } /// Returns 0.0 if `x[i] < edge[i]`, otherwise it returns 1.0. -pub fn step3(edge: &Vec, x: &Vec) -> Vec +pub fn step_vec(edge: &Vec, x: &Vec) -> Vec where DefaultAllocator: Alloc { - edge.zip_map(x, |edge, x| step(edge, x)) + edge.zip_map(x, |edge, x| step_scalar(edge, x)) } /// Returns a value equal to the nearest integer to `x` whose absolute value is not larger than the absolute value of `x`. @@ -244,7 +235,7 @@ pub fn trunc(x: &Vec) -> Vec /// 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. -pub fn uint_bits_to_float(v: u32) -> f32 { +pub fn uint_bits_to_float_scalar(v: u32) -> f32 { unsafe { mem::transmute(v) } } @@ -252,7 +243,7 @@ pub fn uint_bits_to_float(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. -pub fn uint_bits_to_float_vec(v: &Vec) -> Vec +pub fn uint_bits_to_float(v: &Vec) -> Vec where DefaultAllocator: Alloc { - v.map(|v| uint_bits_to_float(v)) + v.map(|v| uint_bits_to_float_scalar(v)) } \ No newline at end of file diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index 9929e54d..bf1ecd11 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -39,7 +39,7 @@ pub fn look_at_rh(eye: &Vec, center: &Vec, up: &Vec(m: &Mat, angle: N, axis: &Vec) -> Mat(m: &Mat, v: &Vec) -> Mat { m.prepend_nonuniform_scaling(v) } -/// Builds a translation 4 * 4 matrix created from a vector of 3 components. +/// Builds a translation 4 * 4 matrix created from a vector of 3 components and right-multiply it to `m`. /// /// # Parameters /// * m − Input matrix multiplied by this translation matrix. diff --git a/nalgebra-glm/src/ext/scalar_common.rs b/nalgebra-glm/src/ext/scalar_common.rs index ca5e2e3d..6829326d 100644 --- a/nalgebra-glm/src/ext/scalar_common.rs +++ b/nalgebra-glm/src/ext/scalar_common.rs @@ -2,22 +2,22 @@ use na; use traits::Number; -/// Returns the maximum value among three. -pub fn max3(a: N, b: N, c: N) -> N { +/// Returns the maximum among three values. +pub fn max3_scalar(a: N, b: N, c: N) -> N { na::sup(&na::sup(&a, &b), &c) } -/// Returns the maximum value among four. -pub fn max4(a: N, b: N, c: N, d: N) -> N { +/// Returns the maximum among four values. +pub fn max4_scalar(a: N, b: N, c: N, d: N) -> N { na::sup(&na::sup(&a, &b), &na::sup(&c, &d)) } -/// Returns the maximum value among three. -pub fn min3(a: N, b: N, c: N) -> N { +/// Returns the maximum among three values. +pub fn min3_scalar(a: N, b: N, c: N) -> N { na::inf(&na::inf(&a, &b), &c) } -/// Returns the maximum value among four. -pub fn min4(a: N, b: N, c: N, d: N) -> N { +/// Returns the maximum among four values. +pub fn min4_scalar(a: N, b: N, c: N, d: N) -> N { na::inf(&na::inf(&a, &b), &na::inf(&c, &d)) } \ No newline at end of file diff --git a/nalgebra-glm/src/gtc/constants.rs b/nalgebra-glm/src/gtc/constants.rs index cfbf4ae7..39255ecd 100644 --- a/nalgebra-glm/src/gtc/constants.rs +++ b/nalgebra-glm/src/gtc/constants.rs @@ -21,12 +21,12 @@ pub fn golden_ratio() -> N { (N::one() + root_five()) / na::convert(2.0) } -/// Returns `4 / pi`. +/// Returns `pi / 2`. pub fn half_pi() -> N { N::frac_pi_2() } -/// Returns `4 / pi`. +/// Returns `ln(ln(2))`. pub fn ln_ln_two() -> N { N::ln_2().ln() } @@ -102,7 +102,7 @@ pub fn root_two_pi() -> N { N::two_pi().sqrt() } -/// Returns `1 / 3. +/// Returns `1 / 3`. pub fn third() -> N { na::convert(1.0 / 2.0) } diff --git a/nalgebra-glm/src/gtc/epsilon.rs b/nalgebra-glm/src/gtc/epsilon.rs index b66ed4c0..bc505b88 100644 --- a/nalgebra-glm/src/gtc/epsilon.rs +++ b/nalgebra-glm/src/gtc/epsilon.rs @@ -1,3 +1,6 @@ +// NOTE those are actually duplicates of vector_relational.rs + +/* use approx::AbsDiffEq; use na::DefaultAllocator; @@ -25,3 +28,4 @@ pub fn epsilon_not_equal(x: &Vec, y: &Vec, pub fn epsilon_not_equal2>(x: N, y: N, epsilon: N) -> bool { abs_diff_ne!(x, y, epsilon = epsilon) } +*/ \ No newline at end of file diff --git a/nalgebra-glm/src/gtc/quaternion.rs b/nalgebra-glm/src/gtc/quaternion.rs index a17721de..3b170a66 100644 --- a/nalgebra-glm/src/gtc/quaternion.rs +++ b/nalgebra-glm/src/gtc/quaternion.rs @@ -30,30 +30,17 @@ pub fn quat_less_than_equal(x: &Qua, y: &Qua) -> Vec { ::less_than_equal(&x.coords, &y.coords) } - -/// Convert a quaternion to a rotation matrix. -pub fn quat_mat3_cast(x: Qua) -> Mat { - let q = UnitQuaternion::new_unchecked(x); - q.to_rotation_matrix().unwrap() -} - /// Convert a quaternion to a rotation matrix in homogeneous coordinates. -pub fn quat_mat4_cast(x: Qua) -> Mat { - let q = UnitQuaternion::new_unchecked(x); - q.to_homogeneous() +pub fn quat_cast(x: &Qua) -> Mat { + ::quat_to_mat4(x) } /// Convert a rotation matrix to a quaternion. -pub fn quat_cast(x: Mat) -> Qua { +pub fn quat_to_mat3(x: &Mat) -> Qua { let rot = Rotation3::from_matrix_unchecked(x); UnitQuaternion::from_rotation_matrix(&rot).unwrap() } -/// Convert a rotation matrix in homogeneous coordinates to a quaternion. -pub fn quat_cast2(x: Mat) -> Qua { - quat_cast(x.fixed_slice::(0, 0).into_owned()) -} - /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). pub fn quat_look_at(direction: &Vec, up: &Vec) -> Qua { quat_look_at_rh(direction, up) diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 1c99440a..1d236f51 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -70,65 +70,49 @@ pub fn make_quat(ptr: &[N]) -> Qua { Quaternion::from_vector(Vector4::from_column_slice(ptr)) } -/// Creates a 1D vector from another vector. -/// -/// Missing components, if any, are set to 0. +/// Creates a 1D vector from a slice. pub fn make_vec1(v: &Vec) -> Vec { *v } /// Creates a 1D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec1_2(v: &Vec) -> Vec { +pub fn vec2_to_vec1(v: &Vec) -> Vec { Vector1::new(v.x) } /// Creates a 1D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec1_3(v: &Vec) -> Vec { +pub fn vec3_to_vec1(v: &Vec) -> Vec { Vector1::new(v.x) } /// Creates a 1D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec1_4(v: &Vec) -> Vec { +pub fn vec4_to_vec1(v: &Vec) -> Vec { Vector1::new(v.x) } /// Creates a 2D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn make_vec2_1(v: &Vec) -> Vec { +pub fn vec1_to_vec2(v: &Vec) -> Vec { Vector2::new(v.x, N::zero()) } /// Creates a 2D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec2_2(v: &Vec) -> Vec { +pub fn vec2_to_vec2(v: &Vec) -> Vec { *v } /// Creates a 2D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec2_3(v: &Vec) -> Vec { +pub fn vec3_to_vec2(v: &Vec) -> Vec { Vector2::new(v.x, v.y) } /// Creates a 2D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec2_4(v: &Vec) -> Vec { +pub fn vec4_to_vec2(v: &Vec) -> Vec { Vector2::new(v.x, v.y) } -/// Creates a 2D vector from another vector. -/// -/// Missing components, if any, are set to 0. +/// Creates a 2D vector from a slice. pub fn make_vec2(ptr: &[N]) -> Vec { Vector2::from_column_slice(ptr) } @@ -136,34 +120,28 @@ pub fn make_vec2(ptr: &[N]) -> Vec { /// Creates a 3D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn make_vec3_1(v: &Vec) -> Vec { +pub fn vec1_to_vec3(v: &Vec) -> Vec { Vector3::new(v.x, N::zero(), N::zero()) } /// Creates a 3D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn make_vec3_2(v: &Vec) -> Vec { +pub fn vec2_to_vec3(v: &Vec) -> Vec { Vector3::new(v.x, v.y, N::zero()) } /// Creates a 3D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec3_3(v: &Vec) -> Vec { +pub fn vec3_to_vec3(v: &Vec) -> Vec { *v } /// Creates a 3D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec3_4(v: &Vec) -> Vec { +pub fn vec4_to_vec3(v: &Vec) -> Vec { Vector3::new(v.x, v.y, v.z) } /// Creates a 3D vector from another vector. -/// -/// Missing components, if any, are set to 0. pub fn make_vec3(ptr: &[N]) -> Vec { Vector3::from_column_slice(ptr) } @@ -171,34 +149,30 @@ pub fn make_vec3(ptr: &[N]) -> Vec { /// Creates a 4D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn make_vec4_1(v: &Vec) -> Vec { +pub fn vec1_to_vec4(v: &Vec) -> Vec { Vector4::new(v.x, N::zero(), N::zero(), N::zero()) } /// Creates a 4D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn make_vec4_2(v: &Vec) -> Vec { +pub fn vec2_to_vec4(v: &Vec) -> Vec { Vector4::new(v.x, v.y, N::zero(), N::zero()) } /// Creates a 4D vector from another vector. /// /// Missing components, if any, are set to 0. -pub fn make_vec4_3(v: &Vec) -> Vec { +pub fn vec3_to_vec4(v: &Vec) -> Vec { Vector4::new(v.x, v.y, v.z, N::zero()) } /// Creates a 4D vector from another vector. -/// -/// Missing components, if any, are set to 0. -pub fn make_vec4_4(v: &Vec) -> Vec { +pub fn vec4_to_vec4(v: &Vec) -> Vec { *v } /// Creates a 4D vector from another vector. -/// -/// Missing components, if any, are set to 0. pub fn make_vec4(ptr: &[N]) -> Vec { Vector4::from_column_slice(ptr) } diff --git a/nalgebra-glm/src/gtx/exterior_product.rs b/nalgebra-glm/src/gtx/exterior_product.rs index 9653e80f..07986d4e 100644 --- a/nalgebra-glm/src/gtx/exterior_product.rs +++ b/nalgebra-glm/src/gtx/exterior_product.rs @@ -4,6 +4,6 @@ use traits::Number; use aliases::Vec; /// The 2D perpendicular product between two vectors. -pub fn cross(v: &Vec, u: &Vec) -> N { +pub fn cross2d(v: &Vec, u: &Vec) -> N { v.perp(u) } \ No newline at end of file diff --git a/nalgebra-glm/src/gtx/matrix_cross_product.rs b/nalgebra-glm/src/gtx/matrix_cross_product.rs index 1cbaddc8..5a41fdd0 100644 --- a/nalgebra-glm/src/gtx/matrix_cross_product.rs +++ b/nalgebra-glm/src/gtx/matrix_cross_product.rs @@ -8,7 +8,7 @@ pub fn matrix_cross3(x: &Vec) -> Mat { } /// Builds a 4x4 matrix `m` such that for any `v`: `m * v == cross(x, v)`. -pub fn matrix_cross4(x: &Vec) -> Mat { +pub fn matrix_cross(x: &Vec) -> Mat { let m = x.cross_matrix(); // FIXME: use a dedicated constructor from Matrix3 to Matrix4. diff --git a/nalgebra-glm/src/gtx/quaternion.rs b/nalgebra-glm/src/gtx/quaternion.rs index e2ab97bf..a8150f8e 100644 --- a/nalgebra-glm/src/gtx/quaternion.rs +++ b/nalgebra-glm/src/gtx/quaternion.rs @@ -8,7 +8,7 @@ pub fn quat_cross(q: &Qua, v: &Vec) -> Vec { } /// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized. -pub fn quat_cross2(v: &Vec, q: &Qua) -> Vec { +pub fn quat_inv_cross(v: &Vec, q: &Qua) -> Vec { UnitQuaternion::new_unchecked(*q).inverse() * v } @@ -42,12 +42,12 @@ pub fn quat_quat_identity() -> Qua { } /// Rotates a vector by a quaternion assumed to be normalized. -pub fn quat_rotate(q: &Qua, v: &Vec) -> Vec { +pub fn quat_rotate_vec3(q: &Qua, v: &Vec) -> Vec { UnitQuaternion::new_unchecked(*q) * v } /// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized. -pub fn quat_rotate2(q: &Qua, v: &Vec) -> Vec { +pub fn quat_rotate(q: &Qua, v: &Vec) -> Vec { // UnitQuaternion::new_unchecked(*q) * v let rotated = Unit::new_unchecked(*q) * v.fixed_rows::(0); Vector4::new(rotated.x, rotated.y, rotated.z, v.w) @@ -78,13 +78,13 @@ pub fn quat_to_mat4(x: &Qua) -> Mat { } /// Converts a rotation matrix to a quaternion. -pub fn to_quat(x: &Mat) -> Qua { +pub fn mat3_to_quat(x: &Mat) -> Qua { let r = Rotation3::from_matrix_unchecked(*x); UnitQuaternion::from_rotation_matrix(&r).unwrap() } /// Converts a rotation matrix in homogeneous coordinates to a quaternion. -pub fn to_quat2(x: &Mat) -> Qua { +pub fn to_quat(x: &Mat) -> Qua { let rot = x.fixed_slice::(0, 0).into_owned(); to_quat(&rot) } diff --git a/nalgebra-glm/src/gtx/rotate_vector.rs b/nalgebra-glm/src/gtx/rotate_vector.rs index eceef954..1b8ce0bb 100644 --- a/nalgebra-glm/src/gtx/rotate_vector.rs +++ b/nalgebra-glm/src/gtx/rotate_vector.rs @@ -12,47 +12,47 @@ pub fn orientation(normal: &Vec, up: &Vec) -> Mat(v: &Vec, angle: N) -> Vec { +pub fn rotate_vec2(v: &Vec, angle: N) -> Vec { UnitComplex::new(angle) * v } /// Rotate a three dimensional vector around an axis. -pub fn rotate(v: &Vec, angle: N, normal: &Vec) -> Vec { +pub fn rotate_vec3(v: &Vec, angle: N, normal: &Vec) -> Vec { Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v } /// Rotate a thee dimensional vector in homogeneous coordinates around an axis. -pub fn rotate4(v: &Vec, angle: N, normal: &Vec) -> Vec { +pub fn rotate_vec4(v: &Vec, angle: N, normal: &Vec) -> Vec { 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(v: &Vec, angle: N) -> Vec { +pub fn rotate_x_vec3(v: &Vec, angle: N) -> Vec { Rotation3::from_axis_angle(&Vector3::x_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `X` axis. -pub fn rotate_x4(v: &Vec, angle: N) -> Vec { +pub fn rotate_x(v: &Vec, angle: N) -> Vec { Rotation3::from_axis_angle(&Vector3::x_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Y` axis. -pub fn rotate_y(v: &Vec, angle: N) -> Vec { +pub fn rotate_y_vec3(v: &Vec, angle: N) -> Vec { Rotation3::from_axis_angle(&Vector3::y_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Y` axis. -pub fn rotate_y4(v: &Vec, angle: N) -> Vec { +pub fn rotate_y(v: &Vec, angle: N) -> Vec { Rotation3::from_axis_angle(&Vector3::y_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Z` axis. -pub fn rotate_z(v: &Vec, angle: N) -> Vec { +pub fn rotate_z_vec3(v: &Vec, angle: N) -> Vec { Rotation3::from_axis_angle(&Vector3::z_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Z` axis. -pub fn rotate_z4(v: &Vec, angle: N) -> Vec { +pub fn rotate_z(v: &Vec, angle: N) -> Vec { Rotation3::from_axis_angle(&Vector3::z_axis(), angle).to_homogeneous() * v } diff --git a/nalgebra-glm/src/gtx/transform.rs b/nalgebra-glm/src/gtx/transform.rs index 065c0079..bf63b19f 100644 --- a/nalgebra-glm/src/gtx/transform.rs +++ b/nalgebra-glm/src/gtx/transform.rs @@ -4,16 +4,16 @@ use traits::Number; use aliases::{Vec, Mat}; /// Builds a rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians. -pub fn rotate(angle: N, v: &Vec) -> Mat { +pub fn rotation(angle: N, v: &Vec) -> Mat { Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous() } -/// Transforms a matrix with a scale 4 * 4 matrix created from a vector of 3 components. -pub fn scale(v: &Vec) -> Mat { +/// A 4 * 4 scale matrix created from a vector of 3 components. +pub fn scaling(v: &Vec) -> Mat { Matrix4::new_nonuniform_scaling(v) } /// Transforms a matrix with a translation 4 * 4 matrix created from 3 scalars. -pub fn translate(v: &Vec) -> Mat { +pub fn translation(v: &Vec) -> Mat { Matrix4::new_translation(v) } diff --git a/nalgebra-glm/src/gtx/transform2.rs b/nalgebra-glm/src/gtx/transform2.rs index 09a788be..30f16cb1 100644 --- a/nalgebra-glm/src/gtx/transform2.rs +++ b/nalgebra-glm/src/gtx/transform2.rs @@ -4,7 +4,7 @@ use traits::Number; use aliases::{Mat, Vec}; /// Build planar projection matrix along normal axis and right-multiply it to `m`. -pub fn proj2(m: &Mat, normal: &Vec) -> Mat { +pub fn proj2d(m: &Mat, normal: &Vec) -> Mat { let mut res = Matrix3::identity(); { @@ -16,7 +16,7 @@ pub fn proj2(m: &Mat, normal: &Vec) -> Mat(m: &Mat, normal: &Vec) -> Mat { +pub fn proj(m: &Mat, normal: &Vec) -> Mat { let mut res = Matrix4::identity(); { @@ -28,7 +28,7 @@ pub fn proj3(m: &Mat, normal: &Vec) -> Mat(m: &Mat, normal: &Vec) -> Mat { +pub fn reflect2d(m: &Mat, normal: &Vec) -> Mat { let mut res = Matrix3::identity(); { @@ -40,7 +40,7 @@ pub fn reflect2(m: &Mat, normal: &Vec) -> Mat(m: &Mat, normal: &Vec) -> Mat { +pub fn reflect(m: &Mat, normal: &Vec) -> Mat { let mut res = Matrix4::identity(); { @@ -52,7 +52,7 @@ pub fn reflect3(m: &Mat, normal: &Vec) -> Mat(scale: N, bias: N) -> Mat { +pub fn scale_bias_matrix(scale: N, bias: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); @@ -65,12 +65,12 @@ pub fn scale_bias(scale: N, bias: N) -> Mat { } /// Builds a scale-bias matrix, and right-multiply it to `m`. -pub fn scale_bias2(m: &Mat, scale: N, bias: N) -> Mat { - m * scale_bias(scale, bias) +pub fn scale_bias(m: &Mat, scale: N, bias: N) -> Mat { + m * scale_bias_matrix(scale, bias) } /// Transforms a matrix with a shearing on X axis. -pub fn shear_x2(m: &Mat, y: N) -> Mat { +pub fn shear2d_x(m: &Mat, y: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); @@ -83,7 +83,7 @@ pub fn shear_x2(m: &Mat, y: N) -> Mat { } /// Transforms a matrix with a shearing on Y axis. -pub fn shear_x3(m: &Mat, y: N, z: N) -> Mat { +pub fn shear_x(m: &Mat, y: N, z: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix4::new( @@ -97,7 +97,7 @@ pub fn shear_x3(m: &Mat, y: N, z: N) -> Mat { } /// Transforms a matrix with a shearing on Y axis. -pub fn shear_y2(m: &Mat, x: N) -> Mat { +pub fn shear_y_mat3(m: &Mat, x: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); @@ -110,7 +110,7 @@ pub fn shear_y2(m: &Mat, x: N) -> Mat { } /// Transforms a matrix with a shearing on Y axis. -pub fn shear_y3(m: &Mat, x: N, z: N) -> Mat { +pub fn shear_y(m: &Mat, x: N, z: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix4::new( @@ -124,7 +124,7 @@ pub fn shear_y3(m: &Mat, x: N, z: N) -> Mat { } /// Transforms a matrix with a shearing on Z axis. -pub fn shear_z3d(m: &Mat, x: N, y: N) -> Mat { +pub fn shear_z(m: &Mat, x: N, y: N) -> Mat { let _0 = N::zero(); let _1 = N::one(); let shear = Matrix4::new( diff --git a/nalgebra-glm/src/gtx/transform2d.rs b/nalgebra-glm/src/gtx/transform2d.rs index 9e4de825..43406694 100644 --- a/nalgebra-glm/src/gtx/transform2d.rs +++ b/nalgebra-glm/src/gtx/transform2d.rs @@ -4,42 +4,16 @@ use traits::Number; use aliases::{Mat, Vec}; /// Builds a 2D rotation matrix from an angle and right-multiply it to `m`. -pub fn rotate(m: &Mat, angle: N) -> Mat { +pub fn rotate2d(m: &Mat, angle: N) -> Mat { m * UnitComplex::new(angle).to_homogeneous() } /// Builds a 2D scaling matrix and right-multiply it to `m`. -pub fn scale(m: &Mat, v: &Vec) -> Mat { +pub fn scale2d(m: &Mat, v: &Vec) -> Mat { m.prepend_nonuniform_scaling(v) } -/// Builds a 2D shearing matrix on the `X` axis and right-multiply it to `m`. -pub fn shear_x(m: &Mat, y: N) -> Mat { - let _0 = N::zero(); - let _1 = N::one(); - - let shear = Matrix3::new( - _1, y, _0, - _0, _1, _0, - _0, _0, _1 - ); - m * shear -} - -/// Builds a 2D shearing matrix on the `Y` axis and right-multiply it to `m`. -pub fn shear_y(m: &Mat, x: N) -> Mat { - let _0 = N::zero(); - let _1 = N::one(); - - let shear = Matrix3::new( - _1, _0, _0, - x, _1, _0, - _0, _0, _1 - ); - m * shear -} - /// Builds a translation matrix and right-multiply it to `m`. -pub fn translate(m: &Mat, v: &Vec) -> Mat { +pub fn translate2d(m: &Mat, v: &Vec) -> Mat { m.prepend_translation(v) } diff --git a/nalgebra-glm/src/gtx/vector_query.rs b/nalgebra-glm/src/gtx/vector_query.rs index 8eb8fd2c..a6d97406 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -9,7 +9,7 @@ pub fn are_collinear(v0: &Vec, v1: &Vec, epsilon: N) -> } /// Returns `true` if two 2D vectors are collinear (up to an epsilon). -pub fn are_collinear2(v0: &Vec, v1: &Vec, epsilon: N) -> bool { +pub fn are_collinear2d(v0: &Vec, v1: &Vec, epsilon: N) -> bool { abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon) }