Skip to content

Commit

Permalink
add Relate impls for GeometryCollection, remove most for Geometry
Browse files Browse the repository at this point in the history
We *do* want to be able to relate any Geometry _variant_ with any other
_variant_. So I've added the missing impls for GeometryCollection.

However, in line with our other traits, we typically only want to relate
any Geometry with another _Geometry_, not to each inner variant
directly, so I've replaced the combinatoric `impl` for Geometry with a
single `impl Relate<Geometry> for Geometry`
  • Loading branch information
michaelkirk committed Mar 22, 2021
1 parent ef984dd commit 1cce0a3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions geo/src/algorithm/relate/mod.rs
Expand Up @@ -2,8 +2,8 @@ pub(crate) use edge_end_builder::EdgeEndBuilder;
pub use geomgraph::intersection_matrix::IntersectionMatrix;

use crate::{
GeoFloat, Geometry, GeometryCow, Line, LineString, MultiLineString, MultiPoint, MultiPolygon,
Point, Polygon, Rect, Triangle,
GeoFloat, Geometry, GeometryCollection, GeometryCow, Line, LineString, MultiLineString,
MultiPoint, MultiPolygon, Point, Polygon, Rect, Triangle,
};

mod edge_end_builder;
Expand Down Expand Up @@ -65,6 +65,9 @@ impl<F: GeoFloat> Relate<F, GeometryCow<'_, F>> for GeometryCow<'_, F> {
}

macro_rules! relate_impl {
($k:ty, $t:ty) => {
relate_impl![($k, $t),];
};
($(($k:ty, $t:ty),)*) => {
$(
impl<F: GeoFloat> Relate<F, $t> for $k {
Expand Down Expand Up @@ -111,4 +114,5 @@ macro_rules! cartesian_pairs_helper {
// Implement Relate for every combination of Geometry. Alternatively we could do something like
// `impl Relate<Into<GeometryCow>> for Into<GeometryCow> { }`
// but I don't know that we want to make GeometryCow public (yet?).
cartesian_pairs!(relate_impl, [Geometry<F>, Point<F>, Line<F>, LineString<F>, Polygon<F>, MultiPoint<F>, MultiLineString<F>, MultiPolygon<F>, Rect<F>, Triangle<F>]);
cartesian_pairs!(relate_impl, [Point<F>, Line<F>, LineString<F>, Polygon<F>, MultiPoint<F>, MultiLineString<F>, MultiPolygon<F>, Rect<F>, Triangle<F>, GeometryCollection<F>]);
relate_impl!(Geometry<F>, Geometry<F>);

0 comments on commit 1cce0a3

Please sign in to comment.