public void RunTest01()
        {
            RotateMatrix test   = new RotateMatrix(Test01Matrix);
            var          result = test.Run();

            CollectionAssert.AreEqual(result, Test01Result, new CollectionAssertComperator());
        }
        public void TestRotateMatrix()
        {
            int[,] matrix = new int[, ] {
                { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 12, 13, 14, 15 }, { 16, 17, 18, 19, 20 }, { 21, 22, 23, 24, 25 }
            };
            int[,] expected = new int[, ] {
                { 21, 16, 11, 6, 1 }, { 22, 17, 12, 7, 2 }, { 23, 18, 13, 8, 3 }, { 24, 19, 14, 9, 4 }, { 25, 20, 15, 10, 5 }
            };
            RotateMatrix rm = new RotateMatrix(matrix);

            rm.Rotate();
            Assert.Equal(expected, matrix);

            matrix = new int[, ] {
                { 1, 2 }, { 3, 4, }
            };
            expected = new int[, ] {
                { 3, 1 }, { 4, 2 }
            };
            rm = new RotateMatrix(matrix);
            rm.Rotate();
            Assert.Equal(expected, matrix);

            matrix = new int[, ] {
                { 120 }
            };
            expected = new int[, ] {
                { 120 }
            };
            rm = new RotateMatrix(matrix);
            rm.Rotate();
            Assert.Equal(expected, matrix);
        }
Пример #3
0
        static IAlgoDriver GetAlgorithmToExecute(string algorithHandle)
        {
            IAlgoDriver driver = null;

            switch (algorithHandle)
            {
            case "WordBreaking":
                driver = new WordBreaking();
                break;

            case "ReverseSLL":
                driver = new RevereseSLL();
                break;

            case "TreeTraversals":
                driver = new TreeTraversals();
                break;

            case "SpiralOrder":
                driver = new SpiralOrder();
                break;

            case "RotateMatrix":
                driver = new RotateMatrix();
                break;
            }

            return(driver);
        }
Пример #4
0
 public void Given_A_3x2_Matrix_Rotate90Degrees_Will_Return_A_Matrix_90_Degrees()
 {
     /*
      * [0][0] = 1
      * [0][1] = 2
      * [0][2] = 3
      * [1][0] = 4
      * [1][1] = 5
      * [1][2] = 6
      * to
      * [0][0] = 3
      * [0][1] = 6
      * [1][0] = 2
      * [1][1] = 5
      * [2][0] = 1
      * [2][1] = 4
      */
     int[,] data = new int[, ] {
         { 1, 2, 3 },
         { 4, 5, 6 }
     };
     int[,] expected = new int[, ] {
         { 3, 6 },
         { 2, 5 },
         { 1, 4 }
     };
     int[,] actual = RotateMatrix.Rotate90Degrees(data);
     Assert.True(Equals(expected, actual));
 }
        public void Rotate90DegreeShouldRotateGivenMatrix(int[][] squareMatrix, int[][] expected)
        {
            RotateMatrix rotate = new RotateMatrix(squareMatrix);

            int[][] actual = rotate.Rotate90Degree();
            Assert.Equal(expected, actual);
        }
 public void Init()
 {
     int[,] input = new int[, ] {
         { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
     };
     obj = new RotateMatrix(input, 3);
 }
Пример #7
0
        public void RotateMatrixTest(int rowsCount, params int[][] rows)
        {
            var m = new List <int[]>();

            for (var i = 0; i < rowsCount; i++)
            {
                m.Add(rows[i]);
            }
            var actual = m.ToArray();

            RotateMatrix.Rotate(actual);
            var expected = new List <int[]>();

            for (var i = rowsCount; i < (rows?.Length ?? 0); i++)
            {
                expected.Add(rows[i]);
            }
            for (var i = 0; i < actual.Length; i++)
            {
                for (var j = 0; j < actual.Length; j++)
                {
                    Assert.Equal(expected[i][j], actual[i][j]);
                }
            }
        }
Пример #8
0
 public virtual void Rotate(float RotateAngle)
 {
     {
         Center = SetCenter();
         RotateMatrix.RotateAt(RotateAngle, Center);
         Path.Transform(RotateMatrix);
     }
 }
Пример #9
0
 public void MyClick(object sender, EventArgs e)
 {
     changey = -changey;
     changex = -changex;
     changez = -changez;
     Xmat    = new XRotate(changex);
     Ymat    = new YRotate(changey);
     Zmat    = new ZRotate(changez);
 }
Пример #10
0
 public void Setup()
 {
     rotateMatrix = new RotateMatrix();
     int[] row1 = { 1, 2, 3, 4 };
     int[] row2 = { 5, 6, 7, 8 };
     int[] row3 = { 9, 10, 11, 12 };
     int[] row4 = { 13, 14, 15, 16 };
     matrix = new int[][] { row1, row2, row3, row4 };
 }
Пример #11
0
 public void MultiplyTest()
 {
     matrix1       = new RotateMatrix(data1);
     double[,] dou = matrix1.Multiply(1.1).m_data;
     Assert.AreEqual(dou[0, 0], data1[0, 0] * 1.1);
     Assert.AreEqual(dou[0, 1], data1[0, 1] * 1.1);
     Assert.AreEqual(dou[1, 0], data1[1, 0] * 1.1);
     Assert.AreEqual(dou[1, 1], data1[1, 1] * 1.1);
 }
Пример #12
0
 public void MultiplyTest1()
 {
     matrix1       = new RotateMatrix(data1);
     matrix2       = new RotateMatrix(data2);
     double[,] dou = matrix1.Multiply(matrix2).m_data;
     Assert.AreEqual(dou[0, 0], 12);
     Assert.AreEqual(dou[0, 1], 13);
     Assert.AreEqual(dou[1, 0], 56);
     Assert.AreEqual(dou[1, 1], 61);
 }
Пример #13
0
 public void SubtractTest()
 {
     matrix1       = new RotateMatrix(data1);
     matrix2       = new RotateMatrix(data2);
     double[,] dou = matrix1.Subtract(matrix2).m_data;
     Assert.AreEqual(dou[0, 0], 0 - 10);
     Assert.AreEqual(dou[0, 1], 1 - 11);
     Assert.AreEqual(dou[1, 0], 2 - 12);
     Assert.AreEqual(dou[1, 1], 3 - 13);
 }
Пример #14
0
 public void AddTest()
 {
     matrix1       = new RotateMatrix(data1);
     matrix2       = new RotateMatrix(data2);
     double[,] dou = matrix1.Add(matrix2).m_data;
     Assert.AreEqual(dou[0, 0], 0 + 10);
     Assert.AreEqual(dou[0, 1], 1 + 11);
     Assert.AreEqual(dou[1, 0], 2 + 12);
     Assert.AreEqual(dou[1, 1], 3 + 13);
 }
Пример #15
0
 public void Given_A_1x1_Matrix_Rotate90Degrees_Will_Return_A_Matrix_90_Degrees()
 {
     int[,] data = new int[, ] {
         { 1 }
     };
     int[,] expected = new int[, ] {
         { 1 }
     };
     int[,] actual = RotateMatrix.Rotate90Degrees(data);
     Assert.True(Equals(expected, actual));
 }
Пример #16
0
 public void RotateAt2DTest()
 {
     //二维测试1
     matrix3       = new RotateMatrix(data3);
     double[,] dou = matrix3.RotateAt2D(90, new Point3D()
     {
         X = 0.5, Y = 1, Z = 1
     }, Types.ArcDirctionType.UNCLOCK_WISE).m_data;
     Assert.AreEqual(Math.Round(dou[0, 0], 8), 0.5);
     Assert.AreEqual(Math.Round(dou[0, 1], 8), 1.5);
 }
Пример #17
0
        public void Rotate_Success()
        {
            int[,] data = new int[4, 4] {
                { 3, 6, 9, 10 }, { 4, 5, 6, 8 }, { 1, 2, 3, 6 }, { 4, 7, 8, 9 }
            };
            var result = RotateMatrix.Rotate(data, 4);

            Assert.AreEqual(result[0, 0], 10, "(0,0) is not equal to 10.");
            Assert.AreEqual(result[1, 0], 9, "(1,0) number is not equal to 9.");
            Assert.AreEqual(result[2, 0], 6, "(2,0) number is not equal to 6.");
            Assert.AreEqual(result[3, 0], 3, "(3,0) number is not equal to 3.");
        }
        public void RotateMatrix_Rotates_Matrix()
        {
            //Arrange
            int[][] matrix = new int[][] { new int[] { 1, 2, 3 }, new int[] { 4, 5, 6 }, new int[] { 7, 8, 9 } };

            //Act
            var actual = RotateMatrix.MatrixRotate(matrix);

            //Assert
            var expected = new int[][] { new int[] { 7, 4, 1 }, new int[] { 8, 5, 2 }, new int[] { 9, 6, 3 } };

            Assert.Equal(expected, actual);
        }
Пример #19
0
        public void RotateFigure(RotateMatrix rotation_matrix, bool direction = false)
        {
            // true - clockwise
            // false - counterclockwise

            double rotate_speed = Constants.ROTATE_SPEED;

            if (!direction)
            {
                rotate_speed = -rotate_speed;
            }
            rotate_matrix = rotate_matrix.Multiply(rotation_matrix(rotate_speed));
        }
Пример #20
0
        /// <summary>
        /// Given a N*N matrix , write a method to rotate the image by 90 degrees
        /// </summary>
        /// <param name="len"></param>
        public static void RotateMatrixImplementation(int len)
        {
            int[][] matrix = new int[len][];
            var     random = new Random();

            for (int i = 0; i < matrix.Length; i++)
            {
                matrix[i] = new int[len]; // Create inner array
                for (int j = 0; j < matrix[i].Length; j++)
                {
                    //generate random numbers
                    matrix[i][j] = random.Next(1, Convert.ToInt32(Math.Pow(len, 3)));
                }
            }
            RotateMatrix.RotateMatrixBy90Degress(matrix);
        }
Пример #21
0
        public void RotateMatrixTest()
        {
            var input  = TestHelpers.BuildJaggedGridOne();
            var result = RotateMatrix.Run(input);

            Assert.Equal("781692543", TestHelpers.ToString(result));

            var inputTwo  = TestHelpers.BuildJaggedGridTwo();
            var resultTwo = RotateMatrix.Run(inputTwo);

            Assert.Equal("1911282237334654", TestHelpers.ToString(resultTwo));

            var inputThree  = TestHelpers.BuildJaggedGridThree();
            var resultThree = RotateMatrix.Run(inputThree);

            Assert.Equal("3142", TestHelpers.ToString(resultThree));
        }
Пример #22
0
        public void MatrixRotation()
        {
            int[,] matrix = new int[4, 4] {
                { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 }
            };
            int[,] rotatedMatrix = new int[4, 4] {
                { 13, 9, 5, 1 }, { 14, 10, 6, 2 }, { 15, 11, 7, 3 }, { 16, 12, 8, 4 }
            };
            var result = RotateMatrix.Solution1(matrix);

            for (int i = 0; i < matrix.GetLength(0); i++)
            {
                for (int j = 0; j < matrix.GetLength(1); j++)
                {
                    Assert.AreEqual(matrix[i, j], rotatedMatrix[i, j]);
                }
                Console.WriteLine();
            }
        }
Пример #23
0
 public void Given_A_2x1_Matrix_Rotate90Degrees_Will_Return_A_Matrix_90_Degrees()
 {
     /*
      * [0][0] = 1
      * [0][1] = 2
      * to
      * [0][0] = 2
      * [1][0] = 1
      */
     int[,] data = new int[, ] {
         { 1, 2 }
     };
     int[,] expected = new int[, ] {
         { 2 },
         { 1 }
     };
     int[,] actual = RotateMatrix.Rotate90Degrees(data);
     Assert.True(Equals(expected, actual));
 }
Пример #24
0
        public void Rotate2DTest()
        {
            //二维测试1
            matrix3       = new RotateMatrix(data3);
            double[,] dou = matrix3.Rotate2D(90, Types.ArcDirctionType.CLOCK_WISE).m_data;
            Assert.AreEqual(Math.Round(dou[0, 0], 8), 1);
            Assert.AreEqual(Math.Round(dou[0, 1], 8), -1);

            //二维测试1
            double d1 = Math.Cos(75 * Math.PI / 180) * Math.Pow(2, 0.5);
            double d2 = Math.Sin(75 * Math.PI / 180) * Math.Pow(2, 0.5);

            matrix3        = new RotateMatrix(data3);
            double[,] dou2 = matrix3.Rotate2D(30, Types.ArcDirctionType.UNCLOCK_WISE).m_data;
            Assert.AreEqual(Math.Round(dou2[0, 0], 8), Math.Round(d1, 8));
            Assert.AreEqual(Math.Round(dou2[0, 1], 8), Math.Round(d2, 8));

            //二维测试3
            matrix3        = new RotateMatrix(data3);
            double[,] dou3 = matrix3.Rotate2D(360, Types.ArcDirctionType.UNCLOCK_WISE).m_data;
            Assert.AreEqual(Math.Round(dou3[0, 0], 8), data3[0, 0]);
            Assert.AreEqual(Math.Round(dou3[0, 1], 8), data3[0, 1]);

            //二维测试4
            string exceptionText = "";

            try
            {
                matrix3        = new RotateMatrix(data3);
                double[,] dou4 = matrix3.Rotate2D(360, Types.ArcDirctionType.UNKONW).m_data;
            }
            catch (Exception ex)
            {
                exceptionText += ex.ToString();
            }
            Assert.AreNotEqual(exceptionText, "");
        }
Пример #25
0
 private void lessZ(object sender, System.EventArgs e)
 {
     changez -= 0.006F;
     Zmat     = new ZRotate(changez);
 }
Пример #26
0
 private void lessY(object sender, System.EventArgs e)
 {
     changey -= 0.006F;
     Ymat     = new YRotate(changey);
 }
Пример #27
0
 private void lessX(object sender, System.EventArgs e)
 {
     changex -= 0.006F;
     Xmat     = new XRotate(changex);
 }
Пример #28
0
    public MainClass()
    {
        Xmat            = new XRotate(changex);
        Ymat            = new YRotate(changey);
        Zmat            = new ZRotate(changez);
        Size            = new Size(400, 260);
        Text            = "Hellllo 3D!";
        FormBorderStyle = FormBorderStyle.FixedToolWindow;
        MaximizeBox     = false;
        Button b1 = new Button();

        b1.Text   = "Add X axis Speed";
        b1.Size   = new Size(115, 25);
        b1.Click += new EventHandler(moreX);
        Controls.Add(b1);
        Button b2 = new Button();

        b2.Text     = "Add Y axis Speed";
        b2.Size     = new Size(115, 25);
        b2.Location = new Point(0, 25);
        b2.Click   += new EventHandler(moreY);
        Controls.Add(b2);
        Button b3 = new Button();

        b3.Text     = "Add Z axis Speed";
        b3.Size     = new Size(115, 25);
        b3.Location = new Point(0, 50);
        b3.Click   += new EventHandler(moreZ);
        Controls.Add(b3);
        Button b4 = new Button();

        b4.Text     = "Less X axis Speed";
        b4.Size     = new Size(115, 25);
        b4.Location = new Point(0, 75);
        b4.Click   += new EventHandler(lessX);
        Controls.Add(b4);
        Button b5 = new Button();

        b5.Text     = "Less Y axis Speed";
        b5.Size     = new Size(115, 25);
        b5.Location = new Point(0, 100);
        b5.Click   += new EventHandler(lessY);
        Controls.Add(b5);
        Button b6 = new Button();

        b6.Text     = "Less Z axis Speed";
        b6.Size     = new Size(115, 25);
        b6.Location = new Point(0, 125);
        b6.Click   += new EventHandler(lessZ);
        Controls.Add(b6);
        b7.Text     = "Stop !!!";
        b7.Size     = new Size(115, 25);
        b7.Location = new Point(0, 150);
        b7.Click   += new EventHandler(Stop);
        Controls.Add(b7);
        RadioButton b8 = new RadioButton();

        b8.Text            = "CUBE";
        b8.Size            = new Size(195, 25);
        b8.Location        = new Point(250, 210);
        b8.BackColor       = Color.White;
        b8.Checked         = false;
        b8.CheckedChanged += new EventHandler(shapeCube);
        Controls.Add(b8);
        RadioButton b9 = new RadioButton();

        b9.Text            = "Sphere";
        b9.Checked         = false;
        b9.Size            = new Size(75, 25);
        b9.BackColor       = Color.White;
        b9.Location        = new Point(115, 210);
        b9.CheckedChanged += new EventHandler(shapeSphere);
        Controls.Add(b9);
        RadioButton b10 = new RadioButton();

        b10.Text            = "Axis";
        b10.Checked         = true;
        b10.Size            = new Size(115, 25);
        b10.BackColor       = Color.White;
        b10.Location        = new Point(190, 210);
        b10.CheckedChanged += new EventHandler(shapeAxis);
        Controls.Add(b10);
        t1           = new Label();
        t2           = new Label();
        t3           = new Label();
        t1.Size      = new Size(115, 20);
        t2.Size      = new Size(115, 20);
        t3.Size      = new Size(115, 20);
        t1.Location  = new Point(0, 175);
        t2.Location  = new Point(0, 195);
        t3.Location  = new Point(0, 215);
        t1.BackColor = Color.White;
        t2.BackColor = Color.White;
        t3.BackColor = Color.White;
        Controls.Add(t1);
        Controls.Add(t2);
        Controls.Add(t3);

        SetStyle(ControlStyles.AllPaintingInWmPaint, true);
        SetStyle(ControlStyles.DoubleBuffer, true);

        Vector z = new Vector(250, 105, 1000);

        Vector[] points1 = new Vector[4];
        Vector[] points2 = new Vector[4];
        Vector[] points3 = new Vector[4];
        Vector[] points4 = new Vector[4];

        Polygon poly1, poly2, poly3, poly4;

        // building the axis shape;
        points1[0] = new Vector(-100, 0, 0);
        points1[1] = new Vector(100, 0, 0);

        points2[0] = new Vector(0, -100, 0);
        points2[1] = new Vector(0, 100, 0);

        points3[0] = new Vector(0, 0, -100);
        points3[1] = new Vector(0, 0, 100);
        poly1      = new Polygon(1000, z, points1[0], points1[1]);
        poly2      = new Polygon(1000, z, points2[0], points2[1]);
        poly3      = new Polygon(1000, z, points3[0], points3[1]);
        Axis       = new Shape3D(poly1, poly2, poly3);

        // building the Cube shape;
        points1[0] = new Vector(0, 0, 50);
        points1[1] = new Vector(0, 50, 50);
        points1[2] = new Vector(50, 50, 50);
        points1[3] = new Vector(50, 0, 50);
        poly1      = new Polygon(1000, z, points1);
        poly1      = poly1.Transpose(new Vector(-5, -5, -30));


        points2[0] = new Vector(0, 0, 50);
        points2[1] = new Vector(0, 0, 100);
        points2[2] = new Vector(0, 50, 100);
        points2[3] = new Vector(0, 50, 50);
        poly2      = new Polygon(1000, z, points2);
        poly2      = poly2.Transpose(new Vector(-5, -5, -30));

        points3[0] = new Vector(0, 0, 100);
        points3[1] = new Vector(0, 50, 100);
        points3[2] = new Vector(50, 50, 100);
        points3[3] = new Vector(50, 0, 100);
        poly3      = new Polygon(1000, z, points3);
        poly3      = poly3.Transpose(new Vector(-5, -5, -30));

        points4[0] = new Vector(50, 0, 50);
        points4[1] = new Vector(50, 0, 100);
        points4[2] = new Vector(50, 50, 100);
        points4[3] = new Vector(50, 50, 50);
        poly4      = new Polygon(1000, z, points4);
        poly4      = poly4.Transpose(new Vector(-5, -5, -30));
        Cube       = new Shape3D(poly1, poly2, poly3, poly4);

        // building the Cube shape;
        Polygon[] p = new Polygon[130];
        poly1 = poly1.Transpose(new Vector(-30, -30, -100));
        for (int count = 0; count < p.Length; count++)
        {
            p[count] = poly1.Rotate(new ZRotate(System.Math.PI / 20 * count)).Rotate(new XRotate(System.Math.PI / 60 * count)).Rotate(new YRotate(System.Math.PI / 180 * count));
        }
        Circle = new Shape3D(p);


        this.Paint += new System.Windows.Forms.PaintEventHandler(MyPaint);
        this.Click += new EventHandler(MyClick);


        currentShape = Axis;

        tm          = new Timer();
        tm.Interval = 10;
        tm.Tick    += new EventHandler(tmEvent);
        tm.Start();
    }
Пример #29
0
 public void rotate90DegreeLayer(int[,] input, int[,] expected)
 {
     RotateMatrix.rotate90DegreeLayer(input);
     Assert.Equal(expected, input);
 }
Пример #30
0
 public void rotate90Degree(int[,] input, int[,] expected)
 {
     int[,] rotated = RotateMatrix.rotate90Degree(input);
     Assert.Equal(expected, rotated);
 }