use geometry_tag::SegmentTag;
use geometry_trait::{Geometry, IndexedAccess, PointMut, Segment};
#[derive(Debug)]
pub struct PointingSegment<'a, P: PointMut> {
start: &'a mut P,
end: &'a mut P,
}
impl<'a, P: PointMut> PointingSegment<'a, P> {
#[inline]
#[must_use]
pub const fn new(start: &'a mut P, end: &'a mut P) -> Self {
Self { start, end }
}
#[inline]
#[must_use]
pub const fn start(&self) -> &P {
self.start
}
#[inline]
#[must_use]
pub const fn end(&self) -> &P {
self.end
}
}
impl<P: PointMut> Geometry for PointingSegment<'_, P> {
type Kind = SegmentTag;
type Point = P;
}
impl<P: PointMut> IndexedAccess for PointingSegment<'_, P> {
#[inline]
fn get_indexed<const I: usize, const D: usize>(&self) -> P::Scalar {
if I == 0 {
self.start.get::<D>()
} else {
self.end.get::<D>()
}
}
#[inline]
fn set_indexed<const I: usize, const D: usize>(&mut self, value: P::Scalar) {
if I == 0 {
self.start.set::<D>(value);
} else {
self.end.set::<D>(value);
}
}
}
impl<P: PointMut> Segment for PointingSegment<'_, P> {}