Resolve some name conflicts.

This commit is contained in:
sebcrozet 2018-09-22 17:36:08 +02:00 committed by Sébastien Crozet
parent 81745b5464
commit 1b2fc74f33
16 changed files with 92 additions and 159 deletions

View File

@ -9,3 +9,6 @@
* 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_
* min(Vec, Vec) -> min_vec
* 2D cross is namepd perp
* quat_cross(vec, quat) -> quat_inv_cross

View File

@ -130,36 +130,26 @@ pub fn int_bits_to_float_vec<D: Dimension>(v: &Vec<i32, D>) -> Vec<f32, D>
// x * (exp).exp2()
//}
/// The maximum between two numbers.
pub fn max<N: Number>(x: N, y: N) -> N {
na::sup(&x, &y)
}
/// The maximum between each component of `x` and `y`.
pub fn max2<N: Number, D: Dimension>(x: &Vec<N, D>, y: N) -> Vec<N, D>
pub fn max<N: Number, D: Dimension>(x: &Vec<N, D>, y: N) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
x.map(|x| na::sup(&x, &y))
}
/// Component-wise maximum between `x` and `y`.
pub fn max3<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
pub fn max_vec<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
na::sup(x, y)
}
/// The minimum between two numbers.
pub fn min<N: Number>(x: N, y: N) -> N {
na::inf(&x, &y)
}
/// The minimum between each component of `x` and `y`.
pub fn min2<N: Number, D: Dimension>(x: &Vec<N, D>,y: N) -> Vec<N, D>
pub fn min<N: Number, D: Dimension>(x: &Vec<N, D>, y: N) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
x.map(|x| na::inf(&x, &y))
}
/// Component-wise minimum between `x` and `y`.
pub fn min3<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
pub fn min_vec<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
na::inf(x, y)
}
@ -174,7 +164,7 @@ pub fn mix<N: Number>(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_<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
pub fn modf_vec<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
x.zip_map(y, |x, y| x % y)
}
@ -216,23 +206,24 @@ pub fn smoothstep<N: Number>(edge0: N, edge1: N, x: N) -> N {
}
/// Returns 0.0 if `x < edge`, otherwise it returns 1.0.
pub fn step<N: Number>(edge: N, x: N) -> N {
pub fn step_scalar<N: Number>(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<N: Number, D: Dimension>(edge: N, x: &Vec<N, D>) -> Vec<N, D>
pub fn step<N: Number, D: Dimension>(edge: N, x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
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<N: Number, D: Dimension>(edge: &Vec<N, D>, x: &Vec<N, D>) -> Vec<N, D>
pub fn step_vec<N: Number, D: Dimension>(edge: &Vec<N, D>, x: &Vec<N, D>) -> Vec<N, D>
where DefaultAllocator: Alloc<N, D> {
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<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
/// 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<D: Dimension>(v: &Vec<u32, D>) -> Vec<f32, D>
pub fn uint_bits_to_float<D: Dimension>(v: &Vec<u32, D>) -> Vec<f32, D>
where DefaultAllocator: Alloc<f32, D> {
v.map(|v| uint_bits_to_float(v))
v.map(|v| uint_bits_to_float_scalar(v))
}

View File

@ -39,7 +39,7 @@ pub fn look_at_rh<N: Real>(eye: &Vec<N, U3>, center: &Vec<N, U3>, up: &Vec<N, U3
Mat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
}
/// Builds a rotation 4 * 4 matrix created from an axis vector and an angle.
/// Builds a rotation 4 * 4 matrix created from an axis vector and an angle and right-multiply it to `m`.
///
/// # Parameters
/// * m Input matrix multiplied by this rotation matrix.
@ -49,7 +49,7 @@ pub fn rotate<N: Real>(m: &Mat<N, U4, U4>, angle: N, axis: &Vec<N, U3>) -> Mat<N
m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous()
}
/// Builds a scale 4 * 4 matrix created from 3 scalars.
/// Builds a scale 4 * 4 matrix created from 3 scalars and right-multiply it to `m`.
///
/// # Parameters
/// * m Input matrix multiplied by this scale matrix.
@ -58,7 +58,7 @@ pub fn scale<N: Number>(m: &Mat<N, U4, U4>, v: &Vec<N, U3>) -> Mat<N, U4, U4> {
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.

View File

@ -2,22 +2,22 @@ use na;
use traits::Number;
/// Returns the maximum value among three.
pub fn max3<N: Number>(a: N, b: N, c: N) -> N {
/// Returns the maximum among three values.
pub fn max3_scalar<N: Number>(a: N, b: N, c: N) -> N {
na::sup(&na::sup(&a, &b), &c)
}
/// Returns the maximum value among four.
pub fn max4<N: Number>(a: N, b: N, c: N, d: N) -> N {
/// Returns the maximum among four values.
pub fn max4_scalar<N: Number>(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<N: Number>(a: N, b: N, c: N) -> N {
/// Returns the maximum among three values.
pub fn min3_scalar<N: Number>(a: N, b: N, c: N) -> N {
na::inf(&na::inf(&a, &b), &c)
}
/// Returns the maximum value among four.
pub fn min4<N: Number>(a: N, b: N, c: N, d: N) -> N {
/// Returns the maximum among four values.
pub fn min4_scalar<N: Number>(a: N, b: N, c: N, d: N) -> N {
na::inf(&na::inf(&a, &b), &na::inf(&c, &d))
}

View File

@ -21,12 +21,12 @@ pub fn golden_ratio<N: Real>() -> N {
(N::one() + root_five()) / na::convert(2.0)
}
/// Returns `4 / pi`.
/// Returns `pi / 2`.
pub fn half_pi<N: Real>() -> N {
N::frac_pi_2()
}
/// Returns `4 / pi`.
/// Returns `ln(ln(2))`.
pub fn ln_ln_two<N: Real>() -> N {
N::ln_2().ln()
}
@ -102,7 +102,7 @@ pub fn root_two_pi<N: Real>() -> N {
N::two_pi().sqrt()
}
/// Returns `1 / 3.
/// Returns `1 / 3`.
pub fn third<N: Real>() -> N {
na::convert(1.0 / 2.0)
}

View File

@ -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<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>,
pub fn epsilon_not_equal2<N: AbsDiffEq<Epsilon = N>>(x: N, y: N, epsilon: N) -> bool {
abs_diff_ne!(x, y, epsilon = epsilon)
}
*/

View File

@ -30,30 +30,17 @@ pub fn quat_less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
::less_than_equal(&x.coords, &y.coords)
}
/// Convert a quaternion to a rotation matrix.
pub fn quat_mat3_cast<N: Real>(x: Qua<N>) -> Mat<N, U3, U3> {
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<N: Real>(x: Qua<N>) -> Mat<N, U4, U4> {
let q = UnitQuaternion::new_unchecked(x);
q.to_homogeneous()
pub fn quat_cast<N: Real>(x: &Qua<N>) -> Mat<N, U4, U4> {
::quat_to_mat4(x)
}
/// Convert a rotation matrix to a quaternion.
pub fn quat_cast<N: Real>(x: Mat<N, U3, U3>) -> Qua<N> {
pub fn quat_to_mat3<N: Real>(x: &Mat<N, U3, U3>) -> Qua<N> {
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<N: Real>(x: Mat<N, U4, U4>) -> Qua<N> {
quat_cast(x.fixed_slice::<U3, U3>(0, 0).into_owned())
}
/// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix).
pub fn quat_look_at<N: Real>(direction: &Vec<N, U3>, up: &Vec<N, U3>) -> Qua<N> {
quat_look_at_rh(direction, up)

View File

@ -70,65 +70,49 @@ pub fn make_quat<N: Real>(ptr: &[N]) -> Qua<N> {
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<N: Scalar>(v: &Vec<N, U1>) -> Vec<N, U1> {
*v
}
/// Creates a 1D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec1_2<N: Scalar>(v: &Vec<N, U2>) -> Vec<N, U1> {
pub fn vec2_to_vec1<N: Scalar>(v: &Vec<N, U2>) -> Vec<N, U1> {
Vector1::new(v.x)
}
/// Creates a 1D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec1_3<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U1> {
pub fn vec3_to_vec1<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U1> {
Vector1::new(v.x)
}
/// Creates a 1D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec1_4<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U1> {
pub fn vec4_to_vec1<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U1> {
Vector1::new(v.x)
}
/// Creates a 2D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec2_1<N: Number>(v: &Vec<N, U1>) -> Vec<N, U2> {
pub fn vec1_to_vec2<N: Number>(v: &Vec<N, U1>) -> Vec<N, U2> {
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<N: Scalar>(v: &Vec<N, U2>) -> Vec<N, U2> {
pub fn vec2_to_vec2<N: Scalar>(v: &Vec<N, U2>) -> Vec<N, U2> {
*v
}
/// Creates a 2D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec2_3<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U2> {
pub fn vec3_to_vec2<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U2> {
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<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U2> {
pub fn vec4_to_vec2<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U2> {
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<N: Scalar>(ptr: &[N]) -> Vec<N, U2> {
Vector2::from_column_slice(ptr)
}
@ -136,34 +120,28 @@ pub fn make_vec2<N: Scalar>(ptr: &[N]) -> Vec<N, U2> {
/// Creates a 3D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec3_1<N: Number>(v: &Vec<N, U1>) -> Vec<N, U3> {
pub fn vec1_to_vec3<N: Number>(v: &Vec<N, U1>) -> Vec<N, U3> {
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<N: Number>(v: &Vec<N, U2>) -> Vec<N, U3> {
pub fn vec2_to_vec3<N: Number>(v: &Vec<N, U2>) -> Vec<N, U3> {
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<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U3> {
pub fn vec3_to_vec3<N: Scalar>(v: &Vec<N, U3>) -> Vec<N, U3> {
*v
}
/// Creates a 3D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec3_4<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U3> {
pub fn vec4_to_vec3<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U3> {
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<N: Scalar>(ptr: &[N]) -> Vec<N, U3> {
Vector3::from_column_slice(ptr)
}
@ -171,34 +149,30 @@ pub fn make_vec3<N: Scalar>(ptr: &[N]) -> Vec<N, U3> {
/// Creates a 4D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec4_1<N: Number>(v: &Vec<N, U1>) -> Vec<N, U4> {
pub fn vec1_to_vec4<N: Number>(v: &Vec<N, U1>) -> Vec<N, U4> {
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<N: Number>(v: &Vec<N, U2>) -> Vec<N, U4> {
pub fn vec2_to_vec4<N: Number>(v: &Vec<N, U2>) -> Vec<N, U4> {
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<N: Number>(v: &Vec<N, U3>) -> Vec<N, U4> {
pub fn vec3_to_vec4<N: Number>(v: &Vec<N, U3>) -> Vec<N, U4> {
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<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U4> {
pub fn vec4_to_vec4<N: Scalar>(v: &Vec<N, U4>) -> Vec<N, U4> {
*v
}
/// Creates a 4D vector from another vector.
///
/// Missing components, if any, are set to 0.
pub fn make_vec4<N: Scalar>(ptr: &[N]) -> Vec<N, U4> {
Vector4::from_column_slice(ptr)
}

View File

@ -4,6 +4,6 @@ use traits::Number;
use aliases::Vec;
/// The 2D perpendicular product between two vectors.
pub fn cross<N: Number>(v: &Vec<N, U2>, u: &Vec<N, U2>) -> N {
pub fn cross2d<N: Number>(v: &Vec<N, U2>, u: &Vec<N, U2>) -> N {
v.perp(u)
}

View File

@ -8,7 +8,7 @@ pub fn matrix_cross3<N: Real>(x: &Vec<N, U3>) -> Mat<N, U3, U3> {
}
/// Builds a 4x4 matrix `m` such that for any `v`: `m * v == cross(x, v)`.
pub fn matrix_cross4<N: Real>(x: &Vec<N, U3>) -> Mat<N, U4, U4> {
pub fn matrix_cross<N: Real>(x: &Vec<N, U3>) -> Mat<N, U4, U4> {
let m = x.cross_matrix();
// FIXME: use a dedicated constructor from Matrix3 to Matrix4.

View File

@ -8,7 +8,7 @@ pub fn quat_cross<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> {
}
/// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized.
pub fn quat_cross2<N: Real>(v: &Vec<N, U3>, q: &Qua<N>) -> Vec<N, U3> {
pub fn quat_inv_cross<N: Real>(v: &Vec<N, U3>, q: &Qua<N>) -> Vec<N, U3> {
UnitQuaternion::new_unchecked(*q).inverse() * v
}
@ -42,12 +42,12 @@ pub fn quat_quat_identity<N: Real>() -> Qua<N> {
}
/// Rotates a vector by a quaternion assumed to be normalized.
pub fn quat_rotate<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> {
pub fn quat_rotate_vec3<N: Real>(q: &Qua<N>, v: &Vec<N, U3>) -> Vec<N, U3> {
UnitQuaternion::new_unchecked(*q) * v
}
/// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized.
pub fn quat_rotate2<N: Real>(q: &Qua<N>, v: &Vec<N, U4>) -> Vec<N, U4> {
pub fn quat_rotate<N: Real>(q: &Qua<N>, v: &Vec<N, U4>) -> Vec<N, U4> {
// UnitQuaternion::new_unchecked(*q) * v
let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<U3>(0);
Vector4::new(rotated.x, rotated.y, rotated.z, v.w)
@ -78,13 +78,13 @@ pub fn quat_to_mat4<N: Real>(x: &Qua<N>) -> Mat<N, U4, U4> {
}
/// Converts a rotation matrix to a quaternion.
pub fn to_quat<N: Real>(x: &Mat<N, U3, U3>) -> Qua<N> {
pub fn mat3_to_quat<N: Real>(x: &Mat<N, U3, U3>) -> Qua<N> {
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<N: Real>(x: &Mat<N, U4, U4>) -> Qua<N> {
pub fn to_quat<N: Real>(x: &Mat<N, U4, U4>) -> Qua<N> {
let rot = x.fixed_slice::<U3, U3>(0, 0).into_owned();
to_quat(&rot)
}

View File

@ -12,47 +12,47 @@ pub fn orientation<N: Real>(normal: &Vec<N, U3>, up: &Vec<N, U3>) -> Mat<N, U4,
}
/// Rotate a two dimensional vector.
pub fn rotate2<N: Real>(v: &Vec<N, U2>, angle: N) -> Vec<N, U2> {
pub fn rotate_vec2<N: Real>(v: &Vec<N, U2>, angle: N) -> Vec<N, U2> {
UnitComplex::new(angle) * v
}
/// Rotate a three dimensional vector around an axis.
pub fn rotate<N: Real>(v: &Vec<N, U3>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U3> {
pub fn rotate_vec3<N: Real>(v: &Vec<N, U3>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U3> {
Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v
}
/// Rotate a thee dimensional vector in homogeneous coordinates around an axis.
pub fn rotate4<N: Real>(v: &Vec<N, U4>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U4> {
pub fn rotate_vec4<N: Real>(v: &Vec<N, U4>, angle: N, normal: &Vec<N, U3>) -> Vec<N, U4> {
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<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
pub fn rotate_x_vec3<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
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<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
pub fn rotate_x<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
Rotation3::from_axis_angle(&Vector3::x_axis(), angle).to_homogeneous() * v
}
/// Rotate a three dimensional vector around the `Y` axis.
pub fn rotate_y<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
pub fn rotate_y_vec3<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
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<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
pub fn rotate_y<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
Rotation3::from_axis_angle(&Vector3::y_axis(), angle).to_homogeneous() * v
}
/// Rotate a three dimensional vector around the `Z` axis.
pub fn rotate_z<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
pub fn rotate_z_vec3<N: Real>(v: &Vec<N, U3>, angle: N) -> Vec<N, U3> {
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<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
pub fn rotate_z<N: Real>(v: &Vec<N, U4>, angle: N) -> Vec<N, U4> {
Rotation3::from_axis_angle(&Vector3::z_axis(), angle).to_homogeneous() * v
}

View File

@ -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<N: Real>(angle: N, v: &Vec<N, U3>) -> Mat<N, U4, U4> {
pub fn rotation<N: Real>(angle: N, v: &Vec<N, U3>) -> Mat<N, U4, U4> {
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<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> {
/// A 4 * 4 scale matrix created from a vector of 3 components.
pub fn scaling<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> {
Matrix4::new_nonuniform_scaling(v)
}
/// Transforms a matrix with a translation 4 * 4 matrix created from 3 scalars.
pub fn translate<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> {
pub fn translation<N: Number>(v: &Vec<N, U3>) -> Mat<N, U4, U4> {
Matrix4::new_translation(v)
}

View File

@ -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<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> {
pub fn proj2d<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> {
let mut res = Matrix3::identity();
{
@ -16,7 +16,7 @@ pub fn proj2<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U
}
/// Build planar projection matrix along normal axis, and right-multiply it to `m`.
pub fn proj3<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> {
pub fn proj<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> {
let mut res = Matrix4::identity();
{
@ -28,7 +28,7 @@ pub fn proj3<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U
}
/// Builds a reflection matrix and right-multiply it to `m`.
pub fn reflect2<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> {
pub fn reflect2d<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3, U3> {
let mut res = Matrix3::identity();
{
@ -40,7 +40,7 @@ pub fn reflect2<N: Number>(m: &Mat<N, U3, U3>, normal: &Vec<N, U2>) -> Mat<N, U3
}
/// Builds a reflection matrix, and right-multiply it to `m`.
pub fn reflect3<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> {
pub fn reflect<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4, U4> {
let mut res = Matrix4::identity();
{
@ -52,7 +52,7 @@ pub fn reflect3<N: Number>(m: &Mat<N, U4, U4>, normal: &Vec<N, U3>) -> Mat<N, U4
}
/// Builds a scale-bias matrix.
pub fn scale_bias<N: Number>(scale: N, bias: N) -> Mat<N, U4, U4> {
pub fn scale_bias_matrix<N: Number>(scale: N, bias: N) -> Mat<N, U4, U4> {
let _0 = N::zero();
let _1 = N::one();
@ -65,12 +65,12 @@ pub fn scale_bias<N: Number>(scale: N, bias: N) -> Mat<N, U4, U4> {
}
/// Builds a scale-bias matrix, and right-multiply it to `m`.
pub fn scale_bias2<N: Number>(m: &Mat<N, U4, U4>, scale: N, bias: N) -> Mat<N, U4, U4> {
m * scale_bias(scale, bias)
pub fn scale_bias<N: Number>(m: &Mat<N, U4, U4>, scale: N, bias: N) -> Mat<N, U4, U4> {
m * scale_bias_matrix(scale, bias)
}
/// Transforms a matrix with a shearing on X axis.
pub fn shear_x2<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> {
pub fn shear2d_x<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> {
let _0 = N::zero();
let _1 = N::one();
@ -83,7 +83,7 @@ pub fn shear_x2<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> {
}
/// Transforms a matrix with a shearing on Y axis.
pub fn shear_x3<N: Number>(m: &Mat<N, U4, U4>, y: N, z: N) -> Mat<N, U4, U4> {
pub fn shear_x<N: Number>(m: &Mat<N, U4, U4>, y: N, z: N) -> Mat<N, U4, U4> {
let _0 = N::zero();
let _1 = N::one();
let shear = Matrix4::new(
@ -97,7 +97,7 @@ pub fn shear_x3<N: Number>(m: &Mat<N, U4, U4>, y: N, z: N) -> Mat<N, U4, U4> {
}
/// Transforms a matrix with a shearing on Y axis.
pub fn shear_y2<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> {
pub fn shear_y_mat3<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> {
let _0 = N::zero();
let _1 = N::one();
@ -110,7 +110,7 @@ pub fn shear_y2<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> {
}
/// Transforms a matrix with a shearing on Y axis.
pub fn shear_y3<N: Number>(m: &Mat<N, U4, U4>, x: N, z: N) -> Mat<N, U4, U4> {
pub fn shear_y<N: Number>(m: &Mat<N, U4, U4>, x: N, z: N) -> Mat<N, U4, U4> {
let _0 = N::zero();
let _1 = N::one();
let shear = Matrix4::new(
@ -124,7 +124,7 @@ pub fn shear_y3<N: Number>(m: &Mat<N, U4, U4>, x: N, z: N) -> Mat<N, U4, U4> {
}
/// Transforms a matrix with a shearing on Z axis.
pub fn shear_z3d<N: Number>(m: &Mat<N, U4, U4>, x: N, y: N) -> Mat<N, U4, U4> {
pub fn shear_z<N: Number>(m: &Mat<N, U4, U4>, x: N, y: N) -> Mat<N, U4, U4> {
let _0 = N::zero();
let _1 = N::one();
let shear = Matrix4::new(

View File

@ -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<N: Real>(m: &Mat<N, U3, U3>, angle: N) -> Mat<N, U3, U3> {
pub fn rotate2d<N: Real>(m: &Mat<N, U3, U3>, angle: N) -> Mat<N, U3, U3> {
m * UnitComplex::new(angle).to_homogeneous()
}
/// Builds a 2D scaling matrix and right-multiply it to `m`.
pub fn scale<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
pub fn scale2d<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
m.prepend_nonuniform_scaling(v)
}
/// Builds a 2D shearing matrix on the `X` axis and right-multiply it to `m`.
pub fn shear_x<N: Number>(m: &Mat<N, U3, U3>, y: N) -> Mat<N, U3, U3> {
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<N: Number>(m: &Mat<N, U3, U3>, x: N) -> Mat<N, U3, U3> {
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<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
pub fn translate2d<N: Number>(m: &Mat<N, U3, U3>, v: &Vec<N, U2>) -> Mat<N, U3, U3> {
m.prepend_translation(v)
}

View File

@ -9,7 +9,7 @@ pub fn are_collinear<N: Number>(v0: &Vec<N, U3>, v1: &Vec<N, U3>, epsilon: N) ->
}
/// Returns `true` if two 2D vectors are collinear (up to an epsilon).
pub fn are_collinear2<N: Number>(v0: &Vec<N, U2>, v1: &Vec<N, U2>, epsilon: N) -> bool {
pub fn are_collinear2d<N: Number>(v0: &Vec<N, U2>, v1: &Vec<N, U2>, epsilon: N) -> bool {
abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon)
}