Ticket #16948: crossing.patch

File crossing.patch, 2.2 KB (added by GerdP, 7 years ago)
  • src/org/openstreetmap/josm/data/osm/WaySegment.java

     
    44import java.awt.geom.Line2D;
    55import java.util.Objects;
    66
     7import org.openstreetmap.josm.data.coor.EastNorth;
     8import org.openstreetmap.josm.tools.Geometry;
     9
    710/**
    811 * A segment consisting of 2 consecutive nodes out of a way.
    912 */
     
    111114                getFirstNode().equals(s2.getSecondNode()) || getSecondNode().equals(s2.getFirstNode()))
    112115            return false;
    113116
    114         return Line2D.linesIntersect(
    115                 getFirstNode().getEastNorth().east(), getFirstNode().getEastNorth().north(),
    116                 getSecondNode().getEastNorth().east(), getSecondNode().getEastNorth().north(),
    117                 s2.getFirstNode().getEastNorth().east(), s2.getFirstNode().getEastNorth().north(),
    118                 s2.getSecondNode().getEastNorth().east(), s2.getSecondNode().getEastNorth().north());
     117        EastNorth p1 = getFirstNode().getEastNorth();
     118        EastNorth p2 = getSecondNode().getEastNorth();
     119        EastNorth p3 = s2.getFirstNode().getEastNorth();
     120        EastNorth p4 = s2.getSecondNode().getEastNorth();
     121        boolean res1 = Line2D.linesIntersect(p1.east(), p1.north(), p2.east(), p2.north(), p3.east(), p3.north(),
     122                p4.east(), p4.north());
     123        if (res1) {
     124            // calculate the position of the intersection point of the lines (not segments)
     125            EastNorth is = Geometry.getLineLineIntersection(p1, p2, p3, p4);
     126            if (is == null)
     127                return false;
     128            double d1 = is.distanceSq(p1);
     129            double d2 = is.distanceSq(p2);
     130            double d3 = is.distanceSq(p3);
     131            double d4 = is.distanceSq(p4);
     132            double eps = 0.00000001;
     133            // return false if the intersection is extremely close to one of the given points
     134            if (Math.abs(d1) < eps || Math.abs(d2) < eps || Math.abs(d3) < eps || Math.abs(d4) < eps)
     135                return false;
     136        }
     137        return res1;
    119138    }
    120139
    121140    /**