Hit-testing


In computer graphics programming, hit-testing is the process of determining whether a user-controlled cursor intersects a given graphical object drawn on the screen. Hit-testing may be performed on the movement or activation of a mouse or other pointing device.
Hit-testing is used by GUI environments to respond to user actions, such as selecting a menu item or a target in a game based on its visual location. In Web programming languages such as HTML, SVG, and CSS, this is associated with the concept of pointer-events.
Collision detection is a related concept for detecting intersections of two or more different graphical objects, rather than intersection of a cursor with one or more graphical objects.

Algorithm

There are many different algorithms that may be used to perform hit-testing, with different performance or accuracy outcomes. One common hit-test algorithm is presented in the pseudo-code below:

function HitTest returns boolean