1pub(crate) mod bounding_volumes;
8pub mod constants;
9pub mod intersection_tests;
10pub mod math;
11pub mod projection;
12
13#[cfg(test)]
14#[path = "world_test.rs"]
15mod world_test;
16
17use geometry::Point;
18use mln_style::geo::LatLng;
19use mln_style::size::Size;
20
21pub type ScreenCoordinate = Point<f64>;
22pub(crate) type ScreenLineString = Vec<Point<f64>>;
23
24#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
26pub enum NorthOrientation {
27 #[default]
28 Upwards,
29 Rightwards,
30 Downwards,
31 Leftwards,
32}
33
34#[derive(Clone, Copy, Debug, Default, PartialEq)]
38pub struct EdgeInsets {
39 pub top: f64,
41 pub left: f64,
43 pub bottom: f64,
45 pub right: f64,
47}
48
49impl EdgeInsets {
50 #[must_use]
51 pub const fn new(top: f64, left: f64, bottom: f64, right: f64) -> Self {
52 EdgeInsets { top, left, bottom, right }
53 }
54
55 #[must_use]
56 pub fn top(&self) -> f64 {
57 self.top
58 }
59 #[must_use]
60 pub fn left(&self) -> f64 {
61 self.left
62 }
63 #[must_use]
64 pub fn bottom(&self) -> f64 {
65 self.bottom
66 }
67 #[must_use]
68 pub fn right(&self) -> f64 {
69 self.right
70 }
71
72 #[must_use]
75 pub(crate) fn center_in(&self, size: Size) -> ScreenCoordinate {
76 Point::new(
77 (f64::from(size.width) - self.left() - self.right()) / 2.0 + self.left(),
78 (f64::from(size.height) - self.top() - self.bottom()) / 2.0 + self.top(),
79 )
80 }
81}
82
83impl std::ops::AddAssign for EdgeInsets {
84 fn add_assign(&mut self, o: EdgeInsets) {
85 self.top += o.top;
86 self.left += o.left;
87 self.bottom += o.bottom;
88 self.right += o.right;
89 }
90}
91
92impl std::ops::Add for EdgeInsets {
93 type Output = EdgeInsets;
94 fn add(mut self, o: EdgeInsets) -> EdgeInsets {
95 self += o;
96 self
97 }
98}
99
100#[derive(Clone, Copy, Debug, Default, PartialEq)]
101#[cfg(test)]
102pub(crate) struct LatLngAltitude {
103 pub(crate) location: LatLng,
104 pub(crate) altitude: f64,
105}
106
107#[must_use]
112pub fn lat_range(id: &crate::tile::UnwrappedTileID, world: &mln_style::crs::WorldMapping) -> [f32; 2] {
113 if !world.wraps() {
114 return [0.0, 0.0];
115 }
116 let canonical = id.canonical;
117 let north = LatLng::from_unwrapped_tile(canonical.z, canonical.x, canonical.y, id.wrap);
118 let south = LatLng::from_unwrapped_tile(canonical.z, canonical.x, canonical.y + 1, id.wrap);
121 [north.latitude() as f32, south.latitude() as f32]
122}