mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibWeb: Add DOMMatrix flipX and flipY
This commit is contained in:
parent
fc380bf516
commit
f1742ae1b9
Notes:
sideshowbarker
2024-07-17 04:21:32 +09:00
Author: https://github.com/bplaat Commit: https://github.com/SerenityOS/serenity/commit/f1742ae1b9 Pull-request: https://github.com/SerenityOS/serenity/pull/20950 Reviewed-by: https://github.com/gmta ✅
5 changed files with 50 additions and 2 deletions
|
@ -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}
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 = {});
|
||||
|
|
Loading…
Reference in a new issue