From a6ac60b7f3c8452fc9687f553f38c487a8d33a08 Mon Sep 17 00:00:00 2001 From: zrnBel Date: Mon, 30 Mar 2026 19:53:24 +0300 Subject: [PATCH 1/2] Fix airspace_loader --- include/air_space/air_space_data.h | 19 +++++---- .../json/airspace_loader/airspace_loader.h | 10 +---- include/math/vec3D.h | 2 +- include/points.h | 40 +++++++++++++++++++ src/json/airspace_loader/airspace.loader.cpp | 11 ++--- 5 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 include/points.h diff --git a/include/air_space/air_space_data.h b/include/air_space/air_space_data.h index 2e656bc..2ad69ce 100644 --- a/include/air_space/air_space_data.h +++ b/include/air_space/air_space_data.h @@ -7,11 +7,16 @@ #include -struct BlockedAirCorridor { +struct Point { + Vec3D vec; + std::size_t id {0}; +}; + +struct AirCorridor { std::size_t id1{0}; std::size_t id2{0}; - bool operator==(const BlockedAirCorridor& other) const { + bool operator==(const AirCorridor& other) const { return (id1 == other.id1 && id2 == other.id2) || (id1 == other.id2 && id2 == other.id1); } @@ -28,16 +33,14 @@ struct HighReliefZone { }; struct AirSpace { - QVector points; - QSet air_corridors; + QVector points; + QSet air_corridors; QVector pvo_list; QVector high_relief_zones; }; -inline unsigned int qHash(const BlockedAirCorridor& key, uint seed = 0) { - std::size_t id_a = std::min(key.id1, key.id2); - std::size_t id_b = std::max(key.id1, key.id2); - return qHash(std::make_pair(id_a, id_b), seed); +inline uint qHash(const AirCorridor& corridor, uint seed = 0) { + return ::qHash(corridor.id1, seed) ^ ::qHash(corridor.id2, seed); } #endif \ No newline at end of file diff --git a/include/json/airspace_loader/airspace_loader.h b/include/json/airspace_loader/airspace_loader.h index 4008d54..63e8303 100644 --- a/include/json/airspace_loader/airspace_loader.h +++ b/include/json/airspace_loader/airspace_loader.h @@ -13,13 +13,7 @@ #include #include "math/vec3D.h" - -struct AirSpace { - QVector points; - QSet air_corridors; - QVector pvo_list; - QVector high_relief_zones; -}; +#include class AirspaceLoader { public: @@ -31,6 +25,4 @@ class AirspaceLoader { static AirSpace _ConstructAirspace(QJsonArray& arr); }; -#endif - #endif \ No newline at end of file diff --git a/include/math/vec3D.h b/include/math/vec3D.h index 2c21cf3..3dd5ca8 100644 --- a/include/math/vec3D.h +++ b/include/math/vec3D.h @@ -10,7 +10,7 @@ class Vec3D { double z { 0.0 }; Vec3D() = default; - Vec3D(double x_, double y_, double z_) : x(x_), y(y_), z(z_) {} + Vec3D(double x_, double y_, double z_ = 0) : x(x_), y(y_), z(z_) {} Vec3D operator+(const Vec3D& other) const { return {x + other.x, y + other.y, z + other.z}; } Vec3D operator-(const Vec3D& other) const { return {x - other.x, y - other.y, z - other.z}; } diff --git a/include/points.h b/include/points.h new file mode 100644 index 0000000..76792e0 --- /dev/null +++ b/include/points.h @@ -0,0 +1,40 @@ +#ifndef POINTS_H +#define POINTS_H + +#include +#include +#include +#include +#include +#include +#include + +const float INFINITY_F = std::numeric_limits::infinity(); + +double euclideanDistance(const Vec3D& a, const Vec3D& b); +bool pointOnSegment(const Vec3D& p, const Vec3D& a, const Vec3D& b, double epsilon = 1e-9); +bool segmentsIntersect(const Vec3D& a1, const Vec3D& a2, const Vec3D& b1, const Vec3D& b2, double epsilon = 1e-9); +double distanceToSegment(const Vec3D& p, const Vec3D& a, const Vec3D& b); +bool segmentIntersectsCircle(const Vec3D& p1, const Vec3D& p2, const Vec3D& center, double radius, double epsilon = 1e-9); +std::pair getTangentPoints(const Vec3D& point, const Vec3D& center, double radius); +double calculateArcLength(const Vec3D& center, double radius, const Vec3D& point1, const Vec3D& point2); + +struct IntersectionInfo { + int pvoIndex{-1}; + const Pvo* pvo{nullptr}; + bool intersects{false}; +}; + +struct BypassPath { + QVector waypoints; + double length{0.0}; +}; + +IntersectionInfo findIntersectingPVO(const Vec3D& p1, const Vec3D& p2, const AirSpace& airspace); +BypassPath calculateCircularBypass(const Vec3D& start, const Vec3D& end, const Vec3D& center, double radius); +double calculateDistanceWithPVO(const Vec3D& p1, const Vec3D& p2, const AirSpace& airspace); + +float* createDistanceMatrix(const AirSpace& airspace); +void deleteDistanceMatrix(float* matrix); + +#endif diff --git a/src/json/airspace_loader/airspace.loader.cpp b/src/json/airspace_loader/airspace.loader.cpp index dbc9312..39fc354 100644 --- a/src/json/airspace_loader/airspace.loader.cpp +++ b/src/json/airspace_loader/airspace.loader.cpp @@ -37,17 +37,18 @@ AirSpace AirspaceLoader::_ConstructAirspace(QJsonArray& arr) { QJsonArray pointsArray = arr[0].toArray(); for (const auto& item : pointsArray) { QJsonObject obj = item.toObject(); - Vec3D point; - point.x = obj["x"].toDouble(); - point.y = obj["y"].toDouble(); - point.z = 0; + Point point; + point.id = obj["id"].toInt(); + point.vec.x = obj["x"].toDouble(); + point.vec.y = obj["y"].toDouble(); + point.vec.z = 0; result.points.append(point); } QJsonArray corridorsArray = arr[1].toArray(); for (const auto& item : corridorsArray) { QJsonObject obj = item.toObject(); - BlockedAirCorridor corridor; + AirCorridor corridor; corridor.id1 = obj["id1"].toInteger(); corridor.id2 = obj["id2"].toInteger(); result.air_corridors.insert(corridor); From c7a0a8d6b17ebcbb9c8d14396602990cc30f9ee9 Mon Sep 17 00:00:00 2001 From: Kirill Beloborodov Date: Mon, 30 Mar 2026 20:02:11 +0300 Subject: [PATCH 2/2] Fix airspace_loader --- include/points.h | 40 ---------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 include/points.h diff --git a/include/points.h b/include/points.h deleted file mode 100644 index 76792e0..0000000 --- a/include/points.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef POINTS_H -#define POINTS_H - -#include -#include -#include -#include -#include -#include -#include - -const float INFINITY_F = std::numeric_limits::infinity(); - -double euclideanDistance(const Vec3D& a, const Vec3D& b); -bool pointOnSegment(const Vec3D& p, const Vec3D& a, const Vec3D& b, double epsilon = 1e-9); -bool segmentsIntersect(const Vec3D& a1, const Vec3D& a2, const Vec3D& b1, const Vec3D& b2, double epsilon = 1e-9); -double distanceToSegment(const Vec3D& p, const Vec3D& a, const Vec3D& b); -bool segmentIntersectsCircle(const Vec3D& p1, const Vec3D& p2, const Vec3D& center, double radius, double epsilon = 1e-9); -std::pair getTangentPoints(const Vec3D& point, const Vec3D& center, double radius); -double calculateArcLength(const Vec3D& center, double radius, const Vec3D& point1, const Vec3D& point2); - -struct IntersectionInfo { - int pvoIndex{-1}; - const Pvo* pvo{nullptr}; - bool intersects{false}; -}; - -struct BypassPath { - QVector waypoints; - double length{0.0}; -}; - -IntersectionInfo findIntersectingPVO(const Vec3D& p1, const Vec3D& p2, const AirSpace& airspace); -BypassPath calculateCircularBypass(const Vec3D& start, const Vec3D& end, const Vec3D& center, double radius); -double calculateDistanceWithPVO(const Vec3D& p1, const Vec3D& p2, const AirSpace& airspace); - -float* createDistanceMatrix(const AirSpace& airspace); -void deleteDistanceMatrix(float* matrix); - -#endif