diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 93a88e78..ed901f20 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -113,7 +113,7 @@ pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. pub fn make_quat(ptr: &[N]) -> Qua { - Quaternion::from_vector(TVec4::from_column_slice(ptr)) + Quaternion::from(TVec4::from_column_slice(ptr)) } /// Creates a 1D vector from a slice. diff --git a/src/geometry/isometry_alga.rs b/src/geometry/isometry_alga.rs index 6a144550..7decea8e 100644 --- a/src/geometry/isometry_alga.rs +++ b/src/geometry/isometry_alga.rs @@ -143,10 +143,7 @@ where #[inline] fn append_rotation(&self, r: &Self::Rotation) -> Self { let shift = r.transform_vector(&self.translation.vector); - Isometry::from_parts( - Translation::from_vector(shift), - r.clone() * self.rotation.clone(), - ) + Isometry::from_parts(Translation::from(shift), r.clone() * self.rotation.clone()) } #[inline] diff --git a/src/geometry/isometry_construction.rs b/src/geometry/isometry_construction.rs index 972e80ec..4af3b413 100644 --- a/src/geometry/isometry_construction.rs +++ b/src/geometry/isometry_construction.rs @@ -58,7 +58,7 @@ where DefaultAllocator: Allocator #[inline] pub fn rotation_wrt_point(r: R, p: Point) -> Self { let shift = r.transform_vector(&-&p.coords); - Self::from_parts(Translation::from_vector(shift + p.coords), r) + Self::from_parts(Translation::from(shift + p.coords), r) } } @@ -122,7 +122,7 @@ impl Isometry> { #[inline] pub fn new(translation: Vector2, angle: N) -> Self { Self::from_parts( - Translation::from_vector(translation), + Translation::from(translation), Rotation::::new(angle), ) } @@ -145,7 +145,7 @@ impl Isometry> { #[inline] pub fn new(translation: Vector2, angle: N) -> Self { Self::from_parts( - Translation::from_vector(translation), + Translation::from(translation), UnitComplex::from_angle(angle), ) } @@ -183,7 +183,7 @@ macro_rules! isometry_construction_impl( #[inline] pub fn new(translation: Vector3, axisangle: Vector3) -> Self { Self::from_parts( - Translation::from_vector(translation), + Translation::from(translation), $RotId::<$($RotParams),*>::from_scaled_axis(axisangle)) } @@ -225,7 +225,7 @@ macro_rules! isometry_construction_impl( up: &Vector3) -> Self { Self::from_parts( - Translation::from_vector(eye.coords.clone()), + Translation::from(eye.coords.clone()), $RotId::new_observer_frame(&(target - eye), up)) } @@ -270,7 +270,7 @@ macro_rules! isometry_construction_impl( let rotation = $RotId::look_at_rh(&(target - eye), up); let trans = &rotation * (-eye); - Self::from_parts(Translation::from_vector(trans.coords), rotation) + Self::from_parts(Translation::from(trans.coords), rotation) } /// Builds a left-handed look-at view matrix. @@ -314,7 +314,7 @@ macro_rules! isometry_construction_impl( let rotation = $RotId::look_at_lh(&(target - eye), up); let trans = &rotation * (-eye); - Self::from_parts(Translation::from_vector(trans.coords), rotation) + Self::from_parts(Translation::from(trans.coords), rotation) } } } diff --git a/src/geometry/isometry_conversion.rs b/src/geometry/isometry_conversion.rs index a896caf6..5dc46009 100644 --- a/src/geometry/isometry_conversion.rs +++ b/src/geometry/isometry_conversion.rs @@ -141,7 +141,9 @@ where #[inline] unsafe fn from_superset_unchecked(m: &MatrixN>) -> Self { let t = m.fixed_slice::(0, D::dim()).into_owned(); - let t = Translation::from_vector(::convert_unchecked(t)); + let t = Translation { + vector: ::convert_unchecked(t), + }; Self::from_parts(t, ::convert_unchecked(m.clone_owned())) } diff --git a/src/geometry/isometry_ops.rs b/src/geometry/isometry_ops.rs index c30c2ac1..a3608a63 100644 --- a/src/geometry/isometry_ops.rs +++ b/src/geometry/isometry_ops.rs @@ -142,7 +142,7 @@ isometry_binop_impl_all!( [ref ref] => { let shift = self.rotation.transform_vector(&rhs.translation.vector); - Isometry::from_parts(Translation::from_vector(&self.translation.vector + shift), + Isometry::from_parts(Translation::from(&self.translation.vector + shift), self.rotation.clone() * rhs.rotation.clone()) // FIXME: too bad we have to clone. }; ); @@ -267,7 +267,7 @@ isometry_binop_impl_all!( [val ref] => &self * right; [ref ref] => { let new_tr = &self.translation.vector + self.rotation.transform_vector(&right.vector); - Isometry::from_parts(Translation::from_vector(new_tr), self.rotation.clone()) + Isometry::from_parts(Translation::from(new_tr), self.rotation.clone()) }; ); @@ -339,10 +339,10 @@ isometry_from_composition_impl_all!( Mul, mul; (D, D), (D, U1) for D: DimName; self: Rotation, right: Translation, Output = Isometry>; - [val val] => Isometry::from_parts(Translation::from_vector(&self * right.vector), self); - [ref val] => Isometry::from_parts(Translation::from_vector(self * right.vector), self.clone()); - [val ref] => Isometry::from_parts(Translation::from_vector(&self * &right.vector), self); - [ref ref] => Isometry::from_parts(Translation::from_vector(self * &right.vector), self.clone()); + [val val] => Isometry::from_parts(Translation::from(&self * right.vector), self); + [ref val] => Isometry::from_parts(Translation::from(self * right.vector), self.clone()); + [val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self); + [ref ref] => Isometry::from_parts(Translation::from(self * &right.vector), self.clone()); ); // UnitQuaternion × Translation @@ -351,10 +351,10 @@ isometry_from_composition_impl_all!( (U4, U1), (U3, U1); self: UnitQuaternion, right: Translation, Output = Isometry>; - [val val] => Isometry::from_parts(Translation::from_vector(&self * right.vector), self); - [ref val] => Isometry::from_parts(Translation::from_vector( self * right.vector), self.clone()); - [val ref] => Isometry::from_parts(Translation::from_vector(&self * &right.vector), self); - [ref ref] => Isometry::from_parts(Translation::from_vector( self * &right.vector), self.clone()); + [val val] => Isometry::from_parts(Translation::from(&self * right.vector), self); + [ref val] => Isometry::from_parts(Translation::from( self * right.vector), self.clone()); + [val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self); + [ref ref] => Isometry::from_parts(Translation::from( self * &right.vector), self.clone()); ); // Rotation × Isometry @@ -368,7 +368,7 @@ isometry_from_composition_impl_all!( [val ref] => &self * right; [ref ref] => { let shift = self * &right.translation.vector; - Isometry::from_parts(Translation::from_vector(shift), self * &right.rotation) + Isometry::from_parts(Translation::from(shift), self * &right.rotation) }; ); @@ -396,7 +396,7 @@ isometry_from_composition_impl_all!( [val ref] => &self * right; [ref ref] => { let shift = self * &right.translation.vector; - Isometry::from_parts(Translation::from_vector(shift), self * &right.rotation) + Isometry::from_parts(Translation::from(shift), self * &right.rotation) }; ); diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 9f380912..2c030f61 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -158,7 +158,7 @@ macro_rules! componentwise_constructors_impl( ($($doc: expr; $D: ty, $($args: ident:$irow: expr),*);* $(;)*) => {$( impl Point where DefaultAllocator: Allocator { - #[doc = "Initializes this matrix from its components."] + #[doc = "Initializes this point from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 3dd31fd8..28d2666a 100644 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -68,7 +68,7 @@ impl Copy for Quaternion {} impl Clone for Quaternion { #[inline] fn clone(&self) -> Self { - Quaternion::from_vector(self.coords.clone()) + Quaternion::from(self.coords.clone()) } } @@ -90,7 +90,7 @@ where Owned: Deserialize<'a> where Des: Deserializer<'a> { let coords = Vector4::::deserialize(deserializer)?; - Ok(Quaternion::from_vector(coords)) + Ok(Quaternion::from(coords)) } } @@ -106,7 +106,7 @@ impl Quaternion { #[inline] #[deprecated(note = "This method is a no-op and will be removed in a future release.")] pub fn clone_owned(&self) -> Quaternion { - Quaternion::from_vector(self.coords.clone_owned()) + Quaternion::from(self.coords.clone_owned()) } /// Normalizes this quaternion. @@ -122,7 +122,7 @@ impl Quaternion { /// ``` #[inline] pub fn normalize(&self) -> Quaternion { - Quaternion::from_vector(self.coords.normalize()) + Quaternion::from(self.coords.normalize()) } /// The conjugate of this quaternion. @@ -142,7 +142,7 @@ impl Quaternion { -self.coords[2], self.coords[3], ); - Quaternion::from_vector(v) + Quaternion::from(v) } /// Inverts this quaternion if it is not zero. @@ -166,7 +166,7 @@ impl Quaternion { /// ``` #[inline] pub fn try_inverse(&self) -> Option> { - let mut res = Quaternion::from_vector(self.coords.clone_owned()); + let mut res = Quaternion::from(self.coords.clone_owned()); if res.try_inverse_mut() { Some(res) @@ -405,7 +405,6 @@ impl Quaternion { } } - /// Raise the quaternion to a given floating power. /// /// # Example @@ -585,14 +584,18 @@ pub type UnitQuaternion = Unit>; impl UnitQuaternion { /// Moves this unit quaternion into one that owns its data. #[inline] - #[deprecated(note = "This method is unnecessary and will be removed in a future release. Use `.clone()` instead.")] + #[deprecated( + note = "This method is unnecessary and will be removed in a future release. Use `.clone()` instead." + )] pub fn into_owned(self) -> UnitQuaternion { self } /// Clones this unit quaternion into one that owns its data. #[inline] - #[deprecated(note = "This method is unnecessary and will be removed in a future release. Use `.clone()` instead.")] + #[deprecated( + note = "This method is unnecessary and will be removed in a future release. Use `.clone()` instead." + )] pub fn clone_owned(&self) -> UnitQuaternion { *self } @@ -741,7 +744,7 @@ impl UnitQuaternion { /// is not well-defined). Use `.try_slerp` instead to avoid the panic. #[inline] pub fn slerp(&self, other: &UnitQuaternion, t: N) -> UnitQuaternion { - Unit::new_unchecked(Quaternion::from_vector( + Unit::new_unchecked(Quaternion::from( Unit::new_unchecked(self.coords) .slerp(&Unit::new_unchecked(other.coords), t) .unwrap(), @@ -768,7 +771,7 @@ impl UnitQuaternion { { Unit::new_unchecked(self.coords) .try_slerp(&Unit::new_unchecked(other.coords), t, epsilon) - .map(|q| Unit::new_unchecked(Quaternion::from_vector(q.unwrap()))) + .map(|q| Unit::new_unchecked(Quaternion::from(q.unwrap()))) } /// Compute the conjugate of this unit quaternion in-place. @@ -993,7 +996,6 @@ impl UnitQuaternion { self.to_rotation_matrix().to_euler_angles() } - /// Retrieves the euler angles corresponding to this unit quaternion. /// /// The angles are produced in the form (roll, pitch, yaw). diff --git a/src/geometry/quaternion_alga.rs b/src/geometry/quaternion_alga.rs index 4b926560..fe1a33b8 100644 --- a/src/geometry/quaternion_alga.rs +++ b/src/geometry/quaternion_alga.rs @@ -98,7 +98,7 @@ impl FiniteDimVectorSpace for Quaternion { #[inline] fn canonical_basis_element(i: usize) -> Self { - Self::from_vector(Vector4::canonical_basis_element(i)) + Self::from(Vector4::canonical_basis_element(i)) } #[inline] @@ -131,7 +131,7 @@ impl NormedSpace for Quaternion { #[inline] fn normalize(&self) -> Self { let v = self.coords.normalize(); - Self::from_vector(v) + Self::from(v) } #[inline] @@ -142,7 +142,7 @@ impl NormedSpace for Quaternion { #[inline] fn try_normalize(&self, min_norm: N) -> Option { if let Some(v) = self.coords.try_normalize(min_norm) { - Some(Self::from_vector(v)) + Some(Self::from(v)) } else { None } diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index 5daa0a3f..53948336 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -23,6 +23,7 @@ impl Quaternion { /// Creates a quaternion from a 4D vector. The quaternion scalar part corresponds to the `w` /// vector component. #[inline] + #[deprecated(note = "Use `::from` instead.")] pub fn from_vector(vector: Vector4) -> Self { Quaternion { coords: vector } } @@ -34,7 +35,7 @@ impl Quaternion { #[inline] pub fn new(w: N, x: N, y: N, z: N) -> Self { let v = Vector4::::new(x, y, z, w); - Self::from_vector(v) + Self::from(v) } /// Creates a new quaternion from its scalar and vector parts. Note that the arguments order does diff --git a/src/geometry/quaternion_conversion.rs b/src/geometry/quaternion_conversion.rs index 451bc9c0..0f8a0d68 100644 --- a/src/geometry/quaternion_conversion.rs +++ b/src/geometry/quaternion_conversion.rs @@ -39,7 +39,7 @@ where { #[inline] fn to_superset(&self) -> Quaternion { - Quaternion::from_vector(self.coords.to_superset()) + Quaternion::from(self.coords.to_superset()) } #[inline] @@ -49,7 +49,9 @@ where #[inline] unsafe fn from_superset_unchecked(q: &Quaternion) -> Self { - Self::from_vector(q.coords.to_subset_unchecked()) + Self { + coords: q.coords.to_subset_unchecked(), + } } } @@ -229,3 +231,10 @@ impl From> for Matrix3 { q.to_rotation_matrix().unwrap() } } + +impl From> for Quaternion { + #[inline] + fn from(coords: Vector4) -> Self { + Quaternion { coords } + } +} diff --git a/src/geometry/quaternion_ops.rs b/src/geometry/quaternion_ops.rs index b269335a..c4ccdf13 100644 --- a/src/geometry/quaternion_ops.rs +++ b/src/geometry/quaternion_ops.rs @@ -103,28 +103,28 @@ quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; - Quaternion::from_vector(&self.coords + &rhs.coords); + Quaternion::from(&self.coords + &rhs.coords); 'a, 'b); quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; - Quaternion::from_vector(&self.coords + rhs.coords); + Quaternion::from(&self.coords + rhs.coords); 'a); quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; - Quaternion::from_vector(self.coords + &rhs.coords); + Quaternion::from(self.coords + &rhs.coords); 'b); quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); self: Quaternion, rhs: Quaternion, Output = Quaternion; - Quaternion::from_vector(self.coords + rhs.coords); + Quaternion::from(self.coords + rhs.coords); ); // Quaternion - Quaternion @@ -132,28 +132,28 @@ quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; - Quaternion::from_vector(&self.coords - &rhs.coords); + Quaternion::from(&self.coords - &rhs.coords); 'a, 'b); quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; - Quaternion::from_vector(&self.coords - rhs.coords); + Quaternion::from(&self.coords - rhs.coords); 'a); quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; - Quaternion::from_vector(self.coords - &rhs.coords); + Quaternion::from(self.coords - &rhs.coords); 'b); quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); self: Quaternion, rhs: Quaternion, Output = Quaternion; - Quaternion::from_vector(self.coords - rhs.coords); + Quaternion::from(self.coords - rhs.coords); ); // Quaternion × Quaternion @@ -495,7 +495,7 @@ macro_rules! scalar_op_impl( #[inline] fn $op(self, n: N) -> Self::Output { - Quaternion::from_vector(self.coords.$op(n)) + Quaternion::from(self.coords.$op(n)) } } @@ -504,7 +504,7 @@ macro_rules! scalar_op_impl( #[inline] fn $op(self, n: N) -> Self::Output { - Quaternion::from_vector((&self.coords).$op(n)) + Quaternion::from((&self.coords).$op(n)) } } @@ -530,7 +530,7 @@ macro_rules! left_scalar_mul_impl( #[inline] fn mul(self, right: Quaternion<$T>) -> Self::Output { - Quaternion::from_vector(self * right.coords) + Quaternion::from(self * right.coords) } } @@ -539,7 +539,7 @@ macro_rules! left_scalar_mul_impl( #[inline] fn mul(self, right: &'b Quaternion<$T>) -> Self::Output { - Quaternion::from_vector(self * &right.coords) + Quaternion::from(self * &right.coords) } } )*} @@ -552,7 +552,7 @@ impl Neg for Quaternion { #[inline] fn neg(self) -> Self::Output { - Quaternion::from_vector(-self.coords) + Quaternion::from(-self.coords) } } @@ -561,7 +561,7 @@ impl<'a, N: Real> Neg for &'a Quaternion { #[inline] fn neg(self) -> Self::Output { - Quaternion::from_vector(-&self.coords) + Quaternion::from(-&self.coords) } } diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index bb04b43e..f321d575 100644 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -184,7 +184,7 @@ where ); Self::from_parts( - Translation::from_vector(&self.isometry.translation.vector * scaling), + Translation::from(&self.isometry.translation.vector * scaling), self.isometry.rotation.clone(), self.scaling * scaling, ) diff --git a/src/geometry/similarity_construction.rs b/src/geometry/similarity_construction.rs index 99e18407..a198b196 100644 --- a/src/geometry/similarity_construction.rs +++ b/src/geometry/similarity_construction.rs @@ -70,7 +70,7 @@ where #[inline] pub fn rotation_wrt_point(r: R, p: Point, scaling: N) -> Self { let shift = r.transform_vector(&-&p.coords); - Self::from_parts(Translation::from_vector(shift + p.coords), r, scaling) + Self::from_parts(Translation::from(shift + p.coords), r, scaling) } } @@ -105,7 +105,7 @@ impl Similarity> { #[inline] pub fn new(translation: Vector2, angle: N, scaling: N) -> Self { Self::from_parts( - Translation::from_vector(translation), + Translation::from(translation), Rotation2::new(angle), scaling, ) @@ -117,7 +117,7 @@ impl Similarity> { #[inline] pub fn new(translation: Vector2, angle: N, scaling: N) -> Self { Self::from_parts( - Translation::from_vector(translation), + Translation::from(translation), UnitComplex::new(angle), scaling, ) diff --git a/src/geometry/similarity_conversion.rs b/src/geometry/similarity_conversion.rs index 8da75f38..34943fee 100644 --- a/src/geometry/similarity_conversion.rs +++ b/src/geometry/similarity_conversion.rs @@ -155,7 +155,9 @@ where } let t = m.fixed_slice::(0, D::dim()).into_owned(); - let t = Translation::from_vector(::convert_unchecked(t)); + let t = Translation { + vector: ::convert_unchecked(t), + }; Self::from_parts(t, ::convert_unchecked(mm), ::convert_unchecked(scale)) } diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index 7469c4cd..57fdc05f 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -269,7 +269,7 @@ similarity_binop_impl_all!( [ref ref] => { let shift = self.isometry.rotation.transform_vector(&rhs.translation.vector) * self.scaling(); Similarity::from_parts( - Translation::from_vector(&self.isometry.translation.vector + shift), + Translation::from(&self.isometry.translation.vector + shift), self.isometry.rotation.clone() * rhs.rotation.clone(), self.scaling()) }; @@ -352,7 +352,7 @@ similarity_binop_impl_all!( [ref ref] => { let shift = self.isometry.rotation.transform_vector(&right.vector) * self.scaling(); Similarity::from_parts( - Translation::from_vector(&self.isometry.translation.vector + shift), + Translation::from(&self.isometry.translation.vector + shift), self.isometry.rotation.clone(), self.scaling()) }; diff --git a/src/geometry/unit_complex_ops.rs b/src/geometry/unit_complex_ops.rs index 9c840e10..8f154423 100644 --- a/src/geometry/unit_complex_ops.rs +++ b/src/geometry/unit_complex_ops.rs @@ -260,7 +260,7 @@ complex_op_impl_all!( [val ref] => &self * rhs; [ref ref] => { let shift = self * &rhs.translation.vector; - Isometry::from_parts(Translation::from_vector(shift), self * &rhs.rotation) + Isometry::from_parts(Translation::from(shift), self * &rhs.rotation) }; ); @@ -282,10 +282,10 @@ complex_op_impl_all!( (U2, U1); self: UnitComplex, rhs: Translation, Output = Isometry>; - [val val] => Isometry::from_parts(Translation::from_vector(&self * rhs.vector), self); - [ref val] => Isometry::from_parts(Translation::from_vector( self * rhs.vector), self.clone()); - [val ref] => Isometry::from_parts(Translation::from_vector(&self * &rhs.vector), self); - [ref ref] => Isometry::from_parts(Translation::from_vector( self * &rhs.vector), self.clone()); + [val val] => Isometry::from_parts(Translation::from(&self * rhs.vector), self); + [ref val] => Isometry::from_parts(Translation::from( self * rhs.vector), self.clone()); + [val ref] => Isometry::from_parts(Translation::from(&self * &rhs.vector), self); + [ref ref] => Isometry::from_parts(Translation::from( self * &rhs.vector), self.clone()); ); // Translation × UnitComplex