Author: luc
Date: Mon Jun  3 07:15:00 2013
New Revision: 1488866

URL: http://svn.apache.org/r1488866
Log:
Fixed NullPointerException in 2D and 3D sub-line intersections.

Patch contributed by Andeas Huber.

JIRA: MATH-988

Modified:
    commons/proper/math/trunk/src/changes/changes.xml
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.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=1488866&r1=1488865&r2=1488866&view=diff
==============================================================================
--- commons/proper/math/trunk/src/changes/changes.xml (original)
+++ commons/proper/math/trunk/src/changes/changes.xml Mon Jun  3 07:15:00 2013
@@ -51,6 +51,9 @@ If the output is not quite correct, chec
   </properties>
   <body>
     <release version="x.y" date="TBD" description="TBD">
+      <action dev="luc" type="fix" issue="MATH-988" due-to="Andreas Huber">
+        Fixed NullPointerException in 2D and 3D sub-line intersections.
+      </action>
       <action dev="psteitz" type="update" issue="MATH-987" due-to="Ajo Fod">
         Added append method to SimpleRegression, making this class 
map/reducible.
       </action>

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java?rev=1488866&r1=1488865&r2=1488866&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
 Mon Jun  3 07:15:00 2013
@@ -111,6 +111,9 @@ public class SubLine {
 
         // compute the intersection on infinite line
         Vector3D v1D = line.intersection(subLine.line);
+        if (v1D == null) {
+            return null;
+        }
 
         // check location of point with respect to first sub-line
         Location loc1 = remainingRegion.checkPoint(line.toSubSpace(v1D));

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java?rev=1488866&r1=1488865&r2=1488866&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
 Mon Jun  3 07:15:00 2013
@@ -115,6 +115,9 @@ public class SubLine extends AbstractSub
 
         // compute the intersection on infinite line
         Vector2D v2D = line1.intersection(line2);
+        if (v2D == null) {
+            return null;
+        }
 
         // check location of point with respect to first sub-line
         Location loc1 = getRemainingRegion().checkPoint(line1.toSubSpace(v2D));

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java?rev=1488866&r1=1488865&r2=1488866&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
 Mon Jun  3 07:15:00 2013
@@ -152,5 +152,13 @@ public class SubLineTest {
         Assert.assertNull(sub1.intersection(sub2, true));
         Assert.assertNull(sub1.intersection(sub2, false));
     }
+    
+    @Test
+    public void testIntersectionNotIntersecting() throws 
MathIllegalArgumentException {
+        SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(1.5, 1, 
1));
+        SubLine sub2 = new SubLine(new Vector3D(2, 3, 0), new Vector3D(2, 3, 
0.5));
+        Assert.assertNull(sub1.intersection(sub2, true));
+        Assert.assertNull(sub1.intersection(sub2, false));
+    }
 
 }

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java?rev=1488866&r1=1488865&r2=1488866&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java
 Mon Jun  3 07:15:00 2013
@@ -144,4 +144,12 @@ public class SubLineTest {
         Assert.assertNull(sub1.intersection(sub2, false));
     }
 
+    @Test
+    public void testIntersectionParallel() {
+        final SubLine sub1 = new SubLine(new Vector2D(0, 1), new Vector2D(0, 
2));
+        final SubLine sub2 = new SubLine(new Vector2D(66, 3), new Vector2D(66, 
4));
+        Assert.assertNull(sub1.intersection(sub2, true));
+        Assert.assertNull(sub1.intersection(sub2, false));
+    }
+
 }


Reply via email to