cross: Vec3: implement rotate_{xy,xz,yz} operations

This commit is contained in:
2022-09-01 21:38:06 -07:00
parent 2044397047
commit 491b5d3591

View File

@@ -253,6 +253,22 @@ impl<R: Real> Vec3<R> {
pub fn with_xy(&self, xy: Vec2<R>) -> Self { pub fn with_xy(&self, xy: Vec2<R>) -> Self {
Self::new(xy.x(), xy.y(), self.z()) Self::new(xy.x(), xy.y(), self.z())
} }
pub fn xz(&self) -> Vec2<R> {
Vec2::new(self.x(), self.z())
}
pub fn with_xz(&self, xz: Vec2<R>) -> Self {
// NB: the `Vec2` type calls these coordinates `x` and `y`
// even though they represent `x` and `z` in this context.
Self::new(xz.x(), self.y(), xz.y())
}
pub fn yz(&self) -> Vec2<R> {
Vec2::new(self.y(), self.z())
}
pub fn with_yz(&self, yz: Vec2<R>) -> Self {
// NB: the `Vec2` type calls these coordinates `x` and `y`
// even though they represent `y` and `z` in this context.
Self::new(self.x(), yz.x(), yz.y())
}
pub fn distance(&self, other: Self) -> R { pub fn distance(&self, other: Self) -> R {
(*self - other).mag() (*self - other).mag()
@@ -365,6 +381,25 @@ impl<R: Real> Vec3<R> {
pub fn floor(&self) -> Self { pub fn floor(&self) -> Self {
Self::new(self.x().floor(), self.y().floor(), self.z().floor()) Self::new(self.x().floor(), self.y().floor(), self.z().floor())
} }
/// rotate in the xy plane
pub fn rotate_xy(&self, angle: R) -> Self {
self.with_xy(
self.xy().rotate(angle)
)
}
/// rotate in the xz plane
pub fn rotate_xz(&self, angle: R) -> Self {
self.with_xz(
self.xz().rotate(angle)
)
}
/// rotate in the yz plane
pub fn rotate_yz(&self, angle: R) -> Self {
self.with_yz(
self.yz().rotate(angle)
)
}
} }
impl<R> Into<(R, R, R)> for Vec3<R> { impl<R> Into<(R, R, R)> for Vec3<R> {