commit
90e531337a
@ -3,6 +3,7 @@
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use na::{Isometry3, Perspective3, Point3, Vector3};
|
||||
use std::f32::consts;
|
||||
|
||||
fn main() {
|
||||
// Our object is translated along the x axis.
|
||||
@ -15,7 +16,7 @@ fn main() {
|
||||
let view = Isometry3::look_at_rh(&eye, &target, &Vector3::y());
|
||||
|
||||
// A perspective projection.
|
||||
let projection = Perspective3::new(16.0 / 9.0, 3.14 / 2.0, 1.0, 1000.0);
|
||||
let projection = Perspective3::new(16.0 / 9.0, consts::PI / 2.0, 1.0, 1000.0);
|
||||
|
||||
// The combination of the model with the view is still an isometry.
|
||||
let model_view = view * model;
|
||||
|
@ -19,6 +19,7 @@ fn main() {
|
||||
|
||||
/* Then pass the raw pointers to some graphics API. */
|
||||
|
||||
#[allow(clippy::float_cmp)]
|
||||
unsafe {
|
||||
assert_eq!(*v_pointer, 1.0);
|
||||
assert_eq!(*v_pointer.offset(1), 0.0);
|
||||
|
@ -3,9 +3,10 @@
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use na::{Perspective3, Point2, Point3, Unit};
|
||||
use std::f32::consts;
|
||||
|
||||
fn main() {
|
||||
let projection = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0);
|
||||
let projection = Perspective3::new(800.0 / 600.0, consts::PI / 2.0, 1.0, 1000.0);
|
||||
let screen_point = Point2::new(10.0f32, 20.0);
|
||||
|
||||
// Compute two points in clip-space.
|
||||
|
@ -1,6 +1,7 @@
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use na::{Isometry2, Similarity2, Vector2};
|
||||
use std::f32::consts;
|
||||
|
||||
fn main() {
|
||||
// Isometry -> Similarity conversion always succeeds.
|
||||
@ -8,8 +9,8 @@ fn main() {
|
||||
let _: Similarity2<f32> = na::convert(iso);
|
||||
|
||||
// Similarity -> Isometry conversion fails if the scaling factor is not 1.0.
|
||||
let sim_without_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), 3.14, 1.0);
|
||||
let sim_with_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), 3.14, 2.0);
|
||||
let sim_without_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), consts::PI, 1.0);
|
||||
let sim_with_scaling = Similarity2::new(Vector2::new(1.0f32, 2.0), consts::PI, 2.0);
|
||||
|
||||
let iso_success: Option<Isometry2<f32>> = na::try_convert(sim_without_scaling);
|
||||
let iso_fail: Option<Isometry2<f32>> = na::try_convert(sim_with_scaling);
|
||||
|
@ -3,6 +3,7 @@ extern crate approx;
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use na::{Matrix4, Point3, Vector3};
|
||||
use std::f32::consts;
|
||||
|
||||
fn main() {
|
||||
// Create a uniform scaling matrix with scaling factor 2.
|
||||
@ -28,7 +29,7 @@ fn main() {
|
||||
);
|
||||
|
||||
// Create rotation.
|
||||
let rot = Matrix4::from_scaled_axis(&Vector3::x() * 3.14);
|
||||
let rot = Matrix4::from_scaled_axis(Vector3::x() * consts::PI);
|
||||
let rot_then_m = m * rot; // Right-multiplication is equivalent to prepending `rot` to `m`.
|
||||
let m_then_rot = rot * m; // Left-multiplication is equivalent to appending `rot` to `m`.
|
||||
|
||||
|
@ -12,6 +12,7 @@ fn main() {
|
||||
|
||||
/* Then pass the raw pointer to some graphics API. */
|
||||
|
||||
#[allow(clippy::float_cmp)]
|
||||
unsafe {
|
||||
assert_eq!(*iso_pointer, 1.0);
|
||||
assert_eq!(*iso_pointer.offset(5), 1.0);
|
||||
|
@ -1,3 +1,4 @@
|
||||
#![allow(clippy::float_cmp)]
|
||||
extern crate nalgebra as na;
|
||||
|
||||
use na::{Unit, Vector3};
|
||||
|
@ -95,9 +95,7 @@ impl<T: Scalar + Zero, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> {
|
||||
for (destination, source) in icols.enumerate() {
|
||||
// NOTE: this is basically a copy_frow but wrapping the values insnide of MaybeUninit.
|
||||
res.column_mut(destination)
|
||||
.zip_apply(&self.column(*source), |out, e| {
|
||||
*out = MaybeUninit::new(e.clone())
|
||||
});
|
||||
.zip_apply(&self.column(*source), |out, e| *out = MaybeUninit::new(e));
|
||||
}
|
||||
|
||||
// Safety: res is now fully initialized.
|
||||
@ -1094,7 +1092,7 @@ unsafe fn compress_rows<T: Scalar>(
|
||||
|
||||
if new_nrows == 0 || ncols == 0 {
|
||||
// The output matrix is empty, drop everything.
|
||||
ptr::drop_in_place(data.as_mut());
|
||||
ptr::drop_in_place(data);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
//! Indexing
|
||||
#![allow(clippy::reversed_empty_ranges)]
|
||||
|
||||
use crate::base::storage::{RawStorage, RawStorageMut};
|
||||
use crate::base::{
|
||||
@ -43,7 +44,7 @@ impl<D: Dim> DimRange<D> for usize {
|
||||
|
||||
#[test]
|
||||
fn dimrange_usize() {
|
||||
assert_eq!(DimRange::contained_by(&0, Const::<0>), false);
|
||||
assert!(!DimRange::contained_by(&0, Const::<0>));
|
||||
assert!(DimRange::contained_by(&0, Const::<1>));
|
||||
}
|
||||
|
||||
@ -68,8 +69,8 @@ impl<D: Dim> DimRange<D> for ops::Range<usize> {
|
||||
|
||||
#[test]
|
||||
fn dimrange_range_usize() {
|
||||
assert_eq!(DimRange::contained_by(&(0..0), Const::<0>), false);
|
||||
assert_eq!(DimRange::contained_by(&(0..1), Const::<0>), false);
|
||||
assert!(!DimRange::contained_by(&(0..0), Const::<0>));
|
||||
assert!(!DimRange::contained_by(&(0..1), Const::<0>));
|
||||
assert!(DimRange::contained_by(&(0..1), Const::<1>));
|
||||
assert!(DimRange::contained_by(
|
||||
&((usize::MAX - 1)..usize::MAX),
|
||||
@ -110,8 +111,8 @@ impl<D: Dim> DimRange<D> for ops::RangeFrom<usize> {
|
||||
|
||||
#[test]
|
||||
fn dimrange_rangefrom_usize() {
|
||||
assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false);
|
||||
assert_eq!(DimRange::contained_by(&(0..), Const::<0>), false);
|
||||
assert!(!DimRange::contained_by(&(0..), Const::<0>));
|
||||
assert!(!DimRange::contained_by(&(0..), Const::<0>));
|
||||
assert!(DimRange::contained_by(&(0..), Const::<1>));
|
||||
assert!(DimRange::contained_by(
|
||||
&((usize::MAX - 1)..),
|
||||
@ -204,16 +205,16 @@ impl<D: Dim> DimRange<D> for ops::RangeInclusive<usize> {
|
||||
|
||||
#[test]
|
||||
fn dimrange_rangeinclusive_usize() {
|
||||
assert_eq!(DimRange::contained_by(&(0..=0), Const::<0>), false);
|
||||
assert!(!DimRange::contained_by(&(0..=0), Const::<0>));
|
||||
assert!(DimRange::contained_by(&(0..=0), Const::<1>));
|
||||
assert_eq!(
|
||||
DimRange::contained_by(&(usize::MAX..=usize::MAX), Dynamic::new(usize::MAX)),
|
||||
false
|
||||
);
|
||||
assert_eq!(
|
||||
DimRange::contained_by(&((usize::MAX - 1)..=usize::MAX), Dynamic::new(usize::MAX)),
|
||||
false
|
||||
);
|
||||
assert!(!DimRange::contained_by(
|
||||
&(usize::MAX..=usize::MAX),
|
||||
Dynamic::new(usize::MAX)
|
||||
));
|
||||
assert!(!DimRange::contained_by(
|
||||
&((usize::MAX - 1)..=usize::MAX),
|
||||
Dynamic::new(usize::MAX)
|
||||
));
|
||||
assert!(DimRange::contained_by(
|
||||
&((usize::MAX - 1)..=(usize::MAX - 1)),
|
||||
Dynamic::new(usize::MAX)
|
||||
@ -255,7 +256,7 @@ impl<D: Dim> DimRange<D> for ops::RangeTo<usize> {
|
||||
#[test]
|
||||
fn dimrange_rangeto_usize() {
|
||||
assert!(DimRange::contained_by(&(..0), Const::<0>));
|
||||
assert_eq!(DimRange::contained_by(&(..1), Const::<0>), false);
|
||||
assert!(!DimRange::contained_by(&(..1), Const::<0>));
|
||||
assert!(DimRange::contained_by(&(..0), Const::<1>));
|
||||
assert!(DimRange::contained_by(
|
||||
&(..(usize::MAX - 1)),
|
||||
@ -292,13 +293,13 @@ impl<D: Dim> DimRange<D> for ops::RangeToInclusive<usize> {
|
||||
|
||||
#[test]
|
||||
fn dimrange_rangetoinclusive_usize() {
|
||||
assert_eq!(DimRange::contained_by(&(..=0), Const::<0>), false);
|
||||
assert_eq!(DimRange::contained_by(&(..=1), Const::<0>), false);
|
||||
assert!(!DimRange::contained_by(&(..=0), Const::<0>));
|
||||
assert!(!DimRange::contained_by(&(..=1), Const::<0>));
|
||||
assert!(DimRange::contained_by(&(..=0), Const::<1>));
|
||||
assert_eq!(
|
||||
DimRange::contained_by(&(..=(usize::MAX)), Dynamic::new(usize::MAX)),
|
||||
false
|
||||
);
|
||||
assert!(!DimRange::contained_by(
|
||||
&(..=(usize::MAX)),
|
||||
Dynamic::new(usize::MAX)
|
||||
));
|
||||
assert!(DimRange::contained_by(
|
||||
&(..=(usize::MAX - 1)),
|
||||
Dynamic::new(usize::MAX)
|
||||
|
@ -1792,7 +1792,7 @@ where
|
||||
assert!(self.shape() == other.shape());
|
||||
self.iter()
|
||||
.zip(other.iter())
|
||||
.all(|(a, b)| a.ulps_eq(b, epsilon.clone(), max_ulps.clone()))
|
||||
.all(|(a, b)| a.ulps_eq(b, epsilon.clone(), max_ulps))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
|
||||
T: SimdPartialOrd + Zero,
|
||||
{
|
||||
self.fold_with(
|
||||
|e| e.map(|e| e.clone()).unwrap_or_else(T::zero),
|
||||
|e| e.cloned().unwrap_or_else(T::zero),
|
||||
|a, b| a.simd_max(b.clone()),
|
||||
)
|
||||
}
|
||||
@ -123,7 +123,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
|
||||
T: SimdPartialOrd + Zero,
|
||||
{
|
||||
self.fold_with(
|
||||
|e| e.map(|e| e.clone()).unwrap_or_else(T::zero),
|
||||
|e| e.cloned().unwrap_or_else(T::zero),
|
||||
|a, b| a.simd_min(b.clone()),
|
||||
)
|
||||
}
|
||||
|
@ -434,12 +434,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: StorageMut<T, R, C>> Matrix<T, R, C, S> {
|
||||
{
|
||||
let n = self.norm();
|
||||
let le = n.clone().simd_le(min_norm);
|
||||
self.apply(|e| {
|
||||
*e = e
|
||||
.clone()
|
||||
.simd_unscale(n.clone())
|
||||
.select(le.clone(), e.clone())
|
||||
});
|
||||
self.apply(|e| *e = e.clone().simd_unscale(n.clone()).select(le, e.clone()));
|
||||
SimdOption::new(n, le)
|
||||
}
|
||||
|
||||
|
@ -66,11 +66,11 @@ unsafe impl<T> InitStatus<T> for Uninit {
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn assume_init_ref(t: &MaybeUninit<T>) -> &T {
|
||||
std::mem::transmute(t.as_ptr()) // TODO: use t.assume_init_ref()
|
||||
&*t.as_ptr() // TODO: use t.assume_init_ref()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn assume_init_mut(t: &mut MaybeUninit<T>) -> &mut T {
|
||||
std::mem::transmute(t.as_mut_ptr()) // TODO: use t.assume_init_mut()
|
||||
&mut *t.as_mut_ptr() // TODO: use t.assume_init_mut()
|
||||
}
|
||||
}
|
||||
|
@ -353,7 +353,7 @@ impl<T: RealField + UlpsEq<Epsilon = T>> UlpsEq for DualQuaternion<T> {
|
||||
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
|
||||
self.clone().to_vector().ulps_eq(&other.clone().to_vector(), epsilon.clone(), max_ulps.clone()) ||
|
||||
// Account for the double-covering of S², i.e. q = -q.
|
||||
self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone()))
|
||||
self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ impl<T: RealField> Orthographic3<T> {
|
||||
);
|
||||
|
||||
let half: T = crate::convert(0.5);
|
||||
let width = zfar.clone() * (vfov.clone() * half.clone()).tan();
|
||||
let width = zfar.clone() * (vfov * half.clone()).tan();
|
||||
let height = width.clone() / aspect;
|
||||
|
||||
Self::new(
|
||||
|
@ -1039,9 +1039,9 @@ impl<T: RealField + UlpsEq<Epsilon = T>> UlpsEq for Quaternion<T> {
|
||||
|
||||
#[inline]
|
||||
fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
|
||||
self.as_vector().ulps_eq(other.as_vector(), epsilon.clone(), max_ulps.clone()) ||
|
||||
self.as_vector().ulps_eq(other.as_vector(), epsilon.clone(), max_ulps) ||
|
||||
// Account for the double-covering of S², i.e. q = -q.
|
||||
self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone()))
|
||||
self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1492,18 +1492,18 @@ where
|
||||
let wk = w.clone() * k.clone() * crate::convert(2.0f64);
|
||||
let wj = w.clone() * j.clone() * crate::convert(2.0f64);
|
||||
let ik = i.clone() * k.clone() * crate::convert(2.0f64);
|
||||
let jk = j.clone() * k.clone() * crate::convert(2.0f64);
|
||||
let wi = w.clone() * i.clone() * crate::convert(2.0f64);
|
||||
let jk = j * k * crate::convert(2.0f64);
|
||||
let wi = w * i * crate::convert(2.0f64);
|
||||
|
||||
Rotation::from_matrix_unchecked(Matrix3::new(
|
||||
ww.clone() + ii.clone() - jj.clone() - kk.clone(),
|
||||
ij.clone() - wk.clone(),
|
||||
wj.clone() + ik.clone(),
|
||||
wk.clone() + ij.clone(),
|
||||
wk + ij,
|
||||
ww.clone() - ii.clone() + jj.clone() - kk.clone(),
|
||||
jk.clone() - wi.clone(),
|
||||
ik.clone() - wj.clone(),
|
||||
wi.clone() + jk.clone(),
|
||||
ik - wj,
|
||||
wi + jk,
|
||||
ww - ii - jj + kk,
|
||||
))
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ impl<T: ComplexField, D: DimMin<D, Output = D>, S: Storage<T, D, D>> SquareMatri
|
||||
let m33 = self.get_unchecked((2, 2)).clone();
|
||||
|
||||
let minor_m12_m23 = m22.clone() * m33.clone() - m32.clone() * m23.clone();
|
||||
let minor_m11_m23 = m21.clone() * m33.clone() - m31.clone() * m23.clone();
|
||||
let minor_m11_m23 = m21.clone() * m33 - m31.clone() * m23;
|
||||
let minor_m11_m22 = m21 * m32 - m31 * m22;
|
||||
|
||||
m11 * minor_m12_m23 - m12 * minor_m11_m23 + m13 * minor_m11_m22
|
||||
|
@ -510,6 +510,7 @@ where
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
#[allow(clippy::float_cmp)]
|
||||
fn one_norm() {
|
||||
use crate::Matrix3;
|
||||
let m = Matrix3::new(-3.0, 5.0, 7.0, 2.0, 6.0, 4.0, 0.0, 2.0, 8.0);
|
||||
|
@ -47,7 +47,7 @@ impl<T: ComplexField> GivensRotation<T> {
|
||||
if denom > eps {
|
||||
let norm = sign0.scale(denom.clone());
|
||||
let c = mod0 / denom;
|
||||
let s = s.clone() / norm.clone();
|
||||
let s = s / norm.clone();
|
||||
Some((Self { c, s }, norm))
|
||||
} else {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user