|
8 | 8 |
|
9 | 9 | use na::{RealField, Scalar}; |
10 | 10 | use serde::{Deserialize, Serialize}; |
| 11 | +use simba::scalar::SupersetOf; |
11 | 12 | use std::ops::*; |
12 | 13 |
|
13 | 14 | /// A stack-allocated 4-dimensional column-vector in Minkowski space. Such |
@@ -106,6 +107,12 @@ impl<N: RealField + Copy> MVector<N> { |
106 | 107 | self.0 * na::RowVector4::new(other.x, other.y, other.z, -other.w) |
107 | 108 | } |
108 | 109 |
|
| 110 | + /// Cast the components of `self` to another type. |
| 111 | + #[inline] |
| 112 | + pub fn cast<N2: RealField + Copy + SupersetOf<N>>(self) -> MVector<N2> { |
| 113 | + MVector(self.0.cast()) |
| 114 | + } |
| 115 | + |
109 | 116 | /// The column vector with components `[0, 0, 0, 0]`. |
110 | 117 | #[inline] |
111 | 118 | pub fn zero() -> Self { |
@@ -158,20 +165,6 @@ impl<N: RealField + Copy> MVector<N> { |
158 | 165 | } |
159 | 166 | } |
160 | 167 |
|
161 | | -impl MVector<f32> { |
162 | | - /// Casts the components to an `f64` |
163 | | - pub fn to_f64(self) -> MVector<f64> { |
164 | | - MVector(self.0.cast::<f64>()) |
165 | | - } |
166 | | -} |
167 | | - |
168 | | -impl MVector<f64> { |
169 | | - /// Casts the components to an `f32` |
170 | | - pub fn to_f32(self) -> MVector<f32> { |
171 | | - MVector(self.0.cast::<f32>()) |
172 | | - } |
173 | | -} |
174 | | - |
175 | 168 | impl<N: Scalar> Index<usize> for MVector<N> { |
176 | 169 | type Output = N; |
177 | 170 | #[inline] |
@@ -465,19 +458,11 @@ impl<N: RealField + Copy> MIsometry<N> { |
465 | 458 | // orientation components. |
466 | 459 | normalized_translation_component * normalized_orientation_component |
467 | 460 | } |
468 | | -} |
469 | 461 |
|
470 | | -impl MIsometry<f32> { |
471 | | - /// Casts the components to an `f64` |
472 | | - pub fn to_f64(self) -> MIsometry<f64> { |
473 | | - MIsometry(self.0.cast::<f64>()) |
474 | | - } |
475 | | -} |
476 | | - |
477 | | -impl MIsometry<f64> { |
478 | | - /// Casts the components to an `f32` |
479 | | - pub fn to_f32(self) -> MIsometry<f32> { |
480 | | - MIsometry(self.0.cast::<f32>()) |
| 462 | + /// Cast the components of `self` to another type. |
| 463 | + #[inline] |
| 464 | + pub fn cast<N2: RealField + Copy + SupersetOf<N>>(self) -> MIsometry<N2> { |
| 465 | + MIsometry(self.0.cast()) |
481 | 466 | } |
482 | 467 | } |
483 | 468 |
|
|
0 commit comments