Skip to content

fix: spread RingBuffer.Resample repeats evenly and document nearest-neighbour [patch] - #113

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/88-even-resample
Oct 9, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/88-even-resample

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #88

What changed

RingBuffer<T>.Resample used to map the first and last slots onto the first and last elements and round with Math.Round, which defaults to banker's rounding. Every .5 tie went to the even index, so some samples were repeated three times while their neighbours appeared once. For example, 5 → 9 gave [0,0,1,2,2,2,3,4,4].

Tests

  • ResampleWithSpecificValues_CorrectlyInterpolates had a comment claiming 10, 15, 20, 25, 30, which was wrong. It now asserts the full output, [10, 10, 20, 30, 30].
  • New: Resample_PicksTheNearestSampleToEachSlotsCentre asserts the full output for 5→9, 2→3, 3→12 and 9→3.
  • New: Resample_Upsampling_RepeatsEverySampleEvenly covers every ratio from 1..12 → up to 40. For each one it checks how many times each sample repeats and that the endpoints are kept.

All five new cases fail on main and pass with the fix. The full suite passes locally (475/475), including the large-buffer Resample tests.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dzcato9evJfMk7iLBAHZpo


Generated by Claude Code

…eighbour [patch]

Resample mapped the ends onto each other and rounded with
Math.Round's default banker's rounding, so ties all went to the even
index and some samples appeared three times while their neighbours
appeared once (5 to 9 gave [0,0,1,2,2,2,3,4,4]). Each slot now takes the
element under its centre, floor((i + 0.5) * oldCount / length), computed
in exact long arithmetic so there are no floating-point ties and no
overflow for large buffers. The XML doc now describes the
nearest-neighbour selection instead of promising linear interpolation,
and the test that claimed 10, 15, 20, 25, 30 asserts the full output.

Fixes #88

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dzcato9evJfMk7iLBAHZpo
@sonarqubecloud

sonarqubecloud Bot commented Oct 8, 2026

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit d1d5cb5 into main Oct 9, 2026
14 checks passed
@matt-edmondson
matt-edmondson deleted the fix/88-even-resample branch October 9, 2026 08:03
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.

RingBuffer.Resample repeats source elements unevenly because of banker's rounding, and its docs promise linear interpolation it doesn't do

2 participants