LibWeb: Add DOMMatrix flipX and flipY

This commit is contained in:
Bastiaan van der Plaat 2023-09-04 18:23:32 +02:00 committed by Jelle Raaijmakers
parent fc380bf516
commit f1742ae1b9
Notes: sideshowbarker 2024-07-17 04:21:32 +09:00
5 changed files with 50 additions and 2 deletions

View file

@ -10,3 +10,5 @@
10. {"a":10,"b":20,"c":31.76326980708465,"d":43.5265396141693,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":31.76326980708465,"m22":43.5265396141693,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
11. {"a":15.289809421253949,"b":27.0530792283386,"c":30,"d":40,"e":50,"f":60,"m11":15.289809421253949,"m12":27.0530792283386,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
12. {"a":15.289809421253949,"b":27.0530792283386,"c":30,"d":40,"e":50,"f":60,"m11":15.289809421253949,"m12":27.0530792283386,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
13. {"a":-10,"b":-20,"c":30,"d":40,"e":50,"f":60,"m11":-10,"m12":-20,"m13":0,"m14":0,"m21":30,"m22":40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}
14. {"a":10,"b":20,"c":-30,"d":-40,"e":50,"f":60,"m11":10,"m12":20,"m13":0,"m14":0,"m21":-30,"m22":-40,"m23":0,"m24":0,"m31":0,"m32":0,"m33":1,"m34":0,"m41":50,"m42":60,"m43":0,"m44":1,"is2D":true,"isIdentity":false}

View file

@ -41,5 +41,11 @@
// 12. Skew Y DOMMatrix with multiply
testPart(() => new DOMMatrix([10, 20, 30, 40, 50, 60]).multiply(new DOMMatrix().skewY(10)));
// 13. Flip X DOMMatrix
testPart(() => new DOMMatrix([10, 20, 30, 40, 50, 60]).flipX());
// 14. Flip Y DOMMatrix
testPart(() => new DOMMatrix([10, 20, 30, 40, 50, 60]).flipY());
});
</script>

View file

@ -284,6 +284,44 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> DOMMatrixReadOnly::multiply(DOM
return result->multiply_self(other);
}
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-flipx
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::flip_x()
{
// 1. Let result be the resulting matrix initialized to the values of the current matrix.
auto result = DOMMatrix::create_from_dom_matrix_read_only(realm(), *this);
// 2. Post-multiply result with new DOMMatrix([-1, 0, 0, 1, 0, 0]).
// clang-format off
Gfx::DoubleMatrix4x4 flip_matrix = { -1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
// clang-format on
result->m_matrix = result->m_matrix * flip_matrix;
// 3. Return result.
return result;
}
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-flipy
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::flip_y()
{
// 1. Let result be the resulting matrix initialized to the values of the current matrix.
auto result = DOMMatrix::create_from_dom_matrix_read_only(realm(), *this);
// 2. Post-multiply result with new DOMMatrix([1, 0, 0, -1, 0, 0]).
// clang-format off
Gfx::DoubleMatrix4x4 flip_matrix = { 1, 0, 0, 0,
0, -1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
// clang-format on
result->m_matrix = result->m_matrix * flip_matrix;
// 3. Return result.
return result;
}
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-inverse
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::inverse() const
{

View file

@ -88,6 +88,8 @@ public:
JS::NonnullGCPtr<DOMMatrix> skew_x(double sx = 0) const;
JS::NonnullGCPtr<DOMMatrix> skew_y(double sy = 0) const;
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> multiply(DOMMatrixInit other = {});
JS::NonnullGCPtr<DOMMatrix> flip_x();
JS::NonnullGCPtr<DOMMatrix> flip_y();
JS::NonnullGCPtr<DOMMatrix> inverse() const;
JS::NonnullGCPtr<DOMPoint> transform_point(DOMPointInit const&) const;

View file

@ -49,8 +49,8 @@ interface DOMMatrixReadOnly {
[NewObject] DOMMatrix skewX(optional unrestricted double sx = 0);
[NewObject] DOMMatrix skewY(optional unrestricted double sy = 0);
[NewObject] DOMMatrix multiply(optional DOMMatrixInit other = {});
// FIXME: [NewObject] DOMMatrix flipX();
// FIXME: [NewObject] DOMMatrix flipY();
[NewObject] DOMMatrix flipX();
[NewObject] DOMMatrix flipY();
[NewObject] DOMMatrix inverse();
[NewObject] DOMPoint transformPoint(optional DOMPointInit point = {});