mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:57:46 +00:00
LibWeb: Add DOMMatrix skewX and skewY
This commit is contained in:
parent
b21ca0d04e
commit
fc380bf516
8 changed files with 82 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -307,6 +308,38 @@ JS::NonnullGCPtr<DOMMatrix> DOMMatrix::translate_self(Optional<double> tx, Optio
|
|||
return *this;
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrix-skewxself
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrix::skew_x_self(double sx)
|
||||
{
|
||||
// 1. Post-multiply a skewX transformation on the current matrix by the specified angle sx in degrees. The 2D skewX matrix is described in CSS Transforms with alpha = sx in degrees. [CSS3-TRANSFORMS]
|
||||
// clang-format off
|
||||
Gfx::DoubleMatrix4x4 skew_matrix = { 1, tan(sx * M_PI / 180.0), 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1 };
|
||||
// clang-format on
|
||||
m_matrix = m_matrix * skew_matrix;
|
||||
|
||||
// 3. Return the current matrix.
|
||||
return *this;
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrix-skewyself
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrix::skew_y_self(double sy)
|
||||
{
|
||||
// 1. Post-multiply a skewX transformation on the current matrix by the specified angle sy in degrees. The 2D skewY matrix is described in CSS Transforms with beta = sy in degrees. [CSS3-TRANSFORMS]
|
||||
// clang-format off
|
||||
Gfx::DoubleMatrix4x4 skew_matrix = { 1, 0, 0, 0,
|
||||
tan(sy * M_PI / 180.0), 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1 };
|
||||
// clang-format on
|
||||
m_matrix = m_matrix * skew_matrix;
|
||||
|
||||
// 3. Return the current matrix.
|
||||
return *this;
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrix-invertself
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrix::invert_self()
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -50,6 +51,8 @@ public:
|
|||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> multiply_self(DOMMatrixInit other = {});
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> pre_multiply_self(DOMMatrixInit other = {});
|
||||
JS::NonnullGCPtr<DOMMatrix> translate_self(Optional<double> tx, Optional<double> ty, Optional<double> tz);
|
||||
JS::NonnullGCPtr<DOMMatrix> skew_x_self(double sx = 0);
|
||||
JS::NonnullGCPtr<DOMMatrix> skew_y_self(double sy = 0);
|
||||
JS::NonnullGCPtr<DOMMatrix> invert_self();
|
||||
|
||||
private:
|
||||
|
|
|
@ -44,8 +44,8 @@ interface DOMMatrix : DOMMatrixReadOnly {
|
|||
// FIXME: DOMMatrix rotateSelf(optional unrestricted double rotX = 0, optional unrestricted double rotY, optional unrestricted double rotZ);
|
||||
// FIXME: DOMMatrix rotateFromVectorSelf(optional unrestricted double x = 0, optional unrestricted double y = 0);
|
||||
// FIXME: DOMMatrix rotateAxisAngleSelf(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double z = 0, optional unrestricted double angle = 0);
|
||||
// FIXME: DOMMatrix skewXSelf(optional unrestricted double sx = 0);
|
||||
// FIXME: DOMMatrix skewYSelf(optional unrestricted double sy = 0);
|
||||
DOMMatrix skewXSelf(optional unrestricted double sx = 0);
|
||||
DOMMatrix skewYSelf(optional unrestricted double sy = 0);
|
||||
DOMMatrix invertSelf();
|
||||
|
||||
// FIXME: [Exposed=Window] DOMMatrix setMatrixValue(DOMString transformList);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -250,6 +251,28 @@ JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::translate(Optional<double> const&
|
|||
return result->translate_self(tx, ty, tz);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-skewx
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::skew_x(double sx) const
|
||||
{
|
||||
// 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. Perform a skewXSelf() transformation on result with the argument sx.
|
||||
// 3. Return result.
|
||||
return result->skew_x_self(sx);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-skewy
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::skew_y(double sy) const
|
||||
{
|
||||
// 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. Perform a skewYSelf() transformation on result with the argument sy.
|
||||
// 3. Return result.
|
||||
return result->skew_y_self(sy);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-multiply
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<DOMMatrix>> DOMMatrixReadOnly::multiply(DOMMatrixInit other)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023, Bastiaan van der Plaat <bastiaan.v.d.plaat@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -84,6 +85,8 @@ public:
|
|||
bool is_identity() const;
|
||||
|
||||
JS::NonnullGCPtr<DOMMatrix> translate(Optional<double> const& tx, Optional<double> const& ty, Optional<double> const& tz) const;
|
||||
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> inverse() const;
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ interface DOMMatrixReadOnly {
|
|||
// FIXME: [NewObject] DOMMatrix rotate(optional unrestricted double rotX = 0, optional unrestricted double rotY, optional unrestricted double rotZ);
|
||||
// FIXME: [NewObject] DOMMatrix rotateFromVector(optional unrestricted double x = 0, optional unrestricted double y = 0);
|
||||
// FIXME: [NewObject] DOMMatrix rotateAxisAngle(optional unrestricted double x = 0, optional unrestricted double y = 0, optional unrestricted double z = 0, optional unrestricted double angle = 0);
|
||||
// FIXME: [NewObject] DOMMatrix skewX(optional unrestricted double sx = 0);
|
||||
// FIXME: [NewObject] DOMMatrix skewY(optional unrestricted double sy = 0);
|
||||
[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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue