Changeset 35617 in osm for applications/editors
- Timestamp:
- 2020-10-25T12:22:46+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
r35597 r35617 16 16 import java.util.Map; 17 17 import java.util.Set; 18 import java.util.stream.Collectors; 18 19 19 20 import javax.swing.JOptionPane; … … 155 156 } else if (referenceObject instanceof Relation) { 156 157 for (RelationMember member : ((Relation) referenceObject).getMembers()) { 157 if ((member.getRole().equals( "outer") ||member.getRole().equals("inner"))158 if (("outer".equals(member.getRole()) || "inner".equals(member.getRole())) 158 159 && member.isWay()) { 159 160 // TODO: could consider more nodes, such as nodes that are members of other ways, … … 165 166 assert false; 166 167 } 167 nodeToReplace = findNearestNode(subjectNode, nodePool); 168 // see #8396: first try to find nearest new node 169 nodeToReplace = findNearestNode(subjectNode, nodePool.stream().filter(Node::isNew).collect(Collectors.toList())); 170 if (nodeToReplace == null) { 171 nodeToReplace = findNearestNode(subjectNode, nodePool); 172 } 168 173 } 169 174 … … 251 256 * @param subjectWay way to modify 252 257 * @param referenceWay way to remove 253 * @return 258 * @return Command to replace geometry or null if user cancelled 254 259 */ 255 260 public static ReplaceGeometryCommand buildReplaceWayCommand(Way subjectWay, Way referenceWay) { … … 291 296 int gLen = geometryPool.size(); 292 297 int nLen = nodePool.size(); 293 int N= Math.max(gLen, nLen);298 int maxDim = Math.max(gLen, nLen); 294 299 boolean useRobust = Config.getPref().getBoolean("utilsplugin2.replace-geometry.robustAssignment", true) 295 && N<= Config.getPref().getInt("utilsplugin2.replace-geometry.robustAssignment.max-size", 300);300 && maxDim <= Config.getPref().getInt("utilsplugin2.replace-geometry.robustAssignment.max-size", 300); 296 301 297 302 // Find new nodes that are closest to the old ones, remove matching old ones from the pool … … 300 305 if (gLen > 0 && nLen > 0) { 301 306 if (useRobust) { // use robust, but slower assignment 302 double[][] cost = new double[ N][N];303 for (int i = 0; i < N; i++) {304 for (int j = 0; j < N; j++) {307 double[][] cost = new double[maxDim][maxDim]; 308 for (int i = 0; i < maxDim; i++) { 309 for (int j = 0; j < maxDim; j++) { 305 310 cost[i][j] = Double.MAX_VALUE; 306 311 } … … 321 326 try { 322 327 assignment = new AssignmentProblem(cost); 323 for (int i = 0; i < N; i++) {328 for (int i = 0; i < maxDim; i++) { 324 329 int nIdx = i; 325 330 int gIdx = assignment.sol(i); … … 369 374 370 375 // Move old nodes to new positions 371 for ( Node node: nodeAssoc.keySet()) {372 commands.add(new MoveCommand( nodeAssoc.get(node), node.getCoor()));376 for (Map.Entry<Node, Node> entry : nodeAssoc.entrySet()) { 377 commands.add(new MoveCommand(entry.getValue(), entry.getKey().getCoor())); 373 378 } 374 379 … … 394 399 * @return list of distinct nodes that are not tagged and not used anywhere except in the way 395 400 */ 396 protectedstatic List<Node> getUnimportantNodes(Way way) {401 static List<Node> getUnimportantNodes(Way way) { 397 402 List<Node> nodePool = new LinkedList<>(); 398 403 for (Node n : way.getNodes()) { … … 410 415 * role membership), and thus cannot be safely modified. 411 416 */ 412 protectedstatic boolean hasImportantNode(Way geometry, Way way) {417 static boolean hasImportantNode(Way geometry, Way way) { 413 418 for (Node n : way.getNodes()) { 414 419 // if original and replacement way share a node, it's safe to replace … … 429 434 } 430 435 431 protected static boolean hasInterestingKey(OsmPrimitive object) { 432 for (String key : object.getKeys().keySet()) { 433 if (!OsmPrimitive.isUninterestingKey(key)) { 434 return true; 435 } 436 } 437 return false; 438 } 439 440 protected static boolean isInArea(Node node, Area area) { 436 static boolean hasInterestingKey(OsmPrimitive object) { 437 return object.getKeys().keySet().stream().anyMatch(k -> !OsmPrimitive.isUninterestingKey(k)); 438 } 439 440 static boolean isInArea(Node node, Area area) { 441 441 LatLon ll = node.getCoor(); 442 if (node.isNewOrUndeleted() || area == null || ll == null || area.contains(ll.getX(), ll.getY())) { 443 return true; 444 } 445 return false; 446 } 447 448 protected static boolean isInArea(Way way, Area area) { 442 return node.isNewOrUndeleted() || area == null || ll == null || area.contains(ll.getX(), ll.getY()); 443 } 444 445 static boolean isInArea(Way way, Area area) { 449 446 if (area == null) { 450 447 return true; … … 469 466 * @throws UserCancelException If the user cancelled a dialog. 470 467 */ 471 protectedstatic List<Command> getTagConflictResolutionCommands(OsmPrimitive source, OsmPrimitive target) throws UserCancelException {468 static List<Command> getTagConflictResolutionCommands(OsmPrimitive source, OsmPrimitive target) throws UserCancelException { 472 469 Collection<OsmPrimitive> primitives = Arrays.asList(source, target); 473 470 // launch a conflict resolution dialog, if necessary … … 480 477 * @return null if there is no such node. 481 478 */ 482 protectedstatic Node findNearestNode(Node node, Collection<Node> nodes) {479 static Node findNearestNode(Node node, Collection<Node> nodes) { 483 480 if (nodes.contains(node)) 484 481 return node;
Note:
See TracChangeset
for help on using the changeset viewer.