siderust-cpp 0.8.0
Header-only C++ wrapper for siderust
Loading...
Searching...
No Matches
bodies.hpp
Go to the documentation of this file.
1#pragma once
2
8#include "coordinates.hpp"
9#include "ffi_core.hpp"
10#include "orbit.hpp"
11#include <optional>
12#include <string>
13#include <utility>
14
15namespace siderust {
16
17// ============================================================================
18// ProperMotion
19// ============================================================================
20
28
29 siderust_proper_motion_t to_c() const {
30 return {ra.deg_per_day() * 365.25, dec.deg_per_day() * 365.25,
31 static_cast<siderust_ra_convention_t>(convention)};
32 }
33};
34
35struct SolarMass {
36 double value;
37};
38
40 double value;
41};
42
44 double value;
45};
46
53
54// ============================================================================
55// Planet
56// ============================================================================
57
61struct Planet {
62 qtty::Kilogram mass;
63 qtty::Kilometer radius;
65
66 static Planet from_c(const siderust_planet_t &c) {
67 return {qtty::Kilogram(c.mass_kg), qtty::Kilometer(c.radius_km),
68 KeplerianOrbit::from_c(c.orbit)};
69 }
70};
71
72namespace detail {
73
75 siderust_planet_t out;
76 check_status(siderust_planet_mercury(&out), "MERCURY");
77 return Planet::from_c(out);
78}
79
81 siderust_planet_t out;
82 check_status(siderust_planet_venus(&out), "VENUS");
83 return Planet::from_c(out);
84}
85
87 siderust_planet_t out;
88 check_status(siderust_planet_earth(&out), "EARTH");
89 return Planet::from_c(out);
90}
91
93 siderust_planet_t out;
94 check_status(siderust_planet_mars(&out), "MARS");
95 return Planet::from_c(out);
96}
97
99 siderust_planet_t out;
100 check_status(siderust_planet_jupiter(&out), "JUPITER");
101 return Planet::from_c(out);
102}
103
105 siderust_planet_t out;
106 check_status(siderust_planet_saturn(&out), "SATURN");
107 return Planet::from_c(out);
108}
109
111 siderust_planet_t out;
112 check_status(siderust_planet_uranus(&out), "URANUS");
113 return Planet::from_c(out);
114}
115
117 siderust_planet_t out;
118 check_status(siderust_planet_neptune(&out), "NEPTUNE");
119 return Planet::from_c(out);
120}
121
122} // namespace detail
123
124inline const Planet &MERCURY() {
125 static const Planet s = detail::make_planet_mercury();
126 return s;
127}
128inline const Planet &VENUS() {
129 static const Planet s = detail::make_planet_venus();
130 return s;
131}
132inline const Planet &EARTH() {
133 static const Planet s = detail::make_planet_earth();
134 return s;
135}
136inline const Planet &MARS() {
137 static const Planet s = detail::make_planet_mars();
138 return s;
139}
140inline const Planet &JUPITER() {
141 static const Planet s = detail::make_planet_jupiter();
142 return s;
143}
144inline const Planet &SATURN() {
145 static const Planet s = detail::make_planet_saturn();
146 return s;
147}
148inline const Planet &URANUS() {
149 static const Planet s = detail::make_planet_uranus();
150 return s;
151}
152inline const Planet &NEPTUNE() {
153 static const Planet s = detail::make_planet_neptune();
154 return s;
155}
156
157// Backward-compatible function aliases.
158inline Planet mercury() { return MERCURY(); }
159inline Planet venus() { return VENUS(); }
160inline Planet earth() { return EARTH(); }
161inline Planet mars() { return MARS(); }
162inline Planet jupiter() { return JUPITER(); }
163inline Planet saturn() { return SATURN(); }
164inline Planet uranus() { return URANUS(); }
165inline Planet neptune() { return NEPTUNE(); }
166
167// ============================================================================
168// Star (RAII)
169// ============================================================================
170
176class Star {
177 SiderustStar *m_handle = nullptr;
178
179 explicit Star(SiderustStar *h) : m_handle(h) {}
180
181public:
182 Star() = default;
184 if (m_handle)
185 siderust_star_free(m_handle);
186 }
187
188 // Move-only
189 Star(Star &&o) noexcept : m_handle(o.m_handle) { o.m_handle = nullptr; }
190 Star &operator=(Star &&o) noexcept {
191 if (this != &o) {
192 if (m_handle)
193 siderust_star_free(m_handle);
194 m_handle = o.m_handle;
195 o.m_handle = nullptr;
196 }
197 return *this;
198 }
199 Star(const Star &) = delete;
200 Star &operator=(const Star &) = delete;
201
203 explicit operator bool() const { return m_handle != nullptr; }
204
206 const SiderustStar *c_handle() const { return m_handle; }
207
208 // -- Factory methods --
209
216 static Star catalog(const std::string &name) {
217 SiderustStar *h = nullptr;
218 check_status(siderust_star_catalog(name.c_str(), &h), "Star::catalog");
219 return Star(h);
220 }
221
231 static Star create(std::string name, StellarProperties properties,
233 std::optional<ProperMotion> pm = std::nullopt) {
234 SiderustStar *h = nullptr;
235 const siderust_proper_motion_t *pm_ptr = nullptr;
236 siderust_proper_motion_t pm_c{};
237 if (pm.has_value()) {
238 pm_c = pm->to_c();
239 pm_ptr = &pm_c;
240 }
241 check_status(siderust_star_create(name.c_str(), properties.distance.value(),
242 properties.mass.value, properties.radius.value,
243 properties.luminosity.value, position.ra().value(),
244 position.dec().value(), epoch.value(), pm_ptr, &h),
245 "Star::create");
246 return Star(h);
247 }
248
249 // -- Accessors --
250
251 std::string name() const {
252 char buf[256];
253 uintptr_t written = 0;
254 check_status(siderust_star_name(m_handle, buf, sizeof(buf), &written), "Star::name");
255 return std::string(buf, written);
256 }
257
258 double distance_ly() const { return siderust_star_distance_ly(m_handle); }
259 double mass_solar() const { return siderust_star_mass_solar(m_handle); }
260 double radius_solar() const { return siderust_star_radius_solar(m_handle); }
261 double luminosity_solar() const { return siderust_star_luminosity_solar(m_handle); }
262};
263
264inline const Star &VEGA() {
265 static const Star s = Star::catalog("VEGA");
266 return s;
267}
268inline const Star &SIRIUS() {
269 static const Star s = Star::catalog("SIRIUS");
270 return s;
271}
272inline const Star &POLARIS() {
273 static const Star s = Star::catalog("POLARIS");
274 return s;
275}
276inline const Star &CANOPUS() {
277 static const Star s = Star::catalog("CANOPUS");
278 return s;
279}
280inline const Star &ARCTURUS() {
281 static const Star s = Star::catalog("ARCTURUS");
282 return s;
283}
284inline const Star &RIGEL() {
285 static const Star s = Star::catalog("RIGEL");
286 return s;
287}
288inline const Star &BETELGEUSE() {
289 static const Star s = Star::catalog("BETELGEUSE");
290 return s;
291}
292inline const Star &PROCYON() {
293 static const Star s = Star::catalog("PROCYON");
294 return s;
295}
296inline const Star &ALDEBARAN() {
297 static const Star s = Star::catalog("ALDEBARAN");
298 return s;
299}
300inline const Star &ALTAIR() {
301 static const Star s = Star::catalog("ALTAIR");
302 return s;
303}
304
305} // namespace siderust
RAII handle to a Star (opaque Rust object).
Definition bodies.hpp:176
Star & operator=(const Star &)=delete
Star & operator=(Star &&o) noexcept
Definition bodies.hpp:190
Star()=default
Star(Star &&o) noexcept
Definition bodies.hpp:189
double mass_solar() const
Definition bodies.hpp:259
static Star create(std::string name, StellarProperties properties, spherical::direction::ICRS position, Time< TT, JD > epoch, std::optional< ProperMotion > pm=std::nullopt)
Create a custom star.
Definition bodies.hpp:231
const SiderustStar * c_handle() const
Access the raw C handle (for passing to altitude functions).
Definition bodies.hpp:206
double distance_ly() const
Definition bodies.hpp:258
Star(const Star &)=delete
static Star catalog(const std::string &name)
Look up a star from the built-in catalog.
Definition bodies.hpp:216
double luminosity_solar() const
Definition bodies.hpp:261
std::string name() const
Definition bodies.hpp:251
double radius_solar() const
Definition bodies.hpp:260
Coordinate module umbrella.
Error handling and utility base for the siderust C++ wrapper.
Planet make_planet_uranus()
Definition bodies.hpp:110
Planet make_planet_earth()
Definition bodies.hpp:86
Planet make_planet_saturn()
Definition bodies.hpp:104
Planet make_planet_mars()
Definition bodies.hpp:92
Planet make_planet_mercury()
Definition bodies.hpp:74
Planet make_planet_jupiter()
Definition bodies.hpp:98
Planet make_planet_neptune()
Definition bodies.hpp:116
Planet make_planet_venus()
Definition bodies.hpp:80
tempoch::EncodedTime< Scale, Format > Time
Definition time.hpp:36
const Star & ARCTURUS()
Definition bodies.hpp:280
const Star & SIRIUS()
Definition bodies.hpp:268
const Star & BETELGEUSE()
Definition bodies.hpp:288
const Star & ALDEBARAN()
Definition bodies.hpp:296
Planet jupiter()
Definition bodies.hpp:162
const Star & POLARIS()
Definition bodies.hpp:272
void check_status(siderust_status_t status, const char *operation)
Definition ffi_core.hpp:111
const Star & CANOPUS()
Definition bodies.hpp:276
Planet uranus()
Definition bodies.hpp:164
const Planet & MARS()
Definition bodies.hpp:136
Planet mercury()
Definition bodies.hpp:158
const Planet & NEPTUNE()
Definition bodies.hpp:152
const Star & VEGA()
Definition bodies.hpp:264
const Planet & URANUS()
Definition bodies.hpp:148
const Star & RIGEL()
Definition bodies.hpp:284
const Planet & EARTH()
Definition bodies.hpp:132
const Star & PROCYON()
Definition bodies.hpp:292
const Planet & MERCURY()
Definition bodies.hpp:124
Planet venus()
Definition bodies.hpp:159
const Planet & SATURN()
Definition bodies.hpp:144
const Planet & JUPITER()
Definition bodies.hpp:140
const Star & ALTAIR()
Definition bodies.hpp:300
Planet neptune()
Definition bodies.hpp:165
Planet earth()
Definition bodies.hpp:160
Planet saturn()
Definition bodies.hpp:163
const Planet & VENUS()
Definition bodies.hpp:128
Planet mars()
Definition bodies.hpp:161
Orbit model wrappers and propagation helpers.
double deg_per_day() const
Definition orbit.hpp:49
static KeplerianOrbit from_c(const siderust_orbit_t &c)
Definition orbit.hpp:61
Planet data (value type, copyable).
Definition bodies.hpp:61
qtty::Kilometer radius
Mean equatorial radius.
Definition bodies.hpp:63
KeplerianOrbit orbit
Definition bodies.hpp:64
qtty::Kilogram mass
Planet mass.
Definition bodies.hpp:62
static Planet from_c(const siderust_planet_t &c)
Definition bodies.hpp:66
Proper motion for a star (equatorial).
Definition bodies.hpp:24
AngularRate ra
RA proper motion.
Definition bodies.hpp:25
AngularRate dec
Dec proper motion.
Definition bodies.hpp:26
RaConvention convention
RA rate convention.
Definition bodies.hpp:27
siderust_proper_motion_t to_c() const
Definition bodies.hpp:29
SolarLuminosity luminosity
Definition bodies.hpp:51
qtty::LightYear distance
Definition bodies.hpp:48
A direction on the celestial sphere, compile-time tagged by frame.
Definition spherical.hpp:50
qtty::Degree dec() const
Definition spherical.hpp:76
qtty::Degree ra() const
Definition spherical.hpp:71