Table of Contents

Interface IHitTestable<TElement>

Namespace
FlowGraph.Core.Input
Assembly
FlowGraph.Core.dll

Interface for components that support hit testing.

Contract: Implementations MUST document and enforce the coordinate space specified by HitTestCoordinateSpace. Callers MUST provide positions in the declared coordinate space.

Inspired by:

  • Konva.js: Stage.getIntersection(pos) returning the topmost Shape
  • react-diagrams: DiagramEngine.getModelAtPosition()
  • WPF/Avalonia: VisualTreeHelper.HitTest() pattern
public interface IHitTestable<TElement>

Type Parameters

TElement

The type of element this tests against.

Properties

HitTestCoordinateSpace

The coordinate space expected for the hit test position parameter.

Implementation guidance:

  • Most hit testers should expect Canvas coordinates
  • Direct renderers that manage their own transforms may expect Screen
  • The caller is responsible for converting coordinates before calling HitTest(Point, double)
CoordinateSpace HitTestCoordinateSpace { get; }

Property Value

CoordinateSpace

Methods

HitTest(Point, double)

Performs a hit test at the specified position.

HitTestResult<TElement> HitTest(Point position, double tolerance = 0)

Parameters

position Point

Position to test. MUST be in the coordinate space specified by HitTestCoordinateSpace. Passing coordinates in the wrong space will produce incorrect results.

tolerance double

Optional tolerance/margin for the hit test, in the same coordinate space. Use this for edge hit testing or touch-friendly targets.

Returns

HitTestResult<TElement>

The hit test result containing the hit element (if any) and positions.