Build properly empty polygons for equal min/max box.

JIRA: MATH-1117

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1590251 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2014-04-26 16:55:11 +00:00
parent cbc32459f8
commit f4c926ea82
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-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.
</action>
<action dev="luc" type="add" issue="MATH-1119">
Added a fast single-step method for fixed-step Runge-Kutta integrators.
</action>

View File

@ -64,6 +64,16 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
* 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
@ -219,6 +229,10 @@ public class PolygonsSet extends AbstractRegion<Euclidean2D, Euclidean1D> {
private static Line[] boxBoundary(final double xMin, final double xMax,
final double yMin, final double yMax,
final double tolerance) {
if ((xMin >= xMax - tolerance) || (yMin >= yMax - tolerance)) {
// too thin box, build an empty polygons set
return null;
}
final Vector2D minMin = new Vector2D(xMin, yMin);
final Vector2D minMax = new Vector2D(xMin, yMax);
final Vector2D maxMin = new Vector2D(xMax, yMin);

View File

@ -1066,6 +1066,28 @@ public class PolygonsSetTest {
Assert.assertEquals(1, verticies.length);
}
@Test
public void testTooThinBox() {
Assert.assertEquals(0.0,
new PolygonsSet(0.0, 0.0, 0.0, 10.3206397147574, 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
PolygonsSet ps = new PolygonsSet(new BSPTree<Euclidean2D>(), 1.0e-10);
Assert.assertNotNull(ps);
try {
ps.getSize();
Assert.fail("an exception should have been thrown");
} catch (NullPointerException npe) {
// this is expected
}
}
private PolygonsSet buildSet(Vector2D[][] vertices) {
ArrayList<SubHyperplane<Euclidean2D>> edges = new ArrayList<SubHyperplane<Euclidean2D>>();
for (int i = 0; i < vertices.length; ++i) {