def is_within_margin_from_plane(obj, obj_b, margin, tol=1e-6):
    """Check if all vertices of an object are within a given margin from a plane."""
    polygon_b = obj_b.data.polygons[0]
    plane_point_b = butil.global_vertex_coordinates(
        obj_b, obj_b.data.vertices[polygon_b.vertices[0]]
    )
    plane_normal_b = butil.global_polygon_normal(obj_b, polygon_b)
    for vertex in obj.data.vertices:
        global_vertex = butil.global_vertex_coordinates(obj, vertex)
        distance = distance_to_plane(global_vertex, plane_point_b, plane_normal_b)
        if not math.isclose(distance, margin, abs_tol=tol):
            return False
    return True
Check if all vertices of an object are within a given margin from a plane.
infinigen/core/constraints/evaluator/indoor_util.py