private void _assertIntersect(String msg, SpatialRelation expected, Shape a, Shape b) { SpatialRelation sect = a.relate(b); if (sect == expected) return; msg = ((msg == null) ? "" : msg + "\r") + a + " intersect " + b; if (expected == WITHIN || expected == CONTAINS) { if (a.getClass().equals(b.getClass())) // they are the same shape type assertEquals(msg, a, b); else { // they are effectively points or lines that are the same location assertTrue(msg, !a.hasArea()); assertTrue(msg, !b.hasArea()); Rectangle aBBox = a.getBoundingBox(); Rectangle bBBox = b.getBoundingBox(); if (aBBox.getHeight() == 0 && bBBox.getHeight() == 0 && (aBBox.getMaxY() == 90 && bBBox.getMaxY() == 90 || aBBox.getMinY() == -90 && bBBox.getMinY() == -90)) ; // == a point at the pole else assertEquals(msg, aBBox, bBBox); } } else { assertEquals(msg, expected, sect); // always fails } }
protected Rectangle computeBoundingBox(Collection<? extends Shape> shapes, SpatialContext ctx) { Range xRange = null; double minY = Double.POSITIVE_INFINITY; double maxY = Double.NEGATIVE_INFINITY; for (Shape geom : shapes) { Rectangle r = geom.getBoundingBox(); Range xRange2 = Range.xRange(r, ctx); if (xRange == null) { xRange = xRange2; } else { xRange = xRange.expandTo(xRange2); } minY = Math.min(minY, r.getMinY()); maxY = Math.max(maxY, r.getMaxY()); } return ctx.makeRectangle(xRange.getMin(), xRange.getMax(), minY, maxY); }
static double boundY(double i, Rectangle bounds) { return bound(i, bounds.getMinY(), bounds.getMaxY()); }