Skip to content

fix: preserve final timestep when resampling trajectories - #3

Open
kejan2514 wants to merge 4 commits into
AxisAIOrg:mainfrom
kejan2514:fix/resample-final-timestep
Open

fix: preserve final timestep when resampling trajectories#3
kejan2514 wants to merge 4 commits into
AxisAIOrg:mainfrom
kejan2514:fix/resample-final-timestep

Conversation

@kejan2514

Copy link
Copy Markdown

Summary

Fixes trajectory resampling so that the final timestep is always preserved.

Previously, np.arange() could exclude the trajectory endpoint when the time range was not evenly divisible by target_dt.

Changes

  • Preserve the exact final trajectory timestamp during resampling
  • Avoid duplicate endpoints when target_dt divides the interval exactly
  • Add regression tests for both divisible and non-divisible intervals

Testing

Added tests covering:

  • Exact interval division
  • Non-divisible intervals with a shorter final step

@faisalnugroho

Copy link
Copy Markdown

Reviewed the patch — I reproduced the bug on main (np.arange(0, 1, 0.1)[-1] == 0.9) and verified this fix against several edge cases:

  • ✅ Span divisible by dt → grid ends exactly at t_end (11 points for 0–1s @ dt=0.1)
  • ✅ Span not divisible by dt → exact landing with a shorter final interval (e.g. [0, 0.3, 0.6, 0.9, 1.0])
  • ✅ Single-frame trajectory (t_start == t_end) → grid collapses to one point instead of being empty
  • ✅ Float drift case (dt = 0.1000001) → isclose catches the near-final point and snaps it to t_end

One minor nit: in the else branch, new_times[-1] = t_end only triggers when the last point is already within isclose tolerance of t_end, so it's effectively a snap-to-endpoint — correct, but worth a one-line comment since future readers may assume it's a no-op.

The included regression tests cover the two main behaviors nicely. From my side this looks safe to merge — leaving the maintainer to confirm the design choice (strict-uniform vs exact-landing), which the linked issue #2 asks about.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants