Changeset 5199 in josm


Ignore:
Timestamp:
2012-04-17T21:03:50+02:00 (12 years ago)
Author:
simon04
Message:

fix #7546 - add validation warning Superfluous turnrestriction as "to" way is oneway

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

Legend:

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

    r5187 r5199  
    591591        return length;
    592592    }
     593
     594    /**
     595     * Tests if this way is a oneway.
     596     * @return {@code 1} if the way is a oneway, {@code -1} if the way is a reversed oneway,
     597     * {@code 0} otherwise.
     598     */
     599    public int isOneway() {
     600        String oneway = get("oneway");
     601        if (oneway != null) {
     602            if ("-1".equals(oneway)) {
     603                return -1;
     604            } else {
     605                Boolean isOneway = OsmUtils.getOsmBoolean(oneway);
     606                if (isOneway != null && isOneway) {
     607                    return 1;
     608                }
     609            }
     610        }
     611        return 0;
     612    }
     613
     614    public Node firstNode(boolean respectOneway) {
     615        return !respectOneway || isOneway() != -1 ? firstNode() : lastNode();
     616    }
     617
     618    public Node lastNode(boolean respectOneway) {
     619        return !respectOneway || isOneway() != -1 ? lastNode() : firstNode();
     620    }
    593621}
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TurnrestrictionTest.java

    r4806 r5199  
    1111import org.openstreetmap.josm.data.osm.Node;
    1212import org.openstreetmap.josm.data.osm.OsmPrimitive;
    13 import org.openstreetmap.josm.data.osm.OsmUtils;
    1413import org.openstreetmap.josm.data.osm.Relation;
    1514import org.openstreetmap.josm.data.osm.RelationMember;
     
    3534    protected static final int MIX_VIA = 1813;
    3635    protected static final int UNCONNECTED_VIA = 1814;
     36    protected static final int SUPERFLUOUS = 1815;
    3737
    3838    public TurnrestrictionTest() {
     
    137137        }
    138138
    139         Node viaNode;
    140139        if (via.get(0) instanceof Node) {
    141             viaNode = (Node) via.get(0);
    142             Way viaPseudoWay = new Way();
     140            final Node viaNode = (Node) via.get(0);
     141            final Way viaPseudoWay = new Way();
    143142            viaPseudoWay.addNode(viaNode);
    144143            checkIfConnected(fromWay, viaPseudoWay,
    145144                    tr("The \"from\" way does not start or end at a \"via\" node"), FROM_VIA_NODE);
     145            if (toWay.isOneway() != 0 && viaNode.equals(toWay.lastNode(true))) {
     146                errors.add(new TestError(this, Severity.WARNING, tr("Superfluous turnrestriction as \"to\" way is oneway"), SUPERFLUOUS, r));
     147                return;
     148            }
    146149            checkIfConnected(viaPseudoWay, toWay,
    147150                    tr("The \"to\" way does not start or end at a \"via\" node"), TO_VIA_NODE);
    148151        } else {
    149152            // check if consecutive ways are connected: from/via[0], via[i-1]/via[i], via[last]/to
    150             checkIfConnected(fromWay, (Way) via.get(0), 
     153            checkIfConnected(fromWay, (Way) via.get(0),
    151154                    tr("The \"from\" and the first \"via\" way are not connected."), FROM_VIA_WAY);
    152155            if (via.size() > 1) {
     
    158161                }
    159162            }
     163            if (toWay.isOneway() != 0 && ((Way) via.get(via.size() - 1)).isFirstLastNode(toWay.lastNode(true))) {
     164                errors.add(new TestError(this, Severity.WARNING, tr("Superfluous turnrestriction as \"to\" way is oneway"), SUPERFLUOUS, r));
     165                return;
     166            }
    160167            checkIfConnected((Way) via.get(via.size() - 1), toWay,
    161168                    tr("The last \"via\" and the \"to\" way are not connected."), TO_VIA_WAY);
     
    165172
    166173    private void checkIfConnected(Way previous, Way current, String msg, int code) {
    167         int onewayPrevious = isOneway(previous);
    168         int onewayCurrent = isOneway(current);
    169         Node endPrevious = onewayPrevious != -1 ? previous.lastNode() : previous.firstNode();
    170         Node startCurrent = onewayCurrent != -1 ? current.firstNode() : current.lastNode();
    171         //System.out.println(previous.getUniqueId() + " -- " + current.getUniqueId() + ": " + onewayPrevious + "/" + onewayCurrent + " " + endPrevious.getUniqueId() + "/" + startCurrent.getUniqueId());
    172174        boolean c;
    173         if (onewayPrevious != 0 && onewayCurrent != 0) {
     175        if (previous.isOneway() != 0 && current.isOneway() != 0) {
    174176            // both oneways: end/start node must be equal
    175             c = endPrevious.equals(startCurrent);
    176         } else if (onewayPrevious != 0) {
     177            c = previous.lastNode(true).equals(current.firstNode(true));
     178        } else if (previous.isOneway() != 0) {
    177179            // previous way is oneway: end of previous must be start/end of current
    178             c = current.isFirstLastNode(endPrevious);
    179         } else if (onewayCurrent != 0) {
     180            c = current.isFirstLastNode(previous.lastNode(true));
     181        } else if (current.isOneway() != 0) {
    180182            // current way is oneway: start of current must be start/end of previous
    181             c = previous.isFirstLastNode(startCurrent);
     183            c = previous.isFirstLastNode(current.firstNode(true));
    182184        } else {
    183185            // otherwise: start/end of previous must be start/end of current
     
    188190        }
    189191    }
    190 
    191     private static int isOneway(Way w) {
    192         String onewayviastr = w.get("oneway");
    193         if (onewayviastr != null) {
    194             if ("-1".equals(onewayviastr)) {
    195                 return -1;
    196             } else {
    197                 Boolean onewayvia = OsmUtils.getOsmBoolean(onewayviastr);
    198                 if (onewayvia != null && onewayvia) {
    199                     return 1;
    200                 }
    201             }
    202         }
    203         return 0;
    204     }
    205192}
Note: See TracChangeset for help on using the changeset viewer.