use crate::geo::coordinate::*;
pub trait CoordinateExt {
fn unit_vector() -> Self;
}
pub trait Coordinate2DExt {
fn unit_vector_at_angle(radians: impl Into<f64>) -> Self;
}
impl<T> CoordinateExt for T
where
T: Coordinate,
{
fn unit_vector() -> Self {
let mut components = vec![0.0; Self::len()];
components[0] = 1.0;
Self::from_components(&components)
}
}
impl<T> Coordinate2DExt for T
where
T: Coordinate+Coordinate2D,
{
fn unit_vector_at_angle(radians: impl Into<f64>) -> Self {
let radians = radians.into();
Self::from_components(&[radians.cos(), radians.sin()])
}
}