nalgebra/geometry/rotation.rs
1// Needed otherwise the rkyv macros generate code incompatible with rust-2024
2#![cfg_attr(feature = "rkyv-serialize", allow(unsafe_op_in_unsafe_fn))]
3
4use approx::{AbsDiffEq, RelativeEq, UlpsEq};
5use num::{One, Zero};
6use std::fmt;
7use std::hash;
8
9#[cfg(feature = "serde-serialize-no-std")]
10use serde::{Deserialize, Deserializer, Serialize, Serializer};
11
12#[cfg(feature = "serde-serialize-no-std")]
13use crate::base::storage::Owned;
14
15use simba::scalar::RealField;
16use simba::simd::SimdRealField;
17
18use crate::base::allocator::Allocator;
19use crate::base::dimension::{DimNameAdd, DimNameSum, U1};
20use crate::base::{Const, DefaultAllocator, OMatrix, SMatrix, SVector, Scalar, Unit};
21use crate::geometry::Point;
22
23#[cfg(feature = "rkyv-serialize")]
24use rkyv::bytecheck;
25
26/// A rotation matrix.
27///
28/// This is also known as an element of a Special Orthogonal (SO) group.
29/// The `Rotation` type can either represent a 2D or 3D rotation, represented as a matrix.
30/// For a rotation based on quaternions, see [`UnitQuaternion`](crate::UnitQuaternion) instead.
31///
32/// Note that instead of using the [`Rotation`](crate::Rotation) type in your code directly, you should use one
33/// of its aliases: [`Rotation2`](crate::Rotation2), or [`Rotation3`](crate::Rotation3). Though
34/// keep in mind that all the documentation of all the methods of these aliases will also appears on
35/// this page.
36///
37/// # Construction
38/// * [Identity <span style="float:right;">`identity`</span>](#identity)
39/// * [From a 2D rotation angle <span style="float:right;">`new`…</span>](#construction-from-a-2d-rotation-angle)
40/// * [From an existing 2D matrix or rotations <span style="float:right;">`from_matrix`, `rotation_between`, `powf`…</span>](#construction-from-an-existing-2d-matrix-or-rotations)
41/// * [From a 3D axis and/or angles <span style="float:right;">`new`, `from_euler_angles`, `from_axis_angle`…</span>](#construction-from-a-3d-axis-andor-angles)
42/// * [From a 3D eye position and target point <span style="float:right;">`look_at`, `look_at_lh`, `rotation_between`…</span>](#construction-from-a-3d-eye-position-and-target-point)
43/// * [From an existing 3D matrix or rotations <span style="float:right;">`from_matrix`, `rotation_between`, `powf`…</span>](#construction-from-an-existing-3d-matrix-or-rotations)
44///
45/// # Transformation and composition
46/// Note that transforming vectors and points can be done by multiplication, e.g., `rotation * point`.
47/// Composing an rotation with another transformation can also be done by multiplication or division.
48/// * [3D axis and angle extraction <span style="float:right;">`angle`, `euler_angles`, `scaled_axis`, `angle_to`…</span>](#3d-axis-and-angle-extraction)
49/// * [2D angle extraction <span style="float:right;">`angle`, `angle_to`…</span>](#2d-angle-extraction)
50/// * [Transformation of a vector or a point <span style="float:right;">`transform_vector`, `inverse_transform_point`…</span>](#transformation-of-a-vector-or-a-point)
51/// * [Transposition and inversion <span style="float:right;">`transpose`, `inverse`…</span>](#transposition-and-inversion)
52/// * [Interpolation <span style="float:right;">`slerp`…</span>](#interpolation)
53///
54/// # Conversion
55/// * [Conversion to a matrix <span style="float:right;">`matrix`, `to_homogeneous`…</span>](#conversion-to-a-matrix)
56///
57#[repr(C)]
58#[cfg_attr(
59 feature = "rkyv-serialize-no-std",
60 derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize),
61 archive(
62 as = "Rotation<T::Archived, D>",
63 bound(archive = "
64 T: rkyv::Archive,
65 SMatrix<T, D, D>: rkyv::Archive<Archived = SMatrix<T::Archived, D, D>>
66 ")
67 )
68)]
69#[cfg_attr(feature = "rkyv-serialize", derive(bytecheck::CheckBytes))]
70#[cfg_attr(feature = "defmt", derive(defmt::Format))]
71#[derive(Copy, Clone)]
72pub struct Rotation<T, const D: usize> {
73 matrix: SMatrix<T, D, D>,
74}
75
76impl<T: fmt::Debug, const D: usize> fmt::Debug for Rotation<T, D> {
77 fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
78 self.matrix.fmt(formatter)
79 }
80}
81
82impl<T: Scalar + hash::Hash, const D: usize> hash::Hash for Rotation<T, D>
83where
84 <DefaultAllocator as Allocator<Const<D>, Const<D>>>::Buffer<T>: hash::Hash,
85{
86 fn hash<H: hash::Hasher>(&self, state: &mut H) {
87 self.matrix.hash(state)
88 }
89}
90
91#[cfg(feature = "bytemuck")]
92unsafe impl<T, const D: usize> bytemuck::Zeroable for Rotation<T, D>
93where
94 T: Scalar + bytemuck::Zeroable,
95 SMatrix<T, D, D>: bytemuck::Zeroable,
96{
97}
98
99#[cfg(feature = "bytemuck")]
100unsafe impl<T, const D: usize> bytemuck::Pod for Rotation<T, D>
101where
102 T: Scalar + bytemuck::Pod,
103 SMatrix<T, D, D>: bytemuck::Pod,
104{
105}
106
107#[cfg(feature = "serde-serialize-no-std")]
108impl<T: Scalar, const D: usize> Serialize for Rotation<T, D>
109where
110 Owned<T, Const<D>, Const<D>>: Serialize,
111{
112 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
113 where
114 S: Serializer,
115 {
116 self.matrix.serialize(serializer)
117 }
118}
119
120#[cfg(feature = "serde-serialize-no-std")]
121impl<'a, T: Scalar, const D: usize> Deserialize<'a> for Rotation<T, D>
122where
123 Owned<T, Const<D>, Const<D>>: Deserialize<'a>,
124{
125 fn deserialize<Des>(deserializer: Des) -> Result<Self, Des::Error>
126 where
127 Des: Deserializer<'a>,
128 {
129 let matrix = SMatrix::<T, D, D>::deserialize(deserializer)?;
130
131 Ok(Self::from_matrix_unchecked(matrix))
132 }
133}
134
135impl<T, const D: usize> Rotation<T, D> {
136 /// Creates a new rotation from the given square matrix.
137 ///
138 /// The matrix orthonormality is not checked.
139 ///
140 /// # Example
141 /// ```
142 /// # use nalgebra::{Rotation2, Rotation3, Matrix2, Matrix3};
143 /// # use std::f32;
144 /// let mat = Matrix3::new(0.8660254, -0.5, 0.0,
145 /// 0.5, 0.8660254, 0.0,
146 /// 0.0, 0.0, 1.0);
147 /// let rot = Rotation3::from_matrix_unchecked(mat);
148 ///
149 /// assert_eq!(*rot.matrix(), mat);
150 ///
151 ///
152 /// let mat = Matrix2::new(0.8660254, -0.5,
153 /// 0.5, 0.8660254);
154 /// let rot = Rotation2::from_matrix_unchecked(mat);
155 ///
156 /// assert_eq!(*rot.matrix(), mat);
157 /// ```
158 #[inline]
159 pub const fn from_matrix_unchecked(matrix: SMatrix<T, D, D>) -> Self {
160 Self { matrix }
161 }
162}
163
164/// # Conversion to a matrix
165impl<T: Scalar, const D: usize> Rotation<T, D> {
166 /// A reference to the underlying matrix representation of this rotation.
167 ///
168 /// # Example
169 /// ```
170 /// # use nalgebra::{Rotation2, Rotation3, Vector3, Matrix2, Matrix3};
171 /// # use std::f32;
172 /// let rot = Rotation3::from_axis_angle(&Vector3::z_axis(), f32::consts::FRAC_PI_6);
173 /// let expected = Matrix3::new(0.8660254, -0.5, 0.0,
174 /// 0.5, 0.8660254, 0.0,
175 /// 0.0, 0.0, 1.0);
176 /// assert_eq!(*rot.matrix(), expected);
177 ///
178 ///
179 /// let rot = Rotation2::new(f32::consts::FRAC_PI_6);
180 /// let expected = Matrix2::new(0.8660254, -0.5,
181 /// 0.5, 0.8660254);
182 /// assert_eq!(*rot.matrix(), expected);
183 /// ```
184 #[inline]
185 #[must_use]
186 pub const fn matrix(&self) -> &SMatrix<T, D, D> {
187 &self.matrix
188 }
189
190 /// A mutable reference to the underlying matrix representation of this rotation.
191 ///
192 /// # Safety
193 ///
194 /// Invariants of the rotation matrix should not be violated.
195 #[inline]
196 #[deprecated(note = "Use `.matrix_mut_unchecked()` instead.")]
197 pub const unsafe fn matrix_mut(&mut self) -> &mut SMatrix<T, D, D> {
198 &mut self.matrix
199 }
200
201 /// A mutable reference to the underlying matrix representation of this rotation.
202 ///
203 /// This is suffixed by "_unchecked" because this allows the user to replace the
204 /// matrix by another one that is non-inversible or non-orthonormal. If one of
205 /// those properties is broken, subsequent method calls may return bogus results.
206 #[inline]
207 pub const fn matrix_mut_unchecked(&mut self) -> &mut SMatrix<T, D, D> {
208 &mut self.matrix
209 }
210
211 /// Unwraps the underlying matrix.
212 ///
213 /// # Example
214 /// ```
215 /// # use nalgebra::{Rotation2, Rotation3, Vector3, Matrix2, Matrix3};
216 /// # use std::f32;
217 /// let rot = Rotation3::from_axis_angle(&Vector3::z_axis(), f32::consts::FRAC_PI_6);
218 /// let mat = rot.into_inner();
219 /// let expected = Matrix3::new(0.8660254, -0.5, 0.0,
220 /// 0.5, 0.8660254, 0.0,
221 /// 0.0, 0.0, 1.0);
222 /// assert_eq!(mat, expected);
223 ///
224 ///
225 /// let rot = Rotation2::new(f32::consts::FRAC_PI_6);
226 /// let mat = rot.into_inner();
227 /// let expected = Matrix2::new(0.8660254, -0.5,
228 /// 0.5, 0.8660254);
229 /// assert_eq!(mat, expected);
230 /// ```
231 #[inline]
232 pub fn into_inner(self) -> SMatrix<T, D, D> {
233 self.matrix
234 }
235
236 /// Unwraps the underlying matrix.
237 /// Deprecated: Use [`Rotation::into_inner`] instead.
238 #[deprecated(note = "use `.into_inner()` instead")]
239 #[inline]
240 pub fn unwrap(self) -> SMatrix<T, D, D> {
241 self.matrix
242 }
243
244 /// Converts this rotation into its equivalent homogeneous transformation matrix.
245 ///
246 /// This is the same as `self.into()`.
247 ///
248 /// # Example
249 /// ```
250 /// # use nalgebra::{Rotation2, Rotation3, Vector3, Matrix3, Matrix4};
251 /// # use std::f32;
252 /// let rot = Rotation3::from_axis_angle(&Vector3::z_axis(), f32::consts::FRAC_PI_6);
253 /// let expected = Matrix4::new(0.8660254, -0.5, 0.0, 0.0,
254 /// 0.5, 0.8660254, 0.0, 0.0,
255 /// 0.0, 0.0, 1.0, 0.0,
256 /// 0.0, 0.0, 0.0, 1.0);
257 /// assert_eq!(rot.to_homogeneous(), expected);
258 ///
259 ///
260 /// let rot = Rotation2::new(f32::consts::FRAC_PI_6);
261 /// let expected = Matrix3::new(0.8660254, -0.5, 0.0,
262 /// 0.5, 0.8660254, 0.0,
263 /// 0.0, 0.0, 1.0);
264 /// assert_eq!(rot.to_homogeneous(), expected);
265 /// ```
266 #[inline]
267 #[must_use]
268 pub fn to_homogeneous(&self) -> OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
269 where
270 T: Zero + One,
271 Const<D>: DimNameAdd<U1>,
272 DefaultAllocator: Allocator<DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
273 {
274 // We could use `SMatrix::to_homogeneous()` here, but that would imply
275 // adding the additional traits `DimAdd` and `IsNotStaticOne`. Maybe
276 // these things will get nicer once specialization lands in Rust.
277 let mut res = OMatrix::<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>::identity();
278 res.fixed_view_mut::<D, D>(0, 0).copy_from(&self.matrix);
279
280 res
281 }
282}
283
284/// # Transposition and inversion
285impl<T: Scalar, const D: usize> Rotation<T, D> {
286 /// Transposes `self`.
287 ///
288 /// Same as `.inverse()` because the inverse of a rotation matrix is its transpose.
289 ///
290 /// # Example
291 /// ```
292 /// # #[macro_use] extern crate approx;
293 /// # use nalgebra::{Rotation2, Rotation3, Vector3};
294 /// let rot = Rotation3::new(Vector3::new(1.0, 2.0, 3.0));
295 /// let tr_rot = rot.transpose();
296 /// assert_relative_eq!(rot * tr_rot, Rotation3::identity(), epsilon = 1.0e-6);
297 /// assert_relative_eq!(tr_rot * rot, Rotation3::identity(), epsilon = 1.0e-6);
298 ///
299 /// let rot = Rotation2::new(1.2);
300 /// let tr_rot = rot.transpose();
301 /// assert_relative_eq!(rot * tr_rot, Rotation2::identity(), epsilon = 1.0e-6);
302 /// assert_relative_eq!(tr_rot * rot, Rotation2::identity(), epsilon = 1.0e-6);
303 /// ```
304 #[inline]
305 #[must_use = "Did you mean to use transpose_mut()?"]
306 pub fn transpose(&self) -> Self {
307 Self::from_matrix_unchecked(self.matrix.transpose())
308 }
309
310 /// Inverts `self`.
311 ///
312 /// Same as `.transpose()` because the inverse of a rotation matrix is its transpose.
313 ///
314 /// # Example
315 /// ```
316 /// # #[macro_use] extern crate approx;
317 /// # use nalgebra::{Rotation2, Rotation3, Vector3};
318 /// let rot = Rotation3::new(Vector3::new(1.0, 2.0, 3.0));
319 /// let inv = rot.inverse();
320 /// assert_relative_eq!(rot * inv, Rotation3::identity(), epsilon = 1.0e-6);
321 /// assert_relative_eq!(inv * rot, Rotation3::identity(), epsilon = 1.0e-6);
322 ///
323 /// let rot = Rotation2::new(1.2);
324 /// let inv = rot.inverse();
325 /// assert_relative_eq!(rot * inv, Rotation2::identity(), epsilon = 1.0e-6);
326 /// assert_relative_eq!(inv * rot, Rotation2::identity(), epsilon = 1.0e-6);
327 /// ```
328 #[inline]
329 #[must_use = "Did you mean to use inverse_mut()?"]
330 pub fn inverse(&self) -> Self {
331 self.transpose()
332 }
333
334 /// Transposes `self` in-place.
335 ///
336 /// Same as `.inverse_mut()` because the inverse of a rotation matrix is its transpose.
337 ///
338 /// # Example
339 /// ```
340 /// # #[macro_use] extern crate approx;
341 /// # use nalgebra::{Rotation2, Rotation3, Vector3};
342 /// let rot = Rotation3::new(Vector3::new(1.0, 2.0, 3.0));
343 /// let mut tr_rot = Rotation3::new(Vector3::new(1.0, 2.0, 3.0));
344 /// tr_rot.transpose_mut();
345 ///
346 /// assert_relative_eq!(rot * tr_rot, Rotation3::identity(), epsilon = 1.0e-6);
347 /// assert_relative_eq!(tr_rot * rot, Rotation3::identity(), epsilon = 1.0e-6);
348 ///
349 /// let rot = Rotation2::new(1.2);
350 /// let mut tr_rot = Rotation2::new(1.2);
351 /// tr_rot.transpose_mut();
352 ///
353 /// assert_relative_eq!(rot * tr_rot, Rotation2::identity(), epsilon = 1.0e-6);
354 /// assert_relative_eq!(tr_rot * rot, Rotation2::identity(), epsilon = 1.0e-6);
355 /// ```
356 #[inline]
357 pub fn transpose_mut(&mut self) {
358 self.matrix.transpose_mut()
359 }
360
361 /// Inverts `self` in-place.
362 ///
363 /// Same as `.transpose_mut()` because the inverse of a rotation matrix is its transpose.
364 ///
365 /// # Example
366 /// ```
367 /// # #[macro_use] extern crate approx;
368 /// # use nalgebra::{Rotation2, Rotation3, Vector3};
369 /// let rot = Rotation3::new(Vector3::new(1.0, 2.0, 3.0));
370 /// let mut inv = Rotation3::new(Vector3::new(1.0, 2.0, 3.0));
371 /// inv.inverse_mut();
372 ///
373 /// assert_relative_eq!(rot * inv, Rotation3::identity(), epsilon = 1.0e-6);
374 /// assert_relative_eq!(inv * rot, Rotation3::identity(), epsilon = 1.0e-6);
375 ///
376 /// let rot = Rotation2::new(1.2);
377 /// let mut inv = Rotation2::new(1.2);
378 /// inv.inverse_mut();
379 ///
380 /// assert_relative_eq!(rot * inv, Rotation2::identity(), epsilon = 1.0e-6);
381 /// assert_relative_eq!(inv * rot, Rotation2::identity(), epsilon = 1.0e-6);
382 /// ```
383 #[inline]
384 pub fn inverse_mut(&mut self) {
385 self.transpose_mut()
386 }
387}
388
389/// # Transformation of a vector or a point
390impl<T: SimdRealField, const D: usize> Rotation<T, D>
391where
392 T::Element: SimdRealField,
393{
394 /// Rotate the given point.
395 ///
396 /// This is the same as the multiplication `self * pt`.
397 ///
398 /// # Example
399 /// ```
400 /// # #[macro_use] extern crate approx;
401 /// # use std::f32;
402 /// # use nalgebra::{Point3, Rotation2, Rotation3, UnitQuaternion, Vector3};
403 /// let rot = Rotation3::new(Vector3::y() * f32::consts::FRAC_PI_2);
404 /// let transformed_point = rot.transform_point(&Point3::new(1.0, 2.0, 3.0));
405 ///
406 /// assert_relative_eq!(transformed_point, Point3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6);
407 /// ```
408 #[inline]
409 #[must_use]
410 pub fn transform_point(&self, pt: &Point<T, D>) -> Point<T, D> {
411 self * pt
412 }
413
414 /// Rotate the given vector.
415 ///
416 /// This is the same as the multiplication `self * v`.
417 ///
418 /// # Example
419 /// ```
420 /// # #[macro_use] extern crate approx;
421 /// # use std::f32;
422 /// # use nalgebra::{Rotation2, Rotation3, UnitQuaternion, Vector3};
423 /// let rot = Rotation3::new(Vector3::y() * f32::consts::FRAC_PI_2);
424 /// let transformed_vector = rot.transform_vector(&Vector3::new(1.0, 2.0, 3.0));
425 ///
426 /// assert_relative_eq!(transformed_vector, Vector3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6);
427 /// ```
428 #[inline]
429 #[must_use]
430 pub fn transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> {
431 self * v
432 }
433
434 /// Rotate the given point by the inverse of this rotation. This may be
435 /// cheaper than inverting the rotation and then transforming the given
436 /// point.
437 ///
438 /// # Example
439 /// ```
440 /// # #[macro_use] extern crate approx;
441 /// # use std::f32;
442 /// # use nalgebra::{Point3, Rotation2, Rotation3, UnitQuaternion, Vector3};
443 /// let rot = Rotation3::new(Vector3::y() * f32::consts::FRAC_PI_2);
444 /// let transformed_point = rot.inverse_transform_point(&Point3::new(1.0, 2.0, 3.0));
445 ///
446 /// assert_relative_eq!(transformed_point, Point3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6);
447 /// ```
448 #[inline]
449 #[must_use]
450 pub fn inverse_transform_point(&self, pt: &Point<T, D>) -> Point<T, D> {
451 Point::from(self.inverse_transform_vector(&pt.coords))
452 }
453
454 /// Rotate the given vector by the inverse of this rotation. This may be
455 /// cheaper than inverting the rotation and then transforming the given
456 /// vector.
457 ///
458 /// # Example
459 /// ```
460 /// # #[macro_use] extern crate approx;
461 /// # use std::f32;
462 /// # use nalgebra::{Rotation2, Rotation3, UnitQuaternion, Vector3};
463 /// let rot = Rotation3::new(Vector3::y() * f32::consts::FRAC_PI_2);
464 /// let transformed_vector = rot.inverse_transform_vector(&Vector3::new(1.0, 2.0, 3.0));
465 ///
466 /// assert_relative_eq!(transformed_vector, Vector3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6);
467 /// ```
468 #[inline]
469 #[must_use]
470 pub fn inverse_transform_vector(&self, v: &SVector<T, D>) -> SVector<T, D> {
471 self.matrix().tr_mul(v)
472 }
473
474 /// Rotate the given vector by the inverse of this rotation. This may be
475 /// cheaper than inverting the rotation and then transforming the given
476 /// vector.
477 ///
478 /// # Example
479 /// ```
480 /// # #[macro_use] extern crate approx;
481 /// # use std::f32;
482 /// # use nalgebra::{Rotation2, Rotation3, UnitQuaternion, Vector3};
483 /// let rot = Rotation3::new(Vector3::z() * f32::consts::FRAC_PI_2);
484 /// let transformed_vector = rot.inverse_transform_unit_vector(&Vector3::x_axis());
485 ///
486 /// assert_relative_eq!(transformed_vector, -Vector3::y_axis(), epsilon = 1.0e-6);
487 /// ```
488 #[inline]
489 #[must_use]
490 pub fn inverse_transform_unit_vector(&self, v: &Unit<SVector<T, D>>) -> Unit<SVector<T, D>> {
491 Unit::new_unchecked(self.inverse_transform_vector(&**v))
492 }
493}
494
495impl<T: Scalar + Eq, const D: usize> Eq for Rotation<T, D> {}
496
497impl<T: Scalar + PartialEq, const D: usize> PartialEq for Rotation<T, D> {
498 #[inline]
499 fn eq(&self, right: &Self) -> bool {
500 self.matrix == right.matrix
501 }
502}
503
504impl<T, const D: usize> AbsDiffEq for Rotation<T, D>
505where
506 T: Scalar + AbsDiffEq,
507 T::Epsilon: Clone,
508{
509 type Epsilon = T::Epsilon;
510
511 #[inline]
512 fn default_epsilon() -> Self::Epsilon {
513 T::default_epsilon()
514 }
515
516 #[inline]
517 fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool {
518 self.matrix.abs_diff_eq(&other.matrix, epsilon)
519 }
520}
521
522impl<T, const D: usize> RelativeEq for Rotation<T, D>
523where
524 T: Scalar + RelativeEq,
525 T::Epsilon: Clone,
526{
527 #[inline]
528 fn default_max_relative() -> Self::Epsilon {
529 T::default_max_relative()
530 }
531
532 #[inline]
533 fn relative_eq(
534 &self,
535 other: &Self,
536 epsilon: Self::Epsilon,
537 max_relative: Self::Epsilon,
538 ) -> bool {
539 self.matrix
540 .relative_eq(&other.matrix, epsilon, max_relative)
541 }
542}
543
544impl<T, const D: usize> UlpsEq for Rotation<T, D>
545where
546 T: Scalar + UlpsEq,
547 T::Epsilon: Clone,
548{
549 #[inline]
550 fn default_max_ulps() -> u32 {
551 T::default_max_ulps()
552 }
553
554 #[inline]
555 fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool {
556 self.matrix.ulps_eq(&other.matrix, epsilon, max_ulps)
557 }
558}
559
560/*
561 *
562 * Display
563 *
564 */
565impl<T, const D: usize> fmt::Display for Rotation<T, D>
566where
567 T: RealField + fmt::Display,
568{
569 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
570 let precision = f.precision().unwrap_or(3);
571
572 writeln!(f, "Rotation matrix {{")?;
573 write!(f, "{:.*}", precision, self.matrix)?;
574 writeln!(f, "}}")
575 }
576}
577
578// // /*
579// // *
580// // * Absolute
581// // *
582// // */
583// // impl<T: Absolute> Absolute for $t<T> {
584// // type AbsoluteValue = $submatrix<T::AbsoluteValue>;
585// //
586// // #[inline]
587// // fn abs(m: &$t<T>) -> $submatrix<T::AbsoluteValue> {
588// // Absolute::abs(&m.submatrix)
589// // }
590// // }