nalgebra-glm: switch to simba instead of alga.
This commit is contained in:
parent
d48a644d5c
commit
426b289871
@ -15,7 +15,7 @@ edition = "2018"
|
||||
|
||||
[features]
|
||||
default = [ "std" ]
|
||||
std = [ "nalgebra/std", "alga/std" ]
|
||||
std = [ "nalgebra/std", "simba/std" ]
|
||||
stdweb = [ "nalgebra/stdweb" ]
|
||||
arbitrary = [ "nalgebra/arbitrary" ]
|
||||
serde-serialize = [ "nalgebra/serde-serialize" ]
|
||||
@ -24,5 +24,5 @@ abomonation-serialize = [ "nalgebra/abomonation-serialize" ]
|
||||
[dependencies]
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
approx = { version = "0.3", default-features = false }
|
||||
alga = { version = "0.9", default-features = false }
|
||||
simba = { version = "0.1", default-features = false }
|
||||
nalgebra = { path = "..", version = "0.20", default-features = false }
|
||||
|
@ -1,19 +1,13 @@
|
||||
//! (Reexported) Additional features not specified by GLSL specification
|
||||
|
||||
pub use self::matrix_clip_space::{
|
||||
ortho, ortho_lh, ortho_lh_no, ortho_lh_zo, ortho_no, ortho_rh, ortho_rh_no, ortho_rh_zo,
|
||||
ortho_zo,
|
||||
|
||||
perspective, perspective_lh, perspective_lh_no, perspective_lh_zo, perspective_no,
|
||||
perspective_rh, perspective_rh_no, perspective_rh_zo, perspective_zo,
|
||||
|
||||
infinite_perspective_rh_no, infinite_perspective_rh_zo, ortho, ortho_lh, ortho_lh_no,
|
||||
ortho_lh_zo, ortho_no, ortho_rh, ortho_rh_no, ortho_rh_zo, ortho_zo, perspective,
|
||||
perspective_fov, perspective_fov_lh, perspective_fov_lh_no, perspective_fov_lh_zo,
|
||||
perspective_fov_no, perspective_fov_rh, perspective_fov_rh_no, perspective_fov_rh_zo,
|
||||
perspective_fov_zo,
|
||||
|
||||
infinite_perspective_rh_no, infinite_perspective_rh_zo,
|
||||
|
||||
reversed_perspective_rh_zo, reversed_infinite_perspective_rh_zo,
|
||||
perspective_fov_zo, perspective_lh, perspective_lh_no, perspective_lh_zo, perspective_no,
|
||||
perspective_rh, perspective_rh_no, perspective_rh_zo, perspective_zo,
|
||||
reversed_infinite_perspective_rh_zo, reversed_perspective_rh_zo,
|
||||
};
|
||||
pub use self::matrix_projection::{
|
||||
pick_matrix, project, project_no, project_zo, unproject, unproject_no, unproject_zo,
|
||||
@ -35,7 +29,9 @@ pub use self::quaternion_relational::{
|
||||
};
|
||||
pub use self::quaternion_transform::{quat_exp, quat_log, quat_pow, quat_rotate};
|
||||
pub use self::quaternion_trigonometric::{quat_angle, quat_angle_axis, quat_axis};
|
||||
pub use self::scalar_common::{max3_scalar, max4_scalar, min3_scalar, min4_scalar};
|
||||
pub use self::scalar_common::{
|
||||
max2_scalar, max3_scalar, max4_scalar, min2_scalar, min3_scalar, min4_scalar,
|
||||
};
|
||||
pub use self::scalar_constants::{epsilon, pi};
|
||||
pub use self::vector_common::{max, max2, max3, max4, min, min2, min3, min4};
|
||||
pub use self::vector_relational::{equal_eps, equal_eps_vec, not_equal_eps, not_equal_eps_vec};
|
||||
|
@ -1,7 +1,51 @@
|
||||
use na;
|
||||
|
||||
use crate::traits::Number;
|
||||
|
||||
/// Returns the maximum among two values.
|
||||
///
|
||||
/// # Examples:
|
||||
///
|
||||
/// ```
|
||||
/// # use nalgebra_glm as glm;
|
||||
/// assert_eq!(2.0, glm::max2_scalar(1.0, 2.0));
|
||||
/// assert_eq!(1, glm::max2_scalar(0, 1));
|
||||
/// ```
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`max4_scalar`](fn.max4_scalar.html)
|
||||
/// * [`min3_scalar`](fn.min3_scalar.html)
|
||||
/// * [`min4_scalar`](fn.min4_scalar.html)
|
||||
pub fn max2_scalar<N: Number>(a: N, b: N) -> N {
|
||||
if a >= b {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the maximum among two values.
|
||||
///
|
||||
/// # Examples:
|
||||
///
|
||||
/// ```
|
||||
/// # use nalgebra_glm as glm;
|
||||
/// assert_eq!(1.0, glm::min2_scalar(1.0, 2.0));
|
||||
/// assert_eq!(0, glm::min2_scalar(0, 1));
|
||||
/// ```
|
||||
///
|
||||
/// # See also:
|
||||
///
|
||||
/// * [`max4_scalar`](fn.max4_scalar.html)
|
||||
/// * [`min3_scalar`](fn.min3_scalar.html)
|
||||
/// * [`min4_scalar`](fn.min4_scalar.html)
|
||||
pub fn min2_scalar<N: Number>(a: N, b: N) -> N {
|
||||
if a <= b {
|
||||
a
|
||||
} else {
|
||||
b
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the maximum among three values.
|
||||
///
|
||||
/// # Examples:
|
||||
@ -18,7 +62,7 @@ use crate::traits::Number;
|
||||
/// * [`min3_scalar`](fn.min3_scalar.html)
|
||||
/// * [`min4_scalar`](fn.min4_scalar.html)
|
||||
pub fn max3_scalar<N: Number>(a: N, b: N, c: N) -> N {
|
||||
na::sup(&na::sup(&a, &b), &c)
|
||||
max2_scalar(max2_scalar(a, b), c)
|
||||
}
|
||||
|
||||
/// Returns the maximum among four values.
|
||||
@ -37,7 +81,7 @@ pub fn max3_scalar<N: Number>(a: N, b: N, c: N) -> N {
|
||||
/// * [`min3_scalar`](fn.min3_scalar.html)
|
||||
/// * [`min4_scalar`](fn.min4_scalar.html)
|
||||
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))
|
||||
max2_scalar(max2_scalar(a, b), max2_scalar(c, d))
|
||||
}
|
||||
|
||||
/// Returns the minimum among three values.
|
||||
@ -56,7 +100,7 @@ pub fn max4_scalar<N: Number>(a: N, b: N, c: N, d: N) -> N {
|
||||
/// * [`max4_scalar`](fn.max4_scalar.html)
|
||||
/// * [`min4_scalar`](fn.min4_scalar.html)
|
||||
pub fn min3_scalar<N: Number>(a: N, b: N, c: N) -> N {
|
||||
na::inf(&na::inf(&a, &b), &c)
|
||||
min2_scalar(min2_scalar(a, b), c)
|
||||
}
|
||||
|
||||
/// Returns the minimum among four values.
|
||||
@ -75,5 +119,5 @@ pub fn min3_scalar<N: Number>(a: N, b: N, c: N) -> N {
|
||||
/// * [`max4_scalar`](fn.max4_scalar.html)
|
||||
/// * [`min3_scalar`](fn.min3_scalar.html)
|
||||
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))
|
||||
min2_scalar(min2_scalar(a, b), min2_scalar(c, d))
|
||||
}
|
||||
|
@ -17,8 +17,10 @@ use crate::traits::{Alloc, Dimension, Number};
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn max<N: Number, D: Dimension>(a: &TVec<N, D>, b: N) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
a.map(|a| na::sup(&a, &b))
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
a.map(|a| crate::max2_scalar(a, b))
|
||||
}
|
||||
|
||||
/// Component-wise maximum between two vectors.
|
||||
@ -35,8 +37,10 @@ where DefaultAllocator: Alloc<N, D> {
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn max2<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
na::sup(a, b)
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
a.zip_map(b, |a, b| crate::max2_scalar(a, b))
|
||||
}
|
||||
|
||||
/// Component-wise maximum between three vectors.
|
||||
@ -53,7 +57,9 @@ where DefaultAllocator: Alloc<N, D> {
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn max3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
max2(&max2(a, b), c)
|
||||
}
|
||||
|
||||
@ -96,8 +102,10 @@ where
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn min<N: Number, D: Dimension>(x: &TVec<N, D>, y: N) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| na::inf(&x, &y))
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
x.map(|x| crate::min2_scalar(x, y))
|
||||
}
|
||||
|
||||
/// Component-wise minimum between two vectors.
|
||||
@ -114,8 +122,10 @@ where DefaultAllocator: Alloc<N, D> {
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn min2<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
na::inf(x, y)
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
x.zip_map(y, |a, b| crate::min2_scalar(a, b))
|
||||
}
|
||||
|
||||
/// Component-wise minimum between three vectors.
|
||||
@ -132,7 +142,9 @@ where DefaultAllocator: Alloc<N, D> {
|
||||
/// * [`min2`](fn.min2.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn min3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
where
|
||||
DefaultAllocator: Alloc<N, D>,
|
||||
{
|
||||
min2(&min2(a, b), c)
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,9 @@ use crate::traits::{Alloc, Dimension, Number};
|
||||
/// * [`comp_min`](fn.comp_min.html)
|
||||
/// * [`comp_mul`](fn.comp_mul.html)
|
||||
pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
m.iter().fold(N::zero(), |x, y| x + *y)
|
||||
}
|
||||
|
||||
@ -49,8 +51,11 @@ where DefaultAllocator: Alloc<N, R, C> {
|
||||
/// * [`max3`](fn.max3.html)
|
||||
/// * [`max4`](fn.max4.html)
|
||||
pub fn comp_max<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::min_value(), |x, y| na::sup(&x, y))
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
m.iter()
|
||||
.fold(N::min_value(), |x, y| crate::max2_scalar(x, *y))
|
||||
}
|
||||
|
||||
/// The minimum of every component of the given matrix or vector.
|
||||
@ -76,8 +81,11 @@ where DefaultAllocator: Alloc<N, R, C> {
|
||||
/// * [`min3`](fn.min3.html)
|
||||
/// * [`min4`](fn.min4.html)
|
||||
pub fn comp_min<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::max_value(), |x, y| na::inf(&x, y))
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
m.iter()
|
||||
.fold(N::max_value(), |x, y| crate::min2_scalar(x, *y))
|
||||
}
|
||||
|
||||
/// The product of every component of the given matrix or vector.
|
||||
@ -99,7 +107,9 @@ where DefaultAllocator: Alloc<N, R, C> {
|
||||
/// * [`comp_max`](fn.comp_max.html)
|
||||
/// * [`comp_min`](fn.comp_min.html)
|
||||
pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
where
|
||||
DefaultAllocator: Alloc<N, R, C>,
|
||||
{
|
||||
m.iter().fold(N::one(), |x, y| x * *y)
|
||||
}
|
||||
|
||||
|
@ -116,10 +116,10 @@
|
||||
extern crate num_traits as num;
|
||||
#[macro_use]
|
||||
extern crate approx;
|
||||
extern crate alga;
|
||||
extern crate nalgebra as na;
|
||||
|
||||
pub use crate::aliases::*;
|
||||
pub use crate::traits::{Alloc, Dimension, Number};
|
||||
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,
|
||||
@ -133,7 +133,6 @@ pub use geometric::{
|
||||
cross, distance, dot, faceforward, length, magnitude, normalize, reflect_vec, refract_vec,
|
||||
};
|
||||
pub use matrix::{determinant, inverse, matrix_comp_mult, outer_product, transpose};
|
||||
pub use crate::traits::{Alloc, Dimension, Number};
|
||||
pub use trigonometric::{
|
||||
acos, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, degrees, radians, sin, sinh, tan, tanh,
|
||||
};
|
||||
@ -143,20 +142,20 @@ pub use vector_relational::{
|
||||
|
||||
pub use ext::{
|
||||
epsilon, equal_columns, equal_columns_eps, equal_columns_eps_vec, equal_eps, equal_eps_vec,
|
||||
identity, look_at, look_at_lh, look_at_rh, max, max2, max3, max3_scalar, max4, max4_scalar,
|
||||
min, min2, min3, min3_scalar, min4, min4_scalar, not_equal_columns, not_equal_columns_eps,
|
||||
not_equal_columns_eps_vec, not_equal_eps, not_equal_eps_vec, ortho, perspective, perspective_fov,
|
||||
perspective_fov_lh,perspective_fov_lh_no, perspective_fov_lh_zo, perspective_fov_no,
|
||||
perspective_fov_rh, perspective_fov_rh_no, perspective_fov_rh_zo, perspective_fov_zo,
|
||||
perspective_lh, perspective_lh_no, perspective_lh_zo, perspective_no, perspective_rh,
|
||||
perspective_rh_no, perspective_rh_zo, perspective_zo, ortho_lh, ortho_lh_no, ortho_lh_zo,
|
||||
ortho_no, ortho_rh, ortho_rh_no, ortho_rh_zo, ortho_zo, pi, pick_matrix, project, project_no,
|
||||
project_zo, quat_angle, quat_angle_axis, quat_axis, quat_conjugate, quat_cross, quat_dot,
|
||||
quat_equal, quat_equal_eps, quat_exp, quat_inverse, quat_length, quat_lerp, quat_log,
|
||||
identity, infinite_perspective_rh_no, infinite_perspective_rh_zo, look_at, look_at_lh,
|
||||
look_at_rh, max, max2, max2_scalar, max3, max3_scalar, max4, max4_scalar, min, min2,
|
||||
min2_scalar, min3, min3_scalar, min4, min4_scalar, not_equal_columns, not_equal_columns_eps,
|
||||
not_equal_columns_eps_vec, not_equal_eps, not_equal_eps_vec, ortho, ortho_lh, ortho_lh_no,
|
||||
ortho_lh_zo, ortho_no, ortho_rh, ortho_rh_no, ortho_rh_zo, ortho_zo, perspective,
|
||||
perspective_fov, perspective_fov_lh, perspective_fov_lh_no, perspective_fov_lh_zo,
|
||||
perspective_fov_no, perspective_fov_rh, perspective_fov_rh_no, perspective_fov_rh_zo,
|
||||
perspective_fov_zo, perspective_lh, perspective_lh_no, perspective_lh_zo, perspective_no,
|
||||
perspective_rh, perspective_rh_no, perspective_rh_zo, perspective_zo, pi, pick_matrix, project,
|
||||
project_no, project_zo, quat_angle, quat_angle_axis, quat_axis, quat_conjugate, quat_cross,
|
||||
quat_dot, quat_equal, quat_equal_eps, quat_exp, quat_inverse, quat_length, quat_lerp, quat_log,
|
||||
quat_magnitude, quat_normalize, quat_not_equal, quat_not_equal_eps, quat_pow, quat_rotate,
|
||||
quat_slerp, rotate, rotate_x, rotate_y, rotate_z, scale, translate, unproject, unproject_no,
|
||||
unproject_zo, infinite_perspective_rh_no, infinite_perspective_rh_zo,
|
||||
reversed_perspective_rh_zo, reversed_infinite_perspective_rh_zo,
|
||||
quat_slerp, reversed_infinite_perspective_rh_zo, reversed_perspective_rh_zo, rotate, rotate_x,
|
||||
rotate_y, rotate_z, scale, translate, unproject, unproject_no, unproject_zo,
|
||||
};
|
||||
pub use gtc::{
|
||||
affine_inverse, column, e, euler, four_over_pi, golden_ratio, half_pi, inverse_transpose,
|
||||
|
@ -3,7 +3,8 @@ use num::{Bounded, FromPrimitive, Signed};
|
||||
|
||||
use na::allocator::Allocator;
|
||||
use na::{DimMin, DimName, Scalar, U1};
|
||||
use simba::scalar::{Lattice, Ring};
|
||||
use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub};
|
||||
use std::cmp::PartialOrd;
|
||||
|
||||
/// A type-level number representing a vector, matrix row, or matrix column, dimension.
|
||||
pub trait Dimension: DimName + DimMin<Self, Output = Self> {}
|
||||
@ -11,15 +12,26 @@ impl<D: DimName + DimMin<D, Output = Self>> Dimension for D {}
|
||||
|
||||
/// A number that can either be an integer or a float.
|
||||
pub trait Number:
|
||||
Scalar + Copy + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded
|
||||
Scalar
|
||||
+ Copy
|
||||
+ PartialOrd
|
||||
+ ClosedAdd
|
||||
+ ClosedSub
|
||||
+ ClosedMul
|
||||
+ AbsDiffEq<Epsilon = Self>
|
||||
+ Signed
|
||||
+ FromPrimitive
|
||||
+ Bounded
|
||||
{
|
||||
}
|
||||
|
||||
impl<
|
||||
T: Scalar
|
||||
+ Copy
|
||||
+ Ring
|
||||
+ Lattice
|
||||
+ PartialOrd
|
||||
+ ClosedAdd
|
||||
+ ClosedSub
|
||||
+ ClosedMul
|
||||
+ AbsDiffEq<Epsilon = Self>
|
||||
+ Signed
|
||||
+ FromPrimitive
|
||||
|
Loading…
Reference in New Issue
Block a user