Skip to content

Commit

Permalink
Merge pull request #1120 from Ralith/unit-vector-cast
Browse files Browse the repository at this point in the history
Implement `cast` for `Unit<Vector<T, D, S>>`
  • Loading branch information
sebcrozet authored Aug 14, 2022
2 parents 0fcf2f6 + 8aa10b8 commit d09d068
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/base/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,3 +2186,28 @@ where
}
}
}

impl<T, D, S> Unit<Vector<T, D, S>>
where
T: Scalar,
D: Dim,
S: RawStorage<T, D, U1>,
{
/// Cast the components of `self` to another type.
///
/// # Example
/// ```
/// # use nalgebra::Vector3;
/// let v = Vector3::<f64>::y_axis();
/// let v2 = v.cast::<f32>();
/// assert_eq!(v2, Vector3::<f32>::y_axis());
/// ```
pub fn cast<T2: Scalar>(self) -> Unit<OVector<T2, D>>
where
T: Scalar,
OVector<T2, D>: SupersetOf<Vector<T, D, S>>,
DefaultAllocator: Allocator<T2, D, U1>,
{
Unit::new_unchecked(crate::convert_ref(self.as_ref()))
}
}

0 comments on commit d09d068

Please sign in to comment.