Changeset 57 in josm for src/org/openstreetmap/josm/data


Ignore:
Timestamp:
2006-02-21T13:39:40+01:00 (18 years ago)
Author:
imi
Message:

fixed bug where merged nodes and line segments were equal but not the same (aliasing)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r52 r57  
    11package org.openstreetmap.josm.data.osm.visitor;
    22
     3import java.util.HashMap;
    34import java.util.Iterator;
     5import java.util.LinkedList;
     6import java.util.Map;
    47
    58import org.openstreetmap.josm.data.osm.DataSet;
     
    2023        private final DataSet ds;
    2124       
     25        /**
     26         * A list of all nodes that got replaced with other nodes.
     27         * Key is the node in the other's dataset and the value is the one that is now
     28         * in ds.nodes instead.
     29         */
     30        private final Map<Node, Node> mergedNodes = new HashMap<Node, Node>();
     31        /**
     32         * A list of all line segments that got replaced with others.
     33         * Key is the segment in the other's dataset and the value is the one that is now
     34         * in ds.lineSegments.
     35         */
     36        private final Map<LineSegment, LineSegment> mergedLineSegments = new HashMap<LineSegment, LineSegment>();
     37       
    2238        public MergeVisitor(DataSet ds) {
    2339                this.ds = ds;
     
    3955                        ds.nodes.add(otherNode);
    4056                else {
     57                        mergedNodes.put(otherNode, myNode);
    4158                        mergeCommon(myNode, otherNode);
    4259                        if (myNode.modified && !otherNode.modified)
     
    6481                        ds.lineSegments.add(otherLs);
    6582                else {
     83                        mergedLineSegments.put(otherLs, myLs);
    6684                        mergeCommon(myLs, otherLs);
    6785                        if (myLs.modified && !otherLs.modified)
     
    99117                        Iterator<LineSegment> it = otherTrack.segments.iterator();
    100118                        for (LineSegment ls : myTrack.segments) {
    101                                 if (!match(ls, it.next())) {
     119                                if (!match(ls, it.next()))
    102120                                        same = false;
    103                                 }
    104121                        }
    105122                        if (!same) {
     
    113130        public void visit(Key k) {
    114131                //TODO: Key doesn't really fit the OsmPrimitive concept!
     132        }
     133       
     134        /**
     135         * Postprocess the dataset and fix all merged references to point to the actual
     136         * data.
     137         */
     138        public void fixReferences() {
     139                for (LineSegment ls : ds.lineSegments) {
     140                        if (mergedNodes.containsKey(ls.start))
     141                                ls.start = mergedNodes.get(ls.start);
     142                        if (mergedNodes.containsKey(ls.end))
     143                                ls.end = mergedNodes.get(ls.end);
     144                }
     145                for (Track t : ds.tracks) {
     146                        boolean replacedSomething = false;
     147                        LinkedList<LineSegment> newSegments = new LinkedList<LineSegment>();
     148                        for (LineSegment ls : t.segments) {
     149                                LineSegment otherLs = mergedLineSegments.get(ls);
     150                                newSegments.add(otherLs == null ? ls : otherLs);
     151                                if (otherLs != null)
     152                                        replacedSomething = true;
     153                        }
     154                        if (replacedSomething) {
     155                                t.segments.clear();
     156                                t.segments.addAll(newSegments);
     157                        }
     158                        for (LineSegment ls : t.segments) {
     159                                if (mergedNodes.containsKey(ls.start))
     160                                        ls.start = mergedNodes.get(ls.start);
     161                                if (mergedNodes.containsKey(ls.end))
     162                                        ls.end = mergedNodes.get(ls.end);
     163                        }
     164                }
    115165        }
    116166       
Note: See TracChangeset for help on using the changeset viewer.