Skip to main content

CorePlotting::SceneHitTester

CorePlotting::SceneHitTester

Multi-strategy hit tester for RenderableScene. More…

#include <SceneHitTester.hpp>

Public Functions

Name
SceneHitTester()
Construct with default configuration.
SceneHitTester(HitTestConfig config)
Construct with custom configuration.
void setConfig(HitTestConfig config)
Set hit testing configuration.
HitTestConfig const & getConfig() const
Get current configuration.
HitTestResult hitTest(float world_x, float world_y, RenderableScene const & scene, LayoutResponse const & layout) const
Perform a hit test at the given world coordinates.
HitTestResult queryQuadTree(float world_x, float world_y, RenderableScene const & scene) const
Query only the QuadTree spatial index for discrete elements.
HitTestResult queryIntervals(float world_x, float world_y, RenderableScene const & scene, std::map< size_t, std::string > const & series_key_map) const
Query for intervals at a given time coordinate.
HitTestResult findIntervalEdgeByEntityId(float world_x, RenderableScene const & scene, std::unordered_set< EntityId > const & selected_entities, std::map< size_t, std::string > const & series_key_map) const
Find interval edge at a given position using EntityId-based selection.
HitTestResult querySeriesRegion(float world_x, float world_y, LayoutResponse const & layout, ClockTicks master_time_axis_origin_absolute =ClockTicks(0)) const
Query which series region contains the given point.

Detailed Description

class CorePlotting::SceneHitTester;

Multi-strategy hit tester for RenderableScene.

This class orchestrates multiple hit testing strategies to determine what element (if any) exists at a given world coordinate. It supports:

  1. QuadTree queries for discrete elements (events, points)
  2. Interval containment for rectangle batches
  3. Series region queries for analog series

The tester prioritizes hits by distance and type, typically preferring discrete elements over continuous regions.

Usage:

SceneHitTester tester;

// Convert screen coordinates to world coordinates
glm::vec2 world_pos = screenToWorld(mouse_pos, viewport_size, 
                                     scene.view_matrix, scene.projection_matrix);

// Perform hit test
HitTestResult result = tester.hitTest(world_pos.x, world_pos.y, scene, layout);

if (result.hasHit()) {
    if (result.hit_type == HitType::DigitalEvent) {
        selectEvent(result.entity_id.value());
    }
}

Public Functions Documentation

function SceneHitTester

SceneHitTester()

Construct with default configuration.

function SceneHitTester

inline explicit SceneHitTester(
    HitTestConfig config
)

Construct with custom configuration.

Parameters:

  • config Hit testing configuration

function setConfig

inline void setConfig(
    HitTestConfig config
)

Set hit testing configuration.

function getConfig

inline HitTestConfig const & getConfig() const

Get current configuration.

function hitTest

HitTestResult hitTest(
    float world_x,
    float world_y,
    RenderableScene const & scene,
    LayoutResponse const & layout
) const

Perform a hit test at the given world coordinates.

Parameters:

  • world_x World X coordinate (typically time)
  • world_y World Y coordinate
  • scene The renderable scene containing spatial index and batches
  • layout Layout information for series positioning

Return: HitTestResult describing what was hit (or NoHit if nothing)

Queries all applicable strategies and returns the best hit. Priority: discrete elements (events, points) > interval edges > interval bodies > analog series regions.

function queryQuadTree

HitTestResult queryQuadTree(
    float world_x,
    float world_y,
    RenderableScene const & scene
) const

Query only the QuadTree spatial index for discrete elements.

Parameters:

  • world_x World X coordinate
  • world_y World Y coordinate
  • scene Scene containing the spatial index

Return: HitTestResult if an element is within tolerance, NoHit otherwise

Use this when you only care about events/points, not regions.

function queryIntervals

HitTestResult queryIntervals(
    float world_x,
    float world_y,
    RenderableScene const & scene,
    std::map< size_t, std::string > const & series_key_map
) const

Query for intervals at a given time coordinate.

Parameters:

  • world_x World X coordinate (time)
  • world_y World Y coordinate (used for distance calculation)
  • scene Scene containing rectangle batches
  • series_key_map Mapping from batch index to series key

Return: HitTestResult for the closest matching interval

Checks all rectangle batches for intervals containing the given time. Returns the interval hit with smallest distance to the query point.

function findIntervalEdgeByEntityId

HitTestResult findIntervalEdgeByEntityId(
    float world_x,
    RenderableScene const & scene,
    std::unordered_set< EntityId > const & selected_entities,
    std::map< size_t, std::string > const & series_key_map
) const

Find interval edge at a given position using EntityId-based selection.

Parameters:

  • world_x World X coordinate
  • scene Scene containing rectangle batches (with entity_ids populated)
  • selected_entities Set of currently selected EntityIds
  • series_key_map Mapping from batch index to series key

Return: HitTestResult with IntervalEdgeLeft/Right if within edge tolerance

Modern version of findIntervalEdge that uses EntityId set for selection state. This integrates with the new selection system where selection is tracked by EntityId rather than time bounds.

function querySeriesRegion

HitTestResult querySeriesRegion(
    float world_x,
    float world_y,
    LayoutResponse const & layout,
    ClockTicks master_time_axis_origin_absolute =ClockTicks(0)
) const

Query which series region contains the given point.

Parameters:

  • world_x World X coordinate
  • world_y World Y coordinate
  • layout Layout information for series positioning

Return: HitTestResult with AnalogSeries type if within a series region

Use this to determine which analog series the mouse is hovering over. Does not check for discrete elements.


Updated on 2026-11-13 at 20:25:42 +0000