Use indices in testing whether on a boundary

This is done to avoid using the upper and lower coordinate extents
in this check as floats equality comparison is not safe.