Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: load fir exit points from dependency
- Loading branch information
Showing
16 changed files
with
600 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "FirExitPoint.h" | ||
#include "FirExitPointCollection.h" | ||
|
||
namespace UKControllerPlugin::IntentionCode { | ||
|
||
void FirExitPointCollection::Add(const std::shared_ptr<FirExitPoint>& point) | ||
{ | ||
if (points.contains(point->Identifier())) { | ||
LogWarning("Duplicate FIR exit point added"); | ||
return; | ||
} | ||
|
||
points[point->Identifier()] = point; | ||
} | ||
|
||
auto FirExitPointCollection::CountPoints() const -> size_t | ||
{ | ||
return points.size(); | ||
} | ||
|
||
auto FirExitPointCollection::PointByIdentifier(const std::string& identifier) const -> std::shared_ptr<FirExitPoint> | ||
{ | ||
return points.contains(identifier) ? points.at(identifier) : nullptr; | ||
} | ||
} // namespace UKControllerPlugin::IntentionCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin::IntentionCode { | ||
|
||
class FirExitPoint; | ||
|
||
/** | ||
* All the FIR exit points in one handy place | ||
*/ | ||
class FirExitPointCollection | ||
{ | ||
public: | ||
void Add(const std::shared_ptr<FirExitPoint>& point); | ||
[[nodiscard]] auto CountPoints() const -> size_t; | ||
[[nodiscard]] auto PointByIdentifier(const std::string& identifier) const -> std::shared_ptr<FirExitPoint>; | ||
|
||
private: | ||
// All the points, indexed by identifier | ||
std::map<std::string, std::shared_ptr<FirExitPoint>> points; | ||
}; | ||
|
||
} // namespace UKControllerPlugin::IntentionCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "ExitCone.h" | ||
#include "FirExitPoint.h" | ||
#include "FirExitPointCollection.h" | ||
#include "FirExitPointCollectionFactory.h" | ||
|
||
namespace UKControllerPlugin::IntentionCode { | ||
|
||
auto MakeFirExitPointCollection(const nlohmann::json& exitPointData) -> std::shared_ptr<FirExitPointCollection> | ||
{ | ||
auto collection = std::make_shared<FirExitPointCollection>(); | ||
if (!exitPointData.is_array()) { | ||
return collection; | ||
} | ||
|
||
for (const auto& exitPoint : exitPointData) { | ||
if (!ExitPointValid(exitPoint)) { | ||
LogError("Invalid FIR exit point: " + exitPoint.dump()); | ||
continue; | ||
} | ||
|
||
collection->Add(std::make_shared<FirExitPoint>( | ||
exitPoint.at("id").get<int>(), | ||
exitPoint.at("exit_point").get<std::string>(), | ||
exitPoint.at("internal").get<bool>(), | ||
std::make_shared<ExitCone>( | ||
exitPoint.at("exit_direction_start").get<int>(), exitPoint.at("exit_direction_end").get<int>()))); | ||
} | ||
|
||
LogInfo("Created FIR Exit Points collection with " + std::to_string(collection->CountPoints()) + " points"); | ||
return collection; | ||
} | ||
|
||
auto ExitPointValid(const nlohmann::json& exitPointData) -> bool | ||
{ | ||
return exitPointData.is_object() && exitPointData.contains("id") && | ||
exitPointData.at("id").is_number_integer() && exitPointData.contains("exit_point") && | ||
exitPointData.at("exit_point").is_string() && exitPointData.contains("internal") && | ||
exitPointData.at("internal").is_boolean() && HeadingValid("exit_direction_start", exitPointData) && | ||
HeadingValid("exit_direction_end", exitPointData); | ||
} | ||
|
||
auto HeadingValid(const std::string& key, const nlohmann::json& exitPointData) -> bool | ||
{ | ||
if (!exitPointData.contains(key)) { | ||
return false; | ||
} | ||
|
||
if (!exitPointData.at(key).is_number_integer()) { | ||
return false; | ||
} | ||
|
||
const auto heading = exitPointData.at(key).get<int>(); | ||
return heading >= 0 && heading <= 360; | ||
} | ||
} // namespace UKControllerPlugin::IntentionCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
namespace UKControllerPlugin::IntentionCode { | ||
|
||
class FirExitPointCollection; | ||
|
||
[[nodiscard]] auto MakeFirExitPointCollection(const nlohmann::json& exitPointData) | ||
-> std::shared_ptr<FirExitPointCollection>; | ||
[[nodiscard]] auto ExitPointValid(const nlohmann::json& exitPointData) -> bool; | ||
[[nodiscard]] auto HeadingValid(const std::string& key, const nlohmann::json& exitPointData) -> bool; | ||
} // namespace UKControllerPlugin::IntentionCode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.