javafxgeometrynodesbounds

Can Someone Explain Why .intersects returns true here?


Image of an example of issue

enter image description here

.intersects is called on both of these nodes and returns true. I used getBoundsInParent() for both. Can someone help me fix this issue. I feel it as something to do with getBoundsInParent() not returning accurate bounds for circles but idk. Thanks


Solution

  • getBoundsInParent() returns a Bounds object. https://openjfx.io/javadoc/11/javafx.graphics/javafx/geometry/Bounds.html

    Look at the properties of Bounds. It represents a bounding "box". It does not account for the curvature of a circle.

    If you want to see if the Circle intersects the Rectangle. There are a few options. You could calculate the intersecting Shape with Shape.intersect(Shape shape1, Shape shape2) and see if the bounds of the result has a non-zero dimension.