1use std::marker::PhantomData;
2
3use crate::{CoordTrait, GeometryTrait, UnimplementedCoord};
4#[cfg(feature = "geo-types")]
5use geo_types::{Coord, CoordNum, Line};
6
7pub trait LineTrait: Sized + GeometryTrait {
13 type CoordType<'a>: 'a + CoordTrait<T = Self::T>
15 where
16 Self: 'a;
17
18 fn start(&self) -> Self::CoordType<'_>;
20
21 fn end(&self) -> Self::CoordType<'_>;
23
24 fn coords(&self) -> [Self::CoordType<'_>; 2] {
26 [self.start(), self.end()]
27 }
28}
29
30#[cfg(feature = "geo-types")]
31impl<T: CoordNum> LineTrait for Line<T> {
32 type CoordType<'a>
33 = &'a Coord<Self::T>
34 where
35 Self: 'a;
36
37 fn start(&self) -> Self::CoordType<'_> {
38 &self.start
39 }
40
41 fn end(&self) -> Self::CoordType<'_> {
42 &self.end
43 }
44}
45
46#[cfg(feature = "geo-types")]
47impl<'a, T: CoordNum> LineTrait for &'a Line<T> {
48 type CoordType<'b>
49 = &'a Coord<Self::T>
50 where
51 Self: 'b;
52
53 fn start(&self) -> Self::CoordType<'_> {
54 &self.start
55 }
56
57 fn end(&self) -> Self::CoordType<'_> {
58 &self.end
59 }
60}
61
62pub struct UnimplementedLine<T>(PhantomData<T>);
67
68impl<T> LineTrait for UnimplementedLine<T> {
69 type CoordType<'a>
70 = UnimplementedCoord<Self::T>
71 where
72 Self: 'a;
73
74 fn start(&self) -> Self::CoordType<'_> {
75 unimplemented!()
76 }
77
78 fn end(&self) -> Self::CoordType<'_> {
79 unimplemented!()
80 }
81}