Changeset 6556 in josm for trunk/src


Ignore:
Timestamp:
2013-12-28T23:17:38+01:00 (10 years ago)
Author:
simon04
Message:

fix #6313 - validator, UnconnectedWays: handle intersections of t shapes and similar

Location:
trunk/src/org/openstreetmap/josm/data
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/Node.java

    r6491 r6556  
    88import org.openstreetmap.josm.data.osm.visitor.Visitor;
    99import org.openstreetmap.josm.data.projection.Projections;
     10import org.openstreetmap.josm.tools.CheckParameterUtil;
     11import org.openstreetmap.josm.tools.Predicate;
     12import org.openstreetmap.josm.tools.Utils;
     13
     14import java.util.Collection;
     15import java.util.Set;
     16import java.util.TreeSet;
    1017
    1118/**
     
    337344        return false;
    338345    }
     346
     347    /**
     348     * Tests whether {@code this} node is connected to {@code otherNode} via at most {@code hops} nodes
     349     * matching the {@code predicate} (which may be {@code null} to consider all nodes).
     350     */
     351    public boolean isConnectedTo(final Collection<Node> otherNodes, final int hops, Predicate<Node> predicate) {
     352        CheckParameterUtil.ensureParameterNotNull(otherNodes);
     353        CheckParameterUtil.ensureThat(!otherNodes.isEmpty(), "otherNodes must not be empty!");
     354        CheckParameterUtil.ensureThat(hops >= 0, "hops must be non-negative!");
     355        return hops == 0
     356                ? isConnectedTo(otherNodes, hops, predicate, null)
     357                : isConnectedTo(otherNodes, hops, predicate, new TreeSet<Node>());
     358    }
     359
     360    private boolean isConnectedTo(final Collection<Node> otherNodes, final int hops, Predicate<Node> predicate, Set<Node> visited) {
     361        if (otherNodes.contains(this)) {
     362            return true;
     363        }
     364        if (hops > 0) {
     365            visited.add(this);
     366            for (final Way w : Utils.filteredCollection(this.getReferrers(), Way.class)) {
     367                for (final Node n : w.getNodes()) {
     368                    final boolean containsN = visited.contains(n);
     369                    visited.add(n);
     370                    if (!containsN && (predicate == null || predicate.evaluate(n)) && n.isConnectedTo(otherNodes, hops - 1, predicate, visited)) {
     371                        return true;
     372                    }
     373                }
     374            }
     375        }
     376        return false;
     377    }
    339378}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UnconnectedWays.java

    r6552 r6556  
    114114        mindist = Main.pref.getDouble(PREFIX + ".node_way_distance", 10.0);
    115115        minmiddledist = Main.pref.getDouble(PREFIX + ".way_way_distance", 0.0);
    116         dsArea = Main.main.getCurrentDataSet().getDataSourceArea();
     116        dsArea = Main.main == null || !Main.main.hasEditLayer() ? null : Main.main.getCurrentDataSet().getDataSourceArea();
    117117    }
    118118
     
    135135                        continue;
    136136                    }
    137                     // There's a small false-positive here.  Imagine an intersection
    138                     // like a 't'.  If the top part of the 't' is short enough, it
    139                     // will trigger the node at the very top of the 't' to be unconnected
    140                     // to the way that "crosses" the 't'.  We should probably check that
    141                     // the ways to which 'en' belongs are not connected to 's.w'.
     137                    // to handle intersections of 't' shapes and similar
     138                    if (en.isConnectedTo(s.w.getNodes(), 3 /* hops */, null)) {
     139                        continue;
     140                    }
    142141                    map.put(en, s.w);
    143142                }
Note: See TracChangeset for help on using the changeset viewer.