final Set<Location> selfIntersections = polyline.selfIntersections();
@Test public void testSelfIntersectsNoIntersections() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 2 2, 3 3, 3 1)"); Assert.assertFalse(polyLine.selfIntersects()); Assert.assertEquals(0, polyLine.selfIntersections().size()); }
@Test public void testSelfIntersectsTouchLast() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 3 1, 3 2, 2 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsClosedLoop() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 2 2, 3 3, 3 1, 1 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,1"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsTouchMiddle() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(1 1, 3 1, 3 2, 2 1, 1 2)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testSelfIntersectsTouchFirst() { final PolyLine polyLine = PolyLine.wkt("LINESTRING(2 1, 3 2, 3 1, 1 1)"); Assert.assertTrue(polyLine.selfIntersects()); final Set<Location> intersections = polyLine.selfIntersections(); Assert.assertEquals(1, intersections.size()); Assert.assertEquals(Location.forString("1,2"), intersections.toArray()[0]); }
@Test public void testSelfIntersects() { final PolyLine polyLine = new WktPolyLineConverter().backwardConvert( "LINESTRING(-122.0095413 37.3362091,-122.0095716 37.3353178,-122.009566 37.33531,-122.0095604 37.3353178,-122.0095907 37.3362091)"); Assert.assertTrue(polyLine.selfIntersects()); Assert.assertEquals(1, polyLine.selfIntersections().size()); }
final Set<Location> selfIntersections = polyLine.selfIntersections();