diff --git a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java index 9975a04b9..9b20b0c02 100644 --- a/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java +++ b/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java @@ -553,7 +553,7 @@ public class PolygonsSet extends AbstractRegion { setBarycenter((Point) Cartesian2D.NaN); } else { setSize(0); - setBarycenter((Point) new Cartesian2D(0, 0)); + setBarycenter((Point) Cartesian2D.NaN); } } else if (v[0][0] == null) { // there is at least one open-loop: the polygon is infinite diff --git a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java index 1ee2ccb14..4584d0312 100644 --- a/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java +++ b/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java @@ -221,15 +221,28 @@ public class PolygonsSetTest { @Test public void testEmpty() { - PolygonsSet empty = (PolygonsSet) new RegionFactory().getComplement(new PolygonsSet(1.0e-10)); - Assert.assertTrue(empty.isEmpty()); - Assert.assertEquals(0, empty.getVertices().length); - Assert.assertEquals(0.0, empty.getBoundarySize(), 1.0e-10); - Assert.assertEquals(0.0, empty.getSize(), 1.0e-10); + // act + PolygonsSet poly = (PolygonsSet) new RegionFactory().getComplement(new PolygonsSet(1e-10)); + + // assert + Assert.assertEquals(1e-10, poly.getTolerance(), Precision.EPSILON); + Assert.assertEquals(0.0, poly.getSize(), 1e-10); + Assert.assertEquals(0.0, poly.getBoundarySize(), 1e-10); + Assert.assertEquals(0, poly.getVertices().length); + Assert.assertEquals(true, poly.isEmpty()); + Assert.assertEquals(false, poly.isFull()); + GeometryTestUtils.assertVectorEquals(Cartesian2D.NaN, (Cartesian2D) poly.getBarycenter(), 1e-10); + + checkPoints(Region.Location.OUTSIDE, poly, new Cartesian2D[] { + new Cartesian2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), + Cartesian2D.ZERO, + new Cartesian2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)}); + + for (double y = -1; y < 1; y += 0.1) { for (double x = -1; x < 1; x += 0.1) { Assert.assertEquals(Double.POSITIVE_INFINITY, - empty.projectToBoundary(new Cartesian2D(x, y)).getOffset(), + poly.projectToBoundary(new Cartesian2D(x, y)).getOffset(), 1.0e-10); } } @@ -237,16 +250,28 @@ public class PolygonsSetTest { @Test public void testFull() { - PolygonsSet empty = new PolygonsSet(1.0e-10); - Assert.assertFalse(empty.isEmpty()); - Assert.assertEquals(0, empty.getVertices().length); - Assert.assertEquals(0.0, empty.getBoundarySize(), 1.0e-10); - Assert.assertEquals(Double.POSITIVE_INFINITY, empty.getSize(), 1.0e-10); + // act + PolygonsSet poly = new PolygonsSet(1e-10); + + // assert + Assert.assertEquals(1e-10, poly.getTolerance(), Precision.EPSILON); + Assert.assertEquals(Double.POSITIVE_INFINITY, poly.getSize(), 1e-10); + Assert.assertEquals(0.0, poly.getBoundarySize(), 1e-10); + Assert.assertEquals(0, poly.getVertices().length); + Assert.assertEquals(false, poly.isEmpty()); + Assert.assertEquals(true, poly.isFull()); + GeometryTestUtils.assertVectorEquals(Cartesian2D.NaN, (Cartesian2D) poly.getBarycenter(), 1e-10); + + checkPoints(Region.Location.INSIDE, poly, new Cartesian2D[] { + new Cartesian2D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY), + Cartesian2D.ZERO, + new Cartesian2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)}); + for (double y = -1; y < 1; y += 0.1) { for (double x = -1; x < 1; x += 0.1) { Assert.assertEquals(Double.NEGATIVE_INFINITY, - empty.projectToBoundary(new Cartesian2D(x, y)).getOffset(), - 1.0e-10); + poly.projectToBoundary(new Cartesian2D(x, y)).getOffset(), + 1e-10); } } }