1#![doc = include_str!("../README.md")]
2pub mod colormap;
11pub mod geometry;
12pub mod grid;
13pub mod preprocess;
14pub mod rotate;
15pub mod srtm;
16pub mod svg;
17
18pub use geometry::{RidgeRow, RidgeScene};
19pub use srtm::{Tile, TileSource};
20
21use serde::{Deserialize, Serialize};
22
23pub const DEFAULT_BBOX: Bbox = Bbox {
25 lon0: -71.928864,
26 lat0: 43.758201,
27 lon1: -70.957947,
28 lat1: 44.465151,
29};
30
31#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
34pub struct Bbox {
35 pub lon0: f64,
36 pub lat0: f64,
37 pub lon1: f64,
38 pub lat1: f64,
39}
40
41impl Bbox {
42 pub fn new(lon0: f64, lat0: f64, lon1: f64, lat1: f64) -> Self {
43 Self {
44 lon0,
45 lat0,
46 lon1,
47 lat1,
48 }
49 }
50
51 pub fn lats(&self) -> (f64, f64) {
53 (self.lat0, self.lat1)
54 }
55
56 pub fn longs(&self) -> (f64, f64) {
58 (self.lon0, self.lon1)
59 }
60
61 pub fn ratio(&self) -> f64 {
63 (self.lat1 - self.lat0) / (self.lon1 - self.lon0)
64 }
65
66 pub fn is_valid(&self) -> bool {
67 self.lon1 > self.lon0
68 && self.lat1 > self.lat0
69 && self.lon0 >= -180.0
70 && self.lon1 <= 180.0
71 && self.lat0 >= -60.0
72 && self.lat1 <= 60.0
73 }
74}
75
76impl Default for Bbox {
77 fn default() -> Self {
78 DEFAULT_BBOX
79 }
80}
81
82#[derive(Debug, thiserror::Error)]
83pub enum Error {
84 #[error("invalid bounding box: {0:?}")]
85 InvalidBbox(Bbox),
86 #[error("elevation data contains no valid points for this bbox")]
87 EmptyData,
88 #[error("srtm tile error: {0}")]
89 Srtm(String),
90 #[error("io error: {0}")]
91 Io(#[from] std::io::Error),
92}
93
94pub type Result<T> = std::result::Result<T, Error>;