Ticket #10821: iwa2.patch

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

     
    142142        for (Pair<Node, Node> wpp : wpps) {
    143143            ++i;
    144144
    145             // Finding intersection of the segment with its altitude from p (c)
    146             EastNorth altitudeIntersection = Geometry.getSegmentAltituteIntersection(wpp.a.getEastNorth(),
    147                     wpp.b.getEastNorth(), pEN);
    148 
    149             if (altitudeIntersection != null) {
    150                 // If the segment intersects with the altitude from p
    151                 currentDistance = pEN.distance(altitudeIntersection);
    152 
    153                 // Making an angle too big to let this candidate win any others
     145            EastNorth a = wpp.a.getEastNorth();
     146            EastNorth b = wpp.b.getEastNorth();
     147           
     148            // Finding intersection of the segment with its altitude from p
     149            EastNorth altitudeIntersection = Geometry.closestPointToSegment(a, b, pEN);
     150            currentDistance = pEN.distance(altitudeIntersection);
     151           
     152            if (!altitudeIntersection.equals(a) && !altitudeIntersection.equals(b)) {
     153                // If the segment intersects with the altitude from p,
     154                // make an angle too big to let this candidate win any others
    154155                // having the same distance.
    155156                currentAngle = Double.MAX_VALUE;
    156 
    157157            } else {
    158                 // Otherwise: Distance is equal to the shortest distance from p
    159                 // to a or b
    160                 currentDistance = Math.min(pEN.distance(wpp.a.getEastNorth()),
    161                         pEN.distance(wpp.b.getEastNorth()));
    162 
    163                 // Measuring the angle
    164                 currentAngle = Math.abs(Geometry.getCornerAngle(
    165                         wpp.a.getEastNorth(), pEN, wpp.b.getEastNorth()));
     158                // Otherwise ьeasurу the angle
     159                currentAngle = Math.abs(Geometry.getCornerAngle(a, pEN, b));
    166160            }
    167161
    168162            if (currentDistance < bestDistance
  • tools/Geometry.java

     
    825825        return new EastNorth(xC, yC);
    826826    }
    827827
    828     /**
    829      * Returns the coordinate of intersection of segment sp1-sp2 and an altitude
    830      * to it starting at point ap. If the line defined with sp1-sp2 intersects
    831      * its altitude out of sp1-sp2, null is returned.
    832      *
    833      * @param sp1
    834      * @param sp2
    835      * @param ap
    836      * @return Intersection coordinate or null
    837      */
    838     public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, EastNorth sp2, EastNorth ap) {
    839 
    840         CheckParameterUtil.ensureValidCoordinates(sp1, "sp1");
    841         CheckParameterUtil.ensureValidCoordinates(sp2, "sp2");
    842         CheckParameterUtil.ensureValidCoordinates(ap, "ap");
    843 
    844         Double segmentLenght = sp1.distance(sp2);
    845         Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2;
    846 
    847         // Taking a random point on the altitude line (angle is known).
    848         EastNorth ap2 = new EastNorth(ap.east() + 1000
    849                 * Math.cos(altitudeAngle), ap.north() + 1000
    850                 * Math.sin(altitudeAngle));
    851 
    852         // Finding the intersection of two lines
    853         EastNorth resultCandidate = Geometry.getLineLineIntersection(sp1, sp2,
    854                 ap, ap2);
    855 
    856         // Filtering result
    857         if (resultCandidate != null
    858                 && resultCandidate.distance(sp1) * .999 < segmentLenght
    859                 && resultCandidate.distance(sp2) * .999 < segmentLenght) {
    860             return resultCandidate;
    861         } else {
    862             return null;
    863         }
    864     }
    865 
    866828    public static class MultiPolygonMembers {
    867829        public final Set<Way> outers = new HashSet<>();
    868830        public final Set<Way> inners = new HashSet<>();