def stable_against(
    state: state_def.State,
    obj_name: str,
    relation_state: state_def.RelationState,
    visualize=False,
    allow_overhangs=False,
):
    """
    check paralell, close to, and not overhanging.
    """

    relation = relation_state.relation
    assert isinstance(relation, cl.StableAgainst)

    logger.debug(f"stable against {obj_name=} {relation_state=} {relation.rev_normal=}")
    a_blender_obj = state.objs[obj_name].obj
    b_blender_obj = state.objs[relation_state.target_name].obj
    sa = state.objs[obj_name]
    sb = state.objs[relation_state.target_name]

    pa, pb = state.planes.get_rel_state_planes(state, obj_name, relation_state)

    poly_a = state.planes.planerep_to_poly(pa)
    poly_b = state.planes.planerep_to_poly(pb)

    normal_a = butil.global_polygon_normal(a_blender_obj, poly_a)
    normal_b = butil.global_polygon_normal(
        b_blender_obj, poly_b, rev_normal=relation.rev_normal
    )
    dot = np.array(normal_a).dot(normal_b)
    if not (np.isclose(np.abs(dot), 1, atol=1e-2) or np.isclose(dot, -1, atol=1e-2)):
        logger.debug(f"stable against failed, not parallel {dot=}")
        return False

    origin_b = butil.global_vertex_coordinates(
        b_blender_obj, b_blender_obj.data.vertices[poly_b.vertices[0]]
    )

    scene = state.trimesh_scene
    a_trimesh = iu.meshes_from_names(scene, sa.obj.name)[0]
    b_trimesh = iu.meshes_from_names(scene, sb.obj.name)[0]

    mask = tagging.tagged_face_mask(sb.obj, relation.parent_tags)
    mask = state.planes.tagged_plane_mask(sb.obj, mask, pb)
    assert mask.any()
    b_trimesh_mask = b_trimesh.submesh([np.where(mask)[0]], append=True)

    # Project mesh A onto the plane of mesh B
    projected_a = trimesh.path.polygons.projected(a_trimesh, normal_b, origin_b)
    projected_b = trimesh.path.polygons.projected(b_trimesh_mask, normal_b, origin_b)
    logger.debug(
        f"stable_against projecting along {normal_b} for parent_tags {relation.parent_tags}"
    )

    if projected_a is None or projected_b is None:
        raise ValueError(f"Invalid {projected_a=} {projected_b=}")

    if allow_overhangs:
        res = projected_a.overlaps(projected_b)
    elif relation.check_z:
        res = projected_a.within(projected_b.buffer(1e-2))
    else:
        z_proj = project_vector(np.array([0, 0, 1]), origin_b, normal_b)
        projected_a_rotated, projected_b_rotated = project_and_align_z_with_x(
            [projected_a, projected_b], z_proj
        )
        res = is_vertically_contained(projected_a_rotated, projected_b_rotated)

    if visualize:
        fig, ax = plt.subplots()
        iu.plot_geometry(ax, projected_a, "blue")
        iu.plot_geometry(ax, projected_b, "green")
        plt.title(f"{obj_name} stable against {relation_state.target_name}? {res=}")
        plt.show()

    logger.debug(f"stable_against {res=}")
    if not res:
        return False

    for vertex in poly_a.vertices:
        vertex_global = butil.global_vertex_coordinates(
            a_blender_obj, a_blender_obj.data.vertices[vertex]
        )
        distance = iu.distance_to_plane(vertex_global, origin_b, normal_b)
        if not np.isclose(distance, relation_state.relation.margin, atol=1e-2):
            logger.debug(f"stable against failed, not close to {distance=}")
            return False

    return True

    check paralell, close to, and not overhanging.
    
infinigen/core/constraints/example_solver/geometry/stability.py