public static List<double[]> toDoubles(Shape s){
  List<double[]> coordLists=new ArrayList<double[]>();
  PathIterator pi2=s.getPathIterator(null);
  FlatteningPathIterator pi=new FlatteningPathIterator(pi2,.25);
  double[] coords=new double[6];
  double lastMovedToPntX=Double.NaN;
  double lastMovedToPntY=Double.NaN;
  List<Double> curCoord=null;
  while (!pi.isDone()) {
    int type=pi.currentSegment(coords);
    if (type == PathIterator.SEG_LINETO) {
      curCoord=assertList(curCoord);
      curCoord.add(coords[1]);
      curCoord.add(coords[0]);
    }
 else     if (type == PathIterator.SEG_MOVETO) {
      if (curCoord != null && !curCoord.isEmpty()) {
        coordLists.add(toArray(curCoord));
        curCoord=null;
      }
      lastMovedToPntX=coords[0];
      lastMovedToPntY=coords[1];
      curCoord=assertList(curCoord);
      curCoord.add(lastMovedToPntY);
      curCoord.add(lastMovedToPntX);
    }
 else     if (type == PathIterator.SEG_CLOSE) {
      final double x=coords[0];
      final double y=coords[1];
      if (x != lastMovedToPntX && y != lastMovedToPntY) {
        curCoord=assertList(curCoord);
        curCoord.add(y);
        curCoord.add(x);
      }
      if (curCoord != null && !curCoord.isEmpty()) {
        coordLists.add(toArray(curCoord));
        curCoord=null;
      }
    }
    pi.next();
  }
  if (curCoord != null && !curCoord.isEmpty()) {
    coordLists.add(toArray(curCoord));
  }
  return coordLists;
}

public static List < double [ ] > toDoubles ( Shape s ) { List < double [ ] > coordLists = new ArrayList < double [ ] > ( ) ; PathIterator pi2 = s . getPathIterator ( null ) ; FlatteningPathIterator pi = new FlatteningPathIterator ( pi2 , .25 ) ; double [ ] coords = new double [ 6 ] ; double lastMovedToPntX = Double . NaN ; double lastMovedToPntY = Double . NaN ; List < Double > curCoord = null ; while ( ! pi . isDone ( ) ) { int type = pi . currentSegment ( coords ) ; if ( type == PathIterator . SEG_LINETO ) { curCoord = assertList ( curCoord ) ; curCoord . add ( coords [ 1 ] ) ; curCoord . add ( coords [ 0 ] ) ; } else if ( type == PathIterator . SEG_MOVETO ) { if ( curCoord != null && ! curCoord . isEmpty ( ) ) { coordLists . add ( toArray ( curCoord ) ) ; curCoord = null ; } lastMovedToPntX = coords [ 0 ] ; lastMovedToPntY = coords [ 1 ] ; curCoord = assertList ( curCoord ) ; curCoord . add ( lastMovedToPntY ) ; curCoord . add ( lastMovedToPntX ) ; } else if ( type == PathIterator . SEG_CLOSE ) { final double x = coords [ 0 ] ; final double y = coords [ 1 ] ; if ( x != lastMovedToPntX && y != lastMovedToPntY ) { curCoord = assertList ( curCoord ) ; curCoord . add ( y ) ; curCoord . add ( x ) ; } if ( curCoord != null && ! curCoord . isEmpty ( ) ) { coordLists . add ( toArray ( curCoord ) ) ; curCoord = null ; } } pi . next ( ) ; } if ( curCoord != null && ! curCoord . isEmpty ( ) ) { coordLists . add ( toArray ( curCoord ) ) ; } return coordLists ; }
convert a shape object into a list of double [ ] . separate double [ ] are created in case there ' s a moveto in the order of coordinates in shape .
