@@ -33,6 +33,78 @@ public class TurfMiscTest extends TestUtils {
3333 @ Rule
3434 public ExpectedException thrown = ExpectedException .none ();
3535
36+ @ Test
37+ public void lineIntersect_intersectingEdge () {
38+ List <Point > line1Coords = new ArrayList <>();
39+ line1Coords .add (Point .fromLngLat (1.0 , 2.0 ));
40+ line1Coords .add (Point .fromLngLat (2.0 , 3.0 ));
41+ LineString line1 = LineString .fromLngLats (line1Coords );
42+
43+ List <Point > line2Coords = new ArrayList <>();
44+ line2Coords .add (Point .fromLngLat (2.0 , 3.0 ));
45+ line2Coords .add (Point .fromLngLat (4.0 , 2.0 ));
46+ LineString line2 = LineString .fromLngLats (line2Coords );
47+
48+ List <Point > result1 = TurfMisc .lineIntersect (line1 , line2 );
49+ assertEquals (1 , result1 .size ());
50+ assertEquals (Point .fromLngLat (2.0 , 3.0 ), result1 .get (0 ));
51+
52+ List <Point > line3Coords = new ArrayList <>();
53+ line3Coords .add (Point .fromLngLat (0.0 , 3.0 ));
54+ line3Coords .add (Point .fromLngLat (1.0 , 2.0 ));
55+ LineString line3 = LineString .fromLngLats (line3Coords );
56+
57+ List <Point > result2 = TurfMisc .lineIntersect (line1 , line3 );
58+ assertEquals (1 , result2 .size ());
59+ assertEquals (Point .fromLngLat (1.0 , 2.0 ), result2 .get (0 ));
60+ }
61+
62+ @ Test
63+ public void lineIntersect_intersecting () {
64+ List <Point > line1Coords = new ArrayList <>();
65+ line1Coords .add (Point .fromLngLat (2.0 , 1.0 ));
66+ line1Coords .add (Point .fromLngLat (2.0 , 5.0 ));
67+ line1Coords .add (Point .fromLngLat (2.0 , 9.0 ));
68+ LineString line1 = LineString .fromLngLats (line1Coords );
69+
70+ List <Point > line2Coords = new ArrayList <>();
71+ line2Coords .add (Point .fromLngLat (4.0 , 1.0 ));
72+ line2Coords .add (Point .fromLngLat (0.0 , 5.0 ));
73+ line2Coords .add (Point .fromLngLat (2.0 , 9.0 ));
74+ LineString line2 = LineString .fromLngLats (line2Coords );
75+
76+ List <Point > expected = new ArrayList <>();
77+ expected .add (Point .fromLngLat (2.0 , 3.0 ));
78+ expected .add (Point .fromLngLat (2.0 , 9.0 ));
79+
80+ List <Point > result = TurfMisc .lineIntersect (line1 , line2 );
81+ for (int i = 0 ; i < result .size (); i ++) {
82+ assertEquals (expected .get (i ), result .get (i ));
83+ }
84+ }
85+
86+ @ Test
87+ public void lineIntersect_nonintersecting () {
88+ List <Point > line1Coords = new ArrayList <>();
89+ line1Coords .add (Point .fromLngLat (2.0 , 1.0 ));
90+ line1Coords .add (Point .fromLngLat (2.0 , 5.0 ));
91+ line1Coords .add (Point .fromLngLat (2.0 , 9.0 ));
92+ LineString line1 = LineString .fromLngLats (line1Coords );
93+
94+ List <Point > line2Coords = new ArrayList <>();
95+ line2Coords .add (Point .fromLngLat (1.0 , 1.0 ));
96+ line2Coords .add (Point .fromLngLat (1.0 , 5.0 ));
97+ line2Coords .add (Point .fromLngLat (1.0 , 9.0 ));
98+ LineString line2 = LineString .fromLngLats (line2Coords );
99+
100+ List <Point > expected = new ArrayList <>();
101+ expected .add (Point .fromLngLat (2.0 , 3.0 ));
102+ expected .add (Point .fromLngLat (2.0 , 9.0 ));
103+
104+ List <Point > result = TurfMisc .lineIntersect (line1 , line2 );
105+ assertEquals (0 , result .size ());
106+ }
107+
36108 @ Test
37109 public void lineSlice_throwsStartStopPointException () throws Exception {
38110 thrown .expect (TurfException .class );
0 commit comments