def find_nearest_index(vertices, x_from, y_from, vertice_count):
    """
    Find the index of the vertex that is the closest to specified 
    coordinate (x_from, y_from).
    """

    min_distance_squared  = 1000000
    nearest_index = 0

    x_from *= 1000
    y_from *= 1000

    for index, vertice in enumerate(vertices):
        dx = (vertice[0] * 1000) - x_from
        dy = (vertice[1] * 1000) - y_from
        square_dist = dx*dx + dy*dy
        
        if square_dist < min_distance_squared and index < vertice_count:
            nearest_index = index
            min_distance_squared = square_dist

    return nearest_index