Ticket #20982: 20982.patch
File 20982.patch, 3.1 KB (added by , 3 years ago) |
---|
-
src/org/openstreetmap/josm/actions/SimplifyWayAction.java
36 36 import org.openstreetmap.josm.command.SequenceCommand; 37 37 import org.openstreetmap.josm.data.SystemOfMeasurement; 38 38 import org.openstreetmap.josm.data.UndoRedoHandler; 39 import org.openstreetmap.josm.data.coor.EastNorth; 39 40 import org.openstreetmap.josm.data.osm.DataSet; 40 41 import org.openstreetmap.josm.data.osm.Node; 41 42 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 431 432 432 433 Node fromN = wnew.get(from); 433 434 Node toN = wnew.get(to); 434 435 EastNorth p1 = fromN.getEastNorth(); 436 EastNorth p2 = toN.getEastNorth(); 435 437 // Get max xte 436 438 int imax = -1; 437 439 double xtemax = 0; 438 440 for (int i = from + 1; i < to; i++) { 439 441 Node n = wnew.get(i); 442 EastNorth p = n.getEastNorth(); 443 double ldx = p2.getX() - p1.getX(); 444 double ldy = p2.getY() - p1.getY(); 445 double offset; 446 //segment zero length 447 if (ldx == 0 && ldy == 0) 448 offset = 0; 449 else { 450 double pdx = p.getX() - p1.getX(); 451 double pdy = p.getY() - p1.getY(); 452 offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy); 453 } 454 final double distRad; 440 455 // CHECKSTYLE.OFF: SingleSpaceSeparator 441 double xte = Math.abs(Ellipsoid.WGS84.a 442 * xtd(fromN.lat() * Math.PI / 180, fromN.lon() * Math.PI / 180, toN.lat() * Math.PI / 180, 443 toN.lon() * Math.PI / 180, n.lat() * Math.PI / 180, n.lon() * Math.PI / 180)); 456 if (offset <= 0) { 457 distRad = dist(fromN.lat() * Math.PI / 180, fromN.lon() * Math.PI / 180, 458 n.lat() * Math.PI / 180, n.lon() * Math.PI / 180); 459 } else if (offset >= 1) { 460 distRad = dist(toN.lat() * Math.PI / 180, toN.lon() * Math.PI / 180, 461 n.lat() * Math.PI / 180, n.lon() * Math.PI / 180); 462 } else { 463 distRad = xtd(fromN.lat() * Math.PI / 180, fromN.lon() * Math.PI / 180, 464 toN.lat() * Math.PI / 180, toN.lon() * Math.PI / 180, 465 n.lat() * Math.PI / 180, n.lon() * Math.PI / 180); 466 } 444 467 // CHECKSTYLE.ON: SingleSpaceSeparator 468 double xte = Math.abs(distRad); 445 469 if (xte > xtemax) { 446 470 xtemax = xte; 447 471 imax = i; 448 472 } 449 473 } 450 451 if (imax != -1 && xtemax >= threshold) { 474 if (imax != -1 && Ellipsoid.WGS84.a * xtemax >= threshold) { 452 475 // Segment cannot be simplified - try shorter segments 453 476 buildSimplifiedNodeList(wnew, from, imax, threshold, simplifiedNodes); 454 477 buildSimplifiedNodeList(wnew, imax, to, threshold, simplifiedNodes);