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: 0b544ddf5343
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: ddf79dd41ea4
Choose a head ref
  • 12 commits
  • 21 files changed
  • 1 contributor

Commits on Nov 6, 2021

  1. First round of changes.

    pleroy committed Nov 6, 2021
    Copy the full SHA
    46a9ff6 View commit details
  2. interface.cpp compiles.

    pleroy committed Nov 6, 2021
    Copy the full SHA
    21a6961 View commit details
  3. interface_flight_plan compiles, but some other things related to flig…

    …ht plans are probably broken.
    pleroy committed Nov 6, 2021
    Copy the full SHA
    605f017 View commit details
  4. Copy the full SHA
    d1c0a8f View commit details
  5. Copy the full SHA
    76fd141 View commit details
  6. Fix the FlightPlan test.

    pleroy committed Nov 6, 2021
    Copy the full SHA
    f476e83 View commit details
  7. Copy the full SHA
    b07534d View commit details
  8. Copy the full SHA
    653b20d View commit details
  9. interface_external compiles.

    pleroy committed Nov 6, 2021
    Copy the full SHA
    2c6a5c0 View commit details
  10. Fix a bug in the construction of the time-to-segment map in compatibi…

    …lity deserialization.
    pleroy committed Nov 6, 2021
    Copy the full SHA
    37de6cc View commit details
  11. Copy the full SHA
    b0572c2 View commit details
  12. Merge pull request #3193 from pleroy/Interface

    Convert the interface methods to DiscreteTraject0ry
    pleroy authored Nov 6, 2021
    Copy the full SHA
    ddf79dd View commit details
17 changes: 5 additions & 12 deletions ksp_plugin/flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -198,22 +198,15 @@ int FlightPlan::number_of_segments() const {
return segments_.size();
}

void FlightPlan::GetSegment(
int const index,
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const {
DiscreteTrajectorySegmentIterator<Barycentric> FlightPlan::GetSegment(
int const index) const {
CHECK_LE(0, index);
CHECK_LT(index, number_of_segments());
begin = segments_[index]->begin();
end = segments_[index]->end();
return segments_[index];
}

void FlightPlan::GetAllSegments(
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const {
begin = segments_.front()->begin();
end = segments_.back()->end();
CHECK(begin != end);
DiscreteTraject0ry<Barycentric> const& FlightPlan::GetAllSegments() const {
return trajectory_;
}

OrbitAnalyser::Analysis* FlightPlan::analysis(int coast_index) {
12 changes: 4 additions & 8 deletions ksp_plugin/flight_plan.hpp
Original file line number Diff line number Diff line change
@@ -112,14 +112,10 @@ class FlightPlan {
// Returns the number of trajectories in this object.
virtual int number_of_segments() const;

// |index| must be in [0, number_of_segments()[. Sets the iterators to denote
// the given trajectory.
virtual void GetSegment(int index,
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const;
virtual void GetAllSegments(
DiscreteTraject0ry<Barycentric>::iterator& begin,
DiscreteTraject0ry<Barycentric>::iterator& end) const;
// |index| must be in [0, number_of_segments()[.
virtual DiscreteTrajectorySegmentIterator<Barycentric>
GetSegment(int index) const;
virtual DiscreteTraject0ry<Barycentric> const& GetAllSegments() const;

// |coast_index| must be in [0, number_of_manœuvres()].
virtual OrbitAnalyser::Analysis* analysis(int coast_index);
10 changes: 6 additions & 4 deletions ksp_plugin/interface.cpp
Original file line number Diff line number Diff line change
@@ -49,7 +49,8 @@
#include "ksp_plugin/identification.hpp"
#include "ksp_plugin/iterators.hpp"
#include "ksp_plugin/part.hpp"
#include "physics/discrete_trajectory.hpp"
#include "physics/discrete_traject0ry.hpp"
#include "physics/discrete_trajectory_segment.hpp"
#include "physics/kepler_orbit.hpp"
#include "physics/solar_system.hpp"
#include "quantities/astronomy.hpp"
@@ -102,7 +103,8 @@ using ksp_plugin::TypedIterator;
using ksp_plugin::VesselSet;
using ksp_plugin::World;
using physics::DegreesOfFreedom;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using physics::DiscreteTrajectorySegment;
using physics::FrameField;
using physics::MassiveBody;
using physics::OblateBody;
@@ -166,10 +168,10 @@ Ephemeris<Barycentric>::AdaptiveStepParameters MakeAdaptiveStepParameters(
ParseQuantity<Speed>(parameters.speed_integration_tolerance));
}

DiscreteTrajectory<Barycentric>::DownsamplingParameters
DiscreteTrajectorySegment<Barycentric>::DownsamplingParameters
MakeDownsamplingParameters(
ConfigurationDownsamplingParameters const& parameters) {
return DiscreteTrajectory<Barycentric>::DownsamplingParameters{
return DiscreteTrajectorySegment<Barycentric>::DownsamplingParameters{
std::stoi(parameters.max_dense_intervals),
ParseQuantity<Length>(parameters.tolerance)};
}
42 changes: 21 additions & 21 deletions ksp_plugin/interface_external.cpp
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
#include "journal/profiles.hpp"
#include "ksp_plugin/frames.hpp"
#include "physics/apsides.hpp"
#include "physics/discrete_traject0ry.hpp"

namespace principia {
namespace interface {
@@ -26,7 +27,7 @@ using ksp_plugin::Vessel;
using ksp_plugin::WorldSun;
using physics::BodyCentredNonRotatingDynamicFrame;
using physics::ComputeApsides;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using physics::OblateBody;
using physics::RigidMotion;
using physics::RigidTransformation;
@@ -282,16 +283,14 @@ Status* __cdecl principia__ExternalGetNearestPlannedCoastDegreesOfFreedom(
std::to_string(manoeuvre_index) + " of " +
vessel.ShortDebugString())));
}
DiscreteTrajectory<Barycentric>::Iterator coast_begin;
DiscreteTrajectory<Barycentric>::Iterator coast_end;
flight_plan.GetSegment(segment_index, coast_begin, coast_end);
auto const body_centred_inertial =
plugin->NewBodyCentredNonRotatingNavigationFrame(central_body_index);
DiscreteTrajectory<Navigation> coast;
for (auto it = coast_begin; it != coast_end; ++it) {
coast.Append(it->time,
body_centred_inertial->ToThisFrameAtTime(it->time)(
it->degrees_of_freedom));
DiscreteTraject0ry<Navigation> coast;
for (auto const& [time, degrees_of_freedom] :
*flight_plan.GetSegment(segment_index)) {
coast.Append(
time,
body_centred_inertial->ToThisFrameAtTime(time)(degrees_of_freedom));
}

Instant const current_time = plugin->CurrentTime();
@@ -315,22 +314,22 @@ Status* __cdecl principia__ExternalGetNearestPlannedCoastDegreesOfFreedom(
Position<Navigation> reference_position =
from_world_body_centred_inertial.rigid_transformation()(
FromXYZ<Position<World>>(world_body_centred_reference_position));
DiscreteTrajectory<Navigation> immobile_reference;
DiscreteTraject0ry<Navigation> immobile_reference;
immobile_reference.Append(coast.front().time,
{reference_position, Navigation::unmoving});
if (coast.Size() > 1) {
if (coast.size() > 1) {
immobile_reference.Append(coast.back().time,
{reference_position, Navigation::unmoving});
}
DiscreteTrajectory<Navigation> apoapsides;
DiscreteTrajectory<Navigation> periapsides;
DiscreteTraject0ry<Navigation> apoapsides;
DiscreteTraject0ry<Navigation> periapsides;
ComputeApsides(/*reference=*/immobile_reference,
coast.begin(),
coast.end(),
coast,
coast.begin(), coast.end(),
/*max_points=*/std::numeric_limits<int>::max(),
apoapsides,
periapsides);
if (periapsides.Empty()) {
if (periapsides.empty()) {
bool const begin_is_nearest =
(coast.front().degrees_of_freedom.position() -
reference_position).Norm²() <
@@ -368,20 +367,21 @@ Status* __cdecl principia__ExternalVesselGetPosition(
absl::StrCat("No vessel with GUID ", vessel_guid))));
}
auto const& vessel = *plugin->GetVessel(vessel_guid);
auto const& trajectory = vessel.psychohistory();
auto const history = vessel.history();
auto const psychohistory = vessel.psychohistory();
Instant const t = FromGameTime(*plugin, time);
if (t < trajectory.t_min() || t > trajectory.t_max()) {
if (t < history->t_min() || t > psychohistory->t_max()) {
return m.Return(ToNewStatus(
absl::OutOfRangeError(
(std::stringstream{}
<< "|time| " << t << " does not lie within the domain ["
<< trajectory.t_min() << ", " << trajectory.t_max()
<< "] of the psychohistory of "
<< history->t_min() << ", " << psychohistory->t_max()
<< "] of the history/psychohistory of "
<< vessel.ShortDebugString()).str())));
}
auto const from_solar_system_barycentre =
plugin->renderer().BarycentricToWorldSun(plugin->PlanetariumRotation())(
trajectory.EvaluatePosition(t) - Barycentric::origin);
vessel.trajectory().EvaluatePosition(t) - Barycentric::origin);
*position = ToXYZ(from_solar_system_barycentre.coordinates() / Metre);
return m.Return(OK());
}
74 changes: 35 additions & 39 deletions ksp_plugin/interface_flight_plan.cpp
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@
#include "physics/body_centred_body_direction_dynamic_frame.hpp"
#include "physics/body_centred_non_rotating_dynamic_frame.hpp"
#include "physics/body_surface_dynamic_frame.hpp"
#include "physics/discrete_trajectory.hpp"
#include "physics/discrete_traject0ry.hpp"
#include "physics/ephemeris.hpp"
#include "quantities/constants.hpp"
#include "quantities/si.hpp"
@@ -40,7 +40,7 @@ using physics::BarycentricRotatingDynamicFrame;
using physics::BodyCentredBodyDirectionDynamicFrame;
using physics::BodyCentredNonRotatingDynamicFrame;
using physics::BodySurfaceDynamicFrame;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using physics::Ephemeris;
using physics::Frenet;
using quantities::Speed;
@@ -404,22 +404,22 @@ void __cdecl principia__FlightPlanRenderedApsides(
{plugin, vessel_guid, celestial_index, sun_world_position, max_points},
{apoapsides, periapsides});
CHECK_NOTNULL(plugin);
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
GetFlightPlan(*plugin, vessel_guid).GetAllSegments(begin, end);
std::unique_ptr<DiscreteTrajectory<World>> rendered_apoapsides;
std::unique_ptr<DiscreteTrajectory<World>> rendered_periapsides;
auto const& flight_plan =
GetFlightPlan(*plugin, vessel_guid).GetAllSegments();
DiscreteTraject0ry<World> rendered_apoapsides;
DiscreteTraject0ry<World> rendered_periapsides;
plugin->ComputeAndRenderApsides(celestial_index,
begin, end,
flight_plan,
flight_plan.begin(), flight_plan.end(),
FromXYZ<Position<World>>(sun_world_position),
max_points,
rendered_apoapsides,
rendered_periapsides);
*apoapsides = new TypedIterator<DiscreteTrajectory<World>>(
check_not_null(std::move(rendered_apoapsides)),
*apoapsides = new TypedIterator<DiscreteTraject0ry<World>>(
std::move(rendered_apoapsides),
plugin);
*periapsides = new TypedIterator<DiscreteTrajectory<World>>(
check_not_null(std::move(rendered_periapsides)),
*periapsides = new TypedIterator<DiscreteTraject0ry<World>>(
std::move(rendered_periapsides),
plugin);
return m.Return();
}
@@ -434,18 +434,17 @@ void __cdecl principia__FlightPlanRenderedClosestApproaches(
{plugin, vessel_guid, sun_world_position, max_points},
{closest_approaches});
CHECK_NOTNULL(plugin);
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
GetFlightPlan(*plugin, vessel_guid).GetAllSegments(begin, end);
std::unique_ptr<DiscreteTrajectory<World>> rendered_closest_approaches;
auto const& flight_plan =
GetFlightPlan(*plugin, vessel_guid).GetAllSegments();
DiscreteTraject0ry<World> rendered_closest_approaches;
plugin->ComputeAndRenderClosestApproaches(
begin,
end,
flight_plan,
flight_plan.begin(), flight_plan.end(),
FromXYZ<Position<World>>(sun_world_position),
max_points,
rendered_closest_approaches);
*closest_approaches = new TypedIterator<DiscreteTrajectory<World>>(
check_not_null(std::move(rendered_closest_approaches)),
*closest_approaches = new TypedIterator<DiscreteTraject0ry<World>>(
std::move(rendered_closest_approaches),
plugin);
return m.Return();
}
@@ -460,21 +459,20 @@ void __cdecl principia__FlightPlanRenderedNodes(Plugin const* const plugin,
{plugin, vessel_guid, sun_world_position, max_points},
{ascending, descending});
CHECK_NOTNULL(plugin);
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
GetFlightPlan(*plugin, vessel_guid).GetAllSegments(begin, end);
std::unique_ptr<DiscreteTrajectory<World>> rendered_ascending;
std::unique_ptr<DiscreteTrajectory<World>> rendered_descending;
plugin->ComputeAndRenderNodes(begin, end,
auto const& flight_plan =
GetFlightPlan(*plugin, vessel_guid).GetAllSegments();
DiscreteTraject0ry<World> rendered_ascending;
DiscreteTraject0ry<World> rendered_descending;
plugin->ComputeAndRenderNodes(flight_plan.begin(), flight_plan.end(),
FromXYZ<Position<World>>(sun_world_position),
max_points,
rendered_ascending,
rendered_descending);
*ascending = new TypedIterator<DiscreteTrajectory<World>>(
check_not_null(std::move(rendered_ascending)),
*ascending = new TypedIterator<DiscreteTraject0ry<World>>(
std::move(rendered_ascending),
plugin);
*descending = new TypedIterator<DiscreteTrajectory<World>>(
check_not_null(std::move(rendered_descending)),
*descending = new TypedIterator<DiscreteTraject0ry<World>>(
std::move(rendered_descending),
plugin);
return m.Return();
}
@@ -489,25 +487,23 @@ Iterator* __cdecl principia__FlightPlanRenderedSegment(
sun_world_position,
index});
CHECK_NOTNULL(plugin);
DiscreteTrajectory<Barycentric>::Iterator begin;
DiscreteTrajectory<Barycentric>::Iterator end;
GetFlightPlan(*plugin, vessel_guid).GetSegment(index, begin, end);
auto const segment = GetFlightPlan(*plugin, vessel_guid).GetSegment(index);
auto rendered_trajectory =
plugin->renderer().RenderBarycentricTrajectoryInWorld(
plugin->CurrentTime(),
begin,
end,
segment->begin(),
segment->end(),
FromXYZ<Position<World>>(sun_world_position),
plugin->PlanetariumRotation());
if (index % 2 == 1 && !rendered_trajectory->Empty() &&
rendered_trajectory->front().time != begin->time) {
if (index % 2 == 1 && !rendered_trajectory.empty() &&
rendered_trajectory.front().time != segment->front().time) {
// TODO(egg): this is ugly; we should centralize rendering.
// If this is a burn and we cannot render the beginning of the burn, we
// render none of it, otherwise we try to render the Frenet trihedron at the
// start and we fail.
rendered_trajectory->ForgetAfter(astronomy::InfinitePast);
rendered_trajectory.clear();
}
return m.Return(new TypedIterator<DiscreteTrajectory<World>>(
return m.Return(new TypedIterator<DiscreteTraject0ry<World>>(
std::move(rendered_trajectory),
plugin));
}
16 changes: 8 additions & 8 deletions ksp_plugin/interface_iterator.cpp
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
#include "ksp_plugin/identification.hpp"
#include "ksp_plugin/iterators.hpp"
#include "ksp_plugin/plugin.hpp"
#include "physics/discrete_trajectory.hpp"
#include "physics/discrete_traject0ry.hpp"
#include "quantities/quantities.hpp"

namespace principia {
@@ -25,7 +25,7 @@ using ksp_plugin::TypedIterator;
using ksp_plugin::VesselSet;
using ksp_plugin::World;
using physics::DegreesOfFreedom;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using quantities::Length;

bool __cdecl principia__IteratorAtEnd(Iterator const* const iterator) {
@@ -44,9 +44,9 @@ QP __cdecl principia__IteratorGetDiscreteTrajectoryQP(
journal::Method<journal::IteratorGetDiscreteTrajectoryQP> m({iterator});
CHECK_NOTNULL(iterator);
auto const typed_iterator = check_not_null(
dynamic_cast<TypedIterator<DiscreteTrajectory<World>> const*>(iterator));
dynamic_cast<TypedIterator<DiscreteTraject0ry<World>> const*>(iterator));
return m.Return(typed_iterator->Get<QP>(
[](DiscreteTrajectory<World>::Iterator const& iterator) -> QP {
[](DiscreteTraject0ry<World>::iterator const& iterator) -> QP {
return ToQP(iterator->degrees_of_freedom);
}));
}
@@ -56,10 +56,10 @@ double __cdecl principia__IteratorGetDiscreteTrajectoryTime(
journal::Method<journal::IteratorGetDiscreteTrajectoryTime> m({iterator});
CHECK_NOTNULL(iterator);
auto const typed_iterator = check_not_null(
dynamic_cast<TypedIterator<DiscreteTrajectory<World>> const*>(iterator));
dynamic_cast<TypedIterator<DiscreteTraject0ry<World>> const*>(iterator));
auto const plugin = typed_iterator->plugin();
return m.Return(typed_iterator->Get<double>(
[plugin](DiscreteTrajectory<World>::Iterator const& iterator) -> double {
[plugin](DiscreteTraject0ry<World>::iterator const& iterator) -> double {
return ToGameTime(*plugin, iterator->time);
}));
}
@@ -69,9 +69,9 @@ XYZ __cdecl principia__IteratorGetDiscreteTrajectoryXYZ(
journal::Method<journal::IteratorGetDiscreteTrajectoryXYZ> m({iterator});
CHECK_NOTNULL(iterator);
auto const typed_iterator = check_not_null(
dynamic_cast<TypedIterator<DiscreteTrajectory<World>> const*>(iterator));
dynamic_cast<TypedIterator<DiscreteTraject0ry<World>> const*>(iterator));
return m.Return(typed_iterator->Get<XYZ>(
[](DiscreteTrajectory<World>::Iterator const& iterator) -> XYZ {
[](DiscreteTraject0ry<World>::iterator const& iterator) -> XYZ {
return ToXYZ(iterator->degrees_of_freedom.position());
}));
}
Loading