what3words_api/models/
gridsection.rs

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
71
72
73
74
75
76
77
78
79
use std::fmt;

use serde::Deserialize;

use crate::Coordinates;

use super::feature::Feature;

pub trait FormattedGridSection {
    fn format() -> &'static str;
}

#[derive(Debug, Deserialize)]
pub struct Line {
    pub start: Coordinates,
    pub end: Coordinates,
}

#[derive(Debug, Deserialize)]
pub struct GridSection {
    pub lines: Vec<Line>,
}

impl FormattedGridSection for GridSection {
    fn format() -> &'static str {
        "json"
    }
}

#[derive(Debug, Deserialize)]
pub struct GridSectionGeoJson {
    pub features: Vec<Feature<Geometry>>,
    #[serde(rename = "type")]
    pub kind: String,
}

impl FormattedGridSection for GridSectionGeoJson {
    fn format() -> &'static str {
        "geojson"
    }
}

#[derive(Debug, Deserialize)]
pub struct Geometry {
    pub coordinates: Vec<Vec<Vec<f32>>>,
    #[serde(rename = "type")]
    pub kind: String,
}

#[derive(Debug, Clone)]
pub struct BoundingBox {
    southwest: Coordinates,
    northeast: Coordinates,
}

impl fmt::Display for BoundingBox {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(
            f,
            "{},{},{},{}",
            self.southwest.lat, self.southwest.lng, self.northeast.lat, self.northeast.lng
        )
    }
}

impl BoundingBox {
    pub fn new(sw_lat: f64, sw_lng: f64, ne_lat: f64, ne_lng: f64) -> Self {
        Self {
            southwest: Coordinates {
                lat: sw_lat,
                lng: sw_lng,
            },
            northeast: Coordinates {
                lat: ne_lat,
                lng: ne_lng,
            },
        }
    }
}