commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r1337929 - in /commons/proper/math/trunk/src: changes/changes.xml main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java test/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSetTest.java
Date Sun, 13 May 2012 15:51:57 GMT
Author: luc
Date: Sun May 13 15:51:56 2012
New Revision: 1337929

URL: http://svn.apache.org/viewvc?rev=1337929&view=rev
Log:
Fixed a wrong assumption on BSP tree attributes.

The assumption was that the attribute was always a boolean when boundary
was empty. This assumption was false when emptiness resulted from a
collapsed boundary. Boolean attributes occur only at leaf nodes, so it
is the cut sub-hyperplane that needed to be checked.

JIRA: MATH-780

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSetTest.java

Modified: commons/proper/math/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/changes/changes.xml?rev=1337929&r1=1337928&r2=1337929&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Sun May 13 15:51:56 2012
@@ -52,6 +52,10 @@ If the output is not quite correct, chec
   <body>
     <release version="3.1" date="TBD" description="
 ">
+      <action dev="luc" type="fix" issue="MATH-780" >
+        Fixed a wrong assumption on BSP tree attributes when boundary collapses to a too
+        small polygon at a non-leaf node.
+      </action>
       <action dev="luc" type="fix" issue="MATH-787" >
         Put serialization back for PointValuePair and PointVectorValuePair.
       </action>

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java?rev=1337929&r1=1337928&r2=1337929&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSet.java
Sun May 13 15:51:56 2012
@@ -132,7 +132,9 @@ public class PolygonsSet extends Abstrac
         final Vector2D[][] v = getVertices();
 
         if (v.length == 0) {
-            if ((Boolean) getTree(false).getAttribute()) {
+            final BSPTree<Euclidean2D> tree = getTree(false);
+            if (tree.getCut() == null && (Boolean) tree.getAttribute()) {
+                // the instance covers the whole space
                 setSize(Double.POSITIVE_INFINITY);
                 setBarycenter(Vector2D.NaN);
             } else {

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSetTest.java?rev=1337929&r1=1337928&r2=1337929&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSetTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSetTest.java
Sun May 13 15:51:56 2012
@@ -16,13 +16,18 @@
  */
 package org.apache.commons.math3.geometry.euclidean.threed;
 
+import java.util.ArrayList;
+
+import org.apache.commons.math3.geometry.euclidean.twod.Euclidean2D;
 import org.apache.commons.math3.geometry.euclidean.twod.PolygonsSet;
+import org.apache.commons.math3.geometry.euclidean.twod.SubLine;
 import org.apache.commons.math3.geometry.euclidean.twod.Vector2D;
 import org.apache.commons.math3.geometry.partitioning.BSPTree;
 import org.apache.commons.math3.geometry.partitioning.BSPTreeVisitor;
 import org.apache.commons.math3.geometry.partitioning.BoundaryAttribute;
 import org.apache.commons.math3.geometry.partitioning.Region;
 import org.apache.commons.math3.geometry.partitioning.RegionFactory;
+import org.apache.commons.math3.geometry.partitioning.SubHyperplane;
 import org.apache.commons.math3.util.FastMath;
 import org.junit.Assert;
 import org.junit.Test;
@@ -228,6 +233,55 @@ public class PolyhedronsSetTest {
 
     }
 
+    @Test
+    public void testIssue780() {
+        float[] coords = {
+            1.000000f, -1.000000f, -1.000000f, 
+            1.000000f, -1.000000f, 1.000000f, 
+            -1.000000f, -1.000000f, 1.000000f, 
+            -1.000000f, -1.000000f, -1.000000f, 
+            1.000000f, 1.000000f, -1f, 
+            0.999999f, 1.000000f, 1.000000f,   // 1.000000f, 1.000000f, 1.000000f, 
+            -1.000000f, 1.000000f, 1.000000f, 
+            -1.000000f, 1.000000f, -1.000000f};
+        int[] indices = {
+            0, 1, 2, 0, 2, 3, 
+            4, 7, 6, 4, 6, 5, 
+            0, 4, 5, 0, 5, 1, 
+            1, 5, 6, 1, 6, 2, 
+            2, 6, 7, 2, 7, 3, 
+            4, 0, 3, 4, 3, 7};
+        ArrayList<SubHyperplane<Euclidean3D>> subHyperplaneList = new ArrayList<SubHyperplane<Euclidean3D>>();
+        for (int idx = 0; idx < indices.length; idx += 3) {
+            int idxA = indices[idx] * 3;
+            int idxB = indices[idx + 1] * 3;
+            int idxC = indices[idx + 2] * 3;
+            Vector3D v_1 = new Vector3D(coords[idxA], coords[idxA + 1], coords[idxA + 2]);
+            Vector3D v_2 = new Vector3D(coords[idxB], coords[idxB + 1], coords[idxB + 2]);
+            Vector3D v_3 = new Vector3D(coords[idxC], coords[idxC + 1], coords[idxC + 2]);
+            Vector3D[] vertices = {v_1, v_2, v_3};
+            Plane polyPlane = new Plane(v_1, v_2, v_3);
+            ArrayList<SubHyperplane<Euclidean2D>> lines = new ArrayList<SubHyperplane<Euclidean2D>>();
+
+            Vector2D[] projPts = new Vector2D[vertices.length];
+            for (int ptIdx = 0; ptIdx < projPts.length; ptIdx++) {
+                projPts[ptIdx] = polyPlane.toSubSpace(vertices[ptIdx]);
+            }
+
+            SubLine lineInPlane = null;
+            for (int ptIdx = 0; ptIdx < projPts.length; ptIdx++) {
+                lineInPlane = new SubLine(projPts[ptIdx], projPts[(ptIdx + 1) % projPts.length]);
+                lines.add(lineInPlane);
+            }
+            Region<Euclidean2D> polyRegion = new PolygonsSet(lines);
+            SubPlane polygon = new SubPlane(polyPlane, polyRegion);
+            subHyperplaneList.add(polygon);
+        }
+        PolyhedronsSet polyhedronsSet = new PolyhedronsSet(subHyperplaneList);
+        Assert.assertEquals( 8.0, polyhedronsSet.getSize(), 3.0e-6);
+        Assert.assertEquals(24.0, polyhedronsSet.getBoundarySize(), 5.0e-6);
+    }
+
     private void checkPoints(Region.Location expected, PolyhedronsSet tree, Vector3D[] points)
{
         for (int i = 0; i < points.length; ++i) {
             Assert.assertEquals(expected, tree.checkPoint(points[i]));



Mime
View raw message