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

Commits on Aug 13, 2021

  1. Copy the full SHA
    5453eae View commit details
  2. Copy the full SHA
    65c1e4e View commit details
  3. Reorder methods.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    bf8165b View commit details
  4. Simplify ForgetAfter.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    da44832 View commit details
  5. Copy the full SHA
    75c742e View commit details
  6. Append and ForgetAfter.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    d9e86cd View commit details
  7. ForgetBefore.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    e219646 View commit details
  8. Construction and writing.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    9aff1b6 View commit details
  9. ExtractIfFull

    pleroy committed Aug 13, 2021
    Copy the full SHA
    b5a5054 View commit details
  10. Change all the things.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    1fe434f View commit details
  11. One test passing.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    2e843ae View commit details
  12. Deserialization.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    4017f11 View commit details
  13. Comments.

    pleroy committed Aug 13, 2021
    Copy the full SHA
    8b7cf53 View commit details

Commits on Aug 15, 2021

  1. Merge.

    pleroy committed Aug 15, 2021
    Copy the full SHA
    0d84ae5 View commit details
  2. Copy the full SHA
    32eac32 View commit details
  3. Copy the full SHA
    5bb9c86 View commit details
  4. Readying.

    pleroy committed Aug 15, 2021
    Copy the full SHA
    87fa256 View commit details
  5. Typo.

    pleroy committed Aug 15, 2021
    Copy the full SHA
    6e45c69 View commit details
  6. Merge pull request #3097 from pleroy/Downsampling

    Add support for downsampling forks
    pleroy authored Aug 15, 2021
    Copy the full SHA
    18d78a8 View commit details
Showing with 39 additions and 30 deletions.
  1. +7 −4 physics/discrete_trajectory.hpp
  2. +28 −16 physics/discrete_trajectory_body.hpp
  3. +3 −2 physics/forkable.hpp
  4. +0 −1 physics/forkable_body.hpp
  5. +0 −6 physics/forkable_test.cpp
  6. +1 −1 serialization/physics.proto
11 changes: 7 additions & 4 deletions physics/discrete_trajectory.hpp
Original file line number Diff line number Diff line change
@@ -61,6 +61,9 @@ class DiscreteTrajectoryIterator
protected:
not_null<DiscreteTrajectoryIterator*> that() override;
not_null<DiscreteTrajectoryIterator const*> that() const override;

template<typename>
friend class internal_discrete_trajectory::DiscreteTrajectory;
};

} // namespace internal_forkable
@@ -230,16 +233,16 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,
const;
static Downsampling ReadFromMessage(
serialization::DiscreteTrajectory::Downsampling const& message,
Timeline const& timeline);
DiscreteTrajectory const& trajectory);

private:
// The maximal number of dense intervals before downsampling occurs.
std::int64_t const max_dense_intervals_;
// The tolerance for downsampling with |FitHermiteSpline|.
Length const tolerance_;

// TODO(phl): Note that, with forks, the iterators in this vector may belong
// to different maps.
// Note that, because of forks, the iterators in this vector may belong to
// different maps.
std::vector<TimelineConstIterator> dense_iterators_;
};

@@ -260,7 +263,7 @@ class DiscreteTrajectory : public Forkable<DiscreteTrajectory<Frame>,

// Updates the downsampling object to reflect that a point was appended to
// this trajectory.
absl::Status UpdateDownsampling(TimelineConstIterator const appended);
absl::Status UpdateDownsampling(TimelineConstIterator appended);

Timeline timeline_;

44 changes: 28 additions & 16 deletions physics/discrete_trajectory_body.hpp
Original file line number Diff line number Diff line change
@@ -233,6 +233,7 @@ void DiscreteTrajectory<Frame>::ForgetAfter(Instant const& time) {

template<typename Frame>
void DiscreteTrajectory<Frame>::ForgetBefore(Instant const& time) {
CHECK(this->is_root());
this->CheckNoForksBefore(time);
if (downsampling_.has_value()) {
downsampling_->ForgetBefore(time);
@@ -250,8 +251,13 @@ void DiscreteTrajectory<Frame>::SetDownsampling(
Length const& tolerance) {
CHECK(!downsampling_.has_value());
downsampling_.emplace(max_dense_intervals, tolerance);
// TODO(phl): If this trajectory is a fork, the fork point should be appended
// first.

// For a fork, the fork point is taken into account for downsampling: it is
// always preserved, but the second point preserved after downsampling may be
// farther down the timeline of this trajectory.
if (!this->is_root()) {
downsampling_->Append(this->Fork().current());
}
for (auto it = timeline_.cbegin(); it != timeline_.cend(); ++it) {
downsampling_->Append(it);
}
@@ -474,25 +480,27 @@ template<typename Frame>
typename DiscreteTrajectory<Frame>::Downsampling
DiscreteTrajectory<Frame>::Downsampling::ReadFromMessage(
serialization::DiscreteTrajectory::Downsampling const& message,
Timeline const& timeline) {
DiscreteTrajectory const& trajectory) {
bool const is_pre_grotendieck_haar = message.has_start_of_dense_timeline();
Downsampling downsampling(message.max_dense_intervals(),
Length::ReadFromMessage(message.tolerance()));
if (is_pre_grotendieck_haar) {
// No support for forks in legacy saves, so |find| will succeed and ++ is
// safe.
auto it = timeline.find(
auto it = trajectory.timeline_.find(
Instant::ReadFromMessage(message.start_of_dense_timeline()));
CHECK(it != timeline.end());
for (; it != timeline.end(); ++it) {
CHECK(it != trajectory.timeline_.end());
for (; it != trajectory.timeline_.end(); ++it) {
downsampling.Append(it);
}
} else {
for (auto const& dense_time : message.dense_timeline()) {
// TODO(phl): This |find| won't work for the first point of a fork.
auto const it = timeline.find(Instant::ReadFromMessage(dense_time));
CHECK(it != timeline.end());
downsampling.Append(it);
auto const t = Instant::ReadFromMessage(dense_time);
// This call to |Find| is needed because we don't know in what timeline
// |t| lives.
auto const it = trajectory.Find(t);
CHECK(it != trajectory.end());
downsampling.Append(it.current());
}
}
return downsampling;
@@ -629,7 +637,7 @@ void DiscreteTrajectory<Frame>::FillSubTreeFromMessage(
}
if (message.has_downsampling()) {
downsampling_.emplace(
Downsampling::ReadFromMessage(message.downsampling(), timeline_));
Downsampling::ReadFromMessage(message.downsampling(), *this));
}
Forkable<DiscreteTrajectory, Iterator, DiscreteTrajectoryTraits<Frame>>::
FillSubTreeFromMessage(message, tracked);
@@ -651,7 +659,7 @@ Hermite3<Instant, Position<Frame>> DiscreteTrajectory<Frame>::GetInterpolation(
template<typename Frame>
absl::Status DiscreteTrajectory<Frame>::UpdateDownsampling(
TimelineConstIterator const appended) {
this->CheckNoForksBefore(this->back().time);
this->CheckNoForksBefore(appended->first);
downsampling_->Append(appended);
if (downsampling_->full()) {
auto const dense_iterators = downsampling_->dense_iterators();
@@ -667,23 +675,27 @@ absl::Status DiscreteTrajectory<Frame>::UpdateDownsampling(
return right_endpoints.status();
}
if (right_endpoints->empty()) {
right_endpoints->push_back(dense_iterators.end() - 1);
right_endpoints->push_back(dense_iterators.cend() - 1);
}

// Poke holes in the timeline at the places given by |right_endpoints|.
TimelineConstIterator left = dense_iterators.front();
// Note that this code carefully avoids incrementing |dense_iterators[0]| as
// it may live in a different timeline than the others.
CHECK_LE(1, dense_iterators.size());
TimelineConstIterator left = dense_iterators[1];
for (const auto& it_in_dense_iterators : right_endpoints.value()) {
TimelineConstIterator const right = *it_in_dense_iterators;
// TODO(phl): Use of ++ won't work with forks.
timeline_.erase(++left, right);
timeline_.erase(left, right);
left = right;
++left;
}

// Re-append the dense iterators that have not been consumed.
for (auto it = right_endpoints->back(); it < dense_iterators.cend(); ++it) {
downsampling_->Append(*it);
}
CHECK(!downsampling_->empty());
CHECK(!downsampling_->full());
}
return absl::OkStatus();
}
5 changes: 3 additions & 2 deletions physics/forkable.hpp
Original file line number Diff line number Diff line change
@@ -196,8 +196,9 @@ class Forkable {
// at or after the fork time of this trajectory, if any.
void DeleteAllForksAfter(Instant const& time);

// Checks that there exist no forks for times (strictly) less than |time|.
// This trajectory must be a root.
// Checks that there exist no forks for times (strictly) less than |time| in
// the timelime of this trajectory (i.e., after its fork point if it's not a
// root).
void CheckNoForksBefore(Instant const& time);

// This trajectory need not be a root. The entire tree rooted at this
1 change: 0 additions & 1 deletion physics/forkable_body.hpp
Original file line number Diff line number Diff line change
@@ -462,7 +462,6 @@ DeleteAllForksAfter(Instant const& time) {
template<typename Tr4jectory, typename It3rator, typename Traits>
void Forkable<Tr4jectory, It3rator, Traits>::
CheckNoForksBefore(Instant const& time) {
CHECK(is_root()) << "CheckNoForksBefore on a nonroot trajectory";
// Get an iterator denoting the first entry with time >= |time|. Check that
// there are no forks before it. A fork with time == |time| is fine.
auto const it = children_.lower_bound(time);
6 changes: 0 additions & 6 deletions physics/forkable_test.cpp
Original file line number Diff line number Diff line change
@@ -466,12 +466,6 @@ TEST_F(ForkableTest, DeleteAllForksAfterSuccess) {
}

TEST_F(ForkableDeathTest, CheckNoForksBeforeError) {
EXPECT_DEATH({
trajectory_.push_back(t1_);
not_null<FakeTrajectory*> const fork =
trajectory_.NewFork(trajectory_.timeline_find(t1_));
fork->CheckNoForksBefore(t1_);
}, "nonroot");
EXPECT_DEATH({
trajectory_.push_back(t1_);
trajectory_.push_back(t2_);
2 changes: 1 addition & 1 deletion serialization/physics.proto
Original file line number Diff line number Diff line change
@@ -80,7 +80,7 @@ message ContinuousTrajectory {

message DiscreteTrajectory {
// A marker to indicate that a fork doesn't have its position tracked.
// Added in Groethendieck/Haar.
// Added in Grothendieck/Haar.
enum ForkPosition {
MISSING_FORK_POSITION = -1;
}