FairyGUI.Utils.ToolSet.Intersection C# (CSharp) Method

Intersection() public static method

public static Intersection ( Rect &rect1, Rect &rect2 ) : Rect
rect1 UnityEngine.Rect
rect2 UnityEngine.Rect
return UnityEngine.Rect
        public static Rect Intersection(ref Rect rect1, ref Rect rect2)
        {
            if (rect1.width == 0 || rect1.height == 0 || rect2.width == 0 || rect2.height == 0)
                return new Rect(0, 0, 0, 0);

            float left = rect1.xMin > rect2.xMin ? rect1.xMin : rect2.xMin;
            float right = rect1.xMax < rect2.xMax ? rect1.xMax : rect2.xMax;
            float top = rect1.yMin > rect2.yMin ? rect1.yMin : rect2.yMin;
            float bottom = rect1.yMax < rect2.yMax ? rect1.yMax : rect2.yMax;

            if (left > right || top > bottom)
                return new Rect(0, 0, 0, 0);
            else
                return Rect.MinMaxRect(left, top, right, bottom);
        }

Usage Example

Example #1
0
        public void SetArea(Rect rect)
        {
            Rect contentRect = _owner.contentRect;

            rect = ToolSet.Intersection(ref contentRect, ref rect);
            if (rect.width == 0 || rect.height == 0)
            {
                shape.Clear();
            }
            else
            {
                shape.SetXY(rect.x, rect.y);
                shape.SetSize(rect.width, rect.height);
                shape.DrawRect(0, Color.clear, _owner.htmlParseOptions.linkBgColor);
            }
        }
All Usage Examples Of FairyGUI.Utils.ToolSet::Intersection