use glam::{DVec3, Vec3};
pub trait IntoWorldPosition {
fn into_world_position(self) -> DVec3;
}
impl IntoWorldPosition for DVec3 {
fn into_world_position(self) -> DVec3 {
self
}
}
impl IntoWorldPosition for Vec3 {
fn into_world_position(self) -> DVec3 {
self.as_dvec3()
}
}
impl IntoWorldPosition for [f64; 3] {
fn into_world_position(self) -> DVec3 {
DVec3::from_array(self)
}
}
impl IntoWorldPosition for [f32; 3] {
fn into_world_position(self) -> DVec3 {
Vec3::from_array(self).as_dvec3()
}
}
#[cfg(test)]
mod tests {
use super::*;
fn take(p: impl IntoWorldPosition) -> DVec3 {
p.into_world_position()
}
#[test]
fn every_form_converts() {
let expect = DVec3::new(1.0, 2.0, 3.0);
assert_eq!(take(expect), expect);
assert_eq!(take(Vec3::new(1.0, 2.0, 3.0)), expect);
assert_eq!(take([1.0f32, 2.0, 3.0]), expect);
assert_eq!(take([1.0, 2.0, 3.0]), expect);
assert_eq!(take([1_048_576.01, 0.0, 0.0]).x, 1_048_576.01);
}
}