blob: 6d9ce02f86298a5a56a55c4e8b4e16e3b85f961a (
plain)
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
|
// Copyright 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 "cc/base/math_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/transform.h"
namespace cc {
namespace {
// TODO(danakj) Move this test to ui/gfx/ when we don't need MathUtil::MapQuad.
TEST(FloatQuadTest, IsRectilinearTest) {
const int kNumRectilinear = 8;
gfx::Transform rectilinear_trans[kNumRectilinear];
rectilinear_trans[1].Rotate(90.f);
rectilinear_trans[2].Rotate(180.f);
rectilinear_trans[3].Rotate(270.f);
rectilinear_trans[4].SkewX(0.00000000001f);
rectilinear_trans[5].SkewY(0.00000000001f);
rectilinear_trans[6].Scale(0.00001f, 0.00001f);
rectilinear_trans[6].Rotate(180.f);
rectilinear_trans[7].Scale(100000.f, 100000.f);
rectilinear_trans[7].Rotate(180.f);
gfx::QuadF original(
gfx::RectF(0.01010101f, 0.01010101f, 100.01010101f, 100.01010101f));
for (int i = 0; i < kNumRectilinear; ++i) {
bool clipped = false;
gfx::QuadF quad =
MathUtil::MapQuad(rectilinear_trans[i], original, &clipped);
ASSERT_TRUE(!clipped) << "case " << i;
EXPECT_TRUE(quad.IsRectilinear()) << "case " << i;
}
const int kNumNonRectilinear = 10;
gfx::Transform non_rectilinear_trans[kNumNonRectilinear];
non_rectilinear_trans[0].Rotate(359.9999f);
non_rectilinear_trans[1].Rotate(0.0000001f);
non_rectilinear_trans[2].Rotate(89.9999f);
non_rectilinear_trans[3].Rotate(90.00001f);
non_rectilinear_trans[4].Rotate(179.9999f);
non_rectilinear_trans[5].Rotate(180.00001f);
non_rectilinear_trans[6].Rotate(269.9999f);
non_rectilinear_trans[7].Rotate(270.0001f);
non_rectilinear_trans[8].SkewX(0.00001f);
non_rectilinear_trans[9].SkewY(0.00001f);
for (int i = 0; i < kNumNonRectilinear; ++i) {
bool clipped = false;
gfx::QuadF quad =
MathUtil::MapQuad(non_rectilinear_trans[i], original, &clipped);
ASSERT_TRUE(!clipped) << "case " << i;
EXPECT_FALSE(quad.IsRectilinear()) << "case " << i;
}
}
} // namespace
} // namespace cc
|