Skip to content

Commit

Permalink
refactor: rename drift to deviation
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyTWF committed Dec 28, 2023
1 parent 3b5f774 commit 4323b23
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 85 deletions.
8 changes: 4 additions & 4 deletions src/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ set(src__approach
approach/ApproachSequencerDisplayAsrLoader.cpp approach/ApproachSequencerDisplayAsrLoader.h
approach/ToggleApproachSequencerDisplay.cpp approach/ToggleApproachSequencerDisplay.h
approach/SequencerAirfieldSelector.cpp approach/SequencerAirfieldSelector.h approach/AircraftSelectionProvider.cpp approach/AircraftSelectionProvider.h approach/TargetSelectorList.cpp approach/TargetSelectorList.h approach/ApproachSpacingCalculator.cpp approach/ApproachSpacingCalculator.h approach/ApproachSequencerOptions.cpp approach/ApproachSequencerOptions.h approach/AirfieldApproachOptions.h approach/ApproachSequencerOptionsLoader.cpp approach/ApproachSequencerOptionsLoader.h approach/AirfieldTargetSelectorList.cpp approach/AirfieldTargetSelectorList.h approach/ApproachSequencerDistanceOptions.cpp approach/ApproachSequencerDistanceOptions.h approach/RemoveLandedAircraft.cpp approach/RemoveLandedAircraft.h approach/ApproachFlightplanEventHandler.cpp approach/ApproachFlightplanEventHandler.h
approach/GlideslopeDriftEstimator.h
approach/GlideslopeDriftEstimator.cpp
approach/GlideslopeDriftTagItem.cpp
approach/GlideslopeDriftTagItem.h)
approach/GlideslopeDeviationEstimator.h
approach/GlideslopeDeviationEstimator.cpp
approach/GlideslopeDeviationTagItem.cpp
approach/GlideslopeDeviationTagItem.h)
source_group("src\\approach" FILES ${src__approach})

set(src__bootstrap
Expand Down
11 changes: 6 additions & 5 deletions src/plugin/approach/ApproachBootstrapProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "ApproachSequencerDisplayOptions.h"
#include "ApproachSequencerOptionsLoader.h"
#include "ApproachSpacingRingRenderer.h"
#include "GlideslopeDriftEstimator.h"
#include "GlideslopeDriftTagItem.h"
#include "GlideslopeDeviationEstimator.h"
#include "GlideslopeDeviationTagItem.h"
#include "RemoveLandedAircraft.h"
#include "SequencerAirfieldSelector.h"
#include "TargetSelectorList.h"
Expand Down Expand Up @@ -42,11 +42,12 @@ namespace UKControllerPlugin::Approach {
container.flightplanHandler->RegisterHandler(
std::make_shared<ApproachFlightplanEventHandler>(container.moduleFactories->Approach().Sequencer()));

// Add the drift tag item
const auto driftEstimator = std::make_shared<GlideslopeDriftEstimator>();
// Add the deviation tag item
const auto deviationEstimator = std::make_shared<GlideslopeDeviationEstimator>();

container.tagHandler->RegisterTagItem(
DRIFT_TAG_ITEM_ID, std::make_shared<GlideslopeDriftTagItem>(driftEstimator, container.runwayCollection));
GLIDESLOPE_DEVIATION_TAG_ITEM_ID,
std::make_shared<GlideslopeDeviationTagItem>(deviationEstimator, container.runwayCollection));
}

void ApproachBootstrapProvider::BootstrapRadarScreen(
Expand Down
2 changes: 1 addition & 1 deletion src/plugin/approach/ApproachBootstrapProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ namespace UKControllerPlugin::Approach {
const RadarScreen::MenuToggleableDisplayFactory& toggleableDisplayFactory) override;

private:
const int DRIFT_TAG_ITEM_ID = 132;
const int GLIDESLOPE_DEVIATION_TAG_ITEM_ID = 132;
};
} // namespace UKControllerPlugin::Approach
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#include "GlideslopeDriftEstimator.h"
#include "GlideslopeDeviationEstimator.h"
#include "euroscope/EuroScopeCRadarTargetInterface.h"
#include "runway/Runway.h"

namespace UKControllerPlugin::Approach {

auto GlideslopeDriftEstimator::CalculateGlideslopeDrift(
auto GlideslopeDeviationEstimator::CalculateGlideslopeDeviation(
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget, const Runway::Runway& runway) const
-> GlideslopeDrift
-> GlideslopeDeviation
{
// Calculate the slope of each line
const auto runwaySlope = runway.RunwayHeadingLineSlope();
Expand All @@ -23,7 +23,7 @@ namespace UKControllerPlugin::Approach {
const auto distance = runway.Threshold().DistanceTo(intersection);

return {
.drift = radarTarget.GetAltitude() - runway.GlideslopeAltitudeAtDistance(distance),
.deviation = radarTarget.GetAltitude() - runway.GlideslopeAltitudeAtDistance(distance),
.perpendicularDistanceFromLocaliser = radarTarget.GetPosition().DistanceTo(intersection),
.localiserRange = distance};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ namespace UKControllerPlugin {
} // namespace UKControllerPlugin

namespace UKControllerPlugin::Approach {
struct GlideslopeDrift
struct GlideslopeDeviation
{
int drift;
int deviation;
double perpendicularDistanceFromLocaliser;
double localiserRange;
};

class GlideslopeDriftEstimator
class GlideslopeDeviationEstimator
{
public:
[nodiscard] auto CalculateGlideslopeDrift(
[nodiscard] auto CalculateGlideslopeDeviation(
const Euroscope::EuroScopeCRadarTargetInterface& radarTarget, const Runway::Runway& runway) const
-> GlideslopeDrift;
-> GlideslopeDeviation;
};
} // namespace UKControllerPlugin::Approach
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#include "GlideslopeDriftEstimator.h"
#include "GlideslopeDriftTagItem.h"
#include "GlideslopeDeviationEstimator.h"
#include "GlideslopeDeviationTagItem.h"
#include "euroscope/EuroScopeCFlightPlanInterface.h"
#include "euroscope/EuroScopeCRadarTargetInterface.h"
#include "runway/Runway.h"
#include "runway/RunwayCollection.h"
#include "tag/TagData.h"

namespace UKControllerPlugin::Approach {
GlideslopeDriftTagItem::GlideslopeDriftTagItem(
std::shared_ptr<const GlideslopeDriftEstimator> glideslopeDriftEstimator,
GlideslopeDeviationTagItem::GlideslopeDeviationTagItem(
std::shared_ptr<const GlideslopeDeviationEstimator> glideslopeDeviationEstimator,
std::shared_ptr<const Runway::RunwayCollection> runways)
: glideslopeDriftEstimator(glideslopeDriftEstimator), runways(runways)
: glideslopeDeviationEstimator(glideslopeDeviationEstimator), runways(runways)
{
assert(this->glideslopeDriftEstimator != nullptr && "Glideslope drift estimator cannot be null");
assert(this->glideslopeDeviationEstimator != nullptr && "Glideslope deviation estimator cannot be null");
assert(this->runways != nullptr && "Runways cannot be null");
}

std::string GlideslopeDriftTagItem::GetTagItemDescription(int tagItemId) const
std::string GlideslopeDeviationTagItem::GetTagItemDescription(int tagItemId) const
{
switch (tagItemId) {
case 132:
Expand All @@ -26,7 +26,7 @@ namespace UKControllerPlugin::Approach {
}
}

void GlideslopeDriftTagItem::SetTagItemData(Tag::TagData& tagData)
void GlideslopeDeviationTagItem::SetTagItemData(Tag::TagData& tagData)
{
const auto& flightplan = tagData.GetFlightplan();

Expand All @@ -43,34 +43,35 @@ namespace UKControllerPlugin::Approach {
return;
}

// Calculate the drift and make sure we're somewhat close
const auto drift = glideslopeDriftEstimator->CalculateGlideslopeDrift(tagData.GetRadarTarget(), *runway);
if (drift.perpendicularDistanceFromLocaliser > 15) {
// Calculate the deviation and make sure we're somewhat close
const auto deviation =
glideslopeDeviationEstimator->CalculateGlideslopeDeviation(tagData.GetRadarTarget(), *runway);
if (deviation.perpendicularDistanceFromLocaliser > 15) {
return;
}

if (drift.localiserRange > 25) {
if (deviation.localiserRange > 25) {
return;
}

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

// If we're massively out, abbreviate the string
if (drift.drift > 999) {
if (deviation.deviation > 999) {
tagData.SetItemString(">1k");
return;
} else if (drift.drift < -999) {
} else if (deviation.deviation < -999) {
tagData.SetItemString("<1k");
return;
}

// Set the tag item string
const auto driftSign = drift.drift >= 0 ? "+" : "";
tagData.SetItemString(driftSign + std::to_string(drift.drift));
const auto deviationSign = deviation.deviation >= 0 ? "+" : "";
tagData.SetItemString(deviationSign + std::to_string(deviation.deviation));
}
} // namespace UKControllerPlugin::Approach
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace UKControllerPlugin {

namespace UKControllerPlugin::Approach {

class GlideslopeDriftEstimator;
class GlideslopeDeviationEstimator;

class GlideslopeDriftTagItem : public Tag::TagItemInterface
class GlideslopeDeviationTagItem : public Tag::TagItemInterface
{
public:
GlideslopeDriftTagItem(
std::shared_ptr<const GlideslopeDriftEstimator> glideslopeDriftEstimator,
GlideslopeDeviationTagItem(
std::shared_ptr<const GlideslopeDeviationEstimator> glideslopeDeviationEstimator,
std::shared_ptr<const Runway::RunwayCollection> runways);
auto GetTagItemDescription(int tagItemId) const -> std::string override;
void SetTagItemData(Tag::TagData& tagData) override;

private:
// The glideslope drift estimator
std::shared_ptr<const GlideslopeDriftEstimator> glideslopeDriftEstimator;
// The glideslope deviation estimator
std::shared_ptr<const GlideslopeDeviationEstimator> glideslopeDeviationEstimator;

// The runways
std::shared_ptr<const Runway::RunwayCollection> runways;
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ set(test__approach
approach/ApproachSequencerDisplayAsrLoaderTest.cpp
approach/ToggleApproachSequencerDisplayTest.cpp
approach/SequencerAirfieldSelectorTest.cpp approach/ApproachModuleFactoryTest.cpp approach/AircraftSelectionProviderTest.cpp approach/TargetSelectorListTest.cpp wake/ApproachSpacingCalculatorTest.cpp approach/ApproachSequencerOptionsTest.cpp approach/ApproachSequencerOptionsLoaderTest.cpp approach/AirfieldTargetSelectorListTest.cpp approach/ApproachSequencerDistanceOptionsTest.cpp approach/AirfieldMinimumSeparationSelectorListTest.cpp approach/RemoveLandedAircraftTest.cpp approach/ApproachFlightplanEventHandlerTest.cpp
approach/GlideslopeDriftEstimatorTest.cpp
approach/GlideslopeDriftTagItemTest.cpp)
approach/GlideslopeDeviationEstimatorTest.cpp
approach/GlideslopeDeviationTagItemTest.cpp)
source_group("test\\approach" FILES ${test__approach})

set(test__bootstrap
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/approach/ApproachBootstrapProviderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace UKControllerPluginTest::Approach {
EXPECT_EQ(1, container.flightplanHandler->CountHandlers());
}

TEST_F(ApproachBootstrapProviderTest, ItRegistersTheDriftTagItem)
TEST_F(ApproachBootstrapProviderTest, ItRegistersTheGlideslopeDeviationTagItem)
{
this->RunBootstrapPlugin(provider);
EXPECT_EQ(1, container.tagHandler->CountHandlers());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "approach/GlideslopeDriftEstimator.h"
#include "approach/GlideslopeDeviationEstimator.h"
#include "runway/Runway.h"

namespace UKControllerPluginTest::Approach {
class GlideslopeDriftEstimatorTest : public ::testing::Test
class GlideslopeDeviationEstimatorTest : public ::testing::Test
{
public:
GlideslopeDriftEstimatorTest() : runway(1, 1, "26L", 257, RunwayPosition())
GlideslopeDeviationEstimatorTest() : runway(1, 1, "26L", 257, RunwayPosition())
{
}

Expand All @@ -19,10 +19,10 @@ namespace UKControllerPluginTest::Approach {

UKControllerPlugin::Runway::Runway runway;
testing::NiceMock<Euroscope::MockEuroScopeCRadarTargetInterface> radarTarget;
UKControllerPlugin::Approach::GlideslopeDriftEstimator glideslopeDriftEstimator;
UKControllerPlugin::Approach::GlideslopeDeviationEstimator glideslopeDeviationEstimator;
};

TEST_F(GlideslopeDriftEstimatorTest, CalculateGlideslopeDrift)
TEST_F(GlideslopeDeviationEstimatorTest, CalculateGlideslopeDeviation)
{
EuroScopePlugIn::CPosition aircraftPosition;
// Approx 8DME
Expand All @@ -31,8 +31,8 @@ namespace UKControllerPluginTest::Approach {
ON_CALL(radarTarget, GetPosition()).WillByDefault(testing::Return(aircraftPosition));
ON_CALL(radarTarget, GetAltitude()).WillByDefault(testing::Return(2000));

const auto result = glideslopeDriftEstimator.CalculateGlideslopeDrift(radarTarget, runway);
EXPECT_DOUBLE_EQ(-448, result.drift);
const auto result = glideslopeDeviationEstimator.CalculateGlideslopeDeviation(radarTarget, runway);
EXPECT_DOUBLE_EQ(-448, result.deviation);
EXPECT_NEAR(0.9515431, result.perpendicularDistanceFromLocaliser, 0.001);
EXPECT_NEAR(7.0799, result.localiserRange, 0.001);
}
Expand Down
Loading

0 comments on commit 4323b23

Please sign in to comment.