Skip to content

Commit

Permalink
Monitor recursion depth and abort if too deep
Browse files Browse the repository at this point in the history
  • Loading branch information
wipfli committed Nov 7, 2024
1 parent 46a42da commit 4bb3b49
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public static void main(String[] args) throws Exception {
lm.add(geom);
return lm.getMergedLineStrings();
});
// time("loop(20.0)", geom -> {
// var lm = new LoopLineMerger();
// lm.setLoopMinLength(20.0);
// lm.setMinLength(0.1);
// lm.add(geom);
// return lm.getMergedLineStrings();
// });
time("loop(20.0)", geom -> {
var lm = new LoopLineMerger();
lm.setLoopMinLength(20.0);
lm.setMinLength(0.1);
lm.add(geom);
return lm.getMergedLineStrings();
});
}
System.err.println(numLines);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ private void removeLoops() {
}
}
}
else {
// MAX_RECURSION_DEPTH was reached. On other edges of the graph the same
// will happen. Abort merging loops...
return;
}
}
}
}
Expand All @@ -119,7 +124,17 @@ List<List<Edge>> findAllPaths(Node start, Node end, double maxLength) {
}
}

var MAX_RECURSION_DEPTH = 1e6;
var currentDepth = 0;

while (!queue.isEmpty()) {

currentDepth += 1;
if (currentDepth > MAX_RECURSION_DEPTH) {
System.out.println("Warning: max recursion depth reached. Unable to perform loop merging...");
return new ArrayList<>();
}

List<Edge> currentPath = queue.poll();
Node currentPoint = currentPath.getLast().to;

Expand Down

0 comments on commit 4bb3b49

Please sign in to comment.