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

Commits on Nov 3, 2021

  1. Start changing Plugin.

    pleroy committed Nov 3, 2021
    Copy the full SHA
    4f2fd11 View commit details
  2. Plugin compiles.

    pleroy committed Nov 3, 2021
    Copy the full SHA
    f0c7441 View commit details
  3. The Plugin test compiles.

    pleroy committed Nov 3, 2021
    Copy the full SHA
    9c4a82c View commit details

Commits on Nov 4, 2021

  1. Chen compatibility and a fix.

    pleroy committed Nov 4, 2021
    Copy the full SHA
    b778515 View commit details
  2. Traces.

    pleroy committed Nov 4, 2021
    Copy the full SHA
    bc82a09 View commit details
  3. Remove traces.

    pleroy committed Nov 4, 2021
    Copy the full SHA
    0c7cbd6 View commit details
  4. Tolerate ZFP differences.

    pleroy committed Nov 4, 2021
    Copy the full SHA
    5481260 View commit details
  5. Copy the full SHA
    455dc82 View commit details
  6. Cleanup.

    pleroy committed Nov 4, 2021
    Copy the full SHA
    8e672d3 View commit details

Commits on Nov 6, 2021

  1. Merge pull request #3191 from pleroy/Plugin

    Convert Plugin and its test to DiscreteTraject0ry
    pleroy authored Nov 6, 2021
    Copy the full SHA
    2959395 View commit details
Showing with 97 additions and 62 deletions.
  1. +33 −28 ksp_plugin/plugin.cpp
  2. +22 −15 ksp_plugin/plugin.hpp
  3. +2 −1 ksp_plugin/vessel.cpp
  4. +29 −7 ksp_plugin_test/plugin_test.cpp
  5. +5 −5 physics/discrete_trajectory_segment.hpp
  6. +6 −6 physics/discrete_trajectory_segment_body.hpp
61 changes: 33 additions & 28 deletions ksp_plugin/plugin.cpp
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ void Plugin::InsertCelestialJacobiKeplerian(
}

void Plugin::InitializeDownsamplingParameters(
DiscreteTrajectory<Barycentric>::DownsamplingParameters const&
DiscreteTrajectorySegment<Barycentric>::DownsamplingParameters const&
downsampling_parameters) {
CHECK(initializing_);
history_downsampling_parameters_ = downsampling_parameters;
@@ -789,7 +789,7 @@ void Plugin::CatchUpLaggingVessels(VesselSet& collided_vessels) {

// Update the vessels.
for (auto const& [_, vessel] : vessels_) {
if (vessel->psychohistory().back().time < current_time_) {
if (vessel->psychohistory()->back().time < current_time_) {
if (Contains(collided_vessels, vessel.get())) {
vessel->DisableDownsampling();
}
@@ -856,7 +856,7 @@ RelativeDegreesOfFreedom<AliceSun> Plugin::VesselFromParent(
vessel->set_parent(parent);
}
RelativeDegreesOfFreedom<Barycentric> const barycentric_result =
vessel->psychohistory().back().degrees_of_freedom -
vessel->psychohistory()->back().degrees_of_freedom -
vessel->parent()->current_degrees_of_freedom(current_time_);
RelativeDegreesOfFreedom<AliceSun> const result =
PlanetariumRotation()(barycentric_result);
@@ -902,14 +902,14 @@ void Plugin::UpdatePrediction(std::vector<GUID> const& vessel_guids) const {
}
Vessel* target_vessel = nullptr;

// If there is a target vessel, ensure that the prediction of the |vessels| is
// not longer than that of the target vessel. This is necessary to build the
// targeting frame.
// If there is a target vessel, ensure that the prediction of the
// |predicted_vessels| is not longer than that of the target vessel. This is
// necessary to build the targeting frame.
if (renderer_->HasTargetVessel()) {
target_vessel = &renderer_->GetTargetVessel();
target_vessel->RefreshPrediction();
for (auto const vessel : predicted_vessels) {
vessel->RefreshPrediction(target_vessel->prediction().back().time);
vessel->RefreshPrediction(target_vessel->prediction()->back().time);
}
} else {
for (auto const vessel : predicted_vessels) {
@@ -939,15 +939,17 @@ void Plugin::CreateFlightPlan(GUID const& vessel_guid,

void Plugin::ComputeAndRenderApsides(
Index const celestial_index,
DiscreteTrajectory<Barycentric>::Iterator const& begin,
DiscreteTrajectory<Barycentric>::Iterator const& end,
DiscreteTraject0ry<Barycentric> const& trajectory,
DiscreteTraject0ry<Barycentric>::iterator const& begin,
DiscreteTraject0ry<Barycentric>::iterator const& end,
Position<World> const& sun_world_position,
int const max_points,
std::unique_ptr<DiscreteTrajectory<World>>& apoapsides,
std::unique_ptr<DiscreteTrajectory<World>>& periapsides) const {
DiscreteTrajectory<Barycentric> apoapsides_trajectory;
DiscreteTrajectory<Barycentric> periapsides_trajectory;
DiscreteTraject0ry<World>& apoapsides,
DiscreteTraject0ry<World>& periapsides) const {
DiscreteTraject0ry<Barycentric> apoapsides_trajectory;
DiscreteTraject0ry<Barycentric> periapsides_trajectory;
ComputeApsides(FindOrDie(celestials_, celestial_index)->trajectory(),
trajectory,
begin,
end,
max_points,
@@ -968,16 +970,18 @@ void Plugin::ComputeAndRenderApsides(
}

void Plugin::ComputeAndRenderClosestApproaches(
DiscreteTrajectory<Barycentric>::Iterator const& begin,
DiscreteTrajectory<Barycentric>::Iterator const& end,
DiscreteTraject0ry<Barycentric> const& trajectory,
DiscreteTraject0ry<Barycentric>::iterator const& begin,
DiscreteTraject0ry<Barycentric>::iterator const& end,
Position<World> const& sun_world_position,
int const max_points,
std::unique_ptr<DiscreteTrajectory<World>>& closest_approaches) const {
DiscreteTraject0ry<World>& closest_approaches) const {
CHECK(renderer_->HasTargetVessel());

DiscreteTrajectory<Barycentric> apoapsides_trajectory;
DiscreteTrajectory<Barycentric> periapsides_trajectory;
ComputeApsides(renderer_->GetTargetVessel().prediction(),
DiscreteTraject0ry<Barycentric> apoapsides_trajectory;
DiscreteTraject0ry<Barycentric> periapsides_trajectory;
ComputeApsides(*renderer_->GetTargetVessel().prediction(),
trajectory,
begin,
end,
max_points,
@@ -993,12 +997,12 @@ void Plugin::ComputeAndRenderClosestApproaches(
}

void Plugin::ComputeAndRenderNodes(
DiscreteTrajectory<Barycentric>::Iterator const& begin,
DiscreteTrajectory<Barycentric>::Iterator const& end,
DiscreteTraject0ry<Barycentric>::iterator const& begin,
DiscreteTraject0ry<Barycentric>::iterator const& end,
Position<World> const& sun_world_position,
int const max_points,
std::unique_ptr<DiscreteTrajectory<World>>& ascending,
std::unique_ptr<DiscreteTrajectory<World>>& descending) const {
DiscreteTraject0ry<World>& ascending,
DiscreteTraject0ry<World>& descending) const {
auto const trajectory_in_plotting =
renderer_->RenderBarycentricTrajectoryInPlotting(begin, end);

@@ -1019,11 +1023,12 @@ void Plugin::ComputeAndRenderNodes(
return (dof.position() - Navigation::origin).Norm() < threshold;
};

DiscreteTrajectory<Navigation> ascending_trajectory;
DiscreteTrajectory<Navigation> descending_trajectory;
DiscreteTraject0ry<Navigation> ascending_trajectory;
DiscreteTraject0ry<Navigation> descending_trajectory;
// The so-called North is orthogonal to the plane of the trajectory.
ComputeNodes(trajectory_in_plotting->begin(),
trajectory_in_plotting->end(),
ComputeNodes(trajectory_in_plotting,
trajectory_in_plotting.begin(),
trajectory_in_plotting.end(),
Vector<double, Navigation>({0, 0, 1}),
max_points,
ascending_trajectory,
@@ -1269,7 +1274,7 @@ Velocity<World> Plugin::UnmanageableVesselVelocity(

Velocity<World> Plugin::VesselVelocity(GUID const& vessel_guid) const {
Vessel const& vessel = *FindOrDie(vessels_, vessel_guid);
auto const back = vessel.psychohistory().back();
auto const back = vessel.psychohistory()->back();
return VesselVelocity(back.time, back.degrees_of_freedom);
}

37 changes: 22 additions & 15 deletions ksp_plugin/plugin.hpp
Original file line number Diff line number Diff line change
@@ -29,7 +29,8 @@
#include "integrators/ordinary_differential_equations.hpp"
#include "physics/body.hpp"
#include "physics/degrees_of_freedom.hpp"
#include "physics/discrete_trajectory.hpp"
#include "physics/discrete_traject0ry.hpp"
#include "physics/discrete_trajectory_segment.hpp"
#include "physics/dynamic_frame.hpp"
#include "physics/ephemeris.hpp"
#include "physics/frame_field.hpp"
@@ -45,6 +46,9 @@

namespace principia {
namespace ksp_plugin {

class TestablePlugin;

namespace internal_plugin {

using base::not_null;
@@ -67,7 +71,8 @@ using integrators::FixedStepSizeIntegrator;
using integrators::AdaptiveStepSizeIntegrator;
using physics::Body;
using physics::DegreesOfFreedom;
using physics::DiscreteTrajectory;
using physics::DiscreteTraject0ry;
using physics::DiscreteTrajectorySegment;
using physics::DynamicFrame;
using physics::Ephemeris;
using physics::FrameField;
@@ -127,7 +132,7 @@ class Plugin {
serialization::InitialState::Keplerian::Body const& initial_state);

virtual void InitializeDownsamplingParameters(
DiscreteTrajectory<Barycentric>::DownsamplingParameters const&
DiscreteTrajectorySegment<Barycentric>::DownsamplingParameters const&
downsampling_parameters);
virtual void InitializeEphemerisParameters(
Ephemeris<Barycentric>::AccuracyParameters const& accuracy_parameters,
@@ -345,31 +350,33 @@ class Plugin {
// respect to the celestial with index |celestial_index|.
virtual void ComputeAndRenderApsides(
Index celestial_index,
DiscreteTrajectory<Barycentric>::Iterator const& begin,
DiscreteTrajectory<Barycentric>::Iterator const& end,
DiscreteTraject0ry<Barycentric> const& trajectory,
DiscreteTraject0ry<Barycentric>::iterator const& begin,
DiscreteTraject0ry<Barycentric>::iterator const& end,
Position<World> const& sun_world_position,
int max_points,
std::unique_ptr<DiscreteTrajectory<World>>& apoapsides,
std::unique_ptr<DiscreteTrajectory<World>>& periapsides) const;
DiscreteTraject0ry<World>& apoapsides,
DiscreteTraject0ry<World>& periapsides) const;

// Computes the closest approaches of the trajectory defined by |begin| and
// |end| with respect to the trajectory of the targetted vessel.
virtual void ComputeAndRenderClosestApproaches(
DiscreteTrajectory<Barycentric>::Iterator const& begin,
DiscreteTrajectory<Barycentric>::Iterator const& end,
DiscreteTraject0ry<Barycentric> const& trajectory,
DiscreteTraject0ry<Barycentric>::iterator const& begin,
DiscreteTraject0ry<Barycentric>::iterator const& end,
Position<World> const& sun_world_position,
int max_points,
std::unique_ptr<DiscreteTrajectory<World>>& closest_approaches) const;
DiscreteTraject0ry<World>& closest_approaches) const;

// Computes the nodes of the trajectory defined by |begin| and |end| with
// respect to plane of the trajectory of the targetted vessel.
virtual void ComputeAndRenderNodes(
DiscreteTrajectory<Barycentric>::Iterator const& begin,
DiscreteTrajectory<Barycentric>::Iterator const& end,
DiscreteTraject0ry<Barycentric>::iterator const& begin,
DiscreteTraject0ry<Barycentric>::iterator const& end,
Position<World> const& sun_world_position,
int max_points,
std::unique_ptr<DiscreteTrajectory<World>>& ascending,
std::unique_ptr<DiscreteTrajectory<World>>& descending) const;
DiscreteTraject0ry<World>& ascending,
DiscreteTraject0ry<World>& descending) const;

virtual bool HasCelestial(Index index) const;
virtual Celestial const& GetCelestial(Index index) const;
@@ -515,7 +522,7 @@ class Plugin {
std::unique_ptr<Ephemeris<Barycentric>> ephemeris_;

// The parameters for computing the various trajectories.
DiscreteTrajectory<Barycentric>::DownsamplingParameters
DiscreteTrajectorySegment<Barycentric>::DownsamplingParameters
history_downsampling_parameters_;
Ephemeris<Barycentric>::FixedStepParameters history_fixed_step_parameters_;
Ephemeris<Barycentric>::AdaptiveStepParameters psychohistory_parameters_;
3 changes: 2 additions & 1 deletion ksp_plugin/vessel.cpp
Original file line number Diff line number Diff line change
@@ -490,7 +490,8 @@ not_null<std::unique_ptr<Vessel>> Vessel::ReadFromMessage(
}

if (is_pre_陈景润) {
vessel->history_->SetDownsampling(DefaultDownsamplingParameters());
vessel->history_->SetDownsamplingUnconditionally(
DefaultDownsamplingParameters());
}

if (message.has_flight_plan()) {
36 changes: 29 additions & 7 deletions ksp_plugin_test/plugin_test.cpp
Original file line number Diff line number Diff line change
@@ -19,7 +19,9 @@
#include "base/serialization.hpp"
#include "geometry/identity.hpp"
#include "geometry/named_quantities.hpp"
#include "geometry/orthogonal_map.hpp"
#include "geometry/permutation.hpp"
#include "geometry/rotation.hpp"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "integrators/methods.hpp"
@@ -28,6 +30,7 @@
#include "integrators/symplectic_runge_kutta_nyström_integrator.hpp"
#include "ksp_plugin/integrators.hpp"
#include "physics/continuous_trajectory.hpp"
#include "physics/degrees_of_freedom.hpp"
#include "physics/kepler_orbit.hpp"
#include "physics/massive_body.hpp"
#include "physics/mock_dynamic_frame.hpp"
@@ -46,7 +49,6 @@

namespace principia {
namespace ksp_plugin {
namespace internal_plugin {

using astronomy::ICRS;
using astronomy::ParseTT;
@@ -56,11 +58,17 @@ using base::not_null;
using base::SerializeAsBytes;
using geometry::AngularVelocity;
using geometry::Bivector;
using geometry::Displacement;
using geometry::Identity;
using geometry::Instant;
using geometry::OddPermutation;
using geometry::OrthogonalMap;
using geometry::Permutation;
using geometry::RigidTransformation;
using geometry::Rotation;
using geometry::Trivector;
using geometry::Vector;
using geometry::Velocity;
using integrators::IntegrationProblem;
using integrators::MockFixedStepSizeIntegrator;
using integrators::SymmetricLinearMultistepIntegrator;
@@ -72,10 +80,12 @@ using physics::KeplerOrbit;
using physics::MassiveBody;
using physics::MockDynamicFrame;
using physics::MockEphemeris;
using physics::RelativeDegreesOfFreedom;
using physics::RigidMotion;
using physics::SolarSystem;
using quantities::Abs;
using quantities::Acceleration;
using quantities::Angle;
using quantities::AngularFrequency;
using quantities::ArcTan;
using quantities::Cos;
@@ -84,12 +94,15 @@ using quantities::GravitationalParameter;
using quantities::Length;
using quantities::Sin;
using quantities::Sqrt;
using quantities::Time;
using quantities::astronomy::AstronomicalUnit;
using quantities::si::Day;
using quantities::si::Degree;
using quantities::si::Hour;
using quantities::si::Kilo;
using quantities::si::Kilogram;
using quantities::si::Metre;
using quantities::si::Milli;
using quantities::si::Minute;
using quantities::si::Newton;
using quantities::si::Radian;
@@ -418,10 +431,7 @@ TEST_F(PluginTest, Serialization) {

serialization::Plugin message;
plugin->WriteToMessage(&message);
plugin = Plugin::ReadFromMessage(message);
serialization::Plugin second_message;
plugin->WriteToMessage(&second_message);
EXPECT_THAT(message, EqualsProto(second_message));

EXPECT_EQ(SolarSystemFactory::LastMajorBody - SolarSystemFactory::Sun + 1,
message.celestial_size());

@@ -437,7 +447,7 @@ TEST_F(PluginTest, Serialization) {
EXPECT_TRUE(message.vessel(0).vessel().has_flight_plan());
EXPECT_TRUE(message.vessel(0).vessel().has_history());
auto const& vessel_0_history = message.vessel(0).vessel().history();
EXPECT_EQ(7, vessel_0_history.zfp().timeline_size());
EXPECT_EQ(7, vessel_0_history.segment(0).zfp().timeline_size());
EXPECT_TRUE(message.has_renderer());
EXPECT_TRUE(message.renderer().has_plotting_frame());
EXPECT_TRUE(message.renderer().plotting_frame().HasExtension(
@@ -446,6 +456,19 @@ TEST_F(PluginTest, Serialization) {
message.renderer().plotting_frame().GetExtension(
serialization::BodyCentredNonRotatingDynamicFrame::extension).
centre());

plugin = Plugin::ReadFromMessage(message);
serialization::Plugin second_message;
plugin->WriteToMessage(&second_message);

// The zfp serialization is not idempotent because we exactly preserve the
// bounds of each segment. Ignore it for the purposes of comparing the
// messages.
message.mutable_vessel(0)->mutable_vessel()
->mutable_history()->mutable_segment(0)->clear_zfp();
second_message.mutable_vessel(0)->mutable_vessel()
->mutable_history()->mutable_segment(0)->clear_zfp();
EXPECT_THAT(message, EqualsProto(second_message));
}

TEST_F(PluginTest, Initialization) {
@@ -965,6 +988,5 @@ TEST_F(PluginTest, Frenet) {
AlmostEquals(alice_sun_to_world(satellite_initial_velocity_), 7, 83));
}

} // namespace internal_plugin
} // namespace ksp_plugin
} // namespace principia
10 changes: 5 additions & 5 deletions physics/discrete_trajectory_segment.hpp
Original file line number Diff line number Diff line change
@@ -106,6 +106,11 @@ class DiscreteTrajectorySegment : public Trajectory<Frame> {
// within the desired tolerance.
void SetDownsampling(DownsamplingParameters const& downsampling_parameters);

// Same as above, but can be used on a nontrivial segment. Use exclusively
// for compatibility deserialization.
void SetDownsamplingUnconditionally(
DownsamplingParameters const& downsampling_parameters);

// Clear the downsampling parameters. From now on, all points appended to the
// segment are going to be retained.
void ClearDownsampling();
@@ -148,11 +153,6 @@ class DiscreteTrajectorySegment : public Trajectory<Frame> {
void ForgetBefore(Instant const& t);
void ForgetBefore(typename Timeline::const_iterator end);

// Same as |SetDownsampling|, but can be used on a nontrivial segment. Used
// for compatibility deserialization.
void SetDownsamplingUnconditionally(
DownsamplingParameters const& downsampling_parameters);

// Computes |number_of_dense_points_| based on the start of the dense
// timeline. Used for compatibility deserialization.
void SetStartOfDenseTimeline(Instant const& t);
Loading