From e10288ec1ce747cba0f1013faf43667fa3971da8 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 25 Jun 2016 22:35:20 -0700 Subject: [PATCH 1/3] Linearly interpolate rotation angles with equal direction Fixes #11808, but still leaves matrix interpolation open. --- .../properties/helpers/animated_properties.mako.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 3b75b4ee07b..b5a2eaef532 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -663,9 +663,14 @@ fn interpolate_transform_list(from_list: &[TransformOperation], result.push(TransformOperation::Scale(ix, iy, iz)); } (&TransformOperation::Rotate(fx, fy, fz, fa), - &TransformOperation::Rotate(_tx, _ty, _tz, _ta)) => { - // TODO(gw): Implement matrix decomposition and interpolation - result.push(TransformOperation::Rotate(fx, fy, fz, fa)); + &TransformOperation::Rotate(tx, ty, tz, ta)) => { + if fx == tx && fy == ty && fz == tz { + let ia = fa.interpolate(&ta, time).unwrap(); + result.push(TransformOperation::Rotate(fx, fy, fz, ia)); + } else { + // TODO(gw): Implement matrix decomposition and interpolation + result.push(TransformOperation::Rotate(fx, fy, fz, fa)); + } } (&TransformOperation::Perspective(fd), &TransformOperation::Perspective(_td)) => { From cab6260c3242d7a5c02e80144336594f1f1afafb Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sun, 26 Jun 2016 09:10:31 -0700 Subject: [PATCH 2/3] Add tests for rotation animation --- tests/wpt/mozilla/meta/MANIFEST.json | 24 +++++++++++++++++ tests/wpt/mozilla/tests/css/rotate_anim.html | 26 +++++++++++++++++++ .../mozilla/tests/css/rotate_anim_ref.html | 11 ++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/wpt/mozilla/tests/css/rotate_anim.html create mode 100644 tests/wpt/mozilla/tests/css/rotate_anim_ref.html diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index fff9517a8b1..19abc30928d 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -4516,6 +4516,18 @@ "url": "/_mozilla/css/root_pseudo_a.html" } ], + "css/rotate_anim.html": [ + { + "path": "css/rotate_anim.html", + "references": [ + [ + "/_mozilla/css/rotate_anim_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/rotate_anim.html" + } + ], "css/rtl_body.html": [ { "path": "css/rtl_body.html", @@ -11604,6 +11616,18 @@ "url": "/_mozilla/css/root_pseudo_a.html" } ], + "css/rotate_anim.html": [ + { + "path": "css/rotate_anim.html", + "references": [ + [ + "/_mozilla/css/rotate_anim_ref.html", + "==" + ] + ], + "url": "/_mozilla/css/rotate_anim.html" + } + ], "css/rtl_body.html": [ { "path": "css/rtl_body.html", diff --git a/tests/wpt/mozilla/tests/css/rotate_anim.html b/tests/wpt/mozilla/tests/css/rotate_anim.html new file mode 100644 index 00000000000..a05f75c44ac --- /dev/null +++ b/tests/wpt/mozilla/tests/css/rotate_anim.html @@ -0,0 +1,26 @@ + + + +Rotation transformation + + +
Hello Servo!
+ + diff --git a/tests/wpt/mozilla/tests/css/rotate_anim_ref.html b/tests/wpt/mozilla/tests/css/rotate_anim_ref.html new file mode 100644 index 00000000000..84a9fea14ef --- /dev/null +++ b/tests/wpt/mozilla/tests/css/rotate_anim_ref.html @@ -0,0 +1,11 @@ + +Rotation transformation reference + +
Hello Servo!
+ From 0dd99e6bd27e9463817ba6acf4a789d82fef3ea7 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 27 Jun 2016 08:04:55 -0700 Subject: [PATCH 3/3] Normalize the direction vector for rotate --- .../style/properties/helpers/animated_properties.mako.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index b5a2eaef532..55ea436b5da 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -664,6 +664,10 @@ fn interpolate_transform_list(from_list: &[TransformOperation], } (&TransformOperation::Rotate(fx, fy, fz, fa), &TransformOperation::Rotate(tx, ty, tz, ta)) => { + let norm_f = ((fx * fx) + (fy * fy) + (fz * fz)).sqrt(); + let norm_t = ((tx * tx) + (ty * ty) + (tz * tz)).sqrt(); + let (fx, fy, fz) = (fx / norm_f, fy / norm_f, fz / norm_f); + let (tx, ty, tz) = (tx / norm_t, ty / norm_t, tz / norm_t); if fx == tx && fy == ty && fz == tz { let ia = fa.interpolate(&ta, time).unwrap(); result.push(TransformOperation::Rotate(fx, fy, fz, ia));