forked from M-Labs/nalgebra
Rename the Mat and Vec aliases to TMat and TVec.
This commit is contained in:
parent
9e4087d466
commit
4140375b6e
@ -5,9 +5,9 @@ use na::{MatrixMN, VectorN, Vector1, Vector2, Vector3, Vector4,
|
||||
Quaternion};
|
||||
|
||||
/// A matrix with components of type `N`. It has `R` rows, and `C` columns.
|
||||
pub type Mat<N, R, C> = MatrixMN<N, R, C>;
|
||||
pub type TMat<N, R, C> = MatrixMN<N, R, C>;
|
||||
/// A column vector with components of type `N`. It has `D` rows (and one column).
|
||||
pub type Vec<N, R> = VectorN<N, R>;
|
||||
pub type TVec<N, R> = VectorN<N, R>;
|
||||
/// A quaternion with components of type `N`.
|
||||
pub type Qua<N> = Quaternion<N>;
|
||||
|
||||
|
@ -2,17 +2,17 @@ use std::mem;
|
||||
use num::FromPrimitive;
|
||||
use na::{self, Real, DefaultAllocator};
|
||||
|
||||
use aliases::{Vec, Mat};
|
||||
use aliases::{TVec, TMat};
|
||||
use traits::{Number, Dimension, Alloc};
|
||||
|
||||
/// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`.
|
||||
pub fn abs<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>) -> Mat<N, R, C>
|
||||
pub fn abs<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>) -> TMat<N, R, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.abs()
|
||||
}
|
||||
|
||||
/// For each matrix or vector component returns a value equal to the nearest integer that is greater than or equal to `x`.
|
||||
pub fn ceil<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn ceil<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.ceil())
|
||||
}
|
||||
@ -24,13 +24,13 @@ pub fn clamp_scalar<N: Number>(x: N, min_val: N, max_val: N) -> N {
|
||||
}
|
||||
|
||||
/// Returns `min(max(x[i], min_val), max_val)` for each component in `x` using the floating-point values `min_val and `max_val`.
|
||||
pub fn clamp<N: Number, D: Dimension>(x: &Vec<N, D>, min_val: N, max_val: N) -> Vec<N, D>
|
||||
pub fn clamp<N: Number, D: Dimension>(x: &TVec<N, D>, min_val: N, max_val: N) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| na::clamp(x, min_val, max_val))
|
||||
}
|
||||
|
||||
/// Returns `min(max(x[i], min_val[i]), max_val[i])` for each component in `x` using the components of `min_val` and `max_val` as bounds.
|
||||
pub fn clamp_vec<N: Number, D: Dimension>(x: &Vec<N, D>, min_val: &Vec<N, D>, max_val: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn clamp_vec<N: Number, D: Dimension>(x: &TVec<N, D>, min_val: &TVec<N, D>, max_val: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
na::clamp(x.clone(), min_val.clone(), max_val.clone())
|
||||
}
|
||||
@ -45,7 +45,7 @@ pub fn float_bits_to_int(v: f32) -> i32 {
|
||||
/// Returns a signed integer value representing the encoding of each component of `v`.
|
||||
///
|
||||
/// The floating point value's bit-level representation is preserved.
|
||||
pub fn float_bits_to_int_vec<D: Dimension>(v: &Vec<f32, D>) -> Vec<i32, D>
|
||||
pub fn float_bits_to_int_vec<D: Dimension>(v: &TVec<f32, D>) -> TVec<i32, D>
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(|v| float_bits_to_int(v))
|
||||
}
|
||||
@ -60,30 +60,30 @@ pub fn float_bits_to_uint(v: f32) -> u32 {
|
||||
/// Returns an unsigned integer value representing the encoding of each component of `v`.
|
||||
///
|
||||
/// The floating point value's bit-level representation is preserved.
|
||||
pub fn float_bits_to_uint_vec<D: Dimension>(v: &Vec<f32, D>) -> Vec<u32, D>
|
||||
pub fn float_bits_to_uint_vec<D: Dimension>(v: &TVec<f32, D>) -> TVec<u32, D>
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(|v| float_bits_to_uint(v))
|
||||
}
|
||||
|
||||
/// Returns componentwise a value equal to the nearest integer that is less then or equal to `x`.
|
||||
pub fn floor<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn floor<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.floor())
|
||||
}
|
||||
|
||||
//// FIXME: should be implemented for Vec/Mat?
|
||||
//// FIXME: should be implemented for TVec/TMat?
|
||||
//pub fn fma<N: Number>(a: N, b: N, c: N) -> N {
|
||||
// // FIXME: use an actual FMA
|
||||
// a * b + c
|
||||
//}
|
||||
|
||||
/// Returns the fractional part of each component of `x`.
|
||||
pub fn fract<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn fract<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.fract())
|
||||
}
|
||||
|
||||
//// FIXME: should be implemented for Vec/Mat?
|
||||
//// FIXME: should be implemented for TVec/TMat?
|
||||
///// Returns the (significant, exponent) of this float number.
|
||||
//pub fn frexp<N: Real>(x: N, exp: N) -> (N, N) {
|
||||
// // FIXME: is there a better approach?
|
||||
@ -102,18 +102,18 @@ pub fn int_bits_to_float(v: i32) -> f32 {
|
||||
/// For each components of `v`, returns a floating-point value corresponding to a signed integer encoding of a floating-point value.
|
||||
///
|
||||
/// If an inf or NaN is passed in, it will not signal, and the resulting floating point value is unspecified. Otherwise, the bit-level representation is preserved.
|
||||
pub fn int_bits_to_float_vec<D: Dimension>(v: &Vec<i32, D>) -> Vec<f32, D>
|
||||
pub fn int_bits_to_float_vec<D: Dimension>(v: &TVec<i32, D>) -> TVec<f32, D>
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(|v| int_bits_to_float(v))
|
||||
}
|
||||
|
||||
//pub fn isinf<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<bool, D>
|
||||
//pub fn isinf<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<bool, D>
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// unimplemented!()
|
||||
//
|
||||
//}
|
||||
//
|
||||
//pub fn isnan<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<bool, D>
|
||||
//pub fn isnan<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<bool, D>
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// unimplemented!()
|
||||
//
|
||||
@ -135,7 +135,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 modf_vec<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn modf_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x % y)
|
||||
}
|
||||
@ -148,19 +148,19 @@ pub fn modf<N: Number>(x: N, i: N) -> N {
|
||||
/// Component-wise rounding.
|
||||
///
|
||||
/// Values equal to `0.5` are rounded away from `0.0`.
|
||||
pub fn round<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn round<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.round())
|
||||
|
||||
}
|
||||
|
||||
//pub fn roundEven<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
//pub fn roundEven<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// unimplemented!()
|
||||
//}
|
||||
|
||||
/// Returns 1 if `x > 0`, 0 if `x == 0`, or -1 if `x < 0`.
|
||||
pub fn sign<N: Number, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn sign<N: Number, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.signum())
|
||||
}
|
||||
@ -186,19 +186,19 @@ pub fn step_scalar<N: Number>(edge: N, x: N) -> N {
|
||||
}
|
||||
|
||||
/// Returns 0.0 if `x[i] < edge`, otherwise it returns 1.0.
|
||||
pub fn step<N: Number, D: Dimension>(edge: N, x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn step<N: Number, D: Dimension>(edge: N, x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| step_scalar(edge, x))
|
||||
}
|
||||
|
||||
/// Returns 0.0 if `x[i] < edge[i]`, otherwise it returns 1.0.
|
||||
pub fn step_vec<N: Number, D: Dimension>(edge: &Vec<N, D>, x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn step_vec<N: Number, D: Dimension>(edge: &TVec<N, D>, x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
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`.
|
||||
pub fn trunc<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn trunc<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|x| x.trunc())
|
||||
}
|
||||
@ -214,7 +214,7 @@ pub fn uint_bits_to_float_scalar(v: u32) -> f32 {
|
||||
/// For each component of `v`, returns a floating-point value corresponding to a unsigned integer encoding of a floating-point value.
|
||||
///
|
||||
/// If an inf or NaN is passed in, it will not signal, and the resulting floating point value is unspecified. Otherwise, the bit-level representation is preserved.
|
||||
pub fn uint_bits_to_float<D: Dimension>(v: &Vec<u32, D>) -> Vec<f32, D>
|
||||
pub fn uint_bits_to_float<D: Dimension>(v: &TVec<u32, D>) -> TVec<f32, D>
|
||||
where DefaultAllocator: Alloc<f32, D> {
|
||||
v.map(|v| uint_bits_to_float_scalar(v))
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
use na::{Scalar, Real, U2, U3, U4};
|
||||
use aliases::{Mat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4,
|
||||
use aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4,
|
||||
TMat4, TMat4x2, TMat4x3};
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ pub fn vec4<N: Scalar>(x: N, y: N, z: N, w: N) -> TVec4<N> {
|
||||
|
||||
/// Create a new 2x2 matrix.
|
||||
pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
Mat::<N, U2, U2>::new(
|
||||
TMat::<N, U2, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
)
|
||||
@ -34,7 +34,7 @@ pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
|
||||
/// Create a new 2x2 matrix.
|
||||
pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
Mat::<N, U2, U2>::new(
|
||||
TMat::<N, U2, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
)
|
||||
@ -42,7 +42,7 @@ pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||
|
||||
/// Create a new 2x3 matrix.
|
||||
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3<N> {
|
||||
Mat::<N, U2, U3>::new(
|
||||
TMat::<N, U2, U3>::new(
|
||||
m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
)
|
||||
@ -50,7 +50,7 @@ pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat
|
||||
|
||||
/// Create a new 2x4 matrix.
|
||||
pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> TMat2x4<N> {
|
||||
Mat::<N, U2, U4>::new(
|
||||
TMat::<N, U2, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
)
|
||||
@ -58,7 +58,7 @@ pub fn mat2x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
|
||||
|
||||
/// Create a new 3x3 matrix.
|
||||
pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3<N> {
|
||||
Mat::<N, U3, U3>::new(
|
||||
TMat::<N, U3, U3>::new(
|
||||
m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
m31, m32, m33,
|
||||
@ -67,7 +67,7 @@ pub fn mat3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m
|
||||
|
||||
/// Create a new 3x2 matrix.
|
||||
pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2<N> {
|
||||
Mat::<N, U3, U2>::new(
|
||||
TMat::<N, U3, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
m31, m32,
|
||||
@ -76,7 +76,7 @@ pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat
|
||||
|
||||
/// Create a new 3x3 matrix.
|
||||
pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3<N> {
|
||||
Mat::<N, U3, U3>::new(
|
||||
TMat::<N, U3, U3>::new(
|
||||
m11, m12, m13,
|
||||
m31, m32, m33,
|
||||
m21, m22, m23,
|
||||
@ -85,7 +85,7 @@ pub fn mat3x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N,
|
||||
|
||||
/// Create a new 3x4 matrix.
|
||||
pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N) -> TMat3x4<N> {
|
||||
Mat::<N, U3, U4>::new(
|
||||
TMat::<N, U3, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
m31, m32, m33, m34,
|
||||
@ -94,7 +94,7 @@ pub fn mat3x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
|
||||
|
||||
/// Create a new 4x2 matrix.
|
||||
pub fn mat4x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> TMat4x2<N> {
|
||||
Mat::<N, U4, U2>::new(
|
||||
TMat::<N, U4, U2>::new(
|
||||
m11, m12,
|
||||
m21, m22,
|
||||
m31, m32,
|
||||
@ -104,7 +104,7 @@ pub fn mat4x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N,
|
||||
|
||||
/// Create a new 4x3 matrix.
|
||||
pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N, m41: N, m42: N, m43: N) -> TMat4x3<N> {
|
||||
Mat::<N, U4, U3>::new(
|
||||
TMat::<N, U4, U3>::new(
|
||||
m11, m12, m13,
|
||||
m21, m22, m23,
|
||||
m31, m32, m33,
|
||||
@ -114,7 +114,7 @@ pub fn mat4x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N,
|
||||
|
||||
/// Create a new 4x4 matrix.
|
||||
pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N, m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
||||
Mat::<N, U4, U4>::new(
|
||||
TMat::<N, U4, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
m31, m32, m33, m34,
|
||||
@ -124,7 +124,7 @@ pub fn mat4x4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N,
|
||||
|
||||
/// Create a new 4x4 matrix.
|
||||
pub fn mat4<N: Scalar>(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N, m41: N, m42: N, m43: N, m44: N) -> TMat4<N> {
|
||||
Mat::<N, U4, U4>::new(
|
||||
TMat::<N, U4, U4>::new(
|
||||
m11, m12, m13, m14,
|
||||
m21, m22, m23, m24,
|
||||
m31, m32, m33, m34,
|
||||
|
@ -1,46 +1,46 @@
|
||||
use na::{Real, DefaultAllocator};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
use traits::{Alloc, Dimension};
|
||||
|
||||
/// Component-wise exponential.
|
||||
pub fn exp<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn exp<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.exp())
|
||||
}
|
||||
|
||||
/// Component-wise base-2 exponential.
|
||||
pub fn exp2<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn exp2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.exp2())
|
||||
}
|
||||
|
||||
/// Compute the inverse of the square root of each component of `v`.
|
||||
pub fn inversesqrt<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| N::one() / x.sqrt())
|
||||
|
||||
}
|
||||
|
||||
/// Component-wise logarithm.
|
||||
pub fn log<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn log<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.ln())
|
||||
}
|
||||
|
||||
/// Component-wise base-2 logarithm.
|
||||
pub fn log2<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn log2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.log2())
|
||||
}
|
||||
|
||||
/// Component-wise power.
|
||||
pub fn pow<N: Real, D: Dimension>(base: &Vec<N, D>, exponent: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn pow<N: Real, D: Dimension>(base: &TVec<N, D>, exponent: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
base.zip_map(exponent, |b, e| b.powf(e))
|
||||
}
|
||||
|
||||
/// Component-wise square root.
|
||||
pub fn sqrt<N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn sqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| x.sqrt())
|
||||
}
|
||||
|
@ -1,14 +1,14 @@
|
||||
use na::DefaultAllocator;
|
||||
|
||||
use aliases::{Vec, Mat};
|
||||
use aliases::{TVec, TMat};
|
||||
use traits::{Alloc, Number, Dimension};
|
||||
|
||||
/// Perform a component-wise equal-to comparison of two matrices.
|
||||
///
|
||||
/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
|
||||
pub fn equal_columns<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>) -> Vec<bool, C>
|
||||
pub fn equal_columns<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y: &TMat<N, R, C>) -> TVec<bool, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
let mut res = Vec::<_, C>::repeat(false);
|
||||
let mut res = TVec::<_, C>::repeat(false);
|
||||
|
||||
for i in 0..C::dim() {
|
||||
res[i] = x.column(i) == y.column(i)
|
||||
@ -20,20 +20,20 @@ pub fn equal_columns<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y:
|
||||
/// Returns the component-wise comparison of `|x - y| < epsilon`.
|
||||
///
|
||||
/// True if this expression is satisfied.
|
||||
pub fn equal_columns_eps<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>, epsilon: N) -> Vec<bool, C>
|
||||
pub fn equal_columns_eps<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y: &TMat<N, R, C>, epsilon: N) -> TVec<bool, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
equal_columns_eps_vec(x, y, &Vec::<_, C>::repeat(epsilon))
|
||||
equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon))
|
||||
}
|
||||
|
||||
/// Returns the component-wise comparison on each matrix column `|x - y| < epsilon`.
|
||||
///
|
||||
/// True if this expression is satisfied.
|
||||
pub fn equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>, epsilon: &Vec<N, C>) -> Vec<bool, C>
|
||||
pub fn equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y: &TMat<N, R, C>, epsilon: &TVec<N, C>) -> TVec<bool, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
let mut res = Vec::<_, C>::repeat(false);
|
||||
let mut res = TVec::<_, C>::repeat(false);
|
||||
|
||||
for i in 0..C::dim() {
|
||||
res[i] = (x.column(i) - y.column(i)).abs() < Vec::<_, R>::repeat(epsilon[i])
|
||||
res[i] = (x.column(i) - y.column(i)).abs() < TVec::<_, R>::repeat(epsilon[i])
|
||||
}
|
||||
|
||||
res
|
||||
@ -42,9 +42,9 @@ pub fn equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R
|
||||
/// Perform a component-wise not-equal-to comparison of two matrices.
|
||||
///
|
||||
/// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices.
|
||||
pub fn not_equal_columns<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>) -> Vec<bool, C>
|
||||
pub fn not_equal_columns<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y: &TMat<N, R, C>) -> TVec<bool, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
let mut res = Vec::<_, C>::repeat(false);
|
||||
let mut res = TVec::<_, C>::repeat(false);
|
||||
|
||||
for i in 0..C::dim() {
|
||||
res[i] = x.column(i) != y.column(i)
|
||||
@ -56,20 +56,20 @@ pub fn not_equal_columns<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>
|
||||
/// Returns the component-wise comparison of `|x - y| < epsilon`.
|
||||
///
|
||||
/// True if this expression is not satisfied.
|
||||
pub fn not_equal_columns_eps<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>, epsilon: N) -> Vec<bool, C>
|
||||
pub fn not_equal_columns_eps<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y: &TMat<N, R, C>, epsilon: N) -> TVec<bool, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
not_equal_columns_eps_vec(x, y, &Vec::<_, C>::repeat(epsilon))
|
||||
not_equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon))
|
||||
}
|
||||
|
||||
/// Returns the component-wise comparison of `|x - y| >= epsilon`.
|
||||
///
|
||||
/// True if this expression is not satisfied.
|
||||
pub fn not_equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>, epsilon: &Vec<N, C>) -> Vec<bool, C>
|
||||
pub fn not_equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y: &TMat<N, R, C>, epsilon: &TVec<N, C>) -> TVec<bool, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
let mut res = Vec::<_, C>::repeat(false);
|
||||
let mut res = TVec::<_, C>::repeat(false);
|
||||
|
||||
for i in 0..C::dim() {
|
||||
res[i] = (x.column(i) - y.column(i)).abs() >= Vec::<_, R>::repeat(epsilon[i])
|
||||
res[i] = (x.column(i) - y.column(i)).abs() >= TVec::<_, R>::repeat(epsilon[i])
|
||||
}
|
||||
|
||||
res
|
||||
|
@ -1,12 +1,12 @@
|
||||
use na::{DefaultAllocator, Real, Unit, Rotation3, Point3};
|
||||
|
||||
use traits::{Dimension, Number, Alloc};
|
||||
use aliases::{Mat, Vec, TVec3, TMat4};
|
||||
use aliases::{TMat, TVec, TVec3, TMat4};
|
||||
|
||||
/// The identity matrix.
|
||||
pub fn identity<N: Number, D: Dimension>() -> Mat<N, D, D>
|
||||
pub fn identity<N: Number, D: Dimension>() -> TMat<N, D, D>
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
Mat::<N, D, D>::identity()
|
||||
TMat::<N, D, D>::identity()
|
||||
}
|
||||
|
||||
/// Build a look at view matrix based on the right handedness.
|
||||
@ -26,7 +26,7 @@ pub fn look_at<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMa
|
||||
/// * `center` − Position where the camera is looking at
|
||||
/// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)`
|
||||
pub fn look_at_lh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||
Mat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
|
||||
TMat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
|
||||
}
|
||||
|
||||
/// Build a right handed look at view matrix.
|
||||
@ -36,7 +36,7 @@ pub fn look_at_lh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) ->
|
||||
/// * `center` − Position where the camera is looking at
|
||||
/// * `u` − Normalized up vector, how the camera is oriented. Typically `(0, 1, 0)`
|
||||
pub fn look_at_rh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||
Mat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up)
|
||||
TMat::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 and right-multiply it to `m`.
|
||||
@ -55,7 +55,7 @@ pub fn rotate<N: Real>(m: &TMat4<N>, angle: N, axis: &TVec3<N>) -> TMat4<N> {
|
||||
/// * m − Input matrix multiplied by this rotation matrix.
|
||||
/// * angle − Rotation angle expressed in radians.
|
||||
pub fn rotate_x<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
rotate(m, angle, &Vec::x())
|
||||
rotate(m, angle, &TVec::x())
|
||||
}
|
||||
|
||||
/// Builds a rotation 4 * 4 matrix around the Y axis and right-multiply it to `m`.
|
||||
@ -64,7 +64,7 @@ pub fn rotate_x<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
/// * m − Input matrix multiplied by this rotation matrix.
|
||||
/// * angle − Rotation angle expressed in radians.
|
||||
pub fn rotate_y<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
rotate(m, angle, &Vec::y())
|
||||
rotate(m, angle, &TVec::y())
|
||||
}
|
||||
|
||||
/// Builds a rotation 4 * 4 matrix around the Z axis and right-multiply it to `m`.
|
||||
@ -73,7 +73,7 @@ pub fn rotate_y<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
/// * m − Input matrix multiplied by this rotation matrix.
|
||||
/// * angle − Rotation angle expressed in radians.
|
||||
pub fn rotate_z<N: Real>(m: &TMat4<N>, angle: N) -> TMat4<N> {
|
||||
rotate(m, angle, &Vec::z())
|
||||
rotate(m, angle, &TVec::z())
|
||||
}
|
||||
|
||||
/// Builds a scale 4 * 4 matrix created from 3 scalars and right-multiply it to `m`.
|
||||
|
@ -12,11 +12,11 @@ pub fn quat_inverse<N: Real>(q: &Qua<N>) -> Qua<N> {
|
||||
q.try_inverse().unwrap_or(na::zero())
|
||||
}
|
||||
|
||||
//pub fn quat_isinf<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
||||
//pub fn quat_isinf<N: Real>(x: &Qua<N>) -> TVec<bool, U4> {
|
||||
// x.coords.map(|e| e.is_inf())
|
||||
//}
|
||||
|
||||
//pub fn quat_isnan<N: Real>(x: &Qua<N>) -> Vec<bool, U4> {
|
||||
//pub fn quat_isnan<N: Real>(x: &Qua<N>) -> TVec<bool, U4> {
|
||||
// x.coords.map(|e| e.is_nan())
|
||||
//}
|
||||
|
||||
|
@ -1,24 +1,24 @@
|
||||
use na::{Real, U4};
|
||||
|
||||
|
||||
use aliases::{Qua, Vec};
|
||||
use aliases::{Qua, TVec};
|
||||
|
||||
/// Component-wise equality comparison between two quaternions.
|
||||
pub fn quat_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||
pub fn quat_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
|
||||
::equal(&x.coords, &y.coords)
|
||||
}
|
||||
|
||||
/// Component-wise approximate equality comparison between two quaternions.
|
||||
pub fn quat_equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> Vec<bool, U4> {
|
||||
pub fn quat_equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> TVec<bool, U4> {
|
||||
::equal_eps(&x.coords, &y.coords, epsilon)
|
||||
}
|
||||
|
||||
/// Component-wise non-equality comparison between two quaternions.
|
||||
pub fn quat_not_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||
pub fn quat_not_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
|
||||
::not_equal(&x.coords, &y.coords)
|
||||
}
|
||||
|
||||
/// Component-wise approximate non-equality comparison between two quaternions.
|
||||
pub fn quat_not_equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> Vec<bool, U4> {
|
||||
pub fn quat_not_equal_eps<N: Real>(x: &Qua<N>, y: &Qua<N>, epsilon: N) -> TVec<bool, U4> {
|
||||
::not_equal_eps(&x.coords, &y.coords, epsilon)
|
||||
}
|
||||
|
@ -1,52 +1,52 @@
|
||||
use na::{self, DefaultAllocator};
|
||||
|
||||
use traits::{Alloc, Number, Dimension};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
/// Component-wise maximum between a vector and a scalar.
|
||||
pub fn max<N: Number, D: Dimension>(a: &Vec<N, D>, b: N) -> Vec<N, D>
|
||||
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))
|
||||
}
|
||||
|
||||
/// Component-wise maximum between two vectors.
|
||||
pub fn max2<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>) -> Vec<N, D>
|
||||
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)
|
||||
}
|
||||
|
||||
/// Component-wise maximum between three vectors.
|
||||
pub fn max3<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>) -> Vec<N, D>
|
||||
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> {
|
||||
max2(&max2(a, b), c)
|
||||
}
|
||||
|
||||
/// Component-wise maximum between four vectors.
|
||||
pub fn max4<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>, d: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn max4<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>, d: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
max2(&max2(a, b), &max2(c, d))
|
||||
}
|
||||
|
||||
/// Component-wise minimum between a vector and a scalar.
|
||||
pub fn min<N: Number, D: Dimension>(x: &Vec<N, D>, y: N) -> Vec<N, D>
|
||||
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))
|
||||
}
|
||||
|
||||
/// Component-wise minimum between two vectors.
|
||||
pub fn min2<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<N, D>
|
||||
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)
|
||||
}
|
||||
|
||||
/// Component-wise minimum between three vectors.
|
||||
pub fn min3<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>) -> Vec<N, D>
|
||||
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> {
|
||||
min2(&min2(a, b), c)
|
||||
}
|
||||
|
||||
/// Component-wise minimum between four vectors.
|
||||
pub fn min4<N: Number, D: Dimension>(a: &Vec<N, D>, b: &Vec<N, D>, c: &Vec<N, D>, d: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn min4<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N, D>, d: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
min2(&min2(a, b), &min2(c, d))
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
use na::{DefaultAllocator};
|
||||
|
||||
use traits::{Alloc, Number, Dimension};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
/// Component-wise approximate equality of two vectors, using a scalar epsilon.
|
||||
pub fn equal_eps<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, epsilon: N) -> Vec<bool, D>
|
||||
pub fn equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon))
|
||||
}
|
||||
|
||||
/// Component-wise approximate equality of two vectors, using a per-component epsilon.
|
||||
pub fn equal_eps_vec<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, epsilon: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn equal_eps_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_eq!(x, y, epsilon = eps))
|
||||
}
|
||||
|
||||
/// Component-wise approximate non-equality of two vectors, using a scalar epsilon.
|
||||
pub fn not_equal_eps<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, epsilon: N) -> Vec<bool, D>
|
||||
pub fn not_equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon))
|
||||
}
|
||||
|
||||
/// Component-wise approximate non-equality of two vectors, using a per-component epsilon.
|
||||
pub fn not_equal_eps_vec<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, epsilon: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn not_equal_eps_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_ne!(x, y, epsilon = eps))
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use na::{Real, DefaultAllocator};
|
||||
|
||||
use traits::{Number, Alloc, Dimension};
|
||||
use aliases::{Vec, TVec3};
|
||||
use aliases::{TVec, TVec3};
|
||||
|
||||
/// The cross product of two vectors.
|
||||
pub fn cross<N: Number, D: Dimension>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
|
||||
@ -9,19 +9,19 @@ pub fn cross<N: Number, D: Dimension>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
|
||||
}
|
||||
|
||||
/// The distance between two points.
|
||||
pub fn distance<N: Real, D: Dimension>(p0: &Vec<N, D>, p1: &Vec<N, D>) -> N
|
||||
pub fn distance<N: Real, D: Dimension>(p0: &TVec<N, D>, p1: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
(p1 - p0).norm()
|
||||
}
|
||||
|
||||
/// The dot product of two vectors.
|
||||
pub fn dot<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
|
||||
pub fn dot<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.dot(y)
|
||||
}
|
||||
|
||||
/// If `dot(nref, i) < 0.0`, return `n`, otherwise, return `-n`.
|
||||
pub fn faceforward<N: Number, D: Dimension>(n: &Vec<N, D>, i: &Vec<N, D>, nref: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn faceforward<N: Number, D: Dimension>(n: &TVec<N, D>, i: &TVec<N, D>, nref: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
if nref.dot(i) < N::zero() {
|
||||
n.clone()
|
||||
@ -31,39 +31,39 @@ pub fn faceforward<N: Number, D: Dimension>(n: &Vec<N, D>, i: &Vec<N, D>, nref:
|
||||
}
|
||||
|
||||
/// The magnitude of a vector.
|
||||
pub fn length<N: Real, D: Dimension>(x: &Vec<N, D>) -> N
|
||||
pub fn length<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm()
|
||||
}
|
||||
|
||||
/// The magnitude of a vector.
|
||||
pub fn magnitude<N: Real, D: Dimension>(x: &Vec<N, D>) -> N
|
||||
pub fn magnitude<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm()
|
||||
}
|
||||
|
||||
/// Normalizes a vector.
|
||||
pub fn normalize<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn normalize<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.normalize()
|
||||
}
|
||||
|
||||
/// For the incident vector `i` and surface orientation `n`, returns the reflection direction : `result = i - 2.0 * dot(n, i) * n`.
|
||||
pub fn reflect_vec<N: Number, D: Dimension>(i: &Vec<N, D>, n: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn reflect_vec<N: Number, D: Dimension>(i: &TVec<N, D>, n: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
let _2 = N::one() + N::one();
|
||||
i - n * (n.dot(i) * _2)
|
||||
}
|
||||
|
||||
/// 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<N: Real, D: Dimension>(i: &Vec<N, D>, n: &Vec<N, D>, eta: N) -> Vec<N, D>
|
||||
pub fn refract_vec<N: Real, D: Dimension>(i: &TVec<N, D>, n: &TVec<N, D>, eta: N) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
|
||||
let ni = n.dot(i);
|
||||
let k = N::one() - eta * eta * (N::one() - ni * ni);
|
||||
|
||||
if k < N::zero() {
|
||||
Vec::<_, D>::zeros()
|
||||
TVec::<_, D>::zeros()
|
||||
}
|
||||
else {
|
||||
i * eta - n * (eta * dot(n, i) + k.sqrt())
|
||||
|
@ -19,7 +19,7 @@ pub fn bitfieldFillOne<IU>(Value: IU, FirstBit: i32, BitCount: i32) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitfieldFillOne2<N: Scalar, D: Dimension>(Value: &Vec<N, D>, FirstBit: i32, BitCount: i32) -> Vec<N, D>
|
||||
pub fn bitfieldFillOne2<N: Scalar, D: Dimension>(Value: &TVec<N, D>, FirstBit: i32, BitCount: i32) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -28,7 +28,7 @@ pub fn bitfieldFillZero<IU>(Value: IU, FirstBit: i32, BitCount: i32) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitfieldFillZero2<N: Scalar, D: Dimension>(Value: &Vec<N, D>, FirstBit: i32, BitCount: i32) -> Vec<N, D>
|
||||
pub fn bitfieldFillZero2<N: Scalar, D: Dimension>(Value: &TVec<N, D>, FirstBit: i32, BitCount: i32) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -113,7 +113,7 @@ pub fn bitfieldRotateLeft<IU>(In: IU, Shift: i32) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitfieldRotateLeft2<N: Scalar, D: Dimension>(In: &Vec<N, D>, Shift: i32) -> Vec<N, D>
|
||||
pub fn bitfieldRotateLeft2<N: Scalar, D: Dimension>(In: &TVec<N, D>, Shift: i32) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -122,7 +122,7 @@ pub fn bitfieldRotateRight<IU>(In: IU, Shift: i32) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitfieldRotateRight2<N: Scalar, D: Dimension>(In: &Vec<N, D>, Shift: i32) -> Vec<N, D>
|
||||
pub fn bitfieldRotateRight2<N: Scalar, D: Dimension>(In: &TVec<N, D>, Shift: i32) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -131,7 +131,7 @@ pub fn mask<IU>(Bits: IU) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn mask2<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn mask2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -5,10 +5,10 @@ use approx::AbsDiffEq;
|
||||
use na::DefaultAllocator;
|
||||
|
||||
use traits::{Alloc, Number, Dimension};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
/// Component-wise approximate equality beween two vectors.
|
||||
pub fn epsilon_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, epsilon: N) -> Vec<bool, D>
|
||||
pub fn epsilon_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon))
|
||||
}
|
||||
@ -19,7 +19,7 @@ pub fn epsilon_equal2<N: AbsDiffEq<Epsilon = N>>(x: N, y: N, epsilon: N) -> bool
|
||||
}
|
||||
|
||||
/// Component-wise approximate non-equality beween two vectors.
|
||||
pub fn epsilon_not_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, epsilon: N) -> Vec<bool, D>
|
||||
pub fn epsilon_not_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon))
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
//use na::{Scalar, DefaultAllocator};
|
||||
//
|
||||
//use traits::{Alloc, Dimension};
|
||||
//use aliases::Vec;
|
||||
//use aliases::TVec;
|
||||
|
||||
//pub fn iround<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<i32, D>
|
||||
//pub fn iround<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<i32, D>
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// x.map(|x| x.round())
|
||||
//}
|
||||
@ -12,7 +12,7 @@
|
||||
// unimplemented!()
|
||||
//}
|
||||
//
|
||||
//pub fn uround<N: Scalar, D: Dimension>(x: &Vec<N, D>) -> Vec<u32, D>
|
||||
//pub fn uround<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<u32, D>
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// unimplemented!()
|
||||
//}
|
@ -1,16 +1,16 @@
|
||||
use na::{Scalar, DefaultAllocator};
|
||||
|
||||
use traits::{Alloc, Dimension};
|
||||
use aliases::{Vec, Mat};
|
||||
use aliases::{TVec, TMat};
|
||||
|
||||
/// The `index`-th column of the matrix `m`.
|
||||
pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &Mat<N, R, C>, index: usize) -> Vec<N, R>
|
||||
pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, R>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.column(index).into_owned()
|
||||
}
|
||||
|
||||
/// Sets to `x` the `index`-th column of the matrix `m`.
|
||||
pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(m: &Mat<N, R, C>, index: usize, x: &Vec<N, R>) -> Mat<N, R, C>
|
||||
pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize, x: &TVec<N, R>) -> TMat<N, R, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
let mut res = m.clone();
|
||||
res.set_column(index, x);
|
||||
@ -18,13 +18,13 @@ pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(m: &Mat<N, R, C>, index
|
||||
}
|
||||
|
||||
/// The `index`-th row of the matrix `m`.
|
||||
pub fn row<N: Scalar, R: Dimension, C: Dimension>(m: &Mat<N, R, C>, index: usize) -> Vec<N, C>
|
||||
pub fn row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.row(index).into_owned().transpose()
|
||||
}
|
||||
|
||||
/// Sets to `x` the `index`-th row of the matrix `m`.
|
||||
pub fn set_row<N: Scalar, R: Dimension, C: Dimension>(m: &Mat<N, R, C>, index: usize, x: &Vec<N, C>) -> Mat<N, R, C>
|
||||
pub fn set_row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize, x: &TVec<N, C>) -> TMat<N, R, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
let mut res = m.clone();
|
||||
res.set_row(index, &x.transpose());
|
||||
|
@ -1,17 +1,17 @@
|
||||
use na::{Real, DefaultAllocator};
|
||||
|
||||
use traits::{Alloc, Dimension};
|
||||
use aliases::Mat;
|
||||
use aliases::TMat;
|
||||
|
||||
/// Fast matrix inverse for affine matrix.
|
||||
pub fn affine_inverse<N: Real, D: Dimension>(m: Mat<N, D, D>) -> Mat<N, D, D>
|
||||
pub fn affine_inverse<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
// FIXME: this should be optimized.
|
||||
m.try_inverse().unwrap_or(Mat::<_, D, D>::zeros())
|
||||
m.try_inverse().unwrap_or(TMat::<_, D, D>::zeros())
|
||||
}
|
||||
|
||||
/// Compute the transpose of the inverse of a matrix.
|
||||
pub fn inverse_transpose<N: Real, D: Dimension>(m: Mat<N, D, D>) -> Mat<N, D, D>
|
||||
pub fn inverse_transpose<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
m.try_inverse().unwrap_or(Mat::<_, D, D>::zeros()).transpose()
|
||||
m.try_inverse().unwrap_or(TMat::<_, D, D>::zeros()).transpose()
|
||||
}
|
@ -12,7 +12,7 @@ pub fn packF3x9_E1x5(v: &Vec3) -> i32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn packHalf<D: Dimension>(v: &Vec<f32, D>) -> Vec<u16, D>
|
||||
pub fn packHalf<D: Dimension>(v: &TVec<f32, D>) -> TVec<u16, D>
|
||||
where DefaultAllocator: Alloc<u16, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -53,7 +53,7 @@ pub fn packRGBM<N: Scalar>(rgb: &TVec3<N>) -> TVec4<N> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn packSnorm<I: Scalar, N: Real, D: Dimension>(v: Vec<N, D>) -> Vec<I, D>
|
||||
pub fn packSnorm<I: Scalar, N: Real, D: Dimension>(v: TVec<N, D>) -> TVec<I, D>
|
||||
where DefaultAllocator: Alloc<N, D> + Alloc<I, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -102,7 +102,7 @@ pub fn packUint4x8(v: &U8Vec4) -> i32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn packUnorm<UI: Scalar, N: Real, D: Dimension>(v: &Vec<N, D>) -> Vec<UI, D>
|
||||
pub fn packUnorm<UI: Scalar, N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<UI, D>
|
||||
where DefaultAllocator: Alloc<N, D> + Alloc<UI, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -155,7 +155,7 @@ pub fn unpackF3x9_E1x5(p: i32) -> Vec3 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn unpackHalf<N: Scalar, D: Dimension>(p: Vec<i16, D>) -> Vec<N, D>
|
||||
pub fn unpackHalf<N: Scalar, D: Dimension>(p: TVec<i16, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -196,7 +196,7 @@ pub fn unpackRGBM<N: Scalar>(rgbm: &TVec4<N>) -> TVec3<N> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn unpackSnorm<I: Scalar, N: Real, D: Dimension>(v: &Vec<I, D>) -> Vec<N, D>
|
||||
pub fn unpackSnorm<I: Scalar, N: Real, D: Dimension>(v: &TVec<I, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> + Alloc<I, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -245,7 +245,7 @@ pub fn unpackUint4x8(p: i32) -> U8Vec4 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn unpackUnorm<UI: Scalar, N: Real, D: Dimension>(v: &Vec<UI, D>) -> Vec<N, D>
|
||||
pub fn unpackUnorm<UI: Scalar, N: Real, D: Dimension>(v: &TVec<UI, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> + Alloc<UI, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use na::{Real, U4, UnitQuaternion};
|
||||
|
||||
use aliases::{Qua, Vec, TVec3, TMat4};
|
||||
use aliases::{Qua, TVec, TVec3, TMat4};
|
||||
|
||||
|
||||
/// Euler angles of the quaternion `q` as (pitch, yaw, roll).
|
||||
@ -11,22 +11,22 @@ pub fn quat_euler_angles<N: Real>(x: &Qua<N>) -> TVec3<N> {
|
||||
}
|
||||
|
||||
/// Component-wise `>` comparison between two quaternions.
|
||||
pub fn quat_greater_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||
pub fn quat_greater_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
|
||||
::greater_than(&x.coords, &y.coords)
|
||||
}
|
||||
|
||||
/// Component-wise `>=` comparison between two quaternions.
|
||||
pub fn quat_greater_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||
pub fn quat_greater_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
|
||||
::greater_than_equal(&x.coords, &y.coords)
|
||||
}
|
||||
|
||||
/// Component-wise `<` comparison between two quaternions.
|
||||
pub fn quat_less_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||
pub fn quat_less_than<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
|
||||
::less_than(&x.coords, &y.coords)
|
||||
}
|
||||
|
||||
/// Component-wise `<=` comparison between two quaternions.
|
||||
pub fn quat_less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> Vec<bool, U4> {
|
||||
pub fn quat_less_than_equal<N: Real>(x: &Qua<N>, y: &Qua<N>) -> TVec<bool, U4> {
|
||||
::less_than_equal(&x.coords, &y.coords)
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
use na::{Scalar, Real, U3, DefaultAllocator};
|
||||
|
||||
use traits::{Number, Alloc, Dimension};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
|
||||
pub fn ceilMultiple<T>(v: T, Multiple: T) -> T {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn ceilMultiple2<N: Scalar, D: Dimension>(v: &Vec<N, D>, Multiple: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn ceilMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -17,7 +17,7 @@ pub fn ceilPowerOfTwo<IU>(v: IU) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn ceilPowerOfTwo2<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn ceilPowerOfTwo2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -26,7 +26,7 @@ pub fn floorMultiple<T>(v: T, Multiple: T) -> T {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn floorMultiple2<N: Scalar, D: Dimension>(v: &Vec<N, D>, Multiple: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn floorMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -35,7 +35,7 @@ pub fn floorPowerOfTwo<IU>(v: IU) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn floorPowerOfTwo2<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn floorPowerOfTwo2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -44,12 +44,12 @@ pub fn isMultiple<IU>(v: IU, Multiple: IU) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn isMultiple2<N: Scalar, D: Dimension>(v: &Vec<N, D>,Multiple: N) -> Vec<bool, D>
|
||||
pub fn isMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>,Multiple: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn isMultiple3<N: Scalar, D: Dimension>(v: &Vec<N, D>, Multiple: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn isMultiple3<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -58,7 +58,7 @@ pub fn isPowerOfTwo2<IU>(v: IU) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn isPowerOfTwo<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn isPowerOfTwo<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -67,7 +67,7 @@ pub fn roundMultiple<T>(v: T, Multiple: T) -> T {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn roundMultiple2<N: Scalar, D: Dimension>(v: &Vec<N, D>, Multiple: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn roundMultiple2<N: Scalar, D: Dimension>(v: &TVec<N, D>, Multiple: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -76,7 +76,7 @@ pub fn roundPowerOfTwo<IU>(v: IU) -> IU {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn roundPowerOfTwo2<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn roundPowerOfTwo2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use na::{Scalar, Real, DefaultAllocator, Quaternion};
|
||||
|
||||
use traits::{Number, Alloc, Dimension};
|
||||
use aliases::{Qua, Mat, TMat2, TMat3, TMat4, TVec1, TVec2, TVec3, TVec4,
|
||||
use aliases::{Qua, TMat, TMat2, TMat3, TMat4, TVec1, TVec2, TVec3, TVec4,
|
||||
TMat2x3, TMat2x4, TMat3x2, TMat3x4, TMat4x2, TMat4x3};
|
||||
|
||||
/// Creates a 2x2 matrix from a slice arranged in column-major order.
|
||||
@ -240,13 +240,13 @@ pub fn make_vec4<N: Scalar>(ptr: &[N]) -> TVec4<N> {
|
||||
}
|
||||
|
||||
/// Converts a matrix or vector to a slice arranged in column-major order.
|
||||
pub fn value_ptr<N: Scalar, R: Dimension, C: Dimension>(x: &Mat<N, R, C>) -> &[N]
|
||||
pub fn value_ptr<N: Scalar, R: Dimension, C: Dimension>(x: &TMat<N, R, C>) -> &[N]
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.as_slice()
|
||||
}
|
||||
|
||||
/// Converts a matrix or vector to a mutable slice arranged in column-major order.
|
||||
pub fn value_ptr_mut<N: Scalar, R: Dimension, C: Dimension>(x: &mut Mat<N, R, C>) -> &mut [N]
|
||||
pub fn value_ptr_mut<N: Scalar, R: Dimension, C: Dimension>(x: &mut TMat<N, R, C>) -> &mut [N]
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.as_mut_slice()
|
||||
}
|
||||
|
@ -1,13 +1,13 @@
|
||||
use na::{Scalar, U2};
|
||||
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
|
||||
pub fn float_distance<T>(x: T, y: T) -> u64 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn float_distance2<N: Scalar>(x: &TVec2<N>, y: &TVec2<N>) -> Vec<u64, U2> {
|
||||
pub fn float_distance2<N: Scalar>(x: &TVec2<N>, y: &TVec2<N>) -> TVec<u64, U2> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
|
@ -1,28 +1,28 @@
|
||||
use na::{self, DefaultAllocator};
|
||||
|
||||
use traits::{Number, Alloc, Dimension};
|
||||
use aliases::Mat;
|
||||
use aliases::TMat;
|
||||
|
||||
/// The sum of every components of the given matrix or vector.
|
||||
pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
||||
pub fn comp_add<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::zero(), |x, y| x + *y)
|
||||
}
|
||||
|
||||
/// The maximum of every components of the given matrix or vector.
|
||||
pub fn comp_max<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
||||
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))
|
||||
}
|
||||
|
||||
/// The minimum of every components of the given matrix or vector.
|
||||
pub fn comp_min<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
||||
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))
|
||||
}
|
||||
|
||||
/// The product of every components of the given matrix or vector.
|
||||
pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &Mat<N, R, C>) -> N
|
||||
pub fn comp_mul<N: Number, R: Dimension, C: Dimension>(m: &TMat<N, R, C>) -> N
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
m.iter().fold(N::one(), |x, y| x * *y)
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use na::{Real, U3, U4};
|
||||
|
||||
use aliases::{Vec, Mat};
|
||||
use aliases::{TVec, TMat};
|
||||
|
||||
pub fn derivedEulerAngleX<N: Real>(angleX: N, angularVelocityX: N) -> TMat4<N> {
|
||||
unimplemented!()
|
||||
|
@ -1,56 +1,56 @@
|
||||
use na::{Real, DefaultAllocator};
|
||||
|
||||
use traits::{Alloc, Dimension};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
/// The squared distance between two points.
|
||||
pub fn distance2<N: Real, D: Dimension>(p0: &Vec<N, D>, p1: &Vec<N, D>) -> N
|
||||
pub fn distance2<N: Real, D: Dimension>(p0: &TVec<N, D>, p1: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
(p1 - p0).norm_squared()
|
||||
}
|
||||
|
||||
/// The l1-norm of `x - y`.
|
||||
pub fn l1_distance<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
|
||||
pub fn l1_distance<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
l1_norm(&(x - y))
|
||||
}
|
||||
|
||||
/// The l1-norm of `v`.
|
||||
pub fn l1_norm<N: Real, D: Dimension>(v: &Vec<N, D>) -> N
|
||||
pub fn l1_norm<N: Real, D: Dimension>(v: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
::comp_add(&v.abs())
|
||||
}
|
||||
|
||||
/// The l2-norm of `x - y`.
|
||||
pub fn l2_distance<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
|
||||
pub fn l2_distance<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
l2_norm(&(y - x))
|
||||
}
|
||||
|
||||
/// The l2-norm of `v`.
|
||||
pub fn l2_norm<N: Real, D: Dimension>(x: &Vec<N, D>) -> N
|
||||
pub fn l2_norm<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm()
|
||||
}
|
||||
|
||||
/// The squared magnitude of `x`.
|
||||
pub fn length2<N: Real, D: Dimension>(x: &Vec<N, D>) -> N
|
||||
pub fn length2<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm_squared()
|
||||
}
|
||||
|
||||
/// The squared magnitude of `x`.
|
||||
pub fn magnitude2<N: Real, D: Dimension>(x: &Vec<N, D>) -> N
|
||||
pub fn magnitude2<N: Real, D: Dimension>(x: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.norm_squared()
|
||||
}
|
||||
|
||||
//pub fn lxNorm<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>, unsigned int Depth) -> N
|
||||
//pub fn lxNorm<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, unsigned int Depth) -> N
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// unimplemented!()
|
||||
//}
|
||||
//
|
||||
//pub fn lxNorm<N: Real, D: Dimension>(x: &Vec<N, D>, unsigned int Depth) -> N
|
||||
//pub fn lxNorm<N: Real, D: Dimension>(x: &TVec<N, D>, unsigned int Depth) -> N
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// unimplemented!()
|
||||
//}
|
||||
|
@ -1,17 +1,17 @@
|
||||
use na::{Real, DefaultAllocator};
|
||||
|
||||
use traits::{Dimension, Alloc};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
/// The dot product of the normalized version of `x` and `y`.
|
||||
pub fn fast_normalize_dot<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
|
||||
pub fn fast_normalize_dot<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
// XXX: improve those.
|
||||
x.normalize().dot(&y.normalize())
|
||||
}
|
||||
|
||||
/// The dot product of the normalized version of `x` and `y`.
|
||||
pub fn normalize_dot<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
|
||||
pub fn normalize_dot<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
// XXX: improve those.
|
||||
x.normalize().dot(&y.normalize())
|
||||
|
@ -1,11 +1,11 @@
|
||||
use na::{DefaultAllocator, Real};
|
||||
|
||||
use traits::{Dimension, Alloc};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
|
||||
/// The angle between two vectors.
|
||||
pub fn angle<N: Real, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> N
|
||||
pub fn angle<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.angle(y)
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
use na::{Real, DefaultAllocator};
|
||||
|
||||
use traits::{Number, Dimension, Alloc};
|
||||
use aliases::{Vec, TVec2, TVec3};
|
||||
use aliases::{TVec, TVec2, TVec3};
|
||||
|
||||
/// Returns `true` if two vectors are collinear (up to an epsilon).
|
||||
pub fn are_collinear<N: Number>(v0: &TVec3<N>, v1: &TVec3<N>, epsilon: N) -> bool {
|
||||
@ -14,30 +14,30 @@ pub fn are_collinear2d<N: Number>(v0: &TVec2<N>, v1: &TVec2<N>, epsilon: N) -> b
|
||||
}
|
||||
|
||||
/// Returns `true` if two vectors are orthogonal (up to an epsilon).
|
||||
pub fn are_orthogonal<N: Number, D: Dimension>(v0: &Vec<N, D>, v1: &Vec<N, D>, epsilon: N) -> bool
|
||||
pub fn are_orthogonal<N: Number, D: Dimension>(v0: &TVec<N, D>, v1: &TVec<N, D>, epsilon: N) -> bool
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
abs_diff_eq!(v0.dot(v1), N::zero(), epsilon = epsilon)
|
||||
}
|
||||
|
||||
//pub fn are_orthonormal<N: Number, D: Dimension>(v0: &Vec<N, D>, v1: &Vec<N, D>, epsilon: N) -> bool
|
||||
//pub fn are_orthonormal<N: Number, D: Dimension>(v0: &TVec<N, D>, v1: &TVec<N, D>, epsilon: N) -> bool
|
||||
// where DefaultAllocator: Alloc<N, D> {
|
||||
// unimplemented!()
|
||||
//}
|
||||
|
||||
/// Returns `true` if all the components of `v` are zero (up to an epsilon).
|
||||
pub fn is_comp_null<N: Number, D: Dimension>(v: &Vec<N, D>, epsilon: N) -> Vec<bool, D>
|
||||
pub fn is_comp_null<N: Number, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon))
|
||||
}
|
||||
|
||||
/// Returns `true` if `v` has a magnitude of 1 (up to an epsilon).
|
||||
pub fn is_normalized<N: Real, D: Dimension>(v: &Vec<N, D>, epsilon: N) -> bool
|
||||
pub fn is_normalized<N: Real, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> bool
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon)
|
||||
}
|
||||
|
||||
/// Returns `true` if `v` is zero (up to an epsilon).
|
||||
pub fn is_null<N: Number, D: Dimension>(v: &Vec<N, D>, epsilon: N) -> bool
|
||||
pub fn is_null<N: Number, D: Dimension>(v: &TVec<N, D>, epsilon: N) -> bool
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
abs_diff_eq!(*v, Vec::<N, D>::zeros(), epsilon = epsilon)
|
||||
abs_diff_eq!(*v, TVec::<N, D>::zeros(), epsilon = epsilon)
|
||||
}
|
||||
|
@ -1,28 +1,28 @@
|
||||
use na::{Scalar, Real, U3, DefaultAllocator};
|
||||
|
||||
use traits::{Number, Alloc, Dimension};
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
|
||||
pub fn bitCount<T>(v: T) -> i32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitCount2<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<i32, D>
|
||||
pub fn bitCount2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<i32, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitfieldExtract<N: Scalar, D: Dimension>(Value: &Vec<N, D>, Offset: i32, Bits: i32) -> Vec<N, D>
|
||||
pub fn bitfieldExtract<N: Scalar, D: Dimension>(Value: &TVec<N, D>, Offset: i32, Bits: i32) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitfieldInsert<N: Scalar, D: Dimension>(Base: &Vec<N, D>, Insert: &Vec<N, D>, Offset: i32, Bits: i32) -> Vec<N, D>
|
||||
pub fn bitfieldInsert<N: Scalar, D: Dimension>(Base: &TVec<N, D>, Insert: &TVec<N, D>, Offset: i32, Bits: i32) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn bitfieldReverse<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn bitfieldReverse<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -31,7 +31,7 @@ pub fn findLSB<IU>(x: IU) -> u32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn findLSB2<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<i32, D>
|
||||
pub fn findLSB2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<i32, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
@ -40,27 +40,27 @@ pub fn findMSB<IU>(x: IU) -> i32 {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn findMSB2<N: Scalar, D: Dimension>(v: &Vec<N, D>) -> Vec<i32, D>
|
||||
pub fn findMSB2<N: Scalar, D: Dimension>(v: &TVec<N, D>) -> TVec<i32, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn imulExtended<N: Scalar, D: Dimension>(x: &Vec<i32, D>, y: &Vec<i32, D>, msb: &Vec<i32, D>, lsb: &Vec<i32, D>)
|
||||
pub fn imulExtended<N: Scalar, D: Dimension>(x: &TVec<i32, D>, y: &TVec<i32, D>, msb: &TVec<i32, D>, lsb: &TVec<i32, D>)
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn uaddCarry<N: Scalar, D: Dimension>(x: &Vec<u32, D>, y: &Vec<u32, D>, carry: &Vec<u32, D>) -> Vec<u32, D>
|
||||
pub fn uaddCarry<N: Scalar, D: Dimension>(x: &TVec<u32, D>, y: &TVec<u32, D>, carry: &TVec<u32, D>) -> TVec<u32, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn umulExtended<N: Scalar, D: Dimension>(x: &Vec<u32, D>, y: &Vec<u32, D>, msb: &Vec<u32, D>, lsb: &Vec<u32, D>)
|
||||
pub fn umulExtended<N: Scalar, D: Dimension>(x: &TVec<u32, D>, y: &TVec<u32, D>, msb: &TVec<u32, D>, lsb: &TVec<u32, D>)
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
pub fn usubBorrow<N: Scalar, D: Dimension>(x: &Vec<u32, D>, y: &Vec<u32, D>, borrow: &Vec<u32, D>) -> Vec<u32, D>
|
||||
pub fn usubBorrow<N: Scalar, D: Dimension>(x: &TVec<u32, D>, y: &TVec<u32, D>, borrow: &TVec<u32, D>) -> TVec<u32, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
@ -1,34 +1,34 @@
|
||||
use na::{Scalar, Real, DefaultAllocator};
|
||||
|
||||
use traits::{Alloc, Dimension, Number};
|
||||
use aliases::{Mat, Vec};
|
||||
use aliases::{TMat, TVec};
|
||||
|
||||
/// The determinant of the matrix `m`.
|
||||
pub fn determinant<N: Real, D: Dimension>(m: &Mat<N, D, D>) -> N
|
||||
pub fn determinant<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> N
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
m.determinant()
|
||||
}
|
||||
|
||||
/// The inverse of the matrix `m`.
|
||||
pub fn inverse<N: Real, D: Dimension>(m: &Mat<N, D, D>) -> Mat<N, D, D>
|
||||
pub fn inverse<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> TMat<N, D, D>
|
||||
where DefaultAllocator: Alloc<N, D, D> {
|
||||
m.clone().try_inverse().unwrap_or(Mat::<N, D, D>::zeros())
|
||||
m.clone().try_inverse().unwrap_or(TMat::<N, D, D>::zeros())
|
||||
}
|
||||
|
||||
/// Component-wise multiplication of two matrices.
|
||||
pub fn matrix_comp_mult<N: Number, R: Dimension, C: Dimension>(x: &Mat<N, R, C>, y: &Mat<N, R, C>) -> Mat<N, R, C>
|
||||
pub fn matrix_comp_mult<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y: &TMat<N, R, C>) -> TMat<N, R, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.component_mul(y)
|
||||
}
|
||||
|
||||
/// Treats the first parameter `c` as a column vector and the second parameter `r` as a row vector and does a linear algebraic matrix multiply `c * r`.
|
||||
pub fn outer_product<N: Number, R: Dimension, C: Dimension>(c: &Vec<N, R>, r: &Vec<N, C>) -> Mat<N, R, C>
|
||||
pub fn outer_product<N: Number, R: Dimension, C: Dimension>(c: &TVec<N, R>, r: &TVec<N, C>) -> TMat<N, R, C>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
c * r.transpose()
|
||||
}
|
||||
|
||||
/// The transpose of the matrix `m`.
|
||||
pub fn transpose<N: Scalar, R: Dimension, C: Dimension>(x: &Mat<N, R, C>) -> Mat<N, C, R>
|
||||
pub fn transpose<N: Scalar, R: Dimension, C: Dimension>(x: &TMat<N, R, C>) -> TMat<N, C, R>
|
||||
where DefaultAllocator: Alloc<N, R, C> {
|
||||
x.transpose()
|
||||
}
|
@ -1,95 +1,95 @@
|
||||
use na::{self, Real, DefaultAllocator};
|
||||
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
use traits::{Alloc, Dimension};
|
||||
|
||||
|
||||
/// Component-wise arc-cosinus.
|
||||
pub fn acos<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn acos<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.acos())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic arc-cosinus.
|
||||
pub fn acosh<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn acosh<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.acosh())
|
||||
}
|
||||
|
||||
/// Component-wise arc-sinus.
|
||||
pub fn asin<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn asin<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.asin())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic arc-sinus.
|
||||
pub fn asinh<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn asinh<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.asinh())
|
||||
}
|
||||
|
||||
/// Component-wise arc-tangent of `y / x`.
|
||||
pub fn atan2<N: Real, D: Dimension>(y: &Vec<N, D>, x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn atan2<N: Real, D: Dimension>(y: &TVec<N, D>, x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
y.zip_map(x, |y, x| y.atan2(x))
|
||||
}
|
||||
|
||||
/// Component-wise arc-tangent.
|
||||
pub fn atan<N: Real, D: Dimension>(y_over_x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn atan<N: Real, D: Dimension>(y_over_x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
y_over_x.map(|e| e.atan())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic arc-tangent.
|
||||
pub fn atanh<N: Real, D: Dimension>(x: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn atanh<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.map(|e| e.atanh())
|
||||
}
|
||||
|
||||
/// Component-wise cosinus.
|
||||
pub fn cos<N: Real, D: Dimension>(angle: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn cos<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.cos())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic cosinus.
|
||||
pub fn cosh<N: Real, D: Dimension>(angle: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn cosh<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.cosh())
|
||||
}
|
||||
|
||||
/// Component-wise conversion from radians to degrees.
|
||||
pub fn degrees<N: Real, D: Dimension>(radians: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn degrees<N: Real, D: Dimension>(radians: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
radians.map(|e| e * na::convert(180.0) / N::pi())
|
||||
}
|
||||
|
||||
/// Component-wise conversion fro degrees to radians.
|
||||
pub fn radians<N: Real, D: Dimension>(degrees: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn radians<N: Real, D: Dimension>(degrees: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
degrees.map(|e| e * N::pi() / na::convert(180.0))
|
||||
}
|
||||
|
||||
/// Component-wise sinus.
|
||||
pub fn sin<N: Real, D: Dimension>(angle: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn sin<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.sin())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic sinus.
|
||||
pub fn sinh<N: Real, D: Dimension>(angle: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn sinh<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.sinh())
|
||||
}
|
||||
|
||||
/// Component-wise tangent.
|
||||
pub fn tan<N: Real, D: Dimension>(angle: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn tan<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.tan())
|
||||
}
|
||||
|
||||
/// Component-wise hyperbolic tangent.
|
||||
pub fn tanh<N: Real, D: Dimension>(angle: &Vec<N, D>) -> Vec<N, D>
|
||||
pub fn tanh<N: Real, D: Dimension>(angle: &TVec<N, D>) -> TVec<N, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
angle.map(|e| e.tanh())
|
||||
}
|
||||
|
@ -1,58 +1,58 @@
|
||||
use na::{DefaultAllocator};
|
||||
|
||||
use aliases::Vec;
|
||||
use aliases::TVec;
|
||||
use traits::{Number, Alloc, Dimension};
|
||||
|
||||
/// Checks that all the vector components are `true`.
|
||||
pub fn all<D: Dimension>(v: &Vec<bool, D>) -> bool
|
||||
pub fn all<D: Dimension>(v: &TVec<bool, D>) -> bool
|
||||
where DefaultAllocator: Alloc<bool, D> {
|
||||
v.iter().all(|x| *x)
|
||||
}
|
||||
|
||||
/// Checks that at least one of the vector components is `true`.
|
||||
pub fn any<D: Dimension>(v: &Vec<bool, D>) -> bool
|
||||
pub fn any<D: Dimension>(v: &TVec<bool, D>) -> bool
|
||||
where DefaultAllocator: Alloc<bool, D> {
|
||||
v.iter().any(|x| *x)
|
||||
}
|
||||
|
||||
/// Component-wise equality comparison.
|
||||
pub fn equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x == y)
|
||||
}
|
||||
|
||||
/// Component-wise `>` comparison.
|
||||
pub fn greater_than<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn greater_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x > y)
|
||||
}
|
||||
|
||||
/// Component-wise `>=` comparison.
|
||||
pub fn greater_than_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn greater_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x >= y)
|
||||
}
|
||||
|
||||
/// Component-wise `<` comparison.
|
||||
pub fn less_than<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn less_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x < y)
|
||||
}
|
||||
|
||||
/// Component-wise `>=` comparison.
|
||||
pub fn less_than_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn less_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x <= y)
|
||||
}
|
||||
|
||||
/// Component-wise not `!`.
|
||||
pub fn not<D: Dimension>(v: &Vec<bool, D>) -> Vec<bool, D>
|
||||
pub fn not<D: Dimension>(v: &TVec<bool, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<bool, D> {
|
||||
v.map(|x| !x)
|
||||
}
|
||||
|
||||
/// Component-wise not-equality `!=`.
|
||||
pub fn not_equal<N: Number, D: Dimension>(x: &Vec<N, D>, y: &Vec<N, D>) -> Vec<bool, D>
|
||||
pub fn not_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
||||
where DefaultAllocator: Alloc<N, D> {
|
||||
x.zip_map(y, |x, y| x != y)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user