From 574295064b43a44449db5518e849683a28d4a077 Mon Sep 17 00:00:00 2001 From: Erin Maus Date: Wed, 24 Jun 2026 12:30:12 -0400 Subject: [PATCH 1/2] Add 'inverseOf' to love.Transform. --- src/modules/math/wrap_Transform.cpp | 12 ++++++++++++ testing/tests/math.lua | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/modules/math/wrap_Transform.cpp b/src/modules/math/wrap_Transform.cpp index 54cf4fb7d..993360f23 100644 --- a/src/modules/math/wrap_Transform.cpp +++ b/src/modules/math/wrap_Transform.cpp @@ -141,6 +141,17 @@ int w_Transform_inverse(lua_State *L) return 1; } +int w_Transform_inverseOf(lua_State *L) +{ + Transform *destination = luax_checktransform(L, 1); + Transform *source = luax_checktransform(L, 2); + Transform *inverseSource = source->inverse(); + destination->setMatrix(inverseSource->getMatrix()); + inverseSource->release(); + lua_pushvalue(L, 1); + return 1; +} + int w_Transform_apply(lua_State *L) { Transform *t = luax_checktransform(L, 1); @@ -298,6 +309,7 @@ static const luaL_Reg functions[] = { { "clone", w_Transform_clone }, { "inverse", w_Transform_inverse }, + { "inverseOf", w_Transform_inverseOf }, { "apply", w_Transform_apply }, { "isAffine2DTransform", w_Transform_isAffine2DTransform }, { "translate", w_Transform_translate }, diff --git a/testing/tests/math.lua b/testing/tests/math.lua index dbc92e714..aacde8e10 100644 --- a/testing/tests/math.lua +++ b/testing/tests/math.lua @@ -145,6 +145,16 @@ love.test.math.Transform = function(test) px, py = transform:transformPoint(0, 0) test:assertCoords({-px, -py}, {ipx, ipy}, 'check inverse points transform') + -- check inverse and inverseOf produce same values + transform:reset() + transform:setTransformation(4, 4, math.pi / 2, 2, 2) + local inverseClone = transform:inverse() + local inverseDestinationTransform = love.math.newTransform() + inverseDestinationTransform:inverseOf(transform) + local opx1, opy1 = inverseClone:transformPoint(0, 0) + local opx2, opy2 = inverseDestinationTransform:transformPoint(0, 0) + test:assertCoords({opx1, opy1}, {opx2, opy2}, 'check inverse and inverseOf produce same values') + -- check matrix manipulation transform:setTransformation(0, 0, 0, 1, 1, 0, 0, 0, 0) transform:translate(4, 4) From 66fafaaaf3cc37513826dd5a63295a8b58720c25 Mon Sep 17 00:00:00 2001 From: Erin Maus Date: Wed, 24 Jun 2026 19:37:04 -0400 Subject: [PATCH 2/2] Use `getMatrix().inverse() instead of heap allocation.` --- src/modules/math/wrap_Transform.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/modules/math/wrap_Transform.cpp b/src/modules/math/wrap_Transform.cpp index 993360f23..f27466e8f 100644 --- a/src/modules/math/wrap_Transform.cpp +++ b/src/modules/math/wrap_Transform.cpp @@ -145,9 +145,7 @@ int w_Transform_inverseOf(lua_State *L) { Transform *destination = luax_checktransform(L, 1); Transform *source = luax_checktransform(L, 2); - Transform *inverseSource = source->inverse(); - destination->setMatrix(inverseSource->getMatrix()); - inverseSource->release(); + destination->setMatrix(source->getMatrix().inverse()); lua_pushvalue(L, 1); return 1; }