Skip to main content

Posts

Showing posts with the label graphics2d

Hit test on Graphics2D object?

I have a few Graphics2D objects (Line2D, Rectangle2D, Ellipse2D, Rectangle2D) and a GeneralPath. I know that if I want to hit test on them I could use the .contains(Point) method, but I need to hit test on these objects when they are not filled in. So I just want to test if the user clicked on their border/line. I don't need to worry about the thickness of the border for now. Let's say that I just need to worry if the user clicked within 10 pixels from the border/line. I do have a MouseListener where I can get the coordinates of the mouse click, and my Graphics2D objects are stored on a data structure that I iterate over. I just don't know how to hit test on the lines/borders. Any suggestions will be appreciated!