Fix broken star browser

pull/1347/head
Levin Li 2022-02-09 21:20:32 +08:00
parent e51f3d5b97
commit 23b75cca63
1 changed files with 13 additions and 33 deletions

View File

@ -17,59 +17,43 @@
using namespace Eigen; using namespace Eigen;
using namespace std; using namespace std;
// TODO: More of the functions in this module should be converted to
// methods of the StarBrowser class.
struct CloserStarPredicate struct CloserStarPredicate
{ {
Vector3f pos; Vector3f pos;
bool operator()(const Star* star0, const Star* star1) const bool operator()(const Star* star0, const Star* star1) const
{ {
Vector3f p0 = star0->getPosition(); return (pos - star0->getPosition()).squaredNorm() < (pos - star1->getPosition()).squaredNorm();
Vector3f p1 = star1->getPosition();
#if 0
Vector3f v0(p0.x * 1e6 - pos.x, p0.y * 1e6 - pos.y, p0.z * 1e6 - pos.z);
Vector3f v1(p1.x * 1e6 - pos.x, p1.y * 1e6 - pos.y, p1.z * 1e6 - pos.z);
#endif
Vector3f v0 = p0 * 1.0e6f - pos;
Vector3f v1 = p1 * 1.0e6f - pos;
return (v0.squaredNorm() < v1.squaredNorm());
} }
}; };
struct BrighterStarPredicate struct BrighterStarPredicate
{ {
Vector3f pos; Vector3f pos;
UniversalCoord ucPos; UniversalCoord ucPos;
bool operator()(const Star* star0, const Star* star1) const bool operator()(const Star* star0, const Star* star1) const
{ {
Vector3f p0 = star0->getPosition(); float d0 = (pos - star0->getPosition()).norm();
Vector3f p1 = star1->getPosition(); float d1 = (pos - star1->getPosition()).norm();
Vector3f v0 = p0 * 1.0e6f - pos;
Vector3f v1 = p1 * 1.0e6f - pos;
float d0 = v0.norm();
float d1 = v1.norm();
return (star0->getApparentMagnitude(d0) < // If the stars are closer than one light year, use
star1->getApparentMagnitude(d1)); // a more precise distance estimate.
if (d0 < 1.0f)
d0 = ucPos.offsetFromLy(star0->getPosition()).norm();
if (d1 < 1.0f)
d1 = ucPos.offsetFromLy(star1->getPosition()).norm();
return star0->getApparentMagnitude(d0) < star1->getApparentMagnitude(d1);
} }
}; };
struct BrightestStarPredicate struct BrightestStarPredicate
{ {
bool operator()(const Star* star0, const Star* star1) const bool operator()(const Star* star0, const Star* star1) const
{ {
return (star0->getAbsoluteMagnitude() < return star0->getAbsoluteMagnitude() < star1->getAbsoluteMagnitude();
star1->getAbsoluteMagnitude());
} }
}; };
struct SolarSystemPredicate struct SolarSystemPredicate
{ {
Vector3f pos; Vector3f pos;
@ -85,11 +69,7 @@ struct SolarSystemPredicate
bool hasPlanets1 = (iter != solarSystems->end()); bool hasPlanets1 = (iter != solarSystems->end());
if (hasPlanets1 == hasPlanets0) if (hasPlanets1 == hasPlanets0)
{ {
Vector3f p0 = star0->getPosition(); return ((pos - star0->getPosition()).squaredNorm() < (pos - star1->getPosition()).squaredNorm());
Vector3f p1 = star1->getPosition();
Vector3f v0 = p0 * 1.0e6f - pos;
Vector3f v1 = p1 * 1.0e6f - pos;
return (v0.squaredNorm() < v1.squaredNorm());
} }
else else
{ {