Skip to content

Commit 90e49e6

Browse files
authored
Merge pull request #3173 from pleroy/LeftEndpoints
Change the representation of the time-to-segment map
2 parents 551ea14 + 88371fb commit 90e49e6

File tree

3 files changed

+215
-100
lines changed

3 files changed

+215
-100
lines changed

physics/discrete_traject0ry.hpp

+19-12
Original file line numberDiff line numberDiff line change
@@ -123,26 +123,34 @@ class DiscreteTraject0ry : public Trajectory<Frame> {
123123
using DownsamplingParameters =
124124
internal_discrete_trajectory_types::DownsamplingParameters;
125125
using Segments = internal_discrete_trajectory_types::Segments<Frame>;
126+
using SegmentByLeftEndpoint =
127+
absl::btree_map<Instant, typename Segments::iterator>;
126128

127129
// This constructor leaves the list of segments empty (but allocated) as well
128130
// as the time-to-segment mapping.
129131
explicit DiscreteTraject0ry(uninitialized_t);
130132

131-
typename Segments::iterator FindSegment(Instant const& t);
132-
typename Segments::const_iterator FindSegment(Instant const& t) const;
133+
// Returns an iterator to a segment with extremities t1 and t2 such that
134+
// t ∈ [t1, t2[. For the last segment, t2 is assumed to be +∞. A 1-point
135+
// segment is never returned, unless it is the last one (because its upper
136+
// bound is assumed to be +∞). Returns segment_by_left_endpoint_->end() iff
137+
// the trajectory is empty(). Fails if t is before the first time of the
138+
// trajectory.
139+
typename SegmentByLeftEndpoint::iterator FindSegment(Instant const& t);
140+
typename SegmentByLeftEndpoint::const_iterator
141+
FindSegment(Instant const& t) const;
133142

134143
// Checks if this objects is in a consistent state, and returns an error
135144
// status with a relevant message if it isn't.
136145
absl::Status ValidateConsistency() const;
137146

138147
// Updates the segments self-pointers and the time-to-segment mapping after
139-
// segments have been spliced from |from| to |to|. The iterators indicate the
148+
// segments have been spliced from |from| to |to|. The iterator indicates the
140149
// segments to fix-up.
141150
static void AdjustAfterSplicing(
142151
DiscreteTraject0ry& from,
143152
DiscreteTraject0ry& to,
144-
typename Segments::iterator to_segments_begin,
145-
std::reverse_iterator<typename Segments::iterator> to_segments_rend);
153+
typename Segments::iterator to_segments_begin);
146154

147155
// Reads a pre-Ζήνων downsampling message and return the downsampling
148156
// parameters and the start of the dense timeline. The latter will have to be
@@ -174,13 +182,12 @@ class DiscreteTraject0ry : public Trajectory<Frame> {
174182
// DiscreteTrajectory moves. This field is never null and never empty.
175183
not_null<std::unique_ptr<Segments>> segments_;
176184

177-
// This list is never empty. For an empty trajectory, there is a sentinel
178-
// with time -∞ denoting the single segment of the trajectory. As soon as a
179-
// point is appended to the trajectory, the sentinel is removed and a bona
180-
// fide entry replaces it. To access the segment for time t, use
181-
// |--upper_bound(t)|.
182-
absl::btree_map<Instant,
183-
typename Segments::iterator> segment_by_left_endpoint_;
185+
// Maps time |t| to the last segment that start at time |t|. Does not contain
186+
// entries for empty segments (at the beginning of the trajectory) or for
187+
// 1-point segments that are not the last at their time. Empty iff the entire
188+
// trajectory is empty. Always updated using |insert_or_assign| to override
189+
// any preexisting segment with the same endpoint.
190+
SegmentByLeftEndpoint segment_by_left_endpoint_;
184191
};
185192

186193
} // namespace internal_discrete_traject0ry

0 commit comments

Comments
 (0)