Skip to content

Commit

Permalink
Add UnimplementedGeometryCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Dec 23, 2024
1 parent 785c1d8 commit 76cece6
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 3 deletions.
78 changes: 78 additions & 0 deletions geo-traits/src/geometry.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::marker::PhantomData;

#[cfg(feature = "geo-types")]
use geo_types::{
CoordNum, Geometry, GeometryCollection, Line, LineString, MultiLineString, MultiPoint,
Expand All @@ -7,6 +9,9 @@ use geo_types::{
use crate::{
Dimensions, GeometryCollectionTrait, LineStringTrait, LineTrait, MultiLineStringTrait,
MultiPointTrait, MultiPolygonTrait, PointTrait, PolygonTrait, RectTrait, TriangleTrait,
UnimplementedGeometryCollection, UnimplementedLine, UnimplementedLineString,
UnimplementedMultiLineString, UnimplementedMultiPoint, UnimplementedMultiPolygon,
UnimplementedPoint, UnimplementedPolygon, UnimplementedRect, UnimplementedTriangle,
};

/// A trait for accessing data from a generic Geometry.
Expand Down Expand Up @@ -431,3 +436,76 @@ impl_specialization!(GeometryCollection);
impl_specialization!(Rect);
impl_specialization!(Triangle);
impl_specialization!(Line);

/// An empty struct that implements [GeometryTrait].
///
/// This is used internally for [`UnimplementedGeometryCollection`], so that
/// `UnimplementedGeometryCollection` can be used as the `GeometryCollectionType` of the
/// `GeometryTrait` by implementations that don't have a GeometryCollection concept
pub struct UnimplementedGeometry<T>(PhantomData<T>);

impl<T> GeometryTrait for UnimplementedGeometry<T> {
type T = T;
type PointType<'b>
= UnimplementedPoint<T>
where
Self: 'b;
type LineStringType<'b>
= UnimplementedLineString<Self::T>
where
Self: 'b;
type PolygonType<'b>
= UnimplementedPolygon<Self::T>
where
Self: 'b;
type MultiPointType<'b>
= UnimplementedMultiPoint<Self::T>
where
Self: 'b;
type MultiLineStringType<'b>
= UnimplementedMultiLineString<Self::T>
where
Self: 'b;
type MultiPolygonType<'b>
= UnimplementedMultiPolygon<Self::T>
where
Self: 'b;
type GeometryCollectionType<'b>
= UnimplementedGeometryCollection<Self::T>
where
Self: 'b;
type RectType<'b>
= UnimplementedRect<Self::T>
where
Self: 'b;
type TriangleType<'b>
= UnimplementedTriangle<Self::T>
where
Self: 'b;
type LineType<'b>
= UnimplementedLine<Self::T>
where
Self: 'b;

fn dim(&self) -> Dimensions {
unimplemented!()
}

fn as_type(
&self,
) -> GeometryType<
'_,
Self::PointType<'_>,
Self::LineStringType<'_>,
Self::PolygonType<'_>,
Self::MultiPointType<'_>,
Self::MultiLineStringType<'_>,
Self::MultiPolygonType<'_>,
Self::GeometryCollectionType<'_>,
Self::RectType<'_>,
Self::TriangleType<'_>,
Self::LineType<'_>,
> {
unimplemented!()
}
}
30 changes: 29 additions & 1 deletion geo-traits/src/geometry_collection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::marker::PhantomData;

use crate::iterator::GeometryCollectionIterator;
use crate::{Dimensions, GeometryTrait};
use crate::{Dimensions, GeometryTrait, UnimplementedGeometry};
#[cfg(feature = "geo-types")]
use geo_types::{CoordNum, Geometry, GeometryCollection};

Expand Down Expand Up @@ -87,3 +89,29 @@ impl<'a, T: CoordNum> GeometryCollectionTrait for &'a GeometryCollection<T> {
self.0.get_unchecked(i)
}
}

/// An empty struct that implements [GeometryCollectionTrait].
///
/// This can be used as the `GeometryCollectionType` of the `GeometryTrait` by implementations that
/// don't have a GeometryCollection concept
pub struct UnimplementedGeometryCollection<T>(PhantomData<T>);

impl<T> GeometryCollectionTrait for UnimplementedGeometryCollection<T> {
type T = T;
type GeometryType<'a>
= UnimplementedGeometry<Self::T>
where
Self: 'a;

fn dim(&self) -> Dimensions {
unimplemented!()
}

fn num_geometries(&self) -> usize {
unimplemented!()
}

unsafe fn geometry_unchecked(&self, _i: usize) -> Self::GeometryType<'_> {
unimplemented!()
}
}
4 changes: 2 additions & 2 deletions geo-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

pub use coord::{CoordTrait, UnimplementedCoord};
pub use dimension::Dimensions;
pub use geometry::{GeometryTrait, GeometryType};
pub use geometry_collection::GeometryCollectionTrait;
pub use geometry::{GeometryTrait, GeometryType, UnimplementedGeometry};
pub use geometry_collection::{GeometryCollectionTrait, UnimplementedGeometryCollection};
pub use line::{LineTrait, UnimplementedLine};
pub use line_string::{LineStringTrait, UnimplementedLineString};
pub use multi_line_string::{MultiLineStringTrait, UnimplementedMultiLineString};
Expand Down

0 comments on commit 76cece6

Please sign in to comment.