reduce method

String reduce(
  1. String path
)

Implementation

String reduce(String path){
  List<String> tosplit = path.split('z');
  Map<String,Point> points = {};
  Map<String,Edge> edges = {};
  List<String> edgesToRemove = [];

  String sort(List<double> edge){
    List<double> temp = [edge[2],edge[3],edge[0],edge[1]];
    temp.sort();
    return temp.toString().replaceAll(' ', '');
  }

  //get edges poits and ploys
  for(int i = 0; i < tosplit.length; i++){
    List<String> temp = tosplit[i].replaceAll('M', '').split('L');
    if(temp.first != ''){
      for(int j = 0; j < temp.length; j++){
        List<String> points1 = temp[j].split(',');
        int k = j != temp.length-1?j+1:0;
        List<String> points2 = temp[k].split(',');
        String p1Loc = temp[j].replaceAll(' ', '');
        double? x1 = double.tryParse(points1[0]);
        double? y1 = double.tryParse(points1[1]);
        if(x1 != null && y1 != null){
          points[p1Loc] = Point( x1, y1 );
        }
        else{ points[p1Loc] = Point( 0, 0 ); }
        String p2Loc = temp[k].replaceAll(' ', '');
        double? x2 = double.tryParse(points2[0]);
        double? y2 = double.tryParse(points2[1]);
        if(x2 != null && y2 != null){
          points[p2Loc] = Point( x2, y2 );
        }
        else{ points[p2Loc] = Point( 0, 0 ); }
        String edgeLoc = sort([points[p1Loc]!.x,points[p1Loc]!.y,points[p2Loc]!.x,points[p2Loc]!.y]);
        if(edges[edgeLoc] != null){
          edgesToRemove.add(edgeLoc);
        }
        edges[edgeLoc] = Edge(p1Loc,p2Loc);
      }
    }
  }
  for(int i = 0; i < edgesToRemove.length;i++){
    edges.remove(edgesToRemove[i]);
  }

  List<Polygon>? polys = getPolys(edges);
  //polys = removeInteriorPolygons(polys,points);
  return placePoints(polys,points);
}