Changeset 7776 in josm for trunk/src


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

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

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

Legend:

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

    r6830 r7776  
    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 measure the angle
     159                currentAngle = Math.abs(Geometry.getCornerAngle(a, pEN, b));
    166160            }
    167161
  • trunk/src/org/openstreetmap/josm/tools/Geometry.java

    r7509 r7776  
    824824        double yC = inv12*b1 + inv22*b2;
    825825        return new EastNorth(xC, yC);
    826     }
    827 
    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         }
    864826    }
    865827
Note: See TracChangeset for help on using the changeset viewer.