Package com.spatial4j.core.shape.impl

Examples of com.spatial4j.core.shape.impl.BufferedLine


        ctx.makePoint(4, 3), 1.0);
  }

  private void testDistToPoint(Point pA, Point pB, Point pC, double dist) {
    if (dist > 0) {
      assertFalse(new BufferedLine(pA, pB, dist * 0.999, ctx).contains(pC));
    } else {
      assert dist == 0;
      assertTrue(new BufferedLine(pA, pB, 0, ctx).contains(pC));
    }
    assertTrue(new BufferedLine(pA, pB, dist * 1.001, ctx).contains(pC));
  }
View Full Code Here


  @Test
  public void misc() {
    //pa == pb
    Point pt = ctx.makePoint(10, 1);
    BufferedLine line = new BufferedLine(pt, pt, 3, ctx);
    assertTrue(line.contains(ctx.makePoint(10, 1 + 3 - 0.1)));
    assertFalse(line.contains(ctx.makePoint(10, 1 + 3 + 0.1)));
  }
View Full Code Here

  @Test
  @Repeat(iterations = 15)
  public void quadrants() {
    //random line
    BufferedLine line = newRandomLine();
//    if (line.getA().equals(line.getB()))
//      return;//this test doesn't work
    Rectangle rect = newRandomLine().getBoundingBox();
    //logShapes(line, rect);
    //compute closest corner brute force
    ArrayList<Point> corners = quadrantCorners(rect);
    // a collection instead of 1 value due to ties
    Collection<Integer> farthestDistanceQuads = new LinkedList<Integer>();
    double farthestDistance = -1;
    int quad = 1;
    for (Point corner : corners) {
      double d = line.getLinePrimary().distanceUnbuffered(corner);
      if (Math.abs(d - farthestDistance) < 0.000001) {//about equal
        farthestDistanceQuads.add(quad);
      } else if (d > farthestDistance) {
        farthestDistanceQuads.clear();
        farthestDistanceQuads.add(quad);
        farthestDistance = d;
      }
      quad++;
    }
    //compare results
    int calcClosestQuad = line.getLinePrimary().quadrant(rect.getCenter());
    assertTrue(farthestDistanceQuads.contains(calcClosestQuad));
  }
View Full Code Here

  private BufferedLine newRandomLine() {
    Point pA = new PointImpl(randomInt(9), randomInt(9), ctx);
    Point pB = new PointImpl(randomInt(9), randomInt(9), ctx);
    int buf = randomInt(5);
    return new BufferedLine(pA, pB, buf, ctx);
  }
View Full Code Here

        Point pA = corners.get(r4);
        Point pB = corners.get((r4 + 2) % 4);
        double maxBuf = Math.max(nearR.getWidth(), nearR.getHeight());
        double buf = Math.abs(randomGaussian()) * maxBuf / 4;
        buf = randomInt((int) divisible(buf));
        return new BufferedLine(pA, pB, buf, ctx);
      }

      protected Point randomPointInEmptyShape(BufferedLine shape) {
        int r = randomInt(1);
        if (r == 0) return shape.getA();
View Full Code Here

  private BufferedLine newBufLine(int x1, int y1, int x2, int y2, int buf) {
    Point pA = ctx.makePoint(x1, y1);
    Point pB = ctx.makePoint(x2, y2);
    if (randomBoolean()) {
      return new BufferedLine(pB, pA, buf, ctx);
    } else {
      return new BufferedLine(pA, pB, buf, ctx);
    }
  }
View Full Code Here

TOP

Related Classes of com.spatial4j.core.shape.impl.BufferedLine

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.