Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/gfx/interpolated_transform.h" | 5 #include "ui/gfx/interpolated_transform.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "ui/gfx/rect.h" | 9 #include "ui/gfx/rect.h" |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 | 31 |
| 32 } // namespace | 32 } // namespace |
| 33 | 33 |
| 34 TEST(InterpolatedTransformTest, InterpolatedRotation) { | 34 TEST(InterpolatedTransformTest, InterpolatedRotation) { |
| 35 ui::InterpolatedRotation interpolated_rotation(0, 100); | 35 ui::InterpolatedRotation interpolated_rotation(0, 100); |
| 36 ui::InterpolatedRotation interpolated_rotation_diff_start_end( | 36 ui::InterpolatedRotation interpolated_rotation_diff_start_end( |
| 37 0, 100, 100, 200); | 37 0, 100, 100, 200); |
| 38 | 38 |
| 39 for (int i = 0; i <= 100; ++i) { | 39 for (int i = 0; i <= 100; ++i) { |
| 40 gfx::Transform rotation; | 40 gfx::Transform rotation; |
| 41 rotation.SetRotate(i); | 41 rotation.Rotate(i); |
| 42 gfx::Transform interpolated = interpolated_rotation.Interpolate(i / 100.0f); | 42 gfx::Transform interpolated = interpolated_rotation.Interpolate(i / 100.0f); |
| 43 CheckApproximatelyEqual(rotation, interpolated); | 43 CheckApproximatelyEqual(rotation, interpolated); |
| 44 interpolated = interpolated_rotation_diff_start_end.Interpolate(i + 100); | 44 interpolated = interpolated_rotation_diff_start_end.Interpolate(i + 100); |
| 45 CheckApproximatelyEqual(rotation, interpolated); | 45 CheckApproximatelyEqual(rotation, interpolated); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 TEST(InterpolatedTransformTest, InterpolatedScale) { | 49 TEST(InterpolatedTransformTest, InterpolatedScale) { |
| 50 ui::InterpolatedScale interpolated_scale(gfx::Point3F(0, 0, 0), | 50 ui::InterpolatedScale interpolated_scale(gfx::Point3F(0, 0, 0), |
| 51 gfx::Point3F(100, 100, 100)); | 51 gfx::Point3F(100, 100, 100)); |
| 52 ui::InterpolatedScale interpolated_scale_diff_start_end( | 52 ui::InterpolatedScale interpolated_scale_diff_start_end( |
| 53 gfx::Point3F(0, 0, 0), gfx::Point3F(100, 100, 100), 100, 200); | 53 gfx::Point3F(0, 0, 0), gfx::Point3F(100, 100, 100), 100, 200); |
| 54 | 54 |
| 55 for (int i = 0; i <= 100; ++i) { | 55 for (int i = 0; i <= 100; ++i) { |
| 56 gfx::Transform scale; | 56 gfx::Transform scale; |
| 57 scale.SetScale(i, i); | 57 scale.Scale(i, i); |
| 58 gfx::Transform interpolated = interpolated_scale.Interpolate(i / 100.0f); | 58 gfx::Transform interpolated = interpolated_scale.Interpolate(i / 100.0f); |
| 59 CheckApproximatelyEqual(scale, interpolated); | 59 CheckApproximatelyEqual(scale, interpolated); |
| 60 interpolated = interpolated_scale_diff_start_end.Interpolate(i + 100); | 60 interpolated = interpolated_scale_diff_start_end.Interpolate(i + 100); |
| 61 CheckApproximatelyEqual(scale, interpolated); | 61 CheckApproximatelyEqual(scale, interpolated); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST(InterpolatedTransformTest, InterpolatedTranslate) { | 65 TEST(InterpolatedTransformTest, InterpolatedTranslate) { |
| 66 ui::InterpolatedTranslation interpolated_xform(gfx::Point(0, 0), | 66 ui::InterpolatedTranslation interpolated_xform(gfx::Point(0, 0), |
| 67 gfx::Point(100, 100)); | 67 gfx::Point(100, 100)); |
| 68 | 68 |
| 69 ui::InterpolatedTranslation interpolated_xform_diff_start_end( | 69 ui::InterpolatedTranslation interpolated_xform_diff_start_end( |
| 70 gfx::Point(0, 0), gfx::Point(100, 100), 100, 200); | 70 gfx::Point(0, 0), gfx::Point(100, 100), 100, 200); |
| 71 | 71 |
| 72 for (int i = 0; i <= 100; ++i) { | 72 for (int i = 0; i <= 100; ++i) { |
| 73 gfx::Transform xform; | 73 gfx::Transform xform; |
| 74 xform.SetTranslate(i, i); | 74 xform.Translate(i, i); |
| 75 gfx::Transform interpolated = interpolated_xform.Interpolate(i / 100.0f); | 75 gfx::Transform interpolated = interpolated_xform.Interpolate(i / 100.0f); |
| 76 CheckApproximatelyEqual(xform, interpolated); | 76 CheckApproximatelyEqual(xform, interpolated); |
| 77 interpolated = interpolated_xform_diff_start_end.Interpolate(i + 100); | 77 interpolated = interpolated_xform_diff_start_end.Interpolate(i + 100); |
| 78 CheckApproximatelyEqual(xform, interpolated); | 78 CheckApproximatelyEqual(xform, interpolated); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST(InterpolatedTransformTest, InterpolatedRotationAboutPivot) { | 82 TEST(InterpolatedTransformTest, InterpolatedRotationAboutPivot) { |
| 83 gfx::Point pivot(100, 100); | 83 gfx::Point pivot(100, 100); |
| 84 gfx::Point above_pivot(100, 200); | 84 gfx::Point above_pivot(100, 200); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 107 CheckApproximatelyEqual(gfx::Transform(), result); | 107 CheckApproximatelyEqual(gfx::Transform(), result); |
| 108 result = interpolated_xform.Interpolate(1.0f); | 108 result = interpolated_xform.Interpolate(1.0f); |
| 109 gfx::Point expected_result = pivot; | 109 gfx::Point expected_result = pivot; |
| 110 result.TransformPoint(pivot); | 110 result.TransformPoint(pivot); |
| 111 EXPECT_EQ(expected_result, pivot); | 111 EXPECT_EQ(expected_result, pivot); |
| 112 expected_result = gfx::Point(100, 300); | 112 expected_result = gfx::Point(100, 300); |
| 113 result.TransformPoint(above_pivot); | 113 result.TransformPoint(above_pivot); |
| 114 EXPECT_EQ(expected_result, above_pivot); | 114 EXPECT_EQ(expected_result, above_pivot); |
| 115 } | 115 } |
| 116 | 116 |
| 117 TEST(InterpolatedTransformTest, FactorTRS) { | |
|
danakj
2012/11/16 19:46:12
Can you point me at the test that replaces this?
Ian Vollick
2012/11/16 21:51:24
This test did still seem useful, so I've ported it
| |
| 118 for (int degrees = 0; degrees < 360; ++degrees) { | |
| 119 // build a transformation matrix. | |
| 120 gfx::Transform transform; | |
| 121 transform.SetScale(degrees + 1, 2 * degrees + 1); | |
| 122 transform.ConcatRotate(degrees); | |
| 123 transform.ConcatTranslate(degrees * 2, -degrees * 3); | |
| 124 | |
| 125 // factor the matrix | |
| 126 gfx::Point translation; | |
| 127 float rotation; | |
| 128 gfx::Point3F scale; | |
| 129 bool success = ui::InterpolatedTransform::FactorTRS(transform, | |
| 130 &translation, | |
| 131 &rotation, | |
| 132 &scale); | |
| 133 EXPECT_TRUE(success); | |
| 134 EXPECT_FLOAT_EQ(translation.x(), degrees * 2); | |
| 135 EXPECT_FLOAT_EQ(translation.y(), -degrees * 3); | |
| 136 EXPECT_FLOAT_EQ(NormalizeAngle(rotation), degrees); | |
| 137 EXPECT_FLOAT_EQ(scale.x(), degrees + 1); | |
| 138 EXPECT_FLOAT_EQ(scale.y(), 2 * degrees + 1); | |
| 139 } | |
| 140 } | |
| 141 | |
| 142 ui::InterpolatedTransform* GetScreenRotation(int degrees, bool reversed) { | 117 ui::InterpolatedTransform* GetScreenRotation(int degrees, bool reversed) { |
| 143 gfx::Point old_pivot; | 118 gfx::Point old_pivot; |
| 144 gfx::Point new_pivot; | 119 gfx::Point new_pivot; |
| 145 | 120 |
| 146 int width = 1920; | 121 int width = 1920; |
| 147 int height = 180; | 122 int height = 180; |
| 148 | 123 |
| 149 switch (degrees) { | 124 switch (degrees) { |
| 150 case 90: | 125 case 90: |
| 151 new_pivot = gfx::Point(width, 0); | 126 new_pivot = gfx::Point(width, 0); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 250 gfx::Transform interpolated = maximize->Interpolate(1.0f); | 225 gfx::Transform interpolated = maximize->Interpolate(1.0f); |
| 251 SkMatrix44& m = interpolated.matrix(); | 226 SkMatrix44& m = interpolated.matrix(); |
| 252 // Upper-left 3x3 matrix should all be 0, 1 or -1. | 227 // Upper-left 3x3 matrix should all be 0, 1 or -1. |
| 253 for (int row = 0; row < 3; ++row) { | 228 for (int row = 0; row < 3; ++row) { |
| 254 for (int col = 0; col < 3; ++col) { | 229 for (int col = 0; col < 3; ++col) { |
| 255 float entry = m.get(row, col); | 230 float entry = m.get(row, col); |
| 256 EXPECT_TRUE(entry == 0 || entry == 1 || entry == -1); | 231 EXPECT_TRUE(entry == 0 || entry == 1 || entry == -1); |
| 257 } | 232 } |
| 258 } | 233 } |
| 259 } | 234 } |
| 260 | |
| OLD | NEW |