in utils/box_intersection.pyx [0:0]
def box_intersection(float [:, :, :, :] rect1,
float [:, :, :, :] rect2,
float [:, :, :] non_rot_inter_areas,
int[:] nums_k2,
float [:, :, :] inter_areas,
bint approximate):
"""
rect1 - B x K1 x 8 x 3 matrix of box corners
rect2 - B x K2 x 8 x 3 matrix of box corners
non_rot_inter_areas - intersection areas of boxes
"""
cdef Py_ssize_t B = rect1.shape[0]
cdef Py_ssize_t K1 = rect1.shape[1]
cdef Py_ssize_t K2 = rect2.shape[2]
for b in range(B):
for k1 in range(K1):
for k2 in range(K2):
if k2 >= nums_k2[b]:
break
if approximate and non_rot_inter_areas[b][k1][k2] == 0:
continue
##### compute volume of intersection
inter = polygon_clip_unnest(rect1[b, k1], rect2[b, k2])
ninter = len(inter)
if ninter > 0: # there is some intersection between the boxes
xs = np.array([x[0] for x in inter]).astype(dtype=FLOAT)
ys = np.array([x[1] for x in inter]).astype(dtype=FLOAT)
inter_areas[b,k1,k2] = 0.5 * np.abs(np.dot(xs,np.roll(ys,1))-np.dot(ys,np.roll(xs,1)))