1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 06:48:12 +00:00

LibWeb: Fix DOMMatrix Gfx::Matrix row/column ordering

The matrix used in the spec is column-major but Gfx::Matrix4x4 is
row-major so we need to transpose the values. This will fix internal
operations on that matrix. Because we also transposed the readonly
matrix property getters the matrix is again transposed when reading
so the JavaScript world only sees a column-major matrix.
This commit is contained in:
Bastiaan van der Plaat 2023-08-22 09:46:02 +02:00 committed by Jelle Raaijmakers
parent b4ae719664
commit 57a1d99cf4
3 changed files with 53 additions and 47 deletions

View file

@ -84,14 +84,14 @@ void DOMMatrix::set_m11(double value)
void DOMMatrix::set_m12(double value)
{
// For the DOMMatrix interface, setting the m12 or the b attribute must set the m12 element to the new value.
m_matrix.elements()[0][1] = value;
m_matrix.elements()[1][0] = value;
}
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-m13
void DOMMatrix::set_m13(double value)
{
// For the DOMMatrix interface, setting the m13 attribute must set the m13 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[0][2] = value;
m_matrix.elements()[2][0] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -100,7 +100,7 @@ void DOMMatrix::set_m13(double value)
void DOMMatrix::set_m14(double value)
{
// For the DOMMatrix interface, setting the m14 attribute must set the m14 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[0][3] = value;
m_matrix.elements()[3][0] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -109,7 +109,7 @@ void DOMMatrix::set_m14(double value)
void DOMMatrix::set_m21(double value)
{
// For the DOMMatrix interface, setting the m21 or the c attribute must set the m21 element to the new value.
m_matrix.elements()[1][0] = value;
m_matrix.elements()[0][1] = value;
}
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-m22
@ -123,7 +123,7 @@ void DOMMatrix::set_m22(double value)
void DOMMatrix::set_m23(double value)
{
// For the DOMMatrix interface, setting the m23 attribute must set the m23 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[1][2] = value;
m_matrix.elements()[2][1] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -132,7 +132,7 @@ void DOMMatrix::set_m23(double value)
void DOMMatrix::set_m24(double value)
{
// For the DOMMatrix interface, setting the m24 attribute must set the m24 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[1][3] = value;
m_matrix.elements()[3][1] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -141,7 +141,7 @@ void DOMMatrix::set_m24(double value)
void DOMMatrix::set_m31(double value)
{
// For the DOMMatrix interface, setting the m31 attribute must set the m31 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[2][0] = value;
m_matrix.elements()[0][2] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -150,7 +150,7 @@ void DOMMatrix::set_m31(double value)
void DOMMatrix::set_m32(double value)
{
// For the DOMMatrix interface, setting the m32 attribute must set the m32 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[2][1] = value;
m_matrix.elements()[1][2] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -168,7 +168,7 @@ void DOMMatrix::set_m33(double value)
void DOMMatrix::set_m34(double value)
{
// For the DOMMatrix interface, setting the m34 attribute must set the m34 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[2][3] = value;
m_matrix.elements()[3][2] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -177,21 +177,21 @@ void DOMMatrix::set_m34(double value)
void DOMMatrix::set_m41(double value)
{
// For the DOMMatrix interface, setting the m41 or the e attribute must set the m41 element to the new value.
m_matrix.elements()[3][0] = value;
m_matrix.elements()[0][3] = value;
}
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-m42
void DOMMatrix::set_m42(double value)
{
// For the DOMMatrix interface, setting the m42 or the f attribute must set the m42 element to the new value.
m_matrix.elements()[3][1] = value;
m_matrix.elements()[1][3] = value;
}
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-m43
void DOMMatrix::set_m43(double value)
{
// For the DOMMatrix interface, setting the m43 attribute must set the m43 element to the new value and, if the new value is not 0 or -0, set is 2D to false.
m_matrix.elements()[3][2] = value;
m_matrix.elements()[2][3] = value;
if (value != 0.0 && value != -0.0)
m_is_2d = false;
}
@ -260,7 +260,7 @@ JS::NonnullGCPtr<DOMMatrix> DOMMatrix::invert_self()
if (!is_invertible) {
for (u8 i = 0; i < 4; i++) {
for (u8 j = 0; j < 4; j++)
m_matrix.elements()[i][j] = NAN;
m_matrix.elements()[j][i] = NAN;
}
m_is_2d = false;
}