Skip to content

Commit 9b2329b

Browse files
committed
pbio/test/trajectory: Fix skipping start of trajectory.
When walking the trajectory we have to skip the first point because there is no previous point to compare to. We already skipped 0, but there can be new matching starting points when a long trajectory rebases itself. This was discovered when adding a missing assert for positive time, which is added in this commit as well.
1 parent fa69853 commit 9b2329b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/pbio/src/trajectory.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ void pbio_trajectory_get_last_vertex(pbio_trajectory_t *trj, uint32_t time_ref,
629629

630630
// Relative time within ongoing maneuver.
631631
int32_t time = TO_TRAJECTORY_TIME(time_ref - trj->start.time);
632+
assert_time(time);
632633

633634
// Find which section of the ongoing maneuver we were in, and take
634635
// corresponding segment starting point. Acceleration is undefined but not

lib/pbio/test/src/test_trajectory.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,18 @@ static void walk_trajectory(pbio_trajectory_t *trj) {
9090

9191
// Loop over all trajectory points and assert results.
9292
const uint32_t increment = 50;
93-
for (uint32_t t = increment; t < duration; t += increment) {
93+
for (uint32_t t = 0; t < duration; t += increment) {
9494

9595
// Get current reference.
9696
uint32_t now = t + time_start;
9797
pbio_trajectory_get_reference(trj, now, &ref_now);
9898

99+
// Skip if current time equals start time. Then there is no previous
100+
// sample to compare to.
101+
if (now == trj->start.time) {
102+
continue;
103+
}
104+
99105
// Current time should match
100106
tt_want_int_op(ref_now.time, ==, now);
101107

0 commit comments

Comments
 (0)