1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/gfx/interpolated_transform.h"
#include "base/basictypes.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
void CheckApproximatelyEqual(const ui::Transform& lhs,
const ui::Transform& rhs) {
for (int i = 0; i < 4; ++i) {
for (int j = 0; j < 4; ++j) {
EXPECT_FLOAT_EQ(lhs.matrix().get(i, j), rhs.matrix().get(i, j));
}
}
}
} // namespace
TEST(InterpolatedTransformTest, InterpolatedRotation) {
ui::InterpolatedRotation interpolated_rotation(0, 100);
ui::InterpolatedRotation interpolated_rotation_diff_start_end(
0, 100, 100, 200);
for (int i = 0; i <= 100; ++i) {
ui::Transform rotation;
rotation.SetRotate(i);
ui::Transform interpolated = interpolated_rotation.Interpolate(i / 100.0f);
CheckApproximatelyEqual(rotation, interpolated);
interpolated = interpolated_rotation_diff_start_end.Interpolate(i + 100);
CheckApproximatelyEqual(rotation, interpolated);
}
}
TEST(InterpolatedTransformTest, InterpolatedScale) {
ui::InterpolatedScale interpolated_scale(0, 100);
ui::InterpolatedScale interpolated_scale_diff_start_end(
0, 100, 100, 200);
for (int i = 0; i <= 100; ++i) {
ui::Transform scale;
scale.SetScale(i, i);
ui::Transform interpolated = interpolated_scale.Interpolate(i / 100.0f);
CheckApproximatelyEqual(scale, interpolated);
interpolated = interpolated_scale_diff_start_end.Interpolate(i + 100);
CheckApproximatelyEqual(scale, interpolated);
}
}
TEST(InterpolatedTransformTest, InterpolatedTranslate) {
ui::InterpolatedTranslation interpolated_xform(gfx::Point(0, 0),
gfx::Point(100, 100));
ui::InterpolatedTranslation interpolated_xform_diff_start_end(
gfx::Point(0, 0), gfx::Point(100, 100), 100, 200);
for (int i = 0; i <= 100; ++i) {
ui::Transform xform;
xform.SetTranslate(i, i);
ui::Transform interpolated = interpolated_xform.Interpolate(i / 100.0f);
CheckApproximatelyEqual(xform, interpolated);
interpolated = interpolated_xform_diff_start_end.Interpolate(i + 100);
CheckApproximatelyEqual(xform, interpolated);
}
}
TEST(InterpolatedTransformTest, InterpolatedRotationAboutPivot) {
gfx::Point pivot(100, 100);
gfx::Point above_pivot(100, 200);
ui::InterpolatedRotation rot(0, 90);
ui::InterpolatedTransformAboutPivot interpolated_xform(
pivot,
new ui::InterpolatedRotation(0, 90));
ui::Transform result = interpolated_xform.Interpolate(0.0f);
CheckApproximatelyEqual(ui::Transform(), result);
result = interpolated_xform.Interpolate(1.0f);
gfx::Point expected_result = pivot;
result.TransformPoint(pivot);
EXPECT_EQ(expected_result, pivot);
expected_result = gfx::Point(0, 100);
result.TransformPoint(above_pivot);
EXPECT_EQ(expected_result, above_pivot);
}
TEST(InterpolatedTransformTest, InterpolatedScaleAboutPivot) {
gfx::Point pivot(100, 100);
gfx::Point above_pivot(100, 200);
ui::InterpolatedTransformAboutPivot interpolated_xform(
pivot,
new ui::InterpolatedScale(1, 2));
ui::Transform result = interpolated_xform.Interpolate(0.0f);
CheckApproximatelyEqual(ui::Transform(), result);
result = interpolated_xform.Interpolate(1.0f);
gfx::Point expected_result = pivot;
result.TransformPoint(pivot);
EXPECT_EQ(expected_result, pivot);
expected_result = gfx::Point(100, 300);
result.TransformPoint(above_pivot);
EXPECT_EQ(expected_result, above_pivot);
}
|