SubLine { public Vector3D intersection(final SubLine subLine, final boolean includeEndPoints) { Vector3D v1D = line.intersection(subLine.line); if (v1D == null) { return null; } Location loc1 = remainingRegion.checkPoint((Point<Euclidean1D>) line.toSubSpace((Point<Euclidean3D>) v1D)); Location loc2 = subLine.remainingRegion.checkPoint((Point<Euclidean1D>) subLine.line.toSubSpace((Point<Euclidean3D>) v1D)); if (includeEndPoints) { return ((loc1 != Location.OUTSIDE) && (loc2 != Location.OUTSIDE)) ? v1D : null; } else { return ((loc1 == Location.INSIDE) && (loc2 == Location.INSIDE)) ? v1D : null; } } SubLine(final Line line, final IntervalsSet remainingRegion);  SubLine(final Vector3D start, final Vector3D end, final double tolerance);  SubLine(final Vector3D start, final Vector3D end);  SubLine(final Segment segment); List<Segment> getSegments(); Vector3D intersection(final SubLine subLine, final boolean includeEndPoints);  }
@Test public void testIntersectionInsideInside() throws MathIllegalArgumentException { SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(3, 1, 1), 1.0e-10); SubLine sub2 = new SubLine(new Vector3D(2, 0, 0), new Vector3D(2, 2, 2), 1.0e-10); Assert.assertEquals(0.0, new Vector3D(2, 1, 1).distance(sub1.intersection(sub2, true)), 1.0e-12); Assert.assertEquals(0.0, new Vector3D(2, 1, 1).distance(sub1.intersection(sub2, false)), 1.0e-12); }
@Test public void testIntersectionInsideBoundary() throws MathIllegalArgumentException { SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(3, 1, 1), 1.0e-10); SubLine sub2 = new SubLine(new Vector3D(2, 0, 0), new Vector3D(2, 1, 1), 1.0e-10); Assert.assertEquals(0.0, new Vector3D(2, 1, 1).distance(sub1.intersection(sub2, true)), 1.0e-12); Assert.assertNull(sub1.intersection(sub2, false)); }
@Test public void testIntersectionInsideOutside() throws MathIllegalArgumentException { SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(3, 1, 1), 1.0e-10); SubLine sub2 = new SubLine(new Vector3D(2, 0, 0), new Vector3D(2, 0.5, 0.5), 1.0e-10); Assert.assertNull(sub1.intersection(sub2, true)); Assert.assertNull(sub1.intersection(sub2, false)); }
@Test public void testIntersectionBoundaryBoundary() throws MathIllegalArgumentException { SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(2, 1, 1), 1.0e-10); SubLine sub2 = new SubLine(new Vector3D(2, 0, 0), new Vector3D(2, 1, 1), 1.0e-10); Assert.assertEquals(0.0, new Vector3D(2, 1, 1).distance(sub1.intersection(sub2, true)), 1.0e-12); Assert.assertNull(sub1.intersection(sub2, false)); }
@Test public void testIntersectionBoundaryOutside() throws MathIllegalArgumentException { SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(2, 1, 1), 1.0e-10); SubLine sub2 = new SubLine(new Vector3D(2, 0, 0), new Vector3D(2, 0.5, 0.5), 1.0e-10); Assert.assertNull(sub1.intersection(sub2, true)); Assert.assertNull(sub1.intersection(sub2, false)); }
@Test public void testIntersectionOutsideOutside() throws MathIllegalArgumentException { SubLine sub1 = new SubLine(new Vector3D(1, 1, 1), new Vector3D(1.5, 1, 1), 1.0e-10); SubLine sub2 = new SubLine(new Vector3D(2, 0, 0), new Vector3D(2, 0.5, 0.5), 1.0e-10); 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), 1.0e-10); SubLine sub2 = new SubLine(new Vector3D(2, 3, 0), new Vector3D(2, 3, 0.5), 1.0e-10); Assert.assertNull(sub1.intersection(sub2, true)); Assert.assertNull(sub1.intersection(sub2, false)); }