Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headers for the new-style DiscreteTrajectory #3137

Merged
merged 4 commits into from
Oct 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions physics/discrete_trajectory2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "physics/degrees_of_freedom.hpp"
#include "physics/discrete_trajectory_iterator.hpp"
#include "physics/discrete_trajectory_segment_iterator.hpp"
#include "physics/discrete_trajectory_segment_range.hpp"
#include "physics/discrete_trajectory_types.hpp"
#include "physics/trajectory.hpp"
#include "serialization/physics.pb.h"
Expand All @@ -30,8 +31,13 @@ using physics::DegreesOfFreedom;
template<typename Frame>
class DiscreteTrajectory2 : public Trajectory<Frame> {
public:
using Iterator = DiscreteTrajectoryIterator<Frame>;
using iterator = DiscreteTrajectoryIterator<Frame>;
using reverse_iterator = std::reverse_iterator<iterator>;
using SegmentIterator = DiscreteTrajectorySegmentIterator<Frame>;
using ReverseSegmentIterator = std::reverse_iterator<SegmentIterator>;
using SegmentRange = DiscreteTrajectorySegmentRange<SegmentIterator>;
using ReverseSegmentRange =
DiscreteTrajectorySegmentRange<ReverseSegmentIterator>;

DiscreteTrajectory2() = default;

Expand All @@ -41,35 +47,31 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {
DiscreteTrajectory2(const DiscreteTrajectory2&) = delete;
DiscreteTrajectory2& operator=(const DiscreteTrajectory2&) = delete;

Iterator begin() const;
Iterator end() const;
iterator begin() const;
iterator end() const;

Iterator rbegin() const;
Iterator rend() const;
reverse_iterator rbegin() const;
reverse_iterator rend() const;

Iterator find(Instant const& t) const;
iterator find(Instant const& t) const;

Iterator lower_bound(Instant const& t) const;
Iterator upper_bound(Instant const& t) const;
iterator lower_bound(Instant const& t) const;
iterator upper_bound(Instant const& t) const;

SegmentIterator segments_begin() const;
SegmentIterator segments_end() const;

SegmentIterator segments_rbegin() const;
SegmentIterator segments_rend() const;
SegmentRange segments() const;
ReverseSegmentRange rsegments() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the Right Thing to do is to have only segments and use an adapter to iterate backward (in C++20 that would be https://en.cppreference.com/w/cpp/ranges/reverse_view, maybe absl has a thing in the meantime, or we can write one in base, we should have make_reverse_iterator).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a TODO to fix this once we have C++20.


SegmentIterator NewSegment();

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

void ForgetAfter(Instant const& t);
void ForgetAfter(Iterator begin);
void ForgetAfter(iterator begin);

void ForgetBefore(Instant const& t);
void ForgetBefore(Iterator end);
void ForgetBefore(iterator end);

void Append(Instant const& t,
DegreesOfFreedom<Frame> const& degrees_of_freedom);
Expand All @@ -82,12 +84,12 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {
void WriteToMessage(
not_null<serialization::DiscreteTrajectory*> message,
std::vector<SegmentIterator> const& tracked,
std::vector<Iterator> const& exact) const;
std::vector<iterator> const& exact) const;
void WriteToMessage(
not_null<serialization::DiscreteTrajectory*> message,
Iterator begin, Iterator end,
iterator begin, iterator end,
std::vector<SegmentIterator> const& tracked,
std::vector<Iterator> const& exact) const;
std::vector<iterator> const& exact) const;

template<typename F = Frame,
typename = std::enable_if_t<base::is_serializable_v<F>>>
Expand All @@ -106,5 +108,5 @@ class DiscreteTrajectory2 : public Trajectory<Frame> {
template<typename Frame>
using DiscreteTrajectory2 = internal_discrete_trajectory::DiscreteTrajectory2;

} // namespace principia
} // namespace physics
} // namespace principia
2 changes: 1 addition & 1 deletion physics/discrete_trajectory_segment.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ template<typename Frame>
using DiscreteTrajectorySegment =
internal_discrete_trajectory_segment::DiscreteTrajectorySegment;

} // namespace principia
} // namespace physics
} // namespace principia
2 changes: 1 addition & 1 deletion physics/discrete_trajectory_segment_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ using DiscreteTrajectorySegmentIterator =
internal_discrete_trajectory_segment_iterator::
DiscreteTrajectorySegmentIterator;

} // namespace principia
} // namespace physics
} // namespace principia
37 changes: 37 additions & 0 deletions physics/discrete_trajectory_segment_range.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <list>
#include <memory>

#include "absl/container/btree_map.h"
#include "geometry/named_quantities.hpp"
#include "physics/degrees_of_freedom.hpp"

namespace principia {
namespace physics {
namespace internal_discrete_trajectory_segment_range {

using geometry::Instant;
using physics::DegreesOfFreedom;

template<typename Iterator>
class DiscreteTrajectorySegmentRange {
public:
DiscreteTrajectorySegmentRange() = default;

Iterator begin() const;
Iterator end() const;

private:
Iterator begin_;
Iterator end_;
};

} // namespace internal_discrete_trajectory_segment_range

template<typename Iterator>
using DiscreteTrajectorySegmentRange =
internal_discrete_trajectory_segment_range::DiscreteTrajectorySegmentRange;

} // namespace physics
} // namespace principia
2 changes: 1 addition & 1 deletion physics/discrete_trajectory_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ template<typename Frame>
using Timeline = absl::btree_map<Instant, DegreesOfFreedom<Frame>>;

} // namespace internal_discrete_trajectory_types
} // namespace principia
} // namespace physics
} // namespace principia
1 change: 1 addition & 0 deletions physics/physics.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<ClInclude Include="discrete_trajectory_iterator.hpp" />
<ClInclude Include="discrete_trajectory_segment.hpp" />
<ClInclude Include="discrete_trajectory_segment_iterator.hpp" />
<ClInclude Include="discrete_trajectory_segment_range.hpp" />
<ClInclude Include="discrete_trajectory_types.hpp" />
<ClInclude Include="mechanical_system.hpp" />
<ClInclude Include="mechanical_system_body.hpp" />
Expand Down
3 changes: 3 additions & 0 deletions physics/physics.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@
<ClInclude Include="discrete_trajectory_types.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="discrete_trajectory_segment_range.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="degrees_of_freedom_test.cpp">
Expand Down