def calculate_positions(patched_img, adv_patch, truths,offset):
    """
    This function calculates a list of every possible (x,y) a patch could be placed on an image
    Params:
        patched_img --> A torch.tensor of an image
        adv_patch --> A torch.tensor of the adversarial patch
        truths --> A torch.tensor containing the bounding box coordinates for the detection
        offset --> The minimum distance between the bounding box and the edge of the patch (int)

    Returns:
        locations --> A list of every tuple (x,y) the patch can be placed (list)

    """

    #Gather measurements for ease
    img_height = patched_img.shape[1]
    img_width = patched_img.shape[2]
    patch_height = adv_patch.shape[1]
    patch_width = adv_patch.shape[2]


    #Convert bounding box coordinates to list of form (x1,y1,x2,y2) for the  bounding box
    object_bounding_box = truths.int().cpu().numpy().tolist()

    locations = []

    #This block adds all locations to the sides of the bounding box to the list locations
    vertical_y= range(0,img_height-patch_height)
    left = set(range(max((object_bounding_box[0]-patch_width-offset),0),(object_bounding_box[0]-patch_width)))
    right = set(range(object_bounding_box[2],min((img_width-patch_width,object_bounding_box[2]+offset))))
    allowableX = left.union(right)
    for y in vertical_y:
        for x in allowableX:
            locations.append((x,y))

    # This block adds all locations above and below the bounding box to the list locations
    horizontal_x = range(0,img_width-patch_width)
    top = set(range(max((object_bounding_box[1]-patch_height-offset),0),(object_bounding_box[1]-patch_height)))
    bottom = set(range(object_bounding_box[3],min((img_height-patch_height,object_bounding_box[3]+offset))))
    allowableY = top.union(bottom)
    for x in horizontal_x:
        for y in allowableY:
            locations.append((x,y))

    #return the list of possible locations for the patch
    return(locations)