11use snk_grid:: {
2+ color:: Color ,
23 direction:: iter_neighbour,
3- grid:: { Color , Grid , iter_rectangle_hull} ,
4+ grid:: { Grid , iter_rectangle_hull} ,
45 point:: Point ,
56} ;
6- use std:: { collections:: HashSet , usize } ;
7+ use std:: collections:: HashSet ;
78
89pub fn update_cost_to_outside (
9- cost_to_outside : & mut Grid < usize > ,
10+ cost_to_outside : & mut Grid < u32 > ,
1011 grid : & Grid < Color > ,
1112 mut changed : HashSet < Point > ,
1213) -> ( ) {
@@ -21,7 +22,8 @@ pub fn update_cost_to_outside(
2122 // propagate the change to its neightbourn
2223 for pn in iter_neighbour ( p) {
2324 if cost_to_outside. is_inside ( pn) {
24- let new_cost = c + ( grid. get ( pn) as usize ) * 100 ;
25+ let cost = grid. get ( pn) . cost ( ) ;
26+ let new_cost = c + cost;
2527 if new_cost < cost_to_outside. get ( pn) {
2628 cost_to_outside. set ( pn, new_cost) ;
2729 changed. insert ( pn) ;
@@ -33,13 +35,13 @@ pub fn update_cost_to_outside(
3335
3436//
3537// cost_to_outside : for each cell return the minimal cost ( = sum of dot, with greater color costing more ) to get outside
36- pub fn create_cost_to_outside ( grid : & Grid < Color > ) -> Grid < usize > {
37- let mut cost_to_outside = Grid :: < usize > :: create_with_value ( grid. width , grid. height , usize :: MAX ) ;
38+ pub fn create_cost_to_outside ( grid : & Grid < Color > ) -> Grid < u32 > {
39+ let mut cost_to_outside = Grid :: < u32 > :: create_with_value ( grid. width , grid. height , u32 :: MAX ) ;
3840
3941 let mut changed = HashSet :: < Point > :: new ( ) ;
4042
4143 for p in iter_rectangle_hull ( grid. width as i8 , grid. height as i8 ) {
42- let cost = ( grid. get ( p) as usize ) * 100 ;
44+ let cost = grid. get ( p) . cost ( ) ;
4345 cost_to_outside. set ( p, cost) ;
4446 changed. insert ( p) ;
4547 }
0 commit comments