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
50
51
52
53
54
55
56
57
58
use super::Contains;
use crate::kernels::*;
use crate::*;

// ┌──────────────────────────────┐
// │ Implementations for Geometry │
// └──────────────────────────────┘

impl<T> Contains<Coordinate<T>> for Geometry<T>
where
    T: HasKernel,
{
    fn contains(&self, coord: &Coordinate<T>) -> bool {
        match self {
            Geometry::Point(g) => g.contains(coord),
            Geometry::Line(g) => g.contains(coord),
            Geometry::LineString(g) => g.contains(coord),
            Geometry::Polygon(g) => g.contains(coord),
            Geometry::MultiPoint(g) => g.contains(coord),
            Geometry::MultiLineString(g) => g.contains(coord),
            Geometry::MultiPolygon(g) => g.contains(coord),
            Geometry::GeometryCollection(g) => g.contains(coord),
            Geometry::Rect(g) => g.contains(coord),
            Geometry::Triangle(g) => g.contains(coord),
        }
    }
}

impl<T> Contains<Point<T>> for Geometry<T>
where
    T: HasKernel,
{
    fn contains(&self, point: &Point<T>) -> bool {
        self.contains(&point.0)
    }
}

// ┌────────────────────────────────────────┐
// │ Implementations for GeometryCollection │
// └────────────────────────────────────────┘

impl<T> Contains<Coordinate<T>> for GeometryCollection<T>
where
    T: HasKernel,
{
    fn contains(&self, coord: &Coordinate<T>) -> bool {
        self.iter().any(|geometry| geometry.contains(coord))
    }
}

impl<T> Contains<Point<T>> for GeometryCollection<T>
where
    T: HasKernel,
{
    fn contains(&self, point: &Point<T>) -> bool {
        self.contains(&point.0)
    }
}