Implement scale*() methods in DOMMatrix.

The methods multiply a scale transformation on the current matrix.

The specification:
  http://dev.w3.org/fxtf/geometry/

Intent to Implement:
  https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/V_bJNtOg0oM

BUG=388780

Review URL: https://codereview.chromium.org/450533006

git-svn-id: svn://svn.chromium.org/blink/trunk@180421 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3b2a55c6
......@@ -1306,3 +1306,4 @@ crbug.com/402379 [ Win7 Debug ] storage/indexeddb/mozilla/indexes.html [ Pass Sl
crbug.com/402801 [ XP Release ] http/tests/misc/location-replace-crossdomain.html [ Pass Slow ]
crbug.com/388780 fast/dom/geometry-interfaces-dom-matrix-translate.html [ NeedsRebaseline ]
crbug.com/388780 fast/dom/geometry-interfaces-dom-matrix-scale.html [ NeedsRebaseline ]
<!DOCTYPE html>
<html>
<head>
<title>Geometry Interfaces: DOMMatrix scale</title>
<script src="../../resources/testharness.js"></script>
</head>
<body>
<script>
function toArray(matrix)
{
return [ matrix.m11, matrix.m21, matrix.m31, matrix.m41,
matrix.m12, matrix.m22, matrix.m32, matrix.m42,
matrix.m13, matrix.m23, matrix.m33, matrix.m43,
matrix.m14, matrix.m24, matrix.m34, matrix.m44 ];
}
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scale(3);
assert_true(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scale(scale)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scale(3, 4, 2);
assert_true(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, -8, 0, 3, 0, -4, 0, 0, 1, 0, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scale(scale, ox, oy)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scale3d(3);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scale3d(scale)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scale3d(3, 2, 7, -1);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, -4, 0, 3, 0, -14, 0, 0, 3, 2, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scale3d(scale, ox, oy, oz)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scaleNonUniform(2, 3, 0.5, 2, -4, -1);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 2, 0, 0, -2, 0, 3, 0, 8, 0, 0, 0.5, -0.5, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scaleNonUniform(sx, sy, sz, ox, oy, oz)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scaleSelf(3);
assert_true(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scaleSelf(scale)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scaleSelf(3, 4, 2);
assert_true(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, -8, 0, 3, 0, -4, 0, 0, 1, 0, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 3, 0, 0, -8, 0, 3, 0, -4, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scaleSelf(scale)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scale3dSelf(3);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1 ]);
assert_false(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scale3dSelf(scale)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scale3dSelf(3, 2, 7, -1);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 3, 0, 0, -4, 0, 3, 0, -14, 0, 0, 3, 2, 0, 0, 0, 1 ]);
assert_false(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 3, 0, 0, -4, 0, 3, 0, -14, 0, 0, 3, 2, 0, 0, 0, 1 ]);
}, "DOMMatrix.scale3dSelf(scale, ox, oy, oz)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scaleNonUniformSelf(2, 3, 0.5, 2, -4, -1);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 2, 0, 0, -2, 0, 3, 0, 8, 0, 0, 0.5, -0.5, 0, 0, 0, 1 ]);
assert_false(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 2, 0, 0, -2, 0, 3, 0, 8, 0, 0, 0.5, -0.5, 0, 0, 0, 1 ]);
}, "DOMMatrix.scaleNonUniformSelf(sx, sy, sz, ox, oy, oz)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.scaleNonUniformSelf(1, 1, 1, 2, -4, -1);
assert_false(result.is2D);
assert_true(result.isIdentity);
assert_array_equals(toArray(result), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
assert_false(matrix.is2D);
assert_true(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.scaleNonUniformSelf(1, 1, 1, ox, oy, oz)");
</script>
</body>
</html>
......@@ -45,4 +45,39 @@ DOMMatrix* DOMMatrix::translateSelf(double tx, double ty, double tz)
return this;
}
DOMMatrix* DOMMatrix::scaleSelf(double scale, double ox, double oy)
{
return scaleNonUniformSelf(scale, scale, 1, ox, oy);
}
DOMMatrix* DOMMatrix::scale3dSelf(double scale, double ox, double oy, double oz)
{
return scaleNonUniformSelf(scale, scale, scale, ox, oy, oz);
}
DOMMatrix* DOMMatrix::scaleNonUniformSelf(double sx, double sy, double sz,
double ox, double oy, double oz)
{
if (sz != 1 || oz)
m_is2D = false;
if (sx == 1 && sy == 1 && sz == 1)
return this;
bool hasTranslation = (ox || oy || oz);
if (hasTranslation)
translateSelf(ox, oy, oz);
if (m_is2D)
m_matrix.scaleNonUniform(sx, sy);
else
m_matrix.scale3d(sx, sy, sz);
if (hasTranslation)
translateSelf(-ox, -oy, -oz);
return this;
}
} // namespace blink
......@@ -39,6 +39,10 @@ public:
void setM44(double value) { m_matrix.setM44(value); setIs2D(value != 1); }
DOMMatrix* translateSelf(double tx, double ty, double tz = 0);
DOMMatrix* scaleSelf(double scale, double ox = 0, double oy = 0);
DOMMatrix* scale3dSelf(double scale, double ox = 0, double oy = 0, double oz = 0);
DOMMatrix* scaleNonUniformSelf(double sx, double sy = 1, double sz = 1,
double ox = 0, double oy = 0, double oz = 0);
private:
DOMMatrix(const TransformationMatrix&, bool is2D = true);
......
......@@ -38,4 +38,17 @@
DOMMatrix translateSelf(unrestricted double tx,
unrestricted double ty,
optional unrestricted double tz = 0);
DOMMatrix scaleSelf(unrestricted double scale,
optional unrestricted double ox = 0,
optional unrestricted double oy = 0);
DOMMatrix scale3dSelf(unrestricted double scale,
optional unrestricted double ox = 0,
optional unrestricted double oy = 0,
optional unrestricted double oz = 0);
DOMMatrix scaleNonUniformSelf(unrestricted double sx,
optional unrestricted double sy = 1,
optional unrestricted double sz = 1,
optional unrestricted double ox = 0,
optional unrestricted double oy = 0,
optional unrestricted double oz = 0);
};
......@@ -22,4 +22,20 @@ DOMMatrix* DOMMatrixReadOnly::translate(double tx, double ty, double tz)
return DOMMatrix::create(this)->translateSelf(tx, ty, tz);
}
DOMMatrix* DOMMatrixReadOnly::scale(double scale, double ox, double oy)
{
return DOMMatrix::create(this)->scaleSelf(scale, ox, oy);
}
DOMMatrix* DOMMatrixReadOnly::scale3d(double scale, double ox, double oy, double oz)
{
return DOMMatrix::create(this)->scale3dSelf(scale, ox, oy, oz);
}
DOMMatrix* DOMMatrixReadOnly::scaleNonUniform(double sx, double sy, double sz,
double ox, double oy, double oz)
{
return DOMMatrix::create(this)->scaleNonUniformSelf(sx, sy, sz, ox, oy, oz);
}
} // namespace blink
......@@ -43,6 +43,10 @@ public:
bool isIdentity() const;
DOMMatrix* translate(double tx, double ty, double tz = 0);
DOMMatrix* scale(double scale, double ox = 0, double oy = 0);
DOMMatrix* scale3d(double scale, double ox = 0, double oy = 0, double oz = 0);
DOMMatrix* scaleNonUniform(double sx, double sy = 1, double sz = 1,
double ox = 0, double oy = 0, double oz = 0);
const TransformationMatrix& matrix() const { return m_matrix; }
......
......@@ -39,4 +39,17 @@
DOMMatrix translate(unrestricted double tx,
unrestricted double ty,
optional unrestricted double tz = 0);
DOMMatrix scale(unrestricted double scale,
optional unrestricted double ox = 0,
optional unrestricted double oy = 0);
DOMMatrix scale3d(unrestricted double scale,
optional unrestricted double ox = 0,
optional unrestricted double oy = 0,
optional unrestricted double oz = 0);
DOMMatrix scaleNonUniform(unrestricted double sx,
optional unrestricted double sy = 1,
optional unrestricted double sz = 1,
optional unrestricted double ox = 0,
optional unrestricted double oy = 0,
optional unrestricted double oz = 0);
};
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment