Coordinates and bounds
Let's look into determining Shape
and Node
bounds in Scene
and Scenegraph.
The simplest of all are layoutBounds
. These rectangular bounds are used for all size and location calculations for this Node, and describe its basic shape size. They don't include any extra effects or transformations.
The next thing is boundsInLocal
. These bounds include all information about effects. So, you can determine how large of an area is covered by your Node or Shape.
The last one is boundsInParent
. These are bounds after all transformations as well and bounding rectangles uses their parents' coordinate system.
Working with Bounds Demo
There is a very nice public demo by Kishori Sharan that shows how bounds work: http://www.java2s.com/Tutorials/Java/JavaFX_How_to/Node/Know_how_three_bounds_layoutBounds_boundsInLocal_and_boundsInParent_are_computed_for_a_node.htm.
It uses a deprecated API, so I've fixed it and added it to our GitHub as chapter2/other/BoundsDemo.java
.
In the following screenshot...