mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-02-05 13:28:16 +00:00
a/math: Let relation history report its size
This commit is contained in:
parent
8279a41c78
commit
aff7079dca
|
@ -84,7 +84,7 @@ m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation
|
|||
}
|
||||
|
||||
enum m_relation_history_result
|
||||
m_relation_history_get(struct m_relation_history *rh, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
|
||||
m_relation_history_get( struct m_relation_history *rh, uint64_t at_timestamp_ns, struct xrt_space_relation *out_relation)
|
||||
{
|
||||
XRT_TRACE_MARKER();
|
||||
os_mutex_lock(&rh->mutex);
|
||||
|
@ -228,6 +228,12 @@ end:
|
|||
return ret;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
m_relation_history_get_size(const struct m_relation_history *rh)
|
||||
{
|
||||
return (uint32_t)rh->impl.length();
|
||||
}
|
||||
|
||||
void
|
||||
m_relation_history_destroy(struct m_relation_history **rh_ptr)
|
||||
{
|
||||
|
|
|
@ -67,6 +67,14 @@ m_relation_history_push(struct m_relation_history *rh, struct xrt_space_relation
|
|||
enum m_relation_history_result
|
||||
m_relation_history_get(struct m_relation_history *rh, uint64_t at_time_ns, struct xrt_space_relation *out_relation);
|
||||
|
||||
/*!
|
||||
* @brief Returns the number of items in the history.
|
||||
*
|
||||
* @public @memberof m_relation_history
|
||||
*/
|
||||
uint32_t
|
||||
m_relation_history_get_size(const struct m_relation_history *rh);
|
||||
|
||||
/*!
|
||||
* Destroys an opaque relation_history object.
|
||||
*
|
||||
|
|
|
@ -29,8 +29,8 @@ private:
|
|||
|
||||
public:
|
||||
// clang-format off
|
||||
int topIdx() { return mTopIdx; }
|
||||
int length() { return mLength; }
|
||||
int topIdx() const noexcept { return mTopIdx; }
|
||||
int length() const noexcept { return mLength; }
|
||||
// clang-format on
|
||||
|
||||
/* Put something at the top, overwrite whatever was at the back*/
|
||||
|
|
|
@ -40,11 +40,20 @@ TEST_CASE("m_relation_history")
|
|||
// two seconds after T0
|
||||
constexpr auto T2 = T1 + (uint64_t)U_TIME_1S_IN_NS;
|
||||
|
||||
m_relation_history_push(rh, &relation, T0);
|
||||
CHECK(m_relation_history_push(rh, &relation, T0));
|
||||
CHECK(m_relation_history_get_size(rh) == 1);
|
||||
|
||||
relation.pose.position.x = 1.f;
|
||||
m_relation_history_push(rh, &relation, T1);
|
||||
CHECK(m_relation_history_push(rh, &relation, T1));
|
||||
CHECK(m_relation_history_get_size(rh) == 2);
|
||||
|
||||
relation.pose.position.x = 2.f;
|
||||
m_relation_history_push(rh, &relation, T2);
|
||||
CHECK(m_relation_history_push(rh, &relation, T2));
|
||||
CHECK(m_relation_history_get_size(rh) == 3);
|
||||
|
||||
// Try going back in time: should fail
|
||||
CHECK_FALSE(m_relation_history_push(rh, &relation, T1));
|
||||
CHECK(m_relation_history_get_size(rh) == 3);
|
||||
|
||||
xrt_space_relation out_relation = XRT_SPACE_RELATION_ZERO;
|
||||
CHECK(m_relation_history_get(rh, 0, &out_relation) == M_RELATION_HISTORY_RESULT_INVALID);
|
||||
|
|
Loading…
Reference in a new issue