Skip to content

Commit

Permalink
Refactor the stc parser
Browse files Browse the repository at this point in the history
- Fix handling of modification of individual RA/Dec coordinates
- Detect cyclic OrbitBarycenter references
- Detect missing magnitude, spectral type when converting Barycenter back to Star
- Fix line number handling in Tokenizer
- Allow Modify to remove OrbitBarycenter if RA/Dec/Position are specified
  • Loading branch information
ajtribick committed Jun 12, 2024
1 parent 9d15060 commit 6a1b6b7
Show file tree
Hide file tree
Showing 12 changed files with 886 additions and 921 deletions.
6 changes: 3 additions & 3 deletions src/celengine/body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,13 @@ float Body::getTemperature(double time) const
}
else // the sun is a barycenter
{
const auto* orbitingStars = sun->getOrbitingStars();
if (orbitingStars == nullptr || orbitingStars->empty())
auto orbitingStars = sun->getOrbitingStars();
if (orbitingStars.empty())
return 0.0f;

const UniversalCoord bodyPos = getPosition(time);
float flux = 0.0f;
for (const auto *s : *orbitingStars)
for (const auto *s : orbitingStars)
{
float distFromSun = (float)s->getPosition(time).distanceFromKm(bodyPos);
float lum = math::square(s->getRadius()) * pow(s->getTemperature(), 4.0f);
Expand Down
20 changes: 9 additions & 11 deletions src/celengine/observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1117,17 +1117,15 @@ static double getPreferredDistance(const Selection& selection)
{
// Handle star system barycenters specially, using the same approach as
// for reference points in solar systems.
const std::vector<Star*>* orbitingStars = selection.star()->getOrbitingStars();
double maxOrbitRadius = orbitingStars == nullptr
? 0.0
: std::accumulate(orbitingStars->begin(), orbitingStars->end(), 0.0,
[](double r, const Star* s)
{
const celestia::ephem::Orbit* orbit = s->getOrbit();
return orbit == nullptr
? r
: std::max(r, orbit->getBoundingRadius());
});
auto orbitingStars = selection.star()->getOrbitingStars();
double maxOrbitRadius = std::accumulate(orbitingStars.begin(), orbitingStars.end(), 0.0,
[](double r, const Star* s)
{
const celestia::ephem::Orbit* orbit = s->getOrbit();
return orbit == nullptr
? r
: std::max(r, orbit->getBoundingRadius());
});

return maxOrbitRadius == 0.0 ? astro::AUtoKilometers(1.0) : maxOrbitRadius * 5.0;
}
Expand Down
Loading

0 comments on commit 6a1b6b7

Please sign in to comment.