Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Nov 24, 2024
1 parent 12987ca commit 0839dae
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ private void simplify() {
for (var node : output) {
for (var edge : node.getEdges()) {
if (edge.main) {
if (!edge.simplify()) {
edge.simplify();
if (edge.isCollapsed()) {
toRemove.add(edge);
}
}
Expand Down Expand Up @@ -551,13 +552,16 @@ void remove() {
return length;
}

/** Returns {@code false} if simplifying this edge collapsed it to {@code length=0}. */
boolean simplify() {
void simplify() {
coordinates = DouglasPeuckerSimplifier.simplify(coordinates, tolerance, false);
if (reversed != null) {
reversed.coordinates = coordinates.reversed();
}
return coordinates.size() != 2 || !coordinates.getFirst().equals(coordinates.getLast());
}

boolean isCollapsed() {
return coordinates.size() < 2 ||
(coordinates.size() == 2 && coordinates.getFirst().equals(coordinates.getLast()));
}

@Override
Expand Down

0 comments on commit 0839dae

Please sign in to comment.