diff --git a/src/databases.cpp b/src/databases.cpp index 57044c45..92f5c0a8 100644 --- a/src/databases.cpp +++ b/src/databases.cpp @@ -373,6 +373,23 @@ TrackingSortedDatabase::TrackingSortedDatabase(const unsigned char *buffer) { } } +int16_t square(int16_t base) { + return base * base; +} + +std::vector TrackingSortedDatabase::QueryNearestStars(const Catalog c, const Vec3 point, int16_t radius) { + std::vector query_ind; + + for (int i = 0; i < indices.size(); i++) { + CatalogStar s = c[i]; + if (square(s.spatial.x - point.x) + square(s.spatial.y - point.y) + square(s.spatial.z - point.z) <= square(radius)) { + query_ind.push_back(i); + } + } + + return query_ind; +} + } diff --git a/src/databases.hpp b/src/databases.hpp index 512ad95d..e9cf4689 100644 --- a/src/databases.hpp +++ b/src/databases.hpp @@ -89,6 +89,7 @@ class TrackingSortedDatabase { public: TrackingSortedDatabase(const unsigned char *databaseBytes); const static int32_t magicValue = 0x2536f0A9; + std::vector QueryNearestStars(const Catalog c, const Vec3 point, int16_t radius); private: int16_t length; // length of catalog