Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 51ea9353042e
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b8d380d8273c
Choose a head ref
  • 7 commits
  • 2 files changed
  • 1 contributor

Commits on Nov 26, 2020

  1. Copy the full SHA
    834c4f6 View commit details
  2. merge

    eggrobin committed Nov 26, 2020
    Copy the full SHA
    3d1023e View commit details

Commits on Nov 27, 2020

  1. Copy the full SHA
    e0a32bd View commit details
  2. factor more

    eggrobin committed Nov 27, 2020
    Copy the full SHA
    639b6d2 View commit details
  3. unused using

    eggrobin committed Nov 27, 2020
    Copy the full SHA
    783301a View commit details
  4. * const

    eggrobin committed Nov 27, 2020
    Copy the full SHA
    e4fd3e1 View commit details
  5. Merge pull request #2798 from eggrobin/orbit-analyser

    Factor out the OrbitAnalyser::Analysis to OrbitAnalysis conversion
    eggrobin authored Nov 27, 2020
    Copy the full SHA
    b8d380d View commit details
Showing with 94 additions and 81 deletions.
  1. +89 −0 ksp_plugin/interface_body.hpp
  2. +5 −81 ksp_plugin/interface_vessel.cpp
89 changes: 89 additions & 0 deletions ksp_plugin/interface_body.hpp
Original file line number Diff line number Diff line change
@@ -533,6 +533,95 @@ Interval ToInterval(geometry::Interval<T> const& interval) {
interval.max / quantities::si::Unit<T>};
}

// Ownership is returned to the caller. Note that the result may own additional
// objects via C pointers; it must be not be deleted from C++, and must instead
// be passed to the generated C# marshaller, which will properly delete it.
inline not_null<OrbitAnalysis*> NewOrbitAnalysis(
ksp_plugin::OrbitAnalyser::Analysis* const vessel_analysis,
ksp_plugin::Plugin const& plugin,
int const* const revolutions_per_cycle,
int const* const days_per_cycle,
int const ground_track_revolution) {
auto* const analysis = new OrbitAnalysis{};
CHECK_EQ(revolutions_per_cycle == nullptr, days_per_cycle == nullptr);
bool const has_nominal_recurrence = revolutions_per_cycle != nullptr;
if (has_nominal_recurrence) {
CHECK_GT(*revolutions_per_cycle, 0);
CHECK_NE(*days_per_cycle, 0);
}
if (vessel_analysis == nullptr) {
return analysis;
}
analysis->primary_index =
vessel_analysis->primary() == nullptr
? nullptr
: new int(plugin.CelestialIndexOfBody(*vessel_analysis->primary()));

analysis->mission_duration = vessel_analysis->mission_duration() / Second;
if (vessel_analysis->elements().has_value()) {
auto const& elements = *vessel_analysis->elements();
analysis->elements = new OrbitalElements{
.sidereal_period = elements.sidereal_period() / Second,
.nodal_period = elements.nodal_period() / Second,
.anomalistic_period = elements.anomalistic_period() / Second,
.nodal_precession = elements.nodal_precession() / (Radian / Second),
.mean_semimajor_axis =
ToInterval(elements.mean_semimajor_axis_interval()),
.mean_eccentricity = ToInterval(elements.mean_eccentricity_interval()),
.mean_inclination = ToInterval(elements.mean_inclination_interval()),
.mean_longitude_of_ascending_nodes =
ToInterval(elements.mean_longitude_of_ascending_node_interval()),
.mean_argument_of_periapsis =
ToInterval(elements.mean_argument_of_periapsis_interval()),
.mean_periapsis_distance =
ToInterval(elements.mean_periapsis_distance_interval()),
.mean_apoapsis_distance =
ToInterval(elements.mean_apoapsis_distance_interval()),
.radial_distance = ToInterval(elements.radial_distance_interval()),
};
}
if (has_nominal_recurrence && vessel_analysis->primary() != nullptr) {
int const Cᴛₒ =
geometry::Sign(vessel_analysis->primary()->angular_frequency()) *
std::abs(*days_per_cycle);
int const νₒ =
std::nearbyint(static_cast<double>(*revolutions_per_cycle) / Cᴛₒ);
int const Dᴛₒ = *revolutions_per_cycle - νₒ * Cᴛₒ;
int const gcd = std::gcd(Dᴛₒ, Cᴛₒ);
vessel_analysis->SetRecurrence({νₒ, Dᴛₒ / gcd, Cᴛₒ / gcd});
} else {
vessel_analysis->ResetRecurrence();
}
if (vessel_analysis->recurrence().has_value()) {
auto const& recurrence = *vessel_analysis->recurrence();
analysis->recurrence = new OrbitRecurrence{
.nuo = recurrence.νₒ(),
.dto = recurrence.Dᴛₒ(),
.cto = recurrence.Cᴛₒ(),
.number_of_revolutions = recurrence.number_of_revolutions(),
.equatorial_shift = recurrence.equatorial_shift() / Radian,
.base_interval = recurrence.base_interval() / Radian,
.grid_interval = recurrence.grid_interval() / Radian,
.subcycle = recurrence.subcycle(),
};
}
if (vessel_analysis->ground_track().has_value() &&
vessel_analysis->equatorial_crossings().has_value()) {
auto const& equatorial_crossings = *vessel_analysis->equatorial_crossings();
analysis->ground_track = new OrbitGroundTrack{
.equatorial_crossings = {
.longitudes_reduced_to_ascending_pass =
ToInterval(equatorial_crossings.longitudes_reduced_to_pass(
2 * ground_track_revolution - 1)),
.longitudes_reduced_to_descending_pass =
ToInterval(equatorial_crossings.longitudes_reduced_to_pass(
2 * ground_track_revolution)),
},
};
}
return analysis;
}

inline Instant FromGameTime(Plugin const& plugin,
double const t) {
return plugin.GameEpoch() + t * Second;
86 changes: 5 additions & 81 deletions ksp_plugin/interface_vessel.cpp
Original file line number Diff line number Diff line change
@@ -82,90 +82,14 @@ OrbitAnalysis* __cdecl principia__VesselRefreshAnalysis(
days_per_cycle,
ground_track_revolution});
CHECK_NOTNULL(plugin);
CHECK_EQ(revolutions_per_cycle == nullptr, days_per_cycle == nullptr);
bool const has_nominal_recurrence = revolutions_per_cycle != nullptr;
if (has_nominal_recurrence) {
CHECK_GT(*revolutions_per_cycle, 0);
CHECK_NE(*days_per_cycle, 0);
}
Vessel& vessel = *plugin->GetVessel(vessel_guid);
vessel.RefreshOrbitAnalysis(mission_duration * Second);
OrbitAnalysis* const analysis = new OrbitAnalysis{};
not_null<OrbitAnalysis*> analysis = NewOrbitAnalysis(vessel.orbit_analysis(),
*plugin,
revolutions_per_cycle,
days_per_cycle,
ground_track_revolution);
analysis->progress_of_next_analysis = vessel.progress_of_orbit_analysis();
if (vessel.orbit_analysis() != nullptr) {
analysis->primary_index = vessel.orbit_analysis()->primary() == nullptr
? nullptr
: new int(plugin->CelestialIndexOfBody(
*vessel.orbit_analysis()->primary()));
analysis->mission_duration =
vessel.orbit_analysis()->mission_duration() / Second;
if (vessel.orbit_analysis()->elements().has_value()) {
auto const& elements = *vessel.orbit_analysis()->elements();
analysis->elements = new OrbitalElements{
.sidereal_period = elements.sidereal_period() / Second,
.nodal_period = elements.nodal_period() / Second,
.anomalistic_period = elements.anomalistic_period() / Second,
.nodal_precession = elements.nodal_precession() / (Radian / Second),
.mean_semimajor_axis =
ToInterval(elements.mean_semimajor_axis_interval()),
.mean_eccentricity =
ToInterval(elements.mean_eccentricity_interval()),
.mean_inclination = ToInterval(elements.mean_inclination_interval()),
.mean_longitude_of_ascending_nodes =
ToInterval(elements.mean_longitude_of_ascending_node_interval()),
.mean_argument_of_periapsis =
ToInterval(elements.mean_argument_of_periapsis_interval()),
.mean_periapsis_distance =
ToInterval(elements.mean_periapsis_distance_interval()),
.mean_apoapsis_distance =
ToInterval(elements.mean_apoapsis_distance_interval()),
.radial_distance = ToInterval(elements.radial_distance_interval()),
};
}
if (has_nominal_recurrence &&
vessel.orbit_analysis()->primary() != nullptr) {
int const Cᴛₒ =
Sign(vessel.orbit_analysis()->primary()->angular_frequency()) *
std::abs(*days_per_cycle);
int const νₒ =
std::nearbyint(static_cast<double>(*revolutions_per_cycle) / Cᴛₒ);
int const Dᴛₒ = *revolutions_per_cycle - νₒ * Cᴛₒ;
int const gcd = std::gcd(Dᴛₒ, Cᴛₒ);
vessel.orbit_analysis()->SetRecurrence({νₒ, Dᴛₒ / gcd, Cᴛₒ / gcd});
} else {
vessel.orbit_analysis()->ResetRecurrence();
}
if (vessel.orbit_analysis()->recurrence().has_value()) {
auto const& recurrence = *vessel.orbit_analysis()->recurrence();
analysis->recurrence = new OrbitRecurrence{
.nuo = recurrence.νₒ(),
.dto = recurrence.Dᴛₒ(),
.cto = recurrence.Cᴛₒ(),
.number_of_revolutions =
recurrence.number_of_revolutions(),
.equatorial_shift =
recurrence.equatorial_shift() / Radian,
.base_interval = recurrence.base_interval() / Radian,
.grid_interval = recurrence.grid_interval() / Radian,
.subcycle = recurrence.subcycle(),
};
}
if (vessel.orbit_analysis()->ground_track().has_value() &&
vessel.orbit_analysis()->equatorial_crossings().has_value()) {
auto const& equatorial_crossings =
*vessel.orbit_analysis()->equatorial_crossings();
analysis->ground_track = new OrbitGroundTrack{
.equatorial_crossings = {
.longitudes_reduced_to_ascending_pass =
ToInterval(equatorial_crossings.longitudes_reduced_to_pass(
2 * ground_track_revolution - 1)),
.longitudes_reduced_to_descending_pass =
ToInterval(equatorial_crossings.longitudes_reduced_to_pass(
2 * ground_track_revolution)),
},
};
}
}

return m.Return(analysis);
}