diff --git a/src/base/norm.rs b/src/base/norm.rs index bc5acce5..150ca341 100644 --- a/src/base/norm.rs +++ b/src/base/norm.rs @@ -256,7 +256,9 @@ impl> Matrix { + where + S: StorageMut, + { let n = self.norm(); self.scale_mut(magnitude / n) } @@ -265,7 +267,9 @@ impl> Matrix MatrixMN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.unscale(self.norm()) } @@ -275,6 +279,9 @@ impl> Matrix SimdOption> @@ -296,7 +303,9 @@ impl> Matrix { /// Otherwise this is equivalent to: `*self = self.normalize() * magnitude. #[inline] pub fn try_set_magnitude(&mut self, magnitude: N::RealField, min_magnitude: N::RealField) - where S: StorageMut { + where + S: StorageMut, + { let n = self.norm(); if n >= min_magnitude { @@ -305,10 +314,14 @@ impl> Matrix { } /// Returns a normalized version of this matrix unless its norm as smaller or equal to `eps`. + /// + /// The components of this matrix cannot be SIMD types (see `simd_try_normalize`) instead. #[inline] #[must_use = "Did you mean to use try_normalize_mut()?"] pub fn try_normalize(&self, min_norm: N::RealField) -> Option> - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { let n = self.norm(); if n <= min_norm { @@ -321,6 +334,8 @@ impl> Matrix { impl> Matrix { /// Normalizes this matrix in-place and returns its norm. + /// + /// The components of the matrix cannot be SIMD types (see `simd_try_normalize_mut` instead). #[inline] pub fn normalize_mut(&mut self) -> N::SimdRealField { let n = self.norm(); @@ -329,6 +344,9 @@ impl> Matrix> Matrix } impl Normed for MatrixMN -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type Norm = N::SimdRealField; @@ -390,7 +409,8 @@ where DefaultAllocator: Allocator } impl Neg for Unit> -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { type Output = Unit>; @@ -405,7 +425,8 @@ where DefaultAllocator: Allocator // − use `x()` instead of `::canonical_basis_element` // − use `::new(x, y, z)` instead of `::from_slice` impl VectorN -where DefaultAllocator: Allocator +where + DefaultAllocator: Allocator, { /// The i-the canonical basis element. #[inline] @@ -458,7 +479,9 @@ where DefaultAllocator: Allocator // FIXME: return an iterator instead when `-> impl Iterator` will be supported by Rust. #[inline] pub fn orthonormal_subspace_basis(vs: &[Self], mut f: F) - where F: FnMut(&Self) -> bool { + where + F: FnMut(&Self) -> bool, + { // FIXME: is this necessary? assert!( vs.len() <= D::dim(), diff --git a/src/base/unit.rs b/src/base/unit.rs index acff561a..f0334679 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -25,7 +25,9 @@ pub struct Unit { #[cfg(feature = "serde-serialize")] impl Serialize for Unit { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.value.serialize(serializer) } } @@ -33,7 +35,9 @@ impl Serialize for Unit { #[cfg(feature = "serde-serialize")] impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit { fn deserialize(deserializer: D) -> Result - where D: Deserializer<'de> { + where + D: Deserializer<'de>, + { T::deserialize(deserializer).map(|x| Unit { value: x }) } } @@ -53,11 +57,17 @@ impl Abomonation for Unit { } } +/// Trait implemented by entities scan be be normalized and put in an `Unit` struct. pub trait Normed { + /// The type of the norm. type Norm: SimdRealField; + /// Computes the norm. fn norm(&self) -> Self::Norm; + /// Computes the squared norm. fn norm_squared(&self) -> Self::Norm; + /// Multiply `self` by n. fn scale_mut(&mut self, n: Self::Norm); + /// Divides `self` by n. fn unscale_mut(&mut self, n: Self::Norm); } @@ -73,7 +83,9 @@ impl Unit { /// Returns `None` if the norm was smaller or equal to `min_norm`. #[inline] pub fn try_new(value: T, min_norm: T::Norm) -> Option - where T::Norm: RealField { + where + T::Norm: RealField, + { Self::try_new_and_get(value, min_norm).map(|res| res.0) } @@ -90,7 +102,9 @@ impl Unit { /// Returns `None` if the norm was smaller or equal to `min_norm`. #[inline] pub fn try_new_and_get(mut value: T, min_norm: T::Norm) -> Option<(Self, T::Norm)> - where T::Norm: RealField { + where + T::Norm: RealField, + { let sq_norm = value.norm_squared(); if sq_norm > min_norm * min_norm { diff --git a/src/geometry/abstract_rotation.rs b/src/geometry/abstract_rotation.rs index 6cadb44e..ff057a09 100644 --- a/src/geometry/abstract_rotation.rs +++ b/src/geometry/abstract_rotation.rs @@ -4,18 +4,30 @@ use crate::{DefaultAllocator, DimName, Point, Scalar, SimdRealField, VectorN, U2 use simba::scalar::ClosedMul; +/// Trait implemented by rotations that can be used inside of an `Isometry` or `Similarity`. pub trait AbstractRotation: PartialEq + ClosedMul + Clone { + /// The rotation identity. fn identity() -> Self; + /// The rotation inverse. fn inverse(&self) -> Self; + /// Change `self` to its inverse. fn inverse_mut(&mut self); + /// Apply the rotation to the given vector. fn transform_vector(&self, v: &VectorN) -> VectorN - where DefaultAllocator: Allocator; + where + DefaultAllocator: Allocator; + /// Apply the rotation to the given point. fn transform_point(&self, p: &Point) -> Point - where DefaultAllocator: Allocator; + where + DefaultAllocator: Allocator; + /// Apply the inverse rotation to the given vector. fn inverse_transform_vector(&self, v: &VectorN) -> VectorN - where DefaultAllocator: Allocator; + where + DefaultAllocator: Allocator; + /// Apply the inverse rotation to the given point. fn inverse_transform_point(&self, p: &Point) -> Point - where DefaultAllocator: Allocator; + where + DefaultAllocator: Allocator; } impl AbstractRotation for Rotation @@ -40,31 +52,40 @@ where #[inline] fn transform_vector(&self, v: &VectorN) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self * v } #[inline] fn transform_point(&self, p: &Point) -> Point - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self * p } #[inline] fn inverse_transform_vector(&self, v: &VectorN) -> VectorN - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.inverse_transform_vector(v) } #[inline] fn inverse_transform_point(&self, p: &Point) -> Point - where DefaultAllocator: Allocator { + where + DefaultAllocator: Allocator, + { self.inverse_transform_point(p) } } impl AbstractRotation for UnitQuaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn identity() -> Self { @@ -103,7 +124,8 @@ where N::Element: SimdRealField } impl AbstractRotation for UnitComplex -where N::Element: SimdRealField +where + N::Element: SimdRealField, { #[inline] fn identity() -> Self { diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 1a593883..45a03c78 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -35,7 +35,8 @@ pub struct Quaternion { #[cfg(feature = "abomonation-serialize")] impl Abomonation for Quaternion -where Vector4: Abomonation +where + Vector4: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.coords.entomb(writer) @@ -53,7 +54,8 @@ where Vector4: Abomonation impl Eq for Quaternion where N::Element: SimdRealField {} impl PartialEq for Quaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { fn eq(&self, rhs: &Self) -> bool { self.coords == rhs.coords || @@ -79,20 +81,26 @@ impl Clone for Quaternion { #[cfg(feature = "serde-serialize")] impl Serialize for Quaternion -where Owned: Serialize +where + Owned: Serialize, { fn serialize(&self, serializer: S) -> Result - where S: Serializer { + where + S: Serializer, + { self.coords.serialize(serializer) } } #[cfg(feature = "serde-serialize")] impl<'a, N: SimdRealField> Deserialize<'a> for Quaternion -where Owned: Deserialize<'a> +where + Owned: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where Des: Deserializer<'a> { + where + Des: Deserializer<'a>, + { let coords = Vector4::::deserialize(deserializer)?; Ok(Self::from(coords)) @@ -100,7 +108,8 @@ where Owned: Deserialize<'a> } impl Quaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// Moves this unit quaternion into one that owns its data. #[inline] @@ -289,10 +298,13 @@ where N::Element: SimdRealField } impl Quaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// Inverts this quaternion if it is not zero. /// + /// This method also does not works with SIMD components (see `simd_try_inverse` instead). + /// /// # Example /// ``` /// # #[macro_use] extern crate approx; @@ -312,7 +324,9 @@ where N::Element: SimdRealField #[inline] #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn try_inverse(&self) -> Option - where N: RealField { + where + N: RealField, + { let mut res = self.clone(); if res.try_inverse_mut() { @@ -322,6 +336,9 @@ where N::Element: SimdRealField } } + /// Attempt to inverse this quaternion. + /// + /// This method also works with SIMD components. #[inline] #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn simd_try_inverse(&self) -> SimdOption { @@ -383,7 +400,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn project(&self, other: &Self) -> Option - where N: RealField { + where + N: RealField, + { self.inner(other).right_div(other) } @@ -403,7 +422,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn reject(&self, other: &Self) -> Option - where N: RealField { + where + N: RealField, + { self.outer(other).right_div(other) } @@ -423,7 +444,9 @@ where N::Element: SimdRealField /// assert_eq!(axis, Some(Vector3::x_axis())); /// ``` pub fn polar_decomposition(&self) -> (N, N, Option>>) - where N: RealField { + where + N: RealField, + { if let Some((q, n)) = Unit::try_new_and_get(*self, N::zero()) { if let Some(axis) = Unit::try_new(self.vector().clone_owned(), N::zero()) { let angle = q.angle() / crate::convert(2.0f64); @@ -640,7 +663,9 @@ where N::Element: SimdRealField /// Calculates B-1 * A where A = self, B = other. #[inline] pub fn left_div(&self, other: &Self) -> Option - where N: RealField { + where + N: RealField, + { other.try_inverse().map(|inv| inv * self) } @@ -660,7 +685,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn right_div(&self, other: &Self) -> Option - where N: RealField { + where + N: RealField, + { other.try_inverse().map(|inv| self * inv) } @@ -753,7 +780,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn tan(&self) -> Self - where N: RealField { + where + N: RealField, + { self.sin().right_div(&self.cos()).unwrap() } @@ -769,7 +798,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn atan(&self) -> Self - where N: RealField { + where + N: RealField, + { let u = Self::from_imag(self.imag().normalize()); let num = u + self; let den = u - self; @@ -857,7 +888,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn tanh(&self) -> Self - where N: RealField { + where + N: RealField, + { self.sinh().right_div(&self.cosh()).unwrap() } @@ -907,8 +940,7 @@ impl> RelativeEq for Quaternion { other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.as_vector().relative_eq(other.as_vector(), epsilon, max_relative) || // Account for the double-covering of S², i.e. q = -q self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.relative_eq(&-*b, epsilon, max_relative)) @@ -967,7 +999,8 @@ impl Normed for Quaternion { } impl UnitQuaternion -where N::Element: SimdRealField +where + N::Element: SimdRealField, { /// The rotation angle in [0; pi] of this unit quaternion. /// @@ -1120,7 +1153,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn slerp(&self, other: &Self, t: N) -> Self - where N: RealField { + where + N: RealField, + { self.try_slerp(other, t, N::default_epsilon()) .expect("Quaternion slerp: ambiguous configuration.") } @@ -1137,7 +1172,9 @@ where N::Element: SimdRealField /// must be to return `None`. #[inline] pub fn try_slerp(&self, other: &Self, t: N, epsilon: N) -> Option - where N: RealField { + where + N: RealField, + { let coords = if self.coords.dot(&other.coords) < N::zero() { Unit::new_unchecked(self.coords).try_slerp( &Unit::new_unchecked(-other.coords), @@ -1194,7 +1231,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn axis(&self) -> Option>> - where N: RealField { + where + N: RealField, + { let v = if self.quaternion().scalar() >= N::zero() { self.as_ref().vector().clone_owned() } else { @@ -1216,7 +1255,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn scaled_axis(&self) -> Vector3 - where N: RealField { + where + N: RealField, + { if let Some(axis) = self.axis() { axis.into_inner() * self.angle() } else { @@ -1242,7 +1283,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn axis_angle(&self) -> Option<(Unit>, N)> - where N: RealField { + where + N: RealField, + { self.axis().map(|axis| (axis, self.angle())) } @@ -1270,7 +1313,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn ln(&self) -> Quaternion - where N: RealField { + where + N: RealField, + { if let Some(v) = self.axis() { Quaternion::from_imag(v.into_inner() * self.angle()) } else { @@ -1296,7 +1341,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn powf(&self, n: N) -> Self - where N: RealField { + where + N: RealField, + { if let Some(v) = self.axis() { Self::from_axis_angle(&v, self.angle() * n) } else { @@ -1357,7 +1404,9 @@ where N::Element: SimdRealField #[inline] #[deprecated(note = "This is renamed to use `.euler_angles()`.")] pub fn to_euler_angles(&self) -> (N, N, N) - where N: RealField { + where + N: RealField, + { self.euler_angles() } @@ -1377,7 +1426,9 @@ where N::Element: SimdRealField /// ``` #[inline] pub fn euler_angles(&self) -> (N, N, N) - where N: RealField { + where + N: RealField, + { self.to_rotation_matrix().euler_angles() } @@ -1533,8 +1584,7 @@ impl> RelativeEq for UnitQuaternion { other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool - { + ) -> bool { self.as_ref() .relative_eq(other.as_ref(), epsilon, max_relative) } diff --git a/src/lib.rs b/src/lib.rs index d0a20c36..9db176bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -79,7 +79,7 @@ an optimized set of tools for computer graphics and physics. Those features incl #![deny(non_upper_case_globals)] #![deny(unused_qualifications)] #![deny(unused_results)] -#![allow(missing_docs)] // XXX: deny that +#![deny(missing_docs)] #![doc( html_favicon_url = "https://nalgebra.org/img/favicon.ico", html_root_url = "https://nalgebra.org/rustdoc" @@ -190,7 +190,9 @@ pub fn zero() -> T { /// The range must not be empty. #[inline] pub fn wrap(mut val: T, min: T, max: T) -> T -where T: Copy + PartialOrd + ClosedAdd + ClosedSub { +where + T: Copy + PartialOrd + ClosedAdd + ClosedSub, +{ assert!(min < max, "Invalid wrapping bounds."); let width = max - min; @@ -390,7 +392,9 @@ pub fn partial_sort2<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<(&'a T, &' /// * [distance_squared](fn.distance_squared.html) #[inline] pub fn center(p1: &Point, p2: &Point) -> Point -where DefaultAllocator: Allocator { +where + DefaultAllocator: Allocator, +{ ((&p1.coords + &p2.coords) * convert::<_, N>(0.5)).into() }