• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "cc/base/math_util.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/gfx/quad_f.h"
8 #include "ui/gfx/rect_f.h"
9 #include "ui/gfx/transform.h"
10 
11 namespace cc {
12 namespace {
13 
14 // TODO(danakj) Move this test to ui/gfx/ when we don't need MathUtil::MapQuad.
TEST(FloatQuadTest,IsRectilinearTest)15 TEST(FloatQuadTest, IsRectilinearTest) {
16   const int kNumRectilinear = 8;
17   gfx::Transform rectilinear_trans[kNumRectilinear];
18   rectilinear_trans[1].Rotate(90.f);
19   rectilinear_trans[2].Rotate(180.f);
20   rectilinear_trans[3].Rotate(270.f);
21   rectilinear_trans[4].SkewX(0.00000000001f);
22   rectilinear_trans[5].SkewY(0.00000000001f);
23   rectilinear_trans[6].Scale(0.00001f, 0.00001f);
24   rectilinear_trans[6].Rotate(180.f);
25   rectilinear_trans[7].Scale(100000.f, 100000.f);
26   rectilinear_trans[7].Rotate(180.f);
27 
28   gfx::QuadF original(
29       gfx::RectF(0.01010101f, 0.01010101f, 100.01010101f, 100.01010101f));
30 
31   for (int i = 0; i < kNumRectilinear; ++i) {
32     bool clipped = false;
33     gfx::QuadF quad =
34         MathUtil::MapQuad(rectilinear_trans[i], original, &clipped);
35     ASSERT_TRUE(!clipped) << "case " << i;
36     EXPECT_TRUE(quad.IsRectilinear()) << "case " << i;
37   }
38 
39   const int kNumNonRectilinear = 10;
40   gfx::Transform non_rectilinear_trans[kNumNonRectilinear];
41   non_rectilinear_trans[0].Rotate(359.9999f);
42   non_rectilinear_trans[1].Rotate(0.0000001f);
43   non_rectilinear_trans[2].Rotate(89.9999f);
44   non_rectilinear_trans[3].Rotate(90.00001f);
45   non_rectilinear_trans[4].Rotate(179.9999f);
46   non_rectilinear_trans[5].Rotate(180.00001f);
47   non_rectilinear_trans[6].Rotate(269.9999f);
48   non_rectilinear_trans[7].Rotate(270.0001f);
49   non_rectilinear_trans[8].SkewX(0.00001f);
50   non_rectilinear_trans[9].SkewY(0.00001f);
51 
52   for (int i = 0; i < kNumNonRectilinear; ++i) {
53     bool clipped = false;
54     gfx::QuadF quad =
55         MathUtil::MapQuad(non_rectilinear_trans[i], original, &clipped);
56     ASSERT_TRUE(!clipped) << "case " << i;
57     EXPECT_FALSE(quad.IsRectilinear()) << "case " << i;
58   }
59 }
60 
61 }  // namespace
62 }  // namespace cc
63