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