private Edge mergeTwoEdges(Node node, Edge edge1, Edge edge2) {
    // attempt to preserve segment directions from the original line
    // when: A << N -- B then output C reversed from B to A
    // when: A >> N -- B then output C from A to B
    Edge a = edge1.main ? edge2 : edge1;
    Edge b = edge1.main ? edge1 : edge2;
    node.getEdges().remove(a);
    node.getEdges().remove(b);
    List<Coordinate> coordinates = new ArrayList<>();
    coordinates.addAll(a.coordinates.reversed());
    coordinates.addAll(b.coordinates.subList(1, b.coordinates.size()));
    Edge c = new Edge(a.to, b.to, coordinates, a.length + b.length);
    a.to.removeEdge(a.reversed);
    b.to.removeEdge(b.reversed);
    a.to.addEdge(c);
    if (a.to != b.to) {
      b.to.addEdge(c.reversed);
    }
    return c;
  }
Adds a geometry to the merger. Only linestrings from the input geometry are considered.
planetiler-core/src/main/java/com/onthegomap/planetiler/util/LoopLineMerger.java