# Changeset 7776 in josm for trunk/src

Ignore:
Timestamp:
2014-12-09T17:59:09+01:00 (5 years ago)
Message:

fix #10821: ImproveWayAccuracy produced self-intersecting ways
remove Geometry.getSegmentAltituteIntersection method (use closestPointToSegment)

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

Unmodified
Added
Removed
• ## trunk/src/org/openstreetmap/josm/actions/mapmode/ImproveWayAccuracyHelper.java

 r6830 ++i; // Finding intersection of the segment with its altitude from p (c) EastNorth altitudeIntersection = Geometry.getSegmentAltituteIntersection(wpp.a.getEastNorth(), wpp.b.getEastNorth(), pEN); if (altitudeIntersection != null) { // If the segment intersects with the altitude from p currentDistance = pEN.distance(altitudeIntersection); // Making an angle too big to let this candidate win any others EastNorth a = wpp.a.getEastNorth(); EastNorth b = wpp.b.getEastNorth(); // Finding intersection of the segment with its altitude from p EastNorth altitudeIntersection = Geometry.closestPointToSegment(a, b, pEN); currentDistance = pEN.distance(altitudeIntersection); if (!altitudeIntersection.equals(a) && !altitudeIntersection.equals(b)) { // If the segment intersects with the altitude from p, // make an angle too big to let this candidate win any others // having the same distance. currentAngle = Double.MAX_VALUE; } else { // Otherwise: Distance is equal to the shortest distance from p // to a or b currentDistance = Math.min(pEN.distance(wpp.a.getEastNorth()), pEN.distance(wpp.b.getEastNorth())); // Measuring the angle currentAngle = Math.abs(Geometry.getCornerAngle( wpp.a.getEastNorth(), pEN, wpp.b.getEastNorth())); // Otherwise measure the angle currentAngle = Math.abs(Geometry.getCornerAngle(a, pEN, b)); }
• ## trunk/src/org/openstreetmap/josm/tools/Geometry.java

 r7509 double yC = inv12*b1 + inv22*b2; return new EastNorth(xC, yC); } /** * Returns the coordinate of intersection of segment sp1-sp2 and an altitude * to it starting at point ap. If the line defined with sp1-sp2 intersects * its altitude out of sp1-sp2, null is returned. * * @param sp1 * @param sp2 * @param ap * @return Intersection coordinate or null */ public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, EastNorth sp2, EastNorth ap) { CheckParameterUtil.ensureValidCoordinates(sp1, "sp1"); CheckParameterUtil.ensureValidCoordinates(sp2, "sp2"); CheckParameterUtil.ensureValidCoordinates(ap, "ap"); Double segmentLenght = sp1.distance(sp2); Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2; // Taking a random point on the altitude line (angle is known). EastNorth ap2 = new EastNorth(ap.east() + 1000 * Math.cos(altitudeAngle), ap.north() + 1000 * Math.sin(altitudeAngle)); // Finding the intersection of two lines EastNorth resultCandidate = Geometry.getLineLineIntersection(sp1, sp2, ap, ap2); // Filtering result if (resultCandidate != null && resultCandidate.distance(sp1) * .999 < segmentLenght && resultCandidate.distance(sp2) * .999 < segmentLenght) { return resultCandidate; } else { return null; } }
Note: See TracChangeset for help on using the changeset viewer.