fix(transforms): avoid NaN at CurveInterpolator's lowest sample point#1005
Conversation
set() at an input equal to the smallest sample's x left the search at begin(), so x0 and x1 were the same point and the interval divide was 0/0 -> NaN. Return the sample's y for a zero-width interval.
Automated reviewVerdict: Correct, minimal fix. Approve. Root cause and fix confirmed by source-tracing; no blocking issues. Root cause — confirmed
Fix correctness — confirmed for all three paths
Degenerate paths — checked
Style / conventionsMinimal, idiomatic, and the comment explains the why (zero-width interval at begin()) rather than narrating the change — matches AGENTS.md comment guidance. No nits. Non-blocking note
|
Bug
CurveInterpolator::set(x)returns NaN whenxequals the smallest sample's input. The interval search starts atbegin()and only advances whileinput > it->input_, so at the lowest point it never advances:x0andx1both reference that same sample, and the interpolation(…)/(x1 - x0)divides by zero.Fix
Guard the zero-width interval: when
x1 == x0, output the sample'sydirectly.How it was found
Surfaced by executing the test suite on a HALMET device (
test_curve_interpolator_exact_sample_points— "Expected 0 Was nan"). CI only compiles the Unity suites (pio test --without-testing), so it never caught this. The existing test intest_transformscovers the fix; it passes on-device after this change.