Issue #2752 - Change DOMMatrix Rotate{Self}() to the current spec.

This changes Rotate{Self}(angle, translateX, translateY) to
Rotate{Self}(rotateX, rotateY, rotateZ) per the spec.
The resulting matrix will be a 3DMatrix

Resolves #2752
This commit is contained in:
Moonchild 2025-06-13 21:31:06 +02:00 • committed by roytam1
commit 2782cded29
3 changed files with 64 additions and 41 deletions

View file

@ -320,12 +320,11 @@ DOMMatrixReadOnly::ScaleNonUniform(double aScaleX,
}
already_AddRefed<DOMMatrix>
DOMMatrixReadOnly::Rotate(double aAngle,
double aOriginX ,
double aOriginY) const
{
DOMMatrixReadOnly::Rotate(double aRotX,
const Optional<double>& aRotY,
const Optional<double>& aRotZ) const {
RefPtr<DOMMatrix> retval = new DOMMatrix(mParent, *this);
retval->RotateSelf(aAngle, aOriginX, aOriginY);
retval->RotateSelf(aRotX, aRotY, aRotZ);
return retval.forget();
}
@ -893,28 +892,52 @@ DOMMatrix::RotateFromVectorSelf(double aX, double aY)
return this;
}
RotateSelf(atan2(aY, aX) / radPerDegree);
const double angle = atan2(aY, aX);
if (fmod(angle, 2 * M_PI) == 0) {
return this;
}
if (mMatrix3D) {
RotateAxisAngleSelf(0, 0, 1, angle / radPerDegree);
} else {
*mMatrix2D = mMatrix2D->PreRotate(angle);
}
return this;
}
DOMMatrix*
DOMMatrix::RotateSelf(double aAngle, double aOriginX, double aOriginY)
{
if (fmod(aAngle, 360) == 0) {
return this;
DOMMatrix* DOMMatrix::RotateSelf(double aRotX, const Optional<double>& aRotY,
const Optional<double>& aRotZ) {
double rotY;
double rotZ;
if (!aRotY.WasPassed() && !aRotZ.WasPassed()) {
rotZ = aRotX;
aRotX = 0;
rotY = 0;
} else {
rotY = aRotY.WasPassed() ? aRotY.Value() : 0;
rotZ = aRotZ.WasPassed() ? aRotZ.Value() : 0;
}
TranslateSelf(aOriginX, aOriginY);
if (aRotX != 0 || rotY != 0) {
Ensure3DMatrix();
}
if (mMatrix3D) {
RotateAxisAngleSelf(0, 0, 1, aAngle);
} else {
*mMatrix2D = mMatrix2D->PreRotate(aAngle * radPerDegree);
if (fmod(rotZ, 360) != 0) {
mMatrix3D->RotateZ(rotZ * radPerDegree);
}
if (fmod(rotY, 360) != 0) {
mMatrix3D->RotateY(rotY * radPerDegree);
}
if (fmod(aRotX, 360) != 0) {
mMatrix3D->RotateX(aRotX * radPerDegree);
}
} else if (fmod(rotZ, 360) != 0) {
*mMatrix2D = mMatrix2D->PreRotate(rotZ * radPerDegree);
}
TranslateSelf(-aOriginX, -aOriginY);
return this;
}

View file

@ -191,9 +191,9 @@ public:
double aOriginX = 0,
double aOriginY = 0,
double aOriginZ = 0) const;
already_AddRefed<DOMMatrix> Rotate(double aAngle,
double aOriginX = 0,
double aOriginY = 0) const;
already_AddRefed<DOMMatrix> Rotate(double aRotX,
const Optional<double>& aRotY,
const Optional<double>& aRotZ) const;
already_AddRefed<DOMMatrix> RotateFromVector(double aX,
double aY) const;
already_AddRefed<DOMMatrix> RotateAxisAngle(double aX,
@ -324,9 +324,9 @@ public:
double aOriginX = 0,
double aOriginY = 0,
double aOriginZ = 0);
DOMMatrix* RotateSelf(double aAngle,
double aOriginX = 0,
double aOriginY = 0);
DOMMatrix* RotateSelf(double aRotX,
const Optional<double>& aRotY,
const Optional<double>& aRotZ);
DOMMatrix* RotateFromVectorSelf(double aX,
double aY);
DOMMatrix* RotateAxisAngleSelf(double aX,

View file

@ -59,15 +59,15 @@ interface DOMMatrixReadOnly {
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix rotate(unrestricted double angle,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0);
DOMMatrix rotateFromVector(unrestricted double x,
unrestricted double y);
DOMMatrix rotateAxisAngle(unrestricted double x,
unrestricted double y,
unrestricted double z,
unrestricted double angle);
[NewObject] DOMMatrix rotate(optional unrestricted double rotX = 0,
optional unrestricted double rotY,
optional unrestricted double rotZ);
[NewObject] DOMMatrix rotateFromVector(optional unrestricted double x = 0,
optional unrestricted double y = 0);
[NewObject] DOMMatrix rotateAxisAngle(optional unrestricted double x = 0,
optional unrestricted double y = 0,
optional unrestricted double z = 0,
optional unrestricted double angle = 0);
DOMMatrix skewX(unrestricted double sx);
DOMMatrix skewY(unrestricted double sy);
[NewObject, Throws] DOMMatrix multiply(optional DOMMatrixInit other);
@ -141,15 +141,15 @@ interface DOMMatrix : DOMMatrixReadOnly {
optional unrestricted double originX = 0,
optional unrestricted double originY = 0,
optional unrestricted double originZ = 0);
DOMMatrix rotateSelf(unrestricted double angle,
optional unrestricted double originX = 0,
optional unrestricted double originY = 0);
DOMMatrix rotateFromVectorSelf(unrestricted double x,
unrestricted double y);
DOMMatrix rotateAxisAngleSelf(unrestricted double x,
unrestricted double y,
unrestricted double z,
unrestricted double angle);
DOMMatrix rotateSelf(optional unrestricted double rotX = 0,
optional unrestricted double rotY,
optional unrestricted double rotZ);
DOMMatrix rotateFromVectorSelf(optional unrestricted double x = 0,
optional unrestricted double y = 0);
DOMMatrix rotateAxisAngleSelf(optional unrestricted double x = 0,
optional unrestricted double y = 0,
optional unrestricted double z = 0,
optional unrestricted double angle = 0);
DOMMatrix skewXSelf(unrestricted double sx);
DOMMatrix skewYSelf(unrestricted double sy);
DOMMatrix invertSelf();