Hit test
Hit checking (or hit detection ) in computer graphics is the process of determining whether a user-controlled cursor (e.g. a mouse pointer or a point of contact on a touchscreen surface) is a specific graphic object (e.g. a shape, line or curve) or a control (widget) drawn on the screen. Hit testing can be performed upon movement or activation of a mouse or other pointing device.
Hit checking is used by graphical user interfaces (GUIs) to respond to user actions, such as: B. 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 (e.g. user-initiated cursor movement or object selection).
Collision detection is a related concept for detecting the intersection of two or more different graphic objects instead of the intersection of a cursor with one or more graphic objects.
algorithm
There are many different algorithms that can be used to perform hit tests with varying degrees of speed or accuracy. A common hit-checking algorithm is presented in the pseudo-code below:
function HitTest(Rectangle r1, Rectangle r2) returns boolean
{
return ((r1.X + r1.Width >= r2.X) and (r1.X <= r2.X + r2.Width) and (r1.Y + r1.Height >= r2.Y) and (r1.Y <= r2.Y + r2.Height));
}
See also
Individual evidence
- ^ Foley et al: Computer Graphics: Principles and Practice . 2015.