src/main/java/de/javagl/geom/Shapes.java
/**
     * Computes the list of sub-shapes of the given shape. These are the
     * shapes that are separated in the given shape via SEG_MOVETO or 
     * SEG_CLOSE operations
     * 
     * @param shape The input shape
     * @return The sub-shapes
     */
Computes the list of sub-shapes of the given shape. These are the
shapes that are separated in the given shape via SEG_MOVETO or
SEG_CLOSE operations

@param shape The input shape
@return The sub-shapes
Computes the list of sub - shapes of the given shape . These are the shapes that are separated in the given shape via SEG_MOVETO or SEG_CLOSE operations @param shape The input shape @return The sub - shapes
public static List<Shape> computeSubShapes(Shape shape)
    {
        List<Shape> result = new ArrayList<Shape>();
        PathIterator pi = shape.getPathIterator(null);
        double[] coords = new double[6];
        double previous[] = new double[2];
        double first[] = new double[2];
        Path2D currentShape = null;
        while (!pi.isDone())
        {
            int segment = pi.currentSegment(coords);
            switch (segment)
            {
                case PathIterator.SEG_MOVETO:
                    if (currentShape != null)
                    {
                         result.add(currentShape);
                         currentShape = null;
                    }
                    previous[0] = coords[0];
                    previous[1] = coords[1];
                    first[0] = coords[0];
                    first[1] = coords[1];
                    break;
                case PathIterator.SEG_CLOSE:
                    if (currentShape != null)
                    {
                        currentShape.closePath();
                        result.add(currentShape);
                        currentShape = null;
                    }
                    previous[0] = first[0];
                    previous[1] = first[1];
                    break;
                case PathIterator.SEG_LINETO:
                    if (currentShape == null)
                    {
                        currentShape = new Path2D.Double();
                        currentShape.moveTo(previous[0], previous[1]);
                    }
                    currentShape.lineTo(coords[0], coords[1]);
                    previous[0] = coords[0];
                    previous[1] = coords[1];
                    break;
                case PathIterator.SEG_QUADTO:
                    if (currentShape == null)
                    {
                        currentShape = new Path2D.Double();
                        currentShape.moveTo(previous[0], previous[1]);
                    }
                    currentShape.quadTo(
                        coords[0], coords[1], 
                        coords[2], coords[3]);
                    previous[0] = coords[2];
                    previous[1] = coords[3];
                    break;
                case PathIterator.SEG_CUBICTO:
                    if (currentShape == null)
                    {
                        currentShape = new Path2D.Double();
                        currentShape.moveTo(previous[0], previous[1]);
                    }
                    currentShape.curveTo(
                        coords[0], coords[1], 
                        coords[2], coords[3],
                        coords[4], coords[5]);
                    previous[0] = coords[4];
                    previous[1] = coords[5];
                    break;
                default:
                    throw new AssertionError(
                        "Invalid segment in path!");
            }
            pi.next();
        }
        if (currentShape != null)
        {
             result.add(currentShape);
             currentShape = null;
        }
        return result;
    }
public static List < Shape > computeSubShapes ( Shape shape ) { List < Shape > result = new ArrayList < Shape > ( ) ; PathIterator pi = shape . getPathIterator ( null ) ; double [ ] coords = new double [ 6 ] ; double previous [ ] = new double [ 2 ] ; double first [ ] = new double [ 2 ] ; Path2D currentShape = null ; while ( ! pi . isDone ( ) ) { int segment = pi . currentSegment ( coords ) ; switch ( segment ) { case PathIterator . SEG_MOVETO : if ( currentShape != null ) { result . add ( currentShape ) ; currentShape = null ; } previous [ 0 ] = coords [ 0 ] ; previous [ 1 ] = coords [ 1 ] ; first [ 0 ] = coords [ 0 ] ; first [ 1 ] = coords [ 1 ] ; break ; case PathIterator . SEG_CLOSE : if ( currentShape != null ) { currentShape . closePath ( ) ; result . add ( currentShape ) ; currentShape = null ; } previous [ 0 ] = first [ 0 ] ; previous [ 1 ] = first [ 1 ] ; break ; case PathIterator . SEG_LINETO : if ( currentShape == null ) { currentShape = new Path2D . Double ( ) ; currentShape . moveTo ( previous [ 0 ] , previous [ 1 ] ) ; } currentShape . lineTo ( coords [ 0 ] , coords [ 1 ] ) ; previous [ 0 ] = coords [ 0 ] ; previous [ 1 ] = coords [ 1 ] ; break ; case PathIterator . SEG_QUADTO : if ( currentShape == null ) { currentShape = new Path2D . Double ( ) ; currentShape . moveTo ( previous [ 0 ] , previous [ 1 ] ) ; } currentShape . quadTo ( coords [ 0 ] , coords [ 1 ] , coords [ 2 ] , coords [ 3 ] ) ; previous [ 0 ] = coords [ 2 ] ; previous [ 1 ] = coords [ 3 ] ; break ; case PathIterator . SEG_CUBICTO : if ( currentShape == null ) { currentShape = new Path2D . Double ( ) ; currentShape . moveTo ( previous [ 0 ] , previous [ 1 ] ) ; } currentShape . curveTo ( coords [ 0 ] , coords [ 1 ] , coords [ 2 ] , coords [ 3 ] , coords [ 4 ] , coords [ 5 ] ) ; previous [ 0 ] = coords [ 4 ] ; previous [ 1 ] = coords [ 5 ] ; break ; default : throw new AssertionError ( "Invalid segment in path!" ) ; } pi . next ( ) ; } if ( currentShape != null ) { result . add ( currentShape ) ; currentShape = null ; } return result ; }
Computes the list of sub-shapes of the given shape.
Computes the list of sub - shapes of the given shape .
// Should never occur
