class ShapeHelper {

    public static List<Shape> splitLine(Shape line, double firstLineLength) {

        ArrayList<Shape> shapes = new ArrayList<Shape>();

        if (ShapeHelper.getLineLength(line) < firstLineLength) {
            shapes.add(line);
            return shapes;
        }

        PathIterator it = line.getPathIterator(null, FLATNESS);
        double coords[] = new double[6];
        Path2D.Double segment = new Path2D.Double();
        double p = 0.0;
        double p1;

        it.currentSegment(coords);

        double x1 = coords[0];
        double y1 = coords[1];
        segment.moveTo(x1, y1);

        double xFirst = x1;
        double yFirst = y1;

        it.next();

        double x2;
        double y2;

        boolean first = true;

        while (!it.isDone()) {
            int type = it.currentSegment(coords);

            if (type == PathIterator.SEG_CLOSE) {
                x2 = xFirst;
                y2 = yFirst;
            } else {
                x2 = coords[0];
                y2 = coords[1];
            }

            double xx, yy;
            xx = x2 - x1;
            yy = y2 - y1;
            p1 = Math.sqrt(xx * xx + yy * yy);
            p += p1;

            if (first && p > firstLineLength) {
                first = false;
                // Le point courant dépasse la limite de longueur
                double delta = (p - firstLineLength);

                // Obtenir le point qui est exactement à la limite
                Point2D.Double pt = getPointAt(x1, y1, x2, y2, p1 - delta);

                x1 = pt.x;
                y1 = pt.y;

                // On termine le segment, l'ajoute à la liste de shapes
                segment.lineTo(x1, y1);
                p = 0;
                shapes.add(segment);

                // Et commence le nouveau segment à
                segment = new Path2D.Double();
                segment.moveTo(x1, y1);

            } else {
                // Le point courant dépasse la limite de longueur
                segment.lineTo(x2, y2);
                x1 = x2;
                y1 = y2;
                it.next();
            }
        }
        //last segment end with last point

        shapes.add(segment);

        return shapes;
    }

    private  ShapeHelper();

}