You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by lu...@apache.org on 2014/12/02 22:20:30 UTC

[4/8] [math] Identified a new failure mode for polygons.

Identified a new failure mode for polygons.

Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/c29e3d68
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/c29e3d68
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/c29e3d68

Branch: refs/heads/master
Commit: c29e3d681f2a46cc3288dc4f38925efbcf30c233
Parents: e11c000
Author: Luc Maisonobe <lu...@apache.org>
Authored: Sun Nov 30 11:40:27 2014 +0100
Committer: Luc Maisonobe <lu...@apache.org>
Committed: Tue Dec 2 15:24:31 2014 +0100

----------------------------------------------------------------------
 .../euclidean/twod/PolygonsSetTest.java         | 37 ++++++++++++++++++++
 1 file changed, 37 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/c29e3d68/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java b/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java
index 348ace8..c6c68a0 100644
--- a/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java
+++ b/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java
@@ -24,6 +24,7 @@ import org.apache.commons.math3.geometry.euclidean.oned.IntervalsSet;
 import org.apache.commons.math3.geometry.euclidean.oned.Vector1D;
 import org.apache.commons.math3.geometry.partitioning.BSPTree;
 import org.apache.commons.math3.geometry.partitioning.BoundaryProjection;
+import org.apache.commons.math3.geometry.partitioning.Hyperplane;
 import org.apache.commons.math3.geometry.partitioning.Region;
 import org.apache.commons.math3.geometry.partitioning.Region.Location;
 import org.apache.commons.math3.geometry.partitioning.RegionFactory;
@@ -1107,6 +1108,42 @@ public class PolygonsSetTest {
 
     }
 
+    @Test
+    public void testThinRectangle() {
+
+        RegionFactory<Euclidean2D> factory = new RegionFactory<Euclidean2D>();
+        Vector2D pA = new Vector2D(0.0,        1.0);
+        Vector2D pB = new Vector2D(0.0,        0.0);
+        Vector2D pC = new Vector2D(1.0 / 64.0, 0.0);
+        Vector2D pD = new Vector2D(1.0 / 64.0, 1.0);
+
+        // if tolerance is smaller than rectangle width, the rectangle is computed accurately
+        Hyperplane<Euclidean2D>[] h1 = new Line[] {
+            new Line(pA, pB, 1.0 / 256),
+            new Line(pB, pC, 1.0 / 256),
+            new Line(pC, pD, 1.0 / 256),
+            new Line(pD, pA, 1.0 / 256)
+        };
+        Region<Euclidean2D> accuratePolygon = factory.buildConvex(h1);
+        Assert.assertEquals(1.0 / 64.0, accuratePolygon.getSize(), 1.0e-10);
+        Assert.assertTrue(Double.isInfinite(new RegionFactory<Euclidean2D>().getComplement(accuratePolygon).getSize()));
+        Assert.assertEquals(2 * (1.0 + 1.0 / 64.0), accuratePolygon.getBoundarySize(), 1.0e-10);
+
+        // if tolerance is larger than rectangle width, the rectangle degenerates
+        // as of 3.3, its two long edges cannot be distinguished anymore and this part of the test fails
+        Hyperplane<Euclidean2D>[] h2 = new Line[] {
+            new Line(pA, pB, 1.0 / 16),
+            new Line(pB, pC, 1.0 / 16),
+            new Line(pC, pD, 1.0 / 16),
+            new Line(pD, pA, 1.0 / 16)
+        };
+        Region<Euclidean2D> degeneratedPolygon = factory.buildConvex(h2);
+        Assert.assertEquals(1.0 / 64.0, degeneratedPolygon.getSize(), 1.0e-10);
+        Assert.assertTrue(Double.isInfinite(new RegionFactory<Euclidean2D>().getComplement(degeneratedPolygon).getSize()));
+        Assert.assertEquals(2 * (1.0 + 1.0 / 64.0), degeneratedPolygon.getBoundarySize(), 1.0e-10);
+
+    }
+
     private PolygonsSet buildSet(Vector2D[][] vertices) {
         ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
         for (int i = 0; i < vertices.length; ++i) {