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
59
60
61
62
63
64
65
66
67
68
69
70
use serde_json::json;

/// A xmin,ymin,xmax,ymax coordinates tuple.
#[derive(Debug, Clone, PartialEq)]
pub struct BoundingBox {
    /// min horizontal coordinate.
    pub left: f64,
    /// min vertical coordinate.
    pub bottom: f64,
    /// max horizontal coordinate.
    pub right: f64,
    /// max vertical coordinate.
    pub top: f64,
}

impl BoundingBox {
    /// Create a new BoundingBox.
    pub fn new(left: f64, bottom: f64, right: f64, top: f64) -> Self {
        Self {
            left,
            bottom,
            right,
            top,
        }
    }
}

/// A x,y Coordinates pair.
#[derive(Debug, Clone, PartialEq)]
pub struct Coords {
    /// horizontal coordinate input projection unit.
    pub x: f64,
    /// vertical coordinate input projection unit.
    pub y: f64,
}

impl Coords {
    /// Create a new Coords.
    pub fn new(x: f64, y: f64) -> Self {
        Self { x, y }
    }
}

/// TileMatrixSet X,Y,Z tile indices.
#[derive(Debug, Clone, PartialEq)]
pub struct Xyz {
    /// horizontal index.
    pub x: u64,
    /// verctical index.
    pub y: u64,
    /// zoom level.
    pub z: u8,
}

impl Xyz {
    /// Create a new Tile.
    pub fn new(x: u64, y: u64, z: u8) -> Self {
        Self { x, y, z }
    }
}

/// Create a GeoJSON feature from a bbox.
pub fn bbox_to_feature(west: f64, south: f64, east: f64, north: f64) -> serde_json::Value {
    json!({
        "type": "Polygon",
        "coordinates": [
            [[west, south], [west, north], [east, north], [east, south], [west, south]]
        ],
    })
}