Exemplo n.º 1
0
        public void GetIntersection(Rectangular first, Rectangular second)
        {
            LeftTop     = new Point();
            LeftBottom  = new Point();
            RightTop    = new Point();
            RightBottom = new Point();

            if (first.RightBottom.X >= second.LeftBottom.X)
            {
                RightBottom.X = first.RightBottom.X;
                RightTop.X    = first.RightBottom.X;
                LeftBottom.X  = second.LeftBottom.X;
                LeftTop.X     = second.LeftBottom.X;
                if (first.LeftBottom.Y >= second.LeftTop.Y)
                {
                    RightBottom.Y = first.LeftBottom.Y;
                    RightTop.Y    = second.LeftTop.Y;
                    LeftBottom.Y  = first.LeftBottom.Y;
                    LeftTop.Y     = second.LeftTop.Y;
                }
                else if (first.LeftTop.Y <= second.LeftBottom.Y)
                {
                    RightBottom.Y = second.LeftBottom.Y;
                    RightTop.Y    = first.LeftTop.Y;
                    LeftBottom.Y  = second.LeftBottom.Y;
                    LeftTop.Y     = first.LeftTop.Y;
                }
            }
            else if (first.LeftBottom.X <= second.RightBottom.X)
            {
                RightBottom.X = second.RightBottom.X;
                RightTop.X    = second.RightBottom.X;
                LeftBottom.X  = first.LeftBottom.X;
                LeftTop.X     = first.LeftBottom.X;
                if (first.LeftBottom.Y >= second.LeftTop.Y)
                {
                    RightBottom.Y = first.LeftBottom.Y;
                    RightTop.Y    = second.LeftTop.Y;
                    LeftBottom.Y  = first.LeftBottom.Y;
                    LeftTop.Y     = second.LeftTop.Y;
                }
                else if (first.LeftTop.Y >= second.LeftBottom.Y)
                {
                    RightBottom.Y = second.LeftBottom.Y;
                    RightTop.Y    = first.LeftTop.Y;
                    LeftBottom.Y  = second.LeftBottom.Y;
                    LeftTop.Y     = first.LeftTop.Y;
                }
            }
        }
Exemplo n.º 2
0
        public void GetUnion(Rectangular first, Rectangular second)
        {
            LeftTop     = new Point();
            LeftBottom  = new Point();
            RightTop    = new Point();
            RightBottom = new Point();

            LeftTop.X    = Math.Min(first.LeftTop.X, second.LeftTop.X);
            LeftBottom.X = Math.Min(first.LeftTop.X, second.LeftTop.X);

            RightTop.X    = Math.Max(first.RightTop.X, second.RightTop.X);
            RightBottom.X = Math.Max(first.RightTop.X, second.RightTop.X);

            LeftTop.Y  = Math.Min(first.LeftTop.Y, second.LeftTop.Y);
            RightTop.Y = Math.Min(first.LeftTop.Y, second.LeftTop.Y);

            LeftBottom.Y  = Math.Max(first.RightBottom.Y, second.RightBottom.Y);
            RightBottom.Y = Math.Max(first.RightBottom.Y, second.RightBottom.Y);
        }