Changeset 15186 in josm


Ignore:
Timestamp:
2019-06-21T01:53:11+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #17810 - incompletely downloaded turn restrictions sometimes break when splitting the from way (patch by taylor.smock, modified)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/command/SplitWayCommand.java

    r15078 r15186  
    4343    private static volatile Consumer<String> warningNotifier = Logging::warn;
    4444
     45    private static final class RelationInformation {
     46        boolean warnme;
     47        boolean insert;
     48        Relation relation;
     49    }
     50
    4551    /**
    4652     * Sets the global warning notifier.
     
    320326                    boolean insert = true;
    321327                    if (relationSpecialTypes.containsKey(type) && "restriction".equals(relationSpecialTypes.get(type))) {
    322                         Map<String, Boolean> rValue = treatAsRestriction(r, rm, c, newWays, way, changedWay);
    323                         warnme = rValue.containsKey("warnme") ? rValue.get("warnme") : warnme;
    324                         insert = rValue.containsKey("insert") ? rValue.get("insert") : insert;
     328                        RelationInformation rValue = treatAsRestriction(r, rm, c, newWays, way, changedWay);
     329                        warnme = rValue.warnme;
     330                        insert = rValue.insert;
     331                        c = rValue.relation;
    325332                    } else if (!("route".equals(type)) && !("multipolygon".equals(type))) {
    326333                        warnme = true;
     
    410417    }
    411418
    412     private static Map<String, Boolean> treatAsRestriction(Relation r,
     419    private static RelationInformation treatAsRestriction(Relation r,
    413420            RelationMember rm, Relation c, Collection<Way> newWays, Way way,
    414421            Way changedWay) {
    415         HashMap<String, Boolean> rMap = new HashMap<>();
     422        RelationInformation relationInformation = new RelationInformation();
    416423        /* this code assumes the restriction is correct. No real error checking done */
    417424        String role = rm.getRole();
     
    448455                    c.addMember(new RelationMember(role, res));
    449456                    c.removeMembersFor(way);
    450                     rMap.put("insert", false);
     457                    relationInformation.insert = false;
    451458                }
    452459            } else {
    453                 rMap.put("insert", false);
     460                relationInformation.insert = false;
    454461            }
    455462        } else if (!"via".equals(role)) {
    456             rMap.put("warnme", true);
    457         }
    458         return rMap;
     463            relationInformation.warnme = true;
     464        }
     465        relationInformation.relation = c;
     466        return relationInformation;
    459467    }
    460468
  • trunk/test/unit/org/openstreetmap/josm/actions/SplitWayActionTest.java

    r14542 r15186  
    77import java.util.Arrays;
    88
     9import org.junit.Assert;
    910import org.junit.Rule;
    1011import org.junit.Test;
     12import org.openstreetmap.josm.TestUtils;
    1113import org.openstreetmap.josm.data.coor.EastNorth;
     14import org.openstreetmap.josm.data.coor.LatLon;
    1215import org.openstreetmap.josm.data.osm.DataSet;
    1316import org.openstreetmap.josm.data.osm.Node;
     17import org.openstreetmap.josm.data.osm.Relation;
     18import org.openstreetmap.josm.data.osm.RelationMember;
    1419import org.openstreetmap.josm.data.osm.Way;
    1520import org.openstreetmap.josm.testutils.JOSMTestRules;
     
    7984        }
    8085    }
     86
     87    /**
     88     * Test case: when a way is split with a turn restriction relation,
     89     * the relation should not be broken.
     90     * see #17810
     91     */
     92    @Test
     93    public void testTicket17810() {
     94        DataSet dataSet = new DataSet();
     95        Way from = TestUtils.newWay("highway=residential", new Node(new LatLon(0.0, 0.0)),
     96                new Node(new LatLon(0.00033, 0.00033)), new Node(new LatLon(0.00066, 0.00066)),
     97                new Node(new LatLon(0.001, 0.001)));
     98        from.getNodes().forEach(node -> dataSet.addPrimitive(node));
     99        dataSet.addPrimitive(from);
     100        Node via = from.lastNode();
     101        Way to = TestUtils.newWay("highway=residential", new Node(new LatLon(0.002, 0.001)), via);
     102        to.getNodes().forEach(node -> {
     103            if (!dataSet.containsNode(node)) {
     104                dataSet.addPrimitive(node);
     105            }
     106        });
     107        dataSet.addPrimitive(to);
     108        Relation restriction = TestUtils.newRelation("type=restriction restriction=no_left_turn",
     109                new RelationMember("from", from), new RelationMember("to", to),
     110                new RelationMember("via", via));
     111        dataSet.addPrimitive(restriction);
     112        dataSet.clearSelection();
     113        dataSet.addSelected(from.getNode(2), from);
     114        SplitWayAction.runOn(dataSet);
     115        for (RelationMember member : restriction.getMembers()) {
     116            if ("from".equals(member.getRole())) {
     117                Assert.assertTrue(member.getWay().containsNode(via));
     118            }
     119        }
     120    }
    81121}
Note: See TracChangeset for help on using the changeset viewer.