use crate::{
format_float,
linestring_3d::{ChunkIterator, Line3, PriorityDistance, WindowIterator},
};
use std::{fmt, fmt::Debug};
use vector_traits::{approx::ulps_eq, prelude::*};
impl<T: GenericVector3> Iterator for WindowIterator<'_, T> {
type Item = Line3<T>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|window| Line3 {
start: window[0],
end: window[1],
})
}
}
impl<T: GenericVector3> Iterator for ChunkIterator<'_, T> {
type Item = Line3<T>;
fn next(&mut self) -> Option<Self::Item> {
self.0.next().map(|window| Line3 {
start: window[0],
end: window[1],
})
}
}
impl<T: GenericVector3> From<[T::Scalar; 6]> for Line3<T> {
fn from(value: [T::Scalar; 6]) -> Self {
Line3 {
start: T::new_3d(value[0], value[1], value[2]),
end: T::new_3d(value[3], value[4], value[5]),
}
}
}
impl<T: GenericVector3> Debug for Line3<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"({},{},{})-({},{},{})",
format_float(self.start.x()),
format_float(self.start.y()),
format_float(self.start.z()),
format_float(self.end.x()),
format_float(self.end.y()),
format_float(self.end.z()),
)
}
}
impl<T: GenericVector3, IT: Copy + Into<T>> From<[IT; 2]> for Line3<T> {
fn from(pos: [IT; 2]) -> Line3<T> {
Line3::<T>::new(pos[0].into(), pos[1].into())
}
}
impl<T: GenericVector3> PartialOrd for PriorityDistance<T> {
#[inline(always)]
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}
impl<T: GenericVector3> Ord for PriorityDistance<T> {
#[inline(always)]
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.key.partial_cmp(&other.key).unwrap().reverse()
}
}
impl<T: GenericVector3> PartialEq for PriorityDistance<T> {
#[inline(always)]
fn eq(&self, other: &Self) -> bool {
ulps_eq!(self.key, other.key)
}
}
impl<T: GenericVector3> Eq for PriorityDistance<T> {}