private bool setAandB()
        {
            double[,] TempA = new double[GridA.Rows, GridA.Rows];
            double[,] TempB = new double[GridA.Rows, GridA.Rows];
            bool worked = true;

            for (int i = 0; i < GridA.Rows; i++)
            {
                for (int j = 0; j < GridA.Rows; j++)
                {
                    if (!Double.TryParse(((String)inputFields["A" + i + ":" + j].Text), out TempA[i, j]) || !Double.TryParse(((String)inputFields["B" + i + ":" + j].Text), out TempB[i, j]))
                    {
                        worked = false;
                        break;
                    }
                    if (!worked)
                    {
                        break;
                    }
                }
            }
            MatrixA = new CustomMatrix(GridA.Rows);
            MatrixB = new CustomMatrix(GridA.Rows);
            MatrixA.PopulateMatrix(TempA);
            MatrixB.PopulateMatrix(TempB);
            return(worked);
        }
예제 #2
0
        public void ConstructorTest_ShouldReturnCorrectMatrixDimensions(int height, int width)
        {
            var matrix   = new CustomMatrix(height, width);
            var expected = (height, width);
            var actual   = (matrix.Matrix.GetLength(0), matrix.Matrix.GetLength(1));

            Assert.AreEqual(expected, actual);
        }
예제 #3
0
 public Node(int x, int y, Node prv, Node nxt, CustomMatrix mx, int constVal)
 {
     defMatrix   = mx;
     previous    = prv;
     next        = nxt;
     pos.x       = x;
     pos.y       = y;
     constantVal = constVal;
 }
예제 #4
0
 public Node()
 {
     defMatrix   = new CustomMatrix(2, 2);
     constantVal = 0;
     next        = null;
     previous    = null;
     pos         = new Vector2(0, 0);
     linkerVal   = 3;
 }
예제 #5
0
        static void Main()
        {
            Console.OutputEncoding = Encoding.UTF8;
            Console.Write(Messages.RequestHeightInput);
            var height = PromptUserMatrixDimension();

            Console.Write(Messages.RequestWidthInput);
            var width  = PromptUserMatrixDimension();
            var matrix = new CustomMatrix(height, width);

            matrix.DisplayMatrix();
            Console.WriteLine($"\n{Messages.MatrixTraceSum} {matrix.GetTraceSum()}");
        }
예제 #6
0
        public void ConstructorTest_PopulationMethod_ShouldReturnMatrixWithValuesBetween0and100()
        {
            int  height   = 10;
            int  width    = 10;
            var  matrix   = new CustomMatrix(height, width);
            var  expected = true;
            bool actual   = true;

            foreach (var element in matrix.Matrix)
            {
                if (element < 0 || element > 100)
                {
                    actual = false;
                }
            }
            Assert.AreEqual(expected, actual);
        }
예제 #7
0
        public static Bitmap Transformation(this Bitmap bitmap, Bitmap reference, double[,] mat)
        {
            /*
             * int offsetX = (int) mat[2, 0];
             * int offsetY = (int) mat[2, 1];
             * double scaleX = Math.Sqrt(Math.Pow(mat[0, 0], 2) + Math.Pow(mat[0, 1], 2));
             * double scaleY = Math.Sqrt(Math.Pow(mat[1, 0], 2) + Math.Pow(mat[1, 1], 2));
             * double theta = Math.Atan(mat[0, 1] / mat[0, 0]);
             *
             * int width = (int) Math.Ceiling((bitmap.Width - offsetX) / Math.Cos(theta) / scaleX);
             * int height = (int) Math.Ceiling(offsetX / Math.Sin(theta) / scaleY);
             */

            Bitmap change = new Bitmap(reference.Width, reference.Height);

            CustomMatrix customMatrix = new CustomMatrix();

            for (int i = 0; i < change.Width; i++)
            {
                for (int j = 0; j < change.Height; j++)
                {
                    double[,] coordinate = new double[1, 3]
                    {
                        { i, j, 1 }
                    };

                    coordinate = customMatrix.MatrixMultiply(coordinate, mat);
                    int x = (int)Math.Round(coordinate[0, 0]);
                    int y = (int)Math.Round(coordinate[0, 1]);

                    if (x >= 0 && x < bitmap.Width && y >= 0 && y < bitmap.Height)
                    {
                        Color color = bitmap.GetPixel(x, y);

                        change.SetPixel(i, j, color);
                    }
                }
            }

            return(change);
        }
예제 #8
0
        public void CalculateTraceSumTest_ShouldReturnCorrectSumOfTraceElements(int height, int width)
        {
            var matrix            = new CustomMatrix(height, width);
            int expected          = 0;
            int shortestDimension = 0;

            if (height < width)
            {
                shortestDimension = height;
            }
            else
            {
                shortestDimension = width;
            }
            for (var i = 0; i < shortestDimension; i++)
            {
                expected += matrix.Matrix[i, i];
            }

            var actual = matrix.GetTraceSum();

            Assert.AreEqual(expected, actual);
        }