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/05/19 17:00:03 UTC
svn commit: r1595924 - in /commons/proper/math/trunk/src: changes/changes.xml
main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java
test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
Author: luc
Date: Mon May 19 15:00:03 2014
New Revision: 1595924
URL: http://svn.apache.org/r1595924
Log:
Fixed NullPointerException in BSPTree.
The error occurred when chopping-off a sub-hyperplane
that was exactly at a region boundary.
Thanks to Aurélien Labrosse for the fix.
JIRA: MATH-1123
Modified:
commons/proper/math/trunk/src/changes/changes.xml
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.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=1595924&r1=1595923&r2=1595924&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Mon May 19 15:00:03 2014
@@ -73,6 +73,10 @@ Users are encouraged to upgrade to this
2. A few methods in the FastMath class are in fact slower that their
counterpart in either Math or StrictMath (cf. MATH-740 and MATH-901).
">
+ <action dev="luc" type="fix" issue="MATH-1123" due-to="Aurélien Labrosse">
+ Fixed NullPointerException when chopping-off a sub-hyperplane
+ that is exactly at a region boundary.
+ </action>
<action dev="erans" type="fix" issue="MATH-1121" due-to="Ajo Fod">
"BrentOptimizer": increment base class iteration counter.
</action>
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java?rev=1595924&r1=1595923&r2=1595924&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/partitioning/BSPTree.java Mon May 19 15:00:03 2014
@@ -294,7 +294,7 @@ public class BSPTree<S extends Space> {
*/
private SubHyperplane<S> fitToCell(final SubHyperplane<S> sub) {
SubHyperplane<S> s = sub;
- for (BSPTree<S> tree = this; tree.parent != null; tree = tree.parent) {
+ for (BSPTree<S> tree = this; tree.parent != null && s != null; tree = tree.parent) {
if (tree == tree.parent.plus) {
s = s.split(tree.parent.cut.getHyperplane()).getPlus();
} else {
Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java?rev=1595924&r1=1595923&r2=1595924&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java Mon May 19 15:00:03 2014
@@ -203,6 +203,103 @@ public abstract class ConvexHullGenerato
checkConvexHull(points, hull);
}
+ @Test
+ public void testIssue1123() {
+
+ List<Vector2D> points = new ArrayList<Vector2D>();
+
+ int[][] data = new int[][] { { -11, -1 }, { -11, 0 }, { -11, 1 },
+ { -10, -3 }, { -10, -2 }, { -10, -1 }, { -10, 0 }, { -10, 1 },
+ { -10, 2 }, { -10, 3 }, { -9, -4 }, { -9, -3 }, { -9, -2 },
+ { -9, -1 }, { -9, 0 }, { -9, 1 }, { -9, 2 }, { -9, 3 },
+ { -9, 4 }, { -8, -5 }, { -8, -4 }, { -8, -3 }, { -8, -2 },
+ { -8, -1 }, { -8, 0 }, { -8, 1 }, { -8, 2 }, { -8, 3 },
+ { -8, 4 }, { -8, 5 }, { -7, -6 }, { -7, -5 }, { -7, -4 },
+ { -7, -3 }, { -7, -2 }, { -7, -1 }, { -7, 0 }, { -7, 1 },
+ { -7, 2 }, { -7, 3 }, { -7, 4 }, { -7, 5 }, { -7, 6 },
+ { -6, -7 }, { -6, -6 }, { -6, -5 }, { -6, -4 }, { -6, -3 },
+ { -6, -2 }, { -6, -1 }, { -6, 0 }, { -6, 1 }, { -6, 2 },
+ { -6, 3 }, { -6, 4 }, { -6, 5 }, { -6, 6 }, { -6, 7 },
+ { -5, -7 }, { -5, -6 }, { -5, -5 }, { -5, -4 }, { -5, -3 },
+ { -5, -2 }, { -5, 4 }, { -5, 5 }, { -5, 6 }, { -5, 7 },
+ { -4, -7 }, { -4, -6 }, { -4, -5 }, { -4, -4 }, { -4, -3 },
+ { -4, -2 }, { -4, 4 }, { -4, 5 }, { -4, 6 }, { -4, 7 },
+ { -3, -8 }, { -3, -7 }, { -3, -6 }, { -3, -5 }, { -3, -4 },
+ { -3, -3 }, { -3, -2 }, { -3, 4 }, { -3, 5 }, { -3, 6 },
+ { -3, 7 }, { -3, 8 }, { -2, -8 }, { -2, -7 }, { -2, -6 },
+ { -2, -5 }, { -2, -4 }, { -2, -3 }, { -2, -2 }, { -2, 4 },
+ { -2, 5 }, { -2, 6 }, { -2, 7 }, { -2, 8 }, { -1, -8 },
+ { -1, -7 }, { -1, -6 }, { -1, -5 }, { -1, -4 }, { -1, -3 },
+ { -1, -2 }, { -1, 4 }, { -1, 5 }, { -1, 6 }, { -1, 7 },
+ { -1, 8 }, { 0, -8 }, { 0, -7 }, { 0, -6 }, { 0, -5 },
+ { 0, -4 }, { 0, -3 }, { 0, -2 }, { 0, 4 }, { 0, 5 }, { 0, 6 },
+ { 0, 7 }, { 0, 8 }, { 1, -8 }, { 1, -7 }, { 1, -6 }, { 1, -5 },
+ { 1, -4 }, { 1, -3 }, { 1, -2 }, { 1, -1 }, { 1, 0 }, { 1, 1 },
+ { 1, 2 }, { 1, 3 }, { 1, 4 }, { 1, 5 }, { 1, 6 }, { 1, 7 },
+ { 1, 8 }, { 2, -8 }, { 2, -7 }, { 2, -6 }, { 2, -5 },
+ { 2, -4 }, { 2, -3 }, { 2, -2 }, { 2, -1 }, { 2, 0 }, { 2, 1 },
+ { 2, 2 }, { 2, 3 }, { 2, 4 }, { 2, 5 }, { 2, 6 }, { 2, 7 },
+ { 2, 8 }, { 3, -8 }, { 3, -7 }, { 3, -6 }, { 3, -5 },
+ { 3, -4 }, { 3, -3 }, { 3, -2 }, { 3, -1 }, { 3, 0 }, { 3, 1 },
+ { 3, 2 }, { 3, 3 }, { 3, 4 }, { 3, 5 }, { 3, 6 }, { 3, 7 },
+ { 3, 8 }, { 4, -7 }, { 4, -6 }, { 4, -5 }, { 4, -4 },
+ { 4, -3 }, { 4, -2 }, { 4, -1 }, { 4, 0 }, { 4, 1 }, { 4, 2 },
+ { 4, 3 }, { 4, 4 }, { 4, 5 }, { 4, 6 }, { 4, 7 }, { 5, -7 },
+ { 5, -6 }, { 5, -5 }, { 5, -4 }, { 5, -3 }, { 5, -2 },
+ { 5, -1 }, { 5, 0 }, { 5, 1 }, { 5, 2 }, { 5, 3 }, { 5, 4 },
+ { 5, 5 }, { 5, 6 }, { 5, 7 }, { 6, -7 }, { 6, -6 }, { 6, -5 },
+ { 6, -4 }, { 6, -3 }, { 6, -2 }, { 6, -1 }, { 6, 0 }, { 6, 1 },
+ { 6, 2 }, { 6, 3 }, { 6, 4 }, { 6, 5 }, { 6, 6 }, { 6, 7 },
+ { 7, -6 }, { 7, -5 }, { 7, -4 }, { 7, -3 }, { 7, -2 },
+ { 7, -1 }, { 7, 0 }, { 7, 1 }, { 7, 2 }, { 7, 3 }, { 7, 4 },
+ { 7, 5 }, { 7, 6 }, { 8, -5 }, { 8, -4 }, { 8, -3 }, { 8, -2 },
+ { 8, -1 }, { 8, 0 }, { 8, 1 }, { 8, 2 }, { 8, 3 }, { 8, 4 },
+ { 8, 5 }, { 9, -4 }, { 9, -3 }, { 9, -2 }, { 9, -1 }, { 9, 0 },
+ { 9, 1 }, { 9, 2 }, { 9, 3 }, { 9, 4 }, { 10, -3 }, { 10, -2 },
+ { 10, -1 }, { 10, 0 }, { 10, 1 }, { 10, 2 }, { 10, 3 },
+ { 11, -1 }, { 11, 0 }, { 11, 1 } };
+
+ for (int[] line : data) {
+ points.add(new Vector2D(line[0], line[1]));
+ }
+
+ Vector2D[] referenceHull = new Vector2D[] {
+ new Vector2D(-11.0, -1.0),
+ new Vector2D(-10.0, -3.0),
+ new Vector2D( -6.0, -7.0),
+ new Vector2D( -3.0, -8.0),
+ new Vector2D( 3.0, -8.0),
+ new Vector2D( 6.0, -7.0),
+ new Vector2D( 10.0, -3.0),
+ new Vector2D( 11.0, -1.0),
+ new Vector2D( 11.0, 1.0),
+ new Vector2D( 10.0, 3.0),
+ new Vector2D( 6.0, 7.0),
+ new Vector2D( 3.0, 8.0),
+ new Vector2D( -3.0, 8.0),
+ new Vector2D( -6.0, 7.0),
+ new Vector2D(-10.0, 3.0),
+ new Vector2D(-11.0, 1.0),
+ };
+
+ ConvexHullGenerator2D generator = new MonotoneChain(true, 1e-6);
+ ConvexHull2D convHull = generator.generate(points);
+ Region<Euclidean2D> hullRegion = convHull.createRegion();
+
+ Assert.assertEquals(274.0, hullRegion.getSize(), 1.0e-12);
+ double perimeter = 0;
+ for (int i = 0; i < referenceHull.length; ++i) {
+ perimeter += Vector2D.distance(referenceHull[i],
+ referenceHull[(i + 1) % referenceHull.length]);
+ }
+ Assert.assertEquals(perimeter, hullRegion.getBoundarySize(), 1.0e-12);
+
+ for (int i = 0; i < referenceHull.length; ++i) {
+ Assert.assertEquals(Location.BOUNDARY, hullRegion.checkPoint(referenceHull[i]));
+ }
+
+ }
+
// ------------------------------------------------------------------------------
protected final List<Vector2D> createRandomPoints(int size) {