@@ -133,6 +133,48 @@ public void FindZeroSegmentsTestSimpleSegment2()
133133 Assert . AreEqual ( 4 , result [ 0 ] . Item2 ) ;
134134 }
135135
136+ [ Test ]
137+ public void IntersectionOfSegmentsFullIntersection ( )
138+ {
139+ var result = FlatImage . IntersectionOfSegments (
140+ new Tuple < int , int > ( 1 , 2 ) ,
141+ new Tuple < int , int > ( 1 , 2 ) ) ;
142+ Assert . AreEqual ( new Tuple < int , int > ( 1 , 2 ) , result ) ;
143+ }
144+
145+ [ Test ]
146+ public void IntersectionOfSegmentsPartialIntersection ( )
147+ {
148+ var a = new Tuple < int , int > ( 1 , 4 ) ;
149+ var b = new Tuple < int , int > ( 2 , 8 ) ;
150+
151+ Assert . AreEqual ( new Tuple < int , int > ( 2 , 4 ) , FlatImage . IntersectionOfSegments ( a , b ) ) ;
152+ Assert . AreEqual ( new Tuple < int , int > ( 2 , 4 ) , FlatImage . IntersectionOfSegments ( b , a ) ) ;
153+ }
154+
155+ [ Test ]
156+ public void IntersectionOfSegmentsNoIntersection ( )
157+ {
158+ var result = FlatImage . IntersectionOfSegments (
159+ new Tuple < int , int > ( 1 , 2 ) ,
160+ new Tuple < int , int > ( 4 , 5 ) ) ;
161+ Assert . IsNull ( result ) ;
162+ }
163+
164+ [ Test ]
165+ public void IntersectionOfSegments ( )
166+ {
167+ var result = FlatImage . IntersectionOfSegments ( new [ ]
168+ {
169+ new [ ] { new Tuple < int , int > ( 1 , 2 ) , new Tuple < int , int > ( 4 , 6 ) } ,
170+ new [ ] { new Tuple < int , int > ( 1 , 2 ) , new Tuple < int , int > ( 5 , 10 ) } ,
171+ } ) ;
172+
173+ Assert . AreEqual ( 2 , result . Count ) ;
174+ Assert . AreEqual ( new Tuple < int , int > ( 1 , 2 ) , result [ 0 ] ) ;
175+ Assert . AreEqual ( new Tuple < int , int > ( 5 , 6 ) , result [ 1 ] ) ;
176+ }
177+
136178 private static FlatImage LoadFlatImageFromResource ( string resourceName )
137179 {
138180 FlatImage flatImage ;
0 commit comments