limit position to layer boundaries