use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class QuadtreeCorrectTest method newGrid.
void newGrid(final int nGridCells) {
int gridSize = (int) Math.sqrt(nGridCells);
gridSize += 1;
final double extent = MAX_EXTENT - MIN_EXTENT;
final double gridInc = extent / gridSize;
final double cellSize = 2 * gridInc;
for (int i = 0; i < gridSize; i++) {
for (int j = 0; j < gridSize; j++) {
final double x = MIN_EXTENT + gridInc * i;
final double y = MIN_EXTENT + gridInc * j;
final BoundingBox env = new BoundingBoxDoubleXY(x, y, x + cellSize, y + cellSize);
this.index.insertItem(env, env);
this.envList.add(env);
}
}
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class SpatialIndexTester method addSourceData.
private void addSourceData(final double offset, final List<BoundingBox> sourceData) {
for (int i = 0; i < CELLS_PER_GRID_SIDE; i++) {
final double minx = i * CELL_EXTENT + offset;
final double maxx = minx + FEATURE_EXTENT;
for (int j = 0; j < CELLS_PER_GRID_SIDE; j++) {
final double miny = j * CELL_EXTENT + offset;
final double maxy = miny + FEATURE_EXTENT;
final BoundingBox e = new BoundingBoxDoubleXY(minx, miny, maxx, maxy);
sourceData.add(e);
}
}
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class GridGenerator method newBoundingBox.
/**
* @return BoundingBox
*
* @see com.revolsys.geometry.testold.generator.GeometryGenerator#newIterator()
*
* @throws NoSuchElementException when all the grids have been created
* @throws NullPointerException when either the Geometry Factory, or the Bounding Box are undefined.
*/
public BoundingBox newBoundingBox() {
if (!canCreate()) {
throw new NoSuchElementException("There are not any grids left to create.");
}
if (this.geometryFactory == null) {
throw new NullPointerException("GeometryFactoryI is not declared");
}
if (this.boundingBox == null || this.boundingBox.isEmpty()) {
throw new NullPointerException("Bounding Box is not declared");
}
// base x
final double x = this.boundingBox.getMinX();
final double dx = this.boundingBox.getMaxX() - x;
// base y
final double y = this.boundingBox.getMinY();
final double dy = this.boundingBox.getMaxY() - y;
final int row = this.numberRows == 1 ? 0 : this.index / this.numberRows;
final int col = this.numberColumns == 1 ? 0 : this.index % this.numberColumns;
// size of a step
double sx, sy;
sx = dx / this.numberColumns;
sy = dy / this.numberRows;
double minx, miny;
minx = x + col * sx;
miny = y + row * sy;
final BoundingBox box = new BoundingBoxDoubleXY(this.geometryFactory.makePrecise(0, minx), this.geometryFactory.makePrecise(1, miny), this.geometryFactory.makePrecise(0, minx + sx), this.geometryFactory.makePrecise(1, miny + sy));
this.index++;
return box;
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class IndexTester method runSelfQuery.
void runSelfQuery(final List items) {
double querySize = 0.0;
for (int i = 0; i < items.size(); i++) {
final BoundingBox env = (BoundingBox) items.get(i);
final List list = this.index.query(env);
Assert.isTrue(!list.isEmpty());
querySize += list.size();
}
// System.out.println("Avg query size = " + querySize / items.size());
}
use of com.revolsys.geometry.model.BoundingBox in project com.revolsys.open by revolsys.
the class KdTreeTest method testSinglePoint.
public void testSinglePoint() {
final KdTree index = new KdTree(GeometryFactory.fixed2d(0, 1000, 1000));
final KdNode node1 = index.insertPoint(new PointDouble(1, 1));
final KdNode node2 = index.insertPoint(new PointDouble(1, 1));
assertTrue("Inserting 2 identical points should create one node", node1 == node2);
final BoundingBox queryEnv = new BoundingBoxDoubleXY(0, 0, 10, 10);
final List result = index.getItems(queryEnv);
assertTrue(result.size() == 1);
final KdNode node = (KdNode) result.get(0);
assertTrue(node.getCount() == 2);
assertTrue(node.isRepeated());
}
Aggregations