@@ -21,15 +21,28 @@ use geo_types::{Coord, CoordNum, MultiPoint};
2121
2222use crate :: { CoordTraitExt , GeoTraitExtWithTypeTag , MultiPointTag , PointTraitExt } ;
2323
24+ /// Extension trait that augments [`geo_traits::MultiPointTrait`] with richer
25+ /// ergonomics and accessors.
26+ ///
27+ /// The trait keeps parity with the APIs provided by `geo-types::MultiPoint`
28+ /// while still working with trait objects that only implement
29+ /// [`geo_traits::MultiPointTrait`]. It also wires the geometry up with a
30+ /// [`MultiPointTag`](crate::MultiPointTag) so the type can participate in the
31+ /// shared `GeoTraitExtWithTypeTag` machinery.
2432pub trait MultiPointTraitExt :
2533 MultiPointTrait + GeoTraitExtWithTypeTag < Tag = MultiPointTag >
2634where
2735 <Self as GeometryTrait >:: T : CoordNum ,
2836{
37+ /// Extension-aware point type returned from accessors on this multi point.
2938 type PointTypeExt < ' a > : ' a + PointTraitExt < T = <Self as GeometryTrait >:: T >
3039 where
3140 Self : ' a ;
3241
42+ /// Returns the point at index `i`, wrapped in the extension trait.
43+ ///
44+ /// This mirrors [`geo_traits::MultiPointTrait::point`] but guarantees the
45+ /// returned point implements [`PointTraitExt`].
3346 fn point_ext ( & self , i : usize ) -> Option < Self :: PointTypeExt < ' _ > > ;
3447
3548 /// Returns a point by index without bounds checking.
@@ -44,21 +57,39 @@ where
4457 /// # Safety
4558 /// The caller must ensure that `i` is a valid index less than the number of points.
4659 /// Otherwise, this function may cause undefined behavior.
60+ /// Returns the coordinate at index `i` without bounds checking.
61+ ///
62+ /// This helper is primarily used by iterator adapters that need direct
63+ /// coordinate access while still honoring the [`PointTraitExt`] abstraction.
64+ ///
65+ /// # Safety
66+ /// The caller must ensure that `i` is a valid index less than the number of points.
67+ /// Otherwise, this function may cause undefined behavior.
4768 #[ inline]
4869 unsafe fn geo_coord_unchecked ( & self , i : usize ) -> Option < Coord < <Self as GeometryTrait >:: T > > {
4970 let point = unsafe { self . point_unchecked_ext ( i) } ;
5071 point. coord_ext ( ) . map ( |c| c. geo_coord ( ) )
5172 }
5273
74+ /// Returns an iterator over all points, each wrapped in [`PointTraitExt`].
5375 fn points_ext ( & self ) -> impl DoubleEndedIterator < Item = Self :: PointTypeExt < ' _ > > ;
5476
77+ /// Iterates over the coordinates contained in this multi point.
78+ ///
79+ /// For trait-based implementations this is derived from
80+ /// [`points_ext`](Self::points_ext), while concrete `geo-types::MultiPoint`
81+ /// instances provide a specialized iterator that avoids intermediate
82+ /// allocations.
5583 #[ inline]
5684 fn coord_iter ( & self ) -> impl DoubleEndedIterator < Item = Coord < <Self as GeometryTrait >:: T > > {
5785 self . points_ext ( ) . flat_map ( |p| p. geo_coord ( ) )
5886 }
5987}
6088
6189#[ macro_export]
90+ /// Forwards [`MultiPointTraitExt`] methods to the underlying
91+ /// [`geo_traits::MultiPointTrait`] implementation while maintaining the
92+ /// extension trait wrappers.
6293macro_rules! forward_multi_point_trait_ext_funcs {
6394 ( ) => {
6495 type PointTypeExt <' __l_inner>
89120{
90121 forward_multi_point_trait_ext_funcs ! ( ) ;
91122
123+ /// Specialized coordinate accessor for `geo_types::MultiPoint`.
92124 unsafe fn geo_coord_unchecked ( & self , i : usize ) -> Option < Coord < T > > {
93125 Some ( self . 0 . get_unchecked ( i) . 0 )
94126 }
@@ -109,6 +141,7 @@ where
109141{
110142 forward_multi_point_trait_ext_funcs ! ( ) ;
111143
144+ /// Specialized coordinate accessor for `&geo_types::MultiPoint`.
112145 unsafe fn geo_coord_unchecked ( & self , i : usize ) -> Option < Coord < T > > {
113146 Some ( self . 0 . get_unchecked ( i) . 0 )
114147 }
0 commit comments