Exemplo n.º 1
0
        static CPoint transformPoint(MatrixValues mv, CPoint pt)
        {
            int x = pt.x * mv.m00 + pt.y * mv.m01;
            int y = pt.x * mv.m10 + pt.y * mv.m11;

            return(new CPoint(x, y));
        }
Exemplo n.º 2
0
        public static Vector2 operator *(IntMatrix im, Vector2 vec)
        {
            MatrixValues mv = allMatrices[im.value];
            float        x  = vec.X * mv.m00 + vec.Y * mv.m01;
            float        y  = vec.X * mv.m10 + vec.Y * mv.m11;

            return(new Vector2(x, y));
        }
Exemplo n.º 3
0
        public override string ToString()
        {
            var matrix = string.Empty;

            for (int i = 0; i < MatrixValues.GetLength(0); i++)
            {
                for (int j = 0; j < MatrixValues.GetLength(1); j++)
                {
                    matrix += MatrixValues[i, j] + " ";
                }
            }
            return(matrix);
        }
Exemplo n.º 4
0
    void RandomiseMatrix()
    {
        //yup you guessed it randomises the matrix header elements and makes sure the two elements cant be the same
        int rand1 = Random.Range(0, 3);
        int rand2;

        do
        {
            rand2 = Random.Range(0, 3);
        } while (rand1 == rand2);
        switch (rand1)
        {
        case 0:
            print("hair");
            firstElement = new MatrixValues(CheckHair);
            break;

        case 1:
            print("shirt");
            firstElement = new MatrixValues(CheckShirt);
            break;

        case 2:
            print("skin");
            firstElement = new MatrixValues(CheckSkin);
            break;
        }
        switch (rand2)
        {
        case 0:
            print("hair");
            secondElement = new MatrixValues(CheckHair);
            break;

        case 1:
            print("shirt");
            secondElement = new MatrixValues(CheckShirt);
            break;

        case 2:
            print("skin");
            secondElement = new MatrixValues(CheckSkin);
            break;
        }
    }
Exemplo n.º 5
0
        /// <summary>Transform integer rectangle with this matrix</summary>
        /// <remarks>The rectangle is assumed to be within [ 0, 0, outerSize.cx, outerSize.cy ] outer rectangle.
        /// The output coordinates are relative to the transformed outer rectangle.
        /// Mirroring component of the matrix is ignored, on output you'll always get a good rectangle with left &lt; right and top &lt; bottom.</remarks>
        public CRect transformRect(CRect rect, CSize outerSize)
        {
            MatrixValues mv = allMatrices[value];

            CPoint topLeft         = transformPoint(mv, rect.topLeft);
            CPoint bottomRight     = transformPoint(mv, rect.bottomRight);
            CPoint transformedSize = transformPoint(mv, new CPoint(outerSize.cx, outerSize.cy));

            int minX = Math.Min(0, transformedSize.x);
            int minY = Math.Min(0, transformedSize.y);

            return(new CRect
                   (
                       Math.Min(topLeft.x, bottomRight.x) - minX,
                       Math.Min(topLeft.y, bottomRight.y) - minY,
                       Math.Max(topLeft.x, bottomRight.x) - minX,
                       Math.Max(topLeft.y, bottomRight.y) - minY
                   ));
        }
Exemplo n.º 6
0
 private void SetTempMatrix()
 {
     TempMatrixValues = (double[, ])MatrixValues.Clone();
 }
Exemplo n.º 7
0
        public Vector4 asVector4()
        {
            MatrixValues mv = allMatrices[value];

            return(new Vector4(mv.m00, mv.m01, mv.m10, mv.m11));
        }
Exemplo n.º 8
0
        public MatrixVM(Matrix matrix)
        {
            this._matrix             = matrix;
            _matrix.PropertyChanged += (o, e) => {
                RaisePropertyChanged(e.PropertyName);
            };

            SelectMatrix = new DelegateCommand(() => {
                MatrixSelected?.Invoke();
            });

            for (int i = 0; i < matrix.Rows; i++)
            {
                for (int k = 0; k < matrix.Columns; k++)
                {
                    CellValueVM cellValue = new CellValueVM();
                    if (double.IsNaN(matrix[i, k]))
                    {
                        //cellValue.Value = (i + k) % 2 == 0 ? "🗙" : "𐩒";
                        cellValue.Value = "🗙";
                    }
                    else
                    {
                        cellValue.Value = matrix[i, k].ToString();
                    }
                    cellValue.RowIndex    = i;
                    cellValue.ColumnIndex = k;
                    MatrixValues.Add(cellValue);
                    cellValue.PropertyChanged += CellValuePropertyChanged;
                }
            }


            AddRow = new DelegateCommand(() => {
                if (Rows < 10)
                {
                    matrix.SetNewSize(Rows + 1, Columns, true);
                    for (int i = 0; i < Columns; i++)
                    {
                        CellValueVM cellValue      = new CellValueVM();
                        cellValue.Value            = "0";
                        cellValue.RowIndex         = Rows - 1;
                        cellValue.ColumnIndex      = i;
                        cellValue.PropertyChanged += CellValuePropertyChanged;
                        MatrixValues.Add(cellValue);
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            AddColumn = new DelegateCommand(() => {
                if (Columns < 10)
                {
                    matrix.SetNewSize(Rows, Columns + 1, true);
                    for (int i = 0; i < Rows; i++)
                    {
                        CellValueVM cellValue      = new CellValueVM();
                        cellValue.Value            = "0";
                        cellValue.RowIndex         = i;
                        cellValue.ColumnIndex      = Columns - 1;
                        cellValue.PropertyChanged += CellValuePropertyChanged;
                        MatrixValues.Insert((Columns - 1) + ((Columns - 1) * i) + i, cellValue);
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            DeleteRow = new DelegateCommand(() => {
                if (Rows > 1)
                {
                    int tmp = Columns * Rows - 1;
                    matrix.SetNewSize(Rows - 1, Columns, false);
                    for (int i = 0; i < Columns; i++)
                    {
                        MatrixValues.RemoveAt(tmp);
                        tmp--;
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            DeleteColumn = new DelegateCommand(() => {
                if (Columns > 1)
                {
                    matrix.SetNewSize(Rows, Columns - 1, false);
                    for (int i = 0; i < Rows; i++)
                    {
                        Console.WriteLine("Count:" + MatrixValues.Count);
                        Console.WriteLine("index:" + ((Columns + (Columns * i)) + 1));
                        MatrixValues.RemoveAt(Columns + (Columns * i));
                    }
                    UpdatedMatrix?.Invoke();
                }
            });

            DeleteMatrix = new DelegateCommand(() => {
                DeletedMatrix?.Invoke();
            });
        }