Connect closest node instead of first node below threshold in polygons.
This commit is contained in:
parent
428a48533c
commit
b4fb13bca9
|
@ -840,18 +840,25 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
|
|||
private int closeVerticesConnections(final List<ConnectableSegment> segments) {
|
||||
int connected = 0;
|
||||
for (final ConnectableSegment segment : segments) {
|
||||
if (segment.getNext() == null) {
|
||||
if (segment.getNext() == null && segment.getEnd() != null) {
|
||||
final Vector2D end = segment.getEnd();
|
||||
ConnectableSegment selectedNext = null;
|
||||
double min = Double.POSITIVE_INFINITY;
|
||||
for (final ConnectableSegment candidateNext : segments) {
|
||||
if (candidateNext.getPrevious() == null &&
|
||||
Vector2D.distance(end, candidateNext.getStart()) <= getTolerance()) {
|
||||
// connect the two segments
|
||||
segment.setNext(candidateNext);
|
||||
candidateNext.setPrevious(segment);
|
||||
++connected;
|
||||
break;
|
||||
if (candidateNext.getPrevious() == null && candidateNext.getStart() != null) {
|
||||
final double distance = Vector2D.distance(end, candidateNext.getStart());
|
||||
if (distance < min) {
|
||||
selectedNext = candidateNext;
|
||||
min = distance;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (min <= getTolerance()) {
|
||||
// connect the two segments
|
||||
segment.setNext(selectedNext);
|
||||
selectedNext.setPrevious(segment);
|
||||
++connected;
|
||||
}
|
||||
}
|
||||
}
|
||||
return connected;
|
||||
|
|
Loading…
Reference in New Issue