Ticket #10821: iwa.patch
File iwa.patch, 3.1 KB (added by , 7 years ago) 


src/org/openstreetmap/josm/tools/Geometry.java
413 413 public static EastNorth closestPointToLine(EastNorth lineP1, EastNorth lineP2, EastNorth point) { 414 414 return closestPointTo(lineP1, lineP2, point, false); 415 415 } 416 416 417 417 /** 418 418 * This method tests if secondNode is clockwise to first node. 419 419 * … … 826 826 } 827 827 828 828 /** 829 * Returns the coordinate of intersection of segment sp1sp2 and an altitude830 * to it starting at point ap. If the line defined with sp1sp2 intersects831 * its altitude out of sp1sp2, null is returned.829 * Returns the coordinate of intersection of segment p1p2 and an altitude 830 * to it starting at point p. If the line defined with p1p2 intersects 831 * its altitude out of p1p2, null is returned. 832 832 * 833 * @param sp1834 * @param sp2835 * @param ap833 * @param p1 834 * @param p2 835 * @param point 836 836 * @return Intersection coordinate or null 837 837 */ 838 public static EastNorth getSegmentAltituteIntersection(EastNorth sp1, EastNorth sp2, EastNorth ap) {838 public static EastNorth getSegmentAltituteIntersection(EastNorth p1, EastNorth p2, EastNorth point) { 839 839 840 CheckParameterUtil.ensure ValidCoordinates(sp1, "sp1");841 CheckParameterUtil.ensure ValidCoordinates(sp2, "sp2");842 CheckParameterUtil.ensure ValidCoordinates(ap, "ap");840 CheckParameterUtil.ensureParameterNotNull(p1, "p1"); 841 CheckParameterUtil.ensureParameterNotNull(p2, "p2"); 842 CheckParameterUtil.ensureParameterNotNull(point, "point"); 843 843 844 Double segmentLenght = sp1.distance(sp2);845 Double altitudeAngle = getSegmentAngle(sp1, sp2) + Math.PI / 2;844 double ldx = p2.getX()  p1.getX(); 845 double ldy = p2.getY()  p1.getY(); 846 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)); 847 if (ldx == 0 && ldy == 0) //segment zero length 848 return p1; 851 849 852 // Finding the intersection of two lines 853 EastNorth resultCandidate = Geometry.getLineLineIntersection(sp1, sp2, 854 ap, ap2); 850 double pdx = point.getX()  p1.getX(); 851 double pdy = point.getY()  p1.getY(); 855 852 856 // Filtering result 857 if (resultCandidate != null 858 && resultCandidate.distance(sp1) * .999 < segmentLenght 859 && resultCandidate.distance(sp2) * .999 < segmentLenght) { 860 return resultCandidate; 853 double offset = (pdx * ldx + pdy * ldy) / (ldx * ldx + ldy * ldy); 854 855 if (offset < 1e8  offset > 1e8) { 856 return null; 861 857 } else { 862 return n ull;858 return new EastNorth(p1.getX() + ldx * offset, p1.getY() + ldy * offset); 863 859 } 864 860 } 865 861