Skip to content

Commit

Permalink
Rename astro namespace to celestia::astro
Browse files Browse the repository at this point in the history
- Tidy up includes in astro.h/astro.cpp
- Replace snprintf with fmt in astro.cpp
  • Loading branch information
ajtribick committed Oct 18, 2023
1 parent 3ab9579 commit 1456261
Show file tree
Hide file tree
Showing 67 changed files with 766 additions and 625 deletions.
487 changes: 280 additions & 207 deletions src/celengine/astro.cpp

Large diffs are not rendered by default.

544 changes: 282 additions & 262 deletions src/celengine/astro.h

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/celengine/body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ using namespace Eigen;
using namespace std;
using namespace celmath;

namespace astro = celestia::astro;


Body::Body(PlanetarySystem* _system, const std::string& _name) :
system(_system),
Expand Down
4 changes: 2 additions & 2 deletions src/celengine/boundaries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ ReadBoundaries(std::istream& in)
currentChain.clear();
}

currentChain.emplace_back(astro::equatorialToCelestialCart(ra, dec,
BoundariesDrawDistance));
currentChain.emplace_back(celestia::astro::equatorialToCelestialCart(ra, dec,
BoundariesDrawDistance));
}

if (currentChain.size() > 1)
Expand Down
2 changes: 2 additions & 0 deletions src/celengine/dateformatter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include <celutil/gettext.h>
#endif

namespace astro = celestia::astro;

namespace celestia::engine
{

Expand Down
8 changes: 4 additions & 4 deletions src/celengine/dateformatter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ class DateFormatter
DateFormatter &operator=(const DateFormatter &) = delete;
DateFormatter &operator=(DateFormatter &&) = delete;

std::string formatDate(double tdb, bool local, astro::Date::Format format);
std::string formatDate(double tdb, bool local, celestia::astro::Date::Format format);

#ifdef USE_ICU
private:
std::array<UDateFormat*, static_cast<size_t>(astro::Date::FormatCount)> localFormatters;
std::array<UDateFormat*, static_cast<size_t>(astro::Date::FormatCount)> utcFormatters;
std::array<UDateFormat*, static_cast<size_t>(celestia::astro::Date::FormatCount)> localFormatters;
std::array<UDateFormat*, static_cast<size_t>(celestia::astro::Date::FormatCount)> utcFormatters;

UDateFormat *getFormatter(bool local, astro::Date::Format format);
UDateFormat *getFormatter(bool local, celestia::astro::Date::Format format);
#endif
};

Expand Down
11 changes: 7 additions & 4 deletions src/celengine/deepskyobj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
#include "astro.h"
#include "hash.h"

namespace astro = celestia::astro;


Eigen::Vector3d DeepSkyObject::getPosition() const
{
return position;
Expand Down Expand Up @@ -86,14 +89,14 @@ bool DeepSkyObject::pick(const Eigen::ParametrizedLine<double, 3>& ray,
bool DeepSkyObject::load(const AssociativeArray* params, const fs::path& resPath)
{
// Get position
if (auto position = params->getLengthVector<double>("Position", KM_PER_LY<double>); position.has_value())
if (auto position = params->getLengthVector<double>("Position", astro::KM_PER_LY<double>); position.has_value())
{
setPosition(*position);
}
else
{
auto distance = params->getLength<double>("Distance", KM_PER_LY<double>).value_or(1.0);
auto RA = params->getAngle<double>("RA", DEG_PER_HRA).value_or(0.0);
auto distance = params->getLength<double>("Distance", astro::KM_PER_LY<double>).value_or(1.0);
auto RA = params->getAngle<double>("RA", astro::DEG_PER_HRA).value_or(0.0);
auto dec = params->getAngle<double>("Dec").value_or(0.0);

Eigen::Vector3d p = astro::equatorialToCelestialCart(RA, dec, distance);
Expand All @@ -107,7 +110,7 @@ bool DeepSkyObject::load(const AssociativeArray* params, const fs::path& resPath
setOrientation(Eigen::Quaternionf(Eigen::AngleAxisf(static_cast<float>(celmath::degToRad(angle)),
axis.cast<float>().normalized())));

setRadius(params->getLength<float>("Radius", KM_PER_LY<double>).value_or(1.0f));
setRadius(params->getLength<float>("Radius", astro::KM_PER_LY<double>).value_or(1.0f));

if (auto absMagValue = params->getNumber<float>("AbsMag"); absMagValue.has_value())
setAbsoluteMagnitude(*absMagValue);
Expand Down
3 changes: 2 additions & 1 deletion src/celengine/dsodb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <cmath>
#include <utility>

#include <celcompat/numbers.h>
#include <celutil/gettext.h>
#include <celutil/logger.h>
#include <celutil/tokenizer.h>
Expand Down Expand Up @@ -336,7 +337,7 @@ void DSODatabase::finish()
void DSODatabase::buildOctree()
{
GetLogger()->debug("Sorting DSOs into octree . . .\n");
float absMag = astro::appToAbsMag(DSO_OCTREE_MAGNITUDE, DSO_OCTREE_ROOT_SIZE * (float) sqrt(3.0));
float absMag = celestia::astro::appToAbsMag(DSO_OCTREE_MAGNITUDE, DSO_OCTREE_ROOT_SIZE * celestia::numbers::sqrt3_v<float>);

// TODO: investigate using a different center--it's possible that more
// objects end up straddling the base level nodes when the center of the
Expand Down
8 changes: 4 additions & 4 deletions src/celengine/dsooctree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void DSOOctree::processVisibleObjects(DSOHandler& processor,
double minDistance = (obsPosition - cellCenterPos).norm() - scale * DSOOctree::SQRT3;

// Process the objects in this node
double dimmest = minDistance > 0.0 ? astro::appToAbsMag((double) limitingFactor, minDistance) : 1000.0;
double dimmest = minDistance > 0.0 ? celestia::astro::appToAbsMag((double) limitingFactor, minDistance) : 1000.0;

for (unsigned int i=0; i<nObjects; ++i)
{
Expand All @@ -113,16 +113,16 @@ void DSOOctree::processVisibleObjects(DSOHandler& processor,
if (absMag < dimmest)
{
double distance = (obsPosition - _obj->getPosition()).norm() - _obj->getBoundingSphereRadius();
float appMag = (float) ((distance >= 32.6167) ? astro::absToAppMag((double) absMag, distance) : absMag);
float appMag = (float) ((distance >= 32.6167) ? celestia::astro::absToAppMag((double) absMag, distance) : absMag);

if ( appMag < limitingFactor)
if (appMag < limitingFactor)
processor.process(_obj, distance, absMag);
}
}

// See if any of the objects in child nodes are potentially included
// that we need to recurse deeper.
if (minDistance <= 0.0 || astro::absToAppMag((double) exclusionFactor, minDistance) <= limitingFactor)
if (minDistance <= 0.0 || celestia::astro::absToAppMag((double) exclusionFactor, minDistance) <= limitingFactor)
{
// Recurse into the child nodes
if (_children != nullptr)
Expand Down
6 changes: 3 additions & 3 deletions src/celengine/dsorenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void DSORenderer::process(DeepSkyObject* const &dso,

float appMag;
if (distanceToDSO >= pc10)
appMag = (float) astro::absToAppMag((double) absMag, distanceToDSO);
appMag = (float) celestia::astro::absToAppMag((double) absMag, distanceToDSO);
else
appMag = absMag + (float) (enhance * tanh(distanceToDSO/pc10 - 1.0));

Expand Down Expand Up @@ -145,14 +145,14 @@ void DSORenderer::process(DeepSkyObject* const &dso,
case Renderer::NebulaLabels:
rep = &renderer->nebulaRep;
labelColor = Renderer::NebulaLabelColor;
appMagEff = astro::absToAppMag(-7.5f, (float)distanceToDSO);
appMagEff = celestia::astro::absToAppMag(-7.5f, (float)distanceToDSO);
symbolSize = (float)(dso->getRadius() / distanceToDSO) / pixelSize;
step = 6.0f;
break;
case Renderer::OpenClusterLabels:
rep = &renderer->openClusterRep;
labelColor = Renderer::OpenClusterLabelColor;
appMagEff = astro::absToAppMag(-6.0f, (float)distanceToDSO);
appMagEff = celestia::astro::absToAppMag(-6.0f, (float)distanceToDSO);
symbolSize = (float)(dso->getRadius() / distanceToDSO) / pixelSize;
step = 4.0f;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/celengine/frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ J2000EquatorFrame::J2000EquatorFrame(Selection center) :
Quaterniond
J2000EquatorFrame::getOrientation(double /* tjd */) const
{
return Quaterniond(AngleAxis<double>(astro::J2000Obliquity, Vector3d::UnitX()));
return Quaterniond(AngleAxis<double>(celestia::astro::J2000Obliquity, Vector3d::UnitX()));
}


Expand Down Expand Up @@ -344,7 +344,7 @@ BodyMeanEquatorFrame::BodyMeanEquatorFrame(Selection center,
Selection obj) :
ReferenceFrame(center),
equatorObject(obj),
freezeEpoch(astro::J2000),
freezeEpoch(celestia::astro::J2000),
isFrozen(false)
{
}
Expand Down
5 changes: 4 additions & 1 deletion src/celengine/globular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ bool Globular::load(const AssociativeArray* params, const fs::path& resPath)
if (auto detailVal = params->getNumber<float>("Detail"); detailVal.has_value())
detail = *detailVal;

if (auto coreRadius = params->getAngle<float>("CoreRadius", 1.0 / MINUTES_PER_DEG); coreRadius.has_value())
if (auto coreRadius = params->getAngle<float>("CoreRadius", 1.0 / celestia::astro::MINUTES_PER_DEG);
coreRadius.has_value())
{
r_c = *coreRadius;
}

if (auto king = params->getNumber<float>("KingConcentration"); king.has_value())
c = *king;
Expand Down
1 change: 1 addition & 0 deletions src/celengine/hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "hash.h"
#include "value.h"

namespace astro = celestia::astro;
namespace celutil = celestia::util;


Expand Down
9 changes: 2 additions & 7 deletions src/celengine/observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,14 +569,9 @@ void Observer::computeGotoParameters(const Selection& destination,
ObserverFrame::CoordinateSystem upCoordSys)
{
if (frame->getCoordinateSystem() == ObserverFrame::PhaseLock)
{
//setFrame(FrameOfReference(astro::Ecliptical, destination));
setFrame(ObserverFrame::Ecliptical, destination);
}
else
{
setFrame(frame->getCoordinateSystem(), destination);
}

UniversalCoord targetPosition = destination.getPosition(getTime());
//Vector3d v = targetPosition.offsetFromKm(getPosition()).normalized();
Expand Down Expand Up @@ -1026,7 +1021,7 @@ static double getPreferredDistance(const Selection& selection)
double r = selection.body()->getRadius();
if (selection.body()->getFrameTree() != nullptr)
r = selection.body()->getFrameTree()->boundingSphereRadius();
return min(astro::lightYearsToKilometers(0.1), r * 5.0);
return min(celestia::astro::lightYearsToKilometers(0.1), r * 5.0);
}
else
{
Expand Down Expand Up @@ -1055,7 +1050,7 @@ static double getPreferredDistance(const Selection& selection)
: std::max(r, orbit->getBoundingRadius());
});

return maxOrbitRadius == 0.0 ? astro::AUtoKilometers(1.0) : maxOrbitRadius * 5.0;
return maxOrbitRadius == 0.0 ? celestia::astro::AUtoKilometers(1.0) : maxOrbitRadius * 5.0;
}

case SelectionType::Location:
Expand Down
15 changes: 8 additions & 7 deletions src/celengine/parseobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ using celestia::ephem::TrajectoryInterpolation;
using celestia::ephem::TrajectoryPrecision;
using celestia::util::GetLogger;

namespace astro = celestia::astro;
namespace celephem = celestia::ephem;

/**
Expand All @@ -57,8 +58,8 @@ GetDefaultUnits(bool usePlanetUnits, double& distanceScale, double& timeScale)
{
if(usePlanetUnits)
{
distanceScale = KM_PER_AU<double>;
timeScale = DAYS_PER_YEAR;
distanceScale = astro::KM_PER_AU<double>;
timeScale = astro::DAYS_PER_YEAR;
}
else
{
Expand All @@ -80,7 +81,7 @@ GetDefaultUnits(bool usePlanetUnits, double& distanceScale, double& timeScale)
static void
GetDefaultUnits(bool usePlanetUnits, double& distanceScale)
{
distanceScale = usePlanetUnits ? KM_PER_AU<double> : 1.0;
distanceScale = usePlanetUnits ? astro::KM_PER_AU<double> : 1.0;
}


Expand Down Expand Up @@ -599,7 +600,7 @@ CreateSpiceRotation(const Hash* rotationData,
// The period of the rotation may be specified if appropriate; a value
// of zero for the period (the default), means that the rotation will
// be considered aperiodic.
auto period = rotationData->getTime<double>("Period", 1.0, 1.0 / HOURS_PER_DAY).value_or(0.0);
auto period = rotationData->getTime<double>("Period", 1.0, 1.0 / astro::HOURS_PER_DAY).value_or(0.0);

// Either a complete time interval must be specified with Beginning/Ending, or
// else neither field can be present.
Expand Down Expand Up @@ -855,7 +856,7 @@ CreateUniformRotationModel(const Hash* rotationData,
double syncRotationPeriod)
{
// Default to synchronous rotation
auto period = rotationData->getTime<double>("Period", 1.0, 1.0 / HOURS_PER_DAY).value_or(syncRotationPeriod);
auto period = rotationData->getTime<double>("Period", 1.0, 1.0 / astro::HOURS_PER_DAY).value_or(syncRotationPeriod);

auto offset = degToRad(rotationData->getAngle<double>("MeridianAngle").value_or(0.0));

Expand Down Expand Up @@ -919,7 +920,7 @@ CreatePrecessingRotationModel(const Hash* rotationData,
double syncRotationPeriod)
{
// Default to synchronous rotation
double period = rotationData->getTime<double>("Period", 1.0, 1.0 / HOURS_PER_DAY).value_or(syncRotationPeriod);
double period = rotationData->getTime<double>("Period", 1.0, 1.0 / astro::HOURS_PER_DAY).value_or(syncRotationPeriod);

auto offset = degToRad(rotationData->getAngle<double>("MeridianAngle").value_or(0.0));

Expand All @@ -931,7 +932,7 @@ CreatePrecessingRotationModel(const Hash* rotationData,

// The default value of 0 is handled specially, interpreted to indicate
// that there's no precession.
auto precessionPeriod = rotationData->getTime<double>("PrecessionPeriod", 1.0, DAYS_PER_YEAR).value_or(0.0);
auto precessionPeriod = rotationData->getTime<double>("PrecessionPeriod", 1.0, astro::DAYS_PER_YEAR).value_or(0.0);


// No period was specified, and the default synchronous
Expand Down
2 changes: 2 additions & 0 deletions src/celengine/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

using namespace std::string_view_literals;

namespace astro = celestia::astro;


namespace
{
Expand Down
2 changes: 1 addition & 1 deletion src/celengine/planetgrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ PlanetographicGrid::setIAULongLatConvention()
}
else
{
if (body.getAngularVelocity(astro::J2000).y() >= 0.0)
if (body.getAngularVelocity(celestia::astro::J2000).y() >= 0.0)
{
northDirection = NorthNormal;
longitudeConvention = Westward;
Expand Down
6 changes: 3 additions & 3 deletions src/celengine/pointstarrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ void PointStarRenderer::process(const Star& star, float distance, float appMag)
Vector3d hPos = astrocentricPosition(observer->getPosition(),
star,
observer->getTime());
relPos = hPos.cast<float>() * -astro::kilometersToLightYears(1.0f);
relPos = hPos.cast<float>() * -celestia::astro::kilometersToLightYears(1.0f);
distance = relPos.norm();

// Recompute apparent magnitude using new distance computation
appMag = star.getApparentMagnitude(distance);

discSizeInPixels = star.getRadius() / astro::lightYearsToKilometers(distance) / pixelSize;
discSizeInPixels = star.getRadius() / celestia::astro::lightYearsToKilometers(distance) / pixelSize;
}

// Stars closer than the maximum solar system size are actually
Expand Down Expand Up @@ -134,7 +134,7 @@ void PointStarRenderer::process(const Star& star, float distance, float appMag)
// Objects in the render list are always rendered relative to
// a viewer at the origin--this is different than for distant
// stars.
float scale = astro::lightYearsToKilometers(1.0f);
float scale = celestia::astro::lightYearsToKilometers(1.0f);
rle.position = relPos * scale;
rle.centerZ = rle.position.dot(viewMatZ);
rle.distance = rle.position.norm();
Expand Down
3 changes: 3 additions & 0 deletions src/celengine/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ using namespace celestia::engine;
using namespace celestia::render;
using celestia::util::GetLogger;

namespace astro = celestia::astro;


#define NEAR_DIST 0.5f
#define FAR_DIST 1.0e9f

Expand Down
2 changes: 1 addition & 1 deletion src/celengine/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Selection::radius() const
case SelectionType::Body:
return static_cast<const Body*>(obj)->getRadius();
case SelectionType::DeepSky:
return astro::lightYearsToKilometers(static_cast<const DeepSkyObject*>(obj)->getRadius());
return celestia::astro::lightYearsToKilometers(static_cast<const DeepSkyObject*>(obj)->getRadius());
case SelectionType::Location:
// The size of a location is its diameter, so divide by 2.
return static_cast<const Location*>(obj)->getSize() / 2.0f;
Expand Down
Loading

0 comments on commit 1456261

Please sign in to comment.