Skip to content

Commit 72e829f

Browse files
authored
Merge pull request #3160 from pleroy/Compatibility2
Compatibility deserialization of DiscreteTrajectory2
2 parents 6d1ac3d + 1e01f8d commit 72e829f

24 files changed

+619
-127
lines changed

base/pull_serializer_test.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ class PullSerializerTest : public ::testing::Test {
4949
make_not_null_unique<DiscreteTrajectory>();
5050
// Build a biggish protobuf for serialization.
5151
for (int i = 0; i < 100; ++i) {
52-
DiscreteTrajectory::InstantaneousDegreesOfFreedom* idof =
53-
result->add_timeline();
52+
auto* const idof = result->add_timeline();
5453
Point* instant = idof->mutable_instant();
5554
Quantity* scalar = instant->mutable_scalar();
5655
scalar->set_dimensions(3);

base/push_deserializer_test.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ class PushDeserializerTest : public ::testing::Test {
6666
make_not_null_unique<DiscreteTrajectory>();
6767
// Build a biggish protobuf for serialization.
6868
for (int i = 0; i < 100; ++i) {
69-
DiscreteTrajectory::InstantaneousDegreesOfFreedom* idof =
70-
result->add_timeline();
69+
auto* const idof = result->add_timeline();
7170
Point* instant = idof->mutable_instant();
7271
Quantity* scalar = instant->mutable_scalar();
7372
scalar->set_dimensions(3);

ksp_plugin_test/ksp_plugin_test.vcxproj

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<ClCompile Include="..\numerics\elliptic_functions.cpp" />
5151
<ClCompile Include="..\numerics\elliptic_integrals.cpp" />
5252
<ClCompile Include="..\physics\protector.cpp" />
53+
<ClCompile Include="..\testing_utilities\string_log_sink.cpp" />
5354
<ClCompile Include="benchmark.cpp" />
5455
<ClCompile Include="celestial_test.cpp" />
5556
<ClCompile Include="equator_relevance_threshold_test.cpp" />

ksp_plugin_test/ksp_plugin_test.vcxproj.filters

+3
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@
197197
<ClCompile Include="plugin_compatibility_test.cpp">
198198
<Filter>Test Files</Filter>
199199
</ClCompile>
200+
<ClCompile Include="..\testing_utilities\string_log_sink.cpp">
201+
<Filter>Source Files</Filter>
202+
</ClCompile>
200203
</ItemGroup>
201204
<ItemGroup>
202205
<ClInclude Include="mock_plugin.hpp">

ksp_plugin_test/plugin_compatibility_test.cpp

+24-37
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "serialization/ksp_plugin.pb.h"
2323
#include "testing_utilities/is_near.hpp"
2424
#include "testing_utilities/serialization.hpp"
25+
#include "testing_utilities/string_log_sink.hpp"
2526

2627
namespace principia {
2728
namespace interface {
@@ -47,6 +48,7 @@ using testing_utilities::IsNear;
4748
using testing_utilities::ReadFromBinaryFile;
4849
using testing_utilities::ReadLinesFromBase64File;
4950
using testing_utilities::ReadLinesFromHexadecimalFile;
51+
using testing_utilities::StringLogSink;
5052
using testing_utilities::WriteToBinaryFile;
5153
using ::testing::AllOf;
5254
using ::testing::ElementsAre;
@@ -61,43 +63,6 @@ using ::testing::internal::GetCapturedStderr;
6163
const char preferred_compressor[] = "gipfeli";
6264
const char preferred_encoder[] = "base64";
6365

64-
class StringLogSink : google::LogSink {
65-
public:
66-
explicit StringLogSink(google::LogSeverity const minimal_severity)
67-
: minimal_severity_(minimal_severity) {
68-
google::AddLogSink(this);
69-
}
70-
71-
~StringLogSink() {
72-
google::RemoveLogSink(this);
73-
}
74-
75-
void send(google::LogSeverity const severity,
76-
char const* const full_filename,
77-
char const* const base_filename,
78-
int const line,
79-
tm const* const tm_time,
80-
const char* const message,
81-
size_t const message_len) override {
82-
if (severity < minimal_severity_) {
83-
return;
84-
}
85-
absl::MutexLock lock(&mutex_);
86-
absl::StrAppend(
87-
&string_,
88-
ToString(severity, base_filename, line, tm_time, message, message_len));
89-
}
90-
91-
std::string& string() {
92-
return string_;
93-
}
94-
95-
private:
96-
google::LogSeverity const minimal_severity_;
97-
absl::Mutex mutex_;
98-
std::string string_ GUARDED_BY(mutex_);
99-
};
100-
10166
class PluginCompatibilityTest : public testing::Test {
10267
protected:
10368
PluginCompatibilityTest()
@@ -375,6 +340,28 @@ TEST_F(PluginCompatibilityTest, DISABLED_Lpg) {
375340
EXPECT_EQ(435'927, history->Size());
376341
EXPECT_EQ(435'929, psychohistory.Size());
377342

343+
// Evaluate a point in each of the two segments.
344+
EXPECT_THAT(history->EvaluateDegreesOfFreedom("1957-10-04T19:28:34"_TT),
345+
Eq(DegreesOfFreedom<Barycentric>(
346+
Barycentric::origin + Displacement<Barycentric>(
347+
{+1.47513683827317657e+11 * Metre,
348+
+2.88696086355042419e+10 * Metre,
349+
+1.24740082262952404e+10 * Metre}),
350+
Velocity<Barycentric>(
351+
{-6.28845231836519179e+03 * (Metre / Second),
352+
+2.34046542233168329e+04 * (Metre / Second),
353+
+4.64410011408655919e+03 * (Metre / Second)}))));
354+
EXPECT_THAT(psychohistory.EvaluateDegreesOfFreedom("1958-10-07T09:38:30"_TT),
355+
Eq(DegreesOfFreedom<Barycentric>(
356+
Barycentric::origin + Displacement<Barycentric>(
357+
{+1.45814173315801941e+11 * Metre,
358+
+3.45409490426372147e+10 * Metre,
359+
+1.49445864962450924e+10 * Metre}),
360+
Velocity<Barycentric>(
361+
{-8.70708379504568074e+03 * (Metre / Second),
362+
+2.61488327506437054e+04 * (Metre / Second),
363+
+1.90319283138508908e+04 * (Metre / Second)}))));
364+
378365
// Serialize the history and psychohistory to a temporary file.
379366
{
380367
serialization::DiscreteTrajectory message;

physics/discrete_trajectory2.hpp

+32
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <vector>
77

88
#include "absl/container/btree_map.h"
9+
#include "absl/status/status.h"
910
#include "base/macros.hpp"
1011
#include "base/not_null.hpp"
1112
#include "base/tags.hpp"
@@ -108,6 +109,8 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {
108109
std::vector<SegmentIterator*> const& tracked);
109110

110111
private:
112+
using DownsamplingParameters =
113+
internal_discrete_trajectory_types::DownsamplingParameters;
111114
using Segments = internal_discrete_trajectory_types::Segments<Frame>;
112115

113116
// This constructor leaves the list of segments empty (but allocated) as well
@@ -117,6 +120,10 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {
117120
typename Segments::iterator FindSegment(Instant const& t);
118121
typename Segments::const_iterator FindSegment(Instant const& t) const;
119122

123+
// Checks if this objects is in a consistent state, and returns an error
124+
// status with a relevant message if it isn't.
125+
absl::Status ValidateConsistency() const;
126+
120127
// Updates the segments self-pointers and the time-to-segment mapping after
121128
// segments have been spliced from |from| to |to|. The iterators indicate the
122129
// segments to fix-up.
@@ -126,6 +133,31 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {
126133
typename Segments::iterator to_segments_begin,
127134
std::reverse_iterator<typename Segments::iterator> to_segments_rend);
128135

136+
// Reads a pre-Ζήνων downsampling message and return the downsampling
137+
// parameters and the start of the dense timeline. The latter will have to be
138+
// converted to a number of points based on the deserialized timeline.
139+
static void ReadFromPreΖήνωνMessage(
140+
serialization::DiscreteTrajectory::Downsampling const& message,
141+
DownsamplingParameters& downsampling_parameters,
142+
Instant& start_of_dense_timeline);
143+
144+
// Reads a set of pre-Ζήνων children. Checks that there is only one child,
145+
// and that it is at the end of the preceding segment. Append a segment to
146+
// the trajectory and returns an iterator to that segment.
147+
static SegmentIterator ReadFromPreΖήνωνMessage(
148+
serialization::DiscreteTrajectory::Brood const& message,
149+
std::vector<SegmentIterator*> const& tracked,
150+
value_type const& fork_point,
151+
DiscreteTrajectory2& trajectory);
152+
153+
// Reads a pre-Ζήνων trajectory, updating the tracked segments as needed. If
154+
// this is not the root of the trajectory, fork_point is set.
155+
static void ReadFromPreΖήνωνMessage(
156+
serialization::DiscreteTrajectory const& message,
157+
std::vector<SegmentIterator*> const& tracked,
158+
std::optional<value_type> const& fork_point,
159+
DiscreteTrajectory2& trajectory);
160+
129161
// We need a level of indirection here to make sure that the pointer to
130162
// Segments in the DiscreteTrajectorySegmentIterator remain valid when the
131163
// DiscreteTrajectory moves. This field is never null and never empty.

0 commit comments

Comments
 (0)