From f15dc9d3c327a8000d181f4f0214ae1b1e483ef1 Mon Sep 17 00:00:00 2001 From: Teppanyaki Date: Sun, 24 May 2026 19:13:43 -0700 Subject: [PATCH 1/2] Add Matrix4f affine inverse round-trip test --- .../test/java/com/jme3/math/Matrix4fTest.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java diff --git a/jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java b/jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java new file mode 100644 index 0000000000..09b42ce96c --- /dev/null +++ b/jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2009-2021 jMonkeyEngine + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'jMonkeyEngine' nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package com.jme3.math; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class Matrix4fTest { + + /** + * Builds an affine transform with translation, scale, and rotation via + * setTransform, inverts it, multiplies transform by inverse, and asserts + * the product is the identity matrix. + */ + @Test + public void testInvert_roundTripWithTranslationScaleAndRotation() { + final Matrix3f rotation = new Matrix3f(); + rotation.fromAngleAxis(FastMath.HALF_PI, Vector3f.UNIT_Y); + + final Matrix4f transform = new Matrix4f(); + transform.setTransform( + new Vector3f(3.0f, -2.0f, 5.0f), + new Vector3f(2.0f, 1.0f, 4.0f), + rotation); + + final Matrix4f inverse = transform.invert(); + final Matrix4f product = transform.mult(inverse); + + assertTrue(product.isSimilar(Matrix4f.IDENTITY, 1e-4f)); + } +} From cb78df99264181f438815993fa7f62f955d482a4 Mon Sep 17 00:00:00 2001 From: Teppanyaki Date: Mon, 25 May 2026 02:54:06 -0700 Subject: [PATCH 2/2] Address Matrix4f test review feedback --- .../src/test/java/com/jme3/math/Matrix4fTest.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java b/jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java index 09b42ce96c..23816f05cb 100644 --- a/jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java +++ b/jme3-core/src/test/java/com/jme3/math/Matrix4fTest.java @@ -39,8 +39,8 @@ public class Matrix4fTest { /** * Builds an affine transform with translation, scale, and rotation via - * setTransform, inverts it, multiplies transform by inverse, and asserts - * the product is the identity matrix. + * setTransform, inverts it, and asserts transform * inverse and + * inverse * transform are both the identity matrix. */ @Test public void testInvert_roundTripWithTranslationScaleAndRotation() { @@ -54,8 +54,13 @@ public void testInvert_roundTripWithTranslationScaleAndRotation() { rotation); final Matrix4f inverse = transform.invert(); + final Matrix4f product = transform.mult(inverse); + assertTrue(product.isSimilar(Matrix4f.IDENTITY, 1e-4f), + () -> "transform * inverse should be identity, but was:\n" + product); - assertTrue(product.isSimilar(Matrix4f.IDENTITY, 1e-4f)); + final Matrix4f inverseProduct = inverse.mult(transform); + assertTrue(inverseProduct.isSimilar(Matrix4f.IDENTITY, 1e-4f), + () -> "inverse * transform should be identity, but was:\n" + inverseProduct); } }