forked from M-Labs/nalgebra
Run rustfmt.
This commit is contained in:
parent
ed07b78b97
commit
8341ec2f10
@ -1,7 +1,7 @@
|
|||||||
|
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10};
|
||||||
use rand::{IsaacRng, Rng};
|
use rand::{IsaacRng, Rng};
|
||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, U10, Vector2, Vector3, Vector4};
|
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[path = "../common/macros.rs"]
|
#[path = "../common/macros.rs"]
|
||||||
mod macros;
|
mod macros;
|
||||||
@ -189,18 +189,10 @@ fn mat_mul_mat(bench: &mut Bencher) {
|
|||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn mat100_from_fn(bench: &mut Bencher) {
|
fn mat100_from_fn(bench: &mut Bencher) {
|
||||||
bench.iter(|| {
|
bench.iter(|| DMatrix::from_fn(100, 100, |a, b| a + b))
|
||||||
DMatrix::from_fn(100, 100, |a, b| {
|
|
||||||
a + b
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn mat500_from_fn(bench: &mut Bencher) {
|
fn mat500_from_fn(bench: &mut Bencher) {
|
||||||
bench.iter(|| {
|
bench.iter(|| DMatrix::from_fn(500, 500, |a, b| a + b))
|
||||||
DMatrix::from_fn(500, 500, |a, b| {
|
|
||||||
a + b
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
|
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
|
||||||
use rand::{IsaacRng, Rng};
|
use rand::{IsaacRng, Rng};
|
||||||
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
use test::{self, Bencher};
|
use test::{self, Bencher};
|
||||||
use typenum::U10000;
|
use typenum::U10000;
|
||||||
use na::{DVector, Vector2, Vector3, Vector4, VectorN};
|
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
|
||||||
|
|
||||||
#[path = "../common/macros.rs"]
|
#[path = "../common/macros.rs"]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use rand::{IsaacRng, Rng};
|
|
||||||
use test::{self, Bencher};
|
|
||||||
use na::{Quaternion, UnitQuaternion, Vector3};
|
use na::{Quaternion, UnitQuaternion, Vector3};
|
||||||
|
use rand::{IsaacRng, Rng};
|
||||||
use std::ops::{Add, Div, Mul, Sub};
|
use std::ops::{Add, Div, Mul, Sub};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[path = "../common/macros.rs"]
|
#[path = "../common/macros.rs"]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
@ -6,12 +6,12 @@ extern crate rand;
|
|||||||
extern crate test;
|
extern crate test;
|
||||||
extern crate typenum;
|
extern crate typenum;
|
||||||
|
|
||||||
use rand::{IsaacRng, Rng};
|
|
||||||
use na::DMatrix;
|
use na::DMatrix;
|
||||||
|
use rand::{IsaacRng, Rng};
|
||||||
|
|
||||||
mod core;
|
mod core;
|
||||||
mod linalg;
|
|
||||||
mod geometry;
|
mod geometry;
|
||||||
|
mod linalg;
|
||||||
|
|
||||||
fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix<f64> {
|
fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix<f64> {
|
||||||
let mut rng = IsaacRng::new_unseeded();
|
let mut rng = IsaacRng::new_unseeded();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{Bidiagonal, DMatrix, Matrix4};
|
use na::{Bidiagonal, DMatrix, Matrix4};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[path = "../common/macros.rs"]
|
#[path = "../common/macros.rs"]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{Cholesky, DMatrix, DVector};
|
use na::{Cholesky, DMatrix, DVector};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn cholesky_100x100(bh: &mut Bencher) {
|
fn cholesky_100x100(bh: &mut Bencher) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, DVector, FullPivLU};
|
use na::{DMatrix, DVector, FullPivLU};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
// Without unpack.
|
// Without unpack.
|
||||||
#[bench]
|
#[bench]
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, Hessenberg, Matrix4};
|
use na::{DMatrix, Hessenberg, Matrix4};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[path = "../common/macros.rs"]
|
#[path = "../common/macros.rs"]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, DVector, LU};
|
use na::{DMatrix, DVector, LU};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
// Without unpack.
|
// Without unpack.
|
||||||
#[bench]
|
#[bench]
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
mod solve;
|
|
||||||
mod cholesky;
|
|
||||||
mod qr;
|
|
||||||
mod hessenberg;
|
|
||||||
mod bidiagonal;
|
mod bidiagonal;
|
||||||
mod lu;
|
mod cholesky;
|
||||||
mod full_piv_lu;
|
mod full_piv_lu;
|
||||||
mod svd;
|
mod hessenberg;
|
||||||
|
mod lu;
|
||||||
|
mod qr;
|
||||||
mod schur;
|
mod schur;
|
||||||
|
mod solve;
|
||||||
|
mod svd;
|
||||||
mod symmetric_eigen;
|
mod symmetric_eigen;
|
||||||
// mod eigen;
|
// mod eigen;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, DVector, Matrix4, QR};
|
use na::{DMatrix, DVector, Matrix4, QR};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[path = "../common/macros.rs"]
|
#[path = "../common/macros.rs"]
|
||||||
mod macros;
|
mod macros;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{Matrix4, RealSchur};
|
use na::{Matrix4, RealSchur};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn schur_decompose_4x4(bh: &mut Bencher) {
|
fn schur_decompose_4x4(bh: &mut Bencher) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::Bencher;
|
|
||||||
use na::{DMatrix, DVector};
|
use na::{DMatrix, DVector};
|
||||||
|
use test::Bencher;
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn solve_l_triangular_100x100(bh: &mut Bencher) {
|
fn solve_l_triangular_100x100(bh: &mut Bencher) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{Matrix4, SVD};
|
use na::{Matrix4, SVD};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn svd_decompose_4x4(bh: &mut Bencher) {
|
fn svd_decompose_4x4(bh: &mut Bencher) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{Matrix4, SymmetricEigen};
|
use na::{Matrix4, SymmetricEigen};
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn symmetric_eigen_decompose_4x4(bh: &mut Bencher) {
|
fn symmetric_eigen_decompose_4x4(bh: &mut Bencher) {
|
||||||
|
@ -2,15 +2,13 @@ extern crate alga;
|
|||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
use alga::linear::FiniteDimInnerSpace;
|
use alga::linear::FiniteDimInnerSpace;
|
||||||
use na::{DefaultAllocator, Real, Unit, Vector2, Vector3, VectorN};
|
|
||||||
use na::allocator::Allocator;
|
use na::allocator::Allocator;
|
||||||
use na::dimension::Dim;
|
use na::dimension::Dim;
|
||||||
|
use na::{DefaultAllocator, Real, Unit, Vector2, Vector3, VectorN};
|
||||||
|
|
||||||
/// Reflects a vector wrt. the hyperplane with normal `plane_normal`.
|
/// Reflects a vector wrt. the hyperplane with normal `plane_normal`.
|
||||||
fn reflect_wrt_hyperplane_with_algebraic_genericity<V>(plane_normal: &Unit<V>, vector: &V) -> V
|
fn reflect_wrt_hyperplane_with_algebraic_genericity<V>(plane_normal: &Unit<V>, vector: &V) -> V
|
||||||
where
|
where V: FiniteDimInnerSpace + Copy {
|
||||||
V: FiniteDimInnerSpace + Copy,
|
|
||||||
{
|
|
||||||
let n = plane_normal.as_ref(); // Get the underlying vector of type `V`.
|
let n = plane_normal.as_ref(); // Get the underlying vector of type `V`.
|
||||||
*vector - *n * (n.dot(vector) * na::convert(2.0))
|
*vector - *n * (n.dot(vector) * na::convert(2.0))
|
||||||
}
|
}
|
||||||
@ -31,9 +29,7 @@ where
|
|||||||
|
|
||||||
/// Reflects a 2D vector wrt. the 2D line with normal `plane_normal`.
|
/// Reflects a 2D vector wrt. the 2D line with normal `plane_normal`.
|
||||||
fn reflect_wrt_hyperplane2<N>(plane_normal: &Unit<Vector2<N>>, vector: &Vector2<N>) -> Vector2<N>
|
fn reflect_wrt_hyperplane2<N>(plane_normal: &Unit<Vector2<N>>, vector: &Vector2<N>) -> Vector2<N>
|
||||||
where
|
where N: Real {
|
||||||
N: Real,
|
|
||||||
{
|
|
||||||
let n = plane_normal.as_ref(); // Get the underlying Vector2
|
let n = plane_normal.as_ref(); // Get the underlying Vector2
|
||||||
vector - n * (n.dot(vector) * na::convert(2.0))
|
vector - n * (n.dot(vector) * na::convert(2.0))
|
||||||
}
|
}
|
||||||
@ -41,9 +37,7 @@ where
|
|||||||
/// Reflects a 3D vector wrt. the 3D plane with normal `plane_normal`.
|
/// Reflects a 3D vector wrt. the 3D plane with normal `plane_normal`.
|
||||||
/// /!\ This is an exact replicate of `reflect_wrt_hyperplane2, but for 3D.
|
/// /!\ This is an exact replicate of `reflect_wrt_hyperplane2, but for 3D.
|
||||||
fn reflect_wrt_hyperplane3<N>(plane_normal: &Unit<Vector3<N>>, vector: &Vector3<N>) -> Vector3<N>
|
fn reflect_wrt_hyperplane3<N>(plane_normal: &Unit<Vector3<N>>, vector: &Vector3<N>) -> Vector3<N>
|
||||||
where
|
where N: Real {
|
||||||
N: Real,
|
|
||||||
{
|
|
||||||
let n = plane_normal.as_ref(); // Get the underlying Vector3
|
let n = plane_normal.as_ref(); // Get the underlying Vector3
|
||||||
vector - n * (n.dot(vector) * na::convert(2.0))
|
vector - n * (n.dot(vector) * na::convert(2.0))
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
extern crate approx;
|
extern crate approx;
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
use std::f32;
|
|
||||||
use na::{Isometry2, Point2, Vector2};
|
use na::{Isometry2, Point2, Vector2};
|
||||||
|
use std::f32;
|
||||||
|
|
||||||
fn use_dedicated_types() {
|
fn use_dedicated_types() {
|
||||||
let iso = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI);
|
let iso = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI);
|
||||||
|
@ -9,9 +9,7 @@ use na::{Id, Isometry3, Point3, Vector3};
|
|||||||
* intermediate value.
|
* intermediate value.
|
||||||
*/
|
*/
|
||||||
fn complicated_algorithm<T>(v: &Vector3<f32>, t: &T, n: usize) -> Vector3<f32>
|
fn complicated_algorithm<T>(v: &Vector3<f32>, t: &T, n: usize) -> Vector3<f32>
|
||||||
where
|
where T: Transformation<Point3<f32>> {
|
||||||
T: Transformation<Point3<f32>>,
|
|
||||||
{
|
|
||||||
let mut result = *v;
|
let mut result = *v;
|
||||||
|
|
||||||
// Do lots of operations involving t.
|
// Do lots of operations involving t.
|
||||||
|
@ -49,10 +49,9 @@ fn main() {
|
|||||||
3,
|
3,
|
||||||
[
|
[
|
||||||
// Components listed column-by-column.
|
// Components listed column-by-column.
|
||||||
1.0, 0.0, 0.0, 0.0,
|
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0,
|
||||||
0.0, 1.0, 0.0, 0.0,
|
]
|
||||||
0.0, 0.0, 1.0, 0.0
|
.iter()
|
||||||
].iter()
|
|
||||||
.cloned(),
|
.cloned(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -2,8 +2,8 @@
|
|||||||
extern crate approx;
|
extern crate approx;
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
use std::f32;
|
|
||||||
use na::{Isometry2, Point2, Vector2};
|
use na::{Isometry2, Point2, Vector2};
|
||||||
|
use std::f32;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let t = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI);
|
let t = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI);
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
use na::{MatrixMN, VectorN,
|
use na::{
|
||||||
Matrix2, Matrix3, Matrix4,
|
Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3,
|
||||||
Matrix2x3, Matrix3x2, Matrix4x2,
|
MatrixMN, Quaternion, VectorN, U1, U2, U3, U4,
|
||||||
Matrix2x4, Matrix3x4, Matrix4x3,
|
};
|
||||||
Quaternion,
|
|
||||||
U1, U2, U3, U4};
|
|
||||||
|
|
||||||
/// A matrix with components of type `N`. It has `R` rows, and `C` columns.
|
/// A matrix with components of type `N`. It has `R` rows, and `C` columns.
|
||||||
///
|
///
|
||||||
@ -270,7 +268,6 @@ pub type I8Vec3 = TVec3<i8>;
|
|||||||
/// A 4D vector with `i8` components.
|
/// A 4D vector with `i8` components.
|
||||||
pub type I8Vec4 = TVec4<i8>;
|
pub type I8Vec4 = TVec4<i8>;
|
||||||
|
|
||||||
|
|
||||||
/// A 2x2 matrix with components of type `N`.
|
/// A 2x2 matrix with components of type `N`.
|
||||||
pub type TMat2<N> = Matrix2<N>;
|
pub type TMat2<N> = Matrix2<N>;
|
||||||
/// A 2x2 matrix with components of type `N`.
|
/// A 2x2 matrix with components of type `N`.
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
use std::mem;
|
use na::{self, DefaultAllocator, Real};
|
||||||
use num::FromPrimitive;
|
use num::FromPrimitive;
|
||||||
use na::{self, Real, DefaultAllocator};
|
use std::mem;
|
||||||
|
|
||||||
use aliases::{TVec, TMat};
|
use aliases::{TMat, TVec};
|
||||||
use traits::{Number, Dimension, Alloc};
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`.
|
/// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`.
|
||||||
///
|
///
|
||||||
@ -125,8 +125,14 @@ pub fn clamp<N: Number, D: Dimension>(x: &TVec<N, D>, min_val: N, max_val: N) ->
|
|||||||
///
|
///
|
||||||
/// * [`clamp_scalar`](fn.clamp_scalar.html)
|
/// * [`clamp_scalar`](fn.clamp_scalar.html)
|
||||||
/// * [`clamp`](fn.clamp.html)
|
/// * [`clamp`](fn.clamp.html)
|
||||||
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>
|
pub fn clamp_vec<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
x: &TVec<N, D>,
|
||||||
|
min_val: &TVec<N, D>,
|
||||||
|
max_val: &TVec<N, D>,
|
||||||
|
) -> TVec<N, D>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Alloc<N, D>,
|
||||||
|
{
|
||||||
x.zip_zip_map(min_val, max_val, |a, min, max| na::clamp(a, min, max))
|
x.zip_zip_map(min_val, max_val, |a, min, max| na::clamp(a, min, max))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,7 +277,6 @@ pub fn fract<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
|||||||
/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html)
|
/// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html)
|
||||||
pub fn int_bits_to_float(v: i32) -> f32 {
|
pub fn int_bits_to_float(v: i32) -> f32 {
|
||||||
f32::from_bits(v as u32)
|
f32::from_bits(v as u32)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For each components of `v`, returns a floating-point value corresponding to a signed integer encoding of a floating-point value.
|
/// For each components of `v`, returns a floating-point value corresponding to a signed integer encoding of a floating-point value.
|
||||||
@ -359,7 +364,6 @@ pub fn modf<N: Number>(x: N, i: N) -> N {
|
|||||||
pub fn round<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
pub fn round<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
where DefaultAllocator: Alloc<N, D> {
|
||||||
x.map(|x| x.round())
|
x.map(|x| x.round())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn roundEven<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
//pub fn roundEven<N: Scalar, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||||
@ -383,13 +387,7 @@ pub fn round<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
|||||||
///
|
///
|
||||||
pub fn sign<N: Number, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
pub fn sign<N: Number, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
where DefaultAllocator: Alloc<N, D> {
|
||||||
x.map(|x| {
|
x.map(|x| if x.is_zero() { N::zero() } else { x.signum() })
|
||||||
if x.is_zero() {
|
|
||||||
N::zero()
|
|
||||||
} else {
|
|
||||||
x.signum()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns 0.0 if `x <= edge0` and `1.0 if x >= edge1` and performs smooth Hermite interpolation between 0 and 1 when `edge0 < x < edge1`.
|
/// Returns 0.0 if `x <= edge0` and `1.0 if x >= edge1` and performs smooth Hermite interpolation between 0 and 1 when `edge0 < x < edge1`.
|
||||||
@ -460,7 +458,6 @@ pub fn trunc<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
|||||||
/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html)
|
/// * [`uint_bits_to_float`](fn.uint_bits_to_float.html)
|
||||||
pub fn uint_bits_to_float_scalar(v: u32) -> f32 {
|
pub fn uint_bits_to_float_scalar(v: u32) -> f32 {
|
||||||
f32::from_bits(v)
|
f32::from_bits(v)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For each component of `v`, returns a floating-point value corresponding to a unsigned integer encoding of a floating-point value.
|
/// For each component of `v`, returns a floating-point value corresponding to a unsigned integer encoding of a floating-point value.
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
use na::{Scalar, Real, U2, U3, U4};
|
use aliases::{
|
||||||
use aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4,
|
Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1,
|
||||||
TMat4, TMat4x2, TMat4x3};
|
TVec2, TVec3, TVec4,
|
||||||
|
};
|
||||||
|
use na::{Real, Scalar, U2, U3, U4};
|
||||||
|
|
||||||
/// Creates a new 1D vector.
|
/// Creates a new 1D vector.
|
||||||
///
|
///
|
||||||
@ -32,112 +33,173 @@ pub fn vec4<N: Scalar>(x: N, y: N, z: N, w: N) -> TVec4<N> {
|
|||||||
TVec4::new(x, y, z, w)
|
TVec4::new(x, y, z, w)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Create a new 2x2 matrix.
|
/// Create a new 2x2 matrix.
|
||||||
pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
pub fn mat2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||||
TMat::<N, U2, U2>::new(
|
TMat::<N, U2, U2>::new(m11, m12, m21, m22)
|
||||||
m11, m12,
|
|
||||||
m21, m22,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 2x2 matrix.
|
/// Create a new 2x2 matrix.
|
||||||
pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
pub fn mat2x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N) -> TMat2<N> {
|
||||||
TMat::<N, U2, U2>::new(
|
TMat::<N, U2, U2>::new(m11, m12, m21, m22)
|
||||||
m11, m12,
|
|
||||||
m21, m22,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 2x3 matrix.
|
/// Create a new 2x3 matrix.
|
||||||
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3<N> {
|
pub fn mat2x3<N: Scalar>(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3<N> {
|
||||||
TMat::<N, U2, U3>::new(
|
TMat::<N, U2, U3>::new(m11, m12, m13, m21, m22, m23)
|
||||||
m11, m12, m13,
|
|
||||||
m21, m22, m23,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 2x4 matrix.
|
/// 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> {
|
pub fn mat2x4<N: Scalar>(
|
||||||
TMat::<N, U2, U4>::new(
|
m11: N,
|
||||||
m11, m12, m13, m14,
|
m12: N,
|
||||||
m21, m22, m23, m24,
|
m13: N,
|
||||||
)
|
m14: N,
|
||||||
|
m21: N,
|
||||||
|
m22: N,
|
||||||
|
m23: N,
|
||||||
|
m24: N,
|
||||||
|
) -> TMat2x4<N>
|
||||||
|
{
|
||||||
|
TMat::<N, U2, U4>::new(m11, m12, m13, m14, m21, m22, m23, m24)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 3x3 matrix.
|
/// 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> {
|
pub fn mat3<N: Scalar>(
|
||||||
TMat::<N, U3, U3>::new(
|
m11: N,
|
||||||
m11, m12, m13,
|
m12: N,
|
||||||
m21, m22, m23,
|
m13: N,
|
||||||
m31, m32, m33,
|
m21: N,
|
||||||
)
|
m22: N,
|
||||||
|
m23: N,
|
||||||
|
m31: N,
|
||||||
|
m32: N,
|
||||||
|
m33: N,
|
||||||
|
) -> TMat3<N>
|
||||||
|
{
|
||||||
|
TMat::<N, U3, U3>::new(m11, m12, m13, m21, m22, m23, m31, m32, m33)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 3x2 matrix.
|
/// Create a new 3x2 matrix.
|
||||||
pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2<N> {
|
pub fn mat3x2<N: Scalar>(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2<N> {
|
||||||
TMat::<N, U3, U2>::new(
|
TMat::<N, U3, U2>::new(m11, m12, m21, m22, m31, m32)
|
||||||
m11, m12,
|
|
||||||
m21, m22,
|
|
||||||
m31, m32,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 3x3 matrix.
|
/// 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> {
|
pub fn mat3x3<N: Scalar>(
|
||||||
TMat::<N, U3, U3>::new(
|
m11: N,
|
||||||
m11, m12, m13,
|
m12: N,
|
||||||
m31, m32, m33,
|
m13: N,
|
||||||
m21, m22, m23,
|
m21: N,
|
||||||
)
|
m22: N,
|
||||||
|
m23: N,
|
||||||
|
m31: N,
|
||||||
|
m32: N,
|
||||||
|
m33: N,
|
||||||
|
) -> TMat3<N>
|
||||||
|
{
|
||||||
|
TMat::<N, U3, U3>::new(m11, m12, m13, m31, m32, m33, m21, m22, m23)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 3x4 matrix.
|
/// 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> {
|
pub fn mat3x4<N: Scalar>(
|
||||||
TMat::<N, U3, U4>::new(
|
m11: N,
|
||||||
m11, m12, m13, m14,
|
m12: N,
|
||||||
m21, m22, m23, m24,
|
m13: N,
|
||||||
m31, m32, m33, m34,
|
m14: N,
|
||||||
)
|
m21: N,
|
||||||
|
m22: N,
|
||||||
|
m23: N,
|
||||||
|
m24: N,
|
||||||
|
m31: N,
|
||||||
|
m32: N,
|
||||||
|
m33: N,
|
||||||
|
m34: N,
|
||||||
|
) -> TMat3x4<N>
|
||||||
|
{
|
||||||
|
TMat::<N, U3, U4>::new(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 4x2 matrix.
|
/// 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> {
|
pub fn mat4x2<N: Scalar>(
|
||||||
TMat::<N, U4, U2>::new(
|
m11: N,
|
||||||
m11, m12,
|
m12: N,
|
||||||
m21, m22,
|
m21: N,
|
||||||
m31, m32,
|
m22: N,
|
||||||
m41, m42,
|
m31: N,
|
||||||
)
|
m32: N,
|
||||||
|
m41: N,
|
||||||
|
m42: N,
|
||||||
|
) -> TMat4x2<N>
|
||||||
|
{
|
||||||
|
TMat::<N, U4, U2>::new(m11, m12, m21, m22, m31, m32, m41, m42)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 4x3 matrix.
|
/// 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> {
|
pub fn mat4x3<N: Scalar>(
|
||||||
TMat::<N, U4, U3>::new(
|
m11: N,
|
||||||
m11, m12, m13,
|
m12: N,
|
||||||
m21, m22, m23,
|
m13: N,
|
||||||
m31, m32, m33,
|
m21: N,
|
||||||
m41, m42, m43,
|
m22: N,
|
||||||
|
m23: N,
|
||||||
|
m31: N,
|
||||||
|
m32: N,
|
||||||
|
m33: N,
|
||||||
|
m41: N,
|
||||||
|
m42: N,
|
||||||
|
m43: N,
|
||||||
|
) -> TMat4x3<N>
|
||||||
|
{
|
||||||
|
TMat::<N, U4, U3>::new(m11, m12, m13, m21, m22, m23, m31, m32, m33, m41, m42, m43)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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>
|
||||||
|
{
|
||||||
|
TMat::<N, U4, U4>::new(
|
||||||
|
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new 4x4 matrix.
|
/// 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> {
|
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>
|
||||||
|
{
|
||||||
TMat::<N, U4, U4>::new(
|
TMat::<N, U4, U4>::new(
|
||||||
m11, m12, m13, m14,
|
m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44,
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
m41, m42, m43, m44,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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> {
|
|
||||||
TMat::<N, U4, U4>::new(
|
|
||||||
m11, m12, m13, m14,
|
|
||||||
m21, m22, m23, m24,
|
|
||||||
m31, m32, m33, m34,
|
|
||||||
m41, m42, m43, m44,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use na::{Real, DefaultAllocator};
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
|
use na::{DefaultAllocator, Real};
|
||||||
use traits::{Alloc, Dimension};
|
use traits::{Alloc, Dimension};
|
||||||
|
|
||||||
/// Component-wise exponential.
|
/// Component-wise exponential.
|
||||||
@ -30,7 +30,6 @@ pub fn exp2<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
|||||||
pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
pub fn inversesqrt<N: Real, D: Dimension>(v: &TVec<N, D>) -> TVec<N, D>
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
where DefaultAllocator: Alloc<N, D> {
|
||||||
v.map(|x| N::one() / x.sqrt())
|
v.map(|x| N::one() / x.sqrt())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise logarithm.
|
/// Component-wise logarithm.
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use na::{Real, Orthographic3, Perspective3};
|
|
||||||
use aliases::TMat4;
|
use aliases::TMat4;
|
||||||
|
use na::{Orthographic3, Perspective3, Real};
|
||||||
|
|
||||||
//pub fn frustum<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
|
//pub fn frustum<N: Real>(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4<N> {
|
||||||
// unimplemented!()
|
// unimplemented!()
|
||||||
@ -90,7 +90,6 @@ pub fn ortho<N: Real>(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -
|
|||||||
// unimplemented!()
|
// unimplemented!()
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
/// Creates a matrix for a perspective-view frustum based on the right handedness and OpenGL near and far clip planes definition.
|
/// Creates a matrix for a perspective-view frustum based on the right handedness and OpenGL near and far clip planes definition.
|
||||||
///
|
///
|
||||||
/// # Important note
|
/// # Important note
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use na::{self, Real, U3};
|
use na::{self, Real, U3};
|
||||||
|
|
||||||
use aliases::{TVec2, TVec3, TVec4, TMat4};
|
use aliases::{TMat4, TVec2, TVec3, TVec4};
|
||||||
|
|
||||||
/// Define a picking region.
|
/// Define a picking region.
|
||||||
///
|
///
|
||||||
@ -13,11 +13,15 @@ pub fn pick_matrix<N: Real>(center: &TVec2<N>, delta: &TVec2<N>, viewport: &TVec
|
|||||||
let shift = TVec3::new(
|
let shift = TVec3::new(
|
||||||
(viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x,
|
(viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x,
|
||||||
(viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y,
|
(viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y,
|
||||||
N::zero()
|
N::zero(),
|
||||||
);
|
);
|
||||||
|
|
||||||
let result = TMat4::new_translation(&shift);
|
let result = TMat4::new_translation(&shift);
|
||||||
result.prepend_nonuniform_scaling(&TVec3::new(viewport.z / delta.x, viewport.w / delta.y, N::one()))
|
result.prepend_nonuniform_scaling(&TVec3::new(
|
||||||
|
viewport.z / delta.x,
|
||||||
|
viewport.w / delta.y,
|
||||||
|
N::one(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Map the specified object coordinates `(obj.x, obj.y, obj.z)` into window coordinates using OpenGL near and far clip planes definition.
|
/// Map the specified object coordinates `(obj.x, obj.y, obj.z)` into window coordinates using OpenGL near and far clip planes definition.
|
||||||
@ -36,7 +40,13 @@ pub fn pick_matrix<N: Real>(center: &TVec2<N>, delta: &TVec2<N>, viewport: &TVec
|
|||||||
/// * [`unproject`](fn.unproject.html)
|
/// * [`unproject`](fn.unproject.html)
|
||||||
/// * [`unproject_no`](fn.unproject_no.html)
|
/// * [`unproject_no`](fn.unproject_no.html)
|
||||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||||
pub fn project<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
pub fn project<N: Real>(
|
||||||
|
obj: &TVec3<N>,
|
||||||
|
model: &TMat4<N>,
|
||||||
|
proj: &TMat4<N>,
|
||||||
|
viewport: TVec4<N>,
|
||||||
|
) -> TVec3<N>
|
||||||
|
{
|
||||||
project_no(obj, model, proj, viewport)
|
project_no(obj, model, proj, viewport)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +68,13 @@ pub fn project<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewp
|
|||||||
/// * [`unproject`](fn.unproject.html)
|
/// * [`unproject`](fn.unproject.html)
|
||||||
/// * [`unproject_no`](fn.unproject_no.html)
|
/// * [`unproject_no`](fn.unproject_no.html)
|
||||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||||
pub fn project_no<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
pub fn project_no<N: Real>(
|
||||||
|
obj: &TVec3<N>,
|
||||||
|
model: &TMat4<N>,
|
||||||
|
proj: &TMat4<N>,
|
||||||
|
viewport: TVec4<N>,
|
||||||
|
) -> TVec3<N>
|
||||||
|
{
|
||||||
let proj = project_zo(obj, model, proj, viewport);
|
let proj = project_zo(obj, model, proj, viewport);
|
||||||
TVec3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5))
|
TVec3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5))
|
||||||
}
|
}
|
||||||
@ -81,7 +97,13 @@ pub fn project_no<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, vi
|
|||||||
/// * [`unproject`](fn.unproject.html)
|
/// * [`unproject`](fn.unproject.html)
|
||||||
/// * [`unproject_no`](fn.unproject_no.html)
|
/// * [`unproject_no`](fn.unproject_no.html)
|
||||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||||
pub fn project_zo<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
pub fn project_zo<N: Real>(
|
||||||
|
obj: &TVec3<N>,
|
||||||
|
model: &TMat4<N>,
|
||||||
|
proj: &TMat4<N>,
|
||||||
|
viewport: TVec4<N>,
|
||||||
|
) -> TVec3<N>
|
||||||
|
{
|
||||||
let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one());
|
let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one());
|
||||||
let scale = N::one() / normalized.w;
|
let scale = N::one() / normalized.w;
|
||||||
|
|
||||||
@ -108,7 +130,13 @@ pub fn project_zo<N: Real>(obj: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, vi
|
|||||||
/// * [`project_zo`](fn.project_zo.html)
|
/// * [`project_zo`](fn.project_zo.html)
|
||||||
/// * [`unproject_no`](fn.unproject_no.html)
|
/// * [`unproject_no`](fn.unproject_no.html)
|
||||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||||
pub fn unproject<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
pub fn unproject<N: Real>(
|
||||||
|
win: &TVec3<N>,
|
||||||
|
model: &TMat4<N>,
|
||||||
|
proj: &TMat4<N>,
|
||||||
|
viewport: TVec4<N>,
|
||||||
|
) -> TVec3<N>
|
||||||
|
{
|
||||||
unproject_no(win, model, proj, viewport)
|
unproject_no(win, model, proj, viewport)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,7 +158,13 @@ pub fn unproject<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, vie
|
|||||||
/// * [`project_zo`](fn.project_zo.html)
|
/// * [`project_zo`](fn.project_zo.html)
|
||||||
/// * [`unproject`](fn.unproject.html)
|
/// * [`unproject`](fn.unproject.html)
|
||||||
/// * [`unproject_zo`](fn.unproject_zo.html)
|
/// * [`unproject_zo`](fn.unproject_zo.html)
|
||||||
pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
pub fn unproject_no<N: Real>(
|
||||||
|
win: &TVec3<N>,
|
||||||
|
model: &TMat4<N>,
|
||||||
|
proj: &TMat4<N>,
|
||||||
|
viewport: TVec4<N>,
|
||||||
|
) -> TVec3<N>
|
||||||
|
{
|
||||||
let _2: N = na::convert(2.0);
|
let _2: N = na::convert(2.0);
|
||||||
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
||||||
let pt = TVec4::new(
|
let pt = TVec4::new(
|
||||||
@ -162,7 +196,13 @@ pub fn unproject_no<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>,
|
|||||||
/// * [`project_zo`](fn.project_zo.html)
|
/// * [`project_zo`](fn.project_zo.html)
|
||||||
/// * [`unproject`](fn.unproject.html)
|
/// * [`unproject`](fn.unproject.html)
|
||||||
/// * [`unproject_no`](fn.unproject_no.html)
|
/// * [`unproject_no`](fn.unproject_no.html)
|
||||||
pub fn unproject_zo<N: Real>(win: &TVec3<N>, model: &TMat4<N>, proj: &TMat4<N>, viewport: TVec4<N>) -> TVec3<N> {
|
pub fn unproject_zo<N: Real>(
|
||||||
|
win: &TVec3<N>,
|
||||||
|
model: &TMat4<N>,
|
||||||
|
proj: &TMat4<N>,
|
||||||
|
viewport: TVec4<N>,
|
||||||
|
) -> TVec3<N>
|
||||||
|
{
|
||||||
let _2: N = na::convert(2.0);
|
let _2: N = na::convert(2.0);
|
||||||
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros);
|
||||||
let pt = TVec4::new(
|
let pt = TVec4::new(
|
||||||
|
@ -1,13 +1,18 @@
|
|||||||
use na::DefaultAllocator;
|
use na::DefaultAllocator;
|
||||||
|
|
||||||
use aliases::{TVec, TMat};
|
use aliases::{TMat, TVec};
|
||||||
use traits::{Alloc, Number, Dimension};
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// Perform a component-wise equal-to comparison of two matrices.
|
/// 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.
|
/// 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: &TMat<N, R, C>, y: &TMat<N, R, C>) -> TVec<bool, C>
|
pub fn equal_columns<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
x: &TMat<N, R, C>,
|
||||||
|
y: &TMat<N, R, C>,
|
||||||
|
) -> TVec<bool, C>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Alloc<N, R, C>,
|
||||||
|
{
|
||||||
let mut res = TVec::<_, C>::repeat(false);
|
let mut res = TVec::<_, C>::repeat(false);
|
||||||
|
|
||||||
for i in 0..C::dim() {
|
for i in 0..C::dim() {
|
||||||
@ -20,16 +25,28 @@ pub fn equal_columns<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C>, y
|
|||||||
/// Returns the component-wise comparison of `|x - y| < epsilon`.
|
/// Returns the component-wise comparison of `|x - y| < epsilon`.
|
||||||
///
|
///
|
||||||
/// True if this expression is satisfied.
|
/// True if this expression is satisfied.
|
||||||
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>
|
pub fn equal_columns_eps<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
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, &TVec::<_, 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`.
|
/// Returns the component-wise comparison on each matrix column `|x - y| < epsilon`.
|
||||||
///
|
///
|
||||||
/// True if this expression is satisfied.
|
/// True if this expression is satisfied.
|
||||||
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>
|
pub fn equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
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 = TVec::<_, C>::repeat(false);
|
let mut res = TVec::<_, C>::repeat(false);
|
||||||
|
|
||||||
for i in 0..C::dim() {
|
for i in 0..C::dim() {
|
||||||
@ -42,8 +59,13 @@ pub fn equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(x: &TMat<N,
|
|||||||
/// Perform a component-wise not-equal-to comparison of two matrices.
|
/// 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.
|
/// 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: &TMat<N, R, C>, y: &TMat<N, R, C>) -> TVec<bool, C>
|
pub fn not_equal_columns<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
x: &TMat<N, R, C>,
|
||||||
|
y: &TMat<N, R, C>,
|
||||||
|
) -> TVec<bool, C>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Alloc<N, R, C>,
|
||||||
|
{
|
||||||
let mut res = TVec::<_, C>::repeat(false);
|
let mut res = TVec::<_, C>::repeat(false);
|
||||||
|
|
||||||
for i in 0..C::dim() {
|
for i in 0..C::dim() {
|
||||||
@ -56,16 +78,28 @@ pub fn not_equal_columns<N: Number, R: Dimension, C: Dimension>(x: &TMat<N, R, C
|
|||||||
/// Returns the component-wise comparison of `|x - y| < epsilon`.
|
/// Returns the component-wise comparison of `|x - y| < epsilon`.
|
||||||
///
|
///
|
||||||
/// True if this expression is not satisfied.
|
/// True if this expression is not satisfied.
|
||||||
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>
|
pub fn not_equal_columns_eps<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
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, &TVec::<_, C>::repeat(epsilon))
|
not_equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the component-wise comparison of `|x - y| >= epsilon`.
|
/// Returns the component-wise comparison of `|x - y| >= epsilon`.
|
||||||
///
|
///
|
||||||
/// True if this expression is not satisfied.
|
/// True if this expression is not satisfied.
|
||||||
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>
|
pub fn not_equal_columns_eps_vec<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
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 = TVec::<_, C>::repeat(false);
|
let mut res = TVec::<_, C>::repeat(false);
|
||||||
|
|
||||||
for i in 0..C::dim() {
|
for i in 0..C::dim() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{DefaultAllocator, Real, Unit, Rotation3, Point3};
|
use na::{DefaultAllocator, Point3, Real, Rotation3, Unit};
|
||||||
|
|
||||||
use traits::{Dimension, Number, Alloc};
|
use aliases::{TMat, TMat4, TVec, TVec3};
|
||||||
use aliases::{TMat, TVec, TVec3, TMat4};
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// The identity matrix.
|
/// The identity matrix.
|
||||||
pub fn identity<N: Number, D: Dimension>() -> TMat<N, D, D>
|
pub fn identity<N: Number, D: Dimension>() -> TMat<N, D, D>
|
||||||
@ -38,7 +38,11 @@ pub fn look_at<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMa
|
|||||||
/// * [`look_at`](fn.look_at.html)
|
/// * [`look_at`](fn.look_at.html)
|
||||||
/// * [`look_at_rh`](fn.look_at_rh.html)
|
/// * [`look_at_rh`](fn.look_at_rh.html)
|
||||||
pub fn look_at_lh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
pub fn look_at_lh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||||
TMat::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.
|
/// Build a right handed look at view matrix.
|
||||||
@ -54,7 +58,11 @@ pub fn look_at_lh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) ->
|
|||||||
/// * [`look_at`](fn.look_at.html)
|
/// * [`look_at`](fn.look_at.html)
|
||||||
/// * [`look_at_lh`](fn.look_at_lh.html)
|
/// * [`look_at_lh`](fn.look_at_lh.html)
|
||||||
pub fn look_at_rh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
pub fn look_at_rh<N: Real>(eye: &TVec3<N>, center: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||||
TMat::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`.
|
/// Builds a rotation 4 * 4 matrix created from an axis vector and an angle and right-multiply it to `m`.
|
||||||
|
@ -1,30 +1,41 @@
|
|||||||
//! (Reexported) Additional features not specified by GLSL specification
|
//! (Reexported) Additional features not specified by GLSL specification
|
||||||
|
|
||||||
pub use self::matrix_clip_space::{ortho, perspective};
|
pub use self::matrix_clip_space::{ortho, perspective};
|
||||||
pub use self::matrix_projection::{pick_matrix, project, project_no, project_zo, unproject, unproject_no, unproject_zo};
|
pub use self::matrix_projection::{
|
||||||
pub use self::matrix_relationnal::{equal_columns, equal_columns_eps, equal_columns_eps_vec, not_equal_columns, not_equal_columns_eps, not_equal_columns_eps_vec};
|
pick_matrix, project, project_no, project_zo, unproject, unproject_no, unproject_zo,
|
||||||
pub use self::matrix_transform::{identity, look_at, look_at_lh, rotate, scale, look_at_rh, translate, rotate_x, rotate_y, rotate_z};
|
};
|
||||||
|
pub use self::matrix_relationnal::{
|
||||||
|
equal_columns, equal_columns_eps, equal_columns_eps_vec, not_equal_columns,
|
||||||
|
not_equal_columns_eps, not_equal_columns_eps_vec,
|
||||||
|
};
|
||||||
|
pub use self::matrix_transform::{
|
||||||
|
identity, look_at, look_at_lh, look_at_rh, rotate, rotate_x, rotate_y, rotate_z, scale,
|
||||||
|
translate,
|
||||||
|
};
|
||||||
|
pub use self::quaternion_common::{quat_conjugate, quat_inverse, quat_lerp, quat_slerp};
|
||||||
|
pub use self::quaternion_geometric::{
|
||||||
|
quat_cross, quat_dot, quat_length, quat_magnitude, quat_normalize,
|
||||||
|
};
|
||||||
|
pub use self::quaternion_relational::{
|
||||||
|
quat_equal, quat_equal_eps, quat_not_equal, quat_not_equal_eps,
|
||||||
|
};
|
||||||
|
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::{max3_scalar, max4_scalar, min3_scalar, min4_scalar};
|
||||||
pub use self::scalar_constants::{epsilon, pi};
|
pub use self::scalar_constants::{epsilon, pi};
|
||||||
pub use self::vector_common::{max, max2, max3, max4, min, min2, min3, min4};
|
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};
|
pub use self::vector_relational::{equal_eps, equal_eps_vec, not_equal_eps, not_equal_eps_vec};
|
||||||
pub use self::quaternion_common::{quat_conjugate, quat_inverse, quat_lerp, quat_slerp};
|
|
||||||
pub use self::quaternion_geometric::{quat_cross, quat_dot, quat_length, quat_magnitude, quat_normalize};
|
|
||||||
pub use self::quaternion_relational::{quat_equal, quat_equal_eps, quat_not_equal, quat_not_equal_eps};
|
|
||||||
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};
|
|
||||||
|
|
||||||
|
|
||||||
mod matrix_clip_space;
|
mod matrix_clip_space;
|
||||||
mod matrix_projection;
|
mod matrix_projection;
|
||||||
mod matrix_relationnal;
|
mod matrix_relationnal;
|
||||||
mod matrix_transform;
|
mod matrix_transform;
|
||||||
mod scalar_common;
|
|
||||||
mod scalar_constants;
|
|
||||||
mod vector_common;
|
|
||||||
mod vector_relational;
|
|
||||||
mod quaternion_common;
|
mod quaternion_common;
|
||||||
mod quaternion_geometric;
|
mod quaternion_geometric;
|
||||||
mod quaternion_relational;
|
mod quaternion_relational;
|
||||||
mod quaternion_transform;
|
mod quaternion_transform;
|
||||||
mod quaternion_trigonometric;
|
mod quaternion_trigonometric;
|
||||||
|
mod scalar_common;
|
||||||
|
mod scalar_constants;
|
||||||
|
mod vector_common;
|
||||||
|
mod vector_relational;
|
||||||
|
@ -31,5 +31,7 @@ pub fn quat_lerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
|||||||
|
|
||||||
/// Interpolate spherically between `x` and `y`.
|
/// Interpolate spherically between `x` and `y`.
|
||||||
pub fn quat_slerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
pub fn quat_slerp<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap()
|
Unit::new_normalize(*x)
|
||||||
|
.slerp(&Unit::new_normalize(*y), a)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use na::{Real, U4};
|
use na::{Real, U4};
|
||||||
|
|
||||||
|
|
||||||
use aliases::{Qua, TVec};
|
use aliases::{Qua, TVec};
|
||||||
|
|
||||||
/// Component-wise equality comparison between two quaternions.
|
/// Component-wise equality comparison between two quaternions.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use na::{Real, UnitQuaternion, Unit};
|
use na::{Real, Unit, UnitQuaternion};
|
||||||
|
|
||||||
use aliases::{Qua, TVec3};
|
use aliases::{Qua, TVec3};
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{self, DefaultAllocator};
|
use na::{self, DefaultAllocator};
|
||||||
|
|
||||||
use traits::{Alloc, Number, Dimension};
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// Component-wise maximum between a vector and a scalar.
|
/// Component-wise maximum between a vector and a scalar.
|
||||||
///
|
///
|
||||||
@ -70,8 +70,15 @@ pub fn max3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N,
|
|||||||
/// * [`min2`](fn.min2.html)
|
/// * [`min2`](fn.min2.html)
|
||||||
/// * [`min3`](fn.min3.html)
|
/// * [`min3`](fn.min3.html)
|
||||||
/// * [`min4`](fn.min4.html)
|
/// * [`min4`](fn.min4.html)
|
||||||
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>
|
pub fn max4<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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))
|
max2(&max2(a, b), &max2(c, d))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +149,14 @@ pub fn min3<N: Number, D: Dimension>(a: &TVec<N, D>, b: &TVec<N, D>, c: &TVec<N,
|
|||||||
/// * [`min`](fn.min.html)
|
/// * [`min`](fn.min.html)
|
||||||
/// * [`min2`](fn.min2.html)
|
/// * [`min2`](fn.min2.html)
|
||||||
/// * [`min3`](fn.min3.html)
|
/// * [`min3`](fn.min3.html)
|
||||||
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>
|
pub fn min4<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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))
|
min2(&min2(a, b), &min2(c, d))
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{DefaultAllocator};
|
use na::DefaultAllocator;
|
||||||
|
|
||||||
use traits::{Alloc, Number, Dimension};
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// Component-wise approximate equality of two vectors, using a scalar epsilon.
|
/// Component-wise approximate equality of two vectors, using a scalar epsilon.
|
||||||
///
|
///
|
||||||
@ -10,8 +10,14 @@ use aliases::TVec;
|
|||||||
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
||||||
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
||||||
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
||||||
pub fn equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
pub fn equal_eps<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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))
|
x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,8 +28,14 @@ pub fn equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilo
|
|||||||
/// * [`equal_eps`](fn.equal_eps.html)
|
/// * [`equal_eps`](fn.equal_eps.html)
|
||||||
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
||||||
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
||||||
pub fn equal_eps_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: &TVec<N, D>) -> TVec<bool, D>
|
pub fn equal_eps_vec<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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))
|
x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_eq!(x, y, epsilon = eps))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,8 +46,14 @@ pub fn equal_eps_vec<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, ep
|
|||||||
/// * [`equal_eps`](fn.equal_eps.html)
|
/// * [`equal_eps`](fn.equal_eps.html)
|
||||||
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
||||||
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
/// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html)
|
||||||
pub fn not_equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, epsilon: N) -> TVec<bool, D>
|
pub fn not_equal_eps<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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))
|
x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +64,13 @@ pub fn not_equal_eps<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>, ep
|
|||||||
/// * [`equal_eps`](fn.equal_eps.html)
|
/// * [`equal_eps`](fn.equal_eps.html)
|
||||||
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
/// * [`equal_eps_vec`](fn.equal_eps_vec.html)
|
||||||
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
/// * [`not_equal_eps`](fn.not_equal_eps.html)
|
||||||
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>
|
pub fn not_equal_eps_vec<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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))
|
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 na::{DefaultAllocator, Real};
|
||||||
|
|
||||||
use traits::{Number, Alloc, Dimension};
|
|
||||||
use aliases::{TVec, TVec3};
|
use aliases::{TVec, TVec3};
|
||||||
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// The cross product of two vectors.
|
/// The cross product of two vectors.
|
||||||
pub fn cross<N: Number, D: Dimension>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
|
pub fn cross<N: Number, D: Dimension>(x: &TVec3<N>, y: &TVec3<N>) -> TVec3<N> {
|
||||||
@ -25,8 +25,14 @@ pub fn dot<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// If `dot(nref, i) < 0.0`, return `n`, otherwise, return `-n`.
|
/// If `dot(nref, i) < 0.0`, return `n`, otherwise, return `-n`.
|
||||||
pub fn faceforward<N: Number, D: Dimension>(n: &TVec<N, D>, i: &TVec<N, D>, nref: &TVec<N, D>) -> TVec<N, D>
|
pub fn faceforward<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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() {
|
if nref.dot(i) < N::zero() {
|
||||||
n.clone()
|
n.clone()
|
||||||
} else {
|
} else {
|
||||||
@ -78,14 +84,12 @@ pub fn reflect_vec<N: Number, D: Dimension>(i: &TVec<N, D>, n: &TVec<N, D>) -> T
|
|||||||
/// For the incident vector `i` and surface normal `n`, and the ratio of indices of refraction `eta`, return the refraction vector.
|
/// 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: &TVec<N, D>, n: &TVec<N, D>, eta: N) -> TVec<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> {
|
where DefaultAllocator: Alloc<N, D> {
|
||||||
|
|
||||||
let ni = n.dot(i);
|
let ni = n.dot(i);
|
||||||
let k = N::one() - eta * eta * (N::one() - ni * ni);
|
let k = N::one() - eta * eta * (N::one() - ni * ni);
|
||||||
|
|
||||||
if k < N::zero() {
|
if k < N::zero() {
|
||||||
TVec::<_, D>::zeros()
|
TVec::<_, D>::zeros()
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
i * eta - n * (eta * dot(n, i) + k.sqrt())
|
i * eta - n * (eta * dot(n, i) + k.sqrt())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Scalar, DefaultAllocator};
|
use na::{DefaultAllocator, Scalar};
|
||||||
|
|
||||||
|
use aliases::{TMat, TVec};
|
||||||
use traits::{Alloc, Dimension};
|
use traits::{Alloc, Dimension};
|
||||||
use aliases::{TVec, TMat};
|
|
||||||
|
|
||||||
/// The `index`-th column of the matrix `m`.
|
/// The `index`-th column of the matrix `m`.
|
||||||
///
|
///
|
||||||
@ -10,8 +10,13 @@ use aliases::{TVec, TMat};
|
|||||||
/// * [`row`](fn.row.html)
|
/// * [`row`](fn.row.html)
|
||||||
/// * [`set_column`](fn.set_column.html)
|
/// * [`set_column`](fn.set_column.html)
|
||||||
/// * [`set_row`](fn.set_row.html)
|
/// * [`set_row`](fn.set_row.html)
|
||||||
pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usize) -> TVec<N, R>
|
pub fn column<N: Scalar, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
m: &TMat<N, R, C>,
|
||||||
|
index: usize,
|
||||||
|
) -> TVec<N, R>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Alloc<N, R, C>,
|
||||||
|
{
|
||||||
m.column(index).into_owned()
|
m.column(index).into_owned()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,8 +27,14 @@ pub fn column<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: u
|
|||||||
/// * [`column`](fn.column.html)
|
/// * [`column`](fn.column.html)
|
||||||
/// * [`row`](fn.row.html)
|
/// * [`row`](fn.row.html)
|
||||||
/// * [`set_row`](fn.set_row.html)
|
/// * [`set_row`](fn.set_row.html)
|
||||||
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>
|
pub fn set_column<N: Scalar, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
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();
|
let mut res = m.clone();
|
||||||
res.set_column(index, x);
|
res.set_column(index, x);
|
||||||
res
|
res
|
||||||
@ -48,8 +59,14 @@ pub fn row<N: Scalar, R: Dimension, C: Dimension>(m: &TMat<N, R, C>, index: usiz
|
|||||||
/// * [`column`](fn.column.html)
|
/// * [`column`](fn.column.html)
|
||||||
/// * [`row`](fn.row.html)
|
/// * [`row`](fn.row.html)
|
||||||
/// * [`set_column`](fn.set_column.html)
|
/// * [`set_column`](fn.set_column.html)
|
||||||
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>
|
pub fn set_row<N: Scalar, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
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();
|
let mut res = m.clone();
|
||||||
res.set_row(index, &x.transpose());
|
res.set_row(index, &x.transpose());
|
||||||
res
|
res
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Real, DefaultAllocator};
|
use na::{DefaultAllocator, Real};
|
||||||
|
|
||||||
use traits::{Alloc, Dimension};
|
|
||||||
use aliases::TMat;
|
use aliases::TMat;
|
||||||
|
use traits::{Alloc, Dimension};
|
||||||
|
|
||||||
/// Fast matrix inverse for affine matrix.
|
/// Fast matrix inverse for affine matrix.
|
||||||
pub fn affine_inverse<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
|
pub fn affine_inverse<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
|
||||||
@ -13,5 +13,7 @@ pub fn affine_inverse<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<N, D, D>
|
|||||||
/// Compute the transpose of the inverse of a matrix.
|
/// Compute the transpose of the inverse of a matrix.
|
||||||
pub fn inverse_transpose<N: Real, D: Dimension>(m: TMat<N, D, D>) -> TMat<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> {
|
where DefaultAllocator: Alloc<N, D, D> {
|
||||||
m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros).transpose()
|
m.try_inverse()
|
||||||
|
.unwrap_or_else(TMat::<_, D, D>::zeros)
|
||||||
|
.transpose()
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,32 @@
|
|||||||
//! (Reexported) Recommended features not specified by GLSL specification
|
//! (Reexported) Recommended features not specified by GLSL specification
|
||||||
|
|
||||||
//pub use self::bitfield::*;
|
//pub use self::bitfield::*;
|
||||||
pub use self::constants::{e, two_pi, euler, four_over_pi, golden_ratio, half_pi, ln_ln_two, ln_ten, ln_two, one, one_over_pi, one_over_root_two, one_over_two_pi, quarter_pi, root_five, root_half_pi, root_ln_four, root_pi, root_three, root_two, root_two_pi, third, three_over_two_pi, two_over_pi, two_over_root_pi, two_thirds, zero};
|
pub use self::constants::{
|
||||||
|
e, euler, four_over_pi, golden_ratio, half_pi, ln_ln_two, ln_ten, ln_two, one, one_over_pi,
|
||||||
|
one_over_root_two, one_over_two_pi, quarter_pi, root_five, root_half_pi, root_ln_four, root_pi,
|
||||||
|
root_three, root_two, root_two_pi, third, three_over_two_pi, two_over_pi, two_over_root_pi,
|
||||||
|
two_pi, two_thirds, zero,
|
||||||
|
};
|
||||||
//pub use self::integer::*;
|
//pub use self::integer::*;
|
||||||
pub use self::matrix_access::{column, row, set_column, set_row};
|
pub use self::matrix_access::{column, row, set_column, set_row};
|
||||||
pub use self::matrix_inverse::{affine_inverse, inverse_transpose};
|
pub use self::matrix_inverse::{affine_inverse, inverse_transpose};
|
||||||
//pub use self::packing::*;
|
//pub use self::packing::*;
|
||||||
//pub use self::reciprocal::*;
|
//pub use self::reciprocal::*;
|
||||||
//pub use self::round::*;
|
//pub use self::round::*;
|
||||||
pub use self::type_ptr::{make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3, make_mat3x2, make_mat3x3, make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4, make_quat, make_vec1, make_vec2, make_vec3, make_vec4, value_ptr, value_ptr_mut, vec1_to_vec2, vec1_to_vec3, vec1_to_vec4, vec2_to_vec1, vec2_to_vec2, vec2_to_vec3, vec2_to_vec4, vec3_to_vec1, vec3_to_vec2, vec3_to_vec3, vec3_to_vec4, vec4_to_vec1, vec4_to_vec2, vec4_to_vec3, vec4_to_vec4, mat2_to_mat3, mat2_to_mat4, mat3_to_mat2, mat3_to_mat4, mat4_to_mat2, mat4_to_mat3};
|
pub use self::type_ptr::{
|
||||||
|
make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3, make_mat3x2, make_mat3x3,
|
||||||
|
make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4, make_quat, make_vec1, make_vec2,
|
||||||
|
make_vec3, make_vec4, mat2_to_mat3, mat2_to_mat4, mat3_to_mat2, mat3_to_mat4, mat4_to_mat2,
|
||||||
|
mat4_to_mat3, value_ptr, value_ptr_mut, vec1_to_vec2, vec1_to_vec3, vec1_to_vec4, vec2_to_vec1,
|
||||||
|
vec2_to_vec2, vec2_to_vec3, vec2_to_vec4, vec3_to_vec1, vec3_to_vec2, vec3_to_vec3,
|
||||||
|
vec3_to_vec4, vec4_to_vec1, vec4_to_vec2, vec4_to_vec3, vec4_to_vec4,
|
||||||
|
};
|
||||||
//pub use self::ulp::*;
|
//pub use self::ulp::*;
|
||||||
pub use self::quaternion::{quat_cast, quat_euler_angles, quat_greater_than, quat_greater_than_equal, quat_less_than, quat_less_than_equal, quat_look_at, quat_look_at_lh, quat_look_at_rh, quat_pitch, quat_roll, quat_yaw};
|
pub use self::quaternion::{
|
||||||
|
quat_cast, quat_euler_angles, quat_greater_than, quat_greater_than_equal, quat_less_than,
|
||||||
|
quat_less_than_equal, quat_look_at, quat_look_at_lh, quat_look_at_rh, quat_pitch, quat_roll,
|
||||||
|
quat_yaw,
|
||||||
|
};
|
||||||
|
|
||||||
//mod bitfield;
|
//mod bitfield;
|
||||||
mod constants;
|
mod constants;
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
use na::{Real, U4, UnitQuaternion};
|
use na::{Real, UnitQuaternion, U4};
|
||||||
|
|
||||||
use aliases::{Qua, TVec, TVec3, TMat4};
|
|
||||||
|
|
||||||
|
use aliases::{Qua, TMat4, TVec, TVec3};
|
||||||
|
|
||||||
/// Euler angles of the quaternion `q` as (pitch, yaw, roll).
|
/// Euler angles of the quaternion `q` as (pitch, yaw, roll).
|
||||||
pub fn quat_euler_angles<N: Real>(x: &Qua<N>) -> TVec3<N> {
|
pub fn quat_euler_angles<N: Real>(x: &Qua<N>) -> TVec3<N> {
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
use na::{Scalar, Real, DefaultAllocator, Quaternion};
|
use na::{DefaultAllocator, Quaternion, Real, Scalar};
|
||||||
|
|
||||||
use traits::{Number, Alloc, Dimension};
|
use aliases::{
|
||||||
use aliases::{Qua, TMat, TMat2, TMat3, TMat4, TVec1, TVec2, TVec3, TVec4,
|
Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1,
|
||||||
TMat2x3, TMat2x4, TMat3x2, TMat3x4, TMat4x2, TMat4x3};
|
TVec2, TVec3, TVec4,
|
||||||
|
};
|
||||||
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// Creates a 2x2 matrix from a slice arranged in column-major order.
|
/// Creates a 2x2 matrix from a slice arranged in column-major order.
|
||||||
pub fn make_mat2<N: Scalar>(ptr: &[N]) -> TMat2<N> {
|
pub fn make_mat2<N: Scalar>(ptr: &[N]) -> TMat2<N> {
|
||||||
@ -69,19 +71,12 @@ pub fn mat2_to_mat3<N: Number>(m: &TMat2<N>) -> TMat3<N> {
|
|||||||
let _0 = N::zero();
|
let _0 = N::zero();
|
||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
|
|
||||||
TMat3::new(
|
TMat3::new(m.m11, m.m12, _0, m.m21, m.m22, _0, _0, _0, _1)
|
||||||
m.m11, m.m12, _0,
|
|
||||||
m.m21, m.m22, _0,
|
|
||||||
_0, _0, _1
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a 3x3 matrix to a 2x2 matrix.
|
/// Converts a 3x3 matrix to a 2x2 matrix.
|
||||||
pub fn mat3_to_mat2<N: Scalar>(m: &TMat3<N>) -> TMat2<N> {
|
pub fn mat3_to_mat2<N: Scalar>(m: &TMat3<N>) -> TMat2<N> {
|
||||||
TMat2::new(
|
TMat2::new(m.m11, m.m12, m.m21, m.m22)
|
||||||
m.m11, m.m12,
|
|
||||||
m.m21, m.m22
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a 3x3 matrix to a 4x4 matrix.
|
/// Converts a 3x3 matrix to a 4x4 matrix.
|
||||||
@ -90,19 +85,14 @@ pub fn mat3_to_mat4<N: Number>(m: &TMat3<N>) -> TMat4<N> {
|
|||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
|
|
||||||
TMat4::new(
|
TMat4::new(
|
||||||
m.m11, m.m12, m.m13, _0,
|
m.m11, m.m12, m.m13, _0, m.m21, m.m22, m.m23, _0, m.m31, m.m32, m.m33, _0, _0, _0, _0, _1,
|
||||||
m.m21, m.m22, m.m23, _0,
|
|
||||||
m.m31, m.m32, m.m33, _0,
|
|
||||||
_0, _0, _0, _1,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a 4x4 matrix to a 3x3 matrix.
|
/// Converts a 4x4 matrix to a 3x3 matrix.
|
||||||
pub fn mat4_to_mat3<N: Scalar>(m: &TMat4<N>) -> TMat3<N> {
|
pub fn mat4_to_mat3<N: Scalar>(m: &TMat4<N>) -> TMat3<N> {
|
||||||
TMat3::new(
|
TMat3::new(
|
||||||
m.m11, m.m12, m.m13,
|
m.m11, m.m12, m.m13, m.m21, m.m22, m.m23, m.m31, m.m32, m.m33,
|
||||||
m.m21, m.m22, m.m23,
|
|
||||||
m.m31, m.m32, m.m33,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,19 +102,13 @@ pub fn mat2_to_mat4<N: Number>(m: &TMat2<N>) -> TMat4<N> {
|
|||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
|
|
||||||
TMat4::new(
|
TMat4::new(
|
||||||
m.m11, m.m12, _0, _0,
|
m.m11, m.m12, _0, _0, m.m21, m.m22, _0, _0, _0, _0, _1, _0, _0, _0, _0, _1,
|
||||||
m.m21, m.m22, _0, _0,
|
|
||||||
_0, _0, _1, _0,
|
|
||||||
_0, _0, _0, _1,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a 4x4 matrix to a 2x2 matrix.
|
/// Converts a 4x4 matrix to a 2x2 matrix.
|
||||||
pub fn mat4_to_mat2<N: Scalar>(m: &TMat4<N>) -> TMat2<N> {
|
pub fn mat4_to_mat2<N: Scalar>(m: &TMat4<N>) -> TMat2<N> {
|
||||||
TMat2::new(
|
TMat2::new(m.m11, m.m12, m.m21, m.m22)
|
||||||
m.m11, m.m12,
|
|
||||||
m.m21, m.m22,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a quaternion from a slice arranged as `[x, y, z, w]`.
|
/// Creates a quaternion from a slice arranged as `[x, y, z, w]`.
|
||||||
@ -409,4 +393,3 @@ pub fn value_ptr_mut<N: Scalar, R: Dimension, C: Dimension>(x: &mut TMat<N, R, C
|
|||||||
where DefaultAllocator: Alloc<N, R, C> {
|
where DefaultAllocator: Alloc<N, R, C> {
|
||||||
x.as_mut_slice()
|
x.as_mut_slice()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{self, DefaultAllocator};
|
use na::{self, DefaultAllocator};
|
||||||
|
|
||||||
use traits::{Number, Alloc, Dimension};
|
|
||||||
use aliases::TMat;
|
use aliases::TMat;
|
||||||
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// The sum of every component of the given matrix or vector.
|
/// The sum of every component of the given matrix or vector.
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use traits::Number;
|
|
||||||
use aliases::TVec2;
|
use aliases::TVec2;
|
||||||
|
use traits::Number;
|
||||||
|
|
||||||
/// The 2D perpendicular product between two vectors.
|
/// The 2D perpendicular product between two vectors.
|
||||||
pub fn cross2d<N: Number>(v: &TVec2<N>, u: &TVec2<N>) -> N {
|
pub fn cross2d<N: Number>(v: &TVec2<N>, u: &TVec2<N>) -> N {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use traits::Number;
|
|
||||||
use aliases::TVec3;
|
use aliases::TVec3;
|
||||||
|
use traits::Number;
|
||||||
|
|
||||||
/// Returns `true` if `{a, b, c}` forms a left-handed trihedron.
|
/// Returns `true` if `{a, b, c}` forms a left-handed trihedron.
|
||||||
///
|
///
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
use aliases::{
|
||||||
|
TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec2, TVec3, TVec4,
|
||||||
|
};
|
||||||
use traits::Number;
|
use traits::Number;
|
||||||
use aliases::{TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3};
|
|
||||||
|
|
||||||
/// Builds a 2x2 diagonal matrix.
|
/// Builds a 2x2 diagonal matrix.
|
||||||
///
|
///
|
||||||
|
@ -1,25 +1,37 @@
|
|||||||
//! (Reexported) Experimental features not specified by GLSL specification.
|
//! (Reexported) Experimental features not specified by GLSL specification.
|
||||||
|
|
||||||
|
|
||||||
pub use self::component_wise::{comp_add, comp_max, comp_min, comp_mul};
|
pub use self::component_wise::{comp_add, comp_max, comp_min, comp_mul};
|
||||||
//pub use self::euler_angles::*;
|
//pub use self::euler_angles::*;
|
||||||
pub use self::exterior_product::{cross2d};
|
pub use self::exterior_product::cross2d;
|
||||||
pub use self::handed_coordinate_space::{left_handed, right_handed};
|
pub use self::handed_coordinate_space::{left_handed, right_handed};
|
||||||
pub use self::matrix_cross_product::{matrix_cross, matrix_cross3};
|
pub use self::matrix_cross_product::{matrix_cross, matrix_cross3};
|
||||||
pub use self::matrix_operation::{diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4, diagonal4x2, diagonal4x3, diagonal4x4};
|
pub use self::matrix_operation::{
|
||||||
|
diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4, diagonal4x2,
|
||||||
|
diagonal4x3, diagonal4x4,
|
||||||
|
};
|
||||||
pub use self::norm::{distance2, l1_distance, l1_norm, l2_distance, l2_norm, length2, magnitude2};
|
pub use self::norm::{distance2, l1_distance, l1_norm, l2_distance, l2_norm, length2, magnitude2};
|
||||||
pub use self::normal::{triangle_normal};
|
pub use self::normal::triangle_normal;
|
||||||
pub use self::normalize_dot::{fast_normalize_dot, normalize_dot};
|
pub use self::normalize_dot::{fast_normalize_dot, normalize_dot};
|
||||||
|
pub use self::quaternion::{
|
||||||
|
mat3_to_quat, quat_cross_vec, quat_extract_real_component, quat_fast_mix, quat_identity,
|
||||||
|
quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_rotate_vec, quat_rotate_vec3,
|
||||||
|
quat_rotation, quat_short_mix, quat_to_mat3, quat_to_mat4, to_quat,
|
||||||
|
};
|
||||||
pub use self::rotate_normalized_axis::{quat_rotate_normalized_axis, rotate_normalized_axis};
|
pub use self::rotate_normalized_axis::{quat_rotate_normalized_axis, rotate_normalized_axis};
|
||||||
pub use self::rotate_vector::{orientation, rotate_vec2, rotate_vec3, rotate_vec4, rotate_x_vec4, rotate_x_vec3, rotate_y_vec4, rotate_y_vec3, rotate_z_vec4, rotate_z_vec3, slerp};
|
pub use self::rotate_vector::{
|
||||||
pub use self::transform::{rotation, scaling, translation, rotation2d, scaling2d, translation2d};
|
orientation, rotate_vec2, rotate_vec3, rotate_vec4, rotate_x_vec3, rotate_x_vec4,
|
||||||
pub use self::transform2::{proj, proj2d, reflect, reflect2d, scale_bias, scale_bias_matrix, shear2d_x, shear_x, shear_y, shear2d_y, shear_z};
|
rotate_y_vec3, rotate_y_vec4, rotate_z_vec3, rotate_z_vec4, slerp,
|
||||||
|
};
|
||||||
|
pub use self::transform::{rotation, rotation2d, scaling, scaling2d, translation, translation2d};
|
||||||
|
pub use self::transform2::{
|
||||||
|
proj, proj2d, reflect, reflect2d, scale_bias, scale_bias_matrix, shear2d_x, shear2d_y, shear_x,
|
||||||
|
shear_y, shear_z,
|
||||||
|
};
|
||||||
pub use self::transform2d::{rotate2d, scale2d, translate2d};
|
pub use self::transform2d::{rotate2d, scale2d, translate2d};
|
||||||
pub use self::vector_angle::{angle};
|
pub use self::vector_angle::angle;
|
||||||
pub use self::vector_query::{are_collinear, are_collinear2d, are_orthogonal, is_comp_null, is_normalized, is_null};
|
pub use self::vector_query::{
|
||||||
pub use self::quaternion::{quat_to_mat3, quat_rotate_vec, quat_cross_vec, mat3_to_quat, quat_extract_real_component, quat_fast_mix, quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_identity, quat_rotate_vec3, quat_rotation, quat_short_mix, quat_to_mat4, to_quat};
|
are_collinear, are_collinear2d, are_orthogonal, is_comp_null, is_normalized, is_null,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
mod component_wise;
|
mod component_wise;
|
||||||
//mod euler_angles;
|
//mod euler_angles;
|
||||||
@ -30,6 +42,7 @@ mod matrix_operation;
|
|||||||
mod norm;
|
mod norm;
|
||||||
mod normal;
|
mod normal;
|
||||||
mod normalize_dot;
|
mod normalize_dot;
|
||||||
|
mod quaternion;
|
||||||
mod rotate_normalized_axis;
|
mod rotate_normalized_axis;
|
||||||
mod rotate_vector;
|
mod rotate_vector;
|
||||||
mod transform;
|
mod transform;
|
||||||
@ -37,4 +50,3 @@ mod transform2;
|
|||||||
mod transform2d;
|
mod transform2d;
|
||||||
mod vector_angle;
|
mod vector_angle;
|
||||||
mod vector_query;
|
mod vector_query;
|
||||||
mod quaternion;
|
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Real, DefaultAllocator};
|
use na::{DefaultAllocator, Real};
|
||||||
|
|
||||||
use traits::{Alloc, Dimension};
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
|
use traits::{Alloc, Dimension};
|
||||||
|
|
||||||
/// The squared distance between two points.
|
/// The squared distance between two points.
|
||||||
///
|
///
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Real, DefaultAllocator};
|
use na::{DefaultAllocator, Real};
|
||||||
|
|
||||||
use traits::{Dimension, Alloc};
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
|
use traits::{Alloc, Dimension};
|
||||||
|
|
||||||
/// The dot product of the normalized version of `x` and `y`.
|
/// The dot product of the normalized version of `x` and `y`.
|
||||||
///
|
///
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use na::{Real, Unit, Rotation3, UnitQuaternion, U3};
|
use na::{Real, Rotation3, Unit, UnitQuaternion, U3};
|
||||||
|
|
||||||
use aliases::{Qua, TMat3, TMat4, TVec3, TVec4};
|
use aliases::{Qua, TMat3, TMat4, TVec3, TVec4};
|
||||||
|
|
||||||
@ -19,7 +19,9 @@ pub fn quat_extract_real_component<N: Real>(q: &Qua<N>) -> N {
|
|||||||
|
|
||||||
/// Normalized linear interpolation between two quaternions.
|
/// Normalized linear interpolation between two quaternions.
|
||||||
pub fn quat_fast_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
pub fn quat_fast_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
Unit::new_unchecked(*x).nlerp(&Unit::new_unchecked(*y), a).unwrap()
|
Unit::new_unchecked(*x)
|
||||||
|
.nlerp(&Unit::new_unchecked(*y), a)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn quat_intermediate<N: Real>(prev: &Qua<N>, curr: &Qua<N>, next: &Qua<N>) -> Qua<N> {
|
//pub fn quat_intermediate<N: Real>(prev: &Qua<N>, curr: &Qua<N>, next: &Qua<N>) -> Qua<N> {
|
||||||
@ -54,12 +56,16 @@ pub fn quat_rotate_vec<N: Real>(q: &Qua<N>, v: &TVec4<N>) -> TVec4<N> {
|
|||||||
|
|
||||||
/// The rotation required to align `orig` to `dest`.
|
/// The rotation required to align `orig` to `dest`.
|
||||||
pub fn quat_rotation<N: Real>(orig: &TVec3<N>, dest: &TVec3<N>) -> Qua<N> {
|
pub fn quat_rotation<N: Real>(orig: &TVec3<N>, dest: &TVec3<N>) -> Qua<N> {
|
||||||
UnitQuaternion::rotation_between(orig, dest).unwrap_or_else(UnitQuaternion::identity).unwrap()
|
UnitQuaternion::rotation_between(orig, dest)
|
||||||
|
.unwrap_or_else(UnitQuaternion::identity)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The spherical linear interpolation between two quaternions.
|
/// The spherical linear interpolation between two quaternions.
|
||||||
pub fn quat_short_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
pub fn quat_short_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
||||||
Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap()
|
Unit::new_normalize(*x)
|
||||||
|
.slerp(&Unit::new_normalize(*y), a)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
//pub fn quat_squad<N: Real>(q1: &Qua<N>, q2: &Qua<N>, s1: &Qua<N>, s2: &Qua<N>, h: N) -> Qua<N> {
|
//pub fn quat_squad<N: Real>(q1: &Qua<N>, q2: &Qua<N>, s1: &Qua<N>, s2: &Qua<N>, h: N) -> Qua<N> {
|
||||||
@ -68,7 +74,9 @@ pub fn quat_short_mix<N: Real>(x: &Qua<N>, y: &Qua<N>, a: N) -> Qua<N> {
|
|||||||
|
|
||||||
/// Converts a quaternion to a rotation matrix.
|
/// Converts a quaternion to a rotation matrix.
|
||||||
pub fn quat_to_mat3<N: Real>(x: &Qua<N>) -> TMat3<N> {
|
pub fn quat_to_mat3<N: Real>(x: &Qua<N>) -> TMat3<N> {
|
||||||
UnitQuaternion::new_unchecked(*x).to_rotation_matrix().unwrap()
|
UnitQuaternion::new_unchecked(*x)
|
||||||
|
.to_rotation_matrix()
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a quaternion to a rotation matrix in homogenous coordinates.
|
/// Converts a quaternion to a rotation matrix in homogenous coordinates.
|
||||||
@ -87,4 +95,3 @@ pub fn to_quat<N: Real>(x: &TMat4<N>) -> Qua<N> {
|
|||||||
let rot = x.fixed_slice::<U3, U3>(0, 0).into_owned();
|
let rot = x.fixed_slice::<U3, U3>(0, 0).into_owned();
|
||||||
mat3_to_quat(&rot)
|
mat3_to_quat(&rot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use na::{Real, Rotation3, Unit, UnitComplex};
|
use na::{Real, Rotation3, Unit, UnitComplex};
|
||||||
|
|
||||||
use aliases::{TVec2, TVec3, TVec4, TMat4};
|
use aliases::{TMat4, TVec2, TVec3, TVec4};
|
||||||
|
|
||||||
/// Build the rotation matrix needed to align `normal` and `up`.
|
/// Build the rotation matrix needed to align `normal` and `up`.
|
||||||
pub fn orientation<N: Real>(normal: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
pub fn orientation<N: Real>(normal: &TVec3<N>, up: &TVec3<N>) -> TMat4<N> {
|
||||||
@ -58,5 +58,7 @@ pub fn rotate_z_vec4<N: Real>(v: &TVec4<N>, angle: N) -> TVec4<N> {
|
|||||||
|
|
||||||
/// Computes a spherical linear interpolation between the vectors `x` and `y` assumed to be normalized.
|
/// Computes a spherical linear interpolation between the vectors `x` and `y` assumed to be normalized.
|
||||||
pub fn slerp<N: Real>(x: &TVec3<N>, y: &TVec3<N>, a: N) -> TVec3<N> {
|
pub fn slerp<N: Real>(x: &TVec3<N>, y: &TVec3<N>, a: N) -> TVec3<N> {
|
||||||
Unit::new_unchecked(*x).slerp(&Unit::new_unchecked(*y), a).unwrap()
|
Unit::new_unchecked(*x)
|
||||||
|
.slerp(&Unit::new_unchecked(*y), a)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Real, Unit, Rotation2, Rotation3};
|
use na::{Real, Rotation2, Rotation3, Unit};
|
||||||
|
|
||||||
|
use aliases::{TMat3, TMat4, TVec2, TVec3};
|
||||||
use traits::Number;
|
use traits::Number;
|
||||||
use aliases::{TVec3, TVec2, TMat3, TMat4};
|
|
||||||
|
|
||||||
/// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians.
|
/// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians.
|
||||||
///
|
///
|
||||||
@ -42,7 +42,6 @@ pub fn translation<N: Number>(v: &TVec3<N>) -> TMat4<N> {
|
|||||||
TMat4::new_translation(v)
|
TMat4::new_translation(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// A rotation 3 * 3 matrix created from an angle expressed in radians.
|
/// A rotation 3 * 3 matrix created from an angle expressed in radians.
|
||||||
///
|
///
|
||||||
/// # See also:
|
/// # See also:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{U2, U3};
|
use na::{U2, U3};
|
||||||
|
|
||||||
|
use aliases::{TMat3, TMat4, TVec2, TVec3};
|
||||||
use traits::Number;
|
use traits::Number;
|
||||||
use aliases::{TVec2, TVec3, TMat3, TMat4};
|
|
||||||
|
|
||||||
/// Build planar projection matrix along normal axis and right-multiply it to `m`.
|
/// Build planar projection matrix along normal axis and right-multiply it to `m`.
|
||||||
pub fn proj2d<N: Number>(m: &TMat3<N>, normal: &TVec2<N>) -> TMat3<N> {
|
pub fn proj2d<N: Number>(m: &TMat3<N>, normal: &TVec2<N>) -> TMat3<N> {
|
||||||
@ -57,10 +57,7 @@ pub fn scale_bias_matrix<N: Number>(scale: N, bias: N) -> TMat4<N> {
|
|||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
|
|
||||||
TMat4::new(
|
TMat4::new(
|
||||||
scale, _0, _0, bias,
|
scale, _0, _0, bias, _0, scale, _0, bias, _0, _0, scale, bias, _0, _0, _0, _1,
|
||||||
_0, scale, _0, bias,
|
|
||||||
_0, _0, scale, bias,
|
|
||||||
_0, _0, _0, _1,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,11 +71,7 @@ pub fn shear2d_x<N: Number>(m: &TMat3<N>, y: N) -> TMat3<N> {
|
|||||||
let _0 = N::zero();
|
let _0 = N::zero();
|
||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
|
|
||||||
let shear = TMat3::new(
|
let shear = TMat3::new(_1, y, _0, _0, _1, _0, _0, _0, _1);
|
||||||
_1, y, _0,
|
|
||||||
_0, _1, _0,
|
|
||||||
_0, _0, _1
|
|
||||||
);
|
|
||||||
m * shear
|
m * shear
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,12 +79,7 @@ pub fn shear2d_x<N: Number>(m: &TMat3<N>, y: N) -> TMat3<N> {
|
|||||||
pub fn shear_x<N: Number>(m: &TMat4<N>, y: N, z: N) -> TMat4<N> {
|
pub fn shear_x<N: Number>(m: &TMat4<N>, y: N, z: N) -> TMat4<N> {
|
||||||
let _0 = N::zero();
|
let _0 = N::zero();
|
||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
let shear = TMat4::new(
|
let shear = TMat4::new(_1, _0, _0, _0, y, _1, _0, _0, z, _0, _1, _0, _0, _0, _0, _1);
|
||||||
_1, _0, _0, _0,
|
|
||||||
y, _1, _0, _0,
|
|
||||||
z, _0, _1, _0,
|
|
||||||
_0, _0, _0, _1,
|
|
||||||
);
|
|
||||||
|
|
||||||
m * shear
|
m * shear
|
||||||
}
|
}
|
||||||
@ -101,11 +89,7 @@ pub fn shear2d_y<N: Number>(m: &TMat3<N>, x: N) -> TMat3<N> {
|
|||||||
let _0 = N::zero();
|
let _0 = N::zero();
|
||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
|
|
||||||
let shear = TMat3::new(
|
let shear = TMat3::new(_1, _0, _0, x, _1, _0, _0, _0, _1);
|
||||||
_1, _0, _0,
|
|
||||||
x, _1, _0,
|
|
||||||
_0, _0, _1
|
|
||||||
);
|
|
||||||
m * shear
|
m * shear
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,12 +97,7 @@ pub fn shear2d_y<N: Number>(m: &TMat3<N>, x: N) -> TMat3<N> {
|
|||||||
pub fn shear_y<N: Number>(m: &TMat4<N>, x: N, z: N) -> TMat4<N> {
|
pub fn shear_y<N: Number>(m: &TMat4<N>, x: N, z: N) -> TMat4<N> {
|
||||||
let _0 = N::zero();
|
let _0 = N::zero();
|
||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
let shear = TMat4::new(
|
let shear = TMat4::new(_1, x, _0, _0, _0, _1, _0, _0, _0, z, _1, _0, _0, _0, _0, _1);
|
||||||
_1, x, _0, _0,
|
|
||||||
_0, _1, _0, _0,
|
|
||||||
_0, z, _1, _0,
|
|
||||||
_0, _0, _0, _1,
|
|
||||||
);
|
|
||||||
|
|
||||||
m * shear
|
m * shear
|
||||||
}
|
}
|
||||||
@ -127,12 +106,7 @@ pub fn shear_y<N: Number>(m: &TMat4<N>, x: N, z: N) -> TMat4<N> {
|
|||||||
pub fn shear_z<N: Number>(m: &TMat4<N>, x: N, y: N) -> TMat4<N> {
|
pub fn shear_z<N: Number>(m: &TMat4<N>, x: N, y: N) -> TMat4<N> {
|
||||||
let _0 = N::zero();
|
let _0 = N::zero();
|
||||||
let _1 = N::one();
|
let _1 = N::one();
|
||||||
let shear = TMat4::new(
|
let shear = TMat4::new(_1, _0, x, _0, _0, _1, y, _0, _0, _0, _1, _0, _0, _0, _0, _1);
|
||||||
_1, _0, x, _0,
|
|
||||||
_0, _1, y, _0,
|
|
||||||
_0, _0, _1, _0,
|
|
||||||
_0, _0, _0, _1,
|
|
||||||
);
|
|
||||||
|
|
||||||
m * shear
|
m * shear
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Real, UnitComplex};
|
use na::{Real, UnitComplex};
|
||||||
|
|
||||||
use traits::Number;
|
|
||||||
use aliases::{TMat3, TVec2};
|
use aliases::{TMat3, TVec2};
|
||||||
|
use traits::Number;
|
||||||
|
|
||||||
/// Builds a 2D rotation matrix from an angle and right-multiply it to `m`.
|
/// Builds a 2D rotation matrix from an angle and right-multiply it to `m`.
|
||||||
///
|
///
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
use na::{DefaultAllocator, Real};
|
use na::{DefaultAllocator, Real};
|
||||||
|
|
||||||
use traits::{Dimension, Alloc};
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
|
use traits::{Alloc, Dimension};
|
||||||
|
|
||||||
/// The angle between two vectors.
|
/// The angle between two vectors.
|
||||||
pub fn angle<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
pub fn angle<N: Real, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> N
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Real, DefaultAllocator};
|
use na::{DefaultAllocator, Real};
|
||||||
|
|
||||||
use traits::{Number, Dimension, Alloc};
|
|
||||||
use aliases::{TVec, TVec2, TVec3};
|
use aliases::{TVec, TVec2, TVec3};
|
||||||
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// Returns `true` if two vectors are collinear (up to an epsilon).
|
/// Returns `true` if two vectors are collinear (up to an epsilon).
|
||||||
///
|
///
|
||||||
@ -22,8 +22,14 @@ 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).
|
/// Returns `true` if two vectors are orthogonal (up to an epsilon).
|
||||||
pub fn are_orthogonal<N: Number, D: Dimension>(v0: &TVec<N, D>, v1: &TVec<N, D>, epsilon: N) -> bool
|
pub fn are_orthogonal<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
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)
|
abs_diff_eq!(v0.dot(v1), N::zero(), epsilon = epsilon)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,68 +119,82 @@ extern crate alga;
|
|||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
pub use aliases::*;
|
pub use aliases::*;
|
||||||
|
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,
|
||||||
|
int_bits_to_float_vec, mix, modf, modf_vec, round, sign, smoothstep, step, step_scalar,
|
||||||
|
step_vec, trunc, uint_bits_to_float, uint_bits_to_float_scalar,
|
||||||
|
};
|
||||||
pub use constructors::*;
|
pub use constructors::*;
|
||||||
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, int_bits_to_float_vec, mix, modf, modf_vec, round, sign, smoothstep, step, step_scalar, step_vec, trunc, uint_bits_to_float, uint_bits_to_float_scalar};
|
|
||||||
pub use geometric::{reflect_vec, cross, distance, dot, faceforward, length, magnitude, normalize, refract_vec};
|
|
||||||
pub use matrix::{transpose, determinant, inverse, matrix_comp_mult, outer_product};
|
|
||||||
pub use traits::{Dimension, Number, Alloc};
|
|
||||||
pub use trigonometric::{acos, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, degrees, radians, sin, sinh, tan, tanh};
|
|
||||||
pub use vector_relational::{all, any, equal, greater_than, greater_than_equal, less_than, less_than_equal, not, not_equal};
|
|
||||||
pub use exponential::{exp, exp2, inversesqrt, log, log2, pow, sqrt};
|
pub use exponential::{exp, exp2, inversesqrt, log, log2, pow, sqrt};
|
||||||
|
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 traits::{Alloc, Dimension, Number};
|
||||||
|
pub use trigonometric::{
|
||||||
|
acos, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, degrees, radians, sin, sinh, tan, tanh,
|
||||||
|
};
|
||||||
|
pub use vector_relational::{
|
||||||
|
all, any, equal, greater_than, greater_than_equal, less_than, less_than_equal, not, not_equal,
|
||||||
|
};
|
||||||
|
|
||||||
pub use gtx::{
|
pub use ext::{
|
||||||
comp_add, comp_max, comp_min, comp_mul,
|
epsilon, equal_columns, equal_columns_eps, equal_columns_eps_vec, equal_eps, equal_eps_vec,
|
||||||
cross2d,
|
identity, look_at, look_at_lh, look_at_rh, max, max2, max3, max3_scalar, max4, max4_scalar,
|
||||||
left_handed, right_handed,
|
min, min2, min3, min3_scalar, min4, min4_scalar, not_equal_columns, not_equal_columns_eps,
|
||||||
matrix_cross, matrix_cross3,
|
not_equal_columns_eps_vec, not_equal_eps, not_equal_eps_vec, ortho, perspective, pi,
|
||||||
diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4, diagonal4x2, diagonal4x3, diagonal4x4,
|
pick_matrix, project, project_no, project_zo, quat_angle, quat_angle_axis, quat_axis,
|
||||||
distance2, l1_distance, l1_norm, l2_distance, l2_norm, length2, magnitude2,
|
quat_conjugate, quat_cross, quat_dot, quat_equal, quat_equal_eps, quat_exp, quat_inverse,
|
||||||
triangle_normal,
|
quat_length, quat_lerp, quat_log, quat_magnitude, quat_normalize, quat_not_equal,
|
||||||
fast_normalize_dot, normalize_dot,
|
quat_not_equal_eps, quat_pow, quat_rotate, quat_slerp, rotate, rotate_x, rotate_y, rotate_z,
|
||||||
quat_rotate_normalized_axis, rotate_normalized_axis,
|
scale, translate, unproject, unproject_no, unproject_zo,
|
||||||
orientation, rotate_vec2, rotate_vec3, rotate_vec4, rotate_x_vec4, rotate_x_vec3, rotate_y_vec4, rotate_y_vec3, rotate_z_vec4, rotate_z_vec3, slerp,
|
|
||||||
rotation, scaling, translation, rotation2d, scaling2d, translation2d,
|
|
||||||
proj, proj2d, reflect, reflect2d, scale_bias, scale_bias_matrix, shear2d_x, shear_x, shear_y, shear2d_y, shear_z,
|
|
||||||
rotate2d, scale2d, translate2d,
|
|
||||||
angle,
|
|
||||||
are_collinear, are_collinear2d, are_orthogonal, is_comp_null, is_normalized, is_null,
|
|
||||||
quat_to_mat3, quat_rotate_vec, quat_cross_vec, mat3_to_quat, quat_extract_real_component, quat_fast_mix, quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_identity, quat_rotate_vec3, quat_rotation, quat_short_mix, quat_to_mat4, to_quat
|
|
||||||
};
|
};
|
||||||
pub use gtc::{
|
pub use gtc::{
|
||||||
e, two_pi, euler, four_over_pi, golden_ratio, half_pi, ln_ln_two, ln_ten, ln_two, one, one_over_pi, one_over_root_two, one_over_two_pi, quarter_pi, root_five, root_half_pi, root_ln_four, root_pi, root_three, root_two, root_two_pi, third, three_over_two_pi, two_over_pi, two_over_root_pi, two_thirds, zero,
|
affine_inverse, column, e, euler, four_over_pi, golden_ratio, half_pi, inverse_transpose,
|
||||||
column, row, set_column, set_row,
|
ln_ln_two, ln_ten, ln_two, make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3,
|
||||||
affine_inverse, inverse_transpose,
|
make_mat3x2, make_mat3x3, make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4,
|
||||||
make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3, make_mat3x2, make_mat3x3, make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4, make_quat, make_vec1, make_vec2, make_vec3, make_vec4, value_ptr, value_ptr_mut, vec1_to_vec2, vec1_to_vec3, vec1_to_vec4, vec2_to_vec1, vec2_to_vec2, vec2_to_vec3, vec2_to_vec4, vec3_to_vec1, vec3_to_vec2, vec3_to_vec3, vec3_to_vec4, vec4_to_vec1, vec4_to_vec2, vec4_to_vec3, vec4_to_vec4, mat2_to_mat3, mat2_to_mat4, mat3_to_mat2, mat3_to_mat4, mat4_to_mat2, mat4_to_mat3,
|
make_quat, make_vec1, make_vec2, make_vec3, make_vec4, mat2_to_mat3, mat2_to_mat4,
|
||||||
quat_cast, quat_euler_angles, quat_greater_than, quat_greater_than_equal, quat_less_than, quat_less_than_equal, quat_look_at, quat_look_at_lh, quat_look_at_rh, quat_pitch, quat_roll, quat_yaw
|
mat3_to_mat2, mat3_to_mat4, mat4_to_mat2, mat4_to_mat3, one, one_over_pi, one_over_root_two,
|
||||||
|
one_over_two_pi, quarter_pi, quat_cast, quat_euler_angles, quat_greater_than,
|
||||||
|
quat_greater_than_equal, quat_less_than, quat_less_than_equal, quat_look_at, quat_look_at_lh,
|
||||||
|
quat_look_at_rh, quat_pitch, quat_roll, quat_yaw, root_five, root_half_pi, root_ln_four,
|
||||||
|
root_pi, root_three, root_two, root_two_pi, row, set_column, set_row, third, three_over_two_pi,
|
||||||
|
two_over_pi, two_over_root_pi, two_pi, two_thirds, value_ptr, value_ptr_mut, vec1_to_vec2,
|
||||||
|
vec1_to_vec3, vec1_to_vec4, vec2_to_vec1, vec2_to_vec2, vec2_to_vec3, vec2_to_vec4,
|
||||||
|
vec3_to_vec1, vec3_to_vec2, vec3_to_vec3, vec3_to_vec4, vec4_to_vec1, vec4_to_vec2,
|
||||||
|
vec4_to_vec3, vec4_to_vec4, zero,
|
||||||
};
|
};
|
||||||
pub use ext::{
|
pub use gtx::{
|
||||||
ortho, perspective,
|
angle, are_collinear, are_collinear2d, are_orthogonal, comp_add, comp_max, comp_min, comp_mul,
|
||||||
pick_matrix, project, project_no, project_zo, unproject, unproject_no, unproject_zo,
|
cross2d, diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4,
|
||||||
equal_columns, equal_columns_eps, equal_columns_eps_vec, not_equal_columns, not_equal_columns_eps, not_equal_columns_eps_vec,
|
diagonal4x2, diagonal4x3, diagonal4x4, distance2, fast_normalize_dot, is_comp_null,
|
||||||
identity, look_at, look_at_lh, rotate, scale, look_at_rh, translate, rotate_x, rotate_y, rotate_z,
|
is_normalized, is_null, l1_distance, l1_norm, l2_distance, l2_norm, left_handed, length2,
|
||||||
max3_scalar, max4_scalar, min3_scalar, min4_scalar,
|
magnitude2, mat3_to_quat, matrix_cross, matrix_cross3, normalize_dot, orientation, proj,
|
||||||
epsilon, pi,
|
proj2d, quat_cross_vec, quat_extract_real_component, quat_fast_mix, quat_identity,
|
||||||
max, max2, max3, max4, min, min2, min3, min4,
|
quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_rotate_normalized_axis,
|
||||||
equal_eps, equal_eps_vec, not_equal_eps, not_equal_eps_vec,
|
quat_rotate_vec, quat_rotate_vec3, quat_rotation, quat_short_mix, quat_to_mat3, quat_to_mat4,
|
||||||
quat_conjugate, quat_inverse, quat_lerp, quat_slerp,
|
reflect, reflect2d, right_handed, rotate2d, rotate_normalized_axis, rotate_vec2, rotate_vec3,
|
||||||
quat_cross, quat_dot, quat_length, quat_magnitude, quat_normalize,
|
rotate_vec4, rotate_x_vec3, rotate_x_vec4, rotate_y_vec3, rotate_y_vec4, rotate_z_vec3,
|
||||||
quat_equal, quat_equal_eps, quat_not_equal, quat_not_equal_eps,
|
rotate_z_vec4, rotation, rotation2d, scale2d, scale_bias, scale_bias_matrix, scaling,
|
||||||
quat_exp, quat_log, quat_pow, quat_rotate,
|
scaling2d, shear2d_x, shear2d_y, shear_x, shear_y, shear_z, slerp, to_quat, translate2d,
|
||||||
quat_angle, quat_angle_axis, quat_axis
|
translation, translation2d, triangle_normal,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use na::{convert, convert_ref, convert_unchecked, convert_ref_unchecked, try_convert, try_convert_ref};
|
pub use na::{
|
||||||
pub use na::{Scalar, Real, DefaultAllocator, U1, U2, U3, U4};
|
convert, convert_ref, convert_ref_unchecked, convert_unchecked, try_convert, try_convert_ref,
|
||||||
|
};
|
||||||
|
pub use na::{DefaultAllocator, Real, Scalar, U1, U2, U3, U4};
|
||||||
|
|
||||||
mod aliases;
|
mod aliases;
|
||||||
mod constructors;
|
|
||||||
mod common;
|
mod common;
|
||||||
mod matrix;
|
mod constructors;
|
||||||
|
mod exponential;
|
||||||
mod geometric;
|
mod geometric;
|
||||||
|
mod matrix;
|
||||||
mod traits;
|
mod traits;
|
||||||
mod trigonometric;
|
mod trigonometric;
|
||||||
mod vector_relational;
|
mod vector_relational;
|
||||||
mod exponential;
|
|
||||||
//mod integer;
|
//mod integer;
|
||||||
//mod packing;
|
//mod packing;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{Scalar, Real, DefaultAllocator};
|
use na::{DefaultAllocator, Real, Scalar};
|
||||||
|
|
||||||
use traits::{Alloc, Dimension, Number};
|
|
||||||
use aliases::{TMat, TVec};
|
use aliases::{TMat, TVec};
|
||||||
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// The determinant of the matrix `m`.
|
/// The determinant of the matrix `m`.
|
||||||
pub fn determinant<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> N
|
pub fn determinant<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> N
|
||||||
@ -12,18 +12,30 @@ pub fn determinant<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> N
|
|||||||
/// The inverse of the matrix `m`.
|
/// The inverse of the matrix `m`.
|
||||||
pub fn inverse<N: Real, D: Dimension>(m: &TMat<N, D, D>) -> TMat<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> {
|
where DefaultAllocator: Alloc<N, D, D> {
|
||||||
m.clone().try_inverse().unwrap_or_else(TMat::<N, D, D>::zeros)
|
m.clone()
|
||||||
|
.try_inverse()
|
||||||
|
.unwrap_or_else(TMat::<N, D, D>::zeros)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Component-wise multiplication of two matrices.
|
/// Component-wise multiplication of two matrices.
|
||||||
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>
|
pub fn matrix_comp_mult<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
x: &TMat<N, R, C>,
|
||||||
|
y: &TMat<N, R, C>,
|
||||||
|
) -> TMat<N, R, C>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Alloc<N, R, C>,
|
||||||
|
{
|
||||||
x.component_mul(y)
|
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`.
|
/// 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: &TVec<N, R>, r: &TVec<N, C>) -> TMat<N, R, C>
|
pub fn outer_product<N: Number, R: Dimension, C: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, R, C> {
|
c: &TVec<N, R>,
|
||||||
|
r: &TVec<N, C>,
|
||||||
|
) -> TMat<N, R, C>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Alloc<N, R, C>,
|
||||||
|
{
|
||||||
c * r.transpose()
|
c * r.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,48 +1,81 @@
|
|||||||
use num::{Signed, FromPrimitive, Bounded};
|
|
||||||
use approx::AbsDiffEq;
|
use approx::AbsDiffEq;
|
||||||
|
use num::{Bounded, FromPrimitive, Signed};
|
||||||
|
|
||||||
use alga::general::{Ring, Lattice};
|
use alga::general::{Lattice, Ring};
|
||||||
use na::{Scalar, DimName, DimMin, U1};
|
|
||||||
use na::allocator::Allocator;
|
use na::allocator::Allocator;
|
||||||
|
use na::{DimMin, DimName, Scalar, U1};
|
||||||
|
|
||||||
/// A type-level number representing a vector, matrix row, or matrix column, dimension.
|
/// A type-level number representing a vector, matrix row, or matrix column, dimension.
|
||||||
pub trait Dimension: DimName + DimMin<Self, Output = Self> {}
|
pub trait Dimension: DimName + DimMin<Self, Output = Self> {}
|
||||||
impl<D: DimName + DimMin<D, Output = Self>> Dimension for D {}
|
impl<D: DimName + DimMin<D, Output = Self>> Dimension for D {}
|
||||||
|
|
||||||
|
|
||||||
/// A number that can either be an integer or a float.
|
/// A number that can either be an integer or a float.
|
||||||
pub trait Number: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded {
|
pub trait Number:
|
||||||
|
Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded> Number for T {
|
impl<T: Scalar + Ring + Lattice + AbsDiffEq<Epsilon = Self> + Signed + FromPrimitive + Bounded>
|
||||||
|
Number for T
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub trait Alloc<N: Scalar, R: Dimension, C: Dimension = U1>:
|
pub trait Alloc<N: Scalar, R: Dimension, C: Dimension = U1>:
|
||||||
Allocator<N, R> + Allocator<N, C> + Allocator<N, U1, R> + Allocator<N, U1, C> + Allocator<N, R, C> + Allocator<N, C, R> + Allocator<N, R, R> + Allocator<N, C, C> +
|
Allocator<N, R>
|
||||||
Allocator<bool, R> + Allocator<bool, C> +
|
+ Allocator<N, C>
|
||||||
Allocator<f32, R> + Allocator<f32, C> +
|
+ Allocator<N, U1, R>
|
||||||
Allocator<u32, R> + Allocator<u32, C> +
|
+ Allocator<N, U1, C>
|
||||||
Allocator<i32, R> + Allocator<i32, C> +
|
+ Allocator<N, R, C>
|
||||||
Allocator<f64, R> + Allocator<f64, C> +
|
+ Allocator<N, C, R>
|
||||||
Allocator<u64, R> + Allocator<u64, C> +
|
+ Allocator<N, R, R>
|
||||||
Allocator<i64, R> + Allocator<i64, C> +
|
+ Allocator<N, C, C>
|
||||||
Allocator<i16, R> + Allocator<i16, C> +
|
+ Allocator<bool, R>
|
||||||
Allocator<(usize, usize), R> + Allocator<(usize, usize), C>
|
+ Allocator<bool, C>
|
||||||
|
+ Allocator<f32, R>
|
||||||
|
+ Allocator<f32, C>
|
||||||
|
+ Allocator<u32, R>
|
||||||
|
+ Allocator<u32, C>
|
||||||
|
+ Allocator<i32, R>
|
||||||
|
+ Allocator<i32, C>
|
||||||
|
+ Allocator<f64, R>
|
||||||
|
+ Allocator<f64, C>
|
||||||
|
+ Allocator<u64, R>
|
||||||
|
+ Allocator<u64, C>
|
||||||
|
+ Allocator<i64, R>
|
||||||
|
+ Allocator<i64, C>
|
||||||
|
+ Allocator<i16, R>
|
||||||
|
+ Allocator<i16, C>
|
||||||
|
+ Allocator<(usize, usize), R>
|
||||||
|
+ Allocator<(usize, usize), C>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Scalar, R: Dimension, C: Dimension, T>
|
impl<N: Scalar, R: Dimension, C: Dimension, T> Alloc<N, R, C> for T where T: Allocator<N, R>
|
||||||
Alloc<N, R, C> for T
|
+ Allocator<N, C>
|
||||||
where T: Allocator<N, R> + Allocator<N, C> + Allocator<N, U1, R> + Allocator<N, U1, C> + Allocator<N, R, C> + Allocator<N, C, R> + Allocator<N, R, R> + Allocator<N, C, C> +
|
+ Allocator<N, U1, R>
|
||||||
Allocator<bool, R> + Allocator<bool, C> +
|
+ Allocator<N, U1, C>
|
||||||
Allocator<f32, R> + Allocator<f32, C> +
|
+ Allocator<N, R, C>
|
||||||
Allocator<u32, R> + Allocator<u32, C> +
|
+ Allocator<N, C, R>
|
||||||
Allocator<i32, R> + Allocator<i32, C> +
|
+ Allocator<N, R, R>
|
||||||
Allocator<f64, R> + Allocator<f64, C> +
|
+ Allocator<N, C, C>
|
||||||
Allocator<u64, R> + Allocator<u64, C> +
|
+ Allocator<bool, R>
|
||||||
Allocator<i64, R> + Allocator<i64, C> +
|
+ Allocator<bool, C>
|
||||||
Allocator<i16, R> + Allocator<i16, C> +
|
+ Allocator<f32, R>
|
||||||
Allocator<(usize, usize), R> + Allocator<(usize, usize), C>
|
+ Allocator<f32, C>
|
||||||
|
+ Allocator<u32, R>
|
||||||
|
+ Allocator<u32, C>
|
||||||
|
+ Allocator<i32, R>
|
||||||
|
+ Allocator<i32, C>
|
||||||
|
+ Allocator<f64, R>
|
||||||
|
+ Allocator<f64, C>
|
||||||
|
+ Allocator<u64, R>
|
||||||
|
+ Allocator<u64, C>
|
||||||
|
+ Allocator<i64, R>
|
||||||
|
+ Allocator<i64, C>
|
||||||
|
+ Allocator<i16, R>
|
||||||
|
+ Allocator<i16, C>
|
||||||
|
+ Allocator<(usize, usize), R>
|
||||||
|
+ Allocator<(usize, usize), C>
|
||||||
{
|
{
|
||||||
}
|
}
|
@ -1,9 +1,8 @@
|
|||||||
use na::{self, Real, DefaultAllocator};
|
use na::{self, DefaultAllocator, Real};
|
||||||
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
use traits::{Alloc, Dimension};
|
use traits::{Alloc, Dimension};
|
||||||
|
|
||||||
|
|
||||||
/// Component-wise arc-cosinus.
|
/// Component-wise arc-cosinus.
|
||||||
pub fn acos<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
pub fn acos<N: Real, D: Dimension>(x: &TVec<N, D>) -> TVec<N, D>
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
where DefaultAllocator: Alloc<N, D> {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use na::{DefaultAllocator};
|
use na::DefaultAllocator;
|
||||||
|
|
||||||
use aliases::TVec;
|
use aliases::TVec;
|
||||||
use traits::{Number, Alloc, Dimension};
|
use traits::{Alloc, Dimension, Number};
|
||||||
|
|
||||||
/// Checks that all the vector components are `true`.
|
/// Checks that all the vector components are `true`.
|
||||||
///
|
///
|
||||||
@ -117,8 +117,13 @@ pub fn greater_than<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) ->
|
|||||||
/// * [`less_than_equal`](fn.less_than_equal.html)
|
/// * [`less_than_equal`](fn.less_than_equal.html)
|
||||||
/// * [`not`](fn.not.html)
|
/// * [`not`](fn.not.html)
|
||||||
/// * [`not_equal`](fn.not_equal.html)
|
/// * [`not_equal`](fn.not_equal.html)
|
||||||
pub fn greater_than_equal<N: Number, D: Dimension>(x: &TVec<N, D>, y: &TVec<N, D>) -> TVec<bool, D>
|
pub fn greater_than_equal<N: Number, D: Dimension>(
|
||||||
where DefaultAllocator: Alloc<N, D> {
|
x: &TVec<N, D>,
|
||||||
|
y: &TVec<N, D>,
|
||||||
|
) -> TVec<bool, D>
|
||||||
|
where
|
||||||
|
DefaultAllocator: Alloc<N, D>,
|
||||||
|
{
|
||||||
x.zip_map(y, |x, y| x >= y)
|
x.zip_map(y, |x, y| x >= y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, Matrix4};
|
use na::{DMatrix, Matrix4};
|
||||||
use nl::Hessenberg;
|
use nl::Hessenberg;
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn hessenberg_decompose_100x100(bh: &mut Bencher) {
|
fn hessenberg_decompose_100x100(bh: &mut Bencher) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, Matrix4};
|
use na::{DMatrix, Matrix4};
|
||||||
use nl::LU;
|
use nl::LU;
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn lu_decompose_100x100(bh: &mut Bencher) {
|
fn lu_decompose_100x100(bh: &mut Bencher) {
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
mod qr;
|
|
||||||
mod lu;
|
|
||||||
mod hessenberg;
|
mod hessenberg;
|
||||||
|
mod lu;
|
||||||
|
mod qr;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use test::{self, Bencher};
|
|
||||||
use na::{DMatrix, Matrix4};
|
use na::{DMatrix, Matrix4};
|
||||||
use nl::QR;
|
use nl::QR;
|
||||||
|
use test::{self, Bencher};
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn qr_decompose_100x100(bh: &mut Bencher) {
|
fn qr_decompose_100x100(bh: &mut Bencher) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num::Zero;
|
use num::Zero;
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
@ -15,26 +15,17 @@ use lapack;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(serialize = "DefaultAllocator: Allocator<N, D>,
|
||||||
bound(
|
MatrixN<N, D>: Serialize"))
|
||||||
serialize = "DefaultAllocator: Allocator<N, D>,
|
|
||||||
MatrixN<N, D>: Serialize"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(deserialize = "DefaultAllocator: Allocator<N, D>,
|
||||||
bound(
|
MatrixN<N, D>: Deserialize<'de>"))
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D>,
|
|
||||||
MatrixN<N, D>: Deserialize<'de>"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Cholesky<N: Scalar, D: Dim>
|
pub struct Cholesky<N: Scalar, D: Dim>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
l: MatrixN<N, D>,
|
l: MatrixN<N, D>,
|
||||||
}
|
}
|
||||||
@ -47,8 +38,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: CholeskyScalar + Zero, D: Dim> Cholesky<N, D>
|
impl<N: CholeskyScalar + Zero, D: Dim> Cholesky<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
/// Computes the cholesky decomposition of the given symmetric-definite-positive square
|
/// Computes the cholesky decomposition of the given symmetric-definite-positive square
|
||||||
/// matrix.
|
/// matrix.
|
||||||
@ -124,9 +114,7 @@ where
|
|||||||
/// Solves in-place the symmetric-definite-positive linear system `self * x = b`, where `x` is
|
/// Solves in-place the symmetric-definite-positive linear system `self * x = b`, where `x` is
|
||||||
/// the unknown to be determined.
|
/// the unknown to be determined.
|
||||||
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||||
where
|
where DefaultAllocator: Allocator<N, R2, C2> {
|
||||||
DefaultAllocator: Allocator<N, R2, C2>,
|
|
||||||
{
|
|
||||||
let dim = self.l.nrows();
|
let dim = self.l.nrows();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num::Zero;
|
use num::Zero;
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
@ -19,27 +19,22 @@ use lapack;
|
|||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(
|
||||||
bound(
|
bound(serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
|
||||||
VectorN<N, D>: Serialize,
|
VectorN<N, D>: Serialize,
|
||||||
MatrixN<N, D>: Serialize"
|
MatrixN<N, D>: Serialize")
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(
|
||||||
bound(
|
bound(deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
|
||||||
VectorN<N, D>: Serialize,
|
VectorN<N, D>: Serialize,
|
||||||
MatrixN<N, D>: Deserialize<'de>"
|
MatrixN<N, D>: Deserialize<'de>")
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Eigen<N: Scalar, D: Dim>
|
pub struct Eigen<N: Scalar, D: Dim>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
/// The eigenvalues of the decomposed matrix.
|
/// The eigenvalues of the decomposed matrix.
|
||||||
pub eigenvalues: VectorN<N, D>,
|
pub eigenvalues: VectorN<N, D>,
|
||||||
@ -58,8 +53,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: EigenScalar + Real, D: Dim> Eigen<N, D>
|
impl<N: EigenScalar + Real, D: Dim> Eigen<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
|
||||||
{
|
{
|
||||||
/// Computes the eigenvalues and eigenvectors of the square matrix `m`.
|
/// Computes the eigenvalues and eigenvectors of the square matrix `m`.
|
||||||
///
|
///
|
||||||
@ -68,7 +62,8 @@ where
|
|||||||
mut m: MatrixN<N, D>,
|
mut m: MatrixN<N, D>,
|
||||||
left_eigenvectors: bool,
|
left_eigenvectors: bool,
|
||||||
eigenvectors: bool,
|
eigenvectors: bool,
|
||||||
) -> Option<Eigen<N, D>> {
|
) -> Option<Eigen<N, D>>
|
||||||
|
{
|
||||||
assert!(
|
assert!(
|
||||||
m.is_square(),
|
m.is_square(),
|
||||||
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
||||||
@ -234,9 +229,7 @@ where
|
|||||||
///
|
///
|
||||||
/// Panics if the eigenvalue computation does not converge.
|
/// Panics if the eigenvalue computation does not converge.
|
||||||
pub fn complex_eigenvalues(mut m: MatrixN<N, D>) -> VectorN<Complex<N>, D>
|
pub fn complex_eigenvalues(mut m: MatrixN<N, D>) -> VectorN<Complex<N>, D>
|
||||||
where
|
where DefaultAllocator: Allocator<Complex<N>, D> {
|
||||||
DefaultAllocator: Allocator<Complex<N>, D>,
|
|
||||||
{
|
|
||||||
assert!(
|
assert!(
|
||||||
m.is_square(),
|
m.is_square(),
|
||||||
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
||||||
|
@ -13,30 +13,21 @@ use lapack;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
bound(
|
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, DimDiff<D, U1>>,
|
Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Serialize,
|
MatrixN<N, D>: Serialize,
|
||||||
VectorN<N, DimDiff<D, U1>>: Serialize"
|
VectorN<N, DimDiff<D, U1>>: Serialize"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
bound(
|
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, DimDiff<D, U1>>,
|
Allocator<N, DimDiff<D, U1>>,
|
||||||
MatrixN<N, D>: Deserialize<'de>,
|
MatrixN<N, D>: Deserialize<'de>,
|
||||||
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"
|
VectorN<N, DimDiff<D, U1>>: Deserialize<'de>"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Hessenberg<N: Scalar, D: DimSub<U1>>
|
pub struct Hessenberg<N: Scalar, D: DimSub<U1>>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
|
||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
|
||||||
{
|
{
|
||||||
h: MatrixN<N, D>,
|
h: MatrixN<N, D>,
|
||||||
tau: VectorN<N, DimDiff<D, U1>>,
|
tau: VectorN<N, DimDiff<D, U1>>,
|
||||||
@ -51,8 +42,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: HessenbergScalar + Zero, D: DimSub<U1>> Hessenberg<N, D>
|
impl<N: HessenbergScalar + Zero, D: DimSub<U1>> Hessenberg<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
|
||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
|
||||||
{
|
{
|
||||||
/// Computes the hessenberg decomposition of the matrix `m`.
|
/// Computes the hessenberg decomposition of the matrix `m`.
|
||||||
pub fn new(mut m: MatrixN<N, D>) -> Hessenberg<N, D> {
|
pub fn new(mut m: MatrixN<N, D>) -> Hessenberg<N, D> {
|
||||||
@ -104,8 +94,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: HessenbergReal + Zero, D: DimSub<U1>> Hessenberg<N, D>
|
impl<N: HessenbergReal + Zero, D: DimSub<U1>> Hessenberg<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>
|
||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, DimDiff<D, U1>>,
|
|
||||||
{
|
{
|
||||||
/// Computes the matrices `(Q, H)` of this decomposition.
|
/// Computes the matrices `(Q, H)` of this decomposition.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -68,8 +68,10 @@
|
|||||||
#![deny(unused_qualifications)]
|
#![deny(unused_qualifications)]
|
||||||
#![deny(unused_results)]
|
#![deny(unused_results)]
|
||||||
#![deny(missing_docs)]
|
#![deny(missing_docs)]
|
||||||
#![doc(html_favicon_url = "http://nalgebra.org/img/favicon.ico",
|
#![doc(
|
||||||
html_root_url = "http://nalgebra.org/rustdoc")]
|
html_favicon_url = "http://nalgebra.org/img/favicon.ico",
|
||||||
|
html_root_url = "http://nalgebra.org/rustdoc"
|
||||||
|
)]
|
||||||
|
|
||||||
extern crate alga;
|
extern crate alga;
|
||||||
extern crate lapack;
|
extern crate lapack;
|
||||||
|
@ -20,30 +20,21 @@ use lapack;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
bound(
|
|
||||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<i32, DimMinimum<R, C>>,
|
Allocator<i32, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Serialize,
|
MatrixMN<N, R, C>: Serialize,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Serialize"
|
PermutationSequence<DimMinimum<R, C>>: Serialize"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
bound(
|
|
||||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<i32, DimMinimum<R, C>>,
|
Allocator<i32, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||||
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"
|
PermutationSequence<DimMinimum<R, C>>: Deserialize<'de>"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct LU<N: Scalar, R: DimMin<C>, C: Dim>
|
pub struct LU<N: Scalar, R: DimMin<C>, C: Dim>
|
||||||
where
|
where DefaultAllocator: Allocator<i32, DimMinimum<R, C>> + Allocator<N, R, C>
|
||||||
DefaultAllocator: Allocator<i32, DimMinimum<R, C>> + Allocator<N, R, C>,
|
|
||||||
{
|
{
|
||||||
lu: MatrixMN<N, R, C>,
|
lu: MatrixMN<N, R, C>,
|
||||||
p: VectorN<i32, DimMinimum<R, C>>,
|
p: VectorN<i32, DimMinimum<R, C>>,
|
||||||
@ -139,9 +130,7 @@ where
|
|||||||
/// Applies the permutation matrix to a given matrix or vector in-place.
|
/// Applies the permutation matrix to a given matrix or vector in-place.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn permute<C2: Dim>(&self, rhs: &mut MatrixMN<N, R, C2>)
|
pub fn permute<C2: Dim>(&self, rhs: &mut MatrixMN<N, R, C2>)
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C2> {
|
||||||
DefaultAllocator: Allocator<N, R, C2>,
|
|
||||||
{
|
|
||||||
let (nrows, ncols) = rhs.shape();
|
let (nrows, ncols) = rhs.shape();
|
||||||
|
|
||||||
N::xlaswp(
|
N::xlaswp(
|
||||||
@ -156,9 +145,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn generic_solve_mut<R2: Dim, C2: Dim>(&self, trans: u8, b: &mut MatrixMN<N, R2, C2>) -> bool
|
fn generic_solve_mut<R2: Dim, C2: Dim>(&self, trans: u8, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||||
where
|
where DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2> {
|
||||||
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
|
|
||||||
{
|
|
||||||
let dim = self.lu.nrows();
|
let dim = self.lu.nrows();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
@ -246,9 +233,7 @@ where
|
|||||||
///
|
///
|
||||||
/// Returns `false` if no solution was found (the decomposed matrix is singular).
|
/// Returns `false` if no solution was found (the decomposed matrix is singular).
|
||||||
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
pub fn solve_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||||
where
|
where DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2> {
|
||||||
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
|
|
||||||
{
|
|
||||||
self.generic_solve_mut(b'N', b)
|
self.generic_solve_mut(b'N', b)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -257,9 +242,7 @@ where
|
|||||||
///
|
///
|
||||||
/// Returns `false` if no solution was found (the decomposed matrix is singular).
|
/// Returns `false` if no solution was found (the decomposed matrix is singular).
|
||||||
pub fn solve_transpose_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
pub fn solve_transpose_mut<R2: Dim, C2: Dim>(&self, b: &mut MatrixMN<N, R2, C2>) -> bool
|
||||||
where
|
where DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2> {
|
||||||
DefaultAllocator: Allocator<N, R2, C2> + Allocator<i32, R2>,
|
|
||||||
{
|
|
||||||
self.generic_solve_mut(b'T', b)
|
self.generic_solve_mut(b'T', b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num::Zero;
|
use num::Zero;
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
@ -16,30 +16,21 @@ use lapack;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(serialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
bound(
|
|
||||||
serialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<N, DimMinimum<R, C>>,
|
Allocator<N, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Serialize,
|
MatrixMN<N, R, C>: Serialize,
|
||||||
VectorN<N, DimMinimum<R, C>>: Serialize"
|
VectorN<N, DimMinimum<R, C>>: Serialize"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
||||||
bound(
|
|
||||||
deserialize = "DefaultAllocator: Allocator<N, R, C> +
|
|
||||||
Allocator<N, DimMinimum<R, C>>,
|
Allocator<N, DimMinimum<R, C>>,
|
||||||
MatrixMN<N, R, C>: Deserialize<'de>,
|
MatrixMN<N, R, C>: Deserialize<'de>,
|
||||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct QR<N: Scalar, R: DimMin<C>, C: Dim>
|
pub struct QR<N: Scalar, R: DimMin<C>, C: Dim>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>
|
||||||
DefaultAllocator: Allocator<N, R, C> + Allocator<N, DimMinimum<R, C>>,
|
|
||||||
{
|
{
|
||||||
qr: MatrixMN<N, R, C>,
|
qr: MatrixMN<N, R, C>,
|
||||||
tau: VectorN<N, DimMinimum<R, C>>,
|
tau: VectorN<N, DimMinimum<R, C>>,
|
||||||
@ -54,11 +45,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: QRScalar + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
|
impl<N: QRScalar + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>
|
||||||
DefaultAllocator: Allocator<N, R, C>
|
|
||||||
+ Allocator<N, R, DimMinimum<R, C>>
|
+ Allocator<N, R, DimMinimum<R, C>>
|
||||||
+ Allocator<N, DimMinimum<R, C>, C>
|
+ Allocator<N, DimMinimum<R, C>, C>
|
||||||
+ Allocator<N, DimMinimum<R, C>>,
|
+ Allocator<N, DimMinimum<R, C>>
|
||||||
{
|
{
|
||||||
/// Computes the QR decomposition of the matrix `m`.
|
/// Computes the QR decomposition of the matrix `m`.
|
||||||
pub fn new(mut m: MatrixMN<N, R, C>) -> QR<N, R, C> {
|
pub fn new(mut m: MatrixMN<N, R, C>) -> QR<N, R, C> {
|
||||||
@ -105,11 +95,10 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: QRReal + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
|
impl<N: QRReal + Zero, R: DimMin<C>, C: Dim> QR<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>
|
||||||
DefaultAllocator: Allocator<N, R, C>
|
|
||||||
+ Allocator<N, R, DimMinimum<R, C>>
|
+ Allocator<N, R, DimMinimum<R, C>>
|
||||||
+ Allocator<N, DimMinimum<R, C>, C>
|
+ Allocator<N, DimMinimum<R, C>, C>
|
||||||
+ Allocator<N, DimMinimum<R, C>>,
|
+ Allocator<N, DimMinimum<R, C>>
|
||||||
{
|
{
|
||||||
/// Retrieves the matrices `(Q, R)` of this decompositions.
|
/// Retrieves the matrices `(Q, R)` of this decompositions.
|
||||||
pub fn unpack(
|
pub fn unpack(
|
||||||
@ -131,7 +120,8 @@ where
|
|||||||
return MatrixMN::from_element_generic(nrows, min_nrows_ncols, N::zero());
|
return MatrixMN::from_element_generic(nrows, min_nrows_ncols, N::zero());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut q = self.qr
|
let mut q = self
|
||||||
|
.qr
|
||||||
.generic_slice((0, 0), (nrows, min_nrows_ncols))
|
.generic_slice((0, 0), (nrows, min_nrows_ncols))
|
||||||
.into_owned();
|
.into_owned();
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num::Zero;
|
use num::Zero;
|
||||||
use num_complex::Complex;
|
use num_complex::Complex;
|
||||||
@ -19,27 +19,22 @@ use lapack;
|
|||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(
|
||||||
bound(
|
bound(serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
|
||||||
VectorN<N, D>: Serialize,
|
VectorN<N, D>: Serialize,
|
||||||
MatrixN<N, D>: Serialize"
|
MatrixN<N, D>: Serialize")
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(
|
||||||
bound(
|
bound(deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
|
||||||
VectorN<N, D>: Serialize,
|
VectorN<N, D>: Serialize,
|
||||||
MatrixN<N, D>: Deserialize<'de>"
|
MatrixN<N, D>: Deserialize<'de>")
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RealSchur<N: Scalar, D: Dim>
|
pub struct RealSchur<N: Scalar, D: Dim>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
re: VectorN<N, D>,
|
re: VectorN<N, D>,
|
||||||
im: VectorN<N, D>,
|
im: VectorN<N, D>,
|
||||||
@ -56,8 +51,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: RealSchurScalar + Real, D: Dim> RealSchur<N, D>
|
impl<N: RealSchurScalar + Real, D: Dim> RealSchur<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
|
||||||
{
|
{
|
||||||
/// Computes the eigenvalues and real Schur form of the matrix `m`.
|
/// Computes the eigenvalues and real Schur form of the matrix `m`.
|
||||||
///
|
///
|
||||||
@ -152,9 +146,7 @@ where
|
|||||||
|
|
||||||
/// Computes the complex eigenvalues of the decomposed matrix.
|
/// Computes the complex eigenvalues of the decomposed matrix.
|
||||||
pub fn complex_eigenvalues(&self) -> VectorN<Complex<N>, D>
|
pub fn complex_eigenvalues(&self) -> VectorN<Complex<N>, D>
|
||||||
where
|
where DefaultAllocator: Allocator<Complex<N>, D> {
|
||||||
DefaultAllocator: Allocator<Complex<N>, D>,
|
|
||||||
{
|
|
||||||
let mut out = unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1) };
|
let mut out = unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1) };
|
||||||
|
|
||||||
for i in 0..out.len() {
|
for i in 0..out.len() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num::Signed;
|
use num::Signed;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
@ -15,34 +15,25 @@ use lapack;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
||||||
bound(
|
|
||||||
serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
|
||||||
Allocator<N, R, R> +
|
Allocator<N, R, R> +
|
||||||
Allocator<N, C, C>,
|
Allocator<N, C, C>,
|
||||||
MatrixN<N, R>: Serialize,
|
MatrixN<N, R>: Serialize,
|
||||||
MatrixN<N, C>: Serialize,
|
MatrixN<N, C>: Serialize,
|
||||||
VectorN<N, DimMinimum<R, C>>: Serialize"
|
VectorN<N, DimMinimum<R, C>>: Serialize"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
||||||
bound(
|
|
||||||
serialize = "DefaultAllocator: Allocator<N, DimMinimum<R, C>> +
|
|
||||||
Allocator<N, R, R> +
|
Allocator<N, R, R> +
|
||||||
Allocator<N, C, C>,
|
Allocator<N, C, C>,
|
||||||
MatrixN<N, R>: Deserialize<'de>,
|
MatrixN<N, R>: Deserialize<'de>,
|
||||||
MatrixN<N, C>: Deserialize<'de>,
|
MatrixN<N, C>: Deserialize<'de>,
|
||||||
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"
|
VectorN<N, DimMinimum<R, C>>: Deserialize<'de>"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SVD<N: Scalar, R: DimMin<C>, C: Dim>
|
pub struct SVD<N: Scalar, R: DimMin<C>, C: Dim>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, R> + Allocator<N, DimMinimum<R, C>> + Allocator<N, C, C>
|
||||||
DefaultAllocator: Allocator<N, R, R> + Allocator<N, DimMinimum<R, C>> + Allocator<N, C, C>,
|
|
||||||
{
|
{
|
||||||
/// The left-singular vectors `U` of this SVD.
|
/// The left-singular vectors `U` of this SVD.
|
||||||
pub u: MatrixN<N, R>, // FIXME: should be MatrixMN<N, R, DimMinimum<R, C>>
|
pub u: MatrixN<N, R>, // FIXME: should be MatrixMN<N, R, DimMinimum<R, C>>
|
||||||
@ -64,22 +55,20 @@ where
|
|||||||
/// Trait implemented by floats (`f32`, `f64`) and complex floats (`Complex<f32>`, `Complex<f64>`)
|
/// Trait implemented by floats (`f32`, `f64`) and complex floats (`Complex<f32>`, `Complex<f64>`)
|
||||||
/// supported by the Singular Value Decompotition.
|
/// supported by the Singular Value Decompotition.
|
||||||
pub trait SVDScalar<R: DimMin<C>, C: Dim>: Scalar
|
pub trait SVDScalar<R: DimMin<C>, C: Dim>: Scalar
|
||||||
where
|
where DefaultAllocator: Allocator<Self, R, R>
|
||||||
DefaultAllocator: Allocator<Self, R, R>
|
|
||||||
+ Allocator<Self, R, C>
|
+ Allocator<Self, R, C>
|
||||||
+ Allocator<Self, DimMinimum<R, C>>
|
+ Allocator<Self, DimMinimum<R, C>>
|
||||||
+ Allocator<Self, C, C>,
|
+ Allocator<Self, C, C>
|
||||||
{
|
{
|
||||||
/// Computes the SVD decomposition of `m`.
|
/// Computes the SVD decomposition of `m`.
|
||||||
fn compute(m: MatrixMN<Self, R, C>) -> Option<SVD<Self, R, C>>;
|
fn compute(m: MatrixMN<Self, R, C>) -> Option<SVD<Self, R, C>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: SVDScalar<R, C>, R: DimMin<C>, C: Dim> SVD<N, R, C>
|
impl<N: SVDScalar<R, C>, R: DimMin<C>, C: Dim> SVD<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, R>
|
||||||
DefaultAllocator: Allocator<N, R, R>
|
|
||||||
+ Allocator<N, R, C>
|
+ Allocator<N, R, C>
|
||||||
+ Allocator<N, DimMinimum<R, C>>
|
+ Allocator<N, DimMinimum<R, C>>
|
||||||
+ Allocator<N, C, C>,
|
+ Allocator<N, C, C>
|
||||||
{
|
{
|
||||||
/// Computes the Singular Value Decomposition of `matrix`.
|
/// Computes the Singular Value Decomposition of `matrix`.
|
||||||
pub fn new(m: MatrixMN<N, R, C>) -> Option<Self> {
|
pub fn new(m: MatrixMN<N, R, C>) -> Option<Self> {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use num::Zero;
|
use num::Zero;
|
||||||
use std::ops::MulAssign;
|
use std::ops::MulAssign;
|
||||||
@ -18,30 +18,21 @@ use lapack;
|
|||||||
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(serialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
bound(
|
|
||||||
serialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, D>,
|
Allocator<N, D>,
|
||||||
VectorN<N, D>: Serialize,
|
VectorN<N, D>: Serialize,
|
||||||
MatrixN<N, D>: Serialize"
|
MatrixN<N, D>: Serialize"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serde-serialize",
|
feature = "serde-serialize",
|
||||||
serde(
|
serde(bound(deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
||||||
bound(
|
|
||||||
deserialize = "DefaultAllocator: Allocator<N, D, D> +
|
|
||||||
Allocator<N, D>,
|
Allocator<N, D>,
|
||||||
VectorN<N, D>: Deserialize<'de>,
|
VectorN<N, D>: Deserialize<'de>,
|
||||||
MatrixN<N, D>: Deserialize<'de>"
|
MatrixN<N, D>: Deserialize<'de>"))
|
||||||
)
|
|
||||||
)
|
|
||||||
)]
|
)]
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct SymmetricEigen<N: Scalar, D: Dim>
|
pub struct SymmetricEigen<N: Scalar, D: Dim>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D> + Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
/// The eigenvectors of the decomposed matrix.
|
/// The eigenvectors of the decomposed matrix.
|
||||||
pub eigenvectors: MatrixN<N, D>,
|
pub eigenvectors: MatrixN<N, D>,
|
||||||
@ -59,8 +50,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: SymmetricEigenScalar + Real, D: Dim> SymmetricEigen<N, D>
|
impl<N: SymmetricEigenScalar + Real, D: Dim> SymmetricEigen<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
||||||
DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>,
|
|
||||||
{
|
{
|
||||||
/// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`.
|
/// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`.
|
||||||
///
|
///
|
||||||
@ -89,7 +79,8 @@ where
|
|||||||
fn do_decompose(
|
fn do_decompose(
|
||||||
mut m: MatrixN<N, D>,
|
mut m: MatrixN<N, D>,
|
||||||
eigenvectors: bool,
|
eigenvectors: bool,
|
||||||
) -> Option<(VectorN<N, D>, Option<MatrixN<N, D>>)> {
|
) -> Option<(VectorN<N, D>, Option<MatrixN<N, D>>)>
|
||||||
|
{
|
||||||
assert!(
|
assert!(
|
||||||
m.is_square(),
|
m.is_square(),
|
||||||
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
"Unable to compute the eigenvalue decomposition of a non-square matrix."
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use nl::Cholesky;
|
|
||||||
use na::{DMatrix, DVector, Matrix3, Matrix4, Matrix4x3, Vector4};
|
use na::{DMatrix, DVector, Matrix3, Matrix4, Matrix4x3, Vector4};
|
||||||
|
use nl::Cholesky;
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn cholesky(m: DMatrix<f64>) -> bool {
|
fn cholesky(m: DMatrix<f64>) -> bool {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use nl::LU;
|
|
||||||
use na::{DMatrix, DVector, Matrix3x4, Matrix4, Matrix4x3, Vector4};
|
use na::{DMatrix, DVector, Matrix3x4, Matrix4, Matrix4x3, Vector4};
|
||||||
|
use nl::LU;
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn lup(m: DMatrix<f64>) -> bool {
|
fn lup(m: DMatrix<f64>) -> bool {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
mod real_eigensystem;
|
|
||||||
mod symmetric_eigen;
|
|
||||||
mod cholesky;
|
mod cholesky;
|
||||||
mod lu;
|
mod lu;
|
||||||
mod qr;
|
mod qr;
|
||||||
mod svd;
|
mod real_eigensystem;
|
||||||
mod real_schur;
|
mod real_schur;
|
||||||
|
mod svd;
|
||||||
|
mod symmetric_eigen;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use nl::QR;
|
|
||||||
use na::{DMatrix, Matrix4x3};
|
use na::{DMatrix, Matrix4x3};
|
||||||
|
use nl::QR;
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn qr(m: DMatrix<f64>) -> bool {
|
fn qr(m: DMatrix<f64>) -> bool {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use nl::Eigen;
|
|
||||||
use na::{DMatrix, Matrix4};
|
use na::{DMatrix, Matrix4};
|
||||||
|
use nl::Eigen;
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn eigensystem(n: usize) -> bool {
|
fn eigensystem(n: usize) -> bool {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::cmp;
|
|
||||||
use nl::RealSchur;
|
|
||||||
use na::{DMatrix, Matrix4};
|
use na::{DMatrix, Matrix4};
|
||||||
|
use nl::RealSchur;
|
||||||
|
use std::cmp;
|
||||||
|
|
||||||
quickcheck! {
|
quickcheck! {
|
||||||
fn schur(n: usize) -> bool {
|
fn schur(n: usize) -> bool {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use nl::SVD;
|
|
||||||
use na::{DMatrix, Matrix3x4};
|
use na::{DMatrix, Matrix3x4};
|
||||||
|
use nl::SVD;
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn svd(m: DMatrix<f64>) -> bool {
|
fn svd(m: DMatrix<f64>) -> bool {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
|
||||||
use nl::SymmetricEigen;
|
|
||||||
use na::{DMatrix, Matrix4};
|
use na::{DMatrix, Matrix4};
|
||||||
|
use nl::SymmetricEigen;
|
||||||
|
|
||||||
quickcheck!{
|
quickcheck!{
|
||||||
fn symmetric_eigen(n: usize) -> bool {
|
fn symmetric_eigen(n: usize) -> bool {
|
||||||
|
@ -79,7 +79,8 @@ where
|
|||||||
N: Scalar,
|
N: Scalar,
|
||||||
DefaultAllocator: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>,
|
DefaultAllocator: Allocator<N, R1, C1> + Allocator<N, SameShapeR<R1, R2>, SameShapeC<C1, C2>>,
|
||||||
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
|
ShapeConstraint: SameNumberOfRows<R1, R2> + SameNumberOfColumns<C1, C2>,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
// XXX: Bad name.
|
// XXX: Bad name.
|
||||||
/// Restricts the given number of rows to be equal.
|
/// Restricts the given number of rows to be equal.
|
||||||
@ -100,4 +101,5 @@ where
|
|||||||
N: Scalar,
|
N: Scalar,
|
||||||
DefaultAllocator: Allocator<N, R1, U1> + Allocator<N, SameShapeR<R1, R2>>,
|
DefaultAllocator: Allocator<N, R1, U1> + Allocator<N, SameShapeR<R1, R2>>,
|
||||||
ShapeConstraint: SameNumberOfRows<R1, R2>,
|
ShapeConstraint: SameNumberOfRows<R1, R2>,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
@ -161,8 +161,7 @@ impl<N: Scalar + PartialOrd + Signed, R: Dim, C: Dim, S: Storage<N, R, C>> Matri
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S>
|
impl<N, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S>
|
||||||
where
|
where N: Scalar + Zero + ClosedAdd + ClosedMul
|
||||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
|
||||||
{
|
{
|
||||||
/// The dot product between two vectors or matrices (seen as vectors).
|
/// The dot product between two vectors or matrices (seen as vectors).
|
||||||
///
|
///
|
||||||
@ -324,9 +323,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn array_axpy<N>(y: &mut [N], a: N, x: &[N], beta: N, stride1: usize, stride2: usize, len: usize)
|
fn array_axpy<N>(y: &mut [N], a: N, x: &[N], beta: N, stride1: usize, stride2: usize, len: usize)
|
||||||
where
|
where N: Scalar + Zero + ClosedAdd + ClosedMul {
|
||||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
|
||||||
{
|
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
unsafe {
|
unsafe {
|
||||||
let y = y.get_unchecked_mut(i * stride1);
|
let y = y.get_unchecked_mut(i * stride1);
|
||||||
@ -336,9 +333,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn array_ax<N>(y: &mut [N], a: N, x: &[N], stride1: usize, stride2: usize, len: usize)
|
fn array_ax<N>(y: &mut [N], a: N, x: &[N], stride1: usize, stride2: usize, len: usize)
|
||||||
where
|
where N: Scalar + Zero + ClosedAdd + ClosedMul {
|
||||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
|
||||||
{
|
|
||||||
for i in 0..len {
|
for i in 0..len {
|
||||||
unsafe {
|
unsafe {
|
||||||
*y.get_unchecked_mut(i * stride1) = a * *x.get_unchecked(i * stride2);
|
*y.get_unchecked_mut(i * stride1) = a * *x.get_unchecked(i * stride2);
|
||||||
@ -576,8 +571,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
|
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
|
||||||
where
|
where N: Scalar + Zero + ClosedAdd + ClosedMul
|
||||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
|
||||||
{
|
{
|
||||||
/// Computes `self = alpha * x * y.transpose() + beta * self`.
|
/// Computes `self = alpha * x * y.transpose() + beta * self`.
|
||||||
///
|
///
|
||||||
@ -817,8 +811,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
|
impl<N, R1: Dim, C1: Dim, S: StorageMut<N, R1, C1>> Matrix<N, R1, C1, S>
|
||||||
where
|
where N: Scalar + Zero + ClosedAdd + ClosedMul
|
||||||
N: Scalar + Zero + ClosedAdd + ClosedMul,
|
|
||||||
{
|
{
|
||||||
/// Computes `self = alpha * x * y.transpose() + beta * self`, where `self` is a **symmetric**
|
/// Computes `self = alpha * x * y.transpose() + beta * self`, where `self` is a **symmetric**
|
||||||
/// matrix.
|
/// matrix.
|
||||||
@ -876,8 +869,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N, D1: Dim, S: StorageMut<N, D1, D1>> SquareMatrix<N, D1, S>
|
impl<N, D1: Dim, S: StorageMut<N, D1, D1>> SquareMatrix<N, D1, S>
|
||||||
where
|
where N: Scalar + Zero + One + ClosedAdd + ClosedMul
|
||||||
N: Scalar + Zero + One + ClosedAdd + ClosedMul,
|
|
||||||
{
|
{
|
||||||
/// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`.
|
/// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`.
|
||||||
///
|
///
|
||||||
|
@ -238,9 +238,7 @@ impl<N: Scalar + Ring, D: DimName, S: StorageMut<N, D, D>> SquareMatrix<N, D, S>
|
|||||||
/// Computes in-place the transformation equal to `self` followed by an uniform scaling factor.
|
/// Computes in-place the transformation equal to `self` followed by an uniform scaling factor.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn append_scaling_mut(&mut self, scaling: N)
|
pub fn append_scaling_mut(&mut self, scaling: N)
|
||||||
where
|
where D: DimNameSub<U1> {
|
||||||
D: DimNameSub<U1>,
|
|
||||||
{
|
|
||||||
let mut to_scale = self.fixed_rows_mut::<DimNameDiff<D, U1>>(0);
|
let mut to_scale = self.fixed_rows_mut::<DimNameDiff<D, U1>>(0);
|
||||||
to_scale *= scaling;
|
to_scale *= scaling;
|
||||||
}
|
}
|
||||||
@ -248,9 +246,7 @@ impl<N: Scalar + Ring, D: DimName, S: StorageMut<N, D, D>> SquareMatrix<N, D, S>
|
|||||||
/// Computes in-place the transformation equal to an uniform scaling factor followed by `self`.
|
/// Computes in-place the transformation equal to an uniform scaling factor followed by `self`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn prepend_scaling_mut(&mut self, scaling: N)
|
pub fn prepend_scaling_mut(&mut self, scaling: N)
|
||||||
where
|
where D: DimNameSub<U1> {
|
||||||
D: DimNameSub<U1>,
|
|
||||||
{
|
|
||||||
let mut to_scale = self.fixed_columns_mut::<DimNameDiff<D, U1>>(0);
|
let mut to_scale = self.fixed_columns_mut::<DimNameDiff<D, U1>>(0);
|
||||||
to_scale *= scaling;
|
to_scale *= scaling;
|
||||||
}
|
}
|
||||||
@ -319,16 +315,16 @@ impl<N: Scalar + Ring, D: DimName, S: StorageMut<N, D, D>> SquareMatrix<N, D, S>
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Real, D: DimNameSub<U1>> Transformation<Point<N, DimNameDiff<D, U1>>> for MatrixN<N, D>
|
impl<N: Real, D: DimNameSub<U1>> Transformation<Point<N, DimNameDiff<D, U1>>> for MatrixN<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D, D>
|
|
||||||
+ Allocator<N, DimNameDiff<D, U1>>
|
+ Allocator<N, DimNameDiff<D, U1>>
|
||||||
+ Allocator<N, DimNameDiff<D, U1>, DimNameDiff<D, U1>>,
|
+ Allocator<N, DimNameDiff<D, U1>, DimNameDiff<D, U1>>
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn transform_vector(
|
fn transform_vector(
|
||||||
&self,
|
&self,
|
||||||
v: &VectorN<N, DimNameDiff<D, U1>>,
|
v: &VectorN<N, DimNameDiff<D, U1>>,
|
||||||
) -> VectorN<N, DimNameDiff<D, U1>> {
|
) -> VectorN<N, DimNameDiff<D, U1>>
|
||||||
|
{
|
||||||
let transform = self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0);
|
let transform = self.fixed_slice::<DimNameDiff<D, U1>, DimNameDiff<D, U1>>(0, 0);
|
||||||
let normalizer = self.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0);
|
let normalizer = self.fixed_slice::<U1, DimNameDiff<D, U1>>(D::dim() - 1, 0);
|
||||||
let n = normalizer.tr_dot(&v);
|
let n = normalizer.tr_dot(&v);
|
||||||
|
@ -8,8 +8,7 @@ pub struct ShapeConstraint;
|
|||||||
/// Constraints `C1` and `R2` to be equivalent.
|
/// Constraints `C1` and `R2` to be equivalent.
|
||||||
pub trait AreMultipliable<R1: Dim, C1: Dim, R2: Dim, C2: Dim>: DimEq<C1, R2> {}
|
pub trait AreMultipliable<R1: Dim, C1: Dim, R2: Dim, C2: Dim>: DimEq<C1, R2> {}
|
||||||
|
|
||||||
impl<R1: Dim, C1: Dim, R2: Dim, C2: Dim> AreMultipliable<R1, C1, R2, C2> for ShapeConstraint where
|
impl<R1: Dim, C1: Dim, R2: Dim, C2: Dim> AreMultipliable<R1, C1, R2, C2> for ShapeConstraint where ShapeConstraint: DimEq<C1, R2>
|
||||||
ShapeConstraint: DimEq<C1, R2>
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
/// Constraints `D1` and `D2` to be equivalent.
|
/// Constraints `D1` and `D2` to be equivalent.
|
||||||
|
@ -26,8 +26,7 @@ use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vector, Ve
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
impl<N: Scalar, R: Dim, C: Dim> MatrixMN<N, R, C>
|
impl<N: Scalar, R: Dim, C: Dim> MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
{
|
||||||
/// Creates a new uninitialized matrix. If the matrix has a compile-time dimension, this panics
|
/// Creates a new uninitialized matrix. If the matrix has a compile-time dimension, this panics
|
||||||
/// if `nrows != R::to_usize()` or `ncols != C::to_usize()`.
|
/// if `nrows != R::to_usize()` or `ncols != C::to_usize()`.
|
||||||
@ -55,18 +54,14 @@ where
|
|||||||
/// Creates a matrix with all its elements set to 0.
|
/// Creates a matrix with all its elements set to 0.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn zeros_generic(nrows: R, ncols: C) -> Self
|
pub fn zeros_generic(nrows: R, ncols: C) -> Self
|
||||||
where
|
where N: Zero {
|
||||||
N: Zero,
|
|
||||||
{
|
|
||||||
Self::from_element_generic(nrows, ncols, N::zero())
|
Self::from_element_generic(nrows, ncols, N::zero())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates a matrix with all its elements filled by an iterator.
|
/// Creates a matrix with all its elements filled by an iterator.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_iterator_generic<I>(nrows: R, ncols: C, iter: I) -> Self
|
pub fn from_iterator_generic<I>(nrows: R, ncols: C, iter: I) -> Self
|
||||||
where
|
where I: IntoIterator<Item = N> {
|
||||||
I: IntoIterator<Item = N>,
|
|
||||||
{
|
|
||||||
Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter))
|
Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,9 +100,7 @@ where
|
|||||||
/// coordinates.
|
/// coordinates.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_fn_generic<F>(nrows: R, ncols: C, mut f: F) -> Self
|
pub fn from_fn_generic<F>(nrows: R, ncols: C, mut f: F) -> Self
|
||||||
where
|
where F: FnMut(usize, usize) -> N {
|
||||||
F: FnMut(usize, usize) -> N,
|
|
||||||
{
|
|
||||||
let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols) };
|
let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols) };
|
||||||
|
|
||||||
for j in 0..ncols.value() {
|
for j in 0..ncols.value() {
|
||||||
@ -125,9 +118,7 @@ where
|
|||||||
/// to the identity matrix. All other entries are set to zero.
|
/// to the identity matrix. All other entries are set to zero.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn identity_generic(nrows: R, ncols: C) -> Self
|
pub fn identity_generic(nrows: R, ncols: C) -> Self
|
||||||
where
|
where N: Zero + One {
|
||||||
N: Zero + One,
|
|
||||||
{
|
|
||||||
Self::from_diagonal_element_generic(nrows, ncols, N::one())
|
Self::from_diagonal_element_generic(nrows, ncols, N::one())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,9 +128,7 @@ where
|
|||||||
/// to the identity matrix. All other entries are set to zero.
|
/// to the identity matrix. All other entries are set to zero.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: N) -> Self
|
pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: N) -> Self
|
||||||
where
|
where N: Zero + One {
|
||||||
N: Zero + One,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros_generic(nrows, ncols);
|
let mut res = Self::zeros_generic(nrows, ncols);
|
||||||
|
|
||||||
for i in 0..::min(nrows.value(), ncols.value()) {
|
for i in 0..::min(nrows.value(), ncols.value()) {
|
||||||
@ -155,9 +144,7 @@ where
|
|||||||
/// Panics if `elts.len()` is larger than the minimum among `nrows` and `ncols`.
|
/// Panics if `elts.len()` is larger than the minimum among `nrows` and `ncols`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[N]) -> Self
|
pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[N]) -> Self
|
||||||
where
|
where N: Zero {
|
||||||
N: Zero,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros_generic(nrows, ncols);
|
let mut res = Self::zeros_generic(nrows, ncols);
|
||||||
assert!(
|
assert!(
|
||||||
elts.len() <= ::min(nrows.value(), ncols.value()),
|
elts.len() <= ::min(nrows.value(), ncols.value()),
|
||||||
@ -177,9 +164,7 @@ where
|
|||||||
/// not have the same dimensions.
|
/// not have the same dimensions.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_rows<SB>(rows: &[Matrix<N, U1, C, SB>]) -> Self
|
pub fn from_rows<SB>(rows: &[Matrix<N, U1, C, SB>]) -> Self
|
||||||
where
|
where SB: Storage<N, U1, C> {
|
||||||
SB: Storage<N, U1, C>,
|
|
||||||
{
|
|
||||||
assert!(rows.len() > 0, "At least one row must be given.");
|
assert!(rows.len() > 0, "At least one row must be given.");
|
||||||
let nrows = R::try_to_usize().unwrap_or(rows.len());
|
let nrows = R::try_to_usize().unwrap_or(rows.len());
|
||||||
let ncols = rows[0].len();
|
let ncols = rows[0].len();
|
||||||
@ -207,9 +192,7 @@ where
|
|||||||
/// columns do not have the same dimensions.
|
/// columns do not have the same dimensions.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_columns<SB>(columns: &[Vector<N, R, SB>]) -> Self
|
pub fn from_columns<SB>(columns: &[Vector<N, R, SB>]) -> Self
|
||||||
where
|
where SB: Storage<N, R> {
|
||||||
SB: Storage<N, R>,
|
|
||||||
{
|
|
||||||
assert!(columns.len() > 0, "At least one column must be given.");
|
assert!(columns.len() > 0, "At least one column must be given.");
|
||||||
let ncols = C::try_to_usize().unwrap_or(columns.len());
|
let ncols = C::try_to_usize().unwrap_or(columns.len());
|
||||||
let nrows = columns[0].len();
|
let nrows = columns[0].len();
|
||||||
@ -235,9 +218,7 @@ where
|
|||||||
#[inline]
|
#[inline]
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn new_random_generic(nrows: R, ncols: C) -> Self
|
pub fn new_random_generic(nrows: R, ncols: C) -> Self
|
||||||
where
|
where Standard: Distribution<N> {
|
||||||
Standard: Distribution<N>,
|
|
||||||
{
|
|
||||||
Self::from_fn_generic(nrows, ncols, |_, _| rand::random())
|
Self::from_fn_generic(nrows, ncols, |_, _| rand::random())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,7 +229,8 @@ where
|
|||||||
ncols: C,
|
ncols: C,
|
||||||
distribution: &mut Distr,
|
distribution: &mut Distr,
|
||||||
rng: &mut G,
|
rng: &mut G,
|
||||||
) -> Self {
|
) -> Self
|
||||||
|
{
|
||||||
Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng))
|
Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -261,9 +243,7 @@ where
|
|||||||
/// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0.
|
/// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_diagonal<SB: Storage<N, D>>(diag: &Vector<N, D, SB>) -> Self
|
pub fn from_diagonal<SB: Storage<N, D>>(diag: &Vector<N, D, SB>) -> Self
|
||||||
where
|
where N: Zero {
|
||||||
N: Zero,
|
|
||||||
{
|
|
||||||
let (dim, _) = diag.data.shape();
|
let (dim, _) = diag.data.shape();
|
||||||
let mut res = Self::zeros_generic(dim, dim);
|
let mut res = Self::zeros_generic(dim, dim);
|
||||||
|
|
||||||
@ -703,9 +683,7 @@ where
|
|||||||
/// The column vector with a 1 as its first component, and zero elsewhere.
|
/// The column vector with a 1 as its first component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn x() -> Self
|
pub fn x() -> Self
|
||||||
where
|
where R::Value: Cmp<typenum::U0, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U0, Output = Greater>,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros();
|
let mut res = Self::zeros();
|
||||||
unsafe {
|
unsafe {
|
||||||
*res.vget_unchecked_mut(0) = N::one();
|
*res.vget_unchecked_mut(0) = N::one();
|
||||||
@ -717,9 +695,7 @@ where
|
|||||||
/// The column vector with a 1 as its second component, and zero elsewhere.
|
/// The column vector with a 1 as its second component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn y() -> Self
|
pub fn y() -> Self
|
||||||
where
|
where R::Value: Cmp<typenum::U1, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U1, Output = Greater>,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros();
|
let mut res = Self::zeros();
|
||||||
unsafe {
|
unsafe {
|
||||||
*res.vget_unchecked_mut(1) = N::one();
|
*res.vget_unchecked_mut(1) = N::one();
|
||||||
@ -731,9 +707,7 @@ where
|
|||||||
/// The column vector with a 1 as its third component, and zero elsewhere.
|
/// The column vector with a 1 as its third component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn z() -> Self
|
pub fn z() -> Self
|
||||||
where
|
where R::Value: Cmp<typenum::U2, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U2, Output = Greater>,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros();
|
let mut res = Self::zeros();
|
||||||
unsafe {
|
unsafe {
|
||||||
*res.vget_unchecked_mut(2) = N::one();
|
*res.vget_unchecked_mut(2) = N::one();
|
||||||
@ -745,9 +719,7 @@ where
|
|||||||
/// The column vector with a 1 as its fourth component, and zero elsewhere.
|
/// The column vector with a 1 as its fourth component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn w() -> Self
|
pub fn w() -> Self
|
||||||
where
|
where R::Value: Cmp<typenum::U3, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U3, Output = Greater>,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros();
|
let mut res = Self::zeros();
|
||||||
unsafe {
|
unsafe {
|
||||||
*res.vget_unchecked_mut(3) = N::one();
|
*res.vget_unchecked_mut(3) = N::one();
|
||||||
@ -759,9 +731,7 @@ where
|
|||||||
/// The column vector with a 1 as its fifth component, and zero elsewhere.
|
/// The column vector with a 1 as its fifth component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn a() -> Self
|
pub fn a() -> Self
|
||||||
where
|
where R::Value: Cmp<typenum::U4, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U4, Output = Greater>,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros();
|
let mut res = Self::zeros();
|
||||||
unsafe {
|
unsafe {
|
||||||
*res.vget_unchecked_mut(4) = N::one();
|
*res.vget_unchecked_mut(4) = N::one();
|
||||||
@ -773,9 +743,7 @@ where
|
|||||||
/// The column vector with a 1 as its sixth component, and zero elsewhere.
|
/// The column vector with a 1 as its sixth component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn b() -> Self
|
pub fn b() -> Self
|
||||||
where
|
where R::Value: Cmp<typenum::U5, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U5, Output = Greater>,
|
|
||||||
{
|
|
||||||
let mut res = Self::zeros();
|
let mut res = Self::zeros();
|
||||||
unsafe {
|
unsafe {
|
||||||
*res.vget_unchecked_mut(5) = N::one();
|
*res.vget_unchecked_mut(5) = N::one();
|
||||||
@ -787,54 +755,42 @@ where
|
|||||||
/// The unit column vector with a 1 as its first component, and zero elsewhere.
|
/// The unit column vector with a 1 as its first component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn x_axis() -> Unit<Self>
|
pub fn x_axis() -> Unit<Self>
|
||||||
where
|
where R::Value: Cmp<typenum::U0, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U0, Output = Greater>,
|
|
||||||
{
|
|
||||||
Unit::new_unchecked(Self::x())
|
Unit::new_unchecked(Self::x())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unit column vector with a 1 as its second component, and zero elsewhere.
|
/// The unit column vector with a 1 as its second component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn y_axis() -> Unit<Self>
|
pub fn y_axis() -> Unit<Self>
|
||||||
where
|
where R::Value: Cmp<typenum::U1, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U1, Output = Greater>,
|
|
||||||
{
|
|
||||||
Unit::new_unchecked(Self::y())
|
Unit::new_unchecked(Self::y())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unit column vector with a 1 as its third component, and zero elsewhere.
|
/// The unit column vector with a 1 as its third component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn z_axis() -> Unit<Self>
|
pub fn z_axis() -> Unit<Self>
|
||||||
where
|
where R::Value: Cmp<typenum::U2, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U2, Output = Greater>,
|
|
||||||
{
|
|
||||||
Unit::new_unchecked(Self::z())
|
Unit::new_unchecked(Self::z())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unit column vector with a 1 as its fourth component, and zero elsewhere.
|
/// The unit column vector with a 1 as its fourth component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn w_axis() -> Unit<Self>
|
pub fn w_axis() -> Unit<Self>
|
||||||
where
|
where R::Value: Cmp<typenum::U3, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U3, Output = Greater>,
|
|
||||||
{
|
|
||||||
Unit::new_unchecked(Self::w())
|
Unit::new_unchecked(Self::w())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unit column vector with a 1 as its fifth component, and zero elsewhere.
|
/// The unit column vector with a 1 as its fifth component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn a_axis() -> Unit<Self>
|
pub fn a_axis() -> Unit<Self>
|
||||||
where
|
where R::Value: Cmp<typenum::U4, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U4, Output = Greater>,
|
|
||||||
{
|
|
||||||
Unit::new_unchecked(Self::a())
|
Unit::new_unchecked(Self::a())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The unit column vector with a 1 as its sixth component, and zero elsewhere.
|
/// The unit column vector with a 1 as its sixth component, and zero elsewhere.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn b_axis() -> Unit<Self>
|
pub fn b_axis() -> Unit<Self>
|
||||||
where
|
where R::Value: Cmp<typenum::U5, Output = Greater> {
|
||||||
R::Value: Cmp<typenum::U5, Output = Greater>,
|
|
||||||
{
|
|
||||||
Unit::new_unchecked(Self::b())
|
Unit::new_unchecked(Self::b())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
|||||||
ncols: C,
|
ncols: C,
|
||||||
rstride: RStride,
|
rstride: RStride,
|
||||||
cstride: CStride,
|
cstride: CStride,
|
||||||
) -> Self {
|
) -> Self
|
||||||
|
{
|
||||||
let data = SliceStorage::from_raw_parts(
|
let data = SliceStorage::from_raw_parts(
|
||||||
data.as_ptr().offset(start as isize),
|
data.as_ptr().offset(start as isize),
|
||||||
(nrows, ncols),
|
(nrows, ncols),
|
||||||
@ -42,7 +43,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
|||||||
ncols: C,
|
ncols: C,
|
||||||
rstride: RStride,
|
rstride: RStride,
|
||||||
cstride: CStride,
|
cstride: CStride,
|
||||||
) -> Self {
|
) -> Self
|
||||||
|
{
|
||||||
// NOTE: The assertion implements the following formula, but without subtractions to avoid
|
// NOTE: The assertion implements the following formula, but without subtractions to avoid
|
||||||
// underflow panics:
|
// underflow panics:
|
||||||
// len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1
|
// len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1
|
||||||
@ -73,7 +75,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
|||||||
ncols: C,
|
ncols: C,
|
||||||
rstride: RStride,
|
rstride: RStride,
|
||||||
cstride: CStride,
|
cstride: CStride,
|
||||||
) -> Self {
|
) -> Self
|
||||||
|
{
|
||||||
let data = SliceStorageMut::from_raw_parts(
|
let data = SliceStorageMut::from_raw_parts(
|
||||||
data.as_mut_ptr().offset(start as isize),
|
data.as_mut_ptr().offset(start as isize),
|
||||||
(nrows, ncols),
|
(nrows, ncols),
|
||||||
@ -93,7 +96,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
|||||||
ncols: C,
|
ncols: C,
|
||||||
rstride: RStride,
|
rstride: RStride,
|
||||||
cstride: CStride,
|
cstride: CStride,
|
||||||
) -> Self {
|
) -> Self
|
||||||
|
{
|
||||||
// NOTE: The assertion implements the following formula, but without subtractions to avoid
|
// NOTE: The assertion implements the following formula, but without subtractions to avoid
|
||||||
// underflow panics:
|
// underflow panics:
|
||||||
// len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1
|
// len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1
|
||||||
@ -120,7 +124,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> {
|
|||||||
start: usize,
|
start: usize,
|
||||||
nrows: R,
|
nrows: R,
|
||||||
ncols: C,
|
ncols: C,
|
||||||
) -> Self {
|
) -> Self
|
||||||
|
{
|
||||||
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
|
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +150,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> {
|
|||||||
start: usize,
|
start: usize,
|
||||||
nrows: R,
|
nrows: R,
|
||||||
ncols: C,
|
ncols: C,
|
||||||
) -> Self {
|
) -> Self
|
||||||
|
{
|
||||||
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
|
Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,8 @@ where
|
|||||||
nrows: R,
|
nrows: R,
|
||||||
ncols: C,
|
ncols: C,
|
||||||
iter: I,
|
iter: I,
|
||||||
) -> Self::Buffer {
|
) -> Self::Buffer
|
||||||
|
{
|
||||||
let mut res = unsafe { Self::allocate_uninitialized(nrows, ncols) };
|
let mut res = unsafe { Self::allocate_uninitialized(nrows, ncols) };
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
|
|
||||||
@ -93,7 +94,8 @@ impl<N: Scalar, C: Dim> Allocator<N, Dynamic, C> for DefaultAllocator {
|
|||||||
nrows: Dynamic,
|
nrows: Dynamic,
|
||||||
ncols: C,
|
ncols: C,
|
||||||
iter: I,
|
iter: I,
|
||||||
) -> Self::Buffer {
|
) -> Self::Buffer
|
||||||
|
{
|
||||||
let it = iter.into_iter();
|
let it = iter.into_iter();
|
||||||
let res: Vec<N> = it.collect();
|
let res: Vec<N> = it.collect();
|
||||||
assert!(res.len() == nrows.value() * ncols.value(),
|
assert!(res.len() == nrows.value() * ncols.value(),
|
||||||
@ -123,7 +125,8 @@ impl<N: Scalar, R: DimName> Allocator<N, R, Dynamic> for DefaultAllocator {
|
|||||||
nrows: R,
|
nrows: R,
|
||||||
ncols: Dynamic,
|
ncols: Dynamic,
|
||||||
iter: I,
|
iter: I,
|
||||||
) -> Self::Buffer {
|
) -> Self::Buffer
|
||||||
|
{
|
||||||
let it = iter.into_iter();
|
let it = iter.into_iter();
|
||||||
let res: Vec<N> = it.collect();
|
let res: Vec<N> = it.collect();
|
||||||
assert!(res.len() == nrows.value() * ncols.value(),
|
assert!(res.len() == nrows.value() * ncols.value(),
|
||||||
@ -154,7 +157,8 @@ where
|
|||||||
rto: RTo,
|
rto: RTo,
|
||||||
cto: CTo,
|
cto: CTo,
|
||||||
buf: <Self as Allocator<N, RFrom, CFrom>>::Buffer,
|
buf: <Self as Allocator<N, RFrom, CFrom>>::Buffer,
|
||||||
) -> MatrixArray<N, RTo, CTo> {
|
) -> MatrixArray<N, RTo, CTo>
|
||||||
|
{
|
||||||
let mut res = <Self as Allocator<N, RTo, CTo>>::allocate_uninitialized(rto, cto);
|
let mut res = <Self as Allocator<N, RTo, CTo>>::allocate_uninitialized(rto, cto);
|
||||||
|
|
||||||
let (rfrom, cfrom) = buf.shape();
|
let (rfrom, cfrom) = buf.shape();
|
||||||
@ -182,7 +186,8 @@ where
|
|||||||
rto: Dynamic,
|
rto: Dynamic,
|
||||||
cto: CTo,
|
cto: CTo,
|
||||||
buf: MatrixArray<N, RFrom, CFrom>,
|
buf: MatrixArray<N, RFrom, CFrom>,
|
||||||
) -> MatrixVec<N, Dynamic, CTo> {
|
) -> MatrixVec<N, Dynamic, CTo>
|
||||||
|
{
|
||||||
let mut res = <Self as Allocator<N, Dynamic, CTo>>::allocate_uninitialized(rto, cto);
|
let mut res = <Self as Allocator<N, Dynamic, CTo>>::allocate_uninitialized(rto, cto);
|
||||||
|
|
||||||
let (rfrom, cfrom) = buf.shape();
|
let (rfrom, cfrom) = buf.shape();
|
||||||
@ -210,7 +215,8 @@ where
|
|||||||
rto: RTo,
|
rto: RTo,
|
||||||
cto: Dynamic,
|
cto: Dynamic,
|
||||||
buf: MatrixArray<N, RFrom, CFrom>,
|
buf: MatrixArray<N, RFrom, CFrom>,
|
||||||
) -> MatrixVec<N, RTo, Dynamic> {
|
) -> MatrixVec<N, RTo, Dynamic>
|
||||||
|
{
|
||||||
let mut res = <Self as Allocator<N, RTo, Dynamic>>::allocate_uninitialized(rto, cto);
|
let mut res = <Self as Allocator<N, RTo, Dynamic>>::allocate_uninitialized(rto, cto);
|
||||||
|
|
||||||
let (rfrom, cfrom) = buf.shape();
|
let (rfrom, cfrom) = buf.shape();
|
||||||
@ -233,7 +239,8 @@ impl<N: Scalar, CFrom: Dim, CTo: Dim> Reallocator<N, Dynamic, CFrom, Dynamic, CT
|
|||||||
rto: Dynamic,
|
rto: Dynamic,
|
||||||
cto: CTo,
|
cto: CTo,
|
||||||
buf: MatrixVec<N, Dynamic, CFrom>,
|
buf: MatrixVec<N, Dynamic, CFrom>,
|
||||||
) -> MatrixVec<N, Dynamic, CTo> {
|
) -> MatrixVec<N, Dynamic, CTo>
|
||||||
|
{
|
||||||
let new_buf = buf.resize(rto.value() * cto.value());
|
let new_buf = buf.resize(rto.value() * cto.value());
|
||||||
MatrixVec::new(rto, cto, new_buf)
|
MatrixVec::new(rto, cto, new_buf)
|
||||||
}
|
}
|
||||||
@ -248,7 +255,8 @@ impl<N: Scalar, CFrom: Dim, RTo: DimName> Reallocator<N, Dynamic, CFrom, RTo, Dy
|
|||||||
rto: RTo,
|
rto: RTo,
|
||||||
cto: Dynamic,
|
cto: Dynamic,
|
||||||
buf: MatrixVec<N, Dynamic, CFrom>,
|
buf: MatrixVec<N, Dynamic, CFrom>,
|
||||||
) -> MatrixVec<N, RTo, Dynamic> {
|
) -> MatrixVec<N, RTo, Dynamic>
|
||||||
|
{
|
||||||
let new_buf = buf.resize(rto.value() * cto.value());
|
let new_buf = buf.resize(rto.value() * cto.value());
|
||||||
MatrixVec::new(rto, cto, new_buf)
|
MatrixVec::new(rto, cto, new_buf)
|
||||||
}
|
}
|
||||||
@ -263,7 +271,8 @@ impl<N: Scalar, RFrom: DimName, CTo: Dim> Reallocator<N, RFrom, Dynamic, Dynamic
|
|||||||
rto: Dynamic,
|
rto: Dynamic,
|
||||||
cto: CTo,
|
cto: CTo,
|
||||||
buf: MatrixVec<N, RFrom, Dynamic>,
|
buf: MatrixVec<N, RFrom, Dynamic>,
|
||||||
) -> MatrixVec<N, Dynamic, CTo> {
|
) -> MatrixVec<N, Dynamic, CTo>
|
||||||
|
{
|
||||||
let new_buf = buf.resize(rto.value() * cto.value());
|
let new_buf = buf.resize(rto.value() * cto.value());
|
||||||
MatrixVec::new(rto, cto, new_buf)
|
MatrixVec::new(rto, cto, new_buf)
|
||||||
}
|
}
|
||||||
@ -278,7 +287,8 @@ impl<N: Scalar, RFrom: DimName, RTo: DimName> Reallocator<N, RFrom, Dynamic, RTo
|
|||||||
rto: RTo,
|
rto: RTo,
|
||||||
cto: Dynamic,
|
cto: Dynamic,
|
||||||
buf: MatrixVec<N, RFrom, Dynamic>,
|
buf: MatrixVec<N, RFrom, Dynamic>,
|
||||||
) -> MatrixVec<N, RTo, Dynamic> {
|
) -> MatrixVec<N, RTo, Dynamic>
|
||||||
|
{
|
||||||
let new_buf = buf.resize(rto.value() * cto.value());
|
let new_buf = buf.resize(rto.value() * cto.value());
|
||||||
MatrixVec::new(rto, cto, new_buf)
|
MatrixVec::new(rto, cto, new_buf)
|
||||||
}
|
}
|
||||||
|
@ -30,9 +30,7 @@ impl Dynamic {
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
impl Serialize for Dynamic {
|
impl Serialize for Dynamic {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where S: Serializer {
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
self.value.serialize(serializer)
|
self.value.serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,9 +38,7 @@ impl Serialize for Dynamic {
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
impl<'de> Deserialize<'de> for Dynamic {
|
impl<'de> Deserialize<'de> for Dynamic {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where D: Deserializer<'de> {
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
usize::deserialize(deserializer).map(|x| Dynamic { value: x })
|
usize::deserialize(deserializer).map(|x| Dynamic { value: x })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,7 +364,8 @@ impl<
|
|||||||
G: Bit + Any + Debug + Copy + PartialEq + Send + Sync,
|
G: Bit + Any + Debug + Copy + PartialEq + Send + Sync,
|
||||||
> IsNotStaticOne
|
> IsNotStaticOne
|
||||||
for UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, A>, B>, C>, D>, E>, F>, G>
|
for UInt<UInt<UInt<UInt<UInt<UInt<UInt<UInt<UTerm, B1>, A>, B>, C>, D>, E>, F>, G>
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
impl<U: Unsigned + DimName, B: Bit + Any + Debug + Copy + PartialEq + Send + Sync> NamedDim
|
impl<U: Unsigned + DimName, B: Bit + Any + Debug + Copy + PartialEq + Send + Sync> NamedDim
|
||||||
for UInt<U, B>
|
for UInt<U, B>
|
||||||
@ -409,4 +406,5 @@ impl<U: Unsigned + DimName, B: Bit + Any + Debug + Copy + PartialEq + Send + Syn
|
|||||||
|
|
||||||
impl<U: Unsigned + DimName, B: Bit + Any + Debug + Copy + PartialEq + Send + Sync> IsNotStaticOne
|
impl<U: Unsigned + DimName, B: Bit + Any + Debug + Copy + PartialEq + Send + Sync> IsNotStaticOne
|
||||||
for UInt<U, B>
|
for UInt<U, B>
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
@ -16,9 +16,7 @@ impl<N: Scalar + Zero, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Extracts the upper triangular part of this matrix (including the diagonal).
|
/// Extracts the upper triangular part of this matrix (including the diagonal).
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn upper_triangle(&self) -> MatrixMN<N, R, C>
|
pub fn upper_triangle(&self) -> MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
let mut res = self.clone_owned();
|
let mut res = self.clone_owned();
|
||||||
res.fill_lower_triangle(N::zero(), 1);
|
res.fill_lower_triangle(N::zero(), 1);
|
||||||
|
|
||||||
@ -28,9 +26,7 @@ impl<N: Scalar + Zero, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Extracts the upper triangular part of this matrix (including the diagonal).
|
/// Extracts the upper triangular part of this matrix (including the diagonal).
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn lower_triangle(&self) -> MatrixMN<N, R, C>
|
pub fn lower_triangle(&self) -> MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
let mut res = self.clone_owned();
|
let mut res = self.clone_owned();
|
||||||
res.fill_upper_triangle(N::zero(), 1);
|
res.fill_upper_triangle(N::zero(), 1);
|
||||||
|
|
||||||
@ -50,9 +46,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Fills `self` with the identity matrix.
|
/// Fills `self` with the identity matrix.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fill_with_identity(&mut self)
|
pub fn fill_with_identity(&mut self)
|
||||||
where
|
where N: Zero + One {
|
||||||
N: Zero + One,
|
|
||||||
{
|
|
||||||
self.fill(N::zero());
|
self.fill(N::zero());
|
||||||
self.fill_diagonal(N::one());
|
self.fill_diagonal(N::one());
|
||||||
}
|
}
|
||||||
@ -551,9 +545,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// rows and/or columns than `self`, then the extra rows or columns are filled with `val`.
|
/// rows and/or columns than `self`, then the extra rows or columns are filled with `val`.
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(any(feature = "std", feature = "alloc"))]
|
||||||
pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix<N>
|
pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix<N>
|
||||||
where
|
where DefaultAllocator: Reallocator<N, R, C, Dynamic, Dynamic> {
|
||||||
DefaultAllocator: Reallocator<N, R, C, Dynamic, Dynamic>,
|
|
||||||
{
|
|
||||||
self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val)
|
self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,9 +554,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more
|
/// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more
|
||||||
/// rows and/or columns than `self`, then the extra rows or columns are filled with `val`.
|
/// rows and/or columns than `self`, then the extra rows or columns are filled with `val`.
|
||||||
pub fn fixed_resize<R2: DimName, C2: DimName>(self, val: N) -> MatrixMN<N, R2, C2>
|
pub fn fixed_resize<R2: DimName, C2: DimName>(self, val: N) -> MatrixMN<N, R2, C2>
|
||||||
where
|
where DefaultAllocator: Reallocator<N, R, C, R2, C2> {
|
||||||
DefaultAllocator: Reallocator<N, R, C, R2, C2>,
|
|
||||||
{
|
|
||||||
self.resize_generic(R2::name(), C2::name(), val)
|
self.resize_generic(R2::name(), C2::name(), val)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,7 +632,8 @@ unsafe fn compress_rows<N: Scalar>(
|
|||||||
ncols: usize,
|
ncols: usize,
|
||||||
i: usize,
|
i: usize,
|
||||||
nremove: usize,
|
nremove: usize,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let new_nrows = nrows - nremove;
|
let new_nrows = nrows - nremove;
|
||||||
|
|
||||||
if new_nrows == 0 || ncols == 0 {
|
if new_nrows == 0 || ncols == 0 {
|
||||||
@ -681,7 +672,8 @@ unsafe fn extend_rows<N: Scalar>(
|
|||||||
ncols: usize,
|
ncols: usize,
|
||||||
i: usize,
|
i: usize,
|
||||||
ninsert: usize,
|
ninsert: usize,
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let new_nrows = nrows + ninsert;
|
let new_nrows = nrows + ninsert;
|
||||||
|
|
||||||
if new_nrows == 0 || ncols == 0 {
|
if new_nrows == 0 || ncols == 0 {
|
||||||
|
@ -18,9 +18,7 @@ pub fn reject<G: Gen, F: FnMut(&T) -> bool, T: Arbitrary>(g: &mut G, f: F) -> T
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn reject_rand<G: Rng + ?Sized, F: FnMut(&T) -> bool, T>(g: &mut G, f: F) -> T
|
pub fn reject_rand<G: Rng + ?Sized, F: FnMut(&T) -> bool, T>(g: &mut G, f: F) -> T
|
||||||
where
|
where Standard: Distribution<T> {
|
||||||
Standard: Distribution<T>,
|
|
||||||
{
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
iter::repeat(()).map(|_| g.gen()).find(f).unwrap()
|
iter::repeat(()).map(|_| g.gen()).find(f).unwrap()
|
||||||
}
|
}
|
||||||
|
@ -99,9 +99,7 @@ where
|
|||||||
S: Serialize,
|
S: Serialize,
|
||||||
{
|
{
|
||||||
fn serialize<T>(&self, serializer: T) -> Result<T::Ok, T::Error>
|
fn serialize<T>(&self, serializer: T) -> Result<T::Ok, T::Error>
|
||||||
where
|
where T: Serializer {
|
||||||
T: Serializer,
|
|
||||||
{
|
|
||||||
self.data.serialize(serializer)
|
self.data.serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,9 +113,7 @@ where
|
|||||||
S: Deserialize<'de>,
|
S: Deserialize<'de>,
|
||||||
{
|
{
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where D: Deserializer<'de> {
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
S::deserialize(deserializer).map(|x| Matrix {
|
S::deserialize(deserializer).map(|x| Matrix {
|
||||||
data: x,
|
data: x,
|
||||||
_phantoms: PhantomData,
|
_phantoms: PhantomData,
|
||||||
@ -319,9 +315,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Moves this matrix into one that owns its data.
|
/// Moves this matrix into one that owns its data.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn into_owned(self) -> MatrixMN<N, R, C>
|
pub fn into_owned(self) -> MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
Matrix::from_data(self.data.into_owned())
|
Matrix::from_data(self.data.into_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,9 +349,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Clones this matrix to one that owns its data.
|
/// Clones this matrix to one that owns its data.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn clone_owned(&self) -> MatrixMN<N, R, C>
|
pub fn clone_owned(&self) -> MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
Matrix::from_data(self.data.clone_owned())
|
Matrix::from_data(self.data.clone_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -393,9 +385,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Returns a matrix containing the result of `f` applied to each of its entries.
|
/// Returns a matrix containing the result of `f` applied to each of its entries.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn map<N2: Scalar, F: FnMut(N) -> N2>(&self, mut f: F) -> MatrixMN<N2, R, C>
|
pub fn map<N2: Scalar, F: FnMut(N) -> N2>(&self, mut f: F) -> MatrixMN<N2, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N2, R, C> {
|
||||||
DefaultAllocator: Allocator<N2, R, C>,
|
|
||||||
{
|
|
||||||
let (nrows, ncols) = self.data.shape();
|
let (nrows, ncols) = self.data.shape();
|
||||||
|
|
||||||
let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols) };
|
let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols) };
|
||||||
@ -541,9 +531,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Transposes `self`.
|
/// Transposes `self`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn transpose(&self) -> MatrixMN<N, C, R>
|
pub fn transpose(&self) -> MatrixMN<N, C, R>
|
||||||
where
|
where DefaultAllocator: Allocator<N, C, R> {
|
||||||
DefaultAllocator: Allocator<N, C, R>,
|
|
||||||
{
|
|
||||||
let (nrows, ncols) = self.data.shape();
|
let (nrows, ncols) = self.data.shape();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -666,9 +654,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Replaces each component of `self` by the result of a closure `f` applied on it.
|
/// Replaces each component of `self` by the result of a closure `f` applied on it.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn apply<F: FnMut(N) -> N>(&mut self, mut f: F)
|
pub fn apply<F: FnMut(N) -> N>(&mut self, mut f: F)
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
let (nrows, ncols) = self.shape();
|
let (nrows, ncols) = self.shape();
|
||||||
|
|
||||||
for j in 0..ncols {
|
for j in 0..ncols {
|
||||||
@ -765,9 +751,7 @@ impl<N: Real, R: Dim, C: Dim, S: Storage<Complex<N>, R, C>> Matrix<Complex<N>, R
|
|||||||
/// The conjugate transposition of `self`.
|
/// The conjugate transposition of `self`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn conjugate_transpose(&self) -> MatrixMN<Complex<N>, C, R>
|
pub fn conjugate_transpose(&self) -> MatrixMN<Complex<N>, C, R>
|
||||||
where
|
where DefaultAllocator: Allocator<Complex<N>, C, R> {
|
||||||
DefaultAllocator: Allocator<Complex<N>, C, R>,
|
|
||||||
{
|
|
||||||
let (nrows, ncols) = self.data.shape();
|
let (nrows, ncols) = self.data.shape();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
@ -808,9 +792,7 @@ impl<N: Scalar, D: Dim, S: Storage<N, D, D>> SquareMatrix<N, D, S> {
|
|||||||
/// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0.
|
/// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn diagonal(&self) -> VectorN<N, D>
|
pub fn diagonal(&self) -> VectorN<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D> {
|
||||||
DefaultAllocator: Allocator<N, D>,
|
|
||||||
{
|
|
||||||
assert!(
|
assert!(
|
||||||
self.is_square(),
|
self.is_square(),
|
||||||
"Unable to get the diagonal of a non-square matrix."
|
"Unable to get the diagonal of a non-square matrix."
|
||||||
@ -831,9 +813,7 @@ impl<N: Scalar, D: Dim, S: Storage<N, D, D>> SquareMatrix<N, D, S> {
|
|||||||
/// Computes a trace of a square matrix, i.e., the sum of its diagonal elements.
|
/// Computes a trace of a square matrix, i.e., the sum of its diagonal elements.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn trace(&self) -> N
|
pub fn trace(&self) -> N
|
||||||
where
|
where N: Ring {
|
||||||
N: Ring,
|
|
||||||
{
|
|
||||||
assert!(
|
assert!(
|
||||||
self.is_square(),
|
self.is_square(),
|
||||||
"Cannot compute the trace of non-square matrix."
|
"Cannot compute the trace of non-square matrix."
|
||||||
@ -855,9 +835,7 @@ impl<N: Scalar + Zero, D: DimAdd<U1>, S: Storage<N, D>> Vector<N, D, S> {
|
|||||||
/// coordinates.
|
/// coordinates.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_homogeneous(&self) -> VectorN<N, DimSum<D, U1>>
|
pub fn to_homogeneous(&self) -> VectorN<N, DimSum<D, U1>>
|
||||||
where
|
where DefaultAllocator: Allocator<N, DimSum<D, U1>> {
|
||||||
DefaultAllocator: Allocator<N, DimSum<D, U1>>,
|
|
||||||
{
|
|
||||||
let len = self.len();
|
let len = self.len();
|
||||||
let hnrows = DimSum::<D, U1>::from_usize(len + 1);
|
let hnrows = DimSum::<D, U1>::from_usize(len + 1);
|
||||||
let mut res = unsafe { VectorN::<N, _>::new_uninitialized_generic(hnrows, U1) };
|
let mut res = unsafe { VectorN::<N, _>::new_uninitialized_generic(hnrows, U1) };
|
||||||
@ -923,7 +901,8 @@ where
|
|||||||
other: &Self,
|
other: &Self,
|
||||||
epsilon: Self::Epsilon,
|
epsilon: Self::Epsilon,
|
||||||
max_relative: Self::Epsilon,
|
max_relative: Self::Epsilon,
|
||||||
) -> bool {
|
) -> bool
|
||||||
|
{
|
||||||
self.relative_eq(other, epsilon, max_relative)
|
self.relative_eq(other, epsilon, max_relative)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1040,7 +1019,8 @@ impl<N, R: Dim, C: Dim, S> Eq for Matrix<N, R, C, S>
|
|||||||
where
|
where
|
||||||
N: Scalar + Eq,
|
N: Scalar + Eq,
|
||||||
S: Storage<N, R, C>,
|
S: Storage<N, R, C>,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
impl<N, R: Dim, C: Dim, S> PartialEq for Matrix<N, R, C, S>
|
impl<N, R: Dim, C: Dim, S> PartialEq for Matrix<N, R, C, S>
|
||||||
where
|
where
|
||||||
@ -1220,8 +1200,7 @@ impl<N: Scalar + Ring, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Real, S: Storage<N, U3>> Vector<N, U3, S>
|
impl<N: Real, S: Storage<N, U3>> Vector<N, U3, S>
|
||||||
where
|
where DefaultAllocator: Allocator<N, U3>
|
||||||
DefaultAllocator: Allocator<N, U3>,
|
|
||||||
{
|
{
|
||||||
/// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`.
|
/// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`.
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -1311,18 +1290,14 @@ impl<N: Real, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
/// Returns a normalized version of this matrix.
|
/// Returns a normalized version of this matrix.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn normalize(&self) -> MatrixMN<N, R, C>
|
pub fn normalize(&self) -> MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
self / self.norm()
|
self / self.norm()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a normalized version of this matrix unless its norm as smaller or equal to `eps`.
|
/// Returns a normalized version of this matrix unless its norm as smaller or equal to `eps`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn try_normalize(&self, min_norm: N) -> Option<MatrixMN<N, R, C>>
|
pub fn try_normalize(&self, min_norm: N) -> Option<MatrixMN<N, R, C>>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
let n = self.norm();
|
let n = self.norm();
|
||||||
|
|
||||||
if n <= min_norm {
|
if n <= min_norm {
|
||||||
@ -1446,7 +1421,8 @@ where
|
|||||||
other: &Self,
|
other: &Self,
|
||||||
epsilon: Self::Epsilon,
|
epsilon: Self::Epsilon,
|
||||||
max_relative: Self::Epsilon,
|
max_relative: Self::Epsilon,
|
||||||
) -> bool {
|
) -> bool
|
||||||
|
{
|
||||||
self.as_ref()
|
self.as_ref()
|
||||||
.relative_eq(other.as_ref(), epsilon, max_relative)
|
.relative_eq(other.as_ref(), epsilon, max_relative)
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Real, R: DimName, C: DimName> NormedSpace for MatrixMN<N, R, C>
|
impl<N: Real, R: DimName, C: DimName> NormedSpace for MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn norm_squared(&self) -> N {
|
fn norm_squared(&self) -> N {
|
||||||
@ -181,8 +180,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Real, R: DimName, C: DimName> InnerSpace for MatrixMN<N, R, C>
|
impl<N: Real, R: DimName, C: DimName> InnerSpace for MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
{
|
||||||
type Real = N;
|
type Real = N;
|
||||||
|
|
||||||
@ -202,8 +200,7 @@ where
|
|||||||
// − use `x()` instead of `::canonical_basis_element`
|
// − use `x()` instead of `::canonical_basis_element`
|
||||||
// − use `::new(x, y, z)` instead of `::from_slice`
|
// − use `::new(x, y, z)` instead of `::from_slice`
|
||||||
impl<N: Real, R: DimName, C: DimName> FiniteDimInnerSpace for MatrixMN<N, R, C>
|
impl<N: Real, R: DimName, C: DimName> FiniteDimInnerSpace for MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn orthonormalize(vs: &mut [MatrixMN<N, R, C>]) -> usize {
|
fn orthonormalize(vs: &mut [MatrixMN<N, R, C>]) -> usize {
|
||||||
@ -236,9 +233,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn orthonormal_subspace_basis<F>(vs: &[Self], mut f: F)
|
fn orthonormal_subspace_basis<F>(vs: &[Self], mut f: F)
|
||||||
where
|
where F: FnMut(&Self) -> bool {
|
||||||
F: FnMut(&Self) -> bool,
|
|
||||||
{
|
|
||||||
// FIXME: is this necessary?
|
// FIXME: is this necessary?
|
||||||
assert!(
|
assert!(
|
||||||
vs.len() <= Self::dimension(),
|
vs.len() <= Self::dimension(),
|
||||||
|
@ -107,7 +107,8 @@ where
|
|||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
GenericArray<N, Prod<R::Value, C::Value>>: Copy,
|
GenericArray<N, Prod<R::Value, C::Value>>: Copy,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
impl<N, R, C> Clone for MatrixArray<N, R, C>
|
impl<N, R, C> Clone for MatrixArray<N, R, C>
|
||||||
where
|
where
|
||||||
@ -132,7 +133,8 @@ where
|
|||||||
C: DimName,
|
C: DimName,
|
||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
impl<N, R, C> PartialEq for MatrixArray<N, R, C>
|
impl<N, R, C> PartialEq for MatrixArray<N, R, C>
|
||||||
where
|
where
|
||||||
@ -182,17 +184,13 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_owned(self) -> Owned<N, R, C>
|
fn into_owned(self) -> Owned<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone_owned(&self) -> Owned<N, R, C>
|
fn clone_owned(&self) -> Owned<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
let it = self.iter().cloned();
|
let it = self.iter().cloned();
|
||||||
|
|
||||||
DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it)
|
DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it)
|
||||||
@ -232,7 +230,8 @@ where
|
|||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
unsafe impl<N, R, C> ContiguousStorageMut<N, R, C> for MatrixArray<N, R, C>
|
unsafe impl<N, R, C> ContiguousStorageMut<N, R, C> for MatrixArray<N, R, C>
|
||||||
where
|
where
|
||||||
@ -242,7 +241,8 @@ where
|
|||||||
R::Value: Mul<C::Value>,
|
R::Value: Mul<C::Value>,
|
||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
DefaultAllocator: Allocator<N, R, C, Buffer = Self>,
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
@ -260,9 +260,7 @@ where
|
|||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
{
|
{
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where S: Serializer {
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
let mut serializer = serializer.serialize_seq(Some(R::dim() * C::dim()))?;
|
let mut serializer = serializer.serialize_seq(Some(R::dim() * C::dim()))?;
|
||||||
|
|
||||||
for e in self.iter() {
|
for e in self.iter() {
|
||||||
@ -283,9 +281,7 @@ where
|
|||||||
Prod<R::Value, C::Value>: ArrayLength<N>,
|
Prod<R::Value, C::Value>: ArrayLength<N>,
|
||||||
{
|
{
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where D: Deserializer<'a> {
|
||||||
D: Deserializer<'a>,
|
|
||||||
{
|
|
||||||
deserializer.deserialize_seq(MatrixArrayVisitor::new())
|
deserializer.deserialize_seq(MatrixArrayVisitor::new())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -330,9 +326,7 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn visit_seq<V>(self, mut visitor: V) -> Result<MatrixArray<N, R, C>, V::Error>
|
fn visit_seq<V>(self, mut visitor: V) -> Result<MatrixArray<N, R, C>, V::Error>
|
||||||
where
|
where V: SeqAccess<'a> {
|
||||||
V: SeqAccess<'a>,
|
|
||||||
{
|
|
||||||
let mut out: Self::Value = unsafe { mem::uninitialized() };
|
let mut out: Self::Value = unsafe { mem::uninitialized() };
|
||||||
let mut curr = 0;
|
let mut curr = 0;
|
||||||
|
|
||||||
|
@ -91,7 +91,8 @@ slice_storage_impl!("A mutable matrix data storage for mutable matrix slice. Onl
|
|||||||
|
|
||||||
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Copy
|
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Copy
|
||||||
for SliceStorage<'a, N, R, C, RStride, CStride>
|
for SliceStorage<'a, N, R, C, RStride, CStride>
|
||||||
{}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone
|
impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone
|
||||||
for SliceStorage<'a, N, R, C, RStride, CStride>
|
for SliceStorage<'a, N, R, C, RStride, CStride>
|
||||||
@ -206,7 +207,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
start: (usize, usize),
|
start: (usize, usize),
|
||||||
shape: (usize, usize),
|
shape: (usize, usize),
|
||||||
steps: (usize, usize),
|
steps: (usize, usize),
|
||||||
) {
|
)
|
||||||
|
{
|
||||||
let my_shape = self.shape();
|
let my_shape = self.shape();
|
||||||
// NOTE: we don't do any subtraction to avoid underflow for zero-sized matrices.
|
// NOTE: we don't do any subtraction to avoid underflow for zero-sized matrices.
|
||||||
//
|
//
|
||||||
@ -803,7 +805,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
pub fn rows_range<RowRange: SliceRange<R>>(
|
pub fn rows_range<RowRange: SliceRange<R>>(
|
||||||
&self,
|
&self,
|
||||||
rows: RowRange,
|
rows: RowRange,
|
||||||
) -> MatrixSlice<N, RowRange::Size, C, S::RStride, S::CStride> {
|
) -> MatrixSlice<N, RowRange::Size, C, S::RStride, S::CStride>
|
||||||
|
{
|
||||||
self.slice_range(rows, ..)
|
self.slice_range(rows, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -812,7 +815,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
pub fn columns_range<ColRange: SliceRange<C>>(
|
pub fn columns_range<ColRange: SliceRange<C>>(
|
||||||
&self,
|
&self,
|
||||||
cols: ColRange,
|
cols: ColRange,
|
||||||
) -> MatrixSlice<N, R, ColRange::Size, S::RStride, S::CStride> {
|
) -> MatrixSlice<N, R, ColRange::Size, S::RStride, S::CStride>
|
||||||
|
{
|
||||||
self.slice_range(.., cols)
|
self.slice_range(.., cols)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -841,7 +845,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
pub fn rows_range_mut<RowRange: SliceRange<R>>(
|
pub fn rows_range_mut<RowRange: SliceRange<R>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
rows: RowRange,
|
rows: RowRange,
|
||||||
) -> MatrixSliceMut<N, RowRange::Size, C, S::RStride, S::CStride> {
|
) -> MatrixSliceMut<N, RowRange::Size, C, S::RStride, S::CStride>
|
||||||
|
{
|
||||||
self.slice_range_mut(rows, ..)
|
self.slice_range_mut(rows, ..)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -850,7 +855,8 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
pub fn columns_range_mut<ColRange: SliceRange<C>>(
|
pub fn columns_range_mut<ColRange: SliceRange<C>>(
|
||||||
&mut self,
|
&mut self,
|
||||||
cols: ColRange,
|
cols: ColRange,
|
||||||
) -> MatrixSliceMut<N, R, ColRange::Size, S::RStride, S::CStride> {
|
) -> MatrixSliceMut<N, R, ColRange::Size, S::RStride, S::CStride>
|
||||||
|
{
|
||||||
self.slice_range_mut(.., cols)
|
self.slice_range_mut(.., cols)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -94,8 +94,7 @@ impl<N, R: Dim, C: Dim> Deref for MatrixVec<N, R, C> {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
unsafe impl<N: Scalar, C: Dim> Storage<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
unsafe impl<N: Scalar, C: Dim> Storage<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
|
||||||
{
|
{
|
||||||
type RStride = U1;
|
type RStride = U1;
|
||||||
type CStride = Dynamic;
|
type CStride = Dynamic;
|
||||||
@ -122,17 +121,13 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_owned(self) -> Owned<N, Dynamic, C>
|
fn into_owned(self) -> Owned<N, Dynamic, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, Dynamic, C> {
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C>,
|
|
||||||
{
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone_owned(&self) -> Owned<N, Dynamic, C>
|
fn clone_owned(&self) -> Owned<N, Dynamic, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, Dynamic, C> {
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C>,
|
|
||||||
{
|
|
||||||
self.clone()
|
self.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,8 +138,7 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, R: DimName> Storage<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
unsafe impl<N: Scalar, R: DimName> Storage<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
|
||||||
{
|
{
|
||||||
type RStride = U1;
|
type RStride = U1;
|
||||||
type CStride = R;
|
type CStride = R;
|
||||||
@ -171,17 +165,13 @@ where
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn into_owned(self) -> Owned<N, R, Dynamic>
|
fn into_owned(self) -> Owned<N, R, Dynamic>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, Dynamic> {
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic>,
|
|
||||||
{
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn clone_owned(&self) -> Owned<N, R, Dynamic>
|
fn clone_owned(&self) -> Owned<N, R, Dynamic>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, Dynamic> {
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic>,
|
|
||||||
{
|
|
||||||
self.clone()
|
self.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,8 +187,7 @@ where
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
unsafe impl<N: Scalar, C: Dim> StorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
unsafe impl<N: Scalar, C: Dim> StorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>,
|
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ptr_mut(&mut self) -> *mut N {
|
fn ptr_mut(&mut self) -> *mut N {
|
||||||
@ -211,17 +200,14 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, C: Dim> ContiguousStorage<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where
|
unsafe impl<N: Scalar, C: Dim> ContiguousStorage<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, C: Dim> ContiguousStorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where
|
unsafe impl<N: Scalar, C: Dim> ContiguousStorageMut<N, Dynamic, C> for MatrixVec<N, Dynamic, C> where DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, Dynamic, C, Buffer = Self>
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, R: DimName> StorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
unsafe impl<N: Scalar, R: DimName> StorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>,
|
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn ptr_mut(&mut self) -> *mut N {
|
fn ptr_mut(&mut self) -> *mut N {
|
||||||
@ -249,10 +235,8 @@ impl<N: Abomonation, R: Dim, C: Dim> Abomonation for MatrixVec<N, R, C> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorage<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where
|
unsafe impl<N: Scalar, R: DimName> ContiguousStorage<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
unsafe impl<N: Scalar, R: DimName> ContiguousStorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where
|
unsafe impl<N: Scalar, R: DimName> ContiguousStorageMut<N, R, Dynamic> for MatrixVec<N, R, Dynamic> where DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
||||||
DefaultAllocator: Allocator<N, R, Dynamic, Buffer = Self>
|
|
||||||
{}
|
{}
|
||||||
|
@ -724,9 +724,7 @@ impl<N: Scalar + ClosedAdd, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C,
|
|||||||
/// Adds a scalar to `self`.
|
/// Adds a scalar to `self`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_scalar(&self, rhs: N) -> MatrixMN<N, R, C>
|
pub fn add_scalar(&self, rhs: N) -> MatrixMN<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C> {
|
||||||
DefaultAllocator: Allocator<N, R, C>,
|
|
||||||
{
|
|
||||||
let mut res = self.clone_owned();
|
let mut res = self.clone_owned();
|
||||||
res.add_scalar_mut(rhs);
|
res.add_scalar_mut(rhs);
|
||||||
res
|
res
|
||||||
@ -735,9 +733,7 @@ impl<N: Scalar + ClosedAdd, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C,
|
|||||||
/// Adds a scalar to `self` in-place.
|
/// Adds a scalar to `self` in-place.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn add_scalar_mut(&mut self, rhs: N)
|
pub fn add_scalar_mut(&mut self, rhs: N)
|
||||||
where
|
where S: StorageMut<N, R, C> {
|
||||||
S: StorageMut<N, R, C>,
|
|
||||||
{
|
|
||||||
for e in self.iter_mut() {
|
for e in self.iter_mut() {
|
||||||
*e += rhs
|
*e += rhs
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,7 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Real, D: Dim, S: Storage<N, D, D>> SquareMatrix<N, D, S>
|
impl<N: Real, D: Dim, S: Storage<N, D, D>> SquareMatrix<N, D, S>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
/// Checks that this matrix is orthogonal and has a determinant equal to 1.
|
/// Checks that this matrix is orthogonal and has a determinant equal to 1.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -105,13 +105,11 @@ pub unsafe trait Storage<N: Scalar, R: Dim, C: Dim = U1>: Debug + Sized {
|
|||||||
|
|
||||||
/// Builds a matrix data storage that does not contain any reference.
|
/// Builds a matrix data storage that does not contain any reference.
|
||||||
fn into_owned(self) -> Owned<N, R, C>
|
fn into_owned(self) -> Owned<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>;
|
||||||
DefaultAllocator: Allocator<N, R, C>;
|
|
||||||
|
|
||||||
/// Clones this data storage to one that does not contain any reference.
|
/// Clones this data storage to one that does not contain any reference.
|
||||||
fn clone_owned(&self) -> Owned<N, R, C>
|
fn clone_owned(&self) -> Owned<N, R, C>
|
||||||
where
|
where DefaultAllocator: Allocator<N, R, C>;
|
||||||
DefaultAllocator: Allocator<N, R, C>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait implemented by matrix data storage that can provide a mutable access to its elements.
|
/// Trait implemented by matrix data storage that can provide a mutable access to its elements.
|
||||||
|
@ -25,9 +25,7 @@ pub struct Unit<T> {
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
impl<T: Serialize> Serialize for Unit<T> {
|
impl<T: Serialize> Serialize for Unit<T> {
|
||||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||||
where
|
where S: Serializer {
|
||||||
S: Serializer,
|
|
||||||
{
|
|
||||||
self.value.serialize(serializer)
|
self.value.serialize(serializer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,9 +33,7 @@ impl<T: Serialize> Serialize for Unit<T> {
|
|||||||
#[cfg(feature = "serde-serialize")]
|
#[cfg(feature = "serde-serialize")]
|
||||||
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit<T> {
|
impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit<T> {
|
||||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||||
where
|
where D: Deserializer<'de> {
|
||||||
D: Deserializer<'de>,
|
|
||||||
{
|
|
||||||
T::deserialize(deserializer).map(|x| Unit { value: x })
|
T::deserialize(deserializer).map(|x| Unit { value: x })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,8 +139,7 @@ impl<T> AsRef<T> for Unit<T> {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
impl<T: NormedSpace> SubsetOf<T> for Unit<T>
|
impl<T: NormedSpace> SubsetOf<T> for Unit<T>
|
||||||
where
|
where T::Field: RelativeEq
|
||||||
T::Field: RelativeEq,
|
|
||||||
{
|
{
|
||||||
#[inline]
|
#[inline]
|
||||||
fn to_superset(&self) -> T {
|
fn to_superset(&self) -> T {
|
||||||
|
@ -13,15 +13,13 @@ use num_complex::Complex;
|
|||||||
/// A random orthogonal matrix.
|
/// A random orthogonal matrix.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct RandomOrthogonal<N: Real, D: Dim = Dynamic>
|
pub struct RandomOrthogonal<N: Real, D: Dim = Dynamic>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
m: MatrixN<N, D>,
|
m: MatrixN<N, D>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<N: Real, D: Dim> RandomOrthogonal<N, D>
|
impl<N: Real, D: Dim> RandomOrthogonal<N, D>
|
||||||
where
|
where DefaultAllocator: Allocator<N, D, D>
|
||||||
DefaultAllocator: Allocator<N, D, D>,
|
|
||||||
{
|
{
|
||||||
/// Retrieve the generated matrix.
|
/// Retrieve the generated matrix.
|
||||||
pub fn unwrap(self) -> MatrixN<N, D> {
|
pub fn unwrap(self) -> MatrixN<N, D> {
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user