/** * Test if this rectangle fully encloses a {@link Located} item * * @param item * The item to test * @return True if this rectangle contains a {@link Located} item */ public boolean fullyGeometricallyEncloses(final Located item) { final Rectangle bounds = item instanceof Rectangle ? (Rectangle) item : item.bounds(); return this.lowerLeft().getLatitude().isLessThanOrEqualTo(bounds.lowerLeft().getLatitude()) && this.lowerLeft().getLongitude() .isLessThanOrEqualTo(bounds.lowerLeft().getLongitude()) && this.upperRight().getLatitude() .isGreaterThanOrEqualTo(bounds.upperRight().getLatitude()) && this.upperRight().getLongitude() .isGreaterThanOrEqualTo(bounds.upperRight().getLongitude()); }
private List<Location> randomLocations(final Rectangle bound, final int numberToGenerate) { final List<Location> list = new ArrayList<>(numberToGenerate); final List<Double> doubleLatitudes = new Random() .doubles(bound.lowerLeft().getLatitude().asDegrees(), bound.upperRight().getLatitude().asDegrees()) .limit(numberToGenerate).boxed().collect(Collectors.toList()); final List<Double> doubleLongitudes = new Random() .doubles(bound.lowerLeft().getLongitude().asDegrees(), bound.upperRight().getLongitude().asDegrees()) .limit(numberToGenerate).boxed().collect(Collectors.toList()); for (int i = 0; i < doubleLongitudes.size(); i++) { list.add(new Location(Latitude.degrees(doubleLatitudes.get(i)), Longitude.degrees(doubleLongitudes.get(i)))); } return list; }
/** * @param bounds * Bounds to constrain the result * @return A random location within the bounds */ public static Location random(final Rectangle bounds) { final int latitude = RANDOM.ints((int) bounds.lowerLeft().getLatitude().asDm7(), (int) bounds.upperRight().getLatitude().asDm7()).iterator().next(); final int longitude = RANDOM.ints((int) bounds.lowerLeft().getLongitude().asDm7(), (int) bounds.upperRight().getLongitude().asDm7()).iterator().next(); return new Location(Latitude.dm7(latitude), Longitude.dm7(longitude)); }
protected Rectangle2D asAwtRectangle() { final int xAxis = (int) this.upperLeft().getLongitude().asDm7(); final int yAxis = (int) this.upperLeft().getLatitude().asDm7(); final int width = (int) (this.upperRight().getLongitude().asDm7() - this.upperLeft().getLongitude().asDm7()); final int height = (int) (this.upperLeft().getLatitude().asDm7() - this.lowerLeft().getLatitude().asDm7()); return new java.awt.Rectangle(xAxis, yAxis, width, height); } }
final SlippyTile upperRight = new SlippyTile(bounds.upperRight(), zoom); final int minX = lowerLeft.getX(); final int maxX = upperRight.getX();
+ bounds.lowerLeft().getLongitude().asDegrees() + "," + bounds.lowerLeft().getLatitude().asDegrees() + "," + bounds.upperRight().getLongitude().asDegrees() + "," + bounds.upperRight().getLatitude().asDegrees() + ",4326))"); counter++; if (tileIterator.hasNext() && counter < MAX_SHARDS_PER_FILE)
this.upperRight().getLongitude()); if (tooShortHeight) final Latitude sharedLatitude = lowerRight.midPoint(this.upperRight()) .getLatitude(); return forCorners(new Location(sharedLatitude, newLowerLeft.getLongitude()),
@Test public void testSurface() { final Rectangle rectangle = Rectangle.TEST_RECTANGLE; Assert.assertEquals(rectangle.surface(), new Polygon(rectangle).surface()); final Polygon tilted = new Polygon(rectangle.lowerLeft(), new Location(rectangle.upperLeft().getLatitude(), Longitude.degrees(rectangle.upperLeft().getLongitude().asDegrees() + 0.1)), new Location(rectangle.upperRight().getLatitude(), Longitude.degrees(rectangle.upperRight().getLongitude().asDegrees() + 0.1)), rectangle.lowerRight()); Assert.assertEquals(rectangle.surface(), tilted.surface()); }
@Test public void testSurface() { final Rectangle rectangle = Rectangle.TEST_RECTANGLE; Assert.assertEquals(rectangle.surface(), MultiPolygon.forPolygon(rectangle).surface()); final MultiPolygon tilted = MultiPolygon.forPolygon(new Polygon(rectangle.lowerLeft(), new Location(rectangle.upperLeft().getLatitude(), Longitude.degrees(rectangle.upperLeft().getLongitude().asDegrees() + 0.1)), new Location(rectangle.upperRight().getLatitude(), Longitude.degrees(rectangle.upperRight().getLongitude().asDegrees() + 0.1)), rectangle.lowerRight())); Assert.assertEquals(rectangle.surface(), tilted.surface()); }
.distanceTo(this.rectangle1.upperRight()); final Rectangle collapsedRectangle1 = this.rectangle1.contract(rectangle1CornerToCorner); Assert.assertEquals(collapsedRectangle1.center().bounds(), collapsedRectangle1); .distanceTo(this.rectangle1.upperRight()).scaleBy(.51); final Rectangle collapsedHorizontally = this.rectangle1 .contract(contractRectangle1Distance);