darkma773r commented on a change in pull request #97:
URL: https://github.com/apache/commons-geometry/pull/97#discussion_r454054904
##########
File path:
commons-geometry-spherical/src/test/java/org/apache/commons/geometry/spherical/twod/RegionBSPTree2STest.java
##########
@@ -838,6 +843,48 @@ public void testCircleToPolygonBoundarySize() {
Assert.assertEquals("Clockwise boundary size", boundary,
cw.getBoundarySize(), 1.0e-7);
}
+ @Test
+ public void testSmallCircleToPolygon() {
+ // arrange
+ final double radius = 5.0e-8;
+ final Point2S center = Point2S.of(0.5, 1.5);
+ final int numPts = 100;
+
+ // act
+ final RegionBSPTree2S circle = circleToPolygon(center, radius, numPts,
false);
+
+ // assert
+ // https://en.wikipedia.org/wiki/Spherical_cap
+ final double area = 4.0 * PlaneAngleRadians.PI *
Math.pow(Math.sin(radius / 2.0), 2.0);
+ final double boundary = PlaneAngleRadians.TWO_PI * Math.sin(radius);
+
+ SphericalTestUtils.assertPointsEq(center, circle.getCentroid(),
TEST_EPS);
+ Assert.assertEquals(area, circle.getSize(), TEST_EPS);
+ Assert.assertEquals(boundary, circle.getBoundarySize(), TEST_EPS);
+ }
+
+ @Test
+ public void testSmallGeographicalRectangle() {
+ // arrange
+ final double[][] vertices = {
+ {42.656216727628696, -70.61919768884546},
+ {42.65612858998112, -70.61938607250165},
+ {42.65579098923594, -70.61909615581666},
+ {42.655879126692355, -70.61890777301083}
+ };
+
+ // act
+ final RegionBSPTree2S rectangle = latLongToTree(TEST_PRECISION,
vertices);
+
+ // assert
+ // approximate the centroid as average of vertices
+ final double avgLat = Stream.of(vertices).mapToDouble(v ->
v[0]).average().getAsDouble();
+ final double avgLon = Stream.of(vertices).mapToDouble(v ->
v[1]).average().getAsDouble();
+ final Point2S centroid = latLongToPoint(avgLat, avgLon);
+
+ SphericalTestUtils.assertPointsEq(centroid, rectangle.getCentroid(),
TEST_EPS);
Review comment:
That would be good but I'm not sure what the exact answers should be.
Google maps' distance calculator gives a boundary size of 124.51 m and an area
of 799.78 m^2. The test here returns values between 125.45 m and 812.42 m^2
(with an earth radius of 6378 km) and 125.04 m and 807.08 m^2 (with an earth
radius of 6357 km). Those seem pretty close in general but I have no idea what
goes into Google's distance calculation so I don't know if it's reasonable to
assert that we're close to those numbers.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]