ID:2154983
 
Resolved
Inverting a transform matrix didn't work correctly for some matrices.
BYOND Version:510
Operating System:Windows 10 Pro 64-bit
Web Browser:Chrome 53.0.2785.116
Applies to:Dream Daemon
Status: Resolved (511.1360)

This issue has been resolved.
client
verb
test()
var matrix
r = turn(matrix(), 90)
a = matrix(0, 1, 0, -1, 0, 0)
b = matrix(0, -1, 0, 1, 0, 0)

src << "a: " + matrix2text(a)
src << "b: " + matrix2text(b)
src << "a * b: " + matrix2text(a * b)

src << "r: " + matrix2text(r)
src << "~r: " + matrix2text(~r)
src << "r * ~r: " + matrix2text(r * ~r)


Output:
runtime error: Invalid matrix
proc name: test (/client/verb/test)
  source file: demo.dm,39
  usr: Kaiochao (/mob/player)
  src: Kaiochao (/client)
  usr.loc: the floor (1,1,1) (/turf/floor)
  call stack:
Kaiochao (/client): test()
a: [[0, 1, 0], [-1, 0, 0]]
b: [[0, -1, 0], [1, 0, 0]]
a * b: [[1, 0, 0], [0, 1, 0]]
r: [[0, 1, 0], [-1, 0, 0]]


Clearly, since A * B == I, B must be the inverse of A (which it is).
However, if you try to get the inverse of A with ~A or A.Invert(), you get an "Invalid matrix" runtime error.

This happens for the matrices turn(matrix(), 90) and turn(matrix(), 270), as far as I know.

It's the same for the latest stable version (510.1347) as it is for the latest beta version (511.1359).
Very weird. I know I tested matrix inversion before matrices were released, but this definitely sounds like there's something not quite right with the inverse routine. I'll get to the bottom of it.
Lummox JR resolved issue with message:
Inverting a transform matrix didn't work correctly for some matrices.
It looks like there were several places this tripped up. The inversion routine believed that if the matrix's a parameter was 0, it couldn't invert, rather than swapping rows like it was supposed to. Additionally, several optimized parts of the inversion routine assumed that the output matrix's rows had not been swapped either. The math has been corrected for the next release.