Changeset 5981 in josm
- Timestamp:
- 2013-06-01T22:33:47+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/mapmode/ParallelWays.java
r4134 r5981 6 6 import java.util.Collections; 7 7 import java.util.HashMap; 8 import java.util.HashSet; 8 9 import java.util.List; 10 import java.util.Set; 9 11 10 12 import org.openstreetmap.josm.Main; … … 36 38 // Possible/sensible to use PrimetiveDeepCopy here? 37 39 38 // //Make a deep copy of the ways, keeping the copied ways connected40 // Make a deep copy of the ways, keeping the copied ways connected 39 41 // TODO: This assumes the first/last nodes of the ways are the only possible shared nodes. 40 42 HashMap<Node, Node> splitNodeMap = new HashMap<Node, Node>(sourceWays.size()); … … 62 64 sourceWays = null; // Ensure that we only use the copies from now 63 65 64 // //Find a linear ordering of the nodes. Fail if there isn't one.66 // Find a linear ordering of the nodes. Fail if there isn't one. 65 67 CombineWayAction.NodeGraph nodeGraph = CombineWayAction.NodeGraph.createUndirectedGraphFromNodeWays(ways); 66 sortedNodes = nodeGraph.buildSpanningPath(); 67 if (sortedNodes == null) 68 List<Node> sortedNodesPath = nodeGraph.buildSpanningPath(); 69 if (sortedNodesPath == null) 68 70 throw new IllegalArgumentException("Ways must have spanning path"); // Create a dedicated exception? 71 72 // Fix #8631 - Remove duplicated nodes from graph to be robust with self-intersecting ways 73 Set<Node> removedNodes = new HashSet<Node>(); 74 sortedNodes = new ArrayList<Node>(); 75 for (int i = 0; i < sortedNodesPath.size(); i++) { 76 Node n = sortedNodesPath.get(i); 77 if (i < sortedNodesPath.size()-1) { 78 if (sortedNodesPath.get(i+1).getCoor().equals(n.getCoor())) { 79 removedNodes.add(n); 80 for (Way w : ways) 81 w.removeNode(n); 82 continue; 83 } 84 } 85 if (!removedNodes.contains(n)) { 86 sortedNodes.add(n); 87 } 88 } 69 89 70 // //Ugly method of ensuring that the offset isn't inverted. I'm sure there is a better and more elegant way, but I'm starting to get sleepy, so I do this for now.90 // Ugly method of ensuring that the offset isn't inverted. I'm sure there is a better and more elegant way, but I'm starting to get sleepy, so I do this for now. 71 91 { 72 92 Way refWay = ways.get(refWayIndex); … … 83 103 } 84 104 85 // //Initialize the required parameters. (segment normals, etc.)105 // Initialize the required parameters. (segment normals, etc.) 86 106 nodeCount = sortedNodes.size(); 87 107 pts = new EastNorth[nodeCount]; … … 110 130 */ 111 131 public void changeOffset(double d) { 112 //// This is the core algorithm: 113 /* 1. Calculate a parallel line, offset by 'd', to each segment in 114 * the path 115 * 2. Find the intersection of lines belonging to neighboring 116 * segments. These become the new node positions 132 // This is the core algorithm: 133 /* 1. Calculate a parallel line, offset by 'd', to each segment in the path 134 * 2. Find the intersection of lines belonging to neighboring segments. These become the new node positions 117 135 * 3. Do some special casing for closed paths 118 136 * … … 161 179 private List<Command> makeAddWayAndNodesCommandList() { 162 180 ArrayList<Command> commands = new ArrayList<Command>(sortedNodes.size() + ways.size()); 163 for (int i = 0; i < sortedNodes.size() - 1; i++) {181 for (int i = 0; i < sortedNodes.size() - (isClosedPath() ? 1 : 0); i++) { 164 182 commands.add(new AddCommand(sortedNodes.get(i))); 165 }166 if (!isClosedPath()) {167 commands.add(new AddCommand(sortedNodes.get(sortedNodes.size() - 1)));168 183 } 169 184 for (Way w : ways) {
Note:
See TracChangeset
for help on using the changeset viewer.