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

Commits on Oct 10, 2021

  1. Implementation and tests.

    pleroy committed Oct 10, 2021
    Copy the full SHA
    de3e0e6 View commit details
  2. Copy the full SHA
    744c27e View commit details
  3. Tests passing.

    pleroy committed Oct 10, 2021
    Copy the full SHA
    25f4121 View commit details
  4. Copy the full SHA
    a2e3028 View commit details
  5. Merge pull request #3146 from pleroy/Forget

    DiscreteTrajectorySegment, part 2: forgetting
    pleroy authored Oct 10, 2021
    Copy the full SHA
    9590119 View commit details
Showing with 58 additions and 4 deletions.
  1. +4 −0 physics/discrete_trajectory_segment.hpp
  2. +16 −4 physics/discrete_trajectory_segment_body.hpp
  3. +38 −0 physics/discrete_trajectory_segment_test.cpp
4 changes: 4 additions & 0 deletions physics/discrete_trajectory_segment.hpp
Original file line number Diff line number Diff line change
@@ -67,9 +67,13 @@ class DiscreteTrajectorySegment {
absl::Status Append(Instant const& t,
DegreesOfFreedom<Frame> const& degrees_of_freedom);

// Removes all points with a time greater than or equal to |t| (1st overload)
// or starting at |begin| (2nd overload).
void ForgetAfter(Instant const& t);
void ForgetAfter(typename Timeline::const_iterator begin);

// Removes all points with a time strictly less than |t| (1st overload) or
// ending at |end| (2nd overload).
void ForgetBefore(Instant const& t);
void ForgetBefore(typename Timeline::const_iterator end);

20 changes: 16 additions & 4 deletions physics/discrete_trajectory_segment_body.hpp
Original file line number Diff line number Diff line change
@@ -111,18 +111,30 @@ absl::Status DiscreteTrajectorySegment<Frame>::Append(
}

template<typename Frame>
void DiscreteTrajectorySegment<Frame>::ForgetAfter(Instant const& t) {}
void DiscreteTrajectorySegment<Frame>::ForgetAfter(Instant const& t) {
ForgetAfter(timeline_.lower_bound(t));
// TODO(phl): Downsampling.
}

template<typename Frame>
void DiscreteTrajectorySegment<Frame>::ForgetAfter(
typename Timeline::const_iterator const begin) {}
typename Timeline::const_iterator const begin) {
timeline_.erase(begin, timeline_.end());
// TODO(phl): Downsampling.
}

template<typename Frame>
void DiscreteTrajectorySegment<Frame>::ForgetBefore(Instant const& t) {}
void DiscreteTrajectorySegment<Frame>::ForgetBefore(Instant const& t) {
ForgetBefore(timeline_.lower_bound(t));
// TODO(phl): Downsampling.
}

template<typename Frame>
void DiscreteTrajectorySegment<Frame>::ForgetBefore(
typename Timeline::const_iterator const end) {}
typename Timeline::const_iterator const end) {
timeline_.erase(timeline_.begin(), end);
// TODO(phl): Downsampling.
}

template<typename Frame>
typename DiscreteTrajectorySegment<Frame>::Timeline::const_iterator
38 changes: 38 additions & 0 deletions physics/discrete_trajectory_segment_test.cpp
Original file line number Diff line number Diff line change
@@ -36,6 +36,14 @@ class DiscreteTrajectorySegmentTest : public ::testing::Test {
segment_->Append(t0_ + 11 * Second, unmoving_origin_);
}

void ForgetAfter(Instant const& t) {
segment_->ForgetAfter(t);
}

void ForgetBefore(Instant const& t) {
segment_->ForgetBefore(t);
}

DiscreteTrajectorySegment<World>* segment_;
internal_discrete_trajectory_types::Segments<World> segments_;
Instant const t0_;
@@ -106,5 +114,35 @@ TEST_F(DiscreteTrajectorySegmentTest, EmptySize) {
EXPECT_EQ(5, segment_->size());
}

TEST_F(DiscreteTrajectorySegmentTest, ForgetAfterExisting) {
ForgetAfter(t0_ + 5 * Second);
EXPECT_EQ(t0_ + 3 * Second, segment_->rbegin()->first);
}

TEST_F(DiscreteTrajectorySegmentTest, ForgetAfterNonexisting) {
ForgetAfter(t0_ + 6 * Second);
EXPECT_EQ(t0_ + 5 * Second, segment_->rbegin()->first);
}

TEST_F(DiscreteTrajectorySegmentTest, ForgetAfterPastTheEnd) {
ForgetAfter(t0_ + 29 * Second);
EXPECT_EQ(t0_ + 11 * Second, segment_->rbegin()->first);
}

TEST_F(DiscreteTrajectorySegmentTest, ForgetBeforeExisting) {
ForgetBefore(t0_ + 7 * Second);
EXPECT_EQ(t0_ + 7 * Second, segment_->begin()->first);
}

TEST_F(DiscreteTrajectorySegmentTest, ForgetBeforeNonexisting) {
ForgetBefore(t0_ + 6 * Second);
EXPECT_EQ(t0_ + 7 * Second, segment_->begin()->first);
}

TEST_F(DiscreteTrajectorySegmentTest, ForgetBeforeTheBeginning) {
ForgetBefore(t0_ + 1 * Second);
EXPECT_EQ(t0_ + 2 * Second, segment_->begin()->first);
}

} // namespace physics
} // namespace principia