Ejemplo n.º 1
0
        /// <summary>
        /// Returns the Rectangle that is the intersection of this rectangle with another. Returns null if there is no intersection
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public Rectd Intersect(Rectd rect)
        {
            double x1 = X + Width;
            double x2 = rect.X + rect.Width;
            double y1 = Y + Height;
            double y2 = rect.Y + rect.Height;

            double xL = Math.Max(X, rect.X);
            double xR = Math.Min(x1, x2);

            if (xR <= xL)
            {
                return(null);
            }
            else
            {
                double yB = Math.Min(y1, y2);
                double yT = Math.Max(Y, rect.Y);
                if (yB <= yT)
                {
                    return(null);
                }
                else
                {
                    return(new Rectd(xL, yT, xR - xL, yB - yT));
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns the Rectangle that is the intersection of this rectangle with another. Returns null if there is no intersection
        /// </summary>
        /// <param name="rect"></param>
        /// <returns></returns>
        public Recti Intersect(Rectd rect)
        {
            int x1 = X + Width;
            int x2 = (int)Math.Round(rect.X + rect.Width);
            int y1 = Y - Height;
            int y2 = (int)Math.Round(rect.Y - Height);

            int xL = (int)Math.Round(Math.Max(X, rect.X));
            int xR = Math.Min(x1, x2);

            if (xR <= xL)
            {
                return(null);
            }
            else
            {
                int yT = (int)Math.Max(Y, rect.Y);
                int yB = (int)Math.Round((double)Math.Min(y1, y2));
                if (yB <= yT)
                {
                    return(null);
                }
                else
                {
                    return(new Recti(xL, yT, xR - xL, yB - yT));
                }
            }
        }