src/main/java/de/javagl/geom/Shapes.java
/**
     * Computes the length of the given shape (i.e. its border)
     * 
     * @param shape The shape
     * @param flatness The flatness for the iteration
     * @return The length of the given shape
     */
Computes the length of the given shape

@param shape The shape
@param flatness The flatness for the iteration
@return The length of the given shape
Computes the length of the given shape @param shape The shape @param flatness The flatness for the iteration @return The length of the given shape
public static double computeLength(
        Shape shape, double flatness)
    {
        PathIterator pi = shape.getPathIterator(null, flatness);
        double coords[] = new double[6];
        double previousMoveX = 0;
        double previousMoveY = 0;
        double length = 0;
        while (!pi.isDone())
        {
            switch (pi.currentSegment(coords))
            {
                case PathIterator.SEG_MOVETO:
                    previousMoveX = coords[0];
                    previousMoveY = coords[1];
                    break;
                case PathIterator.SEG_LINETO:
                case PathIterator.SEG_CLOSE:
                {
                    double dx = coords[0] - previousMoveX;
                    double dy = coords[1] - previousMoveY;
                    double distance = Math.sqrt(dx * dx + dy * dy);
                    length += distance;
                    break;
                }
                case PathIterator.SEG_CUBICTO:
                case PathIterator.SEG_QUADTO:
                default:
                    throw new AssertionError(
                        "Invalid segment in flattened path");
            }
            pi.next();
        }
        return length;
    }
public static double computeLength ( Shape shape , double flatness ) { PathIterator pi = shape . getPathIterator ( null , flatness ) ; double coords [ ] = new double [ 6 ] ; double previousMoveX = 0 ; double previousMoveY = 0 ; double length = 0 ; while ( ! pi . isDone ( ) ) { switch ( pi . currentSegment ( coords ) ) { case PathIterator . SEG_MOVETO : previousMoveX = coords [ 0 ] ; previousMoveY = coords [ 1 ] ; break ; case PathIterator . SEG_LINETO : case PathIterator . SEG_CLOSE : { double dx = coords [ 0 ] - previousMoveX ; double dy = coords [ 1 ] - previousMoveY ; double distance = Math . sqrt ( dx * dx + dy * dy ) ; length += distance ; break ; } case PathIterator . SEG_CUBICTO : case PathIterator . SEG_QUADTO : default : throw new AssertionError ( "Invalid segment in flattened path" ) ; } pi . next ( ) ; } return length ; }
Computes the length of the given shape (i.e.
Computes the length of the given shape ( i . e .