mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:27:35 +00:00
LibWeb: Add DOMMatrix scale and scale3d
This commit is contained in:
parent
67f6a9ee12
commit
42c2a67c83
8 changed files with 125 additions and 5 deletions
|
@ -326,6 +326,51 @@ JS::NonnullGCPtr<DOMMatrix> DOMMatrix::translate_self(Optional<double> tx, Optio
|
|||
return *this;
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrix-scaleself
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrix::scale_self(Optional<double> scale_x, Optional<double> scale_y, Optional<double> scale_z, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z)
|
||||
{
|
||||
// 1. Perform a translateSelf() transformation on the current matrix with the arguments originX, originY, originZ.
|
||||
translate_self(origin_x, origin_y, origin_z);
|
||||
|
||||
// 2. If scaleY is missing, set scaleY to the value of scaleX.
|
||||
if (!scale_y.has_value())
|
||||
scale_y = scale_x.value_or(1);
|
||||
|
||||
// 3. Post-multiply a non-uniform scale transformation on the current matrix. The 3D scale matrix is described in CSS Transforms with sx = scaleX, sy = scaleY and sz = scaleZ. [CSS3-TRANSFORMS]
|
||||
m_matrix = m_matrix * Gfx::scale_matrix(Vector3<double> { scale_x.value_or(1), scale_y.value(), scale_z.value_or(1) });
|
||||
|
||||
// 4. Negate originX, originY and originZ.
|
||||
// 5. Perform a translateSelf() transformation on the current matrix with the arguments originX, originY, originZ.
|
||||
translate_self(-origin_x.value_or(0), -origin_y.value_or(0), -origin_z.value_or(0));
|
||||
|
||||
// 6. If scaleZ is not 1, set is 2D of the current matrix to false.
|
||||
if (scale_z != 1)
|
||||
m_is_2d = false;
|
||||
|
||||
// 7. Return the current matrix.
|
||||
return *this;
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrix-scale3dself
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrix::scale3d_self(Optional<double> scale, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z)
|
||||
{
|
||||
// 1. Apply a translateSelf() transformation to the current matrix with the arguments originX, originY, originZ.
|
||||
translate_self(origin_x, origin_y, origin_z);
|
||||
|
||||
// 2. Post-multiply a uniform 3D scale transformation (m11 = m22 = m33 = scale) on the current matrix. The 3D scale matrix is described in CSS Transforms with sx = sy = sz = scale. [CSS3-TRANSFORMS]
|
||||
m_matrix = m_matrix * Gfx::scale_matrix(Vector3<double> { scale.value_or(1), scale.value_or(1), scale.value_or(1) });
|
||||
|
||||
// 3. Apply a translateSelf() transformation to the current matrix with the arguments -originX, -originY, -originZ.
|
||||
translate_self(-origin_x.value_or(0), -origin_y.value_or(0), -origin_z.value_or(0));
|
||||
|
||||
// 4. If scale is not 1, set is 2D of the current matrix to false.
|
||||
if (scale != 1)
|
||||
m_is_2d = false;
|
||||
|
||||
// 5. Return the current matrix.
|
||||
return *this;
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrix-skewxself
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrix::skew_x_self(double sx)
|
||||
{
|
||||
|
|
|
@ -52,6 +52,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> scale_self(Optional<double> scale_x, Optional<double> scale_y, Optional<double> scale_z, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z);
|
||||
JS::NonnullGCPtr<DOMMatrix> scale3d_self(Optional<double> scale, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z);
|
||||
JS::NonnullGCPtr<DOMMatrix> skew_x_self(double sx = 0);
|
||||
JS::NonnullGCPtr<DOMMatrix> skew_y_self(double sy = 0);
|
||||
JS::NonnullGCPtr<DOMMatrix> invert_self();
|
||||
|
|
|
@ -39,8 +39,8 @@ interface DOMMatrix : DOMMatrixReadOnly {
|
|||
DOMMatrix multiplySelf(optional DOMMatrixInit other = {});
|
||||
DOMMatrix preMultiplySelf(optional DOMMatrixInit other = {});
|
||||
DOMMatrix translateSelf(optional unrestricted double tx = 0, optional unrestricted double ty = 0, optional unrestricted double tz = 0);
|
||||
// FIXME: DOMMatrix scaleSelf(optional unrestricted double scaleX = 1, optional unrestricted double scaleY, optional unrestricted double scaleZ = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
// FIXME: DOMMatrix scale3dSelf(optional unrestricted double scale = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
DOMMatrix scaleSelf(optional unrestricted double scaleX = 1, optional unrestricted double scaleY, optional unrestricted double scaleZ = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
DOMMatrix scale3dSelf(optional unrestricted double scale = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
// 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);
|
||||
|
|
|
@ -270,6 +270,43 @@ JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::translate(Optional<double> const&
|
|||
return result->translate_self(tx, ty, tz);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-scale
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::scale(Optional<double> scale_x, Optional<double> scale_y, Optional<double> scale_z, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z)
|
||||
{
|
||||
// 1. If scaleY is missing, set scaleY to the value of scaleX.
|
||||
if (!scale_y.has_value())
|
||||
scale_y = scale_x;
|
||||
|
||||
// 2. 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);
|
||||
|
||||
// 3. Perform a scaleSelf() transformation on result with the arguments scaleX, scaleY, scaleZ, originX, originY, originZ.
|
||||
// 4. Return result.
|
||||
return result->scale_self(scale_x, scale_y, scale_z, origin_x, origin_y, origin_z);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-scalenonuniform
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::scale_non_uniform(Optional<double> scale_x, Optional<double> scale_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. Perform a scaleSelf() transformation on result with the arguments scaleX, scaleY, 1, 0, 0, 0.
|
||||
// 3. Return result.
|
||||
return result->scale_self(scale_x, scale_y, 1, 0, 0, 0);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-scale3d
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::scale3d(Optional<double> scale, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z)
|
||||
{
|
||||
// 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 scale3dSelf() transformation on result with the arguments scale, originX, originY, originZ.
|
||||
// 3. Return result.
|
||||
return result->scale3d_self(scale, origin_x, origin_y, origin_z);
|
||||
}
|
||||
|
||||
// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-skewx
|
||||
JS::NonnullGCPtr<DOMMatrix> DOMMatrixReadOnly::skew_x(double sx) const
|
||||
{
|
||||
|
|
|
@ -86,6 +86,9 @@ 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> scale(Optional<double> scale_x, Optional<double> scale_y, Optional<double> scale_z, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z);
|
||||
JS::NonnullGCPtr<DOMMatrix> scale_non_uniform(Optional<double> scale_x, Optional<double> scale_y);
|
||||
JS::NonnullGCPtr<DOMMatrix> scale3d(Optional<double> scale, Optional<double> origin_x, Optional<double> origin_y, Optional<double> origin_z);
|
||||
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 = {});
|
||||
|
|
|
@ -40,9 +40,9 @@ interface DOMMatrixReadOnly {
|
|||
|
||||
// Immutable transform methods
|
||||
[NewObject] DOMMatrix translate(optional unrestricted double tx = 0, optional unrestricted double ty = 0, optional unrestricted double tz = 0);
|
||||
// FIXME: [NewObject] DOMMatrix scale(optional unrestricted double scaleX = 1, optional unrestricted double scaleY, optional unrestricted double scaleZ = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
// FIXME: [NewObject] DOMMatrix scaleNonUniform(optional unrestricted double scaleX = 1, optional unrestricted double scaleY = 1);
|
||||
// FIXME: [NewObject] DOMMatrix scale3d(optional unrestricted double scale = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
[NewObject] DOMMatrix scale(optional unrestricted double scaleX = 1, optional unrestricted double scaleY, optional unrestricted double scaleZ = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
[NewObject] DOMMatrix scaleNonUniform(optional unrestricted double scaleX = 1, optional unrestricted double scaleY = 1);
|
||||
[NewObject] DOMMatrix scale3d(optional unrestricted double scale = 1, optional unrestricted double originX = 0, optional unrestricted double originY = 0, optional unrestricted double originZ = 0);
|
||||
// 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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue