in mujoco_worldgen/util/placement.py [0:0]
def _get_pairwise_constraints(xy, boxes, placement_margin):
a_pairwise = []
b_pairwise = []
violated = [0.0 for _ in range(len(boxes))]
sizes = [box["size"] for box in boxes]
for idx0, s0 in enumerate(sizes):
for idx1, s1 in enumerate(sizes):
if idx1 <= idx0:
continue
a_small = []
b_small = []
for axis in [0, 1]:
# x0 >= x1 + s1[0] or y0 >= y1 + s1[1]
a = np.zeros(2 * len(boxes))
a[idx0 + axis * len(boxes)] = 1.0
a[idx1 + axis * len(boxes)] = -1.0
a_small.append(a)
b_small.append(s1[axis] + placement_margin)
# x1 >= x0 + s0[0] or y1 >= y0 + s0[1]
a = np.zeros(2 * len(boxes))
a[idx0 + axis * len(boxes)] = -1.0
a[idx1 + axis * len(boxes)] = 1.0
a_small.append(a)
b_small.append(s0[axis] + placement_margin)
a_small = np.stack(a_small)
b_small = np.array(b_small)
ret = np.matmul(a_small, xy) - b_small
idx = np.argmax(ret)
a_pairwise.append(a_small[idx])
b_pairwise.append(b_small[idx])
if ret[idx] <= -1e-4:
violated[idx0] += ret[idx]
violated[idx1] += ret[idx]
return a_pairwise, b_pairwise, violated