Exemple #1
0
        /// <summary>
        /// Set Transform
        /// </summary>
        private void SetGeometryTransform(XmlDocument doc, XmlElement parentNode, SerializableMatrix transformMatrix)
        {
            if (transformMatrix == null)
            {
                return;
            }

            XmlElement transformMatrixNode = doc.CreateElement("GeometryTransform");

            if (transformMatrix.OffsetX != 0 || transformMatrix.OffsetY != 0)
            {
                XmlElement offsetNode = doc.CreateElement("OffsetTransform");

                XmlAttribute offsetX = doc.CreateAttribute("offsetX");
                offsetX.InnerText = "" + transformMatrix.OffsetX;
                offsetNode.SetAttributeNode(offsetX);

                XmlAttribute offsetY = doc.CreateAttribute("offsetY");
                offsetY.InnerText = "" + transformMatrix.OffsetY;
                offsetNode.SetAttributeNode(offsetY);

                transformMatrixNode.AppendChild(offsetNode);
            }

            if (transformMatrix.ScaleX != 1 || transformMatrix.ScaleY != 1)
            {
                XmlElement scaleNode = doc.CreateElement("ScaleTransform");

                XmlAttribute scaleX = doc.CreateAttribute("scaleX");
                scaleX.InnerText = "" + transformMatrix.ScaleX;
                scaleNode.SetAttributeNode(scaleX);

                XmlAttribute scaleY = doc.CreateAttribute("scaleY");
                scaleY.InnerText = "" + transformMatrix.ScaleY;
                scaleNode.SetAttributeNode(scaleY);

                transformMatrixNode.AppendChild(scaleNode);
            }

            if (transformMatrix.RotateAngle != 0)
            {
                XmlElement rotateNode = doc.CreateElement("RotateTransform");

                XmlAttribute angle = doc.CreateAttribute("angle");
                angle.InnerText = "" + transformMatrix.RotateAngle;
                rotateNode.SetAttributeNode(angle);

                transformMatrixNode.AppendChild(rotateNode);
            }
            parentNode.AppendChild(transformMatrixNode);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            SerializableMatrix s1Matrix = new SerializableMatrix(new double[3, 3] {
                { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }
            });

            s1Matrix.SerializationFormatter = new BinaryFormatter();
            Console.WriteLine(s1Matrix.ToString());

            s1Matrix.SerializeMatrix("matrix1.dat");
            s1Matrix.DeserializeMatrix("matrix.dat");

            Console.WriteLine(s1Matrix.ToString());
            Console.ReadKey();
        }
 // Converts array to matrix
 public bool[,] ConvertArray(SerializableMatrix array, int width, int height)
 {
     if (array == null)
     {
         return(null);
     }
     bool[,] bools = new bool[width, height];
     for (int i = 0; i < width; i++)
     {
         for (int j = 0; j < height; j++)
         {
             bools[i, j] = array.bools[i + j * width];
         }
     }
     return(bools);
 }
    // Converts matrix to array
    public SerializableMatrix ConvertMatrix(bool[,] matrix)
    {
        if (matrix == null)
        {
            return(null);
        }
        SerializableMatrix sMatrix = new SerializableMatrix(matrix.Length);
        int x = 0;

        for (int i = 0; i < matrix.GetLength(0); i++)
        {
            for (int j = 0; j < matrix.GetLength(1); j++)
            {
                sMatrix.bools[x] = matrix[i, j];
                x++;
            }
        }
        return(sMatrix);
    }
 public void SetGrid(SerializableMatrix array)
 {
     this.grid = array;
 }
 // Converts array to matrix
 public bool[,] ConvertArray(SerializableMatrix array, int width, int height)
 {
     if (array == null) {
         return null;
     }
     bool[,] bools = new bool[width, height];
     for (int i = 0; i < width; i++) {
         for (int j = 0; j < height; j++) {
             bools[i, j] = array.bools[i + j*width];
         }
     }
     return bools;
 }
 // Converts matrix to array
 public SerializableMatrix ConvertMatrix(bool[,] matrix)
 {
     if (matrix == null) {
         return null;
     }
     SerializableMatrix sMatrix = new SerializableMatrix(matrix.Length);
     int x = 0;
     for (int i = 0; i < matrix.GetLength(0); i++) {
         for (int j = 0; j < matrix.GetLength(1); j++) {
             sMatrix.bools[x] = matrix[i,j];
             x++;
         }
     }
     return sMatrix;
 }
 public void SetGrid(SerializableMatrix array)
 {
     this.grid = array;
 }