How can I tell if a closed path contains a given point?

Posted by Tom Seago on Stack Overflow See other posts from Stack Overflow or by Tom Seago
Published on 2010-04-08T04:33:41Z Indexed on 2010/04/08 4:43 UTC
Read the original article Hit count: 241

Filed under:
|

In Android, I have a Path object which I happen to know defines a closed path, and I need to figure out if a given point is contained within the path. What I was hoping for was something along the lines of

path.contains(int x, int y)

but that doesn't seem to exist.

The specific reason I'm looking for this is because I have a collection of shapes on screen defined as paths, and I want to figure out which one the user clicked on. If there is a better way to be approaching this such as using different UI elements rather than doing it "the hard way" myself, I'm open to suggestions.

I'm open to writing an algorithm myself if I have to, but that means different research I guess.

© Stack Overflow or respective owner

Related posts about android

Related posts about graphics