feat(plot)!: harden pipeline, XY series, dash/markers, touch, packaging
Breaking: Series::gather emits x relative to x0() and takes a GatherMode; consumers reconstruct absolute x in f64 before mapping (series.hpp documents the contract). Bugs, each pinned by a fail-before regression test: - render: f32 staging quantised epoch-time x into 128 px columns; every data-space draw now stages to_space(x) - to_space(origin) with the origin folded into the offset uniform in f64 (epoch/zero-origin twins rasterise identically) - ticks: major test was ULP-fragile and blanked epoch axes; majors are an integer-index test and are never truncated by the minor cap - gather: LOD envelope emitted buckets straddling [begin,end); ceil/floor bucket edges + raw lead/trail spans - live follow: log x axes held a linear span and zoomed every frame; span and offset now live in axis space (plot + both figure link-group paths) - input: a zero-notch wheel disarmed auto_scale on every axis; dy==0 pans x, factor == 1 / inf refused in wheel and drag zoom - render: the single text flush painted legend names over the crosshair readout panel; two batches, under flushed before the panel - data: NaN dropped from min/max unless it seeded the fold; non-finite samples are now excluded from every aggregate and from cached bounds Robustness: viewport normalisation (no clamp UB), non-finite range refusal, pyramid level cap at 57 (no shift/div UB through public gather), rounded ring capacity documented + pre-sized, GL blend func and UNPACK_ALIGNMENT save/restore, Renderer::release_gl() teardown, u64 buffer epochs, annotation captions clamped, button-aware GLFW row capture, cached figure row rects (no per-event layout), ruler-pair measurement refused, span-nonfinite guards in axis_ends. Features: XY series (sorted x, binary-search neighbours/snap, LOD over sample index); StreamSeries::freeze(); ArraySeries::push(); per-trace dash and markers (scatter at width 0) with auto or literal stride; GatherMode Envelope/Nearest/Mean via bucket_sum/sumsq; Style::line_aa_px; per-glyph text colour (readout values in trace colour); wheel-dx x pan; arrow-key pan; Escape cancels a drag and restores captured ranges; modifier-masked box zoom (Shift both, Ctrl x, Alt y); double-click reset via PointerEvent::time_s; ImGui key repeat unified; pinch gestures on Qt and GTK; pixelDelta wheel path and DevicePixelRatioChange handling; GNUInstallDirs, SOVERSION, SameMinorVersion, generated plot/version.hpp, relocatable plot.pc, licence install, FILES_MATCHING, GitHub Actions CI (debug/coverage/asan). Suite 283 -> 350 cases, 0 failed; coverage 93.9% (3730/3971) over 24 files, floor 80/90 held; ASAN preset suite green; all four demos run headless (the GTK scripted-resize check needs a window manager and fails identically on the parent commit); readme_main.cpp committed and compiles with the README command; pkg-config and find_package consumption verified from a relocated install prefix.
This commit is contained in:
1 parent
f132a5ec92
commit
38ef459897
77 files changed
+5905
-688
No files matched your search
@@ -229,4 +229,115 @@ inline f64 scroll_notches(f64 dy, ScrollUnit unit) noexcept {
|
||||
return -dy;
|
||||
}
|
||||
|
||||
/// The keyvals this adapter maps, as GDK's own numbers, mirrored here so the
|
||||
/// mapping below -- and a test that drives it -- needs no GTK include directory.
|
||||
/// `gtk_plot_area.cpp` static-asserts each against GDK's own macro.
|
||||
///
|
||||
/// These are the *function* keyvals (the `0xFF00` page), fixed by X11's keysym
|
||||
/// convention GDK inherits; a keypad arrow (a keypad key with Num Lock off) is a
|
||||
/// different keyval and deliberately unmapped, exactly as the GLFW adapter maps
|
||||
/// the main-row arrows and not `GLFW_KEY_KP_4`.
|
||||
constexpr u32 kGdkKeyEscape = 0xFF1Bu;
|
||||
constexpr u32 kGdkKeyLeft = 0xFF51u;
|
||||
constexpr u32 kGdkKeyUp = 0xFF52u;
|
||||
constexpr u32 kGdkKeyRight = 0xFF53u;
|
||||
constexpr u32 kGdkKeyDown = 0xFF54u;
|
||||
|
||||
/// One key-press translation, by keyval first and Unicode fallback second.
|
||||
///
|
||||
/// GTK names a key by its keyval, which is layout- and level-dependent: `+` is
|
||||
/// usually shift+`=` and arrives as a different keyval, but both decode to the
|
||||
/// same Unicode code point, which is why the printable keys go through
|
||||
/// `gdk_keyval_to_unicode()`. The function keys decode to no code point at all,
|
||||
/// so they are matched on the keyval itself, before that fallback. `0` means "no
|
||||
/// plot key": the caller returns the event to GTK unhandled.
|
||||
///
|
||||
/// The keypad's plus and minus decode to the same code points as the main row's,
|
||||
/// so they come along for free -- the same set the GLFW adapter maps with
|
||||
/// `GLFW_KEY_KP_ADD`/`GLFW_KEY_KP_SUBTRACT`.
|
||||
inline int key_from(u32 keyval, u32 unicode) noexcept {
|
||||
switch (keyval) {
|
||||
case kGdkKeyEscape: return input::kKeyEscape;
|
||||
case kGdkKeyLeft: return input::kKeyLeft;
|
||||
case kGdkKeyRight: return input::kKeyRight;
|
||||
case kGdkKeyUp: return input::kKeyUp;
|
||||
case kGdkKeyDown: return input::kKeyDown;
|
||||
default: break;
|
||||
}
|
||||
switch (unicode) {
|
||||
case static_cast<u32>(input::kKeyZoomIn):
|
||||
case static_cast<u32>('='): return input::kKeyZoomIn;
|
||||
case static_cast<u32>(input::kKeyZoomOut):
|
||||
case static_cast<u32>('_'): return input::kKeyZoomOut;
|
||||
case static_cast<u32>(input::kKeyFit):
|
||||
case static_cast<u32>(input::kKeyFitUpper): return input::kKeyFit;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// The state one `GtkGestureZoom` is folded into `input::GestureEvent`s from.
|
||||
///
|
||||
/// `GtkGestureZoom` reports a **cumulative** scale (`gtk_gesture_zoom_get_scale_delta()`
|
||||
/// and the `scale-changed` argument are the zoom since the gesture began, 1.0 at
|
||||
/// the start) and knows the focal point only as the bounding box of the pointer
|
||||
/// the gesture holds (`gtk_gesture_bounding_box_center()`), also cumulative in the
|
||||
/// sense that it is where the fingers are *now*. The controller wants the
|
||||
/// increments -- `GestureEvent::scale` is this frame's zoom factor about the focal
|
||||
/// point, 1.0 = no change, and `(dx, dy)` the focal point's movement since the
|
||||
/// previous gesture event -- so the area owns one of these and folds each
|
||||
/// `scale-changed` exactly like the Qt adapter folds its pinch (`PinchTracker`).
|
||||
///
|
||||
/// The focal point is cached in **logical** widget pixels, like `DragAnchor` above,
|
||||
/// for the same reason: the mapping's factor is re-derived on every `::resize`,
|
||||
/// and a cache in device pixels would compare two points taken at different
|
||||
/// factors. The difference of two logical points, scaled by the factor in force
|
||||
/// now, is the movement the fingers actually made.
|
||||
///
|
||||
/// A plain value with no toolkit dependency, like every other type here: the area
|
||||
/// owns one, and the tests drive it directly.
|
||||
struct ZoomAnchor {
|
||||
bool active = false; ///< true between the gesture's begin and its end
|
||||
f32 last_scale = 1.0f; ///< the cumulative scale the previous update folded
|
||||
f32 x = 0.0f; ///< last focal point, logical widget pixels
|
||||
f32 y = 0.0f;
|
||||
|
||||
/// Starts a gesture at its first cumulative `scale` and logical focal point.
|
||||
/// Records only: a zoom that just began has zoomed and moved nothing yet.
|
||||
void begin(f32 scale, Vec2 logical_center) noexcept {
|
||||
active = true;
|
||||
last_scale = scale;
|
||||
x = logical_center.x;
|
||||
y = logical_center.y;
|
||||
}
|
||||
|
||||
/// Folds one `scale-changed` into an incremental `GestureEvent`, in device
|
||||
/// pixels at `mapping`: the zoom about the focal point, and the focal point's
|
||||
/// movement since the previous update. A no-op before `begin()`, so a
|
||||
/// `scale-changed` that arrives without a begin -- a host that missed the start
|
||||
/// -- zooms nothing rather than zooming from a made-up anchor.
|
||||
input::GestureEvent update(f32 scale, Vec2 logical_center,
|
||||
const DeviceMapping& mapping) noexcept {
|
||||
input::GestureEvent g;
|
||||
if (!active) return g;
|
||||
// This frame's zoom: the cumulative ratio over the one last folded. The first
|
||||
// update after begin() divides the scale by itself -- 1.0, no zoom, as it
|
||||
// should be when the fingers have not moved apart yet.
|
||||
g.scale = last_scale != 0.0f ? scale / last_scale : 1.0f;
|
||||
const Vec2 device = mapping.to_device(logical_center.x, logical_center.y);
|
||||
g.x = device.x;
|
||||
g.y = device.y;
|
||||
const Vec2 moved{logical_center.x - x, logical_center.y - y};
|
||||
const Vec2 device_moved = mapping.to_device(moved.x, moved.y);
|
||||
g.dx = device_moved.x;
|
||||
g.dy = device_moved.y;
|
||||
last_scale = scale;
|
||||
x = logical_center.x;
|
||||
y = logical_center.y;
|
||||
return g;
|
||||
}
|
||||
|
||||
/// Ends the gesture: a straggler update after this zooms nothing.
|
||||
void end() noexcept { active = false; }
|
||||
};
|
||||
|
||||
} // namespace plot::gtk4
|
||||
Reference in new issue
Block a user