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

Commits on Jul 11, 2021

  1. Copy the full SHA
    4a2c29c View commit details
  2. Copy the full SHA
    f4f038c View commit details
  3. Merge pull request #3059 from pleroy/DownsamplingForks2

    Change downsampling to work for non-root trajectories
    pleroy authored Jul 11, 2021
    Copy the full SHA
    a000b78 View commit details
Showing with 46 additions and 2 deletions.
  1. +0 −2 physics/discrete_trajectory_body.hpp
  2. +46 −0 physics/discrete_trajectory_test.cpp
2 changes: 0 additions & 2 deletions physics/discrete_trajectory_body.hpp
Original file line number Diff line number Diff line change
@@ -263,7 +263,6 @@ template<typename Frame>
void DiscreteTrajectory<Frame>::SetDownsampling(
std::int64_t const max_dense_intervals,
Length const& tolerance) {
CHECK(this->is_root());
CHECK(!downsampling_.has_value());
downsampling_.emplace(
max_dense_intervals, tolerance, timeline_.begin(), timeline_);
@@ -647,7 +646,6 @@ absl::Status DiscreteTrajectory<Frame>::UpdateDownsampling() {
if (timeline_.size() == 1) {
downsampling_->SetStartOfDenseTimeline(timeline_.begin(), timeline_);
} else {
this->CheckNoForksBefore(this->back().time);
downsampling_->increment_dense_intervals(timeline_);
if (downsampling_->reached_max_dense_intervals()) {
std::vector<TimelineConstIterator> dense_iterators;
46 changes: 46 additions & 0 deletions physics/discrete_trajectory_test.cpp
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ using geometry::Position;
using geometry::R3Element;
using geometry::Vector;
using numerics::DoublePrecision;
using quantities::Abs;
using quantities::AngularFrequency;
using quantities::Cos;
using quantities::Length;
@@ -884,6 +885,51 @@ TEST_F(DiscreteTrajectoryTest, Downsampling) {
<< *std::max_element(errors.begin(), errors.end());
}

TEST_F(DiscreteTrajectoryTest, DownsamplingForks) {
// The number of dense intervals does not divide the lengths of the
// trajectories.
int const max_dense_intervals = 73;
Length const tolerance = 1 * Milli(Metre);

DiscreteTrajectory<World> root;
root.SetDownsampling(max_dense_intervals, tolerance);
AngularFrequency const ω = 3 * Radian / Second;
Length const r = 2 * Metre;
Time const Δt = 10 * Milli(Second);
Instant const t1 = t0_;
Instant const t2 = t0_ + 10 * Second;
auto const root_tmax = AppendCircularTrajectory(ω, r, Δt, t1, t2, root);

auto fork1 = root.NewForkAtLast();
fork1->SetDownsampling(max_dense_intervals, tolerance);
Instant const t3 = t2 + 10 * Second;
auto const fork1_tmax =
AppendCircularTrajectory(ω, r, Δt, root_tmax, t3, *fork1);

// A short fork with no downsampling
auto fork2 = fork1->NewForkAtLast();
fork2->SetDownsampling(max_dense_intervals, tolerance);
Instant const t4 = t3 + 300 * Milli(Second);
auto const fork2_tmax =
AppendCircularTrajectory(ω, r, Δt, fork1_tmax, t4, *fork2);

auto fork3 = fork2->NewForkAtLast();
fork3->SetDownsampling(max_dense_intervals, tolerance);
Instant const t5 = t4 + 10 * Second;
AppendCircularTrajectory(ω, r, Δt, fork2_tmax, t5, *fork3);

// Roughly 55 points per downsampled segments.
EXPECT_THAT(root.Size(), Eq(56));
EXPECT_THAT(fork1->Size(), Eq(root.Size() + 55));
EXPECT_THAT(fork2->Size(), Eq(fork1->Size() + 30));
EXPECT_THAT(fork3->Size(), Eq(fork2->Size() + 55));

for (Instant t = t0_; t <= fork3->t_max(); t += Δt) {
EXPECT_THAT((fork3->EvaluatePosition(t) - World::origin).Norm(),
AbsoluteErrorFrom(r, Lt(0.99 * Milli(Metre))));
}
}

TEST_F(DiscreteTrajectoryTest, DownsamplingSerialization) {
DiscreteTrajectory<World> circle;
circle.SetDownsampling(/*max_dense_intervals=*/50,