Ticket #18274: 18274.patch

File 18274.patch, 3.0 KB (added by taylor.smock, 22 months ago)
  • src/org/openstreetmap/josm/data/osm/BBox.java

     
    336336    }
    337337
    338338    /**
     339     * Check if bboxes are functionally equal
     340     * @param other The other bbox to compare with
     341     * @param maxDifference The maximum difference (in degrees) between the bboxes. May be null.
     342     * @return true if they are functionally equivalent
     343     */
     344    public boolean bboxesAreFunctionallyEqual(BBox other, Double maxDifference) {
     345        return bboxesAreFunctionallyEqual(this, other, maxDifference);
     346    }
     347
     348    /**
     349     * Check if bboxes are functionally equal
     350     * @param bbox1 A bbox to compare with another bbox
     351     * @param bbox2 The other bbox to compare with
     352     * @param maxDifference The maximum difference (in degrees) between the bboxes. May be null.
     353     * @return true if they are functionally equivalent
     354     */
     355    public static boolean bboxesAreFunctionallyEqual(BBox bbox1, BBox bbox2, Double maxDifference) {
     356        if (maxDifference == null) {
     357            maxDifference = LatLon.MAX_SERVER_PRECISION;
     358        }
     359        return (bbox1 != null && bbox2 != null)
     360                && (Math.abs(bbox1.getBottomRightLat() - bbox2.getBottomRightLat()) <= maxDifference
     361                        && Math.abs(bbox1.getBottomRightLon() - bbox2.getBottomRightLon()) <= maxDifference
     362                        && Math.abs(bbox1.getTopLeftLat() - bbox2.getTopLeftLat()) <= maxDifference
     363                        && Math.abs(bbox1.getTopLeftLon() - bbox2.getTopLeftLon()) <= maxDifference);
     364    }
     365
     366    /**
    339367     * @return true if the bbox covers a part of the planets surface
    340368     * Height and width must be non-negative, but may (both) be 0.
    341369     * @since 11269
  • test/unit/org/openstreetmap/josm/data/osm/BBoxTest.java

     
    3939    }
    4040
    4141    /**
     42     * Unit test of method {@link BBox#bboxesAreFunctionallyEqual}
     43     */
     44    @Test
     45    public void testBboxesAreFunctionallyEqual() {
     46        BBox bbox1 = new BBox(0, 1, 1, 0);
     47        BBox bbox2 = new BBox(0.1, 0.9, 0.9, 0.1);
     48
     49        assertFalse(BBox.bboxesAreFunctionallyEqual(bbox1, null, null));
     50        assertFalse(BBox.bboxesAreFunctionallyEqual(null, bbox2, null));
     51        assertFalse(BBox.bboxesAreFunctionallyEqual(null, null, null));
     52
     53        assertFalse(bbox1.bboxesAreFunctionallyEqual(bbox2, null));
     54        assertTrue(bbox1.bboxesAreFunctionallyEqual(bbox2, 0.1));
     55        bbox1.add(0, 1.1);
     56        assertFalse(bbox1.bboxesAreFunctionallyEqual(bbox2, 0.1));
     57        bbox1.add(2, 0);
     58        assertFalse(bbox1.bboxesAreFunctionallyEqual(bbox2, 0.1));
     59    }
     60
     61    /**
    4262     * Test LatLon constructor which might result in invalid bbox
    4363     */
    4464    @Test