1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
use super::Intersects;
use crate::*;

impl<T, G> Intersects<G> for Geometry<T>
where
    T: CoordNum,
    Point<T>: Intersects<G>,
    MultiPoint<T>: Intersects<G>,
    Line<T>: Intersects<G>,
    LineString<T>: Intersects<G>,
    MultiLineString<T>: Intersects<G>,
    Triangle<T>: Intersects<G>,
    Rect<T>: Intersects<G>,
    Polygon<T>: Intersects<G>,
    MultiPolygon<T>: Intersects<G>,
{
    fn intersects(&self, rhs: &G) -> bool {
        match self {
            Geometry::Point(geom) => geom.intersects(rhs),
            Geometry::MultiPoint(geom) => geom.intersects(rhs),
            Geometry::Line(geom) => geom.intersects(rhs),
            Geometry::LineString(geom) => geom.intersects(rhs),
            Geometry::MultiLineString(geom) => geom.intersects(rhs),
            Geometry::Triangle(geom) => geom.intersects(rhs),
            Geometry::Rect(geom) => geom.intersects(rhs),
            Geometry::Polygon(geom) => geom.intersects(rhs),
            Geometry::MultiPolygon(geom) => geom.intersects(rhs),
            Geometry::GeometryCollection(geom) => geom.intersects(rhs),
        }
    }
}
symmetric_intersects_impl!(Coordinate<T>, Geometry<T>);
symmetric_intersects_impl!(Line<T>, Geometry<T>);
symmetric_intersects_impl!(Rect<T>, Geometry<T>);
symmetric_intersects_impl!(Polygon<T>, Geometry<T>);

impl<T, G> Intersects<G> for GeometryCollection<T>
where
    T: CoordNum,
    Geometry<T>: Intersects<G>,
{
    fn intersects(&self, rhs: &G) -> bool {
        self.iter().any(|geom| geom.intersects(rhs))
    }
}
symmetric_intersects_impl!(Coordinate<T>, GeometryCollection<T>);
symmetric_intersects_impl!(Line<T>, GeometryCollection<T>);
symmetric_intersects_impl!(Rect<T>, GeometryCollection<T>);
symmetric_intersects_impl!(Polygon<T>, GeometryCollection<T>);