Working with the Shape operations

There are three operations that allow for the combining of two shapes into one:

  • Union: Combines two shapes
  • Intersect: Leaves only the shared part of two shapes
  • Subtract: Removes the shared part from the first shape

These are static methods that can be applied to any two shapes:

Circle circle = new Circle(30);Rectangle rect = new Rectangle(45, 45);        root.getChildren().addAll(    Shape.union(circle, rect),    Shape.intersect(circle, rect),    Shape.subtract(circle, rect));

The output is as follows:

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.