@@ -169,22 +169,24 @@ mod tests {
169169 use super :: * ;
170170
171171 use crate :: {
172- composition:: InnerLayer ,
172+ composition:: Composition ,
173173 consts:: cpu:: { TILE_HEIGHT , TILE_WIDTH } ,
174174 math:: Point ,
175175 segment:: { GeomId , SegmentBuffer } ,
176176 utils:: Order ,
177177 } ;
178178
179179 fn segments ( p0 : Point , p1 : Point ) -> Vec < PixelSegment < TILE_WIDTH , TILE_HEIGHT > > {
180- let mut builder = SegmentBuffer :: default ( ) ;
181- builder. push ( GeomId :: default ( ) , [ p0, p1] ) ;
182- let lines = builder. fill_cpu_view ( |_| {
183- Some ( InnerLayer {
184- order : Some ( Order :: new ( 0 ) . unwrap ( ) ) ,
185- ..Default :: default ( )
186- } )
187- } ) ;
180+ let mut segment_buffer = SegmentBuffer :: default ( ) ;
181+ let mut composition = Composition :: new ( ) ;
182+
183+ composition. get_mut_or_insert_default ( Order :: new ( 0 ) . unwrap ( ) ) ;
184+
185+ segment_buffer. push ( GeomId :: default ( ) , [ p0, p1] ) ;
186+
187+ let ( layers, geom_id_to_order) = composition. layers_for_segments ( ) ;
188+
189+ let lines = segment_buffer. fill_cpu_view ( usize:: MAX , usize:: MAX , layers, & geom_id_to_order) ;
188190
189191 let mut rasterizer = Rasterizer :: default ( ) ;
190192 rasterizer. rasterize ( & lines) ;
@@ -296,7 +298,7 @@ mod tests {
296298 #[ test]
297299 fn area_cover_octant_5 ( ) {
298300 assert_eq ! (
299- areas_and_covers( & segments( Point :: new( 0 .0, 0 .0) , Point :: new( - 3 .0, - 2 .0) ) ) ,
301+ areas_and_covers( & segments( Point :: new( 3 .0, 2 .0) , Point :: new( 0 .0, 0 .0) ) ) ,
300302 [
301303 ( -( 11 * 16 ) , -11 ) ,
302304 ( -( 5 * 8 ) , -5 ) ,
@@ -309,7 +311,7 @@ mod tests {
309311 #[ test]
310312 fn area_cover_octant_6 ( ) {
311313 assert_eq ! (
312- areas_and_covers( & segments( Point :: new( 0 .0, 0 .0) , Point :: new( - 2 .0, - 3 .0) ) ) ,
314+ areas_and_covers( & segments( Point :: new( 2 .0, 3 .0) , Point :: new( 0 .0, 0 .0) ) ) ,
313315 [
314316 ( -( 16 * 11 ) , -16 ) ,
315317 ( -( 8 * 5 + 2 * ( 8 * 11 ) ) , -8 ) ,
@@ -322,7 +324,7 @@ mod tests {
322324 #[ test]
323325 fn area_cover_octant_7 ( ) {
324326 assert_eq ! (
325- areas_and_covers( & segments( Point :: new( 0.0 , 0 .0) , Point :: new( 2.0 , - 3 .0) ) ) ,
327+ areas_and_covers( & segments( Point :: new( 0.0 , 3 .0) , Point :: new( 2.0 , 0 .0) ) ) ,
326328 [
327329 ( -( 16 * 11 + 2 * ( 16 * 5 ) ) , -16 ) ,
328330 ( -( 8 * 5 ) , -8 ) ,
@@ -335,7 +337,7 @@ mod tests {
335337 #[ test]
336338 fn area_cover_octant_8 ( ) {
337339 assert_eq ! (
338- areas_and_covers( & segments( Point :: new( 0.0 , 0 .0) , Point :: new( 3.0 , - 2 .0) ) ) ,
340+ areas_and_covers( & segments( Point :: new( 0.0 , 2 .0) , Point :: new( 3.0 , 0 .0) ) ) ,
339341 [
340342 ( -( 11 * 16 ) , -11 ) ,
341343 ( -( 5 * 8 + 2 * ( 5 * 8 ) ) , -5 ) ,
@@ -388,23 +390,23 @@ mod tests {
388390 #[ test]
389391 fn area_cover_axis_225 ( ) {
390392 assert_eq ! (
391- areas_and_covers( & segments( Point :: new( 0 .0, 0 .0) , Point :: new( - 1 .0, - 1 .0) ) ) ,
393+ areas_and_covers( & segments( Point :: new( 1 .0, 1 .0) , Point :: new( 0 .0, 0 .0) ) ) ,
392394 [ ( -( 16 * 16 ) , -16 ) ] ,
393395 ) ;
394396 }
395397
396398 #[ test]
397399 fn area_cover_axis_270 ( ) {
398400 assert_eq ! (
399- areas_and_covers( & segments( Point :: new( 0.0 , 0 .0) , Point :: new( 0.0 , - 1 .0) ) ) ,
401+ areas_and_covers( & segments( Point :: new( 0.0 , 1 .0) , Point :: new( 0.0 , 0 .0) ) ) ,
400402 [ ( 2 * -( 16 * 16 ) , -16 ) ] ,
401403 ) ;
402404 }
403405
404406 #[ test]
405407 fn area_cover_axis_315 ( ) {
406408 assert_eq ! (
407- areas_and_covers( & segments( Point :: new( 0.0 , 0 .0) , Point :: new( - 1.0 , - 1 .0) ) ) ,
409+ areas_and_covers( & segments( Point :: new( 0.0 , 1 .0) , Point :: new( 1.0 , 0 .0) ) ) ,
408410 [ ( -( 16 * 16 ) , -16 ) ] ,
409411 ) ;
410412 }
@@ -481,14 +483,14 @@ mod tests {
481483 fn tile_octant_5 ( ) {
482484 assert_eq ! (
483485 tiles( & segments(
484- Point :: new( -( TILE_WIDTH as f32 ) , - ( TILE_HEIGHT as f32 ) ) ,
485- Point :: new( -( TILE_WIDTH as f32 ) - 3.0 , - ( TILE_HEIGHT as f32 ) - 2.0 ) ,
486+ Point :: new( -( TILE_WIDTH as f32 ) , TILE_HEIGHT as f32 ) ,
487+ Point :: new( -( TILE_WIDTH as f32 ) - 3.0 , TILE_HEIGHT as f32 - 2.0 ) ,
486488 ) ) ,
487489 [
488- ( -1 , - 1 , TILE_WIDTH as u8 - 1 , TILE_HEIGHT as u8 - 1 ) ,
489- ( -1 , - 1 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 1 ) ,
490- ( -1 , - 1 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 2 ) ,
491- ( -1 , - 1 , TILE_WIDTH as u8 - 3 , TILE_HEIGHT as u8 - 2 ) ,
490+ ( -1 , 0 , TILE_WIDTH as u8 - 1 , TILE_HEIGHT as u8 - 1 ) ,
491+ ( -1 , 0 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 1 ) ,
492+ ( -1 , 0 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 2 ) ,
493+ ( -1 , 0 , TILE_WIDTH as u8 - 3 , TILE_HEIGHT as u8 - 2 ) ,
492494 ] ,
493495 ) ;
494496 }
@@ -497,14 +499,14 @@ mod tests {
497499 fn tile_octant_6 ( ) {
498500 assert_eq ! (
499501 tiles( & segments(
500- Point :: new( -( TILE_WIDTH as f32 ) , - ( TILE_HEIGHT as f32 ) ) ,
501- Point :: new( -( TILE_WIDTH as f32 ) - 2.0 , - ( TILE_HEIGHT as f32 ) - 3.0 ) ,
502+ Point :: new( -( TILE_WIDTH as f32 ) , TILE_HEIGHT as f32 ) ,
503+ Point :: new( -( TILE_WIDTH as f32 ) - 2.0 , TILE_HEIGHT as f32 - 3.0 ) ,
502504 ) ) ,
503505 [
504- ( -1 , - 1 , TILE_WIDTH as u8 - 1 , TILE_HEIGHT as u8 - 1 ) ,
505- ( -1 , - 1 , TILE_WIDTH as u8 - 1 , TILE_HEIGHT as u8 - 2 ) ,
506- ( -1 , - 1 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 2 ) ,
507- ( -1 , - 1 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 3 ) ,
506+ ( -1 , 0 , TILE_WIDTH as u8 - 1 , TILE_HEIGHT as u8 - 1 ) ,
507+ ( -1 , 0 , TILE_WIDTH as u8 - 1 , TILE_HEIGHT as u8 - 2 ) ,
508+ ( -1 , 0 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 2 ) ,
509+ ( -1 , 0 , TILE_WIDTH as u8 - 2 , TILE_HEIGHT as u8 - 3 ) ,
508510 ] ,
509511 ) ;
510512 }
@@ -513,14 +515,14 @@ mod tests {
513515 fn tile_octant_7 ( ) {
514516 assert_eq ! (
515517 tiles( & segments(
516- Point :: new( TILE_WIDTH as f32 , - ( TILE_HEIGHT as f32 ) ) ,
517- Point :: new( TILE_WIDTH as f32 + 2.0 , - ( TILE_HEIGHT as f32 ) - 3.0 ) ,
518+ Point :: new( TILE_WIDTH as f32 , TILE_HEIGHT as f32 ) ,
519+ Point :: new( TILE_WIDTH as f32 + 2.0 , ( TILE_HEIGHT as f32 ) - 3.0 ) ,
518520 ) ) ,
519521 [
520- ( 1 , - 1 , 0 , TILE_HEIGHT as u8 - 1 ) ,
521- ( 1 , - 1 , 0 , TILE_HEIGHT as u8 - 2 ) ,
522- ( 1 , - 1 , 1 , TILE_HEIGHT as u8 - 2 ) ,
523- ( 1 , - 1 , 1 , TILE_HEIGHT as u8 - 3 ) ,
522+ ( 1 , 0 , 0 , TILE_HEIGHT as u8 - 1 ) ,
523+ ( 1 , 0 , 0 , TILE_HEIGHT as u8 - 2 ) ,
524+ ( 1 , 0 , 1 , TILE_HEIGHT as u8 - 2 ) ,
525+ ( 1 , 0 , 1 , TILE_HEIGHT as u8 - 3 ) ,
524526 ] ,
525527 ) ;
526528 }
@@ -529,14 +531,14 @@ mod tests {
529531 fn tile_octant_8 ( ) {
530532 assert_eq ! (
531533 tiles( & segments(
532- Point :: new( TILE_WIDTH as f32 , - ( TILE_HEIGHT as f32 ) ) ,
533- Point :: new( TILE_WIDTH as f32 + 3.0 , - ( TILE_HEIGHT as f32 ) - 2.0 ) ,
534+ Point :: new( TILE_WIDTH as f32 , TILE_HEIGHT as f32 ) ,
535+ Point :: new( TILE_WIDTH as f32 + 3.0 , ( TILE_HEIGHT as f32 ) - 2.0 ) ,
534536 ) ) ,
535537 [
536- ( 1 , - 1 , 0 , TILE_HEIGHT as u8 - 1 ) ,
537- ( 1 , - 1 , 1 , TILE_HEIGHT as u8 - 1 ) ,
538- ( 1 , - 1 , 1 , TILE_HEIGHT as u8 - 2 ) ,
539- ( 1 , - 1 , 2 , TILE_HEIGHT as u8 - 2 ) ,
538+ ( 1 , 0 , 0 , TILE_HEIGHT as u8 - 1 ) ,
539+ ( 1 , 0 , 1 , TILE_HEIGHT as u8 - 1 ) ,
540+ ( 1 , 0 , 1 , TILE_HEIGHT as u8 - 2 ) ,
541+ ( 1 , 0 , 2 , TILE_HEIGHT as u8 - 2 ) ,
540542 ] ,
541543 ) ;
542544 }
0 commit comments