Mastering JavaFX 10
上QQ阅读APP看书,第一时间看更新

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: