Package com.spatial4j.core.shape

Examples of com.spatial4j.core.shape.Rectangle


      }
    }
  }

  private Shape randomShapePairRect(boolean biasContains) {
    Rectangle shape1 = randomRectangle();
    Rectangle shape2 = randomRectangle();
    return new ShapePair(shape1, shape2, biasContains);
  }
View Full Code Here


      // creating a larger shape that contains the input shape.
      boolean pairTouches = shape1.relate(shape2).intersects();
      if (!pairTouches)
        return r;
      //test all 4 corners
      Rectangle oRect = (Rectangle)other;
      if (relate(ctx.makePoint(oRect.getMinX(), oRect.getMinY())) == CONTAINS
          && relate(ctx.makePoint(oRect.getMinX(), oRect.getMaxY())) == CONTAINS
          && relate(ctx.makePoint(oRect.getMaxX(), oRect.getMinY())) == CONTAINS
          && relate(ctx.makePoint(oRect.getMaxX(), oRect.getMaxY())) == CONTAINS)
        return CONTAINS;
      return r;
    }
View Full Code Here

      throw new RuntimeException("IOException thrown while executing query", ioe);
    }
  }

  protected Point randomPoint() {
    final Rectangle WB = ctx.getWorldBounds();
    return ctx.makePoint(
        randomIntBetween((int) WB.getMinX(), (int) WB.getMaxX()),
        randomIntBetween((int) WB.getMinY(), (int) WB.getMaxY()));
  }
View Full Code Here

        randomIntBetween((int) WB.getMinX(), (int) WB.getMaxX()),
        randomIntBetween((int) WB.getMinY(), (int) WB.getMaxY()));
  }

  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);
  }
View Full Code Here

  public String writeShape(Shape shape, NumberFormat nf) {
    if (shape instanceof Point) {
      Point point = (Point) shape;
      return nf.format(point.getX()) + " " + nf.format(point.getY());
    } else if (shape instanceof Rectangle) {
      Rectangle rect = (Rectangle) shape;
      return nf.format(rect.getMinX()) + " " + nf.format(rect.getMinY()) + " " + nf.format(rect.getMaxX()) + " "
          + nf.format(rect.getMaxY());
    } else if (shape instanceof Circle) {
      Circle c = (Circle) shape;
      return "Circle(" + nf.format(c.getCenter().getX()) + " " + nf.format(c.getCenter().getY()) + " " + "d="
          + nf.format(c.getRadius()) + ")";
    }
View Full Code Here

      throw new RuntimeException("IOException thrown while executing query", ioe);
    }
  }

  protected Point randomPoint() {
    final Rectangle WB = ctx.getWorldBounds();
    return ctx.makePoint(
        randomIntBetween((int) WB.getMinX(), (int) WB.getMaxX()),
        randomIntBetween((int) WB.getMinY(), (int) WB.getMaxY()));
  }
View Full Code Here

        randomIntBetween((int) WB.getMinX(), (int) WB.getMaxX()),
        randomIntBetween((int) WB.getMinY(), (int) WB.getMaxY()));
  }

  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);
  }
View Full Code Here

    Map<String, Rectangle> indexedGriddedShapes = new LinkedHashMap<String, Rectangle>();
    final int numIndexedShapes = randomIntBetween(1, 6);
    for (int i = 1; i <= numIndexedShapes; i++) {
      String id = "" + i;
      Shape indexShape = randomRectangle();
      Rectangle gridShape = gridSnapp(indexShape);
      indexedShapes.put(id, indexShape);
      indexedGriddedShapes.put(id, gridShape);
      adoc(id, indexShape);
    }

    commit();

    final int numQueryShapes = atLeast(10);
    for (int i = 0; i < numQueryShapes; i++) {
      int scanLevel = randomInt(grid.getMaxLevels());
      ((RecursivePrefixTreeStrategy) strategy).setPrefixGridScanLevel(scanLevel);
      Rectangle queryShape = randomRectangle();
      Rectangle queryGridShape = gridSnapp(queryShape);

      //Generate truth via brute force
      final SpatialOperation operation = SpatialOperation.Intersects;
      Set<String> expectedIds = new TreeSet<String>();
      Set<String> optionalIds = new TreeSet<String>();
      for (String id : indexedShapes.keySet()) {
        Shape indexShape = indexedShapes.get(id);
        Rectangle indexGridShape = indexedGriddedShapes.get(id);
        if (operation.evaluate(indexShape, queryShape))
          expectedIds.add(id);
        else if (operation.evaluate(indexGridShape, queryGridShape))
          optionalIds.add(id);
      }
View Full Code Here

    //calc bounding box of cells.
    double minX = Double.POSITIVE_INFINITY, maxX = Double.NEGATIVE_INFINITY;
    double minY = Double.POSITIVE_INFINITY, maxY = Double.NEGATIVE_INFINITY;
    for (Node cell : cells) {
      assert cell.getLevel() <= detailLevel;
      Rectangle cellR = cell.getShape().getBoundingBox();

      minX = Math.min(minX, cellR.getMinX());
      maxX = Math.max(maxX, cellR.getMaxX());
      minY = Math.min(minY, cellR.getMinY());
      maxY = Math.max(maxY, cellR.getMaxY());
    }
    return ctx.makeRectangle(minX, maxX, minY, maxY);
  }
View Full Code Here

    while(n.getLevel() < trie.getMaxLevels()) {
      prevN = n;
      n = n.getSubCells().iterator().next();//TODO random which one?
     
      assertEquals(prevN.getLevel()+1,n.getLevel());
      Rectangle prevNShape = (Rectangle) prevN.getShape();
      Shape s = n.getShape();
      Rectangle sbox = s.getBoundingBox();
      assertTrue(prevNShape.getWidth() > sbox.getWidth());
      assertTrue(prevNShape.getHeight() > sbox.getHeight());
    }
  }
View Full Code Here

TOP

Related Classes of com.spatial4j.core.shape.Rectangle

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.