Simsilica / SimMath

A double-based math package similar to JME's float-based math classes.
BSD 3-Clause "New" or "Revised" License
7 stars 4 forks source link

override equals() and hashCode() for Matrix3d and Matrix4d #10

Closed stephengold closed 1 year ago

stephengold commented 1 year ago

Because Matrix3d and Matrix4d do not override equals(), comparisons between matrices can give unexpected false results.

Once we override equals(), we should also override hashCode() so that invoking hashCode() on equal objects will always produce equal results.

For consistency with JMonkeyEngine's Matrix3f and Matrix4f, these implementations distinguish 0. from -0.

stephengold commented 1 year ago

The hash functions are modeled after Quatd and Vec4d. They're not ideal, since swapping any 2 elements other than m00 results in an identical code. Instead of multiplying by 13L or 19L each time, perhaps there should be a different coefficient for each element? I'm open to suggestions...

stephengold commented 1 year ago

I think it's better now ... ready for review and integration!