Fix handling of gaps when downsampling.