From 03c41adbec42516f133035557227d082fb2ab188 Mon Sep 17 00:00:00 2001 From: Martino Ferrari Date: Mon, 5 Oct 2026 16:12:39 +0200 Subject: [PATCH] fix(render): three warnings a stricter build reports, none of them behavioural The point-index loop in `draw_traces` named its variable `i`, shadowing the trace index that the whole block is nested inside; it is `p` now, which also leaves the comment free to say which one is which. The marker loop's two screen coordinates were narrowed implicitly. And `same_cell()`'s only caller is an `assert`, so a release build had an unused function; it is guarded the way its caller is. Co-Authored-By: Claude Opus 4.6 --- src/render/primitives.cpp | 5 +++++ src/render/renderer.cpp | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/render/primitives.cpp b/src/render/primitives.cpp index d103256..37c3993 100644 --- a/src/render/primitives.cpp +++ b/src/render/primitives.cpp @@ -9,12 +9,17 @@ namespace plot::render { namespace { +#ifndef NDEBUG /// Two declared cells agree when neither size differs by more than the atlas' /// tolerance: the test `glyph_is_cell()` makes, for a cell against a cell. +/// +/// Guarded because its one caller is an `assert` (see `TextBatch::set_cell`), so a +/// release build has no use for it and would warn that it is unused. bool same_cell(Vec2 a, Vec2 b) noexcept { const auto near = [](f32 p, f32 q) { return std::fabs(p - q) <= kAtlasCellTolerance; }; return near(a.x, b.x) && near(a.y, b.y); } +#endif /// `axis` as a unit vector: the cell's local +x, which is what the instance and /// the shader both take (see `TextInstance`). A zero, infinite or NaN direction diff --git a/src/render/renderer.cpp b/src/render/renderer.cpp index 0df2d00..3075912 100644 --- a/src/render/renderer.cpp +++ b/src/render/renderer.cpp @@ -1043,8 +1043,8 @@ void Renderer::draw_traces(const Plot& plot, const PlotLayout& layout) { const f64 x_abs = series.x0() + static_cast(gather_[k]); const f64 y_abs = static_cast(gather_[k + 1]); if (!std::isfinite(x_abs) || !std::isfinite(y_abs)) continue; - const f32 sx = xt.to_screen_x(x_abs); - const f32 sy = yt.to_screen_y(y_abs); + const f32 sx = static_cast(xt.to_screen_x(x_abs)); + const f32 sy = static_cast(yt.to_screen_y(y_abs)); if (!(sx >= layout.axes.x && sx <= layout.axes.right() && sy >= layout.axes.y && sy <= layout.axes.bottom())) { continue; @@ -1085,12 +1085,12 @@ void Renderer::draw_traces(const Plot& plot, const PlotLayout& layout) { usize kept = 0; f64 next = std::numeric_limits::infinity(); for (usize k = count; k > 0; --k) { - const usize i = k - 1u; - const f64 x = static_cast(gather_[2u * i]) + series.x0(); + const usize p = k - 1u; // the point index; `i` above is the trace's + const f64 x = static_cast(gather_[2u * p]) + 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]; + gather_[2u * (count - 1u - kept)] = gather_[2u * p]; + gather_[2u * (count - 1u - kept) + 1u] = gather_[2u * p + 1u]; ++kept; } if (kept != count) {