euv_chart/geo/struct.rs
1use super::*;
2
3/// A point on the globe.
4#[derive(Clone, Copy, Debug, PartialEq)]
5pub struct GeoPoint {
6 /// The longitude, in degrees.
7 pub lng: f64,
8 /// The latitude, in degrees.
9 pub lat: f64,
10}
11
12/// The box a map covers.
13#[derive(Clone, Copy, Debug, lombok_macros::Data, PartialEq)]
14pub struct GeoBounds {
15 /// The westernmost longitude.
16 #[get(type(copy))]
17 pub min_lng: f64,
18 /// The southernmost latitude.
19 #[get(type(copy))]
20 pub min_lat: f64,
21 /// The easternmost longitude.
22 #[get(type(copy))]
23 pub max_lng: f64,
24 /// The northernmost latitude.
25 #[get(type(copy))]
26 pub max_lat: f64,
27}
28
29/// One outline of a region: an outer ring, and the holes in it.
30///
31/// A region is made of one or more outlines: a country with an
32/// enclave, or an archipelago, has more than one.
33#[derive(Clone, Debug, Default, PartialEq)]
34pub struct RegionPolygon {
35 /// The outer ring of the outline.
36 pub outer: Vec<GeoPoint>,
37 /// The holes of the outline — the lakes and the enclaves that are
38 /// not part of the region.
39 pub holes: Vec<Vec<GeoPoint>>,
40}
41
42/// One region of a map.
43///
44/// The name of the region is what the series' data is matched
45/// against: a data item whose name is the name of a region gives that
46/// region its value.
47#[derive(Clone, Debug, Default, lombok_macros::Data, PartialEq)]
48pub struct MapRegion {
49 /// The name of the region.
50 pub name: String,
51 /// The outlines of the region.
52 pub polygons: Vec<RegionPolygon>,
53}
54
55/// One map: the regions it is made of, and the box they cover.
56#[derive(Clone, Debug, Default, lombok_macros::Data, PartialEq)]
57pub struct MapData {
58 /// The name the map is registered under.
59 pub name: String,
60 /// The regions of the map.
61 pub regions: Vec<MapRegion>,
62 /// The box the regions cover.
63 pub bounds: GeoBounds,
64}
65
66/// The maps a chart can draw.
67///
68/// The registry is what turns a map series into a picture: the series
69/// names the map it wants, and the registry holds the geometry. The
70/// geometry is kept out of the option on purpose — a map of a country
71/// is megabytes of coordinates, and it is the same for every chart
72/// that draws it.
73#[derive(Clone, Debug, Default, lombok_macros::Data, PartialEq)]
74pub struct MapRegistry {
75 /// The maps of the registry, by name.
76 pub maps: BTreeMap<String, MapData>,
77}
78
79/// One region of a map, in pixel space.
80#[derive(Clone, Debug, lombok_macros::Data, PartialEq)]
81pub struct GeoRegionLayout {
82 /// The name of the region.
83 pub name: String,
84 /// The outline of the region, projected into the chart.
85 pub path: Path,
86 /// The middle of the region, where its label goes.
87 pub center: Point,
88}
89
90/// A map, in pixel space.
91#[derive(Clone, Debug, lombok_macros::Data, PartialEq)]
92pub struct GeoLayout {
93 /// The name of the map.
94 pub name: String,
95 /// The regions of the map, projected into the chart.
96 pub regions: Vec<GeoRegionLayout>,
97 /// The transform that takes a longitude and a latitude to a point of
98 /// the chart.
99 pub transform: Transform2D,
100}