Skip to content

Commit 0805945

Browse files
committed
fix(mps): allow bisection_timestamp_search to match the first or last timestamp exactly
The border guards used <= and >=, so querying the exact first or last timestamp returned None instead of index 0 or len - 1, violating the "closest or equal" wording in every get_nearest_* wrapper docstring. Tightened to < and >. Separable from the issue #100 fix; can be dropped if you'd rather see it as its own PR.
1 parent bdddaf9 commit 0805945

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

core/python/test/mpsUtilsTest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ def test_equidistant_prefers_lower_index(self) -> None:
3636
# Tie-break is deterministic toward the lower index.
3737
self.assertEqual(bisection_timestamp_search(self.ts, 6000), 2)
3838

39+
def test_exact_match_on_first_or_last_returns_its_index(self) -> None:
40+
# The border guards used <= / >=, so an exact match on the first or
41+
# last timestamp returned None instead of its index.
42+
self.assertEqual(bisection_timestamp_search(self.ts, 1000), 0)
43+
self.assertEqual(bisection_timestamp_search(self.ts, 19000), 9)
44+
3945

4046
if __name__ == "__main__":
4147
unittest.main()

projectaria_tools/core/mps/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ def bisection_timestamp_search(timed_data, query_timestamp_ns: int) -> int:
3636
if timed_data and len(timed_data) > 1:
3737
first_timestamp = timed_data[0].tracking_timestamp.total_seconds() * 1e9
3838
last_timestamp = timed_data[-1].tracking_timestamp.total_seconds() * 1e9
39-
if query_timestamp_ns <= first_timestamp:
39+
if query_timestamp_ns < first_timestamp:
4040
return None
41-
elif query_timestamp_ns >= last_timestamp:
41+
elif query_timestamp_ns > last_timestamp:
4242
return None
4343
# If this is safe we perform the Bisection search
4444
start = 0

0 commit comments

Comments
 (0)