Check if UI element is fully inside another UI element

Hey everyone, I’m doing a gridless inventory system, where you can freely move around items inside a container. The problem I’m facing is checking if an item (image) is completely inside the container (another image). How would I do this? I’ve tried getting each corner of the item image and then using the Contains function to check if the corners are inside the container, but for some reason that didn’t work. Here’s a snippet of the code that I’ve used to attempt to achieve this:

for (int c = 0; c < invContainers.Count; c++)
        {
            if (RectTransformUtility.RectangleContainsScreenPoint(invContainers
.obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>(), Input.mousePosition))
                {
                    Vector3[] corners = new Vector3[4];
                    obj.transform.GetChild(1).gameObject.GetComponent<RectTransform().GetLocalCorners(corners);
    
    
                    if (invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>().rect.Contains(corners[0])
                    && invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>().rect.Contains(corners[1])
                    && invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>().rect.Contains(corners[2])
                    && invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>().rect.Contains(corners[3]))
                    {
                        Debug.Log("Can drop the item in ID " + c);
                        obj.transform.SetParent(invContainers[c].obj.transform.GetChild(2));
                        obj.GetComponent<RectTransform>().localScale = Vector2.one;
                        obj.GetComponent<RectTransform>().position = tempCoords;
                    }
                    else
                    {
                        Debug.Log("Can't drop here");
                    }
                }
            }


Using this code, I seem to pass through this check even if only 1 corner is inside the container (it's almost like it ignores the corner check). If anyone has any suggestions or a solution, please share them with me, I will greatly appreciate them. Thank you in advance.

EDIT:
Fixed by using RectangleContainsScreenPoint instead of rect.Contains. Here's the working code below:

    for (int c = 0; c < invContainers.Count; c++)
            {
                if (RectTransformUtility.RectangleContainsScreenPoint(invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>(), Input.mousePosition))
                {
                    Vector3[] corners = new Vector3[4];
                    obj.transform.GetChild(1).gameObject.GetComponent<RectTransform>().GetWorldCorners(corners);
    
                    if (RectTransformUtility.RectangleContainsScreenPoint(invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>(), corners[0])
                        && RectTransformUtility.RectangleContainsScreenPoint(invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>(), corners[1])
                        && RectTransformUtility.RectangleContainsScreenPoint(invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>(), corners[2])
                        && RectTransformUtility.RectangleContainsScreenPoint(invContainers[c].obj.transform.GetChild(2).gameObject.GetComponent<RectTransform>(), corners[3]))
                    {
    
                            Debug.Log("Can drop the item in ID " + c);
                            obj.transform.SetParent(invContainers[c].obj.transform.GetChild(2));
                            invContainers[c].items.Add(obj.GetComponent<InventoryItem>().item);
                            obj.GetComponent<RectTransform>().localScale = Vector2.one;
                            obj.GetComponent<RectTransform>().position = tempCoords;
                            obj.GetComponent<InventoryItem>().containerID = c;
                            calculateWeight();
                            UpdateContainers();
    
                    }
                    else
                    {
                        Debug.Log("Can't drop here");
                        obj.GetComponent<InventoryItem>().ResetPos();
                    }
                }
            }

public static bool RectContainsAnother (RectTransform rct, RectTransform another)
{
var r = rct.GetWorldRect();
var a = another.GetWorldRect();
return r.xMin <= a.xMin && r.yMin <= a.yMin && r.xMax >= a.xMax && r.yMax >= a.yMax;
}