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/04/26 18:55:11 UTC
svn commit: r1590251 - 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/twod/PolygonsSetTest.java
Author: luc
Date: Sat Apr 26 16:55:11 2014
New Revision: 1590251
URL: http://svn.apache.org/r1590251
Log:
Build properly empty polygons for equal min/max box.
JIRA: MATH-1117
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/twod/PolygonsSetTest.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=1590251&r1=1590250&r2=1590251&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Sat Apr 26 16:55:11 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-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>
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=1590251&r1=1590250&r2=1590251&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 Sat Apr 26 16:55:11 2014
@@ -64,6 +64,16 @@ public class PolygonsSet extends Abstrac
* 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 Abstrac
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);
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java?rev=1590251&r1=1590250&r2=1590251&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/PolygonsSetTest.java Sat Apr 26 16:55:11 2014
@@ -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) {