sct_reader/loaders/euroscope/
waypoint.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
use std::fmt::Display;

use super::{
    position::{Heading, Position, Valid},
    AirspaceClass,
};

pub trait Waypoint {
    fn identifier(&self) -> &String;
    fn position(&self) -> Position<Valid>;
}

#[derive(Debug, Clone)]
pub struct Fix {
    pub identifier: String,
    pub position: Position<Valid>,
}
impl Waypoint for Fix {
    fn identifier(&self) -> &String {
        &self.identifier
    }
    fn position(&self) -> Position<Valid> {
        self.position
    }
}

#[derive(Debug, Clone)]
pub struct Vor {
    pub identifier: String,
    pub position: Position<Valid>,
    pub frequency: String,
}
impl Waypoint for Vor {
    fn identifier(&self) -> &String {
        &self.identifier
    }
    fn position(&self) -> Position<Valid> {
        self.position
    }
}
impl Vor {
    pub fn frequency(&self) -> &String {
        &self.frequency
    }
}

#[derive(Debug, Clone)]
pub struct Ndb {
    pub identifier: String,
    pub position: Position<Valid>,
    pub frequency: String,
}
impl Waypoint for Ndb {
    fn identifier(&self) -> &String {
        &self.identifier
    }
    fn position(&self) -> Position<Valid> {
        self.position
    }
}
impl Ndb {
    pub fn frequency(&self) -> &String {
        &self.frequency
    }
}

#[derive(Debug, Clone)]
pub struct Airport {
    pub identifier: String,
    pub position: Position<Valid>,
    pub tower_frequency: String,
    pub airspace_class: AirspaceClass,
    pub runways: Vec<RunwayStrip>,
}
impl Waypoint for Airport {
    fn identifier(&self) -> &String {
        &self.identifier
    }
    fn position(&self) -> Position<Valid> {
        self.position
    }
}
impl Airport {
    pub fn tower_frequency(&self) -> &String {
        &self.tower_frequency
    }
    pub fn airspace_class(&self) -> AirspaceClass {
        self.airspace_class
    }
}

#[derive(Debug, Clone)]
pub struct RunwayStrip {
    pub end_a: RunwayEnd,
    pub end_b: RunwayEnd,
}

#[derive(Debug, Clone, PartialEq)]
pub struct RunwayEnd {
    pub number: u8,
    pub td_threshold_pos: Position<Valid>,
    pub se_threshold_pos: Position<Valid>,
    pub modifier: RunwayModifier,
    pub magnetic_hdg: Heading,
}
impl RunwayEnd {
    pub fn identifier(&self) -> String {
        format!("{:02}{}", self.number, self.modifier)
    }
    pub fn reciprocal(&self) -> RunwayEnd {
        let number = self.reciprocal_number();
        let td_threshold_pos = self.se_threshold_pos;
        let se_threshold_pos = self.td_threshold_pos;
        let modifier = self.modifier.reciprocal();
        let magnetic_hdg = self.magnetic_hdg.reciprocal();
        RunwayEnd {
            number,
            td_threshold_pos,
            se_threshold_pos,
            modifier,
            magnetic_hdg,
        }
    }
    fn reciprocal_number(&self) -> u8 {
        if self.number > 18 {
            self.number - 18
        } else {
            self.number + 18
        }
    }
}

#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum RunwayModifier {
    Left,
    Right,
    Centre,
    Grass,
    None,
}
impl RunwayModifier {
    pub fn reciprocal(&self) -> RunwayModifier {
        match self {
            Self::Left => Self::Right,
            Self::Right => Self::Left,
            Self::Centre => Self::Centre,
            Self::Grass => Self::Grass,
            Self::None => Self::None,
        }
    }
}

impl Display for RunwayModifier {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "{}",
            match self {
                Self::Left => "L",
                Self::Right => "R",
                Self::Centre => "C",
                Self::Grass => "G",
                Self::None => "",
            }
        )
    }
}