Create a new shape of JavaFX Shape to be the combined area of its current shape and the shape of the specified Shape, minus their intersection. - Java javafx.scene.shape

Java examples for javafx.scene.shape:Shape

Description

Create a new shape of JavaFX Shape to be the combined area of its current shape and the shape of the specified Shape, minus their intersection.

Demo Code


//package com.java2s;

import javafx.scene.shape.Shape;

public class Main {
    /**/*from   w  w w .  ja v  a 2s.co m*/
     * Create a new shape of this <code>Shape</code> to be the combined area of
     * its current shape and the shape of the specified <code>Shape</code>,
     * minus their intersection. The resulting shape of this <code>Shape</code>
     * will include only areas that were contained in either this
     * <code>Shape</code> or in the specified <code>Shape</code>, but not in
     * both.
     * <pre>
     *     // Example:
     *     Area a1 = new Area([triangle 0,0 =&gt; 8,0 =&gt; 0,8]);
     *     Area a2 = new Area([triangle 0,0 =&gt; 8,0 =&gt; 8,8]);
     *     a1.exclusiveOr(a2);
     *
     *        a1(before)    xor        a2         =     a1(after)
     *
     *     ################     ################
     *     ##############         ##############     ##            ##
     *     ############             ############     ####        ####
     *     ##########                 ##########     ######    ######
     *     ########                     ########     ################
     *     ######                         ######     ######    ######
     *     ####                             ####     ####        ####
     *     ##                                 ##     ##            ##
     * </pre>
     *
     * @param shape the <code>Shape</code> origin
     * @param rhs the <code>Shape</code> to be exclusive ORed with this
     * <code>Shape</code>.
     * @return
     */
    public static Shape exclusiveOr(Shape shape, Shape rhs) {
        // Area aspect of Shape not accessible.
        // No NullPointerException if shape and|or rhs is null
        Shape result1 = Shape.union(shape, rhs); // add
        Shape result2 = Shape.intersect(shape, rhs); // intersect
        return Shape.subtract(result1, result2); // subtract;
        // Note: The operation return a Path...
    }
}

Related Tutorials