fix(render): a clamped ring front does not draw a segment across the panel
CI / debug (tests + all adapters) (push) Canceled after 0s
CI / coverage (floor + measured table) (push) Canceled after 0s
CI / asan (AddressSanitizer) (push) Canceled after 0s

A ring-backed series answers a *clamped* stamp for the oldest slots of its window -- the ones the
producer has already overwritten -- because the published window is pinned while both rings slide
under it, and the alternative (a sentinel) collapsed the whole index mapping. The consequence for a
polyline is that the stamps do not increase at the *front*: the first points carry the newest stamp
and everything after them is older. Drawn as they come, that is a segment from the newest sample
back to the oldest -- a line across the whole panel, which a saturated ring shows as a flicker.

The gathered points are now reduced to their longest strictly increasing suffix before anything is
staged, so the unreadable front is left out and the real samples are untouched. A forward pass
cannot express this: the bad points are at the front and everything behind them is legitimately
smaller, so "drop anything that does not advance" would delete the trace -- walking backwards keeps
each point strictly older than the one kept after it and stops at the first unreadable slot. One
pass over the visible points, which the staging then walks anyway.

Test: a_clamped_front_does_not_draw_a_segment_across_the_panel -- a series whose first two samples
carry the newest stamp at -1 while the rest walk 0..50 at +1, the shape a saturated ChannelBuffer
produces. Flat at +1 except for those two, so any ink below the middle of the axes is the bad
segment: with the filter there is none (0 below, 1032 above in the columns the trace covers), and
without it the diagonal crosses the panel.
This commit is contained in:
Martino Ferrari committed 2026-10-03 17:51:37 +02:00
1 parent faef19ba60
commit 0ee6e10c81
3 files changed
+134

No files matched your search

+34
View File
@@ -9,6 +9,7 @@
#include <plot/render/detail/text_scale.hpp>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <cstdlib>
@@ -1065,6 +1066,39 @@ void Renderer::draw_traces(const Plot& plot, const PlotLayout& layout) {
const bool log_x = plot.x_axis(trace.axis_x).log;
const bool log_y = plot.y_axis(trace.axis_y).log;
const Mapping map = mapping(plot, trace.axis_x, trace.axis_y, x_range.min);
// Keep the longest **increasing suffix** of the gathered points, and drop what precedes it.
//
// A ring-backed series may answer a *clamped* stamp for the oldest slots of its window -- the ones
// the producer has already overwritten. The clamp is deliberate (the alternative was a sentinel
// that collapsed the whole index mapping), but it makes the stamps *non-increasing at the front*:
// the first few points carry the newest stamp, and everything after them is older. A polyline
// through that draws a segment from the newest sample back to the oldest -- a line across the
// whole panel, which is what a saturated ring shows as a flicker.
//
// A forward filter cannot express this: the bad points are at the *front* and everything behind
// them is legitimately smaller, so dropping "anything that does not advance" would delete the
// trace. Walking backwards keeps each point that is strictly older than the one kept after it,
// which stops at the first unreadable slot and leaves the real samples alone. The cost is one
// pass over the visible points, which the staging below is about to walk anyway.
{
const usize count = gather_.size() / 2u;
usize kept = 0;
f64 next = std::numeric_limits<f64>::infinity();
for (usize k = count; k > 0; --k) {
const usize i = k - 1u;
const f64 x = static_cast<f64>(gather_[2u * i]) + series.x0();
if (!(x < next)) continue; // out of order with what follows: unreadable, and a NaN too
next = x;
gather_[2u * (count - 1u - kept)] = gather_[2u * i];
gather_[2u * (count - 1u - kept) + 1u] = gather_[2u * i + 1u];
++kept;
}
if (kept != count) {
// The kept points were written back-to-front into the tail; move them down to the front.
std::memmove(gather_.data(), gather_.data() + 2u * (count - kept), 2u * kept * sizeof(f32));
gather_.resize(2u * kept);
}
}
const u32 points = static_cast<u32>(gather_.size() / 2u);
// A trace's dash rides on the same per-draw uniform the crosshair uses, in