Hit-Testing

In computer graphics programming, hit-testing (hit detection, picking, or pick correlation) is the process of determining whether a user-controlled cursor (such as a mouse cursor or touch-point on a touch-screen interface) intersects a given graphical object (such as a shape, line, or curve) 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 (e.g. user-initiated cursor movement or object selection).

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(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)); } 

In Python:

def hit_test(r1: Rectangle, r2: Rectangle) -> bool:     """Return true if it hits else return false."""     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

References

Tags:

Hit-Testing AlgorithmHit-Testing

🔥 Trending searches on Wiki English:

BRICSRana NaiduUEFA Champions LeagueJohn TravoltaA Good PersonNazi GermanyDavid (Michelangelo)HMS Dasher (D37)Marlon BrandoVietnamList of prime ministers of IndiaMasterChef India (Hindi season 7)J. Robert OppenheimerKobe BryantCristian StelliniBill GatesPhronimaMichelle YeohDiablo IVKim KardashianHelen HuntSian BrookeThe WeekndPedro PascalAriana GrandeAlpha-PyrrolidinopentiothiophenoneMatt DamonThe Last of Us Part IIJordan PetersonList of most-liked Instagram postsHimeji CastleFIFA World CupList of countries by GDP (nominal)Great ExpectationsYokozuna (wrestler)Bob OdenkirkPatrick BeverleyHannah WaddinghamThe White LotusKings LeagueCovenant School shootingKevin CostnerBabylon (2022 film)Jennifer SymeAmanda BynesThe Last of UsDalai LamaGeneration ZChernobyl disasterJudd ApatowBruce WillisIslamNetherlandsClient access licenseAlexandra GrantHarry PotterXXXMarie AntoinetteFranklin D. RooseveltBobby HurleyLeonardo da VinciList of mass shootings in the United States in 2023Hiroyuki SanadaFirst Minister of ScotlandWinston Churchill2023 Miami Open – Men's singlesTom Cruise2022–23 CONCACAF Nations LeagueIce SpiceKari MatchettDakota JohnsonNicholas HoultElvis PresleyAmy Jo JohnsonRonald ReaganCanadaBrad Pitt🡆 More