Add Matrix4f affine inverse round-trip test#2804
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new unit test for Matrix4f that verifies the inversion of an affine transform containing translation, scale, and rotation. The reviewer suggested enhancing the test's robustness by checking the identity property for both left and right multiplication and adding descriptive failure messages to the assertions for better diagnostics.
| final Matrix4f product = transform.mult(inverse); | ||
|
|
||
| assertTrue(product.isSimilar(Matrix4f.IDENTITY, 1e-4f)); |
There was a problem hiding this comment.
To make the test more robust and provide better diagnostics on failure, consider checking the inverse multiplication on both sides (transform * inverse and inverse * transform) and adding a failure message to the assertion that includes the actual result. This is standard practice for inversion tests to ensure the mathematical property holds in both directions.
final Matrix4f product = transform.mult(inverse);
assertTrue(product.isSimilar(Matrix4f.IDENTITY, 1e-4f),
() -> "transform * inverse should be identity, but was:\n" + product);
final Matrix4f inverseProduct = inverse.mult(transform);
assertTrue(inverseProduct.isSimilar(Matrix4f.IDENTITY, 1e-4f),
() -> "inverse * transform should be identity, but was:\n" + inverseProduct);References
- Issues found in test code should be reported with a reduced priority, at most medium.
688be22 to
cb78df9
Compare
Summary
Adds an initial
Matrix4fTestforcom.jme3.math.Matrix4f, which previously had no dedicated test suite.The test builds a typical affine transform using translation, scale, and rotation via
setTransform, inverts it withinvert(), multiplies the transform by its inverse withmult(), and verifies the result is approximatelyMatrix4f.IDENTITY.Motivation
Matrix4fis used throughout jMonkeyEngine for world/view/projection matrices, camera math, skinning, shadows, and collision transforms. However, it currently has limited direct test coverage. This test introduces a basic mathematical property of affine transforms to exercise several important methods together, and provides a starting point for future, more comprehensiveMatrix4ftests.