Skip to content

Commit

Permalink
return one-sided values in interpolation helper
Browse files Browse the repository at this point in the history
  • Loading branch information
koide3 committed Nov 22, 2023
1 parent 518cda4 commit be4f9a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/glim/util/concurrent_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ class ConcurrentVector {
std::vector<T, Alloc> get_and_clear(int num_max) {
std::vector<T, Alloc> buffer;
std::lock_guard<std::mutex> lock(mutex);
if (values.empty()) {
return buffer;
}

if (values.size() <= num_max) {
buffer.assign(values.begin(), values.end());
values.clear();
Expand Down
6 changes: 6 additions & 0 deletions include/glim/util/interpolation_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ class InterpolationHelper {

InterpolationHelperResult find(const double stamp, StampedValue* left_ptr, StampedValue* right_ptr, int* remove_cursor_ptr) const {
if (values.empty() || values.back().first < stamp) {
if (!values.empty() && left_ptr) {
*left_ptr = values.back();
}
return InterpolationHelperResult::WAITING;
}

if (values.front().first > stamp) {
if (right_ptr) {
*right_ptr = values.front();
}
return InterpolationHelperResult::FAILURE;
}

Expand Down

0 comments on commit be4f9a3

Please sign in to comment.