SubLine extends AbstractSubHyperplane<Euclidean2D, Euclidean1D> { public List<Segment> getSegments() { final Line line = (Line) getHyperplane(); final List<Interval> list = ((IntervalsSet) getRemainingRegion()).asList(); final List<Segment> segments = new ArrayList<Segment>(list.size()); for (final Interval interval : list) { final Vector2D start = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getInf())); final Vector2D end = line.toSpace((Point<Euclidean1D>) new Vector1D(interval.getSup())); segments.add(new Segment(start, end, line)); } return segments; } SubLine(final Hyperplane<Euclidean2D> hyperplane,
                   final Region<Euclidean1D> remainingRegion);  SubLine(final Vector2D start, final Vector2D end, final double tolerance); @Deprecated  SubLine(final Vector2D start, final Vector2D end);  SubLine(final Segment segment); List<Segment> getSegments(); Vector2D intersection(final SubLine subLine, final boolean includeEndPoints); @Override Side side(final Hyperplane<Euclidean2D> hyperplane); @Override SplitSubHyperplane<Euclidean2D> split(final Hyperplane<Euclidean2D> hyperplane);  }
@Test public void testEndPoints() { Vector2D p1 = new Vector2D(-1, -7); Vector2D p2 = new Vector2D(7, -1); 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 Vector2D(-1, -7).distance(segments.get(0).getStart()), 1.0e-10); Assert.assertEquals(0.0, new Vector2D( 7, -1).distance(segments.get(0).getEnd()), 1.0e-10); }
@Test public void testNoEndPoints() { SubLine wholeLine = new Line(new Vector2D(-1, 7), new Vector2D(7, 1), 1.0e-10).wholeHyperplane(); 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).getEnd().getX()) && segments.get(0).getEnd().getX() > 0); Assert.assertTrue(Double.isInfinite(segments.get(0).getEnd().getY()) && segments.get(0).getEnd().getY() < 0); }
@Test public void testNoSegments() { SubLine empty = new SubLine(new Line(new Vector2D(-1, -7), new Vector2D(7, -1), 1.0e-10), new RegionFactory<Euclidean1D>().getComplement(new IntervalsSet(1.0e-10))); List<Segment> segments = empty.getSegments(); Assert.assertEquals(0, segments.size()); }
@Test public void testSeveralSegments() { SubLine twoSubs = new SubLine(new Line(new Vector2D(-1, -7), new Vector2D(7, -1), 1.0e-10), 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() { SubLine empty = new SubLine(new Line(new Vector2D(-1, -7), new Vector2D(7, -1), 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.assertEquals(0.0, new Vector2D(3, -4).distance(segments.get(0).getEnd()), 1.0e-10); }
@Test public void testHalfInfinitePos() { SubLine empty = new SubLine(new Line(new Vector2D(-1, -7), new Vector2D(7, -1), 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 Vector2D(3, -4).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); }