Search code examples
javagwtshapespoint-in-polygon

gwt-g2d: How to detect if point is in shape?


I'm trying to detect if a point is within an gwt-g2d shape. Does anybody know how this is possible?

I just can determine if the point is within any path in the context.

Lets say I have a context with two rectangle (A & B) and want to determine in which rectangle the mouse is, how can I do this?

 ________________________
|   _______    _______   |
|  |       |  |       |  |
|  |   A   |  |   B   |  |
|  |_______|  |_______|  |
|________________________|

The rectangles were just examples, I also want to determine if the point is in complex shapes.


Solution

  • You could look up the point-in-polygon problem. If you have a lot of polygons people also tend to narrow down the possibilities by storing the left,right,bottom, and top-most points of a polygon (or storing the radius and center point of a circle enclosing the polygon) so that they can quickly determine whether the point could even possibly be inside the polygon.