SubLine { public List<Segment> getSegments() { final List<Interval> list = remainingRegion.asList(); final List<Segment> segments = new ArrayList<Segment>(list.size()); for (final Interval interval : list) { final Vector3D start = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getInf())); final Vector3D end = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } return segments; } 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 testEndPoints() throws MathIllegalArgumentException { Vector3D p1 = new Vector3D(-1, -7, 2); Vector3D p2 = new Vector3D(7, -1, 0); Segment segment = new Segment(p1, p2, new Line(p1, p2, 1.0e-10)); SubLine sub = new SubLine(segment); List<Segment> segments = sub.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertEquals(0.0, new Vector3D(-1, -7, 2).distance(segments.get(0).getStart()), 1.0e-10); Assert.assertEquals(0.0, new Vector3D( 7, -1, 0).distance(segments.get(0).getEnd()), 1.0e-10); }
@Test public void testNoEndPoints() throws MathIllegalArgumentException { SubLine wholeLine = new Line(new Vector3D(-1, 7, 2), new Vector3D(7, 1, 0), 1.0e-10).wholeLine(); List<Segment> segments = wholeLine.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getX()) && segments.get(0).getStart().getX() < 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getY()) && segments.get(0).getStart().getY() > 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getZ()) && segments.get(0).getStart().getZ() > 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getEnd().getX()) && segments.get(0).getEnd().getX() > 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getEnd().getY()) && segments.get(0).getEnd().getY() < 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getEnd().getZ()) && segments.get(0).getEnd().getZ() < 0); }
@Test public void testNoSegments() throws MathIllegalArgumentException { SubLine empty = new SubLine(new Line(new Vector3D(-1, -7, 2), new Vector3D(7, -1, 0), 1.0e-10), (IntervalsSet) new RegionFactory<Euclidean1D>().getComplement(new IntervalsSet(1.0e-10))); List<Segment> segments = empty.getSegments(); Assert.assertEquals(0, segments.size()); }
@Test public void testSeveralSegments() throws MathIllegalArgumentException { SubLine twoSubs = new SubLine(new Line(new Vector3D(-1, -7, 2), new Vector3D(7, -1, 0), 1.0e-10), (IntervalsSet) new RegionFactory<Euclidean1D>().union(new IntervalsSet(1, 2, 1.0e-10), new IntervalsSet(3, 4, 1.0e-10))); List<Segment> segments = twoSubs.getSegments(); Assert.assertEquals(2, segments.size()); }
@Test public void testHalfInfiniteNeg() throws MathIllegalArgumentException { SubLine empty = new SubLine(new Line(new Vector3D(-1, -7, 2), new Vector3D(7, -1, -2), 1.0e-10), new IntervalsSet(Double.NEGATIVE_INFINITY, 0.0, 1.0e-10)); List<Segment> segments = empty.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getX()) && segments.get(0).getStart().getX() < 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getY()) && segments.get(0).getStart().getY() < 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getStart().getZ()) && segments.get(0).getStart().getZ() > 0); Assert.assertEquals(0.0, new Vector3D(3, -4, 0).distance(segments.get(0).getEnd()), 1.0e-10); }
@Test public void testHalfInfinitePos() throws MathIllegalArgumentException { SubLine empty = new SubLine(new Line(new Vector3D(-1, -7, 2), new Vector3D(7, -1, -2), 1.0e-10), new IntervalsSet(0.0, Double.POSITIVE_INFINITY, 1.0e-10)); List<Segment> segments = empty.getSegments(); Assert.assertEquals(1, segments.size()); Assert.assertEquals(0.0, new Vector3D(3, -4, 0).distance(segments.get(0).getStart()), 1.0e-10); Assert.assertTrue(Double.isInfinite(segments.get(0).getEnd().getX()) && segments.get(0).getEnd().getX() > 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getEnd().getY()) && segments.get(0).getEnd().getY() > 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getEnd().getZ()) && segments.get(0).getEnd().getZ() < 0); }