|
1 |
| -use serde::Serialize; |
2 |
| - |
3 |
| -use crate::math::Coordinates; |
4 |
| - |
5 |
| -#[derive(Serialize, Copy, Clone)] |
6 |
| -pub enum FixType { |
7 |
| - #[serde(rename = "A")] |
8 |
| - Airport, |
9 |
| - #[serde(rename = "N")] |
10 |
| - NdbNavaid, |
11 |
| - #[serde(rename = "R")] |
12 |
| - RunwayThreshold, |
13 |
| - #[serde(rename = "G")] |
14 |
| - GlsNavaid, |
15 |
| - #[serde(rename = "I")] |
16 |
| - IlsNavaid, |
17 |
| - #[serde(rename = "V")] |
18 |
| - VhfNavaid, |
19 |
| - #[serde(rename = "W")] |
20 |
| - Waypoint, |
21 |
| - #[serde(rename = "U")] |
22 |
| - None, |
23 |
| -} |
24 |
| - |
25 |
| -#[serde_with::skip_serializing_none] |
26 |
| -#[derive(Serialize, Clone)] |
27 |
| -/// Represents a fix which was used as a reference in a procedure or an airway. |
28 |
| -/// |
29 |
| -/// Every `Fix` will have a full data entry as one of these structs somewhere in the database with the same `ident` and |
30 |
| -/// `icao_code`: |
31 |
| -/// - `Airport` |
32 |
| -/// - `NdbNavaid` |
33 |
| -/// - `RunwayThreshold` |
34 |
| -/// - `GlsNavaid` |
35 |
| -/// - `IlsNavaid` |
36 |
| -/// - `VhfNavaid` |
37 |
| -/// - `Waypoint` |
38 |
| -pub struct Fix { |
39 |
| - /// The type of fix |
40 |
| - pub fix_type: Option<FixType>, |
41 |
| - /// The identifier of this fix (not unique), such as `KLAX` or `BI` or `RW17L` or `G07J` or `ISYK` or `YXM` or |
42 |
| - /// `GLENN` |
43 |
| - pub ident: String, |
44 |
| - /// The icao prefix of the region that this fix is in. |
45 |
| - pub icao_code: String, |
46 |
| - /// The geographic location of this fix |
47 |
| - pub location: Coordinates, |
48 |
| - /// The identifier of the airport that this fix is associated with, if any |
49 |
| - pub airport_ident: Option<String>, |
50 |
| -} |
51 |
| - |
52 |
| -impl Fix { |
53 |
| - /// Creates a `Fix` by using the latitude and longitude fields, and by parsing the linked id field from a procedure |
54 |
| - /// or airway row. |
55 |
| - pub fn from_row_data( |
56 |
| - lat: f64, |
57 |
| - long: f64, |
58 |
| - ident: String, |
59 |
| - icao_code: String, |
60 |
| - airport_ident: Option<String>, |
61 |
| - ref_table: Option<String>, |
62 |
| - ) -> Self { |
63 |
| - let fix_type = ref_table.map(|ref_table| match ref_table.as_str() { |
64 |
| - "PA" => FixType::Airport, |
65 |
| - "PN" | "DB" => FixType::NdbNavaid, |
66 |
| - "PG" => FixType::RunwayThreshold, |
67 |
| - "PT" => FixType::GlsNavaid, |
68 |
| - "PI" => FixType::IlsNavaid, |
69 |
| - "D " => FixType::VhfNavaid, |
70 |
| - "EA" | "PC" => FixType::Waypoint, |
71 |
| - x => panic!("Unexpected table: '{x}'"), |
72 |
| - }); |
73 |
| - |
74 |
| - Self { |
75 |
| - fix_type, |
76 |
| - ident, |
77 |
| - icao_code, |
78 |
| - location: Coordinates { lat, long }, |
79 |
| - airport_ident, |
80 |
| - } |
81 |
| - } |
82 |
| -} |
| 1 | +use serde::Serialize; |
| 2 | + |
| 3 | +use crate::math::Coordinates; |
| 4 | + |
| 5 | +#[derive(Serialize, Copy, Clone)] |
| 6 | +pub enum FixType { |
| 7 | + #[serde(rename = "A")] |
| 8 | + Airport, |
| 9 | + #[serde(rename = "N")] |
| 10 | + NdbNavaid, |
| 11 | + #[serde(rename = "R")] |
| 12 | + RunwayThreshold, |
| 13 | + #[serde(rename = "G")] |
| 14 | + GlsNavaid, |
| 15 | + #[serde(rename = "I")] |
| 16 | + IlsNavaid, |
| 17 | + #[serde(rename = "V")] |
| 18 | + VhfNavaid, |
| 19 | + #[serde(rename = "W")] |
| 20 | + Waypoint, |
| 21 | + #[serde(rename = "U")] |
| 22 | + None, |
| 23 | +} |
| 24 | + |
| 25 | +#[serde_with::skip_serializing_none] |
| 26 | +#[derive(Serialize, Clone)] |
| 27 | +/// Represents a fix which was used as a reference in a procedure or an airway. |
| 28 | +/// |
| 29 | +/// Every `Fix` will have a full data entry as one of these structs somewhere in the database with the same `ident` and |
| 30 | +/// `icao_code`: |
| 31 | +/// - `Airport` |
| 32 | +/// - `NdbNavaid` |
| 33 | +/// - `RunwayThreshold` |
| 34 | +/// - `GlsNavaid` |
| 35 | +/// - `IlsNavaid` |
| 36 | +/// - `VhfNavaid` |
| 37 | +/// - `Waypoint` |
| 38 | +pub struct Fix { |
| 39 | + /// The type of fix |
| 40 | + pub fix_type: Option<FixType>, |
| 41 | + pub fix_code: Option<String>, |
| 42 | + /// The identifier of this fix (not unique), such as `KLAX` or `BI` or `RW17L` or `G07J` or `ISYK` or `YXM` or |
| 43 | + /// `GLENN` |
| 44 | + pub ident: String, |
| 45 | + /// The icao prefix of the region that this fix is in. |
| 46 | + pub icao_code: String, |
| 47 | + /// The geographic location of this fix |
| 48 | + pub location: Coordinates, |
| 49 | + /// The identifier of the airport that this fix is associated with, if any |
| 50 | + pub airport_ident: Option<String>, |
| 51 | +} |
| 52 | + |
| 53 | +impl Fix { |
| 54 | + /// Creates a `Fix` by using the latitude and longitude fields, and by parsing the linked id field from a procedure |
| 55 | + /// or airway row. |
| 56 | + pub fn from_row_data( |
| 57 | + lat: f64, |
| 58 | + long: f64, |
| 59 | + ident: String, |
| 60 | + icao_code: String, |
| 61 | + airport_ident: Option<String>, |
| 62 | + ref_table: Option<String>, |
| 63 | + fix_code: Option<String>, |
| 64 | + ) -> Self { |
| 65 | + let fix_type = ref_table.map(|ref_table| match ref_table.as_str() { |
| 66 | + "PA" => FixType::Airport, |
| 67 | + "PN" | "DB" => FixType::NdbNavaid, |
| 68 | + "PG" => FixType::RunwayThreshold, |
| 69 | + "PT" => FixType::GlsNavaid, |
| 70 | + "PI" => FixType::IlsNavaid, |
| 71 | + "D " => FixType::VhfNavaid, |
| 72 | + "EA" | "PC" => FixType::Waypoint, |
| 73 | + x => panic!("Unexpected table: '{x}'"), |
| 74 | + }); |
| 75 | + |
| 76 | + Self { |
| 77 | + fix_type, |
| 78 | + ident, |
| 79 | + icao_code, |
| 80 | + location: Coordinates { lat, long }, |
| 81 | + airport_ident, |
| 82 | + fix_code, |
| 83 | + } |
| 84 | + } |
| 85 | +} |
0 commit comments