Sharpex2D.Math.Rectangle.Intersect C# (CSharp) Méthode

Intersect() public méthode

Intersects the specified rectangle.
public Intersect ( Rectangle rectangle ) : Rectangle
rectangle Rectangle The rectangle.
Résultat Rectangle
        public Rectangle Intersect(Rectangle rectangle)
        {
            if (!Intersects(rectangle))
            {
                return Empty;
            }

            float[] horizontal = {Left, Right, rectangle.Left, rectangle.Right};
            float[] vertical = {Bottom, Top, rectangle.Bottom, rectangle.Top};

            Array.Sort(horizontal);
            Array.Sort(vertical);

            float left = horizontal[1];
            float bottom = vertical[1];
            float right = horizontal[2];
            float top = vertical[2];

            return new Rectangle(left, top, right - left, bottom - top);
        }