import math


def find_anchor_index(dataset_name, y, x):
    """
    Given y and x coordinate of the center of an anchor box,
    find the index for that anchor
    :param dataset_name:
    :param y:
    :param x:
    :return:
    """
    if dataset_name == 'KittiDataset':
        H_grid = 248
        W_grid = 1296
        H_step = 80 / H_grid
        W_step = 69.12 / W_grid
        row_id = math.floor(y / H_step)
        col_id = math.floor(x / W_step)
        anchor_id = row_id * W_grid + col_id
        return anchor_id
    elif dataset_name == 'CadcDataset':
        H_grid = 200
        W_grid = 1200
        H_step = 100 / H_grid
        W_step = 100 / W_grid
        row_id = math.floor(y / H_step)
        col_id = math.floor(x / W_step)
        anchor_id = row_id * W_grid + col_id
        return anchor_id