@@ -137,4 +137,113 @@ impl IntSlice for [IntPoint] {
137137 . map ( |graph| graph. extract_shapes ( StringRule :: Slice ) )
138138 . unwrap_or_default ( )
139139 }
140+ }
141+
142+ #[ cfg( test) ]
143+ mod tests {
144+ use alloc:: vec;
145+ use i_float:: int:: point:: IntPoint ;
146+ use crate :: core:: fill_rule:: FillRule ;
147+ use crate :: string:: slice:: IntSlice ;
148+
149+ #[ test]
150+ fn test_empty_input ( ) {
151+ #[ rustfmt:: skip]
152+ let shapes = [ ] . slice_by_line (
153+ [ IntPoint :: new ( 0 , 0 ) , IntPoint :: new ( 0 , 0 ) ] ,
154+ FillRule :: NonZero ,
155+ ) ;
156+
157+ assert_eq ! ( shapes. len( ) , 0 ) ;
158+ }
159+
160+ #[ test]
161+ fn test_0 ( ) {
162+ #[ rustfmt:: skip]
163+ let shapes = vec ! [
164+ IntPoint :: new( -2 , -2 ) ,
165+ IntPoint :: new( 2 , -2 ) ,
166+ IntPoint :: new( 2 , 2 ) ,
167+ IntPoint :: new( -2 , 2 ) ,
168+ ]
169+ . slice_by_line (
170+ [ IntPoint :: new ( -5 , 5 ) , IntPoint :: new ( 5 , -5 ) ] ,
171+ FillRule :: NonZero ,
172+ ) ;
173+
174+ assert_eq ! ( shapes. len( ) , 2 ) ;
175+ assert_eq ! ( shapes[ 0 ] [ 0 ] . len( ) , 3 ) ;
176+ assert_eq ! ( shapes[ 1 ] [ 0 ] . len( ) , 3 ) ;
177+ }
178+
179+ #[ test]
180+ fn test_1 ( ) {
181+ #[ rustfmt:: skip]
182+ let shapes = vec ! [
183+ IntPoint :: new( -2 , -2 ) ,
184+ IntPoint :: new( 2 , -2 ) ,
185+ IntPoint :: new( 2 , 2 ) ,
186+ IntPoint :: new( -2 , 2 ) ,
187+ ]
188+ . slice_by_line (
189+ [ IntPoint :: new ( -5 , 5 ) , IntPoint :: new ( 5 , 5 ) ] ,
190+ FillRule :: NonZero ,
191+ ) ;
192+
193+ assert_eq ! ( shapes. len( ) , 1 ) ;
194+ }
195+
196+ #[ test]
197+ fn test_2 ( ) {
198+ #[ rustfmt:: skip]
199+ let shapes = vec ! [
200+ IntPoint :: new( 0 , 0 ) ,
201+ IntPoint :: new( 2 , 0 ) ,
202+ IntPoint :: new( 2 , 3 ) ,
203+ IntPoint :: new( 1 , 1 ) ,
204+ IntPoint :: new( 0 , 3 ) ,
205+ ]
206+ . slice_by_line (
207+ [ IntPoint :: new ( -5 , 2 ) , IntPoint :: new ( 5 , 2 ) ] ,
208+ FillRule :: NonZero ,
209+ ) ;
210+
211+ assert_eq ! ( shapes. len( ) , 3 ) ;
212+ assert_eq ! ( shapes[ 0 ] [ 0 ] . len( ) , 5 ) ;
213+ assert_eq ! ( shapes[ 1 ] [ 0 ] . len( ) , 3 ) ;
214+ assert_eq ! ( shapes[ 2 ] [ 0 ] . len( ) , 3 ) ;
215+ }
216+
217+ #[ test]
218+ fn test_3 ( ) {
219+ #[ rustfmt:: skip]
220+ let shapes = vec ! [
221+ IntPoint :: new( -2 , -2 ) ,
222+ IntPoint :: new( 2 , -2 ) ,
223+ IntPoint :: new( 2 , 2 ) ,
224+ IntPoint :: new( -2 , 2 ) ,
225+ ]
226+ . slice_by_line (
227+ [ IntPoint :: new ( -2 , 5 ) , IntPoint :: new ( 2 , -5 ) ] ,
228+ FillRule :: NonZero ,
229+ ) ;
230+
231+ assert_eq ! ( shapes. len( ) , 1 ) ;
232+ }
233+
234+ #[ test]
235+ fn test_4 ( ) {
236+ #[ rustfmt:: skip]
237+ let shapes = vec ! [
238+ IntPoint :: new( -2 , 0 ) ,
239+ IntPoint :: new( 2 , 0 ) ,
240+ IntPoint :: new( 0 , 2 ) ,
241+ ]
242+ . slice_by_line (
243+ [ IntPoint :: new ( -5 , 2 ) , IntPoint :: new ( 5 , 2 ) ] ,
244+ FillRule :: NonZero ,
245+ ) ;
246+
247+ assert_eq ! ( shapes. len( ) , 1 ) ;
248+ }
140249}
0 commit comments