Beispiel #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);
            }
        }
Beispiel #2
0
        void Conversions()
        {
            WriteLine("#region Conversions");

            foreach (var type in Types)
            {
                string imex = type.IsImplicitlyConvertibleTo(Type) ? "implicit" : "explicit";

                if (type != Type)
                {
                    Quaternion other = new Quaternion(type);

                    var casts = string.Join(", ",
                        Components.Select(component => string.Format("({0})value.{1}", Type, component)));

                    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("return new {0}({1});", Name, casts);
                    Dedent();
                    WriteLine("}");
                }

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

            WriteLine("#endregion");
        }
Beispiel #3
0
        void Functions()
        {
            WriteLine("/// <summary>");
            WriteLine("/// Provides static methods for quaternion functions.");
            WriteLine("/// </summary>");
            WriteLine("public static partial class Quaternion");
            WriteLine("{");
            Indent();

            var result = new Quaternion(Type.PositiveType);

            #region Factory

            WriteLine("#region Factory");

            WriteLine("/// <summary>");
            WriteLine("/// Initializes a new instance of the <see cref=\"{0}\"/> structure given a rotation and an axis.", Name);
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"axis\">The axis of rotation.</param>");
            WriteLine("/// <param name=\"angle\">The angle of rotation.</param>");
            WriteLine("/// <returns>The newly created quaternion.</returns>");
            WriteLine("public static {0} FromRotationAxis({1} axis, {2} angle)", Name, new Vector(Type, 3), Type);
            Indent("{");
            WriteLine("axis = Vector.Normalize(axis);");
            WriteLine("var half = angle * 0.5f;");
            WriteLine("var sin =  Functions.Sin(half);");
            WriteLine("var cos =  Functions.Cos(half);");
            WriteLine("return new {0}(cos, axis.X * sin, axis.Y * sin, axis.Z * sin);", Name);
            Dedent("}");

            WriteLine("/// <summary>");
            WriteLine("/// Initializes a new instance of the <see cref=\"{0}\"/> structure given a yaw, pitch, and roll value.", Name);
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"yaw\">The yaw of rotation.</param>");
            WriteLine("/// <param name=\"pitch\">The pitch of rotation.</param>");
            WriteLine("/// <param name=\"roll\">The roll of rotation.</param>");
            WriteLine("/// <returns>The newly created quaternion.</returns>");
            WriteLine("public static {0} FromRotationAngles({1} yaw, {1} pitch, {1} roll)", Name, Type);
            Indent("{");
            WriteLine("var halfRoll = roll * 0.5f;");
            WriteLine("var sinRoll = Functions.Sin(halfRoll);");
            WriteLine("var cosRoll = Functions.Cos(halfRoll);");
            WriteLine("var halfPitch = pitch * 0.5f;");
            WriteLine("var sinPitch = Functions.Sin(halfPitch);");
            WriteLine("var cosPitch = Functions.Cos(halfPitch);");
            WriteLine("var halfYaw = yaw * 0.5f;");
            WriteLine("var sinYaw = Functions.Sin(halfYaw);");
            WriteLine("var cosYaw = Functions.Cos(halfYaw);");
            WriteLine("return new {0}(", Name);
            WriteLine("\t(cosYaw * cosPitch * cosRoll) + (sinYaw * sinPitch * sinRoll),");
            WriteLine("\t(cosYaw * sinPitch * cosRoll) + (sinYaw * cosPitch * sinRoll),");
            WriteLine("\t(sinYaw * cosPitch * cosRoll) - (cosYaw * sinPitch * sinRoll),");
            WriteLine("\t(cosYaw * cosPitch * sinRoll) - (sinYaw * sinPitch * cosRoll));");
            Dedent("}");

            WriteLine("/// <summary>");
		    WriteLine("/// Initializes a new instance of the <see cref=\"{0}\"/> structure given a rotation matrix.", Name);
		    WriteLine("/// </summary>");
		    WriteLine("/// <param name=\"matrix\">The rotation matrix.</param>");
		    WriteLine("/// <returns>The newly created quaternion.</returns>");
		    WriteLine("public static {0} FromMatrix({1} matrix)", Name, new Matrix(Type, 3,3));
		    Indent("{");
            WriteLine("var a = Functions.Sqrt(Functions.Max(0, 1 + matrix[0, 0] + matrix[1, 1] + matrix[2, 2])) / 2;");
            WriteLine("var b = Functions.Sqrt(Functions.Max(0, 1 + matrix[0, 0] - matrix[1, 1] - matrix[2, 2])) / 2;");
            WriteLine("var c = Functions.Sqrt(Functions.Max(0, 1 - matrix[0, 0] + matrix[1, 1] - matrix[2, 2])) / 2;");
            WriteLine("var d = Functions.Sqrt(Functions.Max(0, 1 - matrix[0, 0] - matrix[1, 1] + matrix[2, 2])) / 2;");
            WriteLine("b *= Functions.Sign(b * (matrix[2, 1] - matrix[1, 2]));");
            WriteLine("c *= Functions.Sign(c * (matrix[0, 2] - matrix[2, 0]));");
            WriteLine("d *= Functions.Sign(d * (matrix[1, 0] - matrix[0, 1]));");
            WriteLine("return new {0}(a, b, c, d);", Name);
		    Dedent("}");

            WriteLine("/// <summary>");
            WriteLine("/// Initializes a new instance of the <see cref=\"{0}\"/> structure given a direction and up axis.", Name);
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"direction\">The direction vector.</param>");
            WriteLine("/// <param name=\"up\">The up axis.</param>");
            WriteLine("/// <returns>The newly created quaternion.</returns>");
            WriteLine("public static {0} FromOrientation({1} direction, {1} up)", Name, new Vector(Type, 3));
            Indent("{");
            WriteLine("var zaxis = Vector.Normalize(direction);");
            WriteLine("var xaxis = Vector.Normalize(Vector.Cross(up, zaxis));");
            WriteLine("var yaxis = Vector.Cross(zaxis, xaxis);");
            WriteLine("var a = Functions.Sqrt(Functions.Max(0, 1 + xaxis.X + yaxis.Y + zaxis.Z)) / 2;");
            WriteLine("var b = Functions.Sqrt(Functions.Max(0, 1 + xaxis.X - yaxis.Y - zaxis.Z)) / 2;");
            WriteLine("var c = Functions.Sqrt(Functions.Max(0, 1 - xaxis.X + yaxis.Y - zaxis.Z)) / 2;");
            WriteLine("var d = Functions.Sqrt(Functions.Max(0, 1 - xaxis.X - yaxis.Y + zaxis.Z)) / 2;");
            WriteLine("b *= Functions.Sign(b * (yaxis.Z - zaxis.Y));");
            WriteLine("c *= Functions.Sign(c * (zaxis.X - xaxis.Z));");
            WriteLine("d *= Functions.Sign(d * (xaxis.Y - yaxis.X));");
            WriteLine("return new {0}(a, b, c, d);", Name);
            Dedent("}");

            WriteLine("#endregion");
            #endregion

            #region Binary
            WriteLine("#region Binary");
            WriteLine("/// <summary>");
            WriteLine("/// Writes the given <see cref=\"{0}\"/> to an <see cref=\"Ibasa.IO.BinaryWriter\">.", Name);
            WriteLine("/// </summary>");
            WriteLine("public static void Write(this Ibasa.IO.BinaryWriter writer, {0} quaternion)", Name);
            WriteLine("{");
            Indent();
            foreach(var component in Components)
            {
                WriteLine("writer.Write(quaternion.{0});", component);
            }
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Reads a <see cref=\"{0}\"/> from an <see cref=\"Ibasa.IO.BinaryReader\">.", Name);
            WriteLine("/// </summary>");
            WriteLine("public static {0} Read{0}(this Ibasa.IO.BinaryReader reader)", Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}({1});", Name, string.Join(", ", Components.Select(c => string.Format("reader.Read{0}()", Type.CLRName))));
            Dedent();
            WriteLine("}");
            WriteLine("#endregion");
            #endregion

            #region Operations
            WriteLine("#region Operations");
            if (Type.NegativeType != NumberType.Invalid)
            {
                var negQuaternion = new Quaternion(Type.NegativeType);

                WriteLine("/// <summary>");
                WriteLine("/// Returns the additive inverse of a quaternion.");
                WriteLine("/// </summary>");
                WriteLine("/// <param name=\"value\">A quaternion.</param>");
                WriteLine("/// <returns>The negative of value.</returns>");
                WriteLine("public static {0} Negative({1} value)", negQuaternion, Name);
                WriteLine("{");
                Indent();
                WriteLine("return new {0}({1});", negQuaternion,
                    string.Join(", ", Components.Select(component => "-value." + component)));
                Dedent();
                WriteLine("}");
            }

            WriteLine("/// <summary>");
            WriteLine("/// Adds two quaternions and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The first value to add.</param>");
            WriteLine("/// <param name=\"right\">The second value to add.</param>");
            WriteLine("/// <returns>The sum of left and right.</returns>");
            WriteLine("public static {0} Add({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}({1});", result,
                string.Join(", ", Components.Select(component => string.Format("left.{0} + right.{0}", component))));
            Dedent();
            WriteLine("}");

            WriteLine("/// <summary>");
            WriteLine("/// Subtracts one quaternion from another and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The value to subtract from (the minuend).</param>");
            WriteLine("/// <param name=\"right\">The value to subtract (the subtrahend).</param>");
            WriteLine("/// <returns>The result of subtracting right from left (the difference).</returns>");
            WriteLine("public static {0} Subtract({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}({1});", result,
                string.Join(", ", Components.Select(component => string.Format("left.{0} - right.{0}", component))));
            Dedent();
            WriteLine("}");

            WriteLine("/// <summary>");
            WriteLine("/// Returns the product of two quaternions.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The first value to add.</param>");
            WriteLine("/// <param name=\"right\">The second value to add.</param>");
            WriteLine("/// <returns>The product of the left and right parameters.</returns>");
            WriteLine("public static {0} Multiply({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}(", Name);
            WriteLine("\t(left.A * right.A) - ((left.B * right.B) + (left.C * right.C) + (left.D * right.D)),");
            WriteLine("\t(left.A * right.B) + (left.B * right.A) + (left.D * right.C) - (left.C * right.D),");
            WriteLine("\t(left.A * right.C) + (left.C * right.A) + (left.B * right.D) - (left.D * right.B),");
            WriteLine("\t(left.A * right.D) + (left.D * right.A) + (left.C * right.B) - (left.B * right.C));");
            Dedent();
            WriteLine("}");

            WriteLine("/// <summary>");
            WriteLine("/// Divides one quaternion by another and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The quaternion to be divided (the dividend).</param>");
            WriteLine("/// <param name=\"right\">The quaternion to divide by (the divisor).</param>");
            WriteLine("/// <returns>The result of dividing left by right (the quotient).</returns>");
            WriteLine("public static {0} Divide({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}(", Name);
            WriteLine("\t(left.A * right.A) - ((left.B * -right.B) + (left.C * -right.C) + (left.D * -right.D)) / AbsoluteSquared(right),");
            WriteLine("\t((left.A * -right.B) + (left.B * right.A) + (left.D * -right.C) - (left.C * -right.D)) / AbsoluteSquared(right),");
            WriteLine("\t((left.A * -right.C) + (left.C * right.A) + (left.B * -right.D) - (left.D * -right.B)) / AbsoluteSquared(right),");
            WriteLine("\t((left.A * -right.D) + (left.D * right.A) + (left.C * -right.B) - (left.B * -right.C)) / AbsoluteSquared(right));");
            Dedent();
            WriteLine("}");
            WriteLine("#endregion");
            #endregion

            #region Equatable
            WriteLine("#region Equatable");
            WriteLine("/// <summary>");
            WriteLine("/// Returns a value that indicates whether two quaternions are equal.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The first quaternion to compare.</param>");
            WriteLine("/// <param name=\"right\">The second quaternion to compare.</param>");
            WriteLine("/// <returns>true if the left and right are equal; otherwise, false.</returns>");
            WriteLine("public static bool Equals({0} left, {0} right)", Name);
            WriteLine("{");
            Indent();
            WriteLine("return left == right;");
            Dedent();
            WriteLine("}");
            WriteLine("#endregion");
            #endregion

            #region Test
            WriteLine("#region Test");
            WriteLine("/// <summary>");
            WriteLine("/// Determines whether all components of a quaternion are non-zero.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>true if all components are non-zero; false otherwise.</returns>");
            if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            WriteLine("public static bool All({0} value)", Name);
            WriteLine("{");
            Indent();
            WriteLine("return {0};",
                string.Join(" && ", Components.Select(component => string.Format("value.{0} != 0", component))));
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Determines whether all components of a quaternion satisfy a condition.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <param name=\"predicate\">A function to test each component for a condition.</param>");
            WriteLine("/// <returns>true if every component of the quaternion passes the test in the specified");
            WriteLine("/// predicate; otherwise, false.</returns>");
            if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            WriteLine("public static bool All({0} value, Predicate<{1}> predicate)", Name, Type);
            WriteLine("{");
            Indent();
            WriteLine("return {0};",
                string.Join(" && ", Components.Select(component => string.Format("predicate(value.{0})", component))));
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Determines whether any component of a quaternion is non-zero.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>true if any components are non-zero; false otherwise.</returns>");
            if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            WriteLine("public static bool Any({0} value)", Name);
            WriteLine("{");
            Indent();
            WriteLine("return {0};",
                string.Join(" || ", Components.Select(component => string.Format("value.{0} != 0", component))));
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Determines whether any components of a quaternion satisfy a condition.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <param name=\"predicate\">A function to test each component for a condition.</param>");
            WriteLine("/// <returns>true if any component of the quaternion passes the test in the specified");
            WriteLine("/// predicate; otherwise, false.</returns>");
            if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            WriteLine("public static bool Any({0} value, Predicate<{1}> predicate)", Name, Type);
            WriteLine("{");
            Indent();
            WriteLine("return {0};",
                string.Join(" || ", Components.Select(component => string.Format("predicate(value.{0})", component))));
            Dedent();
            WriteLine("}");
            WriteLine("#endregion");
            #endregion

            #region Properties
            
            WriteLine("#region Properties");

            WriteLine("/// <summary>");
            WriteLine("/// Return the axis angle representation of a unit quaternion.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A unit quaternion.</param>");
            WriteLine("/// <returns>The axis angle of a quaternion.</returns>");
            WriteLine("public static Tuple<{0}, {1}> AxisAngle({2} value)", new Vector(Type, 3), Type, Name);
            WriteLine("{");
            Indent();
            WriteLine("var s = Functions.Sqrt(1 - value.A - value.A);");
            WriteLine("return Tuple.Create(");
            WriteLine("\tnew {0}(value.B / s, value.C / s, value.D / s),", new Vector(Type, 3));
            WriteLine("\t2 * Functions.Acos(value.A));");
            Dedent();
            WriteLine("}");

            WriteLine("/// <summary>");
            WriteLine("/// Return real part of a quaternion.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The real part of a quaternion.</returns>");
            WriteLine("public static {0} Real({0} value)", Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}(value.A, 0, 0, 0);", Name);
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Return imaginary part of a quaternion.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The imaginary part of a quaternion.</returns>");
            WriteLine("public static {0} Imaginary({0} value)", Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}(0, value.B, value.C, value.D);", Name);
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Computes the absolute squared value of a quaternion and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The absolute squared value of value.</returns>");
            WriteLine("public static {0} AbsoluteSquared({1} value)", Type.PositiveType, Name);
            WriteLine("{");
            Indent();
            WriteLine("return (value.A * value.A + value.B * value.B + value.C * value.C + value.D * value.D);");
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Computes the absolute value (or modulus or magnitude) of a quaternion and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The absolute value of value.</returns>");
            WriteLine("public static {0} Absolute({1} value)", Type.RealType, Name);
            WriteLine("{");
            Indent();
            WriteLine("return Functions.Sqrt(value.A * value.A + value.B * value.B + value.C * value.C + value.D * value.D);");
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Computes the normalized value (or unit) of a quaternion.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The normalized value of value.</returns>");
            WriteLine("public static {0} Normalize({0} value)", Name);
            WriteLine("{");
            Indent();
            WriteLine("var absolute = Absolute(value);");
            WriteLine("if(absolute <= {0}.Epsilon)", Type.RealType);
            WriteLine("{");
            Indent();
            WriteLine("return {0}.Zero;", Name);
            Dedent();
            WriteLine("}");
            WriteLine("return value / absolute;");
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Returns the multiplicative inverse of a quaternion.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The reciprocal of value.</returns>");
            WriteLine("public static {0} Reciprocal({0} value)", Name);
            WriteLine("{");
            Indent();
            WriteLine("var absoluteSquared = AbsoluteSquared(value);");
            WriteLine("return new {0}(", Name);
            WriteLine("\tvalue.A / absoluteSquared,");
            WriteLine("\t-value.B / absoluteSquared,");
            WriteLine("\t-value.C / absoluteSquared,");
            WriteLine("\t-value.D / absoluteSquared);");
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Computes the conjugate of a quaternion and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The conjugate of value.</returns>");
            WriteLine("public static {0} Conjugate({0} value)", Name);
            WriteLine("{");
            Indent();
            WriteLine("return new {0}(value.A, -value.B, -value.C, -value.D);", Name);
            Dedent();
            WriteLine("}");
            WriteLine("/// <summary>");
            WriteLine("/// Computes the argument of a quaternion and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The argument of value.</returns>");
            WriteLine("public static {0} Argument({1} value)", Type.RealType, Name);
            WriteLine("{");
            Indent();
            WriteLine("return Functions.Atan2(Absolute(Imaginary(value)), value.A);");
            Dedent();
            WriteLine("}");
            WriteLine("#endregion");
            #endregion
            
            #region Product
            WriteLine("#region Product");
            WriteLine("/// <summary>");
            WriteLine("/// Calculates the dot product (inner product) of two quaternions.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">First source quaternion.</param>");
            WriteLine("/// <param name=\"right\">Second source quaternion.</param>");
            WriteLine("/// <returns>The dot product of the two quaternions.</returns>");
            WriteLine("public static {0} Dot({1} left, {1} right)", Type, Name);
            Indent("{");
            WriteLine("return left.A * right.A + left.B * right.B + left.C * right.C + left.D * right.D;");
            Dedent("}");
            WriteLine("#endregion");
            #endregion

            #region Interpolation
            WriteLine("#region Interpolation");
            WriteLine("/// <summary>");
            WriteLine("/// Performs a linear interpolation between two quaternions.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"start\">Start quaternion.</param>");
            WriteLine("/// <param name=\"end\">End quaternion.</param>");
            WriteLine("/// <param name=\"amount\">Value between 0 and 1 indicating the weight of <paramref name=\"end\"/>.</param>");
            WriteLine("/// <returns>The linear interpolation of the two quaternions.</returns>");
            WriteLine("/// <remarks>");
            WriteLine("/// This method performs the linear interpolation based on the following formula.");
            WriteLine("/// <code>start + (end - start) * amount</code>");
            WriteLine("/// Passing <paramref name=\"amount\"/> a value of 0 will cause <paramref name=\"start\"/> to be returned; a value of 1 will cause <paramref name=\"end\"/> to be returned. ");
            WriteLine("/// </remarks>");
            WriteLine("public static {0} Lerp({0} start, {0} end, {1} amount)", Name, Type);
            Indent("{");
            WriteLine("return new {0}(", Name);
            WriteLine("\tFunctions.Lerp(start.A, end.A, amount),");
            WriteLine("\tFunctions.Lerp(start.B, end.B, amount),");
            WriteLine("\tFunctions.Lerp(start.C, end.C, amount),");
            WriteLine("\tFunctions.Lerp(start.D, end.D, amount));");
            Dedent("}");
            WriteLine("/// <summary>");
            WriteLine("/// Interpolates between two unit quaternions, using spherical linear interpolation.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"start\">Start quaternion.</param>");
            WriteLine("/// <param name=\"end\">End quaternion.</param>");
            WriteLine("/// <param name=\"amount\">Value between 0 and 1 indicating the weight of <paramref name=\"end\"/>.</param>");
            WriteLine("/// <returns>The spherical linear interpolation of the two quaternions.</returns>");
            WriteLine("///  <remarks>");
            WriteLine("/// Passing <paramref name=\"amount\"/> a value of 0 will cause <paramref name=\"start\"/> to be returned; a value of 1 will cause <paramref name=\"end\"/> to be returned. ");
            WriteLine("/// </remarks>");
            WriteLine("public static {0} Slerp({0} start, {0} end, {1} amount)", Name, Type);
            Indent("{");
            WriteLine("var cosTheta = Dot(start, end);");
            WriteLine("//Cannot use slerp, use lerp instead");
            WriteLine("if (Functions.Abs(cosTheta) - 1 < {0}.Epsilon)", Type);
            Indent("{");
            WriteLine("return Lerp(start, end, amount);");
            Dedent("}");
            WriteLine("var theta = Functions.Acos(cosTheta);");
            WriteLine("var sinTheta = Functions.Sin(theta);");
            WriteLine("var t0 = Functions.Sin((1 - amount) * theta) / sinTheta;");
            WriteLine("var t1 = Functions.Sin(amount * theta) / sinTheta;");
            WriteLine("return t0 * start + t1 * end;");
            Dedent("}");
            WriteLine("#endregion");
            #endregion

            #region Transform
            WriteLine("#region Transform");

            var vector4 = new Vector(Type, 4);

            WriteLine("public static {0} Transform({0} vector, {1} rotation)", vector4, Name);
            Indent("{");
            WriteLine("var v = rotation * new {0}(vector.X, vector.Y, vector.Z, 0) * Conjugate(rotation);", Name);
            WriteLine("return new {0}(v.A, v.B, v.C, vector.W);", vector4);
            Dedent("}");
            
            var vector3 = new Vector(Type, 3);

            WriteLine("public static {0} Transform({0} vector, {1} rotation)", vector3, Name);
            Indent("{");
            WriteLine("var v = rotation * new {0}(vector.X, vector.Y, vector.Z, 0) * Conjugate(rotation);", Name);
            WriteLine("return new {0}(v.A, v.B, v.C);", vector3);
            Dedent("}");

            WriteLine("#endregion");
            #endregion

            #region Old
            //#region Per component
            //WriteLine("#region Per component");

            //WriteLine("#region Transform");
            //foreach (var type in Types)
            //{
            //    var transform = new Quaternion(type, Dimension);

            //    WriteLine("/// <summary>");
            //    WriteLine("/// Transforms the components of a quaternion and returns the result.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">The quaternion to transform.</param>");
            //    WriteLine("/// <param name=\"transformer\">A transform function to apply to each component.</param>");
            //    WriteLine("/// <returns>The result of transforming each component of value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Transform({1} value, Func<{2}, {3}> transformer)", transform, Name, Type, transform.Type);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", transform,
            //        string.Join(", ", Components.Select(component => string.Format("transformer(value.{0})", component))));
            //    Dedent();
            //    WriteLine("}");
            //}
            //WriteLine("#endregion");

            //WriteLine("/// <summary>");
            //WriteLine("/// Multiplys the components of two quaternions and returns the result.");
            //WriteLine("/// </summary>");
            //WriteLine("/// <param name=\"left\">The first quaternion to modulate.</param>");
            //WriteLine("/// <param name=\"right\">The second quaternion to modulate.</param>");
            //WriteLine("/// <returns>The result of multiplying each component of left by the matching component in right.</returns>");
            //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //WriteLine("public static {0} Modulate({1} left, {1} right)", result, Name);
            //WriteLine("{");
            //Indent();
            //WriteLine("return new {0}({1});", result,
            //    string.Join(", ", Components.Select(component => string.Format("left.{0} * right.{0}", component))));
            //Dedent();
            //WriteLine("}");
            //WriteLine("/// <summary>");
            //WriteLine("/// Returns the absolute value (per component).");
            //WriteLine("/// </summary>");
            //WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //WriteLine("/// <returns>The absolute value (per component) of value.</returns>");
            //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //WriteLine("public static {0} Abs({0} value)", Name);
            //WriteLine("{");
            //Indent();
            //WriteLine("return new {0}({1});", Name,
            //    string.Join(", ", Components.Select(component => string.Format("Functions.Abs(value.{0})", component))));
            //Dedent();
            //WriteLine("}");
            //WriteLine("/// <summary>");
            //WriteLine("/// Returns a quaternion that contains the lowest value from each pair of components.");
            //WriteLine("/// </summary>");
            //WriteLine("/// <param name=\"value1\">The first quaternion.</param>");
            //WriteLine("/// <param name=\"value2\">The second quaternion.</param>");
            //WriteLine("/// <returns>The lowest of each component in left and the matching component in right.</returns>");
            //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //WriteLine("public static {0} Min({0} value1, {0} value2)", Name);
            //WriteLine("{");
            //Indent();
            //WriteLine("return new {0}({1});", Name,
            //    string.Join(", ", Components.Select(component => string.Format("Functions.Min(value1.{0}, value2.{0})", component))));
            //Dedent();
            //WriteLine("}");
            //WriteLine("/// <summary>");
            //WriteLine("/// Returns a quaternion that contains the highest value from each pair of components.");
            //WriteLine("/// </summary>");
            //WriteLine("/// <param name=\"value1\">The first quaternion.</param>");
            //WriteLine("/// <param name=\"value2\">The second quaternion.</param>");
            //WriteLine("/// <returns>The highest of each component in left and the matching component in right.</returns>");
            //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //WriteLine("public static {0} Max({0} value1, {0} value2)", Name);
            //WriteLine("{");
            //Indent();
            //WriteLine("return new {0}({1});", Name,
            //    string.Join(", ", Components.Select(component => string.Format("Functions.Max(value1.{0}, value2.{0})", component))));
            //Dedent();
            //WriteLine("}");
            //WriteLine("/// <summary>");
            //WriteLine("/// Constrains each component to a given range.");
            //WriteLine("/// </summary>");
            //WriteLine("/// <param name=\"value\">A quaternion to constrain.</param>");
            //WriteLine("/// <param name=\"min\">The minimum values for each component.</param>");
            //WriteLine("/// <param name=\"max\">The maximum values for each component.</param>");
            //WriteLine("/// <returns>A quaternion with each component constrained to the given range.</returns>");
            //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //WriteLine("public static {0} Clamp({0} value, {0} min, {0} max)", Name);
            //WriteLine("{");
            //Indent();
            //WriteLine("return new {0}({1});", Name,
            //    string.Join(", ", Components.Select(component => string.Format("Functions.Clamp(value.{0}, min.{0}, max.{0})", component))));
            //Dedent();
            //WriteLine("}");
            //if (Type.IsReal)
            //{
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Constrains each component to the range 0 to 1.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion to saturate.</param>");
            //    WriteLine("/// <returns>A quaternion with each component constrained to the range 0 to 1.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Saturate({0} value)", Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", Name,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Saturate(value.{0})", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is the smallest integral value that");
            //    WriteLine("/// is greater than or equal to the specified component.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <returns>The ceiling of value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Ceiling({1} value)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Ceiling(value.{0})", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is the largest integral value that");
            //    WriteLine("/// is less than or equal to the specified component.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <returns>The floor of value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Floor({1} value)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Floor(value.{0})", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is the integral part of the specified component.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <returns>The integral of value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Truncate({1} value)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Truncate(value.{0})", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is the fractional part of the specified component.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <returns>The fractional of value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Fractional({1} value)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Fractional(value.{0})", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is rounded to the nearest integral value.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <returns>The result of rounding value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Round({1} value)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Round(value.{0})", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is rounded to the nearest integral value.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <param name=\"digits\">The number of fractional digits in the return value.</param>");
            //    WriteLine("/// <returns>The result of rounding value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Round({1} value, int digits)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Round(value.{0}, digits)", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is rounded to the nearest integral value.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <param name=\"mode\">Specification for how to round value if it is midway between two other numbers.</param>");
            //    WriteLine("/// <returns>The result of rounding value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Round({1} value, MidpointRounding mode)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Round(value.{0}, mode)", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns a quaternion where each component is rounded to the nearest integral value.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <param name=\"digits\">The number of fractional digits in the return value.</param>");
            //    WriteLine("/// <param name=\"mode\">Specification for how to round value if it is midway between two other numbers.</param>");
            //    WriteLine("/// <returns>The result of rounding value.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Round({1} value, int digits, MidpointRounding mode)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("Functions.Round(value.{0}, digits, mode)", component))));
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Calculates the reciprocal of each component in the quaternion.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value\">A quaternion.</param>");
            //    WriteLine("/// <returns>A quaternion with the reciprocal of each of values components.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Reciprocal({1} value)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return new {0}({1});", result,
            //        string.Join(", ", Components.Select(component => string.Format("1 / value.{0}", component))));
            //    Dedent();
            //    WriteLine("}");
            //}
            //WriteLine("#endregion");
            //#endregion

            //#region Barycentric, Reflect, Refract
            //if (Type.IsReal)
            //{
            //    WriteLine("#region Barycentric, Reflect, Refract");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns the Cartesian coordinate for one axis of a point that is defined");
            //    WriteLine("/// by a given triangle and two normalized barycentric (areal) coordinates.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value1\">The coordinate of vertex 1 of the defining triangle.</param>");
            //    WriteLine("/// <param name=\"value2\">The coordinate of vertex 2 of the defining triangle.</param>");
            //    WriteLine("/// <param name=\"value3\">The coordinate of vertex 3 of the defining triangle.</param>");
            //    WriteLine("/// <param name=\"amount1\">The normalized barycentric (areal) coordinate b2, equal to the weighting");
            //    WriteLine("/// factor for vertex 2, the coordinate of which is specified in value2.</param>");
            //    WriteLine("/// <param name=\"amount2\">The normalized barycentric (areal) coordinate b3, equal to the weighting");
            //    WriteLine("/// factor for vertex 3, the coordinate of which is specified in value3.</param>");
            //    WriteLine("/// <returns>Cartesian coordinate of the specified point.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Barycentric({1} value1, {1} value2, {1} value3, {2} amount1, {2} amount2)", result, Name, result.Type);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return ((1 - amount1 - amount2) * value1) + (amount1 * value2) + (amount2 * value3);");
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns the reflection of a quaternion off a surface that has the specified normal.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"quaternion\">The source quaternion.</param>");
            //    WriteLine("/// <param name=\"normal\">Normal of the surface.</param>");
            //    WriteLine("/// <returns>The reflected quaternion.</returns>");
            //    WriteLine("/// <remarks>Reflect only gives the direction of a reflection off a surface, it does not determine");
            //    WriteLine("/// whether the original quaternion was close enough to the surface to hit it.</remarks>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Reflect({1} quaternion, {1} normal)", result, Name);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return quaternion - ((2 * Dot(quaternion, normal)) * normal);");
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Returns the refraction of a quaternion off a surface that has the specified normal, and refractive index.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"quaternion\">The source quaternion.</param>");
            //    WriteLine("/// <param name=\"normal\">Normal of the surface.</param>");
            //    WriteLine("/// <param name=\"index\">The refractive index, destination index over source index.</param>");
            //    WriteLine("/// <returns>The refracted quaternion.</returns>");
            //    WriteLine("/// <remarks>Refract only gives the direction of a refraction off a surface, it does not determine");
            //    WriteLine("/// whether the original quaternion was close enough to the surface to hit it.</remarks>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Refract({1} quaternion, {1} normal, {2} index)", result, Name, result.Type);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("var cos1 = Dot(quaternion, normal);");
            //    WriteLine("var radicand = 1 - (index * index) * (1 - (cos1 * cos1));");
            //    WriteLine("if (radicand < 0)");
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return {0}.Zero;", result);
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("return (index * quaternion) + ((Functions.Sqrt(radicand) - index * cos1) * normal);");
            //    Dedent();
            //    WriteLine("}");
            //    WriteLine("#endregion");
            //}
            //#endregion

            //#region Interpolation
            //if (Type.IsReal)
            //{
            //    WriteLine("#region Interpolation");
            //    //WriteLine("/// <summary>");
            //    //WriteLine("/// Performs a Hermite spline interpolation.");
            //    //WriteLine("/// </summary>");
            //    //WriteLine("/// <param name=\"value1\">First source position.</param>");
            //    //WriteLine("/// <param name=\"tangent1\">First source tangent.</param>");
            //    //WriteLine("/// <param name=\"value2\">Second source position.</param>");
            //    //WriteLine("/// <param name=\"tangent2\">Second source tangent.</param>");
            //    //WriteLine("/// <param name=\"amount\">Weighting factor.</param>");
            //    //WriteLine("/// <returns>The result of the Hermite spline interpolation.</returns>");
            //    //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); } 
            //    //WriteLine("public static {0} Hermite({1} value1, {1} tangent1, {1} value2, {1} tangent2, {2} amount)", result, Name, result.Type);
            //    //WriteLine("{");
            //    //Indent();
            //    //WriteLine("var amount2 = amount * amount;");
            //    //WriteLine("var amount3 = amount2 * amount;");
            //    //WriteLine("var h00 = 2 * amount3 - 3 * amount2 + 1;");
            //    //WriteLine("var h10 = amount3 - 2 * amount2 + amount;");
            //    //WriteLine("var h01 = -2 * amount3 + 3 * amount2;");
            //    //WriteLine("var h11 = amount3 - amount2;");
            //    //WriteLine("return h00 * value1 + h10 * tangent1 + h01 * value2 + h11 * tangent2;");
            //    //Dedent();
            //    //WriteLine("}");
            //    //WriteLine("/// <summary>");
            //    //WriteLine("/// Performs a Catmull-Rom interpolation using the specified positions.");
            //    //WriteLine("/// </summary>");
            //    //WriteLine("/// <param name=\"value1\">The first position in the interpolation.</param>");
            //    //WriteLine("/// <param name=\"value2\">The second position in the interpolation.</param>");
            //    //WriteLine("/// <param name=\"value3\">The third position in the interpolation.</param>");
            //    //WriteLine("/// <param name=\"value4\">The fourth position in the interpolation.</param>");
            //    //WriteLine("/// <param name=\"amount\">Weighting factor.</param>");
            //    //WriteLine("/// <returns>A quaternion that is the result of the Catmull-Rom interpolation.</returns>");
            //    //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    //WriteLine("public static {0} CatmullRom({1} value1, {1} value2, {1} value3, {1} value4, {2} amount)", result, Name, result.Type);
            //    //WriteLine("{");
            //    //Indent();
            //    //WriteLine("var tangent0 = (value3 - value1) / 2;");
            //    //WriteLine("var tangent1 = (value4 - value2) / 2;");
            //    //WriteLine("return Hermite(value2, tangent0, value3, tangent1, amount);");
            //    //Dedent();
            //    //WriteLine("}");
            //    //WriteLine("/// <summary>");
            //    //WriteLine("/// Performs a cubic interpolation between two values.");
            //    //WriteLine("/// </summary>");
            //    //WriteLine("/// <param name=\"value1\">First values.</param>");
            //    //WriteLine("/// <param name=\"value2\">Second values.</param>");
            //    //WriteLine("/// <param name=\"amount\">Value between 0 and 1 indicating the weight of <paramref name=\"value2\"/>.</param>");
            //    //WriteLine("/// <returns>The cubic interpolation of the two quaternions.</returns>");
            //    //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    //WriteLine("public static {0} SmoothStep({1} value1, {1} value2, {2} amount)", result, Name, result.Type);
            //    //WriteLine("{");
            //    //Indent();
            //    //WriteLine("amount = Functions.Saturate(amount);");
            //    //WriteLine("amount = amount * amount * (3 - 2 * amount);");
            //    //WriteLine("return Lerp(value1, value2, amount);");
            //    //Dedent();
            //    //WriteLine("}");
            //    WriteLine("/// <summary>");
            //    WriteLine("/// Performs a linear interpolation between two values.");
            //    WriteLine("/// </summary>");
            //    WriteLine("/// <param name=\"value1\">First value.</param>");
            //    WriteLine("/// <param name=\"value2\">Second value.</param>");
            //    WriteLine("/// <param name=\"amount\">Value between 0 and 1 indicating the weight of <paramref name=\"value2\"/>.</param>");
            //    WriteLine("/// <returns>The linear interpolation of the two values.</returns>");
            //    if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    WriteLine("public static {0} Lerp({1} value1, {1} value2, {2} amount)", result, Name, result.Type);
            //    WriteLine("{");
            //    Indent();
            //    WriteLine("return (1 - amount) * value1 + amount * value2;");
            //    Dedent();
            //    WriteLine("}");
            //    //WriteLine("/// <summary>");
            //    //WriteLine("/// Performs a quadratic interpolation between three values.");
            //    //WriteLine("/// </summary>");
            //    //WriteLine("/// <param name=\"value1\">First value.</param>");
            //    //WriteLine("/// <param name=\"value2\">Second value.</param>");
            //    //WriteLine("/// <param name=\"value3\">Third value.</param>");
            //    //WriteLine("/// <param name=\"amount\">Value between 0 and 1 indicating the weight towards <paramref name=\"value3\"/>.</param>");
            //    //WriteLine("/// <returns>The quadratic interpolation of the three values.</returns>");
            //    //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    //WriteLine("public static {0} Qerp({1} value1, {1} value2, {1} value3, {2} amount)", result, Name, result.Type);
            //    //WriteLine("{");
            //    //Indent();
            //    //WriteLine("var p = 2 * value1 - value2 + 2 * value3;");
            //    //WriteLine("var q = value2 - value3 - 3 * value1;");
            //    //WriteLine("var r = value1;");
            //    //WriteLine("var amount2 = amount * amount;");
            //    //WriteLine("return (p * amount * amount2) + (q * amount) + (r);");
            //    //Dedent();
            //    //WriteLine("}");
            //    //WriteLine("/// <summary>");
            //    //WriteLine("/// Performs a cubic interpolation between four values.");
            //    //WriteLine("/// </summary>");
            //    //WriteLine("/// <param name=\"value1\">First value.</param>");
            //    //WriteLine("/// <param name=\"value2\">Second value.</param>");
            //    //WriteLine("/// <param name=\"value3\">Third value.</param>");
            //    //WriteLine("/// <param name=\"value4\">Fourth value.</param>");
            //    //WriteLine("/// <param name=\"amount\">Value between 0 and 1 indicating the weight towards <paramref name=\"value4\"/>.</param>");
            //    //WriteLine("/// <returns>The cubic interpolation of the four values.</returns>");
            //    //if (!Type.IsCLSCompliant) { WriteLine("[CLSCompliant(false)]"); }
            //    //WriteLine("public static {0} Cerp({1} value1, {1} value2, {1} value3, {1} value4, {2} amount)", result, Name, result.Type);
            //    //WriteLine("{");
            //    //Indent();
            //    //WriteLine("var p = (value4 - value3) - (value1 - value2);");
            //    //WriteLine("var q = (value1 - value2) - p;");
            //    //WriteLine("var r = value3 - value1;");
            //    //WriteLine("var s = value2;");
            //    //WriteLine("var amount2 = amount * amount;");
            //    //WriteLine("return (p * amount * amount2) + (q * amount2) + (r * amount) + (s);");
            //    //Dedent();
            //    //WriteLine("}");
            //    WriteLine("#endregion");
            //}
            //#endregion
            #endregion

            Dedent();
            WriteLine("}");
        }
Beispiel #4
0
        void Operations()
        {
            var result = new Quaternion(Type.PositiveType);

            WriteLine("#region Operations");

            WriteLine("/// <summary>");
            WriteLine("/// Returns the identity of a specified quaternion.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"value\">A quaternion.</param>");
            WriteLine("/// <returns>The identity of value.</returns>");
            WriteLine("public static {0} operator +({1} value)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return value;");
            Dedent();
            WriteLine("}");

            if (Type.NegativeType != NumberType.Invalid)
            {
                var negQuaternion = new Quaternion(Type.NegativeType);

                WriteLine("/// <summary>");
                WriteLine("/// Returns the additive inverse of a specified quaternion.");
                WriteLine("/// </summary>");
                WriteLine("/// <param name=\"value\">A quaternion.</param>");
                WriteLine("/// <returns>The negative of value.</returns>");
                WriteLine("public static {0} operator -({1} value)", negQuaternion, Name);
                WriteLine("{");
                Indent();
                WriteLine("return Quaternion.Negative(value);");
                Dedent();
                WriteLine("}");
            }

            WriteLine("/// <summary>");
            WriteLine("/// Adds two quaternions and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The first value to add.</param>");
            WriteLine("/// <param name=\"right\">The second value to add.</param>");
            WriteLine("/// <returns>The sum of left and right.</returns>");
            WriteLine("public static {0} operator +({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return Quaternion.Add(left, right);");
            Dedent();
            WriteLine("}");

            WriteLine("/// <summary>");
            WriteLine("/// Subtracts one quaternion from another and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The value to subtract from (the minuend).</param>");
            WriteLine("/// <param name=\"right\">The value to subtract (the subtrahend).</param>");
            WriteLine("/// <returns>The result of subtracting right from left (the difference).</returns>");
            WriteLine("public static {0} operator -({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return Quaternion.Subtract(left, right);");
            Dedent();
            WriteLine("}");

            WriteLine("/// <summary>");
            WriteLine("/// Multiplies one quaternion by another and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The first value to add.</param>");
            WriteLine("/// <param name=\"right\">The second value to add.</param>");
            WriteLine("/// <returns>The product of the left and right parameters.</returns>");
            WriteLine("public static {0} operator *({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return Quaternion.Multiply(left, right);");
            Dedent();
            WriteLine("}");

            WriteLine("/// <summary>");
            WriteLine("/// Divides one quaternion by another and returns the result.");
            WriteLine("/// </summary>");
            WriteLine("/// <param name=\"left\">The quaternion to be divided (the dividend).</param>");
            WriteLine("/// <param name=\"right\">The quaternion to divide by (the divisor).</param>");
            WriteLine("/// <returns>The result of dividing left by right (the quotient).</returns>");
            WriteLine("public static {0} operator /({1} left, {1} right)", result, Name);
            WriteLine("{");
            Indent();
            WriteLine("return Quaternion.Divide(left, right);");
            Dedent();
            WriteLine("}");

            WriteLine("#endregion");
        }