Skip to content

Commit 82f4d75

Browse files
committed
Add comments for public APIs
1 parent 4052c46 commit 82f4d75

File tree

14 files changed

+198
-7
lines changed

14 files changed

+198
-7
lines changed

rust/sedona-geo-traits-ext/src/coord.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ use geo_types::{Coord, CoordNum};
2121

2222
use crate::{CoordTag, GeoTraitExtWithTypeTag};
2323

24+
/// Extension methods that bridge [`CoordTrait`] with concrete `geo-types` helpers.
2425
pub trait CoordTraitExt: CoordTrait + GeoTraitExtWithTypeTag<Tag = CoordTag>
2526
where
2627
<Self as CoordTrait>::T: CoordNum,
2728
{
2829
#[inline]
30+
/// Converts this coordinate into the concrete [`geo_types::Coord`].
2931
fn geo_coord(&self) -> Coord<Self::T> {
3032
Coord {
3133
x: self.x(),

rust/sedona-geo-traits-ext/src/geometry.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,42 +24,58 @@ use geo_types::*;
2424
use crate::*;
2525

2626
#[allow(clippy::type_complexity)]
27+
/// Extension trait that augments [`geo_traits::GeometryTrait`] with Sedona's
28+
/// additional helpers and type tagging support.
29+
///
30+
/// The trait adds accessors that mirror the behavior of `geo-types::Geometry`
31+
/// while keeping the code ergonomic when working through trait objects.
32+
/// Implementations must also opt into [`GeoTraitExtWithTypeTag`] so geometries
33+
/// can be introspected using [`GeometryTag`].
2734
pub trait GeometryTraitExt: GeometryTrait + GeoTraitExtWithTypeTag<Tag = GeometryTag>
2835
where
2936
<Self as GeometryTrait>::T: CoordNum,
3037
{
38+
/// Extension-aware point type exposed by this geometry.
3139
type PointTypeExt<'a>: 'a + PointTraitExt<T = <Self as GeometryTrait>::T>
3240
where
3341
Self: 'a;
3442

43+
/// Extension-aware line string type exposed by this geometry.
3544
type LineStringTypeExt<'a>: 'a + LineStringTraitExt<T = <Self as GeometryTrait>::T>
3645
where
3746
Self: 'a;
3847

48+
/// Extension-aware polygon type exposed by this geometry.
3949
type PolygonTypeExt<'a>: 'a + PolygonTraitExt<T = <Self as GeometryTrait>::T>
4050
where
4151
Self: 'a;
4252

53+
/// Extension-aware multi point type exposed by this geometry.
4354
type MultiPointTypeExt<'a>: 'a + MultiPointTraitExt<T = <Self as GeometryTrait>::T>
4455
where
4556
Self: 'a;
4657

58+
/// Extension-aware multi line string type exposed by this geometry.
4759
type MultiLineStringTypeExt<'a>: 'a + MultiLineStringTraitExt<T = <Self as GeometryTrait>::T>
4860
where
4961
Self: 'a;
5062

63+
/// Extension-aware multi polygon type exposed by this geometry.
5164
type MultiPolygonTypeExt<'a>: 'a + MultiPolygonTraitExt<T = <Self as GeometryTrait>::T>
5265
where
5366
Self: 'a;
5467

68+
/// Extension-aware triangle type exposed by this geometry.
5569
type TriangleTypeExt<'a>: 'a + TriangleTraitExt<T = <Self as GeometryTrait>::T>
5670
where
5771
Self: 'a;
5872

73+
/// Extension-aware rectangle type exposed by this geometry.
5974
type RectTypeExt<'a>: 'a + RectTraitExt<T = <Self as GeometryTrait>::T>
6075
where
6176
Self: 'a;
6277

78+
/// Extension-aware line type exposed by this geometry.
6379
type LineTypeExt<'a>: 'a + LineTraitExt<T = <Self as GeometryTrait>::T>
6480
where
6581
Self: 'a;
@@ -74,6 +90,7 @@ where
7490
// we are not certain if there will be other issues caused by recursive GATs in the future. So we decided to completely get rid
7591
// of recursive GATs.
7692

93+
/// Reference type yielded when iterating over nested geometries inside a collection.
7794
type InnerGeometryRef<'a>: 'a + Borrow<Self>
7895
where
7996
Self: 'a;
@@ -131,6 +148,7 @@ where
131148
}
132149

133150
#[derive(Debug)]
151+
/// Borrowed view into a concrete geometry type implementing the extension traits.
134152
pub enum GeometryTypeExt<'a, P, LS, Y, MP, ML, MY, R, TT, L>
135153
where
136154
P: PointTraitExt,
@@ -164,6 +182,9 @@ where
164182
}
165183

166184
#[macro_export]
185+
/// Forwards [`GeometryTraitExt`] associated types and methods to the
186+
/// underlying [`geo_traits::GeometryTrait`] implementation while retaining the
187+
/// extension trait wrappers.
167188
macro_rules! forward_geometry_trait_ext_funcs {
168189
($t:ty) => {
169190
type PointTypeExt<'__g_inner>

rust/sedona-geo-traits-ext/src/geometry_collection.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,23 @@ use geo_types::{CoordNum, GeometryCollection};
2121

2222
use crate::{GeoTraitExtWithTypeTag, GeometryCollectionTag, GeometryTraitExt};
2323

24+
/// Extension trait that enriches [`geo_traits::GeometryCollectionTrait`] with
25+
/// Sedona-specific conveniences.
26+
///
27+
/// The trait exposes accessor methods that return geometry values wrapped in
28+
/// [`GeometryTraitExt`], enabling downstream consumers to leverage the unified
29+
/// extension API regardless of the backing geometry type.
2430
pub trait GeometryCollectionTraitExt:
2531
GeometryCollectionTrait + GeoTraitExtWithTypeTag<Tag = GeometryCollectionTag>
2632
where
2733
<Self as GeometryTrait>::T: CoordNum,
2834
{
35+
/// Extension-aware geometry type yielded by accessor methods.
2936
type GeometryTypeExt<'a>: 'a + GeometryTraitExt<T = <Self as GeometryTrait>::T>
3037
where
3138
Self: 'a;
3239

40+
/// Returns the geometry at index `i`, wrapped with [`GeometryTraitExt`].
3341
fn geometry_ext(&self, i: usize) -> Option<Self::GeometryTypeExt<'_>>;
3442

3543
/// Returns a geometry by index without bounds checking.
@@ -39,10 +47,14 @@ where
3947
/// Otherwise, this function may cause undefined behavior.
4048
unsafe fn geometry_unchecked_ext(&self, i: usize) -> Self::GeometryTypeExt<'_>;
4149

50+
/// Iterates over all geometries in the collection with extension wrappers applied.
4251
fn geometries_ext(&self) -> impl Iterator<Item = Self::GeometryTypeExt<'_>>;
4352
}
4453

4554
#[macro_export]
55+
/// Forwards [`GeometryCollectionTraitExt`] methods to the underlying
56+
/// [`geo_traits::GeometryCollectionTrait`] implementation while preserving the
57+
/// extension trait wrappers.
4658
macro_rules! forward_geometry_collection_trait_ext_funcs {
4759
() => {
4860
type GeometryTypeExt<'__gc_inner>

rust/sedona-geo-traits-ext/src/line.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use geo_types::{CoordNum, Line};
2121

2222
use crate::{CoordTraitExt, GeoTraitExtWithTypeTag, LineTag};
2323

24+
/// Extra helpers for [`LineTrait`] implementors that mirror `geo-types` APIs.
2425
pub trait LineTraitExt: LineTrait + GeoTraitExtWithTypeTag<Tag = LineTag>
2526
where
2627
<Self as GeometryTrait>::T: CoordNum,
@@ -29,27 +30,34 @@ where
2930
where
3031
Self: 'a;
3132

33+
/// Returns the start coordinate as an extension trait instance.
3234
fn start_ext(&self) -> Self::CoordTypeExt<'_>;
35+
/// Returns the end coordinate as an extension trait instance.
3336
fn end_ext(&self) -> Self::CoordTypeExt<'_>;
37+
/// Returns both start and end coordinates in a fixed-size array.
3438
fn coords_ext(&self) -> [Self::CoordTypeExt<'_>; 2];
3539

3640
#[inline]
41+
/// Returns the start coordinate converted to [`geo_types::Coord`].
3742
fn start_coord(&self) -> geo_types::Coord<<Self as GeometryTrait>::T> {
3843
self.start_ext().geo_coord()
3944
}
4045

4146
#[inline]
47+
/// Returns the end coordinate converted to [`geo_types::Coord`].
4248
fn end_coord(&self) -> geo_types::Coord<<Self as GeometryTrait>::T> {
4349
self.end_ext().geo_coord()
4450
}
4551

4652
#[inline]
53+
/// Returns the line converted to a [`geo_types::Line`].
4754
fn geo_line(&self) -> Line<<Self as GeometryTrait>::T> {
4855
Line::new(self.start_coord(), self.end_coord())
4956
}
5057
}
5158

5259
#[macro_export]
60+
/// Forwards [`LineTraitExt`] methods to an underlying [`LineTrait`] implementation.
5361
macro_rules! forward_line_trait_ext_funcs {
5462
() => {
5563
type CoordTypeExt<'__l_inner>

rust/sedona-geo-traits-ext/src/line_string.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use geo_types::{Coord, CoordNum, Line, LineString, Triangle};
2121

2222
use crate::{CoordTraitExt, GeoTraitExtWithTypeTag, LineStringTag};
2323

24+
/// Additional convenience methods for [`LineStringTrait`] implementors that mirror `geo-types`.
2425
pub trait LineStringTraitExt:
2526
LineStringTrait + GeoTraitExtWithTypeTag<Tag = LineStringTag>
2627
where
@@ -30,6 +31,7 @@ where
3031
where
3132
Self: 'a;
3233

34+
/// Returns the coordinate at the provided index.
3335
fn coord_ext(&self, i: usize) -> Option<Self::CoordTypeExt<'_>>;
3436

3537
/// Returns a coordinate by index without bounds checking.
@@ -39,6 +41,7 @@ where
3941
/// Otherwise, this function may cause undefined behavior.
4042
unsafe fn coord_unchecked_ext(&self, i: usize) -> Self::CoordTypeExt<'_>;
4143

44+
/// Returns an iterator over all coordinates as extension trait instances.
4245
fn coords_ext(&self) -> impl Iterator<Item = Self::CoordTypeExt<'_>>;
4346

4447
/// Returns a coordinate by index without bounds checking.
@@ -92,13 +95,14 @@ where
9295
})
9396
}
9497

95-
// Returns an iterator yielding the coordinates of this line string as `geo_types::Coord`s.
98+
/// Returns an iterator yielding the coordinates of this line string as [`geo_types::Coord`] values.
9699
#[inline]
97100
fn coord_iter(&self) -> impl Iterator<Item = Coord<<Self as GeometryTrait>::T>> {
98101
self.coords_ext().map(|c| c.geo_coord())
99102
}
100103

101104
#[inline]
105+
/// Returns true when the line string is closed (its first and last coordinates are equal).
102106
fn is_closed(&self) -> bool {
103107
match (self.coords_ext().next(), self.coords_ext().last()) {
104108
(Some(first), Some(last)) => first.geo_coord() == last.geo_coord(),
@@ -109,6 +113,7 @@ where
109113
}
110114

111115
#[macro_export]
116+
/// Forwards [`LineStringTraitExt`] methods to an underlying [`LineStringTrait`] implementation.
112117
macro_rules! forward_line_string_trait_ext_funcs {
113118
() => {
114119
type CoordTypeExt<'__l_inner>

rust/sedona-geo-traits-ext/src/multi_line_string.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,26 @@ use geo_types::{CoordNum, MultiLineString};
2121

2222
use crate::{GeoTraitExtWithTypeTag, LineStringTraitExt, MultiLineStringTag};
2323

24+
/// Extension trait that layers additional ergonomics on
25+
/// [`geo_traits::MultiLineStringTrait`].
26+
///
27+
/// Implementors gain access to extension-aware iterators and helper methods
28+
/// that mirror the behavior of `geo-types::MultiLineString`, while still being
29+
/// consumable through the trait abstractions provided by `geo-traits`.
2430
pub trait MultiLineStringTraitExt:
2531
MultiLineStringTrait + GeoTraitExtWithTypeTag<Tag = MultiLineStringTag>
2632
where
2733
<Self as GeometryTrait>::T: CoordNum,
2834
{
35+
/// Extension-friendly line string type returned by accessor methods.
2936
type LineStringTypeExt<'a>: 'a + LineStringTraitExt<T = <Self as GeometryTrait>::T>
3037
where
3138
Self: 'a;
3239

40+
/// Returns the line string at index `i` with the extension trait applied.
41+
///
42+
/// This is analogous to [`geo_traits::MultiLineStringTrait::line_string`]
43+
/// but ensures the result implements [`LineStringTraitExt`].
3344
fn line_string_ext(&self, i: usize) -> Option<Self::LineStringTypeExt<'_>>;
3445

3546
/// Returns a line string by index without bounds checking.
@@ -39,9 +50,10 @@ where
3950
/// Otherwise, this function may cause undefined behavior.
4051
unsafe fn line_string_unchecked_ext(&self, i: usize) -> Self::LineStringTypeExt<'_>;
4152

53+
/// Iterates over all line strings with extension-aware wrappers applied.
4254
fn line_strings_ext(&self) -> impl Iterator<Item = Self::LineStringTypeExt<'_>>;
4355

44-
/// True if the MultiLineString is empty or if all of its LineStrings are closed
56+
/// Returns `true` when the multi line string is empty or every component is closed.
4557
#[inline]
4658
fn is_closed(&self) -> bool {
4759
// Note: Unlike JTS et al, we consider an empty MultiLineString as closed.
@@ -50,6 +62,9 @@ where
5062
}
5163

5264
#[macro_export]
65+
/// Forwards [`MultiLineStringTraitExt`] methods to the underlying
66+
/// [`geo_traits::MultiLineStringTrait`] implementation while keeping the
67+
/// extension trait wrappers intact.
5368
macro_rules! forward_multi_line_string_trait_ext_funcs {
5469
() => {
5570
type LineStringTypeExt<'__l_inner>

rust/sedona-geo-traits-ext/src/multi_point.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,28 @@ use geo_types::{Coord, CoordNum, MultiPoint};
2121

2222
use 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.
2432
pub trait MultiPointTraitExt:
2533
MultiPointTrait + GeoTraitExtWithTypeTag<Tag = MultiPointTag>
2634
where
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.
6293
macro_rules! forward_multi_point_trait_ext_funcs {
6394
() => {
6495
type PointTypeExt<'__l_inner>
@@ -89,6 +120,7 @@ where
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

Comments
 (0)