Changeset 18539 in josm for trunk/src/org


Ignore:
Timestamp:
2022-08-16T15:50:52+02:00 (21 months ago)
Author:
taylor.smock
Message:

Fix #21856: Split way: Wrong position of new member in PTv2 relation splitting a loop

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r17375 r18539  
    488488                            if (way.lastNode() == way.firstNode()) {
    489489                                // Self-closing way.
    490                                 direction = Direction.IRRELEVANT;
     490                                direction = direction.merge(Direction.IRRELEVANT);
    491491                            } else {
    492492                                // For ordered relations, looking beyond the nearest neighbour members is not required,
     
    498498                                    else {
    499499                                        if (w.lastNode() == way.firstNode() || w.firstNode() == way.firstNode()) {
    500                                             direction = Direction.FORWARDS;
     500                                            direction = direction.merge(Direction.FORWARDS);
    501501                                        } else if (w.firstNode() == way.lastNode() || w.lastNode() == way.lastNode()) {
    502                                             direction = Direction.BACKWARDS;
     502                                            direction = direction.merge(Direction.BACKWARDS);
    503503                                        }
    504504                                    }
     
    510510                                    else {
    511511                                        if (w.lastNode() == way.firstNode() || w.firstNode() == way.firstNode()) {
    512                                             direction = Direction.BACKWARDS;
     512                                            direction = direction.merge(Direction.BACKWARDS);
    513513                                        } else if (w.firstNode() == way.lastNode() || w.lastNode() == way.lastNode()) {
    514                                             direction = Direction.FORWARDS;
     514                                            direction = direction.merge(Direction.FORWARDS);
    515515                                        }
    516516                                    }
     
    529529                                    Way w = r.getMember(ir - k).getWay();
    530530                                    if (w.lastNode() == way.firstNode() || w.firstNode() == way.firstNode()) {
    531                                         direction = Direction.FORWARDS;
     531                                        direction = direction.merge(Direction.FORWARDS);
    532532                                    } else if (w.firstNode() == way.lastNode() || w.lastNode() == way.lastNode()) {
    533                                         direction = Direction.BACKWARDS;
     533                                        direction = direction.merge(Direction.BACKWARDS);
    534534                                    }
    535535                                    break;
     
    538538                                    Way w = r.getMember(ir + k).getWay();
    539539                                    if (w.lastNode() == way.firstNode() || w.firstNode() == way.firstNode()) {
    540                                         direction = Direction.BACKWARDS;
     540                                        direction = direction.merge(Direction.BACKWARDS);
    541541                                    } else if (w.firstNode() == way.lastNode() || w.lastNode() == way.lastNode()) {
    542                                         direction = Direction.FORWARDS;
     542                                        direction = direction.merge(Direction.FORWARDS);
    543543                                    }
    544544                                    break;
     
    952952        BACKWARDS,
    953953        UNKNOWN,
    954         IRRELEVANT
     954        IRRELEVANT;
     955
     956        /**
     957         * Merge directions (this helps avoid overriding {@link #FORWARDS} with {@link #BACKWARDS}).
     958         * @param other The other direction to merge. {@link #UNKNOWN} will be overridden.
     959         * @return The merged direction
     960         */
     961        Direction merge(Direction other) {
     962            if (this == other) {
     963                return this;
     964            }
     965            if (this == IRRELEVANT || other == IRRELEVANT ||
     966                    (this == FORWARDS && other == BACKWARDS) ||
     967                    (other == FORWARDS && this == BACKWARDS)) {
     968                return IRRELEVANT;
     969            }
     970            if (this == UNKNOWN) {
     971                return other;
     972            }
     973            if (other == UNKNOWN) {
     974                return this;
     975            }
     976            return UNKNOWN;
     977        }
    955978    }
    956979
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r18468 r18539  
    531531     */
    532532    public void addPrimitiveRecursive(OsmPrimitive primitive) {
     533        Stream<OsmPrimitive> children;
    533534        if (primitive instanceof Way) {
    534             ((Way) primitive).getNodes().forEach(n -> addPrimitiveRecursive(n));
     535            children = ((Way) primitive).getNodes().stream().map(OsmPrimitive.class::cast);
    535536        } else if (primitive instanceof Relation) {
    536             ((Relation) primitive).getMembers().forEach(m -> addPrimitiveRecursive(m.getMember()));
    537         }
     537            children = ((Relation) primitive).getMembers().stream().map(RelationMember::getMember);
     538        } else {
     539            children = Stream.empty();
     540        }
     541        // Relations may have the same member multiple times.
     542        children.filter(p -> !Objects.equals(this, p.getDataSet())).forEach(this::addPrimitiveRecursive);
    538543        addPrimitive(primitive);
    539544    }
Note: See TracChangeset for help on using the changeset viewer.