@@ -123,26 +123,34 @@ class DiscreteTraject0ry : public Trajectory<Frame> {
123
123
using DownsamplingParameters =
124
124
internal_discrete_trajectory_types::DownsamplingParameters;
125
125
using Segments = internal_discrete_trajectory_types::Segments<Frame>;
126
+ using SegmentByLeftEndpoint =
127
+ absl::btree_map<Instant, typename Segments::iterator>;
126
128
127
129
// This constructor leaves the list of segments empty (but allocated) as well
128
130
// as the time-to-segment mapping.
129
131
explicit DiscreteTraject0ry (uninitialized_t );
130
132
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 ;
133
142
134
143
// Checks if this objects is in a consistent state, and returns an error
135
144
// status with a relevant message if it isn't.
136
145
absl::Status ValidateConsistency () const ;
137
146
138
147
// 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
140
149
// segments to fix-up.
141
150
static void AdjustAfterSplicing (
142
151
DiscreteTraject0ry& from,
143
152
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);
146
154
147
155
// Reads a pre-Ζήνων downsampling message and return the downsampling
148
156
// parameters and the start of the dense timeline. The latter will have to be
@@ -174,13 +182,12 @@ class DiscreteTraject0ry : public Trajectory<Frame> {
174
182
// DiscreteTrajectory moves. This field is never null and never empty.
175
183
not_null<std::unique_ptr<Segments>> segments_;
176
184
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_;
184
191
};
185
192
186
193
} // namespace internal_discrete_traject0ry
0 commit comments