/** * @return the area as degrees */ public Surface area() { return this.polygon.bounds().surface(); }
/** * @return the boundary with minimum area (here we suppose the boundary with minimum area is the * smallest boundary ) */ private TimeZoneBoundary smallest(final List<TimeZoneBoundary> boundaries) { if (boundaries.size() == 1) { return boundaries.get(0); } else { TimeZoneBoundary target = null; Surface minimum = Surface.MAXIMUM; for (final TimeZoneBoundary boundary : boundaries) { final Surface area = boundary.getPolygon().bounds().surface(); if (area.isLessThan(minimum)) { minimum = area; target = boundary; } } return target; } } }
@Test public void testSurface() { final Surface surface = this.rectangle3.intersection(this.rectangle4).surface(); Assert.assertTrue(surface.isLessThan(this.rectangle3.surface())); Assert.assertTrue(this.rectangle1.surface().add(this.rectangle2.surface()) .isLessThan(this.rectangle3.surface())); } }
final Rectangle collapsedRectangle1 = this.rectangle1.contract(rectangle1CornerToCorner); Assert.assertEquals(collapsedRectangle1.center().bounds(), collapsedRectangle1); Assert.assertEquals(Surface.forDm7Squared(0), collapsedRectangle1.surface()); final Rectangle collapsedHorizontally = this.rectangle1 .contract(contractRectangle1Distance); Assert.assertEquals(Surface.forDm7Squared(0), collapsedHorizontally.surface()); Assert.assertEquals(collapsedHorizontally.surface(), this.rectangle1.contract(contractRectangle1Distance.scaleBy(10)).surface()); Assert.assertEquals(Math.round(contractRectangle1Distance.asMeters()), Math.round(new Location(this.rectangle1.lowerLeft().getLatitude(), .distanceTo(this.rectangle2.lowerLeft()).scaleBy(.51); final Rectangle collapsedVertically = this.rectangle2.contract(contractRectangle2Distance); Assert.assertEquals(Surface.forDm7Squared(0), collapsedVertically.surface()); Assert.assertEquals(collapsedVertically.surface(), this.rectangle2.contract(contractRectangle2Distance.scaleBy(10)).surface()); Assert.assertEquals(Math.round(contractRectangle2Distance.asMeters()), Math.round(new Location(collapsedVertically.middle().getLatitude(),
@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()); }