diff --git a/crates/cross/src/vec.rs b/crates/cross/src/vec.rs index 2ac670f..a15aca0 100644 --- a/crates/cross/src/vec.rs +++ b/crates/cross/src/vec.rs @@ -253,6 +253,22 @@ impl Vec3 { pub fn with_xy(&self, xy: Vec2) -> Self { Self::new(xy.x(), xy.y(), self.z()) } + pub fn xz(&self) -> Vec2 { + Vec2::new(self.x(), self.z()) + } + pub fn with_xz(&self, xz: Vec2) -> 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 { + Vec2::new(self.y(), self.z()) + } + pub fn with_yz(&self, yz: Vec2) -> 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 { (*self - other).mag() @@ -365,6 +381,25 @@ impl Vec3 { pub fn floor(&self) -> Self { 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 Into<(R, R, R)> for Vec3 {