Override Hood and Shooter goals with vision distance
Change-Id: I9741880fe7f96cf4208ca2cf75d584d683a30cea
diff --git a/aos/common/ring_buffer.h b/aos/common/ring_buffer.h
index 331991a..693ac95 100644
--- a/aos/common/ring_buffer.h
+++ b/aos/common/ring_buffer.h
@@ -26,8 +26,13 @@
}
}
+ void Shift() {
+ oldest_ = (oldest_ + 1) % buffer_size;
+ --size_;
+ }
+
// Return the value of the index requested, adjusted so that the RingBuffer
- // contians the oldest element first and the newest last.
+ // contains the oldest element first and the newest last.
Data &operator[](size_t index) {
return data_[(oldest_ + index) % buffer_size];
}
diff --git a/aos/common/ring_buffer_test.cc b/aos/common/ring_buffer_test.cc
index ca3f35d..bfaecba 100644
--- a/aos/common/ring_buffer_test.cc
+++ b/aos/common/ring_buffer_test.cc
@@ -67,5 +67,27 @@
}
}
+// Tests shifting from the front of the ringbuffer.
+TEST_F(RingBufferTest, RingBufferShift) {
+ // Add numbers 0-24 to the RingBuffer
+ for (int i = 0; i < 25; ++i) {
+ buffer_.Push(i);
+ }
+
+ // It should now be full
+ ASSERT_TRUE(buffer_.full());
+
+ buffer_.Shift();
+ buffer_.Shift();
+ buffer_.Shift();
+
+ ASSERT_EQ(buffer_.size(), 7);
+
+ // The buffer should now contain the numbers 18-24
+ for (size_t i = 0; i < buffer_.size(); ++i) {
+ ASSERT_EQ(18 + i, buffer_[i]);
+ }
+}
+
} // namespace testing
} // namespace aos