From 9dd4023f4a0e2dbf2f92ec7a6d6598b573897f9c Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Tue, 2 Mar 2021 12:53:16 +0100 Subject: [PATCH] Added row-wise constructor to matrix types --- .../Primitives/Float/Matrix/FloatMxN.g.cs | 171 ++++++++++++++++++ .../Core/Primitives/MatrixType.ttinclude | 37 +++- 2 files changed, 207 insertions(+), 1 deletion(-) diff --git a/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs index 0670a69b..7e798335 100644 --- a/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs +++ b/src/ComputeSharp/Core/Primitives/Float/Matrix/FloatMxN.g.cs @@ -474,6 +474,19 @@ namespace ComputeSharp this.m22 = m22; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + public Float2x2(Float2 row1, Float2 row2) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m21 = row2.X; + this.m22 = row2.Y; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -580,6 +593,21 @@ namespace ComputeSharp this.m23 = m23; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + public Float2x3(Float3 row1, Float3 row2) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m13 = row1.Z; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m23 = row2.Z; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -696,6 +724,23 @@ namespace ComputeSharp this.m24 = m24; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + public Float2x4(Float4 row1, Float4 row2) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m13 = row1.Z; + this.m14 = row1.W; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m23 = row2.Z; + this.m24 = row2.W; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -893,6 +938,22 @@ namespace ComputeSharp this.m32 = m32; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + /// The value to assign to the row at position [3]. + public Float3x2(Float2 row1, Float2 row2, Float2 row3) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m31 = row3.X; + this.m32 = row3.Y; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -1014,6 +1075,25 @@ namespace ComputeSharp this.m33 = m33; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + /// The value to assign to the row at position [3]. + public Float3x3(Float3 row1, Float3 row2, Float3 row3) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m13 = row1.Z; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m23 = row2.Z; + this.m31 = row3.X; + this.m32 = row3.Y; + this.m33 = row3.Z; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -1150,6 +1230,28 @@ namespace ComputeSharp this.m34 = m34; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + /// The value to assign to the row at position [3]. + public Float3x4(Float4 row1, Float4 row2, Float4 row3) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m13 = row1.Z; + this.m14 = row1.W; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m23 = row2.Z; + this.m24 = row2.W; + this.m31 = row3.X; + this.m32 = row3.Y; + this.m33 = row3.Z; + this.m34 = row3.W; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -1362,6 +1464,25 @@ namespace ComputeSharp this.m42 = m42; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + /// The value to assign to the row at position [3]. + /// The value to assign to the row at position [4]. + public Float4x2(Float2 row1, Float2 row2, Float2 row3, Float2 row4) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m31 = row3.X; + this.m32 = row3.Y; + this.m41 = row4.X; + this.m42 = row4.Y; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -1498,6 +1619,29 @@ namespace ComputeSharp this.m43 = m43; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + /// The value to assign to the row at position [3]. + /// The value to assign to the row at position [4]. + public Float4x3(Float3 row1, Float3 row2, Float3 row3, Float3 row4) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m13 = row1.Z; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m23 = row2.Z; + this.m31 = row3.X; + this.m32 = row3.Y; + this.m33 = row3.Z; + this.m41 = row4.X; + this.m42 = row4.Y; + this.m43 = row4.Z; + } + /// /// Gets a reference to a specific row in the current instance. /// @@ -1654,6 +1798,33 @@ namespace ComputeSharp this.m44 = m44; } + /// + /// Creates a new instance with the specified parameters. + /// + /// The value to assign to the row at position [1]. + /// The value to assign to the row at position [2]. + /// The value to assign to the row at position [3]. + /// The value to assign to the row at position [4]. + public Float4x4(Float4 row1, Float4 row2, Float4 row3, Float4 row4) + { + this.m11 = row1.X; + this.m12 = row1.Y; + this.m13 = row1.Z; + this.m14 = row1.W; + this.m21 = row2.X; + this.m22 = row2.Y; + this.m23 = row2.Z; + this.m24 = row2.W; + this.m31 = row3.X; + this.m32 = row3.Y; + this.m33 = row3.Z; + this.m34 = row3.W; + this.m41 = row4.X; + this.m42 = row4.Y; + this.m43 = row4.Z; + this.m44 = row4.W; + } + /// /// Gets a reference to a specific row in the current instance. /// diff --git a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude index 1a7b96fc..e15e2c5c 100644 --- a/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude +++ b/src/ComputeSharp/Core/Primitives/MatrixType.ttinclude @@ -55,7 +55,7 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen fieldNames.Add($"m{i}{j}"); } - // Generate the constructors + // Generate the elementwise constructor WriteLine("/// "); WriteLine($"/// Creates a new instance with the specified parameters."); WriteLine("/// "); @@ -79,6 +79,41 @@ void GenerateMatrixProperties(string typeName, int rows, int columns, int elemen WriteLine("}"); WriteLine(""); + // Generate the row-wise constructor, if needed + if (rows > 1 && columns > 1) + { + WriteLine("/// "); + WriteLine($"/// Creates a new instance with the specified parameters."); + WriteLine("/// "); + + for (int i = 1; i <= rows; i++) + { + WriteLine($"/// The value to assign to the row at position [{i}]."); + } + + Write($"public {fullTypeName}("); + + for (int i = 1; i <= rows; i++) + { + if (i > 1) Write(", "); + Write($"{rowTypeName} row{i}"); + } + + WriteLine(")"); + WriteLine("{"); + PushIndent(" "); + + for (int i = 1; i <= rows; i++) + for (int j = 1; j <= columns; j++) + { + WriteLine($"this.m{i}{j} = row{i}.{"XYZW"[j - 1]};"); + } + + PopIndent(); + WriteLine("}"); + WriteLine(""); + } + PopIndent(); PopIndent(); #>