Fix compilation of tests.
This commit is contained in:
parent
cbcf4d7c27
commit
b1857e6a36
|
@ -1,18 +1,9 @@
|
||||||
extern crate alga;
|
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
use alga::linear::FiniteDimInnerSpace;
|
|
||||||
use na::allocator::Allocator;
|
use na::allocator::Allocator;
|
||||||
use na::dimension::Dim;
|
use na::dimension::Dim;
|
||||||
use na::{DefaultAllocator, RealField, Unit, Vector2, Vector3, VectorN};
|
use na::{DefaultAllocator, RealField, Unit, Vector2, Vector3, VectorN};
|
||||||
|
|
||||||
/// 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
|
|
||||||
where V: FiniteDimInnerSpace + Copy {
|
|
||||||
let n = plane_normal.as_ref(); // Get the underlying vector of type `V`.
|
|
||||||
*vector - *n * (n.dot(vector) * na::convert(2.0))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 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_dimensional_genericity<N: RealField, D: Dim>(
|
fn reflect_wrt_hyperplane_with_dimensional_genericity<N: RealField, D: Dim>(
|
||||||
plane_normal: &Unit<VectorN<N, D>>,
|
plane_normal: &Unit<VectorN<N, D>>,
|
||||||
|
@ -50,15 +41,6 @@ fn main() {
|
||||||
let v3 = Vector3::new(1.0, 2.0, 3.0); // 3D vector to be reflected.
|
let v3 = Vector3::new(1.0, 2.0, 3.0); // 3D vector to be reflected.
|
||||||
|
|
||||||
// We can call the same function for 2D and 3D.
|
// We can call the same function for 2D and 3D.
|
||||||
assert_eq!(
|
|
||||||
reflect_wrt_hyperplane_with_algebraic_genericity(&plane2, &v2).y,
|
|
||||||
-2.0
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
reflect_wrt_hyperplane_with_algebraic_genericity(&plane3, &v3).y,
|
|
||||||
-2.0
|
|
||||||
);
|
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
reflect_wrt_hyperplane_with_dimensional_genericity(&plane2, &v2).y,
|
reflect_wrt_hyperplane_with_dimensional_genericity(&plane2, &v2).y,
|
||||||
-2.0
|
-2.0
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
extern crate alga;
|
|
||||||
extern crate nalgebra as na;
|
|
||||||
|
|
||||||
use alga::linear::Transformation;
|
|
||||||
use na::{Id, Isometry3, Point3, Vector3};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Applies `n` times the transformation `t` to the vector `v` and sum each
|
|
||||||
* intermediate value.
|
|
||||||
*/
|
|
||||||
fn complicated_algorithm<T>(v: &Vector3<f32>, t: &T, n: usize) -> Vector3<f32>
|
|
||||||
where T: Transformation<Point3<f32>> {
|
|
||||||
let mut result = *v;
|
|
||||||
|
|
||||||
// Do lots of operations involving t.
|
|
||||||
for _ in 0..n {
|
|
||||||
result = v + t.transform_vector(&result);
|
|
||||||
}
|
|
||||||
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* The two following calls are equivalent in term of result.
|
|
||||||
*/
|
|
||||||
fn main() {
|
|
||||||
let v = Vector3::new(1.0, 2.0, 3.0);
|
|
||||||
|
|
||||||
// The specialization generated by the compiler will do vector additions only.
|
|
||||||
let result1 = complicated_algorithm(&v, &Id::new(), 100000);
|
|
||||||
|
|
||||||
// The specialization generated by the compiler will also include matrix multiplications.
|
|
||||||
let iso = Isometry3::identity();
|
|
||||||
let result2 = complicated_algorithm(&v, &iso, 100000);
|
|
||||||
|
|
||||||
// They both return the same result.
|
|
||||||
assert!(result1 == Vector3::new(100001.0, 200002.0, 300003.0));
|
|
||||||
assert!(result2 == Vector3::new(100001.0, 200002.0, 300003.0));
|
|
||||||
}
|
|
|
@ -1,19 +1,12 @@
|
||||||
extern crate alga;
|
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
use na::{Scalar, Vector3};
|
use na::{Scalar, Vector3};
|
||||||
use simba::scalar::{RealField, RingCommutative};
|
use simba::scalar::RealField;
|
||||||
|
|
||||||
fn print_vector<N: Scalar>(m: &Vector3<N>) {
|
fn print_vector<N: Scalar>(m: &Vector3<N>) {
|
||||||
println!("{:?}", m)
|
println!("{:?}", m)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_squared_norm<N: Scalar + RingCommutative>(v: &Vector3<N>) {
|
|
||||||
// NOTE: alternatively, nalgebra already defines `v.squared_norm()`.
|
|
||||||
let sqnorm = v.dot(v);
|
|
||||||
println!("{:?}", sqnorm);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_norm<N: RealField>(v: &Vector3<N>) {
|
fn print_norm<N: RealField>(v: &Vector3<N>) {
|
||||||
// NOTE: alternatively, nalgebra already defines `v.norm()`.
|
// NOTE: alternatively, nalgebra already defines `v.norm()`.
|
||||||
let norm = v.dot(v).sqrt();
|
let norm = v.dot(v).sqrt();
|
||||||
|
@ -28,6 +21,5 @@ fn main() {
|
||||||
let v2 = Vector3::new(1.0, 2.0, 3.0);
|
let v2 = Vector3::new(1.0, 2.0, 3.0);
|
||||||
|
|
||||||
print_vector(&v1);
|
print_vector(&v1);
|
||||||
print_squared_norm(&v1);
|
|
||||||
print_norm(&v2);
|
print_norm(&v2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,6 @@ fn main() {
|
||||||
assert!(iso_fail.is_none());
|
assert!(iso_fail.is_none());
|
||||||
|
|
||||||
// Similarity -> Isometry conversion can be forced at your own risks.
|
// Similarity -> Isometry conversion can be forced at your own risks.
|
||||||
let iso_forced: Isometry2<f32> = unsafe { na::convert_unchecked(sim_with_scaling) };
|
let iso_forced: Isometry2<f32> = na::convert_unchecked(sim_with_scaling);
|
||||||
assert_eq!(iso_success.unwrap(), iso_forced);
|
assert_eq!(iso_success.unwrap(), iso_forced);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
extern crate alga;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate approx;
|
extern crate approx;
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
extern crate alga;
|
|
||||||
extern crate nalgebra as na;
|
extern crate nalgebra as na;
|
||||||
|
|
||||||
use na::{Matrix4, Point3, Vector3, Vector4};
|
use na::{Matrix4, Point3, Vector3, Vector4};
|
||||||
|
|
|
@ -571,13 +571,13 @@ where N::Element: SimdRealField
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[macro_use] extern crate approx;
|
/// # #[macro_use] extern crate approx;
|
||||||
/// # use nalgebra::Quaternion;
|
/// # use nalgebra::Quaternion;
|
||||||
/// let mut q = Quaternion::new(1.0, 2.0, 3.0, 4.0);
|
/// let mut q = Quaternion::new(1.0f32, 2.0, 3.0, 4.0);
|
||||||
///
|
///
|
||||||
/// assert!(q.try_inverse_mut());
|
/// assert!(q.try_inverse_mut());
|
||||||
/// assert_relative_eq!(q * Quaternion::new(1.0, 2.0, 3.0, 4.0), Quaternion::identity());
|
/// assert_relative_eq!(q * Quaternion::new(1.0, 2.0, 3.0, 4.0), Quaternion::identity());
|
||||||
///
|
///
|
||||||
/// //Non-invertible case
|
/// //Non-invertible case
|
||||||
/// let mut q = Quaternion::new(0.0, 0.0, 0.0, 0.0);
|
/// let mut q = Quaternion::new(0.0f32, 0.0, 0.0, 0.0);
|
||||||
/// assert!(!q.try_inverse_mut());
|
/// assert!(!q.try_inverse_mut());
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#[cfg(feature = "abomonation-serialize")]
|
#[cfg(feature = "abomonation-serialize")]
|
||||||
extern crate abomonation;
|
extern crate abomonation;
|
||||||
extern crate alga;
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate approx;
|
extern crate approx;
|
||||||
#[cfg(feature = "mint")]
|
#[cfg(feature = "mint")]
|
||||||
|
@ -10,9 +9,6 @@ extern crate num_traits as num;
|
||||||
#[cfg(feature = "arbitrary")]
|
#[cfg(feature = "arbitrary")]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate quickcheck;
|
extern crate quickcheck;
|
||||||
extern crate rand;
|
|
||||||
extern crate serde_json;
|
|
||||||
extern crate num_complex;
|
|
||||||
|
|
||||||
mod core;
|
mod core;
|
||||||
mod geometry;
|
mod geometry;
|
||||||
|
|
|
@ -130,7 +130,7 @@ fn matrix5_try_inverse_scaled_identity() {
|
||||||
0.0, 1.0e+20, 0.0, 0.0, 0.0,
|
0.0, 1.0e+20, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 1.0e+20, 0.0, 0.0,
|
0.0, 0.0, 1.0e+20, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 1.0e+20, 0.0,
|
0.0, 0.0, 0.0, 1.0e+20, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0, 1.0e+20);;
|
0.0, 0.0, 0.0, 0.0, 1.0e+20);
|
||||||
let a_inv = a.try_inverse().expect("Matrix should be invertible");
|
let a_inv = a.try_inverse().expect("Matrix should be invertible");
|
||||||
|
|
||||||
assert_relative_eq!(a_inv, expected_inverse);
|
assert_relative_eq!(a_inv, expected_inverse);
|
||||||
|
|
Loading…
Reference in New Issue