Convert a JavaFX Shape to Path. - Java javafx.scene.shape

Java examples for javafx.scene.shape:Path

Description

Convert a JavaFX Shape to Path.

Demo Code


//package com.java2s;

import javafx.scene.shape.Path;

import javafx.scene.shape.Shape;

public class Main {
    /**/*from w  ww .  ja  v  a  2  s.c om*/
     * Convert a Shape to Path.
     *
     * @param shape
     * @return
     */
    public static Path shapeToPath(Shape shape) {
        if (shape == null) {
            return null;
        }
        if (shape instanceof Path) {
            return (Path) shape;
        }
        return (Path) Shape.union(createEmptyShape(), shape);
    }

    /**
     * Create an empty Shape.
     *
     * @return
     */
    public static Path createEmptyShape() {
        return new Path(); // The better, we can do !!!
    }
}

Related Tutorials