Skip to main content

overpass_lib/query/
bbox.rs

1use std::fmt::Write;
2use crate::{OverpassQL, OverpassQLError};
3
4/// A geographic bounding box defined by two latitudes and two longitudes. Used to distinguish
5/// points inside and outside the box.
6#[derive(Debug, Clone, Copy)]
7pub struct Bbox {
8    /// The latitude of the southern edge of the bounding box.
9    pub south: f64,
10    /// The longitude of the western edge of the bounding box.
11    pub west: f64,
12    /// The latitude of the northern edge of the bounding box.
13    pub north: f64,
14    /// The longitude of the eastern edge of the bounding box.
15    pub east: f64,
16}
17
18impl Bbox {
19    pub fn new(south: f64, west: f64, north: f64, east: f64) -> Self {
20        Self { south, west, north, east }
21    }
22}
23
24impl OverpassQL for Bbox {
25    fn fmt_oql(&self, f: &mut impl Write) -> Result<(), OverpassQLError> {
26        let Self { south, west, north, east } = self;
27        write!(f, "{south},{west},{north},{east}")?;
28        Ok(())
29    }
30}
31
32#[cfg(test)]
33mod test {
34    use super::*;
35
36    #[test]
37    fn fmt() {
38        let b = Bbox::new(1f64, 2f64, 3f64, 4f64);
39        assert_eq!(b.to_oql().as_str(), "1,2,3,4");
40    }
41
42    // #[test]
43    // fn query() {
44    //     let s = Set::all_types().within_bounds(Bbox::new(1.5, 2.5, 3.5, 4.5));
45    //     assert_eq!(s.to_oql().as_str(), r#"nwr(1.5,2.5,3.5,4.5)"#);
46    // }
47}