예제 #1
0
파일: RectangleF.cs 프로젝트: vogon/Zeplin
        /// <summary>
        /// Determines if two rectangles are intersecting.
        /// </summary>
        /// <param name="otherRectangle"></param>
        /// <returns></returns>
        public bool Intersects(RectangleF otherRectangle)
        {
            if ((Left > otherRectangle.Right) || (Right < otherRectangle.Left) || (Top > otherRectangle.Bottom) || (Bottom < otherRectangle.Top))
                return false;

            else return true;
        }
예제 #2
0
파일: RectangleF.cs 프로젝트: vogon/Zeplin
        /// <summary>
        /// Returns the overlapping area of two rectangles, if any.
        /// </summary>
        /// <param name="otherRectangle">The rectangle to compute against.</param>
        /// <returns>The overlapping area.</returns>
        public RectangleF Intersect(RectangleF otherRectangle)
        {
            if (Intersects(otherRectangle))
            {
                Vector2 resultTopLeftCorner = new Vector2(Math.Max(Left, otherRectangle.Left), Math.Max(Top, otherRectangle.Top));
                Vector2 resultBottomRightCorner = new Vector2(Math.Min(Right, otherRectangle.Right), Math.Min(Bottom, otherRectangle.Bottom));

                Vector2 resultDimensions = resultBottomRightCorner - resultTopLeftCorner;

                return new RectangleF(resultTopLeftCorner, resultDimensions);
            }

            return new RectangleF();
        }