Bug 1458927: Fix perspective squared distance computation. r?hiro draft
 author Emilio Cobos Álvarez Thu, 03 May 2018 17:43:30 +0200 changeset 791139 1c7efdb4747b29c8553a8d171df8107ed182d03f parent 791138 f21e94af4820e1523c3ba492a187e17a30440574 child 791163 1e2705ef96f9c79112a60ad3e7cb2b2f9615a8a3 push id 108710 push user bmo:emilio@crisal.io push date Thu, 03 May 2018 15:47:05 +0000 reviewers hiro bugs 1458927 milestone 61.0a1
Bug 1458927: Fix perspective squared distance computation. r?hiro MozReview-Commit-ID: YwjTheRonB
```--- a/dom/animation/test/mozilla/test_distance_of_transform.html
+++ b/dom/animation/test/mozilla/test_distance_of_transform.html
@@ -187,35 +187,35 @@ test(function(t) {
assert_equals(dist, Math.sqrt(2 * 2 + 0.5 * 0.5), 'distance of skew');
}, 'Test distance of skew functions');

test(function(t) {
var dist = getDistance(target, 'transform',
'perspective(128px)',
'none');
-  assert_equals(dist, 1/128, 'distance of perspective');
+  assert_equals(dist, 128, 'distance of perspective');
}, 'Test distance of perspective function and none');

test(function(t) {
// perspective(0) is treated as perspective(inf) because perspective length
// should be greater than or equal to zero.
var dist = getDistance(target, 'transform',
'perspective(128px)',
'perspective(0)');
-  assert_equals(dist, 1/128, 'distance of perspective');
+  assert_equals(dist, 128, 'distance of perspective');
}, 'Test distance of perspective function and an invalid perspective');

test(function(t) {
var dist = getDistance(target, 'transform',
'perspective(128px)',
'perspective(1024px)');
-  assert_equals(dist, 1/128 - 1/1024, 'distance of perspective');
+  assert_equals(dist, 1024 - 128, 'distance of perspective');
}, 'Test distance of perspective functions');

test(function(t) {
var sin_30 = Math.sin(Math.PI / 6);
var cos_30 = Math.cos(Math.PI / 6);
// matrix => translate(100, 0) rotate(30deg).
var matrix = createMatrixFromArray([ cos_30, sin_30,```
```--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -2627,26 +2627,17 @@ impl ComputeSquaredDistance for Computed
&TransformOperation::Rotate(ta),
) => {
fa.compute_squared_distance(&ta)
}
(
&TransformOperation::Perspective(ref fd),
&TransformOperation::Perspective(ref td),
) => {
-                let mut fd_matrix = Matrix3D::identity();
-                let mut td_matrix = Matrix3D::identity();
-                if fd.px() > 0. {
-                    fd_matrix.m34 = -1. / fd.px();
-                }
-
-                if td.px() > 0. {
-                    td_matrix.m34 = -1. / td.px();
-                }
-                fd_matrix.compute_squared_distance(&td_matrix)
+                fd.compute_squared_distance(td)
}
(
&TransformOperation::Perspective(ref p),
&TransformOperation::Matrix3D(ref m),
) | (
&TransformOperation::Matrix3D(ref m),
&TransformOperation::Perspective(ref p),
) => {```