fix(math): correct select logic in quaternion and svd
Fixed conditional selection logic in quaternion and SVD math functions by swapping select argument order for correctness. Fixed LookRotationSafe and normalizesafe to return valid quaternions. Corrected SVD helper functions for proper value swapping and safe reciprocal. Added unit tests for matrix, reflection, projection, refraction, quaternion normalization, LookRotationSafe, and SVD operations. Incremented project version to 1.3.3. Minor formatting and using directive updates.
This commit is contained in:
@@ -151,6 +151,18 @@ public class TestQuaternion
|
||||
Assert.AreEqual(1f, math.length(normalized.value), 1e-6f);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestQuaternionNormalizeSafe()
|
||||
{
|
||||
// Create non-unit quaternion
|
||||
var q = new quaternion(1f, 2f, 3f, 4f);
|
||||
|
||||
var normalized = math.normalizesafe(q);
|
||||
|
||||
// Should have length 1
|
||||
Assert.AreEqual(1f, math.length(normalized.value), 1e-6f);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMatrixFromQuaternion()
|
||||
{
|
||||
@@ -240,4 +252,27 @@ public class TestQuaternion
|
||||
Assert.AreEqual(1f, rotatedUp.y, 1e-6f);
|
||||
Assert.AreEqual(0f, rotatedUp.z, 1e-6f);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestLookRotationSafe()
|
||||
{
|
||||
var forward = new float3(0f, 0f, -1f);
|
||||
var up = new float3(0f, 1f, 0f);
|
||||
var q = quaternion.LookRotationSafe(forward, up);
|
||||
|
||||
// Should be unit quaternion
|
||||
Assert.AreEqual(1f, math.length(q.value), 1e-6f);
|
||||
|
||||
// Should rotate (0,0,1) to approximately (0,0,1)
|
||||
var rotatedForward = math.mul(q, forward);
|
||||
Assert.AreEqual(0f, rotatedForward.x, 1e-6f);
|
||||
Assert.AreEqual(0f, rotatedForward.y, 1e-6f);
|
||||
Assert.AreEqual(1f, rotatedForward.z, 1e-6f);
|
||||
|
||||
// Should rotate (0,1,0) to approximately (0,1,0)
|
||||
var rotatedUp = math.mul(q, up);
|
||||
Assert.AreEqual(0f, rotatedUp.x, 1e-6f);
|
||||
Assert.AreEqual(1f, rotatedUp.y, 1e-6f);
|
||||
Assert.AreEqual(0f, rotatedUp.z, 1e-6f);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user