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

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1590254 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2014-04-26 17:36:34 +00:00
parent f4c926ea82
commit 2a6c6409a9
3 changed files with 40 additions and 0 deletions

View File

@ -51,6 +51,10 @@ If the output is not quite correct, check for invisible trailing spaces!
</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.

View File

@ -59,6 +59,16 @@ public class PolyhedronsSet extends AbstractRegion<Euclidean3D, Euclidean2D> {
* 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 AbstractRegion<Euclidean3D, Euclidean2D> {
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);

View File

@ -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]));