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 11namespace cc { 12namespace { 13 14// TODO(danakj) Move this test to ui/gfx/ when we don't need MathUtil::MapQuad. 15TEST(FloatQuadTest, IsRectilinearTest) { 16 const int kNumRectilinear = 8; 17 gfx::Transform rectilinear_trans[kNumRectilinear]; 18 rectilinear_trans[1].Rotate(90.0); 19 rectilinear_trans[2].Rotate(180.0); 20 rectilinear_trans[3].Rotate(270.0); 21 rectilinear_trans[4].SkewX(0.00000000001); 22 rectilinear_trans[5].SkewY(0.00000000001); 23 rectilinear_trans[6].Scale(0.00001, 0.00001); 24 rectilinear_trans[6].Rotate(180.0); 25 rectilinear_trans[7].Scale(100000, 100000); 26 rectilinear_trans[7].Rotate(180.0); 27 28 for (int i = 0; i < kNumRectilinear; ++i) { 29 bool clipped = false; 30 gfx::QuadF quad = MathUtil::MapQuad( 31 rectilinear_trans[i], 32 gfx::QuadF( 33 gfx::RectF(0.01010101f, 0.01010101f, 100.01010101f, 100.01010101f)), 34 &clipped); 35 ASSERT_TRUE(!clipped); 36 EXPECT_TRUE(quad.IsRectilinear()); 37 } 38 39 const int kNumNonRectilinear = 10; 40 gfx::Transform non_rectilinear_trans[kNumNonRectilinear]; 41 non_rectilinear_trans[0].Rotate(359.999); 42 non_rectilinear_trans[1].Rotate(0.0000001); 43 non_rectilinear_trans[2].Rotate(89.999999); 44 non_rectilinear_trans[3].Rotate(90.0000001); 45 non_rectilinear_trans[4].Rotate(179.999999); 46 non_rectilinear_trans[5].Rotate(180.0000001); 47 non_rectilinear_trans[6].Rotate(269.999999); 48 non_rectilinear_trans[7].Rotate(270.0000001); 49 non_rectilinear_trans[8].SkewX(0.00001); 50 non_rectilinear_trans[9].SkewY(0.00001); 51 52 for (int i = 0; i < kNumNonRectilinear; ++i) { 53 bool clipped = false; 54 gfx::QuadF quad = MathUtil::MapQuad( 55 non_rectilinear_trans[i], 56 gfx::QuadF( 57 gfx::RectF(0.01010101f, 0.01010101f, 100.01010101f, 100.01010101f)), 58 &clipped); 59 ASSERT_TRUE(!clipped); 60 EXPECT_FALSE(quad.IsRectilinear()); 61 } 62} 63 64} // namespace 65} // namespace cc 66