singhbaljit commented on a change in pull request #97:
URL: https://github.com/apache/commons-geometry/pull/97#discussion_r454456153



##########
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:
       Tests for area and boundary are passing with this branch locally in my 
test environment.




----------------------------------------------------------------
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]


Reply via email to