let
distance_to_boundary i = min i (length - i)