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

Commits on Oct 23, 2021

  1. it compiles

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    dd50cea View commit details
  2. Earlier

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    4e46172 View commit details
  3. line length

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    859eeed View commit details
  4. comment, line length

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    5b81860 View commit details
  5. body

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    3e5af5c View commit details
  6. Copy the full SHA
    b35c902 View commit details
  7. add the implementation

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    cfaf91f View commit details
  8. fit on previous line

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    e105803 View commit details
  9. the final frontier

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    b77de88 View commit details
  10. more firsts and seconds

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    24c8b39 View commit details
  11. line length

    eggrobin committed Oct 23, 2021
    Copy the full SHA
    5961a9d View commit details
  12. Merge pull request #3169 from eggrobin/stat-rosa-pristina-nomine

    Stat rosa pristina nomine
    pleroy authored Oct 23, 2021
    Copy the full SHA
    a26020a View commit details
25 changes: 13 additions & 12 deletions physics/discrete_traject0ry_body.hpp
Original file line number Diff line number Diff line change
@@ -184,9 +184,9 @@ DiscreteTraject0ry<Frame>::AttachSegments(
// NOTE(phl): This check might be too strict, we might want to allow LT as the
// time comparison, and to adjust the first point of trajectory as needed.
// We'll see if the clients need that.
CHECK_EQ(rbegin()->first, trajectory.begin()->first)
CHECK_EQ(rbegin()->time, trajectory.begin()->time)
<< "Mismatching times when attaching segments";
CHECK_EQ(rbegin()->second, trajectory.begin()->second)
CHECK_EQ(rbegin()->degrees_of_freedom, trajectory.begin()->degrees_of_freedom)
<< "Mismatching degrees of freedom when attaching segments";

if (empty()) {
@@ -417,10 +417,10 @@ absl::Status DiscreteTraject0ry<Frame>::ValidateConsistency() const {
auto it1 = segments_->cbegin();
auto it2 = segment_by_left_endpoint_.cbegin();
for (; it1 != segments_->cend(); ++it1, ++it2, ++i) {
if (it1->begin()->first != it2->first) {
if (it1->begin()->time != it2->first) {
return absl::InternalError(
absl::StrCat("Times mismatch ",
DebugString(it1->begin()->first),
DebugString(it1->begin()->time),
" and ",
DebugString(it2->first),
" for segment #",
@@ -442,20 +442,21 @@ absl::Status DiscreteTraject0ry<Frame>::ValidateConsistency() const {
// times match. We must look at the endpoints of the timeline explicitly.
auto const timeline_rbegin = --sit->timeline_end();
auto const timeline_begin = std::next(sit)->timeline_begin();
if (timeline_rbegin->first != timeline_begin->first) {
if (timeline_rbegin->time != timeline_begin->time) {
return absl::InternalError(
absl::StrCat("Duplicated time mismatch ",
DebugString(timeline_rbegin->first),
DebugString(timeline_rbegin->time),
" and ",
DebugString(timeline_begin->first),
DebugString(timeline_begin->time),
" for segment #",
i));
} else if (timeline_rbegin->second != timeline_begin->second) {
} else if (timeline_rbegin->degrees_of_freedom !=
timeline_begin->degrees_of_freedom) {
return absl::InternalError(
absl::StrCat("Duplicated degrees of freedom mismatch ",
DebugString(timeline_rbegin->second),
DebugString(timeline_rbegin->degrees_of_freedom),
" and ",
DebugString(timeline_begin->second),
DebugString(timeline_begin->degrees_of_freedom),
" for segment #",
i));
}
@@ -514,7 +515,7 @@ DiscreteTraject0ry<Frame>::ReadFromPreΖήνωνMessage(
std::vector<SegmentIterator*> const& tracked,
value_type const& fork_point,
DiscreteTraject0ry& trajectory) {
CHECK_EQ(fork_point.first, Instant::ReadFromMessage(message.fork_time()))
CHECK_EQ(fork_point.time, Instant::ReadFromMessage(message.fork_time()))
<< "Cannot read trajectory with a fork not at end of segment";
CHECK_EQ(1, message.trajectories_size())
<< "Cannot read trajectory with multiple forks";
@@ -618,7 +619,7 @@ void DiscreteTraject0ry<Frame>::ReadFromPreΖήνωνMessage(
}

// Finally, set the time-to-segment map.
trajectory.segment_by_left_endpoint_.emplace(sit->begin()->first, sit);
trajectory.segment_by_left_endpoint_.emplace(sit->begin()->time, sit);
}

} // namespace internal_discrete_traject0ry
68 changes: 35 additions & 33 deletions physics/discrete_traject0ry_test.cpp
Original file line number Diff line number Diff line change
@@ -132,8 +132,8 @@ TEST_F(DiscreteTraject0ryTest, Make) {

TEST_F(DiscreteTraject0ryTest, BackFront) {
auto const trajectory = MakeTrajectory();
EXPECT_EQ(t0_, trajectory.front().first);
EXPECT_EQ(t0_ + 14 * Second, trajectory.back().first);
EXPECT_EQ(t0_, trajectory.front().time);
EXPECT_EQ(t0_ + 14 * Second, trajectory.back().time);
}

TEST_F(DiscreteTraject0ryTest, IterateForward) {
@@ -164,7 +164,7 @@ TEST_F(DiscreteTraject0ryTest, IterateBackward) {
auto const trajectory = MakeTrajectory();
std::vector<Instant> times;
for (auto it = trajectory.rbegin(); it != trajectory.rend(); ++it) {
times.push_back(it->first);
times.push_back(it->time);
}
EXPECT_THAT(times,
ElementsAre(t0_ + 14 * Second,
@@ -317,8 +317,8 @@ TEST_F(DiscreteTraject0ryTest, Segments) {
std::vector<Instant> begin;
std::vector<Instant> rbegin;
for (auto const& sit : trajectory.segments()) {
begin.push_back(sit.begin()->first);
rbegin.push_back(sit.rbegin()->first);
begin.push_back(sit.begin()->time);
rbegin.push_back(sit.rbegin()->time);
}
EXPECT_THAT(
begin,
@@ -333,8 +333,8 @@ TEST_F(DiscreteTraject0ryTest, RSegments) {
std::vector<Instant> begin;
std::vector<Instant> rbegin;
for (auto const& sit : trajectory.rsegments()) {
begin.push_back(sit.begin()->first);
rbegin.push_back(sit.rbegin()->first);
begin.push_back(sit.begin()->time);
rbegin.push_back(sit.rbegin()->time);
}
EXPECT_THAT(
begin,
@@ -351,10 +351,10 @@ TEST_F(DiscreteTraject0ryTest, DetachSegments) {
auto trajectory2 = trajectory1.DetachSegments(second_segment);
EXPECT_EQ(1, trajectory1.segments().size());
EXPECT_EQ(2, trajectory2.segments().size());
EXPECT_EQ(t0_, trajectory1.begin()->first);
EXPECT_EQ(t0_ + 4 * Second, trajectory1.rbegin()->first);
EXPECT_EQ(t0_ + 4 * Second, trajectory2.begin()->first);
EXPECT_EQ(t0_ + 14 * Second, trajectory2.rbegin()->first);
EXPECT_EQ(t0_, trajectory1.begin()->time);
EXPECT_EQ(t0_ + 4 * Second, trajectory1.rbegin()->time);
EXPECT_EQ(t0_ + 4 * Second, trajectory2.begin()->time);
EXPECT_EQ(t0_ + 14 * Second, trajectory2.rbegin()->time);

// Check that the trajectories are minimally usable (in particular, as far as
// the time-to-segment mapping is concerned).
@@ -409,8 +409,8 @@ TEST_F(DiscreteTraject0ryTest, AttachSegments) {
1 * Metre / Second})));
trajectory1.AttachSegments(std::move(trajectory2));
EXPECT_EQ(6, trajectory1.segments().size());
EXPECT_EQ(t0_, trajectory1.begin()->first);
EXPECT_EQ(t0_ + 28 * Second, trajectory1.rbegin()->first);
EXPECT_EQ(t0_, trajectory1.begin()->time);
EXPECT_EQ(t0_ + 28 * Second, trajectory1.rbegin()->time);

// Check that the trajectories are minimally usable (in particular, as far as
// the time-to-segment mapping is concerned).
@@ -449,46 +449,46 @@ TEST_F(DiscreteTraject0ryTest, DeleteSegments) {
auto const second_segment = std::next(first_segment);
trajectory.DeleteSegments(second_segment);
EXPECT_EQ(1, trajectory.segments().size());
EXPECT_EQ(t0_, trajectory.begin()->first);
EXPECT_EQ(t0_ + 4 * Second, trajectory.rbegin()->first);
EXPECT_EQ(t0_, trajectory.begin()->time);
EXPECT_EQ(t0_ + 4 * Second, trajectory.rbegin()->time);
}

TEST_F(DiscreteTraject0ryTest, ForgetAfter) {
auto trajectory = MakeTrajectory();

trajectory.ForgetAfter(t0_ + 12 * Second);
EXPECT_EQ(3, trajectory.segments().size());
EXPECT_EQ(t0_, trajectory.begin()->first);
EXPECT_EQ(t0_ + 11 * Second, trajectory.rbegin()->first);
EXPECT_EQ(t0_, trajectory.begin()->time);
EXPECT_EQ(t0_ + 11 * Second, trajectory.rbegin()->time);

trajectory.ForgetAfter(t0_ + 6.1 * Second);
EXPECT_EQ(2, trajectory.segments().size());
EXPECT_EQ(t0_, trajectory.begin()->first);
EXPECT_EQ(t0_ + 6 * Second, trajectory.rbegin()->first);
EXPECT_EQ(t0_, trajectory.begin()->time);
EXPECT_EQ(t0_ + 6 * Second, trajectory.rbegin()->time);

trajectory.ForgetAfter(t0_ + 4 * Second);
EXPECT_EQ(1, trajectory.segments().size());
EXPECT_EQ(t0_, trajectory.begin()->first);
EXPECT_EQ(t0_ + 4 * Second, trajectory.rbegin()->first);
EXPECT_EQ(t0_, trajectory.begin()->time);
EXPECT_EQ(t0_ + 4 * Second, trajectory.rbegin()->time);
}

TEST_F(DiscreteTraject0ryTest, ForgetBefore) {
auto trajectory = MakeTrajectory();

trajectory.ForgetBefore(t0_ + 3 * Second);
EXPECT_EQ(3, trajectory.segments().size());
EXPECT_EQ(t0_ + 3 * Second, trajectory.begin()->first);
EXPECT_EQ(t0_ + 14 * Second, trajectory.rbegin()->first);
EXPECT_EQ(t0_ + 3 * Second, trajectory.begin()->time);
EXPECT_EQ(t0_ + 14 * Second, trajectory.rbegin()->time);

trajectory.ForgetBefore(t0_ + 6.1 * Second);
EXPECT_EQ(2, trajectory.segments().size());
EXPECT_EQ(t0_ + 7 * Second, trajectory.begin()->first);
EXPECT_EQ(t0_ + 14 * Second, trajectory.rbegin()->first);
EXPECT_EQ(t0_ + 7 * Second, trajectory.begin()->time);
EXPECT_EQ(t0_ + 14 * Second, trajectory.rbegin()->time);

trajectory.ForgetBefore(t0_ + 9 * Second);
EXPECT_EQ(1, trajectory.segments().size());
EXPECT_EQ(t0_ + 9 * Second, trajectory.begin()->first);
EXPECT_EQ(t0_ + 14 * Second, trajectory.rbegin()->first);
EXPECT_EQ(t0_ + 9 * Second, trajectory.begin()->time);
EXPECT_EQ(t0_ + 14 * Second, trajectory.rbegin()->time);
}

TEST_F(DiscreteTraject0ryTest, TMinTMaxEvaluate) {
@@ -531,14 +531,16 @@ TEST_F(DiscreteTraject0ryTest, SerializationRoundTrip) {
message1, /*tracked=*/{&deserialized_second_segment});

// Check that the tracked segment was properly retrieved.
EXPECT_EQ(t0_ + 4 * Second, deserialized_second_segment->begin()->first);
EXPECT_EQ(t0_ + 9 * Second, deserialized_second_segment->rbegin()->first);
EXPECT_EQ(t0_ + 4 * Second, deserialized_second_segment->begin()->time);
EXPECT_EQ(t0_ + 9 * Second, deserialized_second_segment->rbegin()->time);

// Check that the exact points are exact.
EXPECT_EQ(deserialized_trajectory.lower_bound(t0_ + 2 * Second)->second,
trajectory.lower_bound(t0_ + 2 * Second)->second);
EXPECT_EQ(deserialized_trajectory.lower_bound(t0_ + 3 * Second)->second,
trajectory.lower_bound(t0_ + 3 * Second)->second);
EXPECT_EQ(
deserialized_trajectory.lower_bound(t0_ + 2 * Second)->degrees_of_freedom,
trajectory.lower_bound(t0_ + 2 * Second)->degrees_of_freedom);
EXPECT_EQ(
deserialized_trajectory.lower_bound(t0_ + 3 * Second)->degrees_of_freedom,
trajectory.lower_bound(t0_ + 3 * Second)->degrees_of_freedom);

serialization::DiscreteTrajectory message2;
deserialized_trajectory.WriteToMessage(
10 changes: 5 additions & 5 deletions physics/discrete_trajectory_iterator_body.hpp
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ DiscreteTrajectoryIterator<Frame>&
DiscreteTrajectoryIterator<Frame>::operator++() {
CHECK(!is_at_end(point_));
auto& point = iterator(point_);
Instant const previous_time = point->first;
Instant const previous_time = point->time;
do {
if (point == --segment_->timeline_end()) {
++segment_;
@@ -28,7 +28,7 @@ DiscreteTrajectoryIterator<Frame>::operator++() {
} else {
++point;
}
} while (point->first == previous_time);
} while (point->time == previous_time);
return *this;
}

@@ -44,7 +44,7 @@ DiscreteTrajectoryIterator<Frame>::operator--() {
}
auto& point = iterator(point_);
std::optional<Instant> const previous_time =
point_is_at_end ? std::nullopt : std::make_optional(point->first);
point_is_at_end ? std::nullopt : std::make_optional(point->time);
do {
if (point == segment_->timeline_begin()) {
CHECK(!segment_.is_begin());
@@ -53,7 +53,7 @@ DiscreteTrajectoryIterator<Frame>::operator--() {
} else {
--point;
}
} while (point->first == previous_time);
} while (point->time == previous_time);
return *this;
}

@@ -95,7 +95,7 @@ bool DiscreteTrajectoryIterator<Frame>::operator==(
} else if (is_at_end(other.point_)) {
return false;
} else {
return iterator(point_)->first == iterator(other.point_)->first;
return iterator(point_)->time == iterator(other.point_)->time;
}
}

42 changes: 21 additions & 21 deletions physics/discrete_trajectory_iterator_test.cpp
Original file line number Diff line number Diff line change
@@ -97,26 +97,26 @@ class DiscreteTrajectoryIteratorTest : public ::testing::Test {
TEST_F(DiscreteTrajectoryIteratorTest, ForwardOneSegment) {
auto segment = segments_->begin();
auto iterator = MakeBegin(segment);
EXPECT_EQ(t0_ + 2 * Second, iterator->first);
EXPECT_EQ(t0_ + 2 * Second, iterator->time);
auto const current = ++iterator;
EXPECT_EQ(t0_ + 3 * Second, iterator->first);
EXPECT_EQ(t0_ + 3 * Second, current->first);
EXPECT_EQ(t0_ + 3 * Second, iterator->time);
EXPECT_EQ(t0_ + 3 * Second, current->time);
auto const previous = iterator++;
EXPECT_EQ(t0_ + 5 * Second, iterator->first);
EXPECT_EQ(t0_ + 3 * Second, previous->first);
EXPECT_EQ(t0_ + 5 * Second, iterator->time);
EXPECT_EQ(t0_ + 3 * Second, previous->time);
}

TEST_F(DiscreteTrajectoryIteratorTest, BackwardOneSegment) {
auto segment = --segments_->end();
auto iterator = MakeEnd(segment);
--iterator;
EXPECT_EQ(t0_ + 23 * Second, (*iterator).first);
EXPECT_EQ(t0_ + 23 * Second, (*iterator).time);
auto const current = --iterator;
EXPECT_EQ(t0_ + 19 * Second, (*iterator).first);
EXPECT_EQ(t0_ + 19 * Second, (*current).first);
EXPECT_EQ(t0_ + 19 * Second, (*iterator).time);
EXPECT_EQ(t0_ + 19 * Second, (*current).time);
auto const previous = iterator--;
EXPECT_EQ(t0_ + 17 * Second, (*iterator).first);
EXPECT_EQ(t0_ + 19 * Second, (*previous).first);
EXPECT_EQ(t0_ + 17 * Second, (*iterator).time);
EXPECT_EQ(t0_ + 19 * Second, (*previous).time);
}

TEST_F(DiscreteTrajectoryIteratorTest, ForwardAcrossSegments) {
@@ -125,11 +125,11 @@ TEST_F(DiscreteTrajectoryIteratorTest, ForwardAcrossSegments) {
for (int i = 0; i < 4; ++i) {
++iterator;
}
EXPECT_EQ(t0_ + 11 * Second, iterator->first);
EXPECT_EQ(t0_ + 11 * Second, iterator->time);
++iterator;
EXPECT_EQ(t0_ + 13 * Second, iterator->first);
EXPECT_EQ(t0_ + 13 * Second, iterator->time);
++iterator;
EXPECT_EQ(t0_ + 17 * Second, iterator->first);
EXPECT_EQ(t0_ + 17 * Second, iterator->time);
}

TEST_F(DiscreteTrajectoryIteratorTest, BackwardAcrossSegments) {
@@ -138,11 +138,11 @@ TEST_F(DiscreteTrajectoryIteratorTest, BackwardAcrossSegments) {
for (int i = 0; i < 3; ++i) {
--iterator;
}
EXPECT_EQ(t0_ + 17 * Second, (*iterator).first);
EXPECT_EQ(t0_ + 17 * Second, (*iterator).time);
--iterator;
EXPECT_EQ(t0_ + 13 * Second, (*iterator).first);
EXPECT_EQ(t0_ + 13 * Second, (*iterator).time);
--iterator;
EXPECT_EQ(t0_ + 11 * Second, (*iterator).first);
EXPECT_EQ(t0_ + 11 * Second, (*iterator).time);
}

TEST_F(DiscreteTrajectoryIteratorTest, Equality) {
@@ -152,17 +152,17 @@ TEST_F(DiscreteTrajectoryIteratorTest, Equality) {
for (int i = 0; i < 3; ++i) {
--it1;
}
EXPECT_EQ(t0_ + 17 * Second, (*it1).first);
EXPECT_EQ(t0_ + 17 * Second, (*it1).time);
--it1;
EXPECT_EQ(t0_ + 13 * Second, (*it1).first);
EXPECT_EQ(t0_ + 13 * Second, (*it1).time);

auto it2 = MakeBegin(segments_->begin());
for (int i = 0; i < 4; ++i) {
++it2;
}
EXPECT_EQ(t0_ + 11 * Second, it2->first);
EXPECT_EQ(t0_ + 11 * Second, it2->time);
++it2;
EXPECT_EQ(t0_ + 13 * Second, it2->first);
EXPECT_EQ(t0_ + 13 * Second, it2->time);

EXPECT_EQ(it1, it2);
EXPECT_NE(it1, MakeBegin(segments_->begin()));
@@ -209,7 +209,7 @@ TEST_F(DiscreteTrajectoryIteratorTest, EmptyLastSegment) {
auto segments = MakeSegments(2);
auto segment = segments->begin();
Append(segment, t0_, unmoving_origin_);
EXPECT_EQ(t0_, segment->rbegin()->first);
EXPECT_EQ(t0_, segment->rbegin()->time);
}

} // namespace physics
Loading