import math


def _minmaxcoord(min_threshold, max_threshold, sp_res):
    """Gets min and max coordinates of a specific grid.

    Based on the frame of a global grid.

    Parameters
    ----------
    min_threshold : float
        Minimum value of coordinate
    max_threshold : float
        Maximum value of coordinate
    sp_res : float or int
        Spatial resolution or the grid

    Returns
    -------
    minval : float
        Updated minimum coordinate
    maxval : float
        Updated maximum coordinate
    """

    res = float(sp_res)

    minval = int(math.ceil(min_threshold / res)) * res
    maxval = int(math.floor(max_threshold / res)) * res

    if minval != maxval:
        if minval - (res / 2) < min_threshold:
            minval += res / 2
        else:
            minval -= res / 2

        if maxval + (res / 2) > max_threshold:
            maxval -= res / 2
        else:
            maxval += res / 2

    return minval, maxval