Implement DOMMatrixReadOnly.transformPoint()
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Jun 2017 15:21:52 +0000 (15:21 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Jun 2017 15:21:52 +0000 (15:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172900

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Rebaseline W3C test now that more checks are passing.

* web-platform-tests/css/geometry-1/DOMMatrix-newobject-expected.txt:

Source/WebCore:

Implement DOMMatrixReadOnly.transformPoint():
- https://drafts.fxtf.org/geometry/#dommatrixreadonly
- https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-transformpoint

Test: imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint.html

* css/DOMMatrixReadOnly.cpp:
(WebCore::DOMMatrixReadOnly::transformPoint):
* css/DOMMatrixReadOnly.h:
* css/DOMMatrixReadOnly.idl:

LayoutTests:

* imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint-expected.txt: Added.
* imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint.html: Added.
* imported/blink/fast/dom/resources/geometry-interfaces-test-helpers.js: Added.
Import test coverage from Blink.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217767 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint-expected.txt [new file with mode: 0644]
LayoutTests/imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint.html [new file with mode: 0644]
LayoutTests/imported/blink/fast/dom/resources/geometry-interfaces-test-helpers.js [new file with mode: 0644]
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/css/geometry-1/DOMMatrix-newobject-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/css/DOMMatrixReadOnly.cpp
Source/WebCore/css/DOMMatrixReadOnly.h
Source/WebCore/css/DOMMatrixReadOnly.idl

index bc76bfa..388e84e 100644 (file)
@@ -1,3 +1,15 @@
+2017-06-04  Chris Dumez  <cdumez@apple.com>
+
+        Implement DOMMatrixReadOnly.transformPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=172900
+
+        Reviewed by Simon Fraser.
+
+        * imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint-expected.txt: Added.
+        * imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint.html: Added.
+        * imported/blink/fast/dom/resources/geometry-interfaces-test-helpers.js: Added.
+        Import test coverage from Blink.
+
 2017-06-04  Zan Dobersek  <zdobersek@igalia.com>
 
         Unreviewed GTK+ gardening. Add a few test failure expectations, linking them to
diff --git a/LayoutTests/imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint-expected.txt b/LayoutTests/imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint-expected.txt
new file mode 100644 (file)
index 0000000..aba4e84
--- /dev/null
@@ -0,0 +1,18 @@
+
+PASS DOMMatrixReadOnly transformPoint() - 2d matrix  
+PASS DOMMatrixReadOnly transformPoint() - 3d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x)) - 2d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, 0, 0, 0)) - 2d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y)) - 2d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, 0, 0)) - 2d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z)) - 2d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, 0)) - 2d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, w)) - 2d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x)) - 3d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, 0, 0, 0)) - 3d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y)) - 3d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, 0, 0)) - 3d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z)) - 3d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, 0)) - 3d matrix 
+PASS DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, w)) - 3d matrix 
+
diff --git a/LayoutTests/imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint.html b/LayoutTests/imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint.html
new file mode 100644 (file)
index 0000000..d2fc014
--- /dev/null
@@ -0,0 +1,102 @@
+<!DOCTYPE HTML>
+<script src="../../../../resources/testharness.js"></script>
+<script src="../../../../resources/testharnessreport.js"></script>
+<script src="./resources/geometry-interfaces-test-helpers.js"></script>
+<script>
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6]);
+  var point = matrix2d.transformPoint();
+  assert_dom_point_equals(point, new DOMPoint(5, 6, 0, 1));
+}, "DOMMatrixReadOnly transformPoint() - 2d matrix ");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint();
+  assert_dom_point_equals(point, new DOMPoint(13, 14, 15, 16));
+}, "DOMMatrixReadOnly transformPoint() - 3d matrix");
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([2, 0, 0, 2, 10, 10]);
+  var point = matrix2d.transformPoint(new DOMPoint(5));
+  assert_dom_point_equals(point, new DOMPoint(20, 10, 0, 1));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x)) - 2d matrix");
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([2, 0, 0, 2, 10, 10]);
+  var point = matrix2d.transformPoint(new DOMPoint(5, 0, 0, 0));
+  assert_dom_point_equals(point, new DOMPoint(10, 0, 0, 0));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, 0, 0, 0)) - 2d matrix");
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([2, 0, 0, 2, 10, 10]);
+  var point = matrix2d.transformPoint(new DOMPoint(5, 4));
+  assert_dom_point_equals(point, new DOMPoint(20, 18, 0, 1));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y)) - 2d matrix");
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([2, 0, 0, 2, 10, 10]);
+  var point = matrix2d.transformPoint(new DOMPoint(5, 4, 0, 0));
+  assert_dom_point_equals(point, new DOMPoint(10, 8, 0, 0));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, 0, 0)) - 2d matrix");
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([2, 0, 0, 2, 10, 10]);
+  var point = matrix2d.transformPoint(new DOMPoint(5, 4, 3));
+  assert_dom_point_equals(point, new DOMPoint(20, 18, 3, 1));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z)) - 2d matrix");
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([2, 0, 0, 2, 10, 10]);
+  var point = matrix2d.transformPoint(new DOMPoint(5, 4, 3, 0));
+  assert_dom_point_equals(point, new DOMPoint(10, 8, 3, 0));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, 0)) - 2d matrix");
+
+test(function() {
+  var matrix2d = new DOMMatrixReadOnly([2, 0, 0, 2, 10, 10]);
+  var point = matrix2d.transformPoint(new DOMPoint(5, 4, 14, 5));
+  assert_dom_point_equals(point, new DOMPoint(60, 58, 14, 5));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, w)) - 2d matrix");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint(new DOMPoint(5));
+  assert_dom_point_equals(point, new DOMPoint(18, 24, 30, 36));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x)) - 3d matrix");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint(new DOMPoint(5, 0, 0, 0));
+  assert_dom_point_equals(point, new DOMPoint(5, 10, 15, 20));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, 0, 0, 0)) - 3d matrix");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint(new DOMPoint(5, 4));
+  assert_dom_point_equals(point, new DOMPoint(38, 48, 58, 68));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y)) - 3d matrix");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint(new DOMPoint(5, 4, 0, 0));
+  assert_dom_point_equals(point, new DOMPoint(25, 34, 43, 52));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, 0, 0)) - 3d matrix");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint(new DOMPoint(5, 4, 3));
+  assert_dom_point_equals(point, new DOMPoint(65, 78, 91, 104));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z)) - 3d matrix");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint(new DOMPoint(5, 4, 3, 0));
+  assert_dom_point_equals(point, new DOMPoint(52, 64, 76, 88));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, 0)) - 3d matrix");
+
+test(function() {
+  var matrix3d = new DOMMatrixReadOnly([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]);
+  var point = matrix3d.transformPoint(new DOMPoint(5, 4, 14, 5));
+  assert_dom_point_equals(point, new DOMPoint(216, 244, 272, 300));
+}, "DOMMatrixReadOnly transformPoint(DOMPoint(x, y, z, w)) - 3d matrix");
+</script>
diff --git a/LayoutTests/imported/blink/fast/dom/resources/geometry-interfaces-test-helpers.js b/LayoutTests/imported/blink/fast/dom/resources/geometry-interfaces-test-helpers.js
new file mode 100644 (file)
index 0000000..1104c43
--- /dev/null
@@ -0,0 +1,109 @@
+function assert_identity_2d_matrix(actual) {
+  assert_true(actual instanceof DOMMatrixReadOnly);
+  assert_true(actual.is2D, "is2D");
+  assert_true(actual.isIdentity, "isIdentity");
+  assert_identity_matrix(actual);
+}
+
+function assert_identity_3d_matrix(actual) {
+  assert_true(actual instanceof DOMMatrixReadOnly);
+  assert_false(actual.is2D, "is2D");
+  assert_true(actual.isIdentity, "isIdentity");
+  assert_identity_matrix(actual);
+}
+
+function assert_identity_matrix(actual) {
+  assert_array_equals(actual.toFloat64Array(), [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
+}
+
+function toArray(actual) {
+  var array = actual.toFloat64Array();
+  // Do not care negative zero for testing accommodation.
+  for (var i = 0; i < array.length; i++) {
+    if (array[i] === -0)
+      array[i] = 0;
+  }
+  return array;
+}
+
+function assert_2d_matrix_equals(actual, expected) {
+  assert_true(actual instanceof DOMMatrixReadOnly);
+  assert_true(Array.isArray(expected));
+  assert_equals(6, expected.length, "expected.length");
+  assert_true(actual.is2D, "is2D");
+  assert_false(actual.isIdentity, "isIdentity");
+  assert_array_equals(toArray(actual), [
+    expected[0], expected[1], 0, 0,
+    expected[2], expected[3], 0, 0,
+    0, 0, 1, 0,
+    expected[4], expected[5], 0, 1
+  ]);
+}
+
+function assert_3d_matrix_equals(actual, expected) {
+  assert_true(actual instanceof DOMMatrixReadOnly);
+  assert_true(Array.isArray(expected) );
+  assert_equals(16, expected.length, "expected.length");
+  assert_false(actual.is2D, "is2D");
+  assert_false(actual.isIdentity, "isIdentity");
+  assert_array_equals(toArray(actual), [
+    expected[0], expected[1], expected[2], expected[3],
+    expected[4], expected[5], expected[6], expected[7],
+    expected[8], expected[9], expected[10], expected[11],
+    expected[12], expected[13], expected[14], expected[15],
+  ]);
+}
+
+function assert_array_almost_equals(actual, expected) {
+  for (var i = 0; i < actual.length; i++) {
+    assert_equals(actual[i].toFixed(10), expected[i].toFixed(10));
+  }
+}
+
+function assert_matrix_almost_equals(actual, expected) {
+  assert_array_almost_equals(actual.toFloat64Array(), expected.toFloat64Array());
+}
+
+function assert_dom_point_equals(actual, expected) {
+  assert_true(actual instanceof DOMPointReadOnly);
+  if(Array.isArray(expected)) {
+    assert_equals(expected.length, 4);
+    assert_equals(actual.x, expected[0], "point equality: x differs");
+    assert_equals(actual.y, expected[1], "point equality: y differs");
+    assert_equals(actual.z, expected[2], "point equality: z differs");
+    assert_equals(actual.w, expected[3], "point equality: w differs");
+  } else if(expected instanceof DOMPointReadOnly) {
+    assert_equals(actual.x, expected.x, "point equality: x differs");
+    assert_equals(actual.y, expected.y, "point equality: y differs");
+    assert_equals(actual.z, expected.z, "point equality: z differs");
+    assert_equals(actual.w, expected.w, "point equality: w differs");
+  } else {
+    assert_unreached();
+  }
+}
+function assert_dom_rect_equals(actual, expected) {
+  assert_true(actual instanceof DOMRectReadOnly);
+  if(Array.isArray(expected)) {
+    assert_equals(expected.length, 8);
+    assert_equals(actual.x, expected[0], "rect equality: x differs");
+    assert_equals(actual.y, expected[1], "rect equality: y differs");
+    assert_equals(actual.width, expected[2], "rect equality: width differs");
+    assert_equals(actual.height, expected[3], "rect equality: height differs");
+    assert_equals(actual.top, expected[4], "rect equality: top differs");
+    assert_equals(actual.right, expected[5], "rect equality: right differs");
+    assert_equals(actual.bottom, expected[6], "rect equality: bottom differs");
+    assert_equals(actual.left, expected[7], "rect equality: left differs");
+  } else if(expected instanceof DOMRectReadOnly) {
+    assert_equals(actual.x, expected.x, "rect equality: x differs");
+    assert_equals(actual.y, expected.y, "rect equality: y differs");
+    assert_equals(actual.width, expected.width, "rect equality: width differs");
+    assert_equals(actual.height, expected.height, "rect equality: height differs");
+    assert_equals(actual.top, expected.top, "rect equality: top differs");
+    assert_equals(actual.right, expected.right, "rect equality: right differs");
+    assert_equals(actual.bottom, expected.bottom, "rect equality: bottom differs");
+    assert_equals(actual.left, expected.left, "poirectnt equality: left differs");
+  } else {
+    assert_unreached();
+  }
+}
\ No newline at end of file
index 148bfe7..6bf9f1f 100644 (file)
@@ -1,3 +1,14 @@
+2017-06-04  Chris Dumez  <cdumez@apple.com>
+
+        Implement DOMMatrixReadOnly.transformPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=172900
+
+        Reviewed by Simon Fraser.
+
+        Rebaseline W3C test now that more checks are passing.
+
+        * web-platform-tests/css/geometry-1/DOMMatrix-newobject-expected.txt:
+
 2017-06-03  Chris Dumez  <cdumez@apple.com>
 
         Implement DOMMatrix's fromFloat32Array / fromFloat64Array & toFloat32Array / toFloat64Array
index d2313c4..9d9e3c9 100644 (file)
@@ -11,7 +11,7 @@ PASS DOMMatrix multiply
 PASS DOMMatrix flipX 
 PASS DOMMatrix flipY 
 PASS DOMMatrix inverse 
-FAIL DOMMatrix transformPoint matrix[method] is not a function. (In 'matrix[method]()', 'matrix[method]' is undefined)
+PASS DOMMatrix transformPoint 
 PASS DOMMatrix toFloat32Array 
 PASS DOMMatrix toFloat64Array 
 PASS DOMMatrixReadOnly translate 
@@ -26,7 +26,7 @@ PASS DOMMatrixReadOnly multiply
 PASS DOMMatrixReadOnly flipX 
 PASS DOMMatrixReadOnly flipY 
 PASS DOMMatrixReadOnly inverse 
-FAIL DOMMatrixReadOnly transformPoint matrix[method] is not a function. (In 'matrix[method]()', 'matrix[method]' is undefined)
+PASS DOMMatrixReadOnly transformPoint 
 PASS DOMMatrixReadOnly toFloat32Array 
 PASS DOMMatrixReadOnly toFloat64Array 
 
index 0916675..b95749a 100644 (file)
@@ -1,3 +1,21 @@
+2017-06-04  Chris Dumez  <cdumez@apple.com>
+
+        Implement DOMMatrixReadOnly.transformPoint()
+        https://bugs.webkit.org/show_bug.cgi?id=172900
+
+        Reviewed by Simon Fraser.
+
+        Implement DOMMatrixReadOnly.transformPoint():
+        - https://drafts.fxtf.org/geometry/#dommatrixreadonly
+        - https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-transformpoint
+
+        Test: imported/blink/fast/dom/geometry-interfaces-dom-matrix-transformPoint.html
+
+        * css/DOMMatrixReadOnly.cpp:
+        (WebCore::DOMMatrixReadOnly::transformPoint):
+        * css/DOMMatrixReadOnly.h:
+        * css/DOMMatrixReadOnly.idl:
+
 2017-06-04  Zan Dobersek  <zdobersek@igalia.com>
 
         [GCrypt] Improve comments in AES, PBKDF2, RSA-SSA algorithm implementations
index 82da40b..5e64230 100644 (file)
@@ -29,6 +29,7 @@
 #include "CSSParser.h"
 #include "CSSToLengthConversionData.h"
 #include "DOMMatrix.h"
+#include "DOMPoint.h"
 #include "ExceptionCode.h"
 #include "StyleProperties.h"
 #include "TransformFunctions.h"
@@ -285,6 +286,13 @@ Ref<DOMMatrix> DOMMatrixReadOnly::inverse() const
     return matrix->invertSelf();
 }
 
+// https://drafts.fxtf.org/geometry/#dom-dommatrixreadonly-transformpoint
+Ref<DOMPoint> DOMMatrixReadOnly::transformPoint(DOMPointInit&& pointInit)
+{
+    m_matrix.map4ComponentPoint(pointInit.x, pointInit.y, pointInit.z, pointInit.w);
+    return DOMPoint::create(pointInit.x, pointInit.y, pointInit.z, pointInit.w);
+}
+
 ExceptionOr<Ref<Float32Array>> DOMMatrixReadOnly::toFloat32Array() const
 {
     auto array32 = Float32Array::createUninitialized(16);
index 7a10b23..407f22d 100644 (file)
@@ -39,6 +39,8 @@
 namespace WebCore {
 
 class DOMMatrix;
+class DOMPoint;
+struct DOMPointInit;
 
 class DOMMatrixReadOnly : public ScriptWrappable, public RefCounted<DOMMatrixReadOnly> {
     WTF_MAKE_FAST_ALLOCATED;
@@ -111,6 +113,8 @@ public:
     Ref<DOMMatrix> skewY(double sy = 0); // Angle is in degrees.
     Ref<DOMMatrix> inverse() const;
 
+    Ref<DOMPoint> transformPoint(DOMPointInit&&);
+
     ExceptionOr<Ref<Float32Array>> toFloat32Array() const;
     ExceptionOr<Ref<Float64Array>> toFloat64Array() const;
 
index 3cf0e46..5826041 100644 (file)
@@ -92,7 +92,7 @@
     [NewObject] DOMMatrix flipY();
     [NewObject] DOMMatrix inverse();
 
-    // [NewObject] DOMPoint transformPoint(optional DOMPointInit point); // FIXME: Implement this.
+    [NewObject] DOMPoint transformPoint(optional DOMPointInit point);
     [MayThrowException] Float32Array toFloat32Array();
     [MayThrowException] Float64Array toFloat64Array();