You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tn...@apache.org on 2014/02/05 23:10:22 UTC
svn commit: r1564954 - in /commons/proper/math/trunk/src:
main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/GiftWrap.java
test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
Author: tn
Date: Wed Feb 5 22:10:22 2014
New Revision: 1564954
URL: http://svn.apache.org/r1564954
Log:
[MATH-749] Handle case that all points are identical.
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/GiftWrap.java
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/hull/ConvexHullGenerator2DAbstractTest.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/GiftWrap.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/GiftWrap.java?rev=1564954&r1=1564953&r2=1564954&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/GiftWrap.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/hull/GiftWrap.java Wed Feb 5 22:10:22 2014
@@ -115,7 +115,7 @@ public class GiftWrap extends AbstractCo
}
}
pointOnHull = nextPoint;
- } while (nextPoint != hullVertices.get(0));
+ } while (nextPoint != hullVertices.get(0) && nextPoint != null);
return hullVertices;
}
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=1564954&r1=1564953&r2=1564954&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 Wed Feb 5 22:10:22 2014
@@ -88,6 +88,18 @@ public abstract class ConvexHullGenerato
}
@Test
+ public void testAllIdentical() {
+ final Collection<Vector2D> points = new ArrayList<Vector2D>();
+ points.add(new Vector2D(1, 1));
+ points.add(new Vector2D(1, 1));
+ points.add(new Vector2D(1, 1));
+ points.add(new Vector2D(1, 1));
+
+ final ConvexHull2D hull = generator.generate(points);
+ checkConvexHull(points, hull);
+ }
+
+ @Test
public void testConvexHull() {
// execute 100 random variations
for (int i = 0; i < 100; i++) {
@@ -219,6 +231,10 @@ public abstract class ConvexHullGenerato
double sign = 0.0;
final Vector2D[] points = hull.getVertices();
+ if (points.length < 3) {
+ return true;
+ }
+
for (int i = 0; i < points.length; i++) {
Vector2D p1 = points[i == 0 ? points.length - 1 : i - 1];
Vector2D p2 = points[i];
@@ -252,6 +268,9 @@ public abstract class ConvexHullGenerato
final boolean includesCollinearPoints) {
final Collection<Vector2D> hullVertices = Arrays.asList(hull.getVertices());
+ if (hullVertices.size() < 3) {
+ return;
+ }
final Region<Euclidean2D> region = hull.createRegion();
for (final Vector2D p : points) {