You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2018/02/06 23:59:15 UTC
[1/3] [math] MATH-1449: fixing PolygonsSet.getBarycenter() to return
Cartesian2D.NaN for empty regions
Repository: commons-math
Updated Branches:
refs/heads/master a37dcb93b -> cfe050299
MATH-1449: fixing PolygonsSet.getBarycenter() to return Cartesian2D.NaN for empty regions
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/0e9f604e
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/0e9f604e
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/0e9f604e
Branch: refs/heads/master
Commit: 0e9f604e87a5b42b27abc13a9328846cadd640f4
Parents: a37dcb9
Author: darkma773r <ma...@hotmail.com>
Authored: Sun Feb 4 14:18:36 2018 -0500
Committer: darkma773r <ma...@hotmail.com>
Committed: Sun Feb 4 14:18:36 2018 -0500
----------------------------------------------------------------------
.../geometry/euclidean/twod/PolygonsSet.java | 2 +-
.../euclidean/twod/PolygonsSetTest.java | 51 +++++++++++++++-----
2 files changed, 39 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/0e9f604e/src/main/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSet.java
----------------------------------------------------------------------
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 9975a04..9b20b0c 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<Euclidean2D, Euclidean1D> {
setBarycenter((Point<Euclidean2D>) Cartesian2D.NaN);
} else {
setSize(0);
- setBarycenter((Point<Euclidean2D>) new Cartesian2D(0, 0));
+ setBarycenter((Point<Euclidean2D>) Cartesian2D.NaN);
}
} else if (v[0][0] == null) {
// there is at least one open-loop: the polygon is infinite
http://git-wip-us.apache.org/repos/asf/commons-math/blob/0e9f604e/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java
----------------------------------------------------------------------
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 1ee2ccb..4584d03 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<Euclidean2D>().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<Euclidean2D>().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);
}
}
}
[2/3] [math] MATH-1449: updating unit test syntax based on code review
Posted by er...@apache.org.
MATH-1449: updating unit test syntax based on code review
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/53a0a9ff
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/53a0a9ff
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/53a0a9ff
Branch: refs/heads/master
Commit: 53a0a9ff85666348a38054e335f5b4c5355a6419
Parents: 0e9f604
Author: darkma773r <ma...@hotmail.com>
Authored: Mon Feb 5 21:02:07 2018 -0500
Committer: darkma773r <ma...@hotmail.com>
Committed: Mon Feb 5 21:02:07 2018 -0500
----------------------------------------------------------------------
.../euclidean/twod/PolygonsSetTest.java | 26 +++++++++++---------
1 file changed, 14 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-math/blob/53a0a9ff/src/test/java/org/apache/commons/math4/geometry/euclidean/twod/PolygonsSetTest.java
----------------------------------------------------------------------
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 4584d03..94a7157 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
@@ -229,8 +229,8 @@ public class PolygonsSetTest {
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());
+ Assert.assertTrue(poly.isEmpty());
+ Assert.assertFalse(poly.isFull());
GeometryTestUtils.assertVectorEquals(Cartesian2D.NaN, (Cartesian2D) poly.getBarycenter(), 1e-10);
checkPoints(Region.Location.OUTSIDE, poly, new Cartesian2D[] {
@@ -238,12 +238,12 @@ public class PolygonsSetTest {
Cartesian2D.ZERO,
new Cartesian2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)});
-
+ double offset;
for (double y = -1; y < 1; y += 0.1) {
for (double x = -1; x < 1; x += 0.1) {
- Assert.assertEquals(Double.POSITIVE_INFINITY,
- poly.projectToBoundary(new Cartesian2D(x, y)).getOffset(),
- 1.0e-10);
+ offset = poly.projectToBoundary(new Cartesian2D(x, y)).getOffset();
+ Assert.assertTrue(offset > 0);
+ Assert.assertTrue(Double.isInfinite(offset));
}
}
}
@@ -255,11 +255,12 @@ public class PolygonsSetTest {
// assert
Assert.assertEquals(1e-10, poly.getTolerance(), Precision.EPSILON);
- Assert.assertEquals(Double.POSITIVE_INFINITY, poly.getSize(), 1e-10);
+ Assert.assertTrue(poly.getSize() > 0);
+ Assert.assertTrue(Double.isInfinite(poly.getSize()));
Assert.assertEquals(0.0, poly.getBoundarySize(), 1e-10);
Assert.assertEquals(0, poly.getVertices().length);
- Assert.assertEquals(false, poly.isEmpty());
- Assert.assertEquals(true, poly.isFull());
+ Assert.assertFalse(poly.isEmpty());
+ Assert.assertTrue(poly.isFull());
GeometryTestUtils.assertVectorEquals(Cartesian2D.NaN, (Cartesian2D) poly.getBarycenter(), 1e-10);
checkPoints(Region.Location.INSIDE, poly, new Cartesian2D[] {
@@ -267,11 +268,12 @@ public class PolygonsSetTest {
Cartesian2D.ZERO,
new Cartesian2D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY)});
+ double offset;
for (double y = -1; y < 1; y += 0.1) {
for (double x = -1; x < 1; x += 0.1) {
- Assert.assertEquals(Double.NEGATIVE_INFINITY,
- poly.projectToBoundary(new Cartesian2D(x, y)).getOffset(),
- 1e-10);
+ offset = poly.projectToBoundary(new Cartesian2D(x, y)).getOffset();
+ Assert.assertTrue(offset < 0);
+ Assert.assertTrue(Double.isInfinite(offset));
}
}
}
[3/3] [math] Merge branch 'fix_MATH-1449'
Posted by er...@apache.org.
Merge branch 'fix_MATH-1449'
Closes #80
Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/cfe05029
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/cfe05029
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/cfe05029
Branch: refs/heads/master
Commit: cfe0502990a1e61d5ae7c744b119e8c330c37c0c
Parents: a37dcb9 53a0a9f
Author: Gilles <er...@apache.org>
Authored: Wed Feb 7 00:53:41 2018 +0100
Committer: Gilles <er...@apache.org>
Committed: Wed Feb 7 00:53:41 2018 +0100
----------------------------------------------------------------------
.../geometry/euclidean/twod/PolygonsSet.java | 2 +-
.../euclidean/twod/PolygonsSetTest.java | 59 ++++++++++++++------
2 files changed, 44 insertions(+), 17 deletions(-)
----------------------------------------------------------------------