Changeset 15076 in josm


Ignore:
Timestamp:
2019-05-15T22:28:07+02:00 (5 months ago)
Author:
Don-vip
Message:

fix #17501 - Detect if a oneway in a relation may be going in the wrong direction (patch by taylor.smock)

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/data_nodist/relation_sort.osm

    r11887 r15076  
    11<?xml version='1.0' encoding='UTF-8'?>
    22<osm version='0.6' upload='never' generator='JOSM'>
    3   <node id='-136' action='modify' visible='true' lat='0.012919043857859922' lon='-0.02396592658039119'>
     3  <node id='-102392' action='modify' lat='0.01291904386' lon='-0.02396592658'>
    44    <tag k='leisure' v='playground' />
    55    <tag k='name' v='playground' />
    66  </node>
    7   <node id='-119' action='modify' visible='true' lat='0.013321070318548687' lon='-0.02263899788567645'>
     7  <node id='-102394' action='modify' lat='0.01332107032' lon='-0.02263899789'>
    88    <tag k='name' v='tree' />
    99    <tag k='natural' v='tree' />
    1010  </node>
    11   <node id='-62' action='modify' visible='true' lat='0.011392242679627185' lon='-0.02151079901779618' />
    12   <node id='-60' action='modify' visible='true' lat='0.010990181404602947' lon='-0.02221645759558677' />
    13   <node id='-58' action='modify' visible='true' lat='0.0121881598958588' lon='-0.02275800952737954' />
    14   <node id='-56' action='modify' visible='true' lat='0.011571901667096615' lon='-0.023094362404978128' />
    15   <node id='-54' action='modify' visible='true' lat='0.01196661592868377' lon='-0.023053401490175603' />
    16   <node id='-52' action='modify' visible='true' lat='0.011096850722520079' lon='-0.023143660145474393' />
    17   <node id='-50' action='modify' visible='true' lat='0.011113261386811617' lon='-0.023652390748067607' />
    18   <node id='-48' action='modify' visible='true' lat='0.011539938658067678' lon='-0.02462061995945469' />
    19   <node id='-46' action='modify' visible='true' lat='0.01539626034645824' lon='-0.023880241371069214' />
    20   <node id='-44' action='modify' visible='true' lat='0.015428020586761428' lon='-0.023340317266381447' />
    21   <node id='-42' action='modify' visible='true' lat='0.0154002303764964' lon='-0.02298301455004395' />
    22   <node id='-40' action='modify' visible='true' lat='0.015181878724288504' lon='-0.022316049479547295' />
    23   <node id='-38' action='modify' visible='true' lat='0.014911916681254264' lon='-0.022177098423193826' />
    24   <node id='-36' action='modify' visible='true' lat='0.014657834758095989' lon='-0.022161218302467714' />
    25   <node id='-34' action='modify' visible='true' lat='0.01427274184276135' lon='-0.02253440113953132' />
    26   <node id='-32' action='modify' visible='true' lat='0.013986899678383742' lon='-0.022423240294448546' />
    27   <node id='-30' action='modify' visible='true' lat='0.01389955901697638' lon='-0.022077847668655632' />
    28   <node id='-28' action='modify' visible='true' lat='0.014014689888824738' lon='-0.021819795706856333' />
    29   <node id='-26' action='modify' visible='true' lat='0.014252891692468746' lon='-0.021776125374859526' />
    30   <node id='-24' action='modify' visible='true' lat='0.014379932654311749' lon='-0.021569683805420084'>
     11  <node id='-102396' action='modify' lat='0.01139224268' lon='-0.02151079902' />
     12  <node id='-102398' action='modify' lat='0.0109901814' lon='-0.0222164576' />
     13  <node id='-102400' action='modify' lat='0.0121881599' lon='-0.02275800953' />
     14  <node id='-102402' action='modify' lat='0.01157190167' lon='-0.0230943624' />
     15  <node id='-102404' action='modify' lat='0.01196661593' lon='-0.02305340149' />
     16  <node id='-102406' action='modify' lat='0.01109685072' lon='-0.02314366015' />
     17  <node id='-102408' action='modify' lat='0.01111326139' lon='-0.02365239075' />
     18  <node id='-102410' action='modify' lat='0.01153993866' lon='-0.02462061996' />
     19  <node id='-102412' action='modify' lat='0.01539626035' lon='-0.02388024137' />
     20  <node id='-102414' action='modify' lat='0.01542802059' lon='-0.02334031727' />
     21  <node id='-102416' action='modify' lat='0.01540023038' lon='-0.02298301455' />
     22  <node id='-102418' action='modify' lat='0.01518187872' lon='-0.02231604948' />
     23  <node id='-102420' action='modify' lat='0.01491191668' lon='-0.02217709842' />
     24  <node id='-102422' action='modify' lat='0.01465783476' lon='-0.0221612183' />
     25  <node id='-102424' action='modify' lat='0.01427274184' lon='-0.02253440114' />
     26  <node id='-102426' action='modify' lat='0.01398689968' lon='-0.02242324029' />
     27  <node id='-102428' action='modify' lat='0.01389955902' lon='-0.02207784767' />
     28  <node id='-102430' action='modify' lat='0.01401468989' lon='-0.02181979571' />
     29  <node id='-102432' action='modify' lat='0.01425289169' lon='-0.02177612537' />
     30  <node id='-102434' action='modify' lat='0.01437993265' lon='-0.02156968381'>
    3131    <tag k='name' v='t1n1' />
    3232  </node>
    33   <node id='-22' action='modify' visible='true' lat='0.014268771812702965' lon='-0.021518073413060227' />
    34   <node id='-20' action='modify' visible='true' lat='0.014332292293628876' lon='-0.02137515232652523'>
     33  <node id='-102436' action='modify' lat='0.01426877181' lon='-0.02151807341' />
     34  <node id='-102438' action='modify' lat='0.01433229229' lon='-0.02137515233'>
    3535    <tag k='name' v='t1n2' />
    3636  </node>
    37   <node id='-18' action='modify' visible='true' lat='0.01342315540873657' lon='-0.024273274359040455' />
    38   <node id='-16' action='modify' visible='true' lat='0.01305394261171071' lon='-0.023320467115473805' />
    39   <node id='-14' action='modify' visible='true' lat='0.013204803754647857' lon='-0.021911106401031468' />
    40   <node id='-12' action='modify' visible='true' lat='0.01301027228084355' lon='-0.02147837311124495' />
    41   <node id='-10' action='modify' visible='true' lat='0.013173043514037084' lon='-0.023991402216151987'>
     37  <node id='-102440' action='modify' lat='0.01342315541' lon='-0.02427327436' />
     38  <node id='-102442' action='modify' lat='0.01305394261' lon='-0.02332046712' />
     39  <node id='-102444' action='modify' lat='0.01320480375' lon='-0.0219111064' />
     40  <node id='-102446' action='modify' lat='0.01301027228' lon='-0.02147837311' />
     41  <node id='-102448' action='modify' lat='0.01317304351' lon='-0.02399140222'>
    4242    <tag k='addr:housenumber' v='1' />
    4343    <tag k='name' v='t2n1' />
    4444  </node>
    45   <node id='-8' action='modify' visible='true' lat='0.013073792762102373' lon='-0.023697619982718937'>
     45  <node id='-102450' action='modify' lat='0.01307379276' lon='-0.02369761998'>
    4646    <tag k='addr:housenumber' v='2' />
    4747    <tag k='name' v='t2n2' />
    4848  </node>
    49   <node id='-6' action='modify' visible='true' lat='0.012930871679247545' lon='-0.023173575998757284'>
     49  <node id='-102452' action='modify' lat='0.01293087168' lon='-0.023173576'>
    5050    <tag k='addr:housenumber' v='3' />
    5151    <tag k='name' v='t2n3' />
    5252  </node>
    53   <node id='-4' action='modify' visible='true' lat='0.013038062491396258' lon='-0.022228708815553687'>
     53  <node id='-102454' action='modify' lat='0.01303806249' lon='-0.02222870882'>
    5454    <tag k='addr:housenumber' v='4' />
    5555    <tag k='name' v='t2n4' />
    5656  </node>
    57   <way id='-94' action='modify' visible='true'>
    58     <nd ref='-52' />
    59     <nd ref='-56' />
     57  <node id='-102479' action='modify' lat='0.01033835868' lon='-0.02471605239' />
     58  <node id='-102480' action='modify' lat='0.0103474155' lon='-0.02419528553' />
     59  <node id='-102482' action='modify' lat='0.01009382468' lon='-0.0240503765' />
     60  <node id='-102484' action='modify' lat='0.01007118265' lon='-0.02420887076' />
     61  <node id='-102486' action='modify' lat='0.00997608609' lon='-0.02410018898' />
     62  <node id='-102488' action='modify' lat='0.01002137016' lon='-0.02383301294' />
     63  <node id='-102490' action='modify' lat='0.01036552913' lon='-0.02307676889' />
     64  <node id='-102492' action='modify' lat='0.01029760301' lon='-0.02173183188' />
     65  <way id='-102455' action='modify'>
     66    <nd ref='-102406' />
     67    <nd ref='-102402' />
    6068    <tag k='name' v='t3w2' />
    6169  </way>
    62   <way id='-92' action='modify' visible='true'>
    63     <nd ref='-60' />
    64     <nd ref='-62' />
     70  <way id='-102456' action='modify'>
     71    <nd ref='-102398' />
     72    <nd ref='-102396' />
    6573    <tag k='name' v='t3w7' />
    6674  </way>
    67   <way id='-90' action='modify' visible='true'>
    68     <nd ref='-54' />
    69     <nd ref='-58' />
     75  <way id='-102457' action='modify'>
     76    <nd ref='-102404' />
     77    <nd ref='-102400' />
    7078    <tag k='name' v='t3w4' />
    7179  </way>
    72   <way id='-88' action='modify' visible='true'>
    73     <nd ref='-56' />
    74     <nd ref='-54' />
     80  <way id='-102458' action='modify'>
     81    <nd ref='-102402' />
     82    <nd ref='-102404' />
    7583    <tag k='name' v='t3w3' />
    7684  </way>
    77   <way id='-86' action='modify' visible='true'>
    78     <nd ref='-52' />
    79     <nd ref='-60' />
     85  <way id='-102459' action='modify'>
     86    <nd ref='-102406' />
     87    <nd ref='-102398' />
    8088    <tag k='name' v='t3w6' />
    8189  </way>
    82   <way id='-84' action='modify' visible='true'>
    83     <nd ref='-48' />
    84     <nd ref='-50' />
    85     <nd ref='-52' />
     90  <way id='-102460' action='modify'>
     91    <nd ref='-102410' />
     92    <nd ref='-102408' />
     93    <nd ref='-102406' />
    8694    <tag k='name' v='t3w1' />
    8795  </way>
    88   <way id='-82' action='modify' visible='true'>
    89     <nd ref='-46' />
    90     <nd ref='-44' />
     96  <way id='-102461' action='modify'>
     97    <nd ref='-102412' />
     98    <nd ref='-102414' />
    9199    <tag k='name' v='t1w1' />
    92100  </way>
    93   <way id='-80' action='modify' visible='true'>
    94     <nd ref='-36' />
    95     <nd ref='-34' />
     101  <way id='-102462' action='modify'>
     102    <nd ref='-102422' />
     103    <nd ref='-102424' />
    96104    <tag k='name' v='t1w5' />
    97105  </way>
    98   <way id='-78' action='modify' visible='true'>
    99     <nd ref='-32' />
    100     <nd ref='-30' />
    101     <nd ref='-28' />
     106  <way id='-102463' action='modify'>
     107    <nd ref='-102426' />
     108    <nd ref='-102428' />
     109    <nd ref='-102430' />
    102110    <tag k='name' v='t1w6' />
    103111  </way>
    104   <way id='-76' action='modify' visible='true'>
    105     <nd ref='-44' />
    106     <nd ref='-42' />
     112  <way id='-102464' action='modify'>
     113    <nd ref='-102414' />
     114    <nd ref='-102416' />
    107115    <tag k='name' v='t1w2' />
    108116  </way>
    109   <way id='-74' action='modify' visible='true'>
    110     <nd ref='-42' />
    111     <nd ref='-40' />
     117  <way id='-102465' action='modify'>
     118    <nd ref='-102416' />
     119    <nd ref='-102418' />
    112120    <tag k='name' v='t1w3' />
    113121  </way>
    114   <way id='-72' action='modify' visible='true'>
    115     <nd ref='-40' />
    116     <nd ref='-38' />
     122  <way id='-102466' action='modify'>
     123    <nd ref='-102418' />
     124    <nd ref='-102420' />
    117125    <tag k='name' v='t1w4' />
    118126  </way>
    119   <way id='-70' action='modify' visible='true'>
    120     <nd ref='-28' />
    121     <nd ref='-26' />
    122     <nd ref='-22' />
     127  <way id='-102467' action='modify'>
     128    <nd ref='-102430' />
     129    <nd ref='-102432' />
     130    <nd ref='-102436' />
    123131    <tag k='name' v='t1w7' />
    124132  </way>
    125   <way id='-68' action='modify' visible='true'>
    126     <nd ref='-18' />
    127     <nd ref='-16' />
     133  <way id='-102468' action='modify'>
     134    <nd ref='-102440' />
     135    <nd ref='-102442' />
    128136    <tag k='name' v='t2w1' />
    129137  </way>
    130   <way id='-66' action='modify' visible='true'>
    131     <nd ref='-16' />
    132     <nd ref='-14' />
    133     <nd ref='-12' />
     138  <way id='-102469' action='modify'>
     139    <nd ref='-102442' />
     140    <nd ref='-102444' />
     141    <nd ref='-102446' />
    134142    <tag k='name' v='t2w2' />
    135143  </way>
    136   <way id='-64' action='modify' visible='true'>
    137     <nd ref='-58' />
    138     <nd ref='-52' />
     144  <way id='-102470' action='modify'>
     145    <nd ref='-102400' />
     146    <nd ref='-102406' />
    139147    <tag k='name' v='t3w5' />
    140148  </way>
    141   <relation id='-123' action='modify' visible='true'>
    142     <member type='node' ref='-136' role='' />
    143     <member type='way' ref='-68' role='street' />
    144     <member type='node' ref='-10' role='house' />
    145     <member type='node' ref='-8' role='house' />
    146     <member type='node' ref='-6' role='house' />
    147     <member type='way' ref='-66' role='street' />
    148     <member type='node' ref='-119' role='tree' />
    149     <member type='node' ref='-4' role='house' />
     149  <way id='-102481' action='modify'>
     150    <nd ref='-102479' />
     151    <nd ref='-102480' />
     152    <tag k='name' v='t4w1' />
     153    <tag k='oneway' v='yes' />
     154  </way>
     155  <way id='-102499' action='modify'>
     156    <nd ref='-102480' />
     157    <nd ref='-102482' />
     158    <tag k='name' v='t4w2' />
     159    <tag k='oneway' v='yes' />
     160  </way>
     161  <way id='-102500' action='modify'>
     162    <nd ref='-102482' />
     163    <nd ref='-102484' />
     164    <tag k='name' v='t4w3' />
     165    <tag k='oneway' v='yes' />
     166  </way>
     167  <way id='-102501' action='modify'>
     168    <nd ref='-102484' />
     169    <nd ref='-102486' />
     170    <tag k='name' v='t4w4' />
     171    <tag k='oneway' v='yes' />
     172  </way>
     173  <way id='-102502' action='modify'>
     174    <nd ref='-102486' />
     175    <nd ref='-102488' />
     176    <tag k='name' v='t4w5' />
     177    <tag k='oneway' v='yes' />
     178  </way>
     179  <way id='-102503' action='modify'>
     180    <nd ref='-102490' />
     181    <nd ref='-102488' />
     182    <tag k='name' v='t4w6' />
     183    <tag k='oneway' v='yes' />
     184  </way>
     185  <way id='-102504' action='modify'>
     186    <nd ref='-102490' />
     187    <nd ref='-102492' />
     188    <tag k='name' v='t4w7' />
     189    <tag k='oneway' v='yes' />
     190  </way>
     191  <relation id='-102471' action='modify'>
     192    <member type='node' ref='-102392' role='' />
     193    <member type='way' ref='-102468' role='street' />
     194    <member type='node' ref='-102448' role='house' />
     195    <member type='node' ref='-102450' role='house' />
     196    <member type='node' ref='-102452' role='house' />
     197    <member type='way' ref='-102469' role='street' />
     198    <member type='node' ref='-102394' role='tree' />
     199    <member type='node' ref='-102454' role='house' />
    150200    <tag k='test' v='street' />
    151201    <tag k='type' v='street' />
    152202  </relation>
    153   <relation id='-100' action='modify' visible='true'>
    154     <member type='way' ref='-64' role='forward' />
    155     <member type='way' ref='-94' role='forward' />
    156     <member type='way' ref='-92' role='' />
    157     <member type='way' ref='-90' role='forward' />
    158     <member type='way' ref='-86' role='' />
    159     <member type='way' ref='-88' role='forward' />
    160     <member type='way' ref='-84' role='' />
     203  <relation id='-102472' action='modify'>
     204    <member type='way' ref='-102470' role='forward' />
     205    <member type='way' ref='-102455' role='forward' />
     206    <member type='way' ref='-102456' role='' />
     207    <member type='way' ref='-102457' role='forward' />
     208    <member type='way' ref='-102459' role='' />
     209    <member type='way' ref='-102458' role='forward' />
     210    <member type='way' ref='-102460' role='' />
    161211    <tag k='test' v='loop' />
    162212  </relation>
    163   <relation id='-98' action='modify' visible='true'>
    164     <member type='way' ref='-74' role='' />
    165     <member type='way' ref='-70' role='' />
    166     <member type='way' ref='-82' role='' />
    167     <member type='way' ref='-76' role='' />
    168     <member type='way' ref='-72' role='' />
    169     <member type='way' ref='-80' role='' />
    170     <member type='way' ref='-78' role='' />
    171     <member type='node' ref='-24' role='' />
    172     <member type='node' ref='-20' role='' />
     213  <relation id='-102473' action='modify'>
     214    <member type='way' ref='-102465' role='' />
     215    <member type='way' ref='-102467' role='' />
     216    <member type='way' ref='-102461' role='' />
     217    <member type='way' ref='-102464' role='' />
     218    <member type='way' ref='-102466' role='' />
     219    <member type='way' ref='-102462' role='' />
     220    <member type='way' ref='-102463' role='' />
     221    <member type='node' ref='-102434' role='' />
     222    <member type='node' ref='-102438' role='' />
    173223    <tag k='test' v='generic' />
    174224  </relation>
    175   <relation id='-96' action='modify' visible='true'>
    176     <member type='way' ref='-68' role='street' />
    177     <member type='node' ref='-10' role='house' />
    178     <member type='node' ref='-8' role='house' />
    179     <member type='node' ref='-6' role='house' />
    180     <member type='way' ref='-66' role='street' />
    181     <member type='node' ref='-4' role='house' />
     225  <relation id='-102474' action='modify'>
     226    <member type='way' ref='-102468' role='street' />
     227    <member type='node' ref='-102448' role='house' />
     228    <member type='node' ref='-102450' role='house' />
     229    <member type='node' ref='-102452' role='house' />
     230    <member type='way' ref='-102469' role='street' />
     231    <member type='node' ref='-102454' role='house' />
    182232    <tag k='test' v='associatedStreet' />
    183233    <tag k='type' v='associatedStreet' />
    184234  </relation>
     235  <relation id='-102497' action='modify'>
     236    <member type='way' ref='-102481' role='' />
     237    <member type='way' ref='-102499' role='' />
     238    <member type='way' ref='-102500' role='' />
     239    <member type='way' ref='-102501' role='' />
     240    <member type='way' ref='-102502' role='' />
     241    <member type='way' ref='-102503' role='' />
     242    <member type='way' ref='-102504' role='' />
     243    <tag k='test' v='direction' />
     244  </relation>
    185245</osm>
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/MemberTableLinkedCellRenderer.java

    r12657 r15076  
    6767
    6868        if (value.linkPrev) {
    69             g.setColor(Color.black);
     69            if (value.onewayFollowsPrevious) {
     70                g.setColor(Color.black);
     71            } else {
     72                g.setColor(Color.lightGray);
     73            }
    7074            if (value.isOnewayHead) {
    7175                g.fillRect(xoff - 1, 0, 3, 1);
     
    9397
    9498        if (value.linkNext) {
    95             g.setColor(Color.black);
     99            if (value.onewayFollowsNext) {
     100                g.setColor(Color.black);
     101            } else {
     102                g.setColor(Color.lightGray);
     103            }
    96104            if (value.isOnewayTail) {
    97105                g.fillRect(xoff - 1, ymax, 3, 1);
     
    120128
    121129        /* vertical lines */
    122         g.setColor(Color.black);
     130        if (value.onewayFollowsNext && value.onewayFollowsPrevious) {
     131            g.setColor(Color.black);
     132        } else {
     133            g.setColor(Color.lightGray);
     134        }
    123135        if (value.isLoop) {
    124136            g.drawLine(xoff+xloop, y1, xoff+xloop, y2);
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionType.java

    r14030 r15076  
    2222     * and / or the last node of this way is connected to the next way.
    2323     * direction is BACKWARD if it is the other way around.
     24     * direction has a ONEWAY value, if it is tagged as such and it is connected
     25     * to the previous / next member.
     26     * ONEWAY_FORWARD == the first node of the oneway is the last node of the previous way
     27     * ONEWAY_BACKWARD == the last node of the oneway is the last node of the previous way
    2428     * direction has a ROUNDABOUT value, if it is tagged as such and it is somehow
    2529     * connected to the previous / next member.
     
    4448    public boolean isOnewayHead;
    4549    public boolean isOnewayTail;
     50
     51    /** False, if the way is oneway and it doesn't follow the flow of the previous member */
     52    public boolean onewayFollowsPrevious = true;
     53    /** True, if the way is oneway and it doesn't follow the flow of the next member */
     54    public boolean onewayFollowsNext = true;
    4655
    4756    public WayConnectionType(boolean linkPrev, boolean linkNext, Direction direction) {
     
    8392     */
    8493    public String getTooltip() {
     94        boolean onewayGood = onewayFollowsPrevious && onewayFollowsNext;
    8595        if (!isValid())
    8696            return "";
    87         else if (linkPrev && linkNext)
     97        else if (linkPrev && linkNext && onewayGood)
    8898            return tr("way is connected");
    89         else if (linkPrev)
     99        else if (linkPrev && linkNext && !onewayGood)
     100            return tr("way is connected but has a wrong oneway direction");
     101        else if (linkPrev && onewayGood)
    90102            return tr("way is connected to previous relation member");
    91         else if (linkNext)
     103        else if (linkPrev && !onewayGood)
     104            return tr("way is connected to previous relation member but has a wrong oneway direction");
     105        else if (linkNext && onewayGood)
    92106            return tr("way is connected to next relation member");
     107        else if (linkNext && !onewayGood)
     108            return tr("way is connected to next relation member but has a wrong oneway direction");
    93109        else
    94110            return tr("way is not connected to previous or next relation member");
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java

    r14473 r15076  
    119119        if (lastWct != null) {
    120120            lastWct.linkNext = wct.linkPrev;
     121        }
     122
     123        if (lastWct != null && i > 0 && m.getMember() instanceof Way && members.get(i - 1).getMember() instanceof Way
     124                && (m.getWay().isOneway() != 0 || members.get(i - 1).getWay().isOneway() != 0)) {
     125            Way way = m.getWay();
     126            Way previousWay = members.get(i - 1).getWay();
     127            if (way.isOneway() != 0 && previousWay.isOneway() != 0 &&
     128                    (way.firstNode(true) != previousWay.lastNode(true) &&
     129                        way.lastNode(true) != previousWay.firstNode(true))) {
     130                wct.onewayFollowsPrevious = false;
     131                lastWct.onewayFollowsNext = false;
     132            } else if (way.isOneway() != 0 && previousWay.isOneway() == 0 &&
     133                    previousWay.isFirstLastNode(way.lastNode(true))) {
     134                wct.onewayFollowsPrevious = false;
     135            }
    121136        }
    122137        con.set(i, wct);
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java

    r15034 r15076  
    88import java.util.ArrayList;
    99import java.util.Arrays;
     10import java.util.Collections;
     11import java.util.HashSet;
    1012import java.util.List;
    1113
     
    1517import org.junit.Test;
    1618import org.openstreetmap.josm.data.osm.DataSet;
     19import org.openstreetmap.josm.data.osm.Node;
     20import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1721import org.openstreetmap.josm.data.osm.Relation;
     22import org.openstreetmap.josm.data.osm.Way;
    1823import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1924import org.openstreetmap.josm.io.IllegalDataException;
     
    131136        Assert.assertEquals("[BACKWARD, BACKWARD, BACKWARD, FPH FORWARD, FPH FORWARD, FPH FORWARD, FPH FORWARD]", actual);
    132137    }
     138
     139    private void reverseWay(Way way) {
     140        List<Node> nodes = way.getNodes();
     141        Collections.reverse(nodes);
     142        way.removeNodes(new HashSet<>(nodes));
     143        for (Node node : nodes) {
     144            way.addNode(node);
     145        }
     146    }
     147
     148    /**
     149     * Test directional {@link WayConnectionTypeCalculator#computeNextWayConnection}
     150     */
     151    @Test
     152    public void testDirectionsOnewaysOnly() {
     153        Relation relation = getRelation("direction");
     154
     155        // Check with only one wrong oneway
     156        List<WayConnectionType> returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers());
     157        for (int i = 0; i < 4; i++) {
     158            Assert.assertTrue(returned.get(i).onewayFollowsPrevious);
     159            Assert.assertTrue(returned.get(i).onewayFollowsNext);
     160        }
     161
     162        Assert.assertTrue(returned.get(4).onewayFollowsPrevious);
     163        Assert.assertFalse(returned.get(4).onewayFollowsNext);
     164
     165        Assert.assertFalse(returned.get(5).onewayFollowsPrevious);
     166        Assert.assertFalse(returned.get(5).onewayFollowsNext);
     167
     168        Assert.assertFalse(returned.get(6).onewayFollowsPrevious);
     169        Assert.assertTrue(returned.get(6).onewayFollowsNext);
     170
     171        // Reverse the last oneway
     172        OsmPrimitive way7 = relation.getMemberPrimitivesList().get(6);
     173        if (way7 instanceof Way) {
     174            Way way = (Way) way7;
     175            reverseWay(way);
     176            returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers());
     177            for (int i = 0; i < 4; i++) {
     178                Assert.assertTrue(returned.get(i).onewayFollowsPrevious);
     179                Assert.assertTrue(returned.get(i).onewayFollowsNext);
     180            }
     181
     182            Assert.assertTrue(returned.get(4).onewayFollowsPrevious);
     183            Assert.assertFalse(returned.get(4).onewayFollowsNext);
     184
     185            Assert.assertFalse(returned.get(5).onewayFollowsPrevious);
     186            Assert.assertTrue(returned.get(5).onewayFollowsNext);
     187
     188            Assert.assertTrue(returned.get(6).onewayFollowsPrevious);
     189            Assert.assertTrue(returned.get(6).onewayFollowsNext);
     190            reverseWay(way);
     191        }
     192
     193        // Reverse the wrong oneway
     194        OsmPrimitive way6 = relation.getMemberPrimitivesList().get(5);
     195        if (way6 instanceof Way) {
     196            Way way = (Way) way6;
     197            reverseWay(way);
     198            returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers());
     199            for (int i = 0; i < 7; i++) {
     200                Assert.assertTrue(returned.get(i).onewayFollowsPrevious);
     201                Assert.assertTrue(returned.get(i).onewayFollowsNext);
     202            }
     203        }
     204
     205        // Reverse everything
     206        for (Way way : relation.getMemberPrimitives(Way.class)) {
     207            reverseWay(way);
     208        }
     209        returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers());
     210        for (int i = 0; i < 7; i++) {
     211            Assert.assertTrue(returned.get(i).onewayFollowsPrevious);
     212            Assert.assertTrue(returned.get(i).onewayFollowsNext);
     213        }
     214    }
     215
     216    /**
     217     * Test directional {@link WayConnectionTypeCalculator#computeNextWayConnection}
     218     */
     219    @Test
     220    public void testDirectionsOnewayMix() {
     221        Relation relation = getRelation("direction");
     222
     223        // Remove the oneway in the wrong direction
     224        OsmPrimitive osm = relation.getMemberPrimitivesList().get(5);
     225        osm.remove("oneway");
     226        List<WayConnectionType> returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers());
     227        for (WayConnectionType type : returned) {
     228            Assert.assertTrue(type.onewayFollowsNext);
     229            Assert.assertTrue(type.onewayFollowsPrevious);
     230        }
     231
     232        // Check with a oneway=-1 tag without reversing the way
     233        osm.put("oneway", "-1");
     234        returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers());
     235        for (WayConnectionType type : returned) {
     236            Assert.assertTrue(type.onewayFollowsNext);
     237            Assert.assertTrue(type.onewayFollowsPrevious);
     238        }
     239
     240        // Check with oneways that converge onto a two-way
     241        // TODO figure out a way to find this situation?
     242        osm.remove("oneway");
     243        OsmPrimitive way7 = relation.getMemberPrimitivesList().get(6);
     244        way7.put("oneway", "-1");
     245        returned = wayConnectionTypeCalculator.updateLinks(relation.getMembers());
     246        for (int i = 0; i < returned.size() - 1; i++) {
     247            WayConnectionType type = returned.get(i);
     248            Assert.assertTrue(type.onewayFollowsNext);
     249            Assert.assertTrue(type.onewayFollowsPrevious);
     250        }
     251        Assert.assertTrue(returned.get(6).onewayFollowsNext);
     252        Assert.assertFalse(returned.get(6).onewayFollowsPrevious);
     253    }
    133254}
Note: See TracChangeset for help on using the changeset viewer.