예제 #1
0
        public static Rectangle MovingRectangle(Rectangle rectangle, Coordinates coordsA, Coordinates coordsB)
        {
            rectangle.coordsA.x = coordsA.x;
            rectangle.coordsA.y = coordsA.y;
            rectangle.coordsB.x = coordsB.x;
            rectangle.coordsB.y = coordsB.y;

            return(rectangle);
        }
예제 #2
0
 public static double Height(Coordinates A, Coordinates B)
 {
     return(Math.Abs(A.y - B.y));
 }
예제 #3
0
 public Rectangle(Coordinates coordsA, Coordinates coordsB)
 {
     this.coordsA = coordsA;
     this.coordsB = coordsB;
 }
예제 #4
0
 public static double Width(Coordinates A, Coordinates B)
 {
     return(Math.Abs(A.x - B.x));
 }
예제 #5
0
        public static Rectangle CrossRectangles(Rectangle rect1, Rectangle rect2)
        {
            Coordinates B = new Coordinates(rect2.coordsB.x, rect2.coordsA.y);
            Coordinates C = new Coordinates(rect2.coordsA.x, rect2.coordsB.y);

            Rectangle rectTemp = new Rectangle();

            if (Height(rect1.coordsA, rect1.coordsB) * Width(rect1.coordsA, rect1.coordsB) <
                Height(rect2.coordsA, rect2.coordsB) * Width(rect2.coordsA, rect2.coordsB))
            {
                rectTemp = rect1;
                rect1    = rect2;
                rect2    = rectTemp;
            }


            if (ChekCross(rect1, rect2.coordsA) == true)
            {
                Rectangle rect3 = new Rectangle();

                if (ChekCross(rect1, B) == true)
                {
                    Coordinates coord = new Coordinates(rect2.coordsB.x, rect1.coordsB.y);

                    rect3.coordsA = rect2.coordsA;
                    rect3.coordsB = coord;
                }

                if (ChekCross(rect1, C) == true)
                {
                    Coordinates coord = new Coordinates(rect1.coordsB.x, rect2.coordsB.y);
                    rect3.coordsA = rect2.coordsA;
                    rect3.coordsB = coord;
                }

                else
                {
                    rect3.coordsA = rect2.coordsA;
                    rect3.coordsB = rect1.coordsB;
                }

                return(rect3);
            }

            if (ChekCross(rect1, rect2.coordsB) == true)
            {
                Rectangle rect3 = new Rectangle();

                if (ChekCross(rect1, B) == true)
                {
                    Coordinates coord = new Coordinates(rect1.coordsA.x, rect2.coordsA.y);

                    rect3.coordsB = rect2.coordsB;
                    rect3.coordsA = coord;
                }

                if (ChekCross(rect1, C) == true)
                {
                    Coordinates coord = new Coordinates(rect2.coordsA.x, rect1.coordsA.y);
                    rect3.coordsB = rect2.coordsB;
                    rect3.coordsA = coord;
                }

                else
                {
                    rect3.coordsA = rect1.coordsA;
                    rect3.coordsB = rect2.coordsB;
                }

                return(rect3);
            }

            if (ChekCross(rect1, C))
            {
                Rectangle rect3 = new Rectangle();

                Coordinates coordA = new Coordinates(rect2.coordsA.x, rect1.coordsA.y);
                Coordinates coordB = new Coordinates(rect1.coordsB.x, rect2.coordsB.y);

                rect3.coordsA = coordA;
                rect3.coordsB = coordB;

                return(rect3);
            }

            if (ChekCross(rect1, B))
            {
                Rectangle rect3 = new Rectangle();

                Coordinates coordA = new Coordinates(rect1.coordsA.x, rect2.coordsA.y);
                Coordinates coordB = new Coordinates(rect2.coordsB.x, rect1.coordsB.y);

                rect3.coordsA = coordA;
                rect3.coordsB = coordB;

                return(rect3);
            }

            if (ChekCross(rect1, rect2.coordsB) == true && ChekCross(rect1, rect2.coordsA) == true)
            {
                return(rect2);
            }

            throw new InvalidOperationException();
        }