def coplanarity_cost_pair(scene, a: str, b: str):
    """
    Computes the coplanarity cost between a and b
    """
    a_trimesh = iu.meshes_from_names(scene, a)[0]
    b_trimesh = iu.meshes_from_names(scene, b)[0]

    iu.blender_objs_from_names(a)[0]
    iu.blender_objs_from_names(b)[0]

    a_trimesh_bbox = a_trimesh.bounding_box_oriented
    b_trimesh_bbox = b_trimesh.bounding_box_oriented

    object1_planes = []
    object2_planes = []

    # Helper function to check if a normal is close to any in the list
    def is_normal_new(normal, normals_list):
        normals_np = np.array(normals_list)
        if len(normals_list) > 0:
            return not np.any(np.all(np.isclose(normals_np, normal, atol=1e-3), axis=1))
        return True

    for i in range(len(a_trimesh_bbox.faces)):
        normal = a_trimesh_bbox.face_normals[i]
        if is_normal_new(normal, [n for _, n in object1_planes]):
            object1_planes.append(
                (a_trimesh_bbox.vertices[a_trimesh_bbox.faces[i]][0], normal)
            )

    for i in range(len(b_trimesh_bbox.faces)):
        normal = b_trimesh_bbox.face_normals[i]
        if is_normal_new(normal, [n for _, n in object2_planes]):
            object2_planes.append(
                (b_trimesh_bbox.vertices[b_trimesh_bbox.faces[i]][0], normal)
            )

    # Calculate angle cost matrix for bipartite matching
    angle_cost_matrix = np.zeros((len(object1_planes), len(object2_planes)))
    for j, plane1 in enumerate(object1_planes):
        for k, plane2 in enumerate(object2_planes):
            angle_cost = 1 - np.dot(plane1[1], plane2[1])
            angle_cost_matrix[j, k] = angle_cost

    # Perform linear sum assignment based on angle alignment
    row_ind, col_ind = linear_sum_assignment(angle_cost_matrix)

    # Calculate total costs (angle + distance) for the optimal matching
    total_costs = []
    for r, c in zip(row_ind, col_ind):
        distance_cost = iu.distance_to_plane(
            object1_planes[r][0], object2_planes[c][0], object2_planes[c][1]
        )
        total_cost = (
            angle_cost_matrix[r, c] + distance_cost
        )  # Sum angle and distance costs
        total_costs.append(total_cost)
    total_costs = sorted(total_costs)

    return sum(total_costs[:-2])

    Computes the coplanarity cost between a and b
    
infinigen/core/constraints/evaluator/node_impl/trimesh_geometry.py