Implement translate() and translateSelf() in DOMMatrix.

The methods multiply a translation 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/446803002

git-svn-id: svn://svn.chromium.org/blink/trunk@180418 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 60106f66
...@@ -1304,3 +1304,5 @@ crbug.com/402379 [ Win7 Debug ] storage/indexeddb/cursor-continue-validity.html ...@@ -1304,3 +1304,5 @@ crbug.com/402379 [ Win7 Debug ] storage/indexeddb/cursor-continue-validity.html
crbug.com/402379 [ Win7 Debug ] storage/indexeddb/mozilla/indexes.html [ Pass Slow ] crbug.com/402379 [ Win7 Debug ] storage/indexeddb/mozilla/indexes.html [ Pass Slow ]
crbug.com/402801 [ XP Release ] http/tests/misc/location-replace-crossdomain.html [ Pass Slow ] 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 ]
<!DOCTYPE html>
<html>
<head>
<title>Geometry Interfaces: DOMMatrix translate</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.translate(2, 3);
assert_true(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 1, 0, 0, 2, 0, 1, 0, 3, 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.translate(tx, ty)");
test(function() {
var matrix = new DOMMatrix();
matrix.translateSelf(2, 3);
assert_true(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.translate(4, 2);
assert_true(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 1, 0, 0, 6, 0, 1, 0, 5, 0, 0, 1, 0, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.translate(tx, ty) with non-identity");
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.translateSelf(4, 2);
assert_true(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.translateSelf(tx, ty)");
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.translate(2, 3, 4);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 4, 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.translate(tx, ty, tz)");
test(function() {
var matrix = new DOMMatrix();
matrix.translateSelf(2, 3);
assert_true(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0, 1 ]);
var result = matrix.translate(4, 2, 3);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 1, 0, 0, 6, 0, 1, 0, 5, 0, 0, 1, 3, 0, 0, 0, 1 ]);
assert_true(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 2, 0, 1, 0, 3, 0, 0, 1, 0, 0, 0, 0, 1 ]);
}, "DOMMatrix.translate(tx, ty, tz) with non-identity");
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.translateSelf(4, 2, 3);
assert_false(result.is2D);
assert_false(result.isIdentity);
assert_array_equals(toArray(result), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 3, 0, 0, 0, 1 ]);
assert_false(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 4, 0, 1, 0, 2, 0, 0, 1, 3, 0, 0, 0, 1 ]);
}, "DOMMatrix.translateSelf(tx, ty, tz)");
test(function() {
var matrix = new DOMMatrix();
assert_true(matrix.is2D);
assert_true(matrix.isIdentity);
matrix.m14 = 2;
matrix.m24 = 3;
matrix.m34 = 4;
matrix.m44 = 7;
assert_false(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 2, 3, 4, 7 ]);
matrix.translateSelf(7, -8, 2);
assert_false(matrix.is2D);
assert_false(matrix.isIdentity);
assert_array_equals(toArray(matrix), [ 1, 0, 0, 7, 0, 1, 0, -8, 0, 0, 1, 2, 2, 3, 4, 5 ]);
}, "DOMMatrix.translateSelf(tx, ty, tz) Homogeneous Coordinates");
</script>
</body>
</html>
...@@ -29,4 +29,20 @@ void DOMMatrix::setIs2D(bool value) ...@@ -29,4 +29,20 @@ void DOMMatrix::setIs2D(bool value)
m_is2D = value; m_is2D = value;
} }
DOMMatrix* DOMMatrix::translateSelf(double tx, double ty, double tz)
{
if (!tx && !ty && !tz)
return this;
if (tz)
m_is2D = false;
if (m_is2D)
m_matrix.translate(tx, ty);
else
m_matrix.translate3d(tx, ty, tz);
return this;
}
} // namespace blink } // namespace blink
...@@ -38,6 +38,8 @@ public: ...@@ -38,6 +38,8 @@ public:
void setM43(double value) { m_matrix.setM43(value); setIs2D(!value); } void setM43(double value) { m_matrix.setM43(value); setIs2D(!value); }
void setM44(double value) { m_matrix.setM44(value); setIs2D(value != 1); } void setM44(double value) { m_matrix.setM44(value); setIs2D(value != 1); }
DOMMatrix* translateSelf(double tx, double ty, double tz = 0);
private: private:
DOMMatrix(const TransformationMatrix&, bool is2D = true); DOMMatrix(const TransformationMatrix&, bool is2D = true);
......
...@@ -34,4 +34,8 @@ ...@@ -34,4 +34,8 @@
attribute unrestricted double m44; attribute unrestricted double m44;
// FIXME: Should implement some methods (See: crbug.com/388780) // FIXME: Should implement some methods (See: crbug.com/388780)
// Mutable transform methods
DOMMatrix translateSelf(unrestricted double tx,
unrestricted double ty,
optional unrestricted double tz = 0);
}; };
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "config.h" #include "config.h"
#include "core/dom/DOMMatrixReadOnly.h" #include "core/dom/DOMMatrix.h"
namespace blink { namespace blink {
...@@ -17,4 +17,9 @@ bool DOMMatrixReadOnly::isIdentity() const ...@@ -17,4 +17,9 @@ bool DOMMatrixReadOnly::isIdentity() const
return m_matrix.isIdentity(); return m_matrix.isIdentity();
} }
DOMMatrix* DOMMatrixReadOnly::translate(double tx, double ty, double tz)
{
return DOMMatrix::create(this)->translateSelf(tx, ty, tz);
}
} // namespace blink } // namespace blink
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
namespace blink { namespace blink {
class DOMMatrix;
class DOMMatrixReadOnly : public GarbageCollected<DOMMatrixReadOnly>, public ScriptWrappableBase { class DOMMatrixReadOnly : public GarbageCollected<DOMMatrixReadOnly>, public ScriptWrappableBase {
public: public:
double a() const { return m_matrix.m11(); } double a() const { return m_matrix.m11(); }
...@@ -40,6 +42,8 @@ public: ...@@ -40,6 +42,8 @@ public:
bool is2D() const; bool is2D() const;
bool isIdentity() const; bool isIdentity() const;
DOMMatrix* translate(double tx, double ty, double tz = 0);
const TransformationMatrix& matrix() const { return m_matrix; } const TransformationMatrix& matrix() const { return m_matrix; }
void trace(Visitor*) { } void trace(Visitor*) { }
......
...@@ -35,4 +35,8 @@ ...@@ -35,4 +35,8 @@
readonly attribute boolean isIdentity; readonly attribute boolean isIdentity;
// FIXME: Should implement some methods (See: crbug.com/388780) // FIXME: Should implement some methods (See: crbug.com/388780)
// Immutable transform methods
DOMMatrix translate(unrestricted double tx,
unrestricted double ty,
optional unrestricted double tz = 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