Ticket #20054: 20054.patch

File 20054.patch, 1.9 KB (added by GerdP, 5 years ago)
  • src/org/openstreetmap/josm/tools/Geometry.java

     
    633633        Area inter = new Area(a1);
    634634        inter.intersect(a2);
    635635
     636        boolean b1InsideB2 = a2.getBounds2D().contains(a1.getBounds2D());
     637        boolean b2InsideB1 = a1.getBounds2D().contains(a2.getBounds2D());
     638
    636639        if (inter.isEmpty() || !checkIntersection(inter, eps)) {
    637640            return new Pair<>(PolygonIntersection.OUTSIDE, inter);
    638         } else if (a2.getBounds2D().contains(a1.getBounds2D()) && inter.equals(a1)) {
     641        } else if (b1InsideB2 && inter.equals(a1)) {
    639642            return new Pair<>(PolygonIntersection.FIRST_INSIDE_SECOND, inter);
    640         } else if (a1.getBounds2D().contains(a2.getBounds2D()) && inter.equals(a2)) {
     643        } else if (b2InsideB1 && inter.equals(a2)) {
    641644            return new Pair<>(PolygonIntersection.SECOND_INSIDE_FIRST, inter);
    642         } else {
    643             return new Pair<>(PolygonIntersection.CROSSING, inter);
     645        } else if (b1InsideB2) {
     646            // see #20054
     647            Area doubleCheck = new Area(inter);
     648            doubleCheck.subtract(a1);
     649            if (doubleCheck.isEmpty() || !checkIntersection(doubleCheck, eps)) {
     650                return new Pair<>(PolygonIntersection.FIRST_INSIDE_SECOND, inter);
     651            }
     652        } else if (b2InsideB1) {
     653            // see #20054
     654            Area doubleCheck = new Area(inter);
     655            doubleCheck.subtract(a2);
     656            if (doubleCheck.isEmpty() || !checkIntersection(doubleCheck, eps)) {
     657                return new Pair<>(PolygonIntersection.SECOND_INSIDE_FIRST, inter);
     658            }
    644659        }
     660        return new Pair<>(PolygonIntersection.CROSSING, inter);
    645661    }
    646662
    647663    /**