Skip to content

Commit

Permalink
load runway elevation and glideslope from dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Dec 28, 2023
1 parent c41e96a commit 9c34fdc
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/plugin/approach/GlideslopeDeviationTagItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ namespace UKControllerPlugin::Approach {
}

// Set the tag colour based on the deviation
if (std::abs(deviation.deviation) < 300) {
tagData.SetTagColour(RGB(2, 48, 32));
} else {
if (deviation.deviation > 300) {
tagData.SetTagColour(RGB(255, 87, 51));
} else {
tagData.SetTagColour(RGB(2, 48, 32));
}

// If we're massively out, abbreviate the string
Expand Down
24 changes: 20 additions & 4 deletions src/plugin/runway/Runway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,23 @@

namespace UKControllerPlugin::Runway {

Runway::Runway(int id, int airfieldId, std::string identifier, int heading, EuroScopePlugIn::CPosition threshold)
// TODO: Remove hard-coded threshold elevation
// TODO: remove hard-coded glideslope angle
Runway::Runway(
int id,
int airfieldId,
std::string identifier,
int heading,
EuroScopePlugIn::CPosition threshold,
int thresholdElevation,
double glideslopeAngle)
// TODO: Remove hard-coded airfield identifier
: id(id), airfieldId(airfieldId), airfieldIdentifier("EGKK"), identifier(std::move(identifier)),
heading(heading), headingRadians(Geometry::DegreesToRadians(heading)),
perpendicularHeading(Headings::PerpendicularHeading(heading)),
perpendicularHeadingRadians(Geometry::DegreesToRadians(perpendicularHeading)),
runwayHeadingLineSlope(Geometry::Slope(headingRadians)),
runwayPerpendicularHeadingLineSlope(Geometry::Slope(perpendicularHeadingRadians)), threshold(threshold),
thresholdElevation(196), glideslopeAngleRadians(Geometry::DegreesToRadians(3))
thresholdElevation(thresholdElevation), glideslopeAngle(glideslopeAngle),
glideslopeAngleRadians(Geometry::DegreesToRadians(glideslopeAngle))
{
}

Expand Down Expand Up @@ -63,4 +69,14 @@ namespace UKControllerPlugin::Runway {
{
return runwayPerpendicularHeadingLineSlope;
}

auto Runway::ThresholdElevation() const -> int
{
return thresholdElevation;
}

auto Runway::GlideslopeAngle() const -> double
{
return glideslopeAngle;
}
} // namespace UKControllerPlugin::Runway
14 changes: 13 additions & 1 deletion src/plugin/runway/Runway.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ namespace UKControllerPlugin::Runway {
class Runway
{
public:
Runway(int id, int airfieldId, std::string identifier, int heading, EuroScopePlugIn::CPosition threshold);
Runway(
int id,
int airfieldId,
std::string identifier,
int heading,
EuroScopePlugIn::CPosition threshold,
int thresholdElevation,
double glideslopeAngle);
[[nodiscard]] auto Id() const -> int;
[[nodiscard]] auto AirfieldId() const -> int;
[[nodiscard]] auto AirfieldIdentifier() const -> const std::string&;
[[nodiscard]] auto Identifier() const -> const std::string&;
[[nodiscard]] auto Heading() const -> int;
[[nodiscard]] auto Threshold() const -> const EuroScopePlugIn::CPosition&;
[[nodiscard]] auto ThresholdElevation() const -> int;
[[nodiscard]] auto GlideslopeAngle() const -> double;
[[nodiscard]] auto GlideslopeAltitudeAtDistance(const double distanceInNauticalMiles) const -> int;
[[nodiscard]] auto RunwayHeadingLineSlope() const -> double;
[[nodiscard]] auto RunwayPerpendicularHeadingLineSlope() const -> double;
Expand Down Expand Up @@ -58,6 +67,9 @@ namespace UKControllerPlugin::Runway {
// The elevation of the runway threshold
int thresholdElevation;

// The glideslope angle in degrees
double glideslopeAngle;

// The glideslope angle (in radians)
double glideslopeAngleRadians;
};
Expand Down
8 changes: 6 additions & 2 deletions src/plugin/runway/RunwayCollectionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ namespace UKControllerPlugin::Runway {
runway.at("airfield_id").get<int>(),
runway.at("identifier").get<std::string>(),
runway.at("heading").get<int>(),
std::move(threshold)));
std::move(threshold),
runway.at("threshold_elevation").get<int>(),
runway.at("glideslope_angle").get<double>()));
}

LogInfo("Loaded " + std::to_string(collection->Count()) + " runways");
Expand All @@ -40,6 +42,8 @@ namespace UKControllerPlugin::Runway {
runway.contains("identifier") && runway.at("identifier").is_string() && runway.contains("heading") &&
runway.at("heading").is_number_integer() && runway.contains("threshold_latitude") &&
runway.at("threshold_latitude").is_number() && runway.contains("threshold_longitude") &&
runway.at("threshold_longitude").is_number();
runway.at("threshold_longitude").is_number() && runway.contains("threshold_elevation") &&
runway.at("threshold_elevation").is_number_integer() && runway.contains("glideslope_angle") &&
runway.at("glideslope_angle").is_number();
}
} // namespace UKControllerPlugin::Runway
2 changes: 1 addition & 1 deletion test/plugin/approach/GlideslopeDeviationEstimatorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace UKControllerPluginTest::Approach {
class GlideslopeDeviationEstimatorTest : public ::testing::Test
{
public:
GlideslopeDeviationEstimatorTest() : runway(1, 1, "26L", 257, RunwayPosition())
GlideslopeDeviationEstimatorTest() : runway(1, 1, "26L", 257, RunwayPosition(), 196, 3.0)
{
}

Expand Down
6 changes: 3 additions & 3 deletions test/plugin/approach/GlideslopeDeviationTagItemTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace UKControllerPluginTest::Approach {
EuroScopePlugIn::CPosition pos;
pos.m_Latitude = 51.150675;
pos.m_Longitude = -0.171925;
runways->Add(std::make_shared<UKControllerPlugin::Runway::Runway>(1, 1, "26L", 257, pos));
runways->Add(std::make_shared<UKControllerPlugin::Runway::Runway>(1, 1, "26L", 257, pos, 196, 3.0));

// Flightplan
ON_CALL(mockFlightplan, GetCallsign()).WillByDefault(testing::Return("BAW123"));
Expand Down Expand Up @@ -91,7 +91,7 @@ namespace UKControllerPluginTest::Approach {
glideslopeDeviationTagItem.SetTagItemData(tagData);

EXPECT_EQ("-448", tagData.GetItemString());
EXPECT_EQ(RGB(255, 87, 51), tagData.GetTagColour());
EXPECT_EQ(RGB(2, 48, 32), tagData.GetTagColour());
}

TEST_F(GlideslopeDeviationTagItemTest, ItSetsTagItemDataSlightlyBelow)
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace UKControllerPluginTest::Approach {
glideslopeDeviationTagItem.SetTagItemData(tagData);

EXPECT_EQ("<1k", tagData.GetItemString());
EXPECT_EQ(RGB(255, 87, 51), tagData.GetTagColour());
EXPECT_EQ(RGB(2, 48, 32), tagData.GetTagColour());
}

TEST_F(GlideslopeDeviationTagItemTest, ItDoesntSetTagItemDataIfRunwayNotFound)
Expand Down
39 changes: 34 additions & 5 deletions test/plugin/runway/RunwayCollectionFactoryTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ namespace UKControllerPluginTest::Runway {
{"heading", 123},
{"threshold_latitude", 1.2},
{"threshold_longitude", 3.4},
};
{"threshold_elevation", 201},
{"glideslope_angle", 3.0}};
runway.update(overridingData);

if (!keyToRemove.empty()) {
Expand Down Expand Up @@ -91,6 +92,26 @@ namespace UKControllerPluginTest::Runway {
EXPECT_FALSE(RunwayValid(MakeRunway(nlohmann::json{{"threshold_longitude", "abc"}})));
}

TEST_F(RunwayCollectionFactoryTest, RunwayIsInvalidIfThresholdElevationMissing)
{
EXPECT_FALSE(RunwayValid(MakeRunway(nlohmann::json::object(), "threshold_elevation")));
}

TEST_F(RunwayCollectionFactoryTest, RunwayIsInvalidIfThresholdElevationNotAnInteger)
{
EXPECT_FALSE(RunwayValid(MakeRunway(nlohmann::json{{"threshold_elevation", 1.5}})));
}

TEST_F(RunwayCollectionFactoryTest, RunwayIsInvalidIfGlideslopeAngleMissing)
{
EXPECT_FALSE(RunwayValid(MakeRunway(nlohmann::json::object(), "glideslope_angle")));
}

TEST_F(RunwayCollectionFactoryTest, RunwayIsInvalidIfThresholdElevationNotANumber)
{
EXPECT_FALSE(RunwayValid(MakeRunway(nlohmann::json{{"glideslope_angle", "abc"}})));
}

TEST_F(RunwayCollectionFactoryTest, RunwayIsInvalidIfNotAnObject)
{
EXPECT_FALSE(RunwayValid(nlohmann::json::array()));
Expand All @@ -111,15 +132,17 @@ namespace UKControllerPluginTest::Runway {
{"heading", 123},
{"threshold_latitude", 1.2},
{"threshold_longitude", 3.4},
});
{"threshold_elevation", 201},
{"glideslope_angle", 3.0}});
dependency.push_back(nlohmann::json{
{"id", 2},
{"airfield_id", 3},
{"identifier", "04"},
{"heading", 234},
{"threshold_latitude", 3.4},
{"threshold_longitude", 4.5},
});
{"threshold_elevation", 202},
{"glideslope_angle", 3.1}});

auto collection = BuildRunwayCollection(dependency);
EXPECT_EQ(2, collection->Count());
Expand All @@ -131,6 +154,8 @@ namespace UKControllerPluginTest::Runway {
EXPECT_EQ(123, runway1->Heading());
EXPECT_FLOAT_EQ(1.2, runway1->Threshold().m_Latitude);
EXPECT_FLOAT_EQ(3.4, runway1->Threshold().m_Longitude);
EXPECT_EQ(201, runway1->ThresholdElevation());
EXPECT_FLOAT_EQ(3.0, runway1->GlideslopeAngle());

auto runway2 = collection->GetById(2);
EXPECT_EQ(2, runway2->Id());
Expand All @@ -139,6 +164,8 @@ namespace UKControllerPluginTest::Runway {
EXPECT_EQ(234, runway2->Heading());
EXPECT_FLOAT_EQ(3.4, runway2->Threshold().m_Latitude);
EXPECT_FLOAT_EQ(4.5, runway2->Threshold().m_Longitude);
EXPECT_EQ(202, runway2->ThresholdElevation());
EXPECT_DOUBLE_EQ(3.1, runway2->GlideslopeAngle());
}

TEST_F(RunwayCollectionFactoryTest, ItIgnoresInvalidRunways)
Expand All @@ -151,15 +178,17 @@ namespace UKControllerPluginTest::Runway {
{"heading", 123},
{"threshold_latitude", 1.2},
{"threshold_longitude", 3.4},
});
{"threshold_elevation", 201},
{"glideslope_angle", 3.0}});
dependency.push_back(nlohmann::json{
{"id", 2},
{"airfield_id", 3},
{"identifier", "04"},
{"heading", 234},
{"threshold_latitude", "abc"}, // Invalid
{"threshold_longitude", 4.5},
});
{"threshold_elevation", 201},
{"glideslope_angle", 3.0}});

EXPECT_EQ(0, BuildRunwayCollection(nlohmann::json::object())->Count());
}
Expand Down
6 changes: 3 additions & 3 deletions test/plugin/runway/RunwayCollectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ namespace UKControllerPluginTest::Runway {
{
public:
RunwayCollectionTest()
: runway1(std::make_shared<class Runway>(1, 2, "05", 50, GetPosition())),
runway2(std::make_shared<class Runway>(2, 2, "27L", 270, GetPosition())),
runway3(std::make_shared<class Runway>(3, 3, "27L", 275, GetPosition()))
: runway1(std::make_shared<class Runway>(1, 2, "05", 50, GetPosition(), 196, 3.0)),
runway2(std::make_shared<class Runway>(2, 2, "27L", 270, GetPosition(), 196, 3.0)),
runway3(std::make_shared<class Runway>(3, 3, "27L", 275, GetPosition(), 196, 3.0))
{
}

Expand Down
12 changes: 11 additions & 1 deletion test/plugin/runway/RunwayTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace UKControllerPluginTest::Runway {
class RunwayTest : public testing::Test
{
public:
RunwayTest() : runway(1, 2, "27L", 123, GetPosition())
RunwayTest() : runway(1, 2, "27L", 123, GetPosition(), 196, 3.0)
{
}

Expand Down Expand Up @@ -57,6 +57,16 @@ namespace UKControllerPluginTest::Runway {
EXPECT_EQ(2407, runway.GlideslopeAltitudeAtDistance(6.95));
}

TEST_F(RunwayTest, ItHasAThresholdElevation)
{
EXPECT_EQ(196, runway.ThresholdElevation());
}

TEST_F(RunwayTest, ItHasAGlideslopeAngle)
{
EXPECT_DOUBLE_EQ(3, runway.GlideslopeAngle());
}

TEST_F(RunwayTest, ItCalculatesRunwayHeadingLineSlope)
{
EXPECT_DOUBLE_EQ(-1.5398649638145827, runway.RunwayHeadingLineSlope());
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/sid/FlightplanSidMapperTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace UKControllerPluginTest::Sid {
EuroScopePlugIn::CPosition threshold;
threshold.m_Latitude = 1;
threshold.m_Latitude = 2;
this->runways.Add(std::make_shared<class Runway>(2, 2, "27L", 123, threshold));
this->runways.Add(std::make_shared<class Runway>(2, 2, "27L", 123, threshold, 196, 3.0));
this->sids.AddSid(std::make_shared<StandardInstrumentDeparture>(1, 1, "TEST1A", 1, 2, 3));
this->sids.AddSid(std::make_shared<StandardInstrumentDeparture>(2, 2, "TEST1B", 3, 4, 5));

Expand Down

0 comments on commit 9c34fdc

Please sign in to comment.