use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class HeatmapFacetCounterTest method validateHeatmapResult.
private void validateHeatmapResult(Rectangle inputRange, int facetLevel, HeatmapFacetCounter.Heatmap heatmap) throws IOException {
final Rectangle heatRect = heatmap.region;
assertTrue(heatRect.relate(inputRange) == SpatialRelation.CONTAINS || heatRect.equals(inputRange));
final double cellWidth = heatRect.getWidth() / heatmap.columns;
final double cellHeight = heatRect.getHeight() / heatmap.rows;
for (int c = 0; c < heatmap.columns; c++) {
for (int r = 0; r < heatmap.rows; r++) {
final int facetCount = heatmap.getCount(c, r);
double x = DistanceUtils.normLonDEG(heatRect.getMinX() + c * cellWidth + cellWidth / 2);
double y = DistanceUtils.normLatDEG(heatRect.getMinY() + r * cellHeight + cellHeight / 2);
Point pt = ctx.makePoint(x, y);
assertEquals(countMatchingDocsAtLevel(pt, facetLevel), facetCount);
}
}
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class Geo3dRptTest method testFailure1.
@Test
public void testFailure1() throws IOException {
setupStrategy();
final List<GeoPoint> points = new ArrayList<GeoPoint>();
points.add(new GeoPoint(PlanetModel.SPHERE, 18 * DEGREES_TO_RADIANS, -27 * DEGREES_TO_RADIANS));
points.add(new GeoPoint(PlanetModel.SPHERE, -57 * DEGREES_TO_RADIANS, 146 * DEGREES_TO_RADIANS));
points.add(new GeoPoint(PlanetModel.SPHERE, 14 * DEGREES_TO_RADIANS, -180 * DEGREES_TO_RADIANS));
points.add(new GeoPoint(PlanetModel.SPHERE, -15 * DEGREES_TO_RADIANS, 153 * DEGREES_TO_RADIANS));
final Shape triangle = new Geo3dShape(GeoPolygonFactory.makeGeoPolygon(PlanetModel.SPHERE, points), ctx);
final Rectangle rect = ctx.makeRectangle(-49, -45, 73, 86);
testOperation(rect, SpatialOperation.Intersects, triangle, false);
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class RandomizedShapeTestCase method divisible.
/** reset()'s p, and confines to world bounds. Might not be divisible if
* the world bound isn't divisible too.
*/
protected Point divisible(Point p) {
Rectangle bounds = ctx.getWorldBounds();
double newX = boundX(divisible(p.getX()), bounds);
double newY = boundY(divisible(p.getY()), bounds);
p.reset(newX, newY);
return p;
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class RandomizedShapeTestCase method _assertIntersect.
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 (// they are the same shape type
a.getClass().equals(b.getClass()))
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 {
//always fails
assertEquals(msg, expected, sect);
}
}
use of org.locationtech.spatial4j.shape.Rectangle in project lucene-solr by apache.
the class HeatmapFacetCounterTest method testRandom.
@Test
@Repeat(iterations = 20)
public void testRandom() throws IOException {
// Tests using random index shapes & query shapes. This has found all sorts of edge case bugs (e.g. dateline,
// cell border, overflow(?)).
final int numIndexedShapes = 1 + atMost(9);
List<Shape> indexedShapes = new ArrayList<>(numIndexedShapes);
for (int i = 0; i < numIndexedShapes; i++) {
indexedShapes.add(randomIndexedShape());
}
//Main index loop:
for (int i = 0; i < indexedShapes.size(); i++) {
Shape shape = indexedShapes.get(i);
adoc("" + i, shape);
if (random().nextInt(10) == 0)
//intermediate commit, produces extra segments
commit();
}
//delete some documents randomly
for (int id = 0; id < indexedShapes.size(); id++) {
if (random().nextInt(10) == 0) {
deleteDoc("" + id);
indexedShapes.set(id, null);
}
}
commit();
// once without dateline wrap
final Rectangle rect = randomRectangle();
queryHeatmapRecursive(usually() ? ctx.getWorldBounds() : rect, 1);
// and once with dateline wrap
if (rect.getWidth() > 0) {
double shift = random().nextDouble() % rect.getWidth();
queryHeatmapRecursive(ctx.makeRectangle(DistanceUtils.normLonDEG(rect.getMinX() - shift), DistanceUtils.normLonDEG(rect.getMaxX() - shift), rect.getMinY(), rect.getMaxY()), 1);
}
}
Aggregations