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 target = addDiv(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) {
var target = addDiv(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 target = addDiv(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 target = addDiv(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),
) => {