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: b50bf9ce80ec
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9324301616ac
Choose a head ref

Commits on Oct 3, 2021

  1. Range.

    pleroy committed Oct 3, 2021
    Copy the full SHA
    0fba0ad View commit details
  2. Segment iterator.

    pleroy committed Oct 3, 2021
    Copy the full SHA
    47e7cd7 View commit details
  3. Iterator and test.

    pleroy committed Oct 3, 2021
    Copy the full SHA
    d3bf299 View commit details
  4. Faking doesn't work so well.

    pleroy committed Oct 3, 2021
    Copy the full SHA
    6879461 View commit details
  5. Cleanups.

    pleroy committed Oct 3, 2021
    Copy the full SHA
    951f2c8 View commit details
  6. Another attempt at faking.

    pleroy committed Oct 3, 2021
    Copy the full SHA
    7d88318 View commit details

Commits on Oct 4, 2021

  1. Copy the full SHA
    3ef266e View commit details
  2. Something that links.

    pleroy committed Oct 4, 2021
    Copy the full SHA
    297765f View commit details
  3. Tests that pass.

    pleroy committed Oct 4, 2021
    Copy the full SHA
    8c54c7d View commit details
  4. Copy the full SHA
    5dddf39 View commit details
  5. Test restructuring.

    pleroy committed Oct 4, 2021
    Copy the full SHA
    284064b View commit details
  6. It compiles.

    pleroy committed Oct 4, 2021
    Copy the full SHA
    1e97903 View commit details

Commits on Oct 5, 2021

  1. Copy the full SHA
    93ea005 View commit details
  2. Some more tests pass.

    pleroy committed Oct 5, 2021
    Copy the full SHA
    120980b View commit details
  3. Tips.

    pleroy committed Oct 5, 2021
    Copy the full SHA
    e703ffe View commit details
  4. The tests pass.

    pleroy committed Oct 5, 2021
    Copy the full SHA
    7386a04 View commit details
  5. Copy the full SHA
    009e87f View commit details

Commits on Oct 7, 2021

  1. Copy the full SHA
    5689992 View commit details
  2. Reimplement.

    pleroy committed Oct 7, 2021
    Copy the full SHA
    068d937 View commit details
  3. Copy the full SHA
    408fd52 View commit details
  4. Readying for review.

    pleroy committed Oct 7, 2021
    Copy the full SHA
    b3a909b View commit details

Commits on Oct 8, 2021

  1. Merge.

    pleroy committed Oct 8, 2021
    Copy the full SHA
    a825b5f View commit details
  2. Consequences of merging.

    pleroy committed Oct 8, 2021
    Copy the full SHA
    763f65a View commit details
  3. Readying for review.

    pleroy committed Oct 8, 2021
    Copy the full SHA
    f4406ea View commit details
  4. Lint.

    pleroy committed Oct 8, 2021
    Copy the full SHA
    5c61d02 View commit details

Commits on Oct 9, 2021

  1. Merge pull request #3142 from pleroy/Iterators

    DiscreteTrajectoryIterator
    pleroy authored Oct 9, 2021
    Copy the full SHA
    9324301 View commit details
20 changes: 12 additions & 8 deletions physics/discrete_trajectory2.hpp
Original file line number Diff line number Diff line change
@@ -5,6 +5,7 @@
#include <vector>

#include "absl/container/btree_map.h"
#include "base/macros.hpp"
#include "base/not_null.hpp"
#include "geometry/named_quantities.hpp"
#include "physics/degrees_of_freedom.hpp"
@@ -18,8 +19,9 @@
namespace principia {
namespace physics {

template<typename Frame>
class DiscreteTrajectorySegment;
FORWARD_DECLARE_FROM(discrete_trajectory_segment,
TEMPLATE(typename Frame) class,
DiscreteTrajectorySegment);

namespace internal_discrete_trajectory {

@@ -65,8 +67,8 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {

SegmentIterator NewSegment();

DiscreteTrajectory DetachSegments(iterator begin);
SegmentIterator AttachSegments(DiscreteTrajectory&& trajectory);
DiscreteTrajectory2 DetachSegments(iterator begin);
SegmentIterator AttachSegments(DiscreteTrajectory2&& trajectory);
void DeleteSegments(iterator begin);

void ForgetAfter(Instant const& t);
@@ -78,6 +80,9 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {
void Append(Instant const& t,
DegreesOfFreedom<Frame> const& degrees_of_freedom);

Instant t_min() const override;
Instant t_max() const override;

Position<Frame> EvaluatePosition(Instant const& time) const override;
Velocity<Frame> EvaluateVelocity(Instant const& time) const override;
DegreesOfFreedom<Frame> EvaluateDegreesOfFreedom(
@@ -95,9 +100,9 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {

template<typename F = Frame,
typename = std::enable_if_t<base::is_serializable_v<F>>>
static not_null<std::unique_ptr<DiscreteTrajectory>> ReadFromMessage(
static not_null<std::unique_ptr<DiscreteTrajectory2>> ReadFromMessage(
serialization::DiscreteTrajectory const& message,
std::vector<DiscreteTrajectory<Frame>**> const& tracked);
std::vector<DiscreteTrajectory2**> const& tracked);

private:
using Segments = internal_discrete_trajectory_types::Segments<Frame>;
@@ -107,8 +112,7 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {

} // namespace internal_discrete_trajectory

template<typename Frame>
using DiscreteTrajectory2 = internal_discrete_trajectory::DiscreteTrajectory2;
using internal_discrete_trajectory::DiscreteTrajectory2;

} // namespace physics
} // namespace principia
42 changes: 39 additions & 3 deletions physics/discrete_trajectory_iterator.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include <optional>

#include "absl/container/btree_map.h"
#include "geometry/named_quantities.hpp"
#include "physics/degrees_of_freedom.hpp"
@@ -27,14 +29,46 @@ class DiscreteTrajectoryIterator {
DiscreteTrajectoryIterator operator++(int);
DiscreteTrajectoryIterator operator--(int);

typename DiscreteTrajectory<Frame>::value_type const& operator*() const;
typename DiscreteTrajectory<Frame>::value_type const* operator->() const;
typename
internal_discrete_trajectory_types::Timeline<Frame>::value_type const&
operator*() const;
typename
internal_discrete_trajectory_types::Timeline<Frame>::value_type const*
operator->() const;

bool operator==(DiscreteTrajectoryIterator const& other) const;
bool operator!=(DiscreteTrajectoryIterator const& other) const;

private:
using Timeline = internal_discrete_trajectory_types::Timeline<Frame>;

// Optional because we cannot construct a point iterator in the end segment.
using OptionalTimelineConstIterator =
std::optional<typename Timeline::const_iterator>;

DiscreteTrajectoryIterator(DiscreteTrajectorySegmentIterator<Frame> segment,
OptionalTimelineConstIterator point);

static bool is_at_end(OptionalTimelineConstIterator point);

static typename Timeline::const_iterator& iterator(
OptionalTimelineConstIterator& point);
static typename Timeline::const_iterator const& iterator(
OptionalTimelineConstIterator const& point);

// |point_| is always an iterator in the timeline of the segment denoted by
// |segment_|. When |segment_| is at the end of its list, |point_| is
// nullopt. It is possible to have repeated times in a segment or across
// segments and the iterator will skip them, so that they will appear as a
// single point to clients.
DiscreteTrajectorySegmentIterator<Frame> segment_;
Timeline::const_iterator point_;
OptionalTimelineConstIterator point_;

// The last time that was seen by the iterator. Used to skip over repeated
// times.
std::optional<Instant> previous_time_;

friend class DiscreteTrajectoryIteratorTest;
};

} // namespace internal_discrete_trajectory_iterator
@@ -43,3 +77,5 @@ using internal_discrete_trajectory_iterator::DiscreteTrajectoryIterator;

} // namespace physics
} // namespace principia

#include "physics/discrete_trajectory_iterator_body.hpp"
142 changes: 142 additions & 0 deletions physics/discrete_trajectory_iterator_body.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#pragma once

#include "physics/discrete_trajectory_iterator.hpp"

#include "geometry/named_quantities.hpp"

namespace principia {
namespace physics {
namespace internal_discrete_trajectory_iterator {

using geometry::Instant;

template<typename Frame>
DiscreteTrajectoryIterator<Frame>&
DiscreteTrajectoryIterator<Frame>::operator++() {
CHECK(!is_at_end(point_));
auto& point = iterator(point_);
for (;;) {
if (point == --segment_->timeline_end()) {
++segment_;
if (segment_ == segment_.end()) {
point_.reset();
break;
} else {
point = segment_->timeline_begin();
}
} else {
++point;
}
if (point->first != previous_time_) {
previous_time_ = point->first;
break;
}
}
return *this;
}

template<typename Frame>
DiscreteTrajectoryIterator<Frame>&
DiscreteTrajectoryIterator<Frame>::operator--() {
if (is_at_end(point_)) {
segment_ = --segment_.end();
point_ = --segment_->timeline_end();
} else {
auto& point = iterator(point_);
for (;;) {
if (point == segment_->timeline_begin()) {
CHECK(segment_ != segment_.begin());
--segment_;
point = --segment_->timeline_end();
} else {
--point;
}
if (point->first != previous_time_) {
previous_time_ = point->first;
break;
}
}
}
return *this;
}

template<typename Frame>
DiscreteTrajectoryIterator<Frame>
DiscreteTrajectoryIterator<Frame>::operator++(int) { // NOLINT
auto const initial = *this;
++*this;
return initial;
}

template<typename Frame>
DiscreteTrajectoryIterator<Frame>
DiscreteTrajectoryIterator<Frame>::operator--(int) { // NOLINT
auto const initial = *this;
--*this;
return initial;
}

template<typename Frame>
typename internal_discrete_trajectory_types::Timeline<Frame>::value_type const&
DiscreteTrajectoryIterator<Frame>::operator*() const {
CHECK(!is_at_end(point_));
return *iterator(point_);
}

template<typename Frame>
typename internal_discrete_trajectory_types::Timeline<Frame>::value_type const*
DiscreteTrajectoryIterator<Frame>::operator->() const {
CHECK(!is_at_end(point_));
return &*iterator(point_);
}

template<typename Frame>
bool DiscreteTrajectoryIterator<Frame>::operator==(
DiscreteTrajectoryIterator const& other) const {
if (is_at_end(point_)) {
return segment_ == other.segment_ && is_at_end(other.point_);
} else if (is_at_end(other.point_)) {
return false;
} else {
return iterator(point_)->first == iterator(other.point_)->first;
}
}

template<typename Frame>
bool DiscreteTrajectoryIterator<Frame>::operator!=(
DiscreteTrajectoryIterator const& other) const {
return !operator==(other);
}

template<typename Frame>
DiscreteTrajectoryIterator<Frame>::DiscreteTrajectoryIterator(
DiscreteTrajectorySegmentIterator<Frame> const segment,
OptionalTimelineConstIterator const point)
: segment_(segment),
point_(point) {}

template<typename Frame>
bool DiscreteTrajectoryIterator<Frame>::is_at_end(
OptionalTimelineConstIterator const point) {
return !point.has_value();
}

template<typename Frame>
typename DiscreteTrajectoryIterator<Frame>::Timeline::const_iterator&
DiscreteTrajectoryIterator<Frame>::iterator(
OptionalTimelineConstIterator& point) {
DCHECK(point.has_value());
return point.value();
}

template<typename Frame>
typename DiscreteTrajectoryIterator<Frame>::Timeline::const_iterator const&
DiscreteTrajectoryIterator<Frame>::iterator(
OptionalTimelineConstIterator const& point) {
DCHECK(point.has_value());
return point.value();
}

} // namespace internal_discrete_trajectory_iterator
} // namespace physics
} // namespace principia
Loading