Search code examples
javaswinggraphics2d

Java graphics2d: Verify if point is contained in region


I'm creating a java desktop application that draws a map in a JFrame designing a country at a time.

After closing the region region.closePath(); I need to know if a point is inside the region last drawn.

In JavaScript, there was the element canvas2d the function isPointInPath(x, y).

Is there something similar in java Graphics2D?


Solution

  • In my situation i was using the setTransform method.

    So, to contains method works correctly, i had to convert the point to the correct proportion of matrix.

    Like that:

    reg.contains(x / this.Matrix[0], y / this.Matrix[3])