let distance_to_boundary width height = let of_1d = of_1d width height in let maxx, maxy = width-1, height-1 in fun index -> let x,y = of_1d index in min (min x (maxx - x)) (min y (maxy - y))