geometry_model/
pointing_segment.rs1use geometry_tag::SegmentTag;
8use geometry_trait::{Geometry, IndexedAccess, PointMut, Segment};
9
10#[derive(Debug)]
18pub struct PointingSegment<'a, P: PointMut> {
19 start: &'a mut P,
20 end: &'a mut P,
21}
22
23impl<'a, P: PointMut> PointingSegment<'a, P> {
24 #[inline]
30 #[must_use]
31 pub const fn new(start: &'a mut P, end: &'a mut P) -> Self {
32 Self { start, end }
33 }
34
35 #[inline]
37 #[must_use]
38 pub const fn start(&self) -> &P {
39 self.start
40 }
41
42 #[inline]
44 #[must_use]
45 pub const fn end(&self) -> &P {
46 self.end
47 }
48}
49
50impl<P: PointMut> Geometry for PointingSegment<'_, P> {
51 type Kind = SegmentTag;
52 type Point = P;
53}
54
55impl<P: PointMut> IndexedAccess for PointingSegment<'_, P> {
56 #[inline]
57 fn get_indexed<const I: usize, const D: usize>(&self) -> P::Scalar {
58 if I == 0 {
59 self.start.get::<D>()
60 } else {
61 self.end.get::<D>()
62 }
63 }
64
65 #[inline]
66 fn set_indexed<const I: usize, const D: usize>(&mut self, value: P::Scalar) {
67 if I == 0 {
68 self.start.set::<D>(value);
69 } else {
70 self.end.set::<D>(value);
71 }
72 }
73}
74
75impl<P: PointMut> Segment for PointingSegment<'_, P> {}