-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAirport.java
266 lines (222 loc) · 9.46 KB
/
Airport.java
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
import java.util.*;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@XmlRootElement
@XmlType(propOrder = { "resa", "stripEnd", "blastAllowance", "minSlope", "runways","runwayPositions","obstacles"})
public class Airport
{ // Default values below, can be set
public static int RESA = 240;
public static int StripEnd = 60;
public static int BlastAllowance = 300;
public static int MinSlope = 50;
// Runway designations, position of start of left runway
private Map<String, Point> runwayPositions;
private List<ObstacleData> obstacles;
private List<Runway> runways;
private Airport() {
runways = new ArrayList<>();
obstacles = new ArrayList<>();
runwayPositions = new HashMap<>();
}
public Airport(int RESA, int StripEnd, int BlastAllowance, int MinSlope)
{
if (RESA < 0 || StripEnd < 0 || BlastAllowance < 0 || MinSlope < 0) {
throw new IllegalArgumentException("Invalid data given for airport");
}
runways = new ArrayList<>();
this.RESA = RESA;
this.StripEnd = StripEnd;
this.BlastAllowance = BlastAllowance;
this.MinSlope = MinSlope;
this.obstacles = new ArrayList<ObstacleData>();
runwayPositions = new HashMap<String, Point>();
}
@XmlElementWrapper(name = "runways")
@XmlElement(name = "runway")
public List<Runway> getRunways() {
return runways;
}
@XmlElement(name = "resa")
public int getResa() {
return this.RESA;
}
@XmlElement(name = "stripEnd")
public int getStripEnd() {
return this.StripEnd;
}
@XmlElement(name = "blastAllowance")
public int getBlastAllowance() {
return this.BlastAllowance;
}
@XmlElement(name = "minSlope")
public int getMinSlope() {
return this.MinSlope;
}
@XmlElement
public Map<String,Point> getRunwayPositions() {
return this.runwayPositions;
}
@XmlElementWrapper(name = "obstacles")
@XmlElement(name = "obstacle")
public List<ObstacleData> getObstacles() {
return this.obstacles;
}
public void setRunways(List<Runway> runways) {
this.runways = runways;
}
public void setRunwayPositions(Map<String,Point> positions) {
this.runwayPositions = positions;
}
public void setObstacles(List<ObstacleData> obstacles) {
this.obstacles = obstacles;
}
public void addRunway(Runway run)
{
if (run == null) {
throw new IllegalArgumentException("Error adding runways to airport");
}
runwayPositions.put(run.getName(), new Point(1000000 * runways.size(), 1000000 * runways.size()));
this.runways.add(run);
}
public void addRunway(Runway oldRun, int intersectionPoint, Runway toAdd, int newRunIntersection)
{ // intersectionPoint: distance from start of left threshold in oldRun that an intersection occurs
// newRunIntersection: distance from start of left runway in toAdd that an intersection occurs
Point runStart = runwayPositions.get(oldRun.getName());
Point otherRunStart = MathsHelpers.calculatePositionFromIntersection(runStart, oldRun, intersectionPoint, toAdd, newRunIntersection);
runwayPositions.put(toAdd.getName(), otherRunStart);
this.runways.add(toAdd);
}
public void addRunwaysWithIntersections(Runway oldRun, List<Integer> intersectionPoints, List<Runway> toAdd, List<Integer> newRunIntersections)
{ // intersectionPoint: distance from start of left threshold in oldRun that an intersection occurs
// newRunIntersection: distance from start of left runway in toAdd that an intersection occurs
Point runStart = runwayPositions.get(oldRun.getName());
for (int i = 0; i < intersectionPoints.size(); i++) {
Point otherRunStart = MathsHelpers.calculatePositionFromIntersection(runStart, oldRun, intersectionPoints.get(i), toAdd.get(i), newRunIntersections.get(i));
runwayPositions.put(toAdd.get(i).getName(), otherRunStart);
this.runways.add(toAdd.get(i));
}
}
public Map<Runway, Point> getIntersectingRunways(Runway run)
{
Map<Runway, Point> returnVals = new HashMap<Runway, Point>();
Point relativePoint = runwayPositions.get(run.getName());
returnVals.put(run, new Point(0, 0));
for (Runway runway : runways) {
if (runway != run && MathsHelpers.linesintersect( runwayPositions.get(run.getName()), run.getLeftBearing(), run.getRunL().getRunwaySpec().TORA,
runwayPositions.get(runway.getName()), runway.getLeftBearing(), runway.getRunL().getRunwaySpec().TORA)) {
Point properPoint = runwayPositions.get(runway.getName());
returnVals.put(run, new Point(properPoint.x - relativePoint.x, properPoint.y - relativePoint.y));
}
}
return returnVals;
}
public RunwayOneWay getRunway(String runName)
{
if (runName == null) {
throw new IllegalArgumentException("No name given for runway");
}
boolean left = runName.charAt(2) == 'L';
if (left) {
for (int i = 0; i < runways.size(); i++) {
if (runways.get(i).getRunL().getName().equals(runName)) {
return runways.get(i).getRunL();
}
}
} else {
for (int i = 0; i < runways.size(); i++) {
if (runways.get(i).getRunR().getName().equals(runName)) {
return runways.get(i).getRunR();
}
}
}
throw new IllegalArgumentException("There is no runway in this airport with identifier '" + runName + "'");
}
public Point getRunwayPos(String runName)
{
return runwayPositions.get(runName);
}
public Runway getRunwayFull(String name)
{
if (name == null) {
throw new IllegalArgumentException("No name given for runway");
}
for (Runway run : runways) {
if (run.getName().equals(name)) {
return run;
}
}
throw new IllegalArgumentException("There is no runway in this airport with identifier '" + name + "'");
}
// runName is taken to be the full name, "09L/27R"
public void addObstacle(int height, int runwayPosition, String runName, boolean left)
{
if (runName == null) {
throw new IllegalArgumentException("No runway specified to add obstacle to");
}
if (left) {
addObstacle(new ObstacleData(MathsHelpers.calculatePosition(getRunwayFull(runName).getLeftBearing(), runwayPosition, 0, runwayPositions.get(runName)), height, 0));
} else {
addObstacle(new ObstacleData(MathsHelpers.calculatePosition(getRunwayFull(runName).getRightBearing(), runwayPosition, 0, MathsHelpers.calculatePositionInner(getRunwayFull(runName).getLeftBearing(), getRunwayFull(runName).getRunR().getRunwaySpec().TORA, runwayPositions.get(runName))), height, 0));
}
}
// runName is taken to be the full name, "09L/27R"
public void addObstacle(int height, int runwayPosition, int distanceFromCentreLine, String runName, boolean left)
{
if (runName == null) {
throw new IllegalArgumentException("No runway specified to add obstacle to");
}
if (left) {
addObstacle(new ObstacleData(MathsHelpers.calculatePosition(getRunwayFull(runName).getLeftBearing(), runwayPosition, distanceFromCentreLine, runwayPositions.get(runName)), height, distanceFromCentreLine));
} else {
addObstacle(new ObstacleData(MathsHelpers.calculatePosition(getRunwayFull(runName).getRightBearing(), runwayPosition, distanceFromCentreLine, MathsHelpers.calculatePositionInner(getRunwayFull(runName).getLeftBearing(), getRunwayFull(runName).getRunR().getRunwaySpec().TORA, runwayPositions.get(runName))), height, distanceFromCentreLine));
}
}
public void clearRunway(String runName)
{
List<ObstacleData> obstaclesToRemove = getRunwayFull(runName).clear();
for (Runway run : runways) {
for (ObstacleData ob : obstaclesToRemove) {
run.removeObstacle(ob, runwayPositions.get(run.getName()), MathsHelpers.calculateOtherStart(run.getRunL().getRunwaySpec().TORA, run.getLeftBearing(), runwayPositions.get(run.getName())));
}
}
obstacles.removeAll(obstaclesToRemove);
MainWindowController.addActivityText("Removed all obstacles near runway " + runName);
}
public void removeObstacle(ObstacleData OD)
{
if (OD == null) throw new IllegalArgumentException("Obstacle you tried to remove is null");
obstacles.remove(OD);
for (Runway run : runways) {
run.removeObstacle(OD, runwayPositions.get(run.getName()), MathsHelpers.calculateOtherStart(run.getRunL().getRunwaySpec().TORA, run.getLeftBearing(), runwayPositions.get(run.getName())));
}
}
public void addObstacle(ObstacleData OD)
{
obstacles.add(OD);
for (Runway run : runways) {
run.checkObstacle(OD, runwayPositions.get(run.getName()));
}
}
public List<ObstacleData> getRunwayObstacles(Runway run) {
if (!this.getRunways().contains(run)) throw new IllegalArgumentException("Passed a runway which is not part of this airport!");
else {
List<ObstacleData> runObs = new ArrayList<>();
this.getObstacles().forEach(obs -> {
if (run.getRunL().getImpactfulObstacles().contains(obs)) runObs.add(obs);
});
return runObs;
}
}
public static Runway findRunwayByName(String runName, List<Runway> runways) {
for (Runway run: runways) {
if (run.getName().equals(runName)) return run;
}
throw new IllegalArgumentException("Runway name doesn't match that of any runways in the passed list!");
}
public static ObstacleData findObstacleByName(String obsName, List<ObstacleData> obstacles ) {
for (ObstacleData obstacleData: obstacles) {
if (obstacleData.getName().equals(obsName)) return obstacleData;
}
throw new IllegalArgumentException("Obstacle name doesn't match that of any obstacles in the passed list!");
}
}