/// <summary>
    /// Returns if a UI object is inside the visible area or not by checking if the rect is inside the canvas rect, the algorithm is very optimized. World space canvases not supported.
    /// </summary>
    /// <param name="canvas">A reference to the canvas is needed, getting the reference is a expensive operation so if you set null here the operation is made inside this method each time you call it, otherwise you can get the reference once and pass it here to improve performance.</param>
    public static bool IsVisible(this RectTransform tr, Canvas canvas = null)
    {
        if (canvas == null)
        {
            canvas = tr.GetCanvas().GetComponent <Canvas>();
        }

        RteRectTools.GetRectCornersInScreenSpacePixels(tr, canvas, Corners);

        float maxY = Mathf.Max(Corners[0].y, Corners[1].y, Corners[2].y, Corners[3].y);
        float minY = Mathf.Min(Corners[0].y, Corners[1].y, Corners[2].y, Corners[3].y);
        float maxX = Mathf.Max(Corners[0].x, Corners[1].x, Corners[2].x, Corners[3].x);
        float minX = Mathf.Min(Corners[0].x, Corners[1].x, Corners[2].x, Corners[3].x);

        return(!(
                   maxY.IsAproximatelyOrLess(0) ||
                   minY.IsAproximatelyOrMore(Screen.height) ||
                   maxX.IsAproximatelyOrLess(0) ||
                   minX.IsAproximatelyOrMore(Screen.width)
                   ));
    }