Skip to content

Commit

Permalink
Document the geo-traits mod (#732)
Browse files Browse the repository at this point in the history
For #689
  • Loading branch information
kylebarron authored Aug 28, 2024
1 parent babe001 commit 3b19393
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/geo_traits/coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use geo::{Coord, CoordNum, Point};

/// A trait for accessing data from a generic Coord.
pub trait CoordTrait {
/// The coordinate type of this geometry
type T: CoordNum;

/// Access the n'th (0-based) element of the CoordinateTuple.
Expand Down
60 changes: 0 additions & 60 deletions src/geo_traits/dimension.rs

This file was deleted.

28 changes: 28 additions & 0 deletions src/geo_traits/geometry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,54 @@ use super::{
/// A trait for accessing data from a generic Geometry.
#[allow(clippy::type_complexity)]
pub trait GeometryTrait {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying Point, which implements [PointTrait]
type Point<'a>: 'a + PointTrait<T = Self::T>
where
Self: 'a;

/// The type of each underlying LineString, which implements [LineStringTrait]
type LineString<'a>: 'a + LineStringTrait<T = Self::T>
where
Self: 'a;

/// The type of each underlying Polygon, which implements [PolygonTrait]
type Polygon<'a>: 'a + PolygonTrait<T = Self::T>
where
Self: 'a;

/// The type of each underlying MultiPoint, which implements [MultiPointTrait]
type MultiPoint<'a>: 'a + MultiPointTrait<T = Self::T>
where
Self: 'a;

/// The type of each underlying MultiLineString, which implements [MultiLineStringTrait]
type MultiLineString<'a>: 'a + MultiLineStringTrait<T = Self::T>
where
Self: 'a;

/// The type of each underlying MultiPolygon, which implements [MultiPolygonTrait]
type MultiPolygon<'a>: 'a + MultiPolygonTrait<T = Self::T>
where
Self: 'a;

/// The type of each underlying GeometryCollection, which implements [GeometryCollectionTrait]
type GeometryCollection<'a>: 'a + GeometryCollectionTrait<T = Self::T>
where
Self: 'a;

/// The type of each underlying Rect, which implements [RectTrait]
type Rect<'a>: 'a + RectTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// Cast this geometry to a [`GeometryType`] enum, which allows for downcasting to a specific
/// type
fn as_type(
&self,
) -> GeometryType<
Expand Down Expand Up @@ -68,13 +88,21 @@ where
GC: GeometryCollectionTrait,
R: RectTrait,
{
/// A Point, which implements [PointTrait]
Point(&'a P),
/// A LineString, which implements [LineStringTrait]
LineString(&'a L),
/// A Polygon, which implements [PolygonTrait]
Polygon(&'a Y),
/// A MultiPoint, which implements [MultiPointTrait]
MultiPoint(&'a MP),
/// A MultiLineString, which implements [MultiLineStringTrait]
MultiLineString(&'a ML),
/// A MultiPolygon, which implements [MultiPolygonTrait]
MultiPolygon(&'a MY),
/// A GeometryCollection, which implements [GeometryCollectionTrait]
GeometryCollection(&'a GC),
/// A Rect, which implements [RectTrait]
Rect(&'a R),
}

Expand Down
4 changes: 4 additions & 0 deletions src/geo_traits/geometry_collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use geo::{CoordNum, Geometry, GeometryCollection};

/// A trait for accessing data from a generic GeometryCollection.
pub trait GeometryCollectionTrait: Sized {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying geometry, which implements [GeometryTrait]
type ItemType<'a>: 'a + GeometryTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// An iterator over the geometries in this GeometryCollection
Expand Down
1 change: 1 addition & 0 deletions src/geo_traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ macro_rules! impl_iterator {
G: $self_trait<T = T, ItemType<'a> = ItemType>,
> $struct_name<'a, T, ItemType, G>
{
/// Create a new iterator
pub fn new(geom: &'a G, index: usize, end: usize) -> Self {
Self { geom, index, end }
}
Expand Down
4 changes: 4 additions & 0 deletions src/geo_traits/line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use geo::{Coord, CoordNum, LineString};

/// A trait for accessing data from a generic LineString.
pub trait LineStringTrait: Sized {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying coordinate, which implements [CoordTrait]
type ItemType<'a>: 'a + CoordTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// An iterator over the coords in this LineString
Expand Down
2 changes: 0 additions & 2 deletions src/geo_traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
//! [here](https://github.com/georust/geo/pull/1019)) but that is vendored into this repository for
//! use internally, such as in the WKB parser.
#![allow(missing_docs)] // FIXME

pub use coord::CoordTrait;
pub use geometry::{GeometryTrait, GeometryType};
pub use geometry_collection::GeometryCollectionTrait;
Expand Down
4 changes: 4 additions & 0 deletions src/geo_traits/multi_line_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use geo::{CoordNum, LineString, MultiLineString};

/// A trait for accessing data from a generic MultiLineString.
pub trait MultiLineStringTrait: Sized {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying LineString, which implements [LineStringTrait]
type ItemType<'a>: 'a + LineStringTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// An iterator over the LineStrings in this MultiLineString
Expand Down
4 changes: 4 additions & 0 deletions src/geo_traits/multi_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use geo::{CoordNum, MultiPoint, Point};

/// A trait for accessing data from a generic MultiPoint.
pub trait MultiPointTrait: Sized {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying Point, which implements [PointTrait]
type ItemType<'a>: 'a + PointTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// An iterator over the points in this MultiPoint
Expand Down
4 changes: 4 additions & 0 deletions src/geo_traits/multi_polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use geo::{CoordNum, MultiPolygon, Polygon};

/// A trait for accessing data from a generic MultiPolygon.
pub trait MultiPolygonTrait: Sized {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying Polygon, which implements [PolygonTrait]
type ItemType<'a>: 'a + PolygonTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// An iterator over the Polygons in this MultiPolygon
Expand Down
1 change: 1 addition & 0 deletions src/geo_traits/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use geo::{Coord, CoordNum, Point};

/// A trait for accessing data from a generic Point.
pub trait PointTrait {
/// The coordinate type of this geometry
type T: CoordNum;

/// Access the n'th (0-based) element of the CoordinateTuple.
Expand Down
4 changes: 4 additions & 0 deletions src/geo_traits/polygon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ use geo::{CoordNum, LineString, Polygon};

/// A trait for accessing data from a generic Polygon.
pub trait PolygonTrait: Sized {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying ring, which implements [LineStringTrait]
type ItemType<'a>: 'a + LineStringTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// The exterior ring of the polygon
Expand Down
6 changes: 6 additions & 0 deletions src/geo_traits/rect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ use crate::geo_traits::CoordTrait;

/// A trait for accessing data from a generic Rect.
pub trait RectTrait {
/// The coordinate type of this geometry
type T: CoordNum;

/// The type of each underlying coordinate, which implements [CoordTrait]
type ItemType<'a>: 'a + CoordTrait<T = Self::T>
where
Self: 'a;

/// The number of dimensions in this geometry
fn dim(&self) -> usize;

/// The lower coordinate of this Rect
fn lower(&self) -> Self::ItemType<'_>;

/// The upper coordinate of this Rect
fn upper(&self) -> Self::ItemType<'_>;
}

Expand Down

0 comments on commit 3b19393

Please sign in to comment.