geo_traits/
multi_point.rs1use std::marker::PhantomData;
2
3use crate::iterator::MultiPointIterator;
4use crate::{GeometryTrait, PointTrait, UnimplementedPoint};
5#[cfg(feature = "geo-types")]
6use geo_types::{CoordNum, MultiPoint, Point};
7
8pub trait MultiPointTrait: Sized + GeometryTrait {
14 type InnerPointType<'a>: 'a + PointTrait<T = Self::T>
16 where
17 Self: 'a;
18
19 fn points(
21 &self,
22 ) -> impl DoubleEndedIterator + ExactSizeIterator<Item = Self::InnerPointType<'_>> {
23 MultiPointIterator::new(self, 0, self.num_points())
24 }
25
26 fn num_points(&self) -> usize;
28
29 fn point(&self, i: usize) -> Option<Self::InnerPointType<'_>> {
32 if i >= self.num_points() {
33 None
34 } else {
35 unsafe { Some(self.point_unchecked(i)) }
36 }
37 }
38
39 unsafe fn point_unchecked(&self, i: usize) -> Self::InnerPointType<'_>;
45}
46
47#[cfg(feature = "geo-types")]
48impl<T: CoordNum> MultiPointTrait for MultiPoint<T> {
49 type InnerPointType<'a>
50 = &'a Point<Self::T>
51 where
52 Self: 'a;
53
54 fn num_points(&self) -> usize {
55 self.0.len()
56 }
57
58 unsafe fn point_unchecked(&self, i: usize) -> Self::InnerPointType<'_> {
59 self.0.get_unchecked(i)
60 }
61}
62
63#[cfg(feature = "geo-types")]
64impl<'a, T: CoordNum> MultiPointTrait for &'a MultiPoint<T> {
65 type InnerPointType<'b>
66 = &'a Point<Self::T>
67 where
68 Self: 'b;
69
70 fn num_points(&self) -> usize {
71 self.0.len()
72 }
73
74 unsafe fn point_unchecked(&self, i: usize) -> Self::InnerPointType<'_> {
75 self.0.get_unchecked(i)
76 }
77}
78
79pub struct UnimplementedMultiPoint<T>(PhantomData<T>);
84
85impl<T> MultiPointTrait for UnimplementedMultiPoint<T> {
86 type InnerPointType<'a>
87 = UnimplementedPoint<Self::T>
88 where
89 Self: 'a;
90
91 fn num_points(&self) -> usize {
92 unimplemented!()
93 }
94
95 unsafe fn point_unchecked(&self, _i: usize) -> Self::InnerPointType<'_> {
96 unimplemented!()
97 }
98}