コード例 #1
0
        public void collision_RotateCollision()
        {
            //Rotate -> Collision

            //Rotate 15
            //Rotate 15
            //Rotate 15
            //Rotate 15 -can't do this because collision

            //Make
            PointF point = new PointF(400, 200);
            PointF pointWall = new PointF(400, 50);

            ProductModel product = new ProductModel(100, 300, 50);
            ProductModel productWall = new ProductModel(100, 50, 50);

            PlacedProduct placedP = new PlacedProduct(product, point);
            PlacedProduct placedWall = new PlacedProduct(productWall, pointWall);

            PlacementController.placedProductList.Add(placedP);
            PlacementController.placedProductList.Add(placedWall);
            

            double radius = Math.Sqrt(Math.Pow(product.Width/2, 2) + Math.Pow(product.Length/2, 2));
            double initialAngle = (Math.Atan((0.5 * product.Length) / (0.5 * product.Width)) * 180 / Math.PI);
            
            double angle_Even = 45 + initialAngle;
            double angle_Uneven = 45 - initialAngle;            

            float Cos_Even = (float)(Math.Cos(angle_Even * Math.PI / 180) * radius);
            float Sin_Even = (float)(Math.Sin(angle_Even * Math.PI / 180) * radius);

            float Cos_Uneven = (float)(Math.Cos(angle_Uneven * Math.PI / 180) * radius);
            float Sin_Uneven = (float)(Math.Sin(angle_Uneven * Math.PI / 180) * radius);


            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X - Cos_Even, point.Y - Sin_Even);   //{205 ; 195}
            pointCorner[1] = new PointF(point.X + Cos_Uneven, point.Y + Sin_Uneven);   //{215 ; 195}
            pointCorner[2] = new PointF(point.X + Cos_Even, point.Y + Sin_Even);   //{215 ; 205}
            pointCorner[3] = new PointF(point.X - Cos_Uneven, point.Y - Sin_Uneven);   //{205 ; 205}



            //Do
            placedP.AddAngle(15); //after this it's 15
            placedP.AddAngle(15); //after this it's 30
            placedP.AddAngle(15); //after this it's 45
            placedP.AddAngle(15); //after this it's 60 -Can't perform this because of the collision.
            placedP.AddAngle(15); //after this it's 75 -Can't perform this.
            placedP.AddAngle(15); //after this it's 90 -Can't perform this.


            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product is different!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product is different!");

            for (int index = 1; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
コード例 #2
0
        public void rotation_addAngle_45()
        {
            //Make
            PointF point = new PointF(200, 200);
            ProductModel product = new ProductModel(10, 10, 50);
            PlacedProduct placedP = new PlacedProduct(product, point);

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X, point.Y - (float)Math.Sqrt(50));    //{200 ; 200-√50}
            pointCorner[1] = new PointF(point.X + (float)Math.Sqrt(50), point.Y);                           //{200+√50 ; 200}
            pointCorner[2] = new PointF(point.X, point.Y + (float)Math.Sqrt(50));    //{200 ; 200+√50}
            pointCorner[3] = new PointF(point.X - (float)Math.Sqrt(50), point.Y);                           //{200-√50 ; 200}
            

            //Do
            placedP.AddAngle(25);
            placedP.AddAngle(20);



            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product has changed!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product has changed!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
コード例 #3
0
        public void rotation_addAngle_minus180()
        {
            //Make
            PointF point = new PointF(200, 200);
            ProductModel product = new ProductModel(10, 10, 50);
            PlacedProduct placedP = new PlacedProduct(product, point);

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X + product.Width / 2, point.Y + product.Length / 2); //now the lower right
            pointCorner[1] = new PointF(point.X - product.Width / 2, point.Y + product.Length / 2); //now the lower left
            pointCorner[2] = new PointF(point.X - product.Width / 2, point.Y - product.Length / 2); //now the top left
            pointCorner[3] = new PointF(point.X + product.Width / 2, point.Y - product.Length / 2); //now the top right

            //Do
            placedP.AddAngle(90);
            placedP.AddAngle(-270);



            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product has changed!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product has changed!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }
コード例 #4
0
        public void move_RotateMove()
        {
            //Rotate
            //Move X+0, Y+15

            //Make
            PointF point = new PointF(200, 200);
            ProductModel product = new ProductModel(10, 10, 50);
            PlacedProduct placedP = new PlacedProduct(product, point);

            int move_x = 0;
            int move_y = 15;

            PointF[] pointCorner = new PointF[4];
            pointCorner[0] = new PointF(point.X + (product.Width / 2) + move_x, point.Y - (product.Length / 2) + move_y);   //{205 ; 210}
            pointCorner[1] = new PointF(point.X + (product.Width / 2) + move_x, point.Y + (product.Length / 2) + move_y);   //{205 ; 220}
            pointCorner[2] = new PointF(point.X - (product.Width / 2) + move_x, point.Y + (product.Length / 2) + move_y);   //{195 ; 220}
            pointCorner[3] = new PointF(point.X - (product.Width / 2) + move_x, point.Y - (product.Length / 2) + move_y);   //{195 ; 210}


            //Do
            placedP.AddAngle(90);
            placedP.GridSpace = 15;
            placedP.Move(false);
            point.X += move_x;
            point.Y += move_y;


            //Look
            Assert.AreEqual(point.X, placedP.Location.X, 0.1, "The horizontal location of the product is different!");
            Assert.AreEqual(point.Y, placedP.Location.Y, 0.1, "The vertical location of the product is different!");

            for (int index = 0; index < pointCorner.Length; index++)
            {
                Assert.AreEqual(pointCorner[index].ToString(), placedP.CornerPoints[index].ToString(), true, "Corner #" + index + " is in the wrong spot!");
            }
        }