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(' ', '');
        points[p1Loc] = Point(double.parse(points1[0]), double.parse(points1[1]));
        String p2Loc = temp[k].replaceAll(' ', '');
        points[p2Loc] = Point(double.parse(points2[0]), double.parse(points2[1]));
        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]);
  }
  return placePoints(getPolys(edges), points);
}