[ 
https://issues.apache.org/jira/browse/MATH-988?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andreas Huber updated MATH-988:
-------------------------------

    Description: 
When calling SubLine.intersection() with two lines that not intersect, then a 
NullPointerException is thrown in Line.toSubSpace(). This bug is in the twod 
and threed implementations.

The attached patch fixes both implementations and adds the required test cases.



  was:
When calling SubLine.intersection() with two lines that not intersect, then a 
NullPointerException is thrown in Line.toSubSpace(). This bug is in the twod 
and threed implementations.

The following patch fixes both implementations and adds the required test cases:

Index: 
src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
===================================================================
--- 
src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
   (revision 1488671)
+++ 
src/test/java/org/apache/commons/math3/geometry/euclidean/threed/SubLineTest.java
   (working copy)
@@ -152,5 +152,13 @@
         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));
+    }
 
 }
Index: 
src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java
===================================================================
--- 
src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java 
    (revision 1488671)
+++ 
src/test/java/org/apache/commons/math3/geometry/euclidean/twod/SubLineTest.java 
    (working copy)
@@ -144,4 +144,12 @@
         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));
+    }
 }
Index: 
src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java
===================================================================
--- 
src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java   
    (revision 1488671)
+++ 
src/main/java/org/apache/commons/math3/geometry/euclidean/threed/SubLine.java   
    (working copy)
@@ -111,6 +111,10 @@
 
         // 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));
Index: 
src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java
===================================================================
--- src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java 
(revision 1488671)
+++ src/main/java/org/apache/commons/math3/geometry/euclidean/twod/SubLine.java 
(working copy)
@@ -115,6 +115,10 @@
 
         // 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));




    
> NPE when calling SubLine.intersection() with non-intersecting lines
> -------------------------------------------------------------------
>
>                 Key: MATH-988
>                 URL: https://issues.apache.org/jira/browse/MATH-988
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.0, 3.1, 3.2, 3.1.1
>            Reporter: Andreas Huber
>         Attachments: SubLineIntersection.patch
>
>
> When calling SubLine.intersection() with two lines that not intersect, then a 
> NullPointerException is thrown in Line.toSubSpace(). This bug is in the twod 
> and threed implementations.
> The attached patch fixes both implementations and adds the required test 
> cases.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to