Changeset 16886 in josm


Ignore:
Timestamp:
2020-08-12T22:17:36+02:00 (9 months ago)
Author:
simon04
Message:

fix #19633 - Route relations with split start do not show links as expected in the relation editor (patch by matthijskooijman)

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/nodist/data/relation_sort.osm

    r15076 r16886  
    6363  <node id='-102490' action='modify' lat='0.01036552913' lon='-0.02307676889' />
    6464  <node id='-102492' action='modify' lat='0.01029760301' lon='-0.02173183188' />
     65  <node id='-103305' action='modify' lat='0.00917928039' lon='-0.02535833538' />
     66  <node id='-103306' action='modify' lat='0.00919265151' lon='-0.02491040287' />
     67  <node id='-103307' action='modify' lat='0.00941996054' lon='-0.02466303715' />
     68  <node id='-103308' action='modify' lat='0.00943333166' lon='-0.0242886458' />
     69  <node id='-103309' action='modify' lat='0.00918596595' lon='-0.02404796564' />
     70  <node id='-103310' action='modify' lat='0.00920602263' lon='-0.02374042989' />
     71  <node id='-103311' action='modify' lat='0.0094266461' lon='-0.02356660533' />
     72  <node id='-103312' action='modify' lat='0.00944001722' lon='-0.02323232734' />
     73  <node id='-103313' action='modify' lat='0.00923945043' lon='-0.02305181722' />
     74  <node id='-103314' action='modify' lat='0.00943333166' lon='-0.02283119374' />
     75  <node id='-103315' action='modify' lat='0.0094266461' lon='-0.02251697243' />
     76  <node id='-103316' action='modify' lat='0.00924613599' lon='-0.02232309119' />
     77  <node id='-103317' action='modify' lat='0.00925950711' lon='-0.02201555543' />
     78  <node id='-103318' action='modify' lat='0.00909236811' lon='-0.02257045691' />
     79  <node id='-103319' action='modify' lat='0.00911242479' lon='-0.02281782262' />
     80  <node id='-103320' action='modify' lat='0.00903219807' lon='-0.0232724407' />
     81  <node id='-103321' action='modify' lat='0.00903888363' lon='-0.02356660533' />
     82  <node id='-103322' action='modify' lat='0.00898539915' lon='-0.02424853244' />
     83  <node id='-103323' action='modify' lat='0.00899877027' lon='-0.02461623823' />
     84  <node id='-103324' action='modify' lat='0.00851740997' lon='-0.02201555543' />
     85  <node id='-103325' action='modify' lat='0.00847729661' lon='-0.0254051343' />
     86  <node id='-103326' action='modify' lat='0.00796919406' lon='-0.02515776859' />
     87  <node id='-103327' action='modify' lat='0.0079959363' lon='-0.02430870248' />
     88  <node id='-103328' action='modify' lat='0.00801599298' lon='-0.02347300749' />
     89  <node id='-103329' action='modify' lat='0.0080293641' lon='-0.02221612223' />
     90  <node id='-103330' action='modify' lat='0.00765497275' lon='-0.02223617891' />
     91  <node id='-103331' action='modify' lat='0.00766165831' lon='-0.02343289413' />
     92  <node id='-103332' action='modify' lat='0.00765497275' lon='-0.02426190356' />
     93  <node id='-103333' action='modify' lat='0.00766165831' lon='-0.02509091299' />
    6594  <way id='-102455' action='modify'>
    6695    <nd ref='-102406' />
     
    188217    <tag k='name' v='t4w7' />
    189218    <tag k='oneway' v='yes' />
     219  </way>
     220  <way id='-103860' action='modify'>
     221    <nd ref='-103306' />
     222    <nd ref='-103307' />
     223    <tag k='name' v='t5w2a' />
     224  </way>
     225  <way id='-103861' action='modify'>
     226    <nd ref='-103316' />
     227    <nd ref='-103318' />
     228    <tag k='name' v='t5w11b' />
     229  </way>
     230  <way id='-103862' action='modify'>
     231    <nd ref='-103309' />
     232    <nd ref='-103322' />
     233    <tag k='name' v='t5w4b' />
     234  </way>
     235  <way id='-103863' action='modify'>
     236    <nd ref='-103313' />
     237    <nd ref='-103320' />
     238    <tag k='name' v='t5w8b' />
     239  </way>
     240  <way id='-103864' action='modify'>
     241    <nd ref='-103305' />
     242    <nd ref='-103306' />
     243    <tag k='name' v='t5w1' />
     244  </way>
     245  <way id='-103865' action='modify'>
     246    <nd ref='-103309' />
     247    <nd ref='-103310' />
     248    <tag k='name' v='t5w5' />
     249  </way>
     250  <way id='-103866' action='modify'>
     251    <nd ref='-103311' />
     252    <nd ref='-103312' />
     253    <tag k='name' v='t5w7a' />
     254  </way>
     255  <way id='-103867' action='modify'>
     256    <nd ref='-103314' />
     257    <nd ref='-103315' />
     258    <tag k='name' v='t5w10a' />
     259  </way>
     260  <way id='-103868' action='modify'>
     261    <nd ref='-103317' />
     262    <nd ref='-103324' />
     263    <nd ref='-103325' />
     264    <nd ref='-103305' />
     265    <tag k='name' v='t5w13' />
     266  </way>
     267  <way id='-103869' action='modify'>
     268    <nd ref='-103308' />
     269    <nd ref='-103309' />
     270    <tag k='name' v='t5w4a' />
     271  </way>
     272  <way id='-103870' action='modify'>
     273    <nd ref='-103307' />
     274    <nd ref='-103308' />
     275    <tag k='name' v='t5w3a' />
     276  </way>
     277  <way id='-103871' action='modify'>
     278    <nd ref='-103323' />
     279    <nd ref='-103306' />
     280    <tag k='name' v='t5w2b' />
     281  </way>
     282  <way id='-103872' action='modify'>
     283    <nd ref='-103322' />
     284    <nd ref='-103323' />
     285    <tag k='name' v='t5w3b' />
     286  </way>
     287  <way id='-103873' action='modify'>
     288    <nd ref='-103321' />
     289    <nd ref='-103310' />
     290    <tag k='name' v='t5w6b' />
     291  </way>
     292  <way id='-103874' action='modify'>
     293    <nd ref='-103310' />
     294    <nd ref='-103311' />
     295    <tag k='name' v='t5w6a' />
     296  </way>
     297  <way id='-103875' action='modify'>
     298    <nd ref='-103312' />
     299    <nd ref='-103313' />
     300    <tag k='name' v='t5w8a' />
     301  </way>
     302  <way id='-103876' action='modify'>
     303    <nd ref='-103320' />
     304    <nd ref='-103321' />
     305    <tag k='name' v='t5w7b' />
     306  </way>
     307  <way id='-103877' action='modify'>
     308    <nd ref='-103319' />
     309    <nd ref='-103313' />
     310    <tag k='name' v='t5w9b' />
     311  </way>
     312  <way id='-103878' action='modify'>
     313    <nd ref='-103313' />
     314    <nd ref='-103314' />
     315    <tag k='name' v='t5w9a' />
     316  </way>
     317  <way id='-103879' action='modify'>
     318    <nd ref='-103315' />
     319    <nd ref='-103316' />
     320    <tag k='name' v='t5w11a' />
     321  </way>
     322  <way id='-103880' action='modify'>
     323    <nd ref='-103318' />
     324    <nd ref='-103319' />
     325    <tag k='name' v='t5w10b' />
     326  </way>
     327  <way id='-103881' action='modify'>
     328    <nd ref='-103316' />
     329    <nd ref='-103317' />
     330    <tag k='name' v='t5w12' />
     331  </way>
     332  <way id='-103882' action='modify'>
     333    <nd ref='-103326' />
     334    <nd ref='-103327' />
     335    <tag k='name' v='t6w1a' />
     336  </way>
     337  <way id='-103883' action='modify'>
     338    <nd ref='-103330' />
     339    <nd ref='-103331' />
     340    <tag k='name' v='t6w3b' />
     341  </way>
     342  <way id='-103884' action='modify'>
     343    <nd ref='-103327' />
     344    <nd ref='-103328' />
     345    <tag k='name' v='t6w2a' />
     346  </way>
     347  <way id='-103885' action='modify'>
     348    <nd ref='-103328' />
     349    <nd ref='-103329' />
     350    <tag k='name' v='t6w3a' />
     351  </way>
     352  <way id='-103886' action='modify'>
     353    <nd ref='-103331' />
     354    <nd ref='-103332' />
     355    <tag k='name' v='t6w2b' />
     356  </way>
     357  <way id='-103887' action='modify'>
     358    <nd ref='-103332' />
     359    <nd ref='-103333' />
     360    <tag k='name' v='t6w1b' />
    190361  </way>
    191362  <relation id='-102471' action='modify'>
     
    198369    <member type='node' ref='-102394' role='tree' />
    199370    <member type='node' ref='-102454' role='house' />
     371    <tag k='name' v='street' />
    200372    <tag k='test' v='street' />
    201373    <tag k='type' v='street' />
     
    209381    <member type='way' ref='-102458' role='forward' />
    210382    <member type='way' ref='-102460' role='' />
     383    <tag k='name' v='loop' />
    211384    <tag k='test' v='loop' />
    212385  </relation>
     
    221394    <member type='node' ref='-102434' role='' />
    222395    <member type='node' ref='-102438' role='' />
     396    <tag k='name' v='generic' />
    223397    <tag k='test' v='generic' />
    224398  </relation>
     
    230404    <member type='way' ref='-102469' role='street' />
    231405    <member type='node' ref='-102454' role='house' />
     406    <tag k='name' v='associatedStreet' />
    232407    <tag k='test' v='associatedStreet' />
    233408    <tag k='type' v='associatedStreet' />
     
    241416    <member type='way' ref='-102503' role='' />
    242417    <member type='way' ref='-102504' role='' />
     418    <tag k='name' v='direction' />
    243419    <tag k='test' v='direction' />
    244420  </relation>
     421  <relation id='-102591' action='modify'>
     422    <member type='way' ref='-103864' role='' />
     423    <member type='way' ref='-103881' role='' />
     424    <member type='way' ref='-103874' role='forward' />
     425    <member type='way' ref='-103870' role='forward' />
     426    <member type='way' ref='-103875' role='forward' />
     427    <member type='way' ref='-103867' role='forward' />
     428    <member type='way' ref='-103873' role='forward' />
     429    <member type='way' ref='-103878' role='forward' />
     430    <member type='way' ref='-103871' role='forward' />
     431    <member type='way' ref='-103879' role='forward' />
     432    <member type='way' ref='-103860' role='forward' />
     433    <member type='way' ref='-103880' role='forward' />
     434    <member type='way' ref='-103865' role='' />
     435    <member type='way' ref='-103866' role='forward' />
     436    <member type='way' ref='-103876' role='forward' />
     437    <member type='way' ref='-103862' role='forward' />
     438    <member type='way' ref='-103861' role='forward' />
     439    <member type='way' ref='-103872' role='forward' />
     440    <member type='way' ref='-103869' role='forward' />
     441    <member type='way' ref='-103877' role='forward' />
     442    <member type='way' ref='-103863' role='forward' />
     443    <tag k='name' v='three-loops-ends-way' />
     444    <tag k='test' v='three-loops-ends-way' />
     445  </relation>
     446  <relation id='-102592' action='modify'>
     447    <member type='way' ref='-103874' role='forward' />
     448    <member type='way' ref='-103861' role='forward' />
     449    <member type='way' ref='-103866' role='forward' />
     450    <member type='way' ref='-103873' role='forward' />
     451    <member type='way' ref='-103880' role='forward' />
     452    <member type='way' ref='-103867' role='forward' />
     453    <member type='way' ref='-103872' role='forward' />
     454    <member type='way' ref='-103862' role='forward' />
     455    <member type='way' ref='-103865' role='' />
     456    <member type='way' ref='-103870' role='forward' />
     457    <member type='way' ref='-103876' role='forward' />
     458    <member type='way' ref='-103875' role='forward' />
     459    <member type='way' ref='-103877' role='forward' />
     460    <member type='way' ref='-103869' role='forward' />
     461    <member type='way' ref='-103860' role='forward' />
     462    <member type='way' ref='-103871' role='forward' />
     463    <member type='way' ref='-103863' role='forward' />
     464    <member type='way' ref='-103879' role='forward' />
     465    <member type='way' ref='-103878' role='forward' />
     466    <tag k='name' v='three-loops-ends-node' />
     467    <tag k='test' v='three-loops-ends-node' />
     468  </relation>
     469  <relation id='-102593' action='modify'>
     470    <member type='way' ref='-103865' role='' />
     471    <member type='way' ref='-103874' role='forward' />
     472    <member type='way' ref='-103872' role='forward' />
     473    <member type='way' ref='-103878' role='forward' />
     474    <member type='way' ref='-103880' role='forward' />
     475    <member type='way' ref='-103869' role='forward' />
     476    <member type='way' ref='-103863' role='forward' />
     477    <member type='way' ref='-103862' role='forward' />
     478    <member type='way' ref='-103876' role='forward' />
     479    <member type='way' ref='-103866' role='forward' />
     480    <member type='way' ref='-103873' role='forward' />
     481    <member type='way' ref='-103877' role='forward' />
     482    <member type='way' ref='-103875' role='forward' />
     483    <member type='way' ref='-103867' role='forward' />
     484    <member type='way' ref='-103870' role='forward' />
     485    <tag k='name' v='one-loop-ends-split' />
     486    <tag k='test' v='one-loop-ends-split' />
     487  </relation>
     488  <relation id='-102594' action='modify'>
     489    <member type='way' ref='-103866' role='forward' />
     490    <member type='way' ref='-103875' role='forward' />
     491    <member type='way' ref='-103876' role='forward' />
     492    <member type='way' ref='-103863' role='forward' />
     493    <member type='way' ref='-103878' role='forward' />
     494    <member type='way' ref='-103867' role='forward' />
     495    <member type='way' ref='-103877' role='forward' />
     496    <member type='way' ref='-103880' role='forward' />
     497    <tag k='name' v='no-loop-ends-split' />
     498    <tag k='test' v='no-loop-ends-split' />
     499  </relation>
     500  <relation id='-102595' action='modify'>
     501    <member type='way' ref='-103864' role='' />
     502    <member type='way' ref='-103876' role='forward' />
     503    <member type='way' ref='-103870' role='forward' />
     504    <member type='way' ref='-103873' role='forward' />
     505    <member type='way' ref='-103867' role='forward' />
     506    <member type='way' ref='-103869' role='forward' />
     507    <member type='way' ref='-103872' role='forward' />
     508    <member type='way' ref='-103874' role='forward' />
     509    <member type='way' ref='-103879' role='forward' />
     510    <member type='way' ref='-103877' role='forward' />
     511    <member type='way' ref='-103861' role='forward' />
     512    <member type='way' ref='-103865' role='' />
     513    <member type='way' ref='-103863' role='forward' />
     514    <member type='way' ref='-103868' role='' />
     515    <member type='way' ref='-103860' role='forward' />
     516    <member type='way' ref='-103871' role='forward' />
     517    <member type='way' ref='-103866' role='forward' />
     518    <member type='way' ref='-103875' role='forward' />
     519    <member type='way' ref='-103862' role='forward' />
     520    <member type='way' ref='-103881' role='' />
     521    <member type='way' ref='-103880' role='forward' />
     522    <member type='way' ref='-103878' role='forward' />
     523    <tag k='name' v='three-loops-ends-loop' />
     524    <tag k='test' v='three-loops-ends-loop' />
     525  </relation>
     526  <relation id='-102596' action='modify'>
     527    <member type='way' ref='-103882' role='forward' />
     528    <member type='way' ref='-103887' role='forward' />
     529    <member type='way' ref='-103886' role='forward' />
     530    <member type='way' ref='-103883' role='forward' />
     531    <member type='way' ref='-103885' role='forward' />
     532    <member type='way' ref='-103884' role='forward' />
     533    <tag k='name' v='parallel-oneway' />
     534    <tag k='test' v='parallel-oneway' />
     535  </relation>
     536  <relation id='-102605' action='modify'>
     537    <member type='way' ref='-103864' role='' />
     538    <member type='way' ref='-103874' role='forward' />
     539    <member type='way' ref='-103870' role='forward' />
     540    <member type='way' ref='-103875' role='forward' />
     541    <member type='way' ref='-103867' role='forward' />
     542    <member type='way' ref='-103873' role='forward' />
     543    <member type='way' ref='-103878' role='forward' />
     544    <member type='way' ref='-103871' role='forward' />
     545    <member type='way' ref='-103879' role='forward' />
     546    <member type='way' ref='-103860' role='forward' />
     547    <member type='way' ref='-103880' role='forward' />
     548    <member type='way' ref='-103865' role='' />
     549    <member type='way' ref='-103866' role='forward' />
     550    <member type='way' ref='-103876' role='forward' />
     551    <member type='way' ref='-103881' role='' />
     552    <member type='way' ref='-103861' role='forward' />
     553    <member type='way' ref='-103872' role='forward' />
     554    <member type='way' ref='-103869' role='forward' />
     555    <member type='way' ref='-103877' role='forward' />
     556    <tag k='name' v='incomplete-loops' />
     557    <tag k='test' v='incomplete-loops' />
     558  </relation>
    245559</osm>
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationNodeMap.java

    r16630 r16886  
    177177    private Integer popForwardOnewayPart(Integer way) {
    178178        if (onewayMap.ways.containsKey(way)) {
    179             for (Node n : onewayMap.ways.get(way)) {
    180                 Integer i = findAdjacentWay(onewayMap, n);
    181                 if (i == null) {
    182                     continue;
    183                 }
    184 
    185                 lastOnewayNode = processBackwardIfEndOfLoopReached(i);
    186                 if (lastOnewayNode != null)
    187                     return popBackwardOnewayPart(firstOneway);
    188 
    189                 deleteWayNode(onewayMap, i, n);
    190                 return i;
    191             }
     179            Node exitNode = onewayMap.ways.get(way).iterator().next();
     180
     181            if (checkIfEndOfLoopReached(exitNode)) {
     182                lastOnewayNode = exitNode;
     183                return popBackwardOnewayPart(firstOneway);
     184            }
     185
     186            Integer i = deleteAndGetAdjacentNode(onewayMap, exitNode);
     187            if (i != null) return i;
     188
     189            // When our forward route ends in a dead end try to start
     190            // the backward route anyway from the split point
     191            // (firstOneWay), to support routes with split a split start
     192            // or end.
     193            lastOnewayNode = exitNode;
     194            return popBackwardOnewayPart(firstOneway);
    192195        }
    193196
     
    196199    }
    197200
    198     private Node processBackwardIfEndOfLoopReached(Integer way) { //find if we didn't reach end of the loop (and process backward part)
    199         if (onewayReverseMap.ways.containsKey(way)) {
    200             for (Node n : onewayReverseMap.ways.get(way)) {
    201                 if (map.nodes.containsKey(n)
    202                         || (onewayMap.nodes.containsKey(n) && onewayMap.nodes.get(n).size() > 1))
    203                     return n;
    204                 if (firstCircular != null && firstCircular == n)
    205                     return firstCircular;
    206             }
    207         }
    208         return null;
     201    // Check if the given node can be the end of the loop (i.e. it has
     202    // an outgoing bidirectional or multiple outgoing oneways, or we
     203    // looped back to our first circular node)
     204    private boolean checkIfEndOfLoopReached(Node n) {
     205        if (map.nodes.containsKey(n)
     206                || (onewayMap.nodes.containsKey(n) && onewayMap.nodes.get(n).size() > 1))
     207            return true;
     208        if (firstCircular != null && firstCircular == n)
     209            return true;
     210        return false;
    209211    }
    210212
     
    267269        } else {
    268270            done(way);
    269         }
    270         nw.ways.get(way).remove(n);
     271            // For bidirectional ways, remove the entry node, so
     272            // subsequent lookups will only return the other node(s) as
     273            // valid exit nodes.
     274            nw.ways.get(way).remove(n);
     275        }
    271276    }
    272277
  • trunk/src/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculator.java

    r15747 r16886  
    146146
    147147        if (!wct.linkPrev) {
    148             wct.direction = determineDirectionOfFirst(i, m);
     148            wct.direction = determineDirectionOfFirst(i, m, false);
    149149            if (RelationSortUtils.isOneway(m)) {
    150150                wct.isOnewayLoopForwardPart = true;
     
    218218    }
    219219
    220     private Direction determineDirectionOfFirst(final int i, final RelationMember m) {
     220    private Direction determineDirectionOfFirst(final int i, final RelationMember m, boolean reversed) {
    221221        Direction result = RelationSortUtils.roundaboutType(m);
    222222        if (result != NONE)
     
    224224
    225225        if (RelationSortUtils.isOneway(m)) {
    226             if (RelationSortUtils.isBackward(m)) return BACKWARD;
     226            if (RelationSortUtils.isBackward(m) != reversed) return BACKWARD;
    227227            else return FORWARD;
    228228        } else { /** guess the direction and see if it fits with the next member */
     
    248248            }
    249249
     250            // Support split-start routes. When the current way does
     251            // not fit as forward or backward and we have no backward
     252            // ways yet (onewayBeginning) and the most recent oneway
     253            // head starts a new segment (!linkPrev), instead of
     254            // disconnecting the current way, make it the start of the
     255            // backward route. To render properly, unset isOnewayHead on
     256            // the most recent head (since the current backward way does
     257            // no longer start there).
     258            if (dirFW == NONE && dirBW == NONE && RelationSortUtils.isOneway(m) && !wct.isOnewayHead) {
     259                WayConnectionType prevHead = null;
     260                for (int j = i - 1; j >= 0; --j) {
     261                    if (con.get(j).isOnewayHead) {
     262                        prevHead = con.get(j);
     263                        break;
     264                    }
     265                }
     266
     267                if (prevHead != null && !prevHead.linkPrev) {
     268                    dirBW = determineDirectionOfFirst(i, m, true);
     269                    prevHead.isOnewayHead = false;
     270                }
     271            }
     272
    250273            if (dirBW != NONE) {
    251274                onewayBeginning = false;
     
    269292            if (dirFW == NONE && dirBW == NONE) {
    270293                wct.linkPrev = false;
    271                 if (RelationSortUtils.isOneway(m)) {
    272                     wct.isOnewayHead = true;
    273                     lastForwardWay = i-1;
    274                     lastBackwardWay = i-1;
    275                 } else {
    276                     lastForwardWay = UNCONNECTED;
    277                     lastBackwardWay = UNCONNECTED;
    278                 }
     294                wct.isOnewayHead = true;
     295                lastForwardWay = i-1;
     296                lastBackwardWay = i-1;
    279297                onewayBeginning = true;
    280298            }
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/RelationSorterTest.java

    r16438 r16886  
    5959    }
    6060
     61    // This cluster of tests checks whether these relations are sorted
     62    // as expected, so these relations are of course not sorted in the
     63    // data file.
     64
    6165    @Test
    6266    public void testGeneric() {
     
    7983        Assert.assertArrayEquals(new String[]{"t2w1", "t2w2", "t2n1", "t2n2", "t2n3", "t2n4", "playground", "tree"}, actual);
    8084    }
     85
     86    // The following cluster of tests does the same, but with various
     87    // configurations involving split / dual carriageway routes (i.e.
     88    // containing members with role=forward or role=backward). Again,
     89    // these are intentionally not already sorted.
     90
     91    @Test
     92    public void testThreeLoopsEndsLoop() {
     93        Relation relation = getRelation("three-loops-ends-loop");
     94        // Check the first way before sorting, otherwise the sorter
     95        // might pick a different loop starting point than expected below
     96        Assert.assertEquals("t5w1", relation.getMembers().get(0).getMember().get("name"));
     97
     98        String[] actual = getNames(sorter.sortMembers(relation.getMembers()));
     99        Assert.assertArrayEquals(new String[]{
     100            "t5w1", "t5w2a", "t5w3a", "t5w4a", "t5w2b", "t5w3b", "t5w4b",
     101            "t5w5", "t5w6a", "t5w7a", "t5w8a", "t5w6b", "t5w7b", "t5w8b",
     102            "t5w9a", "t5w10a", "t5w11a", "t5w9b", "t5w10b", "t5w11b",
     103            "t5w12", "t5w13",
     104        }, actual);
     105    }
     106
     107    @Test
     108    public void testThreeLoopsEndsWay() {
     109        Relation relation = getRelation("three-loops-ends-way");
     110        // Check the first way before sorting, otherwise the sorter
     111        // might sort in reverse compared to what is expected below
     112        Assert.assertEquals("t5w1", relation.getMembers().get(0).getMember().get("name"));
     113
     114        String[] actual = getNames(sorter.sortMembers(relation.getMembers()));
     115        Assert.assertArrayEquals(new String[]{
     116            "t5w1", "t5w2a", "t5w3a", "t5w4a", "t5w2b", "t5w3b", "t5w4b",
     117            "t5w5", "t5w6a", "t5w7a", "t5w8a", "t5w6b", "t5w7b", "t5w8b",
     118            "t5w9a", "t5w10a", "t5w11a", "t5w9b", "t5w10b", "t5w11b",
     119            "t5w12",
     120        }, actual);
     121    }
     122
     123    @Test
     124    public void testThreeLoopsEndsNode() {
     125        Relation relation = getRelation("three-loops-ends-node");
     126        String[] actual = getNames(sorter.sortMembers(relation.getMembers()));
     127        Assert.assertArrayEquals(new String[]{
     128            "t5w4a", "t5w3a", "t5w2a", "t5w2b", "t5w3b", "t5w4b",
     129            "t5w5", "t5w6a", "t5w7a", "t5w8a", "t5w6b", "t5w7b", "t5w8b",
     130            "t5w9a", "t5w10a", "t5w11a", "t5w11b", "t5w10b", "t5w9b",
     131        }, actual);
     132    }
     133
     134    @Test
     135    public void testOneLoopEndsSplit() {
     136        Relation relation = getRelation("one-loop-ends-split");
     137        String[] actual = getNames(sorter.sortMembers(relation.getMembers()));
     138        Assert.assertArrayEquals(new String[]{
     139            "t5w3a", "t5w4a", "t5w3b", "t5w4b",
     140            "t5w5", "t5w6a", "t5w7a", "t5w8a", "t5w6b", "t5w7b", "t5w8b",
     141            "t5w9a", "t5w10a", "t5w9b", "t5w10b",
     142        }, actual);
     143    }
     144
     145    @Test
     146    public void testNoLoopEndsSplit() {
     147        Relation relation = getRelation("no-loop-ends-split");
     148        // TODO: This is not yet sorted properly, so this route is
     149        // presorted in the data file, making this a bit of a dummy test
     150        // for now.
     151        String[] actual = getNames(relation.getMembers());
     152        Assert.assertArrayEquals(new String[]{
     153            "t5w7a", "t5w8a", "t5w7b", "t5w8b",
     154            "t5w9a", "t5w10a", "t5w9b", "t5w10b",
     155        }, actual);
     156    }
     157
     158    @Test
     159    public void testIncompleteLoops() {
     160        Relation relation = getRelation("incomplete-loops");
     161        // TODO: This is not yet sorted perfectly (might not be possible)
     162        String[] actual = getNames(sorter.sortMembers(relation.getMembers()));
     163        Assert.assertArrayEquals(new String[]{
     164            "t5w1", "t5w2a", "t5w3a", "t5w4a", "t5w2b", "t5w3b",
     165            "t5w5", "t5w6a", "t5w7a", "t5w8a", "t5w9a", "t5w10a", "t5w11a", "t5w6b", "t5w7b",
     166            "t5w12", "t5w11b", "t5w10b", "t5w9b",
     167        }, actual);
     168    }
     169
     170    @Test
     171    public void testParallelOneWay() {
     172        Relation relation = getRelation("parallel-oneway");
     173        // TODO: This is not always sorted properly, only when the right
     174        // way is already at the top, so check that
     175        Assert.assertEquals("t6w1a", relation.getMembers().get(0).getMember().get("name"));
     176
     177        String[] actual = getNames(sorter.sortMembers(relation.getMembers()));
     178        Assert.assertArrayEquals(new String[]{
     179            "t6w1a", "t6w2a", "t6w3a",
     180            "t6w1b", "t6w2b", "t6w3b",
     181        }, actual);
     182    }
    81183}
  • trunk/test/unit/org/openstreetmap/josm/gui/dialogs/relation/sort/WayConnectionTypeCalculatorTest.java

    r16438 r16886  
    105105    }
    106106
     107    // This cluster of tests checks the rendering before and after
     108    // sorting of a few relations. Initially, these relations are
     109    // intentionally not sorted to ensure the sorting has some work.
     110
    107111    @Test
    108112    public void testGeneric() {
     
    130134        //TODO Sorting doesn't work well in this case
    131135        actual = getConnections(wayConnectionTypeCalculator.updateLinks(sorter.sortMembers(relation.getMembers())));
    132         Assert.assertEquals("[BACKWARD, BACKWARD, BACKWARD, FPH FORWARD, FPH FORWARD, FPH FORWARD, FPH FORWARD]", actual);
     136        Assert.assertEquals("[BACKWARD, BACKWARD, BACKWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, BPT BACKWARD]", actual);
     137    }
     138
     139    // The following cluster of tests checks various configurations
     140    // involving split / dual carriageway routes (i.e. containing
     141    // members with role=forward or role=backward). Again, these are
     142    // intentionally not sorted.
     143
     144    @Test
     145    public void testThreeLoopsEndsLoop() {
     146        Relation relation = getRelation("three-loops-ends-loop");
     147        // Check the first way before sorting, otherwise the sorter
     148        // might pick a different loop starting point than expected below
     149        Assert.assertEquals("t5w1", relation.getMembers().get(0).getMember().get("name"));
     150        String actual = getConnections(wayConnectionTypeCalculator.updateLinks(sorter.sortMembers(relation.getMembers())));
     151        String expected = "[" +
     152            "L FORWARD, LFPH FORWARD, LFP FORWARD, LFP FORWARD, LBP BACKWARD, LBP BACKWARD, LBPT BACKWARD, " +
     153            "L FORWARD, LFPH FORWARD, LFP FORWARD, LFP FORWARD, LBP BACKWARD, LBP BACKWARD, LBPT BACKWARD, " +
     154            "LFPH FORWARD, LFP FORWARD, LFP FORWARD, LBP BACKWARD, LBP BACKWARD, LBPT BACKWARD, " +
     155            "L FORWARD, L FORWARD" +
     156        "]";
     157        Assert.assertEquals(expected, actual);
     158    }
     159
     160    @Test
     161    public void testThreeLoopsEndsWay() {
     162        Relation relation = getRelation("three-loops-ends-way");
     163        // Check the first way before sorting, otherwise the sorter
     164        // might sort in reverse compared to what is expected below
     165        Assert.assertEquals("t5w1", relation.getMembers().get(0).getMember().get("name"));
     166        String actual = getConnections(wayConnectionTypeCalculator.updateLinks(sorter.sortMembers(relation.getMembers())));
     167        String expected = "[" +
     168            "FORWARD, FPH FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, BPT BACKWARD, " +
     169            "FORWARD, FPH FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, BPT BACKWARD, " +
     170            "FPH FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, BPT BACKWARD, " +
     171            "FORWARD" +
     172        "]";
     173        Assert.assertEquals(expected, actual);
     174    }
     175
     176    @Test
     177    public void testThreeLoopsEndsNode() {
     178        Relation relation = getRelation("three-loops-ends-node");
     179        String actual = getConnections(wayConnectionTypeCalculator.updateLinks(sorter.sortMembers(relation.getMembers())));
     180        String expected = "[" +
     181            "FPH FORWARD, BP BACKWARD, BP BACKWARD, BP BACKWARD, BP BACKWARD, BPT BACKWARD, " +
     182            "FORWARD, FPH FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, BPT BACKWARD, " +
     183            "FPH FORWARD, FP FORWARD, FP FORWARD, FP FORWARD, FP FORWARD, BPT BACKWARD" +
     184        "]";
     185        Assert.assertEquals(expected, actual);
     186    }
     187
     188    @Test
     189    public void testOneLoopEndsSplit() {
     190        Relation relation = getRelation("one-loop-ends-split");
     191        String actual = getConnections(wayConnectionTypeCalculator.updateLinks(sorter.sortMembers(relation.getMembers())));
     192        String expected = "[" +
     193            "FP FORWARD, FP FORWARD, BP BACKWARD, BPT BACKWARD, " +
     194            "FORWARD, FPH FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, BPT BACKWARD, " +
     195            "FPH FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD" +
     196        "]";
     197        Assert.assertEquals(expected, actual);
     198    }
     199
     200    @Test
     201    public void testNoLoopEndsSplit() {
     202        Relation relation = getRelation("no-loop-ends-split");
     203        // TODO: This is not yet sorted properly, so this route is
     204        // presorted in the data file
     205        String actual = getConnections(wayConnectionTypeCalculator.updateLinks(relation.getMembers()));
     206        String expected = "[" +
     207            "FP FORWARD, FP FORWARD, BP BACKWARD, BPT BACKWARD, " +
     208            "FPH FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD" +
     209        "]";
     210        Assert.assertEquals(expected, actual);
     211    }
     212
     213    @Test
     214    public void testIncompleteLoops() {
     215        Relation relation = getRelation("incomplete-loops");
     216        // TODO: This is not yet sorted perfectly (might not be possible)
     217        String actual = getConnections(wayConnectionTypeCalculator.updateLinks(sorter.sortMembers(relation.getMembers())));
     218        String expected = "[" +
     219            "FORWARD, FPH FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, " +
     220            "FORWARD, FPH FORWARD, FP FORWARD, FP FORWARD, FP FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, " +
     221            "BACKWARD, FPH FORWARD, FP FORWARD, FP FORWARD" +
     222        "]";
     223        Assert.assertEquals(expected, actual);
     224    }
     225
     226    @Test
     227    public void testParallelOneWay() {
     228        Relation relation = getRelation("parallel-oneway");
     229        // TODO: This is not always sorted properly, only when the right
     230        // way is already at the top, so check that
     231        Assert.assertEquals("t6w1a", relation.getMembers().get(0).getMember().get("name"));
     232        String actual = getConnections(wayConnectionTypeCalculator.updateLinks(sorter.sortMembers(relation.getMembers())));
     233        String expected = "[" +
     234            "FP FORWARD, FP FORWARD, FP FORWARD, BP BACKWARD, BP BACKWARD, BP BACKWARD" +
     235        "]";
     236        Assert.assertEquals(expected, actual);
    133237    }
    134238
Note: See TracChangeset for help on using the changeset viewer.