# Ticket #10821: iwa2.patch

File iwa2.patch, 4.0 KB (added by akks, 7 years ago)
• ## actions/mapmode/ImproveWayAccuracyHelper.java

 for (Pair wpp : wpps) { ++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 ьeasurу the angle currentAngle = Math.abs(Geometry.getCornerAngle(a, pEN, b)); } if (currentDistance < bestDistance
• ## tools/Geometry.java

 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; } } public static class MultiPolygonMembers { public final Set outers = new HashSet<>(); public final Set inners = new HashSet<>();