@Test
  public void testCellTraverse() {
    trie = new GeohashPrefixTree(ctx, 4);

    Cell prevC = null;
    Cell c = trie.getWorldCell();
    assertEquals(0, c.getLevel());
    assertEquals(ctx.getWorldBounds(), c.getShape());
    while (c.getLevel() < trie.getMaxLevels()) {
      prevC = c;
      List<Cell> subCells = new ArrayList<>();
      CellIterator subCellsIter = c.getNextLevelCells(null);
      while (subCellsIter.hasNext()) {
        subCells.add(subCellsIter.next());
      }
      c = subCells.get(random().nextInt(subCells.size() - 1));

      assertEquals(prevC.getLevel() + 1, c.getLevel());
      Rectangle prevNShape = (Rectangle) prevC.getShape();
      Shape s = c.getShape();
      Rectangle sbox = s.getBoundingBox();
      assertTrue(prevNShape.getWidth() > sbox.getWidth());
      assertTrue(prevNShape.getHeight() > sbox.getHeight());
    }
  }
Exemple #2
0
  protected Rectangle randomRectangle() {
    final Rectangle WB = ctx.getWorldBounds();
    int rW = (int) randomGaussianMeanMax(10, WB.getWidth());
    double xMin = randomIntBetween((int) WB.getMinX(), (int) WB.getMaxX() - rW);
    double xMax = xMin + rW;

    int yH = (int) randomGaussianMeanMax(Math.min(rW, WB.getHeight()), WB.getHeight());
    double yMin = randomIntBetween((int) WB.getMinY(), (int) WB.getMaxY() - yH);
    double yMax = yMin + yH;

    return ctx.makeRectangle(xMin, xMax, yMin, yMax);
  }