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); } }
void Conversions() { WriteLine("#region Conversions"); foreach (var type in Types.Where(t => t != Type)) { string imex = type.IsImplicitlyConvertibleTo(Type) ? "implicit" : "explicit"; Plane other = new Plane(type); var casts = string.Format("({0})value.Normal.X, ({0})value.Normal.Y, ({0})value.Normal.Z, ({0})value.D", Type); 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("#endregion"); }
void Functions() { WriteLine("/// <summary>"); WriteLine("/// Provides static methods for plane functions."); WriteLine("/// </summary>"); WriteLine("public static partial class Plane"); WriteLine("{"); Indent(); var result = new Plane(Type.PositiveType); #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} plane)", Name); WriteLine("{"); Indent(); WriteLine("writer.Write(plane.Normal.X);"); WriteLine("writer.Write(plane.Normal.Y);"); WriteLine("writer.Write(plane.Normal.Z);"); WriteLine("writer.Write(plane.D);"); 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}(reader.Read{1}(), reader.Read{1}(), reader.Read{1}(), reader.Read{1}());", Name, Type.CLRName); Dedent(); WriteLine("}"); WriteLine("#endregion"); #endregion #region Operations WriteLine("#region Operations"); WriteLine("/// <summary>"); WriteLine("/// Returns the product of a plane and scalar."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"plane\">The plane to multiply.</param>"); WriteLine("/// <param name=\"scalar\">The scalar to multiply.</param>"); WriteLine("/// <returns>The product of the left and right parameters.</returns>"); WriteLine("public static {0} Multiply({1} plane, {2} scalar)", result, Name, result.Type); WriteLine("{"); Indent(); WriteLine("return new {0}(plane.Normal.X * scalar, plane.Normal.Y * scalar, plane.Normal.Z * scalar, plane.D * scalar);", result); Dedent(); WriteLine("}"); WriteLine("#endregion"); #endregion #region Equatable WriteLine("#region Equatable"); WriteLine("/// <summary>"); WriteLine("/// Returns a value that indicates whether two planes are equal."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"left\">The first plane to compare.</param>"); WriteLine("/// <param name=\"right\">The second plane 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 Products WriteLine("#region Products"); WriteLine("/// <summary>"); WriteLine("/// Calculates the dot product of the specified vector and plane."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"plane\">The source plane.</param>"); WriteLine("/// <param name=\"vector\">The source vector.</param>"); WriteLine("/// <returns>The dot product of the specified point and plane.</returns>"); WriteLine("public static {0} Dot({1} plane, {2} vector)", Type, Name, new Vector(Type, 4)); Indent("{"); WriteLine("return (plane.Normal.X * vector.X) + (plane.Normal.Y * vector.Y) + (plane.Normal.Z * vector.Z) + (plane.D * vector.W);"); Dedent("}"); WriteLine("/// <summary>"); WriteLine("/// Calculates the dot product of a specified vector and the normal of the plane plus the distance value of the plane."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"plane\">The source plane.</param>"); WriteLine("/// <param name=\"point\">The source point.</param>"); WriteLine("/// <returns>The dot product of a specified vector and the normal of the Plane plus the distance value of the plane.</returns>"); WriteLine("public static {0} DotCoordinate({1} plane, {2} point)", Type, Name, new Point(Type, 3)); Indent("{"); WriteLine("return (plane.Normal.X * point.X) + (plane.Normal.Y * point.Y) + (plane.Normal.Z * point.Z) + plane.D;"); Dedent("}"); WriteLine("/// <summary>"); WriteLine("/// Calculates the dot product of the specified vector and the normal of the plane."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"plane\">The source plane.</param>"); WriteLine("/// <param name=\"normal\">The source vector.</param>"); WriteLine("/// <returns>The dot product of the specified vector and the normal of the plane.</returns>"); WriteLine("public static {0} DotNormal({1} plane, {2} normal)", Type, Name, new Vector(Type, 3)); Indent("{"); WriteLine("return (plane.Normal.X * normal.X) + (plane.Normal.Y * normal.Y) + (plane.Normal.Z * normal.Z);"); Dedent("}"); WriteLine("#endregion"); #endregion #region Normalize WriteLine("#region Normalize"); WriteLine("/// <summary>"); WriteLine("/// Changes the coefficients of the normal vector of a plane to make it of unit length."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"plane\">The plane to normalize.</param>"); WriteLine("/// <returns>A new plane with a normal having unit length.</returns>"); WriteLine("public static {0} Normalize({0} plane)", Name); Indent("{"); WriteLine("return new {0}(Vector.Normalize(plane.Normal), plane.D);", Name); Dedent("}"); WriteLine("#endregion"); #endregion Dedent(); WriteLine("}"); }
void Operations() { var result = new Plane(Type.PositiveType); WriteLine("#region Operations"); WriteLine("/// <summary>"); WriteLine("/// Scales the plane by the given scaling factor."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"plane\">The source plane.</param>"); WriteLine("/// <param name=\"scale\">The scaling factor.</param>"); WriteLine("/// <returns>The scaled plane.</returns>"); WriteLine("public static {0} operator *({0} plane, {1} scale)", Name, Type); Indent("{"); WriteLine("return Plane.Multiply(plane, scale);"); Dedent("}"); WriteLine("/// <summary>"); WriteLine("/// Scales the plane by the given scaling factor."); WriteLine("/// </summary>"); WriteLine("/// <param name=\"plane\">The source plane.</param>"); WriteLine("/// <param name=\"scale\">The scaling factor.</param>"); WriteLine("/// <returns>The scaled plane.</returns>"); WriteLine("public static {0} operator *({1} scale, {0} plane)", Name, Type); Indent("{"); WriteLine("return Plane.Multiply(plane, scale);"); Dedent("}"); WriteLine("#endregion"); }