19 for (
int i = 0; i < (int)catalog.size(); i++) {
20 if (catalog[i].magnitude <= maxMagnitude) {
21 result.push_back(catalog[i]);
26 std::set<int> tooCloseIndices;
29 for (
int i = 0; i < (int)result.size(); i++) {
30 for (
int j = i+1; j < (int)result.size(); j++) {
31 if (
AngleUnit(result[i].spatial, result[j].spatial) < minSeparation) {
32 tooCloseIndices.insert(i);
33 tooCloseIndices.insert(j);
40 for (
auto it = tooCloseIndices.rbegin(); it != tooCloseIndices.rend(); it++) {
41 result.erase(result.begin() + *it);
45 if (maxStars < (
int)result.size()) {
47 result.resize(maxStars);
55 for (
auto it = catalog.cbegin(); it != catalog.cend(); ++it) {
56 if (it->name == name) {
60 return catalog.cend();
73 SerializePrimitive<decimal>(ser, catalogStar.
magnitude);
77 SerializePrimitive<int16_t>(ser, catalogStar.
name);
90 result.
magnitude = DeserializePrimitive<decimal>(des);
95 result.
name = DeserializePrimitive<int16_t>(des);
108 SerializePrimitive<int16_t>(ser, catalog.size());
111 int8_t flags = (inclMagnitude) | (inclName << 1);
112 SerializePrimitive<int8_t>(ser, flags);
124 bool inclName, inclMagnitude;
127 int16_t numStars = DeserializePrimitive<int16_t>(des);
129 int8_t flags = DeserializePrimitive<int8_t>(des);
130 inclMagnitude = (flags) & 1;
131 inclName = (flags>>1) & 1;
133 if (inclMagnitudeReturn != NULL) {
134 *inclMagnitudeReturn = inclMagnitude;
136 if (inclNameReturn != NULL) {
137 *inclNameReturn = inclName;
140 for (
int i = 0; i < numStars; i++) {
A star from the Bright Star Catalog.
int name
A unique number which unambiguously identifies the catalog star.
int magnitude
The magnitude of the star, with the decimal point shifted two places right.
Vec3 spatial
The point on the unit sphere where the star lies.
#define DECIMAL_POW(base, power)
void SerializeCatalogStar(SerializeContext *ser, const CatalogStar &catalogStar, bool inclMagnitude, bool inclName)
Serialize a CatalogStar into a byte buffer.
void SerializeCatalog(SerializeContext *ser, const Catalog &catalog, bool inclMagnitude, bool inclName)
Serialize the catalog to buffer.
Catalog DeserializeCatalog(DeserializeContext *des, bool *inclMagnitudeReturn, bool *inclNameReturn)
Deserialize a catalog.
decimal MagToBrightness(int mag)
returns some relative brightness measure, which is proportional to the total number of photons receiv...
decimal AngleUnit(const Vec3 &vec1, const Vec3 &vec2)
Calculate the inner angle, in radians, between two /unit/ vectors.
bool CatalogStarMagnitudeCompare(const CatalogStar &a, const CatalogStar &b)
CatalogStar DeserializeCatalogStar(DeserializeContext *des, bool inclMagnitude, bool inclName)
Deserialize a catalog star.
Catalog NarrowCatalog(const Catalog &catalog, int maxMagnitude, int maxStars, decimal minSeparation)
Remove unwanted stars from an unfiltered catalog.
void SerializeVec3(SerializeContext *ser, const Vec3 &vec)
Serialize a Vec3 to buffer. Takes up space according to SerializeLengthVec3.
Vec3 DeserializeVec3(DeserializeContext *des)
Catalog::const_iterator FindNamedStar(const Catalog &catalog, int name)
Return a pointer to the star with the given name, or NULL if not found.
std::vector< CatalogStar > Catalog