Added new numeric types for unsigned integers, including uint2, uint3, and uint4, along with their matrix types. Added a new `quaternion` struct with constructors and methods for creating and manipulating quaternions. Added methods for projecting and reflecting vectors, enhancing geometric operations. Added utility functions for generating orthonormal bases and changing vector signs. Added comprehensive unit tests for new mathematical functions and quaternion operations. Added a high-performance job scheduling system with job management features and worker thread management. Added new structs for job execution, allowing efficient job scheduling and execution. Added utility functions for job execution, including methods for obtaining unique job IDs. Changed access modifiers and property definitions in several files for improved clarity and maintainability. Changed property definitions and method implementations in `ImageInfo.cs`, `ImageResult.cs`, and `ImageResultFloat.cs` for better readability. Changed memory management functions in `CRuntime.cs` and improved memory allocation tracking in `MemoryStats.cs`. Changed the project file to include references to necessary projects and enable unsafe code blocks. Removed the `WorkerThreadPool.cs` file, integrating worker thread management directly into the `JobScheduler`. Removed the `float4` struct and its associated methods and properties, transitioning to a new code generation strategy. Removed the `float4.tt` template and other related files, indicating a shift in code generation approach. Removed the `Vectorize.cs` file, indicating a change in how vector operations are handled. Updated the `.gitignore` file to include IDE-specific settings. Updated various XML files to define project components and structure. Updated the `AllocationManager.cs` to improve memory allocation management and introduce new strategies. Updated the `UnsafeArray.cs`, `UnsafeHashMap.cs`, and `UnsafeList.cs` to enhance performance and safety in unsafe contexts. Updated error handling and function pointer management in `MemoryLeakException.cs` and `FunctionPointer.cs`. Updated the `AssemblyInfo.cs` file to include global using directives for better code organization.
199 lines
4.8 KiB
C#
199 lines
4.8 KiB
C#
using Misaki.HighPerformance.Mathematics;
|
|
|
|
namespace Misaki.HighPerformance.Test.UnitTest.Mathematics;
|
|
|
|
[TestClass]
|
|
public class TestInt2x2
|
|
{
|
|
[TestMethod]
|
|
public void TestConstructors()
|
|
{
|
|
// Default constructor
|
|
var m1 = new int2x2();
|
|
|
|
// Column constructor
|
|
var c0 = new int2(1, 2);
|
|
var c1 = new int2(3, 4);
|
|
var m2 = new int2x2(c0, c1);
|
|
|
|
Assert.AreEqual(1, m2.c0.x);
|
|
Assert.AreEqual(2, m2.c0.y);
|
|
Assert.AreEqual(3, m2.c1.x);
|
|
Assert.AreEqual(4, m2.c1.y);
|
|
|
|
var m3 = new int2x2(1, 2, 3, 4);
|
|
Assert.AreEqual(1, m3.c0.x);
|
|
Assert.AreEqual(2, m3.c1.x);
|
|
Assert.AreEqual(3, m3.c0.y);
|
|
Assert.AreEqual(4, m3.c1.y);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestArithmeticOperators()
|
|
{
|
|
var a = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
var b = new int2x2(
|
|
new int2(5, 6),
|
|
new int2(7, 8)
|
|
);
|
|
|
|
// Addition
|
|
var add = a + b;
|
|
Assert.AreEqual(6, add.c0.x);
|
|
Assert.AreEqual(8, add.c0.y);
|
|
Assert.AreEqual(10, add.c1.x);
|
|
Assert.AreEqual(12, add.c1.y);
|
|
|
|
// Subtraction
|
|
var sub = b - a;
|
|
Assert.AreEqual(4, sub.c0.x);
|
|
Assert.AreEqual(4, sub.c0.y);
|
|
Assert.AreEqual(4, sub.c1.x);
|
|
Assert.AreEqual(4, sub.c1.y);
|
|
|
|
// Scalar multiplication
|
|
var scalarMul = a * 2;
|
|
Assert.AreEqual(2, scalarMul.c0.x);
|
|
Assert.AreEqual(4, scalarMul.c0.y);
|
|
Assert.AreEqual(6, scalarMul.c1.x);
|
|
Assert.AreEqual(8, scalarMul.c1.y);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestMatrixMultiplication()
|
|
{
|
|
var a = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
var b = new int2x2(
|
|
new int2(5, 6),
|
|
new int2(7, 8)
|
|
);
|
|
|
|
// Matrix multiplication
|
|
var mul = math.mul(a, b);
|
|
|
|
// Expected result: [1 3] * [5 7] = [1*5+3*6 1*7+3*8] = [23 31]
|
|
// [2 4] [6 8] [2*5+4*6 2*7+4*8] [34 46]
|
|
Assert.AreEqual(23, mul.c0.x);
|
|
Assert.AreEqual(34, mul.c0.y);
|
|
Assert.AreEqual(31, mul.c1.x);
|
|
Assert.AreEqual(46, mul.c1.y);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestMatrixVectorMultiplication()
|
|
{
|
|
var matrix = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
var vector = new int2(5, 6);
|
|
|
|
// Matrix-vector multiplication
|
|
var result = math.mul(matrix, vector);
|
|
|
|
// Expected: [1 3] * [5] = [1*5 + 3*6] = [23]
|
|
// [2 4] [6] [2*5 + 4*6] [34]
|
|
Assert.AreEqual(23, result.x);
|
|
Assert.AreEqual(34, result.y);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestTranspose()
|
|
{
|
|
var matrix = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
var transposed = math.transpose(matrix);
|
|
|
|
// [1 3] -> [1 2]
|
|
// [2 4] [3 4]
|
|
Assert.AreEqual(1, transposed.c0.x);
|
|
Assert.AreEqual(3, transposed.c0.y);
|
|
Assert.AreEqual(2, transposed.c1.x);
|
|
Assert.AreEqual(4, transposed.c1.y);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestDeterminant()
|
|
{
|
|
var matrix = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
var det = math.determinant(matrix);
|
|
|
|
// det = 1*4 - 2*3 = 4 - 6 = -2
|
|
Assert.AreEqual(-2, det);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestIdentityMatrix()
|
|
{
|
|
var identity = int2x2.identity;
|
|
|
|
var testMatrix = new int2x2(
|
|
new int2(5, 6),
|
|
new int2(7, 8)
|
|
);
|
|
|
|
var result = math.mul(identity, testMatrix);
|
|
|
|
Assert.AreEqual(testMatrix.c0.x, result.c0.x);
|
|
Assert.AreEqual(testMatrix.c0.y, result.c0.y);
|
|
Assert.AreEqual(testMatrix.c1.x, result.c1.x);
|
|
Assert.AreEqual(testMatrix.c1.y, result.c1.y);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestIndexer()
|
|
{
|
|
var matrix = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
Assert.AreEqual(1, matrix[0].x);
|
|
Assert.AreEqual(2, matrix[0].y);
|
|
Assert.AreEqual(3, matrix[1].x);
|
|
Assert.AreEqual(4, matrix[1].y);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void TestComparisonOperators()
|
|
{
|
|
var a = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
var b = new int2x2(
|
|
new int2(1, 2),
|
|
new int2(3, 4)
|
|
);
|
|
|
|
var c = new int2x2(
|
|
new int2(5, 6),
|
|
new int2(7, 8)
|
|
);
|
|
|
|
// Test equality
|
|
var isEqual = math.all(a.c0 == b.c0) && math.all(a.c1 == b.c1);
|
|
Assert.IsTrue(isEqual);
|
|
|
|
var isDifferent = math.any(a.c0 != c.c0) || math.any(a.c1 != c.c1);
|
|
Assert.IsTrue(isDifferent);
|
|
}
|
|
}
|