Author: luc Date: Sat Apr 26 17:36:34 2014 New Revision: 1590254 URL: http://svn.apache.org/r1590254 Log: Build empty polyhedrons set when given equal min/max boundaries.
Also explained better in the javadoc about some wrong usage of PolyhedronsSet constructor. JIRA: MATH-1115 Modified: commons/proper/math/trunk/src/changes/changes.xml commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.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=1590254&r1=1590253&r2=1590254&view=diff ============================================================================== --- commons/proper/math/trunk/src/changes/changes.xml (original) +++ commons/proper/math/trunk/src/changes/changes.xml Sat Apr 26 17:36:34 2014 @@ -51,6 +51,10 @@ If the output is not quite correct, chec </properties> <body> <release version="3.3" date="TBD" description="TBD"> + <action dev="luc" type="fix" issue="MATH-1115"> + Build properly empty polyhedrons set when given equal min/max boundaries. Also explained + better in the javadoc about some wrong usage of PolyhedronsSet constructor. + </action> <action dev="luc" type="fix" issue="MATH-1117"> Build properly empty polygons set when given equal min/max boundaries. Also explained better in the javadoc about some wrong usage of PolygonsSet constructor. Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java?rev=1590254&r1=1590253&r2=1590254&view=diff ============================================================================== --- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java (original) +++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/PolyhedronsSet.java Sat Apr 26 17:36:34 2014 @@ -59,6 +59,16 @@ public class PolyhedronsSet extends Abst * cells). In order to avoid building too many small objects, it is * recommended to use the predefined constants * {@code Boolean.TRUE} and {@code Boolean.FALSE}</p> + * <p> + * This constructor is aimed at expert use, as building the tree may + * be a difficult taks. It is not intended for general use and for + * performances reasons does not check thoroughly its input, as this would + * require walking the full tree each time. Failing to provide a tree with + * the proper attributes, <em>will</em> therefore generate problems like + * {@link NullPointerException} or {@link ClassCastException} only later on. + * This limitation is known and explains why this constructor is for expert + * use only. The caller does have the responsibility to provided correct arguments. + * </p> * @param tree inside/outside BSP tree representing the region * @param tolerance tolerance below which points are considered identical * @since 3.3 @@ -190,6 +200,10 @@ public class PolyhedronsSet extends Abst final double yMin, final double yMax, final double zMin, final double zMax, final double tolerance) { + if ((xMin >= xMax - tolerance) || (yMin >= yMax - tolerance) || (zMin >= zMax - tolerance)) { + // too thin box, build an empty polygons set + return new BSPTree<Euclidean3D>(Boolean.FALSE); + } final Plane pxMin = new Plane(new Vector3D(xMin, 0, 0), Vector3D.MINUS_I, tolerance); final Plane pxMax = new Plane(new Vector3D(xMax, 0, 0), Vector3D.PLUS_I, tolerance); final Plane pyMin = new Plane(new Vector3D(0, yMin, 0), Vector3D.MINUS_J, tolerance); 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=1590254&r1=1590253&r2=1590254&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 Sat Apr 26 17:36:34 2014 @@ -285,6 +285,28 @@ public class PolyhedronsSetTest { Assert.assertEquals(24.0, polyhedronsSet.getBoundarySize(), 5.0e-6); } + @Test + public void testTooThinBox() { + Assert.assertEquals(0.0, + new PolyhedronsSet(0.0, 0.0, 0.0, 1.0, 0.0, 1.0, 1.0e-10).getSize(), + 1.0e-10); + } + + @Test + public void testWrongUsage() { + // the following is a wrong usage of the constructor. + // as explained in the javadoc, the failure is NOT detected at construction + // time but occurs later on + PolyhedronsSet ps = new PolyhedronsSet(new BSPTree<Euclidean3D>(), 1.0e-10); + Assert.assertNotNull(ps); + try { + ps.checkPoint(Vector3D.ZERO); + Assert.fail("an exception should have been thrown"); + } catch (NullPointerException npe) { + // this is expected + } + } + 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]));