private void breakLoops() {
    for (var node : output) {
      if (node.getEdges().size() <= 1) {
        continue;
      }
      for (var current : List.copyOf(node.getEdges())) {
        record HasLoop(Edge edge, double distance) {}
        List<HasLoop> loops = new ArrayList<>();
        if (!node.getEdges().contains(current)) {
          continue;
        }
        for (var other : node.getEdges()) {
          double distance = other.length +
            shortestDistanceAStar(other.to, current.to, current.from, loopMinLength - other.length);
          if (distance <= loopMinLength) {
            loops.add(new HasLoop(other, distance));
          }
        }
        if (loops.size() > 1) {
          HasLoop min = loops.stream().min(Comparator.comparingDouble(HasLoop::distance)).get();
          for (var loop : loops) {
            if (loop != min) {
              loop.edge.remove();
            }
          }
        }
      }
    }
  }
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