use glam::DVec3;
use crate::traits::Discard;
pub trait RotateTransform {
fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self;
fn rotate_on_x(&mut self, angle: f64) -> &mut Self {
self.rotate_on_axis(DVec3::X, angle)
}
fn rotate_on_y(&mut self, angle: f64) -> &mut Self {
self.rotate_on_axis(DVec3::Y, angle)
}
fn rotate_on_z(&mut self, angle: f64) -> &mut Self {
self.rotate_on_axis(DVec3::Z, angle)
}
}
impl RotateTransform for DVec3 {
fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self {
*self = DVec3::rotate_axis(*self, axis, angle);
self
}
}
impl<T: RotateTransform> RotateTransform for [T] {
fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self {
self.iter_mut()
.for_each(|x| x.rotate_on_axis(axis, angle).discard());
self
}
}
impl<T: RotateTransform> RotateTransform for Vec<T> {
fn rotate_on_axis(&mut self, axis: DVec3, angle: f64) -> &mut Self {
self.as_mut_slice().rotate_on_axis(axis, angle);
self
}
}