import math


def pts2bins(pts, prec=0.25):
    """
    :param pts: List of 2d points
    :param prec: Width of each bin
    :return: A dictionary of bin centers and points in the bin
    """
    # for pt in pts:
        # def val2bin_int(val):
        #     return math.ceil(val / prec) if val > 0 else math.floor(pt[1] / prec)
        # f =
        # loc = math.floor(pt[0] / prec), math.floor(pt[1] / prec)
        # ic(loc, pt)
    locs_pt = {tuple(pt.tolist()): (math.floor(pt[0] / prec), math.floor(pt[1] / prec)) for pt in pts}
    d_bin = dict()
    for pt, loc in locs_pt.items():
        # ic(pt, loc)
        if loc in d_bin:
            d_bin[loc].append(pt)
        else:
            d_bin[loc] = [pt]

    def unit2val(u):
        return (u+0.5)*prec
    return {(unit2val(k1), unit2val(k2)): v for (k1, k2), v in d_bin.items()}