Exemple #1
0
        static void Main(string[] args)
        {
            string root = System.IO.Path.Combine("..", "..", "..", "Numerics");

            var integer_path = System.IO.Path.Combine(root, "Integer.cs");
            System.IO.File.Delete(integer_path);
            foreach (var size in Integer.Sizes)
            {
                var integer = new Integer(size, true);
                integer.Generate();

                System.IO.File.AppendAllText(integer_path, integer.Text);
                Console.WriteLine("Done - " + integer.Name);

                var uinteger = new Integer(size, false);
                uinteger.Generate();

                System.IO.File.AppendAllText(integer_path, uinteger.Text);
                Console.WriteLine("Done - " + uinteger.Name);
            }

            foreach (var type in Color.Types)
            {
                var color = new Color(type);
                color.Generate();

                var path = System.IO.Path.Combine(root, color.Name + ".cs");
                System.IO.File.WriteAllText(path, color.Text);
                Console.WriteLine("Done - " + color.Name);
            }

            foreach (var type in Quaternion.Types)
            {
                var quaternion = new Quaternion(type);
                quaternion.Generate();

                var path = System.IO.Path.Combine(root, "Geometry", quaternion.Name + ".cs");
                System.IO.File.WriteAllText(path, quaternion.Text);
                Console.WriteLine("Done - " + quaternion.Name);
            } 
            
            foreach (var type in Plane.Types)
            {
                var plane = new Plane(type);
                plane.Generate();

                var path = System.IO.Path.Combine(root, "Geometry", plane.Name + ".cs");
                System.IO.File.WriteAllText(path, plane.Text);
                Console.WriteLine("Done - " + plane.Name);
            }

            foreach (int dimension in Vector.Sizes)
            {
                foreach (var type in Vector.Types)
                {
                    var vector = new Vector(type, dimension);
                    vector.Generate();

                    var path = System.IO.Path.Combine(root, "Vectors", vector.Name + ".cs");
                    System.IO.File.WriteAllText(path, vector.Text);
                    Console.WriteLine("Done - " + vector.Name);
                }
            }

            foreach (int rows in Matrix.Sizes)
            {
                foreach (int columns in Matrix.Sizes)
                {
                    foreach (var type in Matrix.Types)
                    {
                        var matrix = new Matrix(type, rows, columns);
                        matrix.Generate();
                        var path = System.IO.Path.Combine(root, "Matrices", matrix.Name + ".cs");
                        System.IO.File.WriteAllText(path, matrix.Text);
                        Console.WriteLine("Done - " + matrix.Name);
                    }
                }
            }

            foreach (var type in Shapes.Types)
            {
                var rpath = System.IO.Path.Combine(root, "Geometry");

                var line1 = new Line(type, 1);
                line1.Generate();
                System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, line1.Name + ".cs"), line1.Text);
                Console.WriteLine("Done - " + line1.Name);

                foreach (int dimension in Shapes.Sizes)
                {
                    var point = new Point(type, dimension);
                    point.Generate();
                    System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, point.Name + ".cs"), point.Text);
                    Console.WriteLine("Done - " + point.Name);

                    var size = new Size(type, dimension);
                    size.Generate();
                    System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, size.Name + ".cs"), size.Text);
                    Console.WriteLine("Done - " + size.Name);

                    var polygon = new Polygon(type, dimension);
                    polygon.Generate();
                    System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, polygon.Name + ".cs"), polygon.Text);
                    Console.WriteLine("Done - " + polygon.Name);

                    var line = new Line(type, dimension);
                    line.Generate();
                    System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, line.Name + ".cs"), line.Text);
                    Console.WriteLine("Done - " + line.Name);
                }

                var rectangle = new Rectangle(type);
                rectangle.Generate();
                System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, rectangle.Name + ".cs"), rectangle.Text);
                Console.WriteLine("Done - " + rectangle.Name);

                var box = new Box(type);
                box.Generate();
                System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, box.Name + ".cs"), box.Text);
                Console.WriteLine("Done - " + box.Name);

                var ellipse = new Ellipse(type);
                ellipse.Generate();
                System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, ellipse.Name + ".cs"), ellipse.Text);
                Console.WriteLine("Done - " + ellipse.Name);

                var circle = new Circle(type);
                circle.Generate();
                System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, circle.Name + ".cs"), circle.Text);
                Console.WriteLine("Done - " + circle.Name);

                var sphere = new Sphere(type);
                sphere.Generate();
                System.IO.File.WriteAllText(System.IO.Path.Combine(rpath, sphere.Name + ".cs"), sphere.Text);
                Console.WriteLine("Done - " + sphere.Name);
            }

            foreach (var type in Ray.Types)
            {
                var ray = new Ray(type);
                ray.Generate();

                var path = System.IO.Path.Combine(root, "Geometry", ray.Name + ".cs");
                System.IO.File.WriteAllText(path, ray.Text);
                Console.WriteLine("Done - " + ray.Name);
            }
        }
Exemple #2
0
        void Conversions()
        {
            WriteLine("#region Conversions");

            foreach (var type in Shapes.Types.Where(t => t != Type))
            {
                string imex = type.IsImplicitlyConvertibleTo(Type) ? "implicit" : "explicit";
                Polygon other = new Polygon(type, Dimension);

                WriteLine("/// <summary>");
                WriteLine("/// Defines an {0} conversion of a {1} value to a {2}.", imex, other, Name);
                WriteLine("/// </summary>");
                WriteLine("/// <param name=\"value\">The value to convert to a {0}.</param>", Name);
                WriteLine("/// <returns>A {0} that has all components equal to value.</returns>", Name);
                if (Type.IsCLSCompliant && !type.IsCLSCompliant)
                {
                    WriteLine("[CLSCompliant(false)]");
                }
                WriteLine("public static {0} operator {1}({2} value)", imex, Name, other);
                WriteLine("{");
                Indent();
                WriteLine("var points = new {0}[value.Count];", Point);
                WriteLine("for (int i=0; i<points.Length; ++i)");
                WriteLine("{");
                Indent();
                WriteLine("points[i] = ({0})value[i];", Point);
                Dedent();
                WriteLine("}");
                WriteLine("return new {0}(points);", Name);
                Dedent();
                WriteLine("}");
            }

            WriteLine("#endregion");
        }