Changeset 11441 in josm for trunk/src/org


Ignore:
Timestamp:
2017-01-07T17:19:05+01:00 (7 years ago)
Author:
Don-vip
Message:

fix #14202 - fix self-intersecting way test (patch by GerdP)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/validation/tests/SelfIntersectingWay.java

    r11149 r11441  
    3131    @Override
    3232    public void visit(Way w) {
     33        int last = w.getNodesCount();
     34        if (last < 2)
     35            return;
    3336        Set<Node> nodes = new HashSet<>();
    34         for (int i = 1; i < w.getNodesCount() - 1; i++) {
     37        nodes.add(w.firstNode());
     38        int countFirst = 0;
     39        int countLast = 0;
     40        for (int i = 1; i < last; i++) {
    3541            Node n = w.getNode(i);
    3642            if (nodes.contains(n)) {
    37                 errors.add(TestError.builder(this, Severity.WARNING, SELF_INTERSECT)
    38                         .message(tr("Self-intersecting ways"))
    39                         .primitives(w)
    40                         .highlight(n)
    41                         .build());
    42                 break;
     43                boolean ok = false;
     44                if (n == w.firstNode()) {
     45                    if (countFirst++ == 0)
     46                        ok = true;
     47                } else if (i + 1 == last) {
     48                    if (countLast++ == 0)
     49                        ok = true;
     50                }
     51                if (!ok || countFirst + countLast > 1) {
     52                    errors.add(TestError.builder(this, Severity.WARNING, SELF_INTERSECT)
     53                            .message(tr("Self-intersecting ways"))
     54                            .primitives(w)
     55                            .highlight(n)
     56                            .build());
     57                    break;
     58                }
    4359            } else {
    4460                nodes.add(n);
Note: See TracChangeset for help on using the changeset viewer.