Changeset 11069 in josm for trunk


Ignore:
Timestamp:
2016-10-01T22:08:48+02:00 (3 years ago)
Author:
simon04
Message:

fix #10260 - Do not switch (absolute) cardinal directions / degrees

Location:
trunk
Files:
2 edited

Legend:

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

    r11061 r11069  
    55
    66import java.util.ArrayList;
    7 import java.util.Arrays;
    87import java.util.Collection;
    98import java.util.HashMap;
     
    8079            };
    8180        }
    82 
    83         static IStringSwitcher compassCardinal() {
    84             final List<String> cardinal = Arrays.asList(
    85                     "N", "NNE", "NE", "ENE", "E", "ESE", "SE", "SSE",
    86                     "S", "SSW", "SW", "WSW", "W", "WNW", "NW", "NNW");
    87             return key -> {
    88                 final int index = cardinal.indexOf(key);
    89                 if (index >= 0) {
    90                     return cardinal.get((index + cardinal.size() / 2) % cardinal.size());
    91                 }
    92                 return key;
    93             };
    94         }
    95 
    96         static IStringSwitcher compassDegrees() {
    97             return key -> {
    98                 if (!key.matches("\\d+")) {
    99                     return key;
    100                 }
    101                 final int i = Integer.parseInt(key);
    102                 if (i < 0 || i > 360) {
    103                     return key;
    104                 }
    105                 return Integer.toString((i + 180) % 360);
    106             };
    107         }
    108 
    109         static IStringSwitcher compass() {
    110             return combined(
    111                     IStringSwitcher.compassCardinal(),
    112                     IStringSwitcher.compassDegrees()
    113             );
    114         }
    11581    }
    11682
     
    188154            } else if (key.startsWith("direction") || key.endsWith("direction")) {
    189155                newValue = COMBINED_SWITCHERS.apply(value);
    190                 if (newValue.equals(value)) {
    191                     newValue = IStringSwitcher.compass().apply(value);
    192                 }
    193156            } else if (key.endsWith(":forward") || key.endsWith(":backward")) {
    194157                // Change key but not left/right value (fix #8518)
  • trunk/test/unit/org/openstreetmap/josm/corrector/ReverseWayTagCorrectorTest.java

    r11061 r11069  
    5353        assertSwitch(new Tag("direction", "backward"), new Tag("direction", "forward"));
    5454        assertSwitch(new Tag("direction", "north"), new Tag("direction", "south"));
    55         assertSwitch(new Tag("direction", "NNE"), new Tag("direction", "SSW"));
    56         assertSwitch(new Tag("direction", "270"), new Tag("direction", "90"));
    57         assertSwitch(new Tag("direction", "135"), new Tag("direction", "315"));
    58         assertSwitch(new Tag("direction", "337"), new Tag("direction", "157"));
    5955        // :left/:right with oneway (see #10977)
    6056        assertSwitch(new Tag("cycleway:left:oneway", "-1"), new Tag("cycleway:right:oneway", "yes"));
     
    118114    }
    119115
     116    private Map<OsmPrimitive, List<TagCorrection>> getTagCorrectionsForWay(String middleNodeTags) {
     117        final OsmPrimitive n1 = OsmUtils.createPrimitive("node");
     118        final OsmPrimitive n2 = OsmUtils.createPrimitive("node " + middleNodeTags);
     119        final OsmPrimitive n3 = OsmUtils.createPrimitive("node");
     120        final Way w = new Way();
     121        Stream.of(n1, n2, n3).map(Node.class::cast).forEach(w::addNode);
     122        return ReverseWayTagCorrector.getTagCorrectionsMap(w);
     123    }
     124
    120125    /**
    121126     * Test tag correction on way nodes
     
    123128    @Test
    124129    public void testSwitchingWayNodes() {
    125         final OsmPrimitive n1 = OsmUtils.createPrimitive("node");
    126         final OsmPrimitive n2 = OsmUtils.createPrimitive("node direction=SSW");
    127         final OsmPrimitive n3 = OsmUtils.createPrimitive("node");
    128         final Way w = new Way();
    129         Stream.of(n1, n2, n3).map(Node.class::cast).forEach(w::addNode);
    130         final Map<OsmPrimitive, List<TagCorrection>> tagCorrections = ReverseWayTagCorrector.getTagCorrectionsMap(w);
     130        final Map<OsmPrimitive, List<TagCorrection>> tagCorrections = getTagCorrectionsForWay("direction=forward");
    131131        Assert.assertEquals(1, tagCorrections.size());
    132         Assert.assertEquals(Collections.singleton(n2),
    133                 tagCorrections.keySet());
    134         Assert.assertEquals(Collections.singletonList(new TagCorrection("direction", "SSW", "direction", "NNE")),
     132        Assert.assertEquals(Collections.singletonList(new TagCorrection("direction", "forward", "direction", "backward")),
    135133                tagCorrections.values().iterator().next());
    136134    }
     135
     136    /**
     137     * Test tag correction on way nodes are not applied for absolute values such as compass cardinal directions
     138     */
     139    @Test
     140    public void testNotSwitchingWayNodes() {
     141        Assert.assertEquals(0, getTagCorrectionsForWay("direction=SSW").size());
     142        Assert.assertEquals(0, getTagCorrectionsForWay("direction=145").size());
     143    }
    137144}
Note: See TracChangeset for help on using the changeset viewer.