Changeset 17289 in josm


Ignore:
Timestamp:
2020-11-02T09:04:47+01:00 (4 weeks ago)
Author:
GerdP
Message:

fix #20013: When combining two ways and one of them needs to have the direction changed then JOSM doesn't consider effects on stop and give way signs

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/corrector/ReverseWayTagCorrector.java

    r16771 r17289  
    1414import java.util.regex.Matcher;
    1515import java.util.regex.Pattern;
     16import java.util.stream.Collectors;
    1617
    1718import org.openstreetmap.josm.command.Command;
     
    2526import org.openstreetmap.josm.data.osm.RelationMember;
    2627import org.openstreetmap.josm.data.osm.Tag;
    27 import org.openstreetmap.josm.data.osm.TagCollection;
    2828import org.openstreetmap.josm.data.osm.Tagged;
    2929import org.openstreetmap.josm.data.osm.Way;
     
    174174     * Tests whether way can be reversed without semantic change, i.e., whether tags have to be changed.
    175175     * Looks for keys like oneway, oneway:bicycle, cycleway:right:oneway, left/right.
     176     * Also tests the nodes, e.g. a highway=stop with direction, see #20013.
    176177     * @param way way to test
    177178     * @return false if tags should be changed to keep semantic, true otherwise.
    178179     */
    179180    public static boolean isReversible(Way way) {
    180         for (Tag tag : TagCollection.from(way)) {
    181             if (!tag.equals(TagSwitcher.apply(tag))) {
    182                 return false;
    183             }
    184         }
    185         return true;
     181        return getTagCorrectionsMap(way).isEmpty();
    186182    }
    187183
     
    193189     */
    194190    public static List<Way> irreversibleWays(List<Way> ways) {
    195         List<Way> newWays = new ArrayList<>(ways);
    196         for (Way way : ways) {
    197             if (isReversible(way)) {
    198                 newWays.remove(way);
    199             }
    200         }
    201         return newWays;
     191        return ways.stream().filter(w -> !isReversible(w)).collect(Collectors.toList());
    202192    }
    203193
  • trunk/test/unit/org/openstreetmap/josm/actions/corrector/ReverseWayTagCorrectorTest.java

    r17275 r17289  
    88
    99import org.junit.Assert;
     10import org.junit.jupiter.api.Test;
    1011import org.junit.jupiter.api.extension.RegisterExtension;
    11 import org.junit.jupiter.api.Test;
    1212import org.openstreetmap.josm.data.correction.TagCorrection;
    1313import org.openstreetmap.josm.data.osm.Node;
     
    108108    }
    109109
    110     private Map<OsmPrimitive, List<TagCorrection>> getTagCorrectionsForWay(String middleNodeTags) {
     110    private Way buildWayWithMiddleNode(String middleNodeTags) {
    111111        final OsmPrimitive n1 = OsmUtils.createPrimitive("node");
    112112        final OsmPrimitive n2 = OsmUtils.createPrimitive("node " + middleNodeTags);
     
    114114        final Way w = new Way();
    115115        Stream.of(n1, n2, n3).map(Node.class::cast).forEach(w::addNode);
     116        return w;
     117    }
     118
     119    private Map<OsmPrimitive, List<TagCorrection>> getTagCorrectionsForWay(String middleNodeTags) {
     120        Way w = buildWayWithMiddleNode(middleNodeTags);
    116121        return ReverseWayTagCorrector.getTagCorrectionsMap(w);
    117122    }
     
    136141        Assert.assertEquals(0, getTagCorrectionsForWay("direction=145").size());
    137142    }
     143
     144    /**
     145     * Tests that IsReversible() also works for nodes. See #20013
     146     */
     147    @Test
     148    void testIsReversible() {
     149        Way w0 = buildWayWithMiddleNode("highway=stop");
     150        Assert.assertTrue(ReverseWayTagCorrector.isReversible(w0));
     151        Way w1 = buildWayWithMiddleNode("direction=forward");
     152        Assert.assertFalse(ReverseWayTagCorrector.isReversible(w1));
     153        Assert.assertEquals(3, w1.getNodesCount());
     154        w1.getNodes().forEach(n -> n.setKeys(null));
     155        Assert.assertTrue(ReverseWayTagCorrector.isReversible(w1));
     156        w1.put("oneway", "yes");
     157        Assert.assertFalse(ReverseWayTagCorrector.isReversible(w1));
     158    }
     159
    138160}
Note: See TracChangeset for help on using the changeset viewer.