Skip to content

Commit

Permalink
added query function
Browse files Browse the repository at this point in the history
  • Loading branch information
karenhaining committed Jul 6, 2022
1 parent 04ebb59 commit 8700009
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/databases.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,23 @@ TrackingSortedDatabase::TrackingSortedDatabase(const unsigned char *buffer) {
}
}

int16_t square(int16_t base) {
return base * base;
}

std::vector<int16_t> TrackingSortedDatabase::QueryNearestStars(const Catalog c, const Vec3 point, int16_t radius) {
std::vector<int16_t> 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)) {

This comment has been minimized.

Copy link
@markasoftware

markasoftware Jul 6, 2022

Member

Subtract vectors and use Vec3::MagnitudeSq instead.

query_ind.push_back(i);
}
}

return query_ind;
}


}

Expand Down
1 change: 1 addition & 0 deletions src/databases.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class TrackingSortedDatabase {
public:
TrackingSortedDatabase(const unsigned char *databaseBytes);
const static int32_t magicValue = 0x2536f0A9;
std::vector<int16_t> QueryNearestStars(const Catalog c, const Vec3 point, int16_t radius);

private:
int16_t length; // length of catalog
Expand Down

0 comments on commit 8700009

Please sign in to comment.