Re #8665. Refactor by pulling the first event out of the loop.

Dealing with the first event ahead of the loop allows some simplifications
of the code within the loop. It does require returning early if the list is
empty (which is a good thing anyway).
Re #8665. Move up the compression 'window' by a multiple of tolerance.

This is instead of moving it up to the time of the first event outside the
current window, which introduces a bias.
The previous behaviour is maintained for a zero tolerance (which is a
valid input) to avoid an infinite loop.
Merge branch 'feature/8665_compress_events_gridding' into develop