Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1342)

Side by Side Diff: cc/math_util_unittest.cc

Issue 11264056: cc: Use gfx:: Geometry types for positions, bounds, and related things. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ScaleAsVector Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/math_util.cc ('k') | cc/occlusion_tracker.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "config.h" 5 #include "config.h"
6 6
7 #include "cc/math_util.h" 7 #include "cc/math_util.h"
8 8
9 #include "FloatRect.h"
10 #include "cc/test/geometry_test_utils.h" 9 #include "cc/test/geometry_test_utils.h"
11 #include "testing/gmock/include/gmock/gmock.h" 10 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/rect_f.h"
13 #include <public/WebTransformationMatrix.h> 14 #include <public/WebTransformationMatrix.h>
14 15
15 using namespace cc; 16 using namespace cc;
16 using WebKit::WebTransformationMatrix; 17 using WebKit::WebTransformationMatrix;
17 18
18 namespace { 19 namespace {
19 20
20 TEST(MathUtilTest, verifyBackfaceVisibilityBasicCases) 21 TEST(MathUtilTest, verifyBackfaceVisibilityBasicCases)
21 { 22 {
22 WebTransformationMatrix transform; 23 WebTransformationMatrix transform;
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 84
84 TEST(MathUtilTest, verifyProjectionOfPerpendicularPlane) 85 TEST(MathUtilTest, verifyProjectionOfPerpendicularPlane)
85 { 86 {
86 // In this case, the m33() element of the transform becomes zero, which coul d cause a 87 // In this case, the m33() element of the transform becomes zero, which coul d cause a
87 // divide-by-zero when projecting points/quads. 88 // divide-by-zero when projecting points/quads.
88 89
89 WebTransformationMatrix transform; 90 WebTransformationMatrix transform;
90 transform.makeIdentity(); 91 transform.makeIdentity();
91 transform.setM33(0); 92 transform.setM33(0);
92 93
93 FloatRect rect = FloatRect(0, 0, 1, 1); 94 gfx::RectF rect = gfx::RectF(0, 0, 1, 1);
94 FloatRect projectedRect = MathUtil::projectClippedRect(transform, rect); 95 gfx::RectF projectedRect = MathUtil::projectClippedRect(transform, rect);
95 96
96 EXPECT_EQ(0, projectedRect.x()); 97 EXPECT_EQ(0, projectedRect.x());
97 EXPECT_EQ(0, projectedRect.y()); 98 EXPECT_EQ(0, projectedRect.y());
98 EXPECT_TRUE(projectedRect.isEmpty()); 99 EXPECT_TRUE(projectedRect.IsEmpty());
99 } 100 }
100 101
101 TEST(MathUtilTest, verifyEnclosingClippedRectUsesCorrectInitialBounds) 102 TEST(MathUtilTest, verifyEnclosingClippedRectUsesCorrectInitialBounds)
102 { 103 {
103 HomogeneousCoordinate h1(-100, -100, 0, 1); 104 HomogeneousCoordinate h1(-100, -100, 0, 1);
104 HomogeneousCoordinate h2(-10, -10, 0, 1); 105 HomogeneousCoordinate h2(-10, -10, 0, 1);
105 HomogeneousCoordinate h3(10, 10, 0, -1); 106 HomogeneousCoordinate h3(10, 10, 0, -1);
106 HomogeneousCoordinate h4(100, 100, 0, -1); 107 HomogeneousCoordinate h4(100, 100, 0, -1);
107 108
108 // The bounds of the enclosing clipped rect should be -100 to -10 for both x and y. 109 // The bounds of the enclosing clipped rect should be -100 to -10 for both x and y.
109 // However, if there is a bug where the initial xmin/xmax/ymin/ymax are init ialized to 110 // However, if there is a bug where the initial xmin/xmax/ymin/ymax are init ialized to
110 // numeric_limits<float>::min() (which is zero, not -flt_max) then the enclo sing 111 // numeric_limits<float>::min() (which is zero, not -flt_max) then the enclo sing
111 // clipped rect will be computed incorrectly. 112 // clipped rect will be computed incorrectly.
112 FloatRect result = MathUtil::computeEnclosingClippedRect(h1, h2, h3, h4); 113 gfx::RectF result = MathUtil::computeEnclosingClippedRect(h1, h2, h3, h4);
113 114
114 EXPECT_FLOAT_RECT_EQ(FloatRect(FloatPoint(-100, -100), FloatSize(90, 90)), r esult); 115 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(-100, -100), gfx::SizeF(90, 90)) , result);
115 } 116 }
116 117
117 TEST(MathUtilTest, verifyEnclosingRectOfVerticesUsesCorrectInitialBounds) 118 TEST(MathUtilTest, verifyEnclosingRectOfVerticesUsesCorrectInitialBounds)
118 { 119 {
119 FloatPoint vertices[3]; 120 gfx::PointF vertices[3];
120 int numVertices = 3; 121 int numVertices = 3;
121 122
122 vertices[0] = FloatPoint(-10, -100); 123 vertices[0] = gfx::PointF(-10, -100);
123 vertices[1] = FloatPoint(-100, -10); 124 vertices[1] = gfx::PointF(-100, -10);
124 vertices[2] = FloatPoint(-30, -30); 125 vertices[2] = gfx::PointF(-30, -30);
125 126
126 // The bounds of the enclosing rect should be -100 to -10 for both x and y. However, 127 // The bounds of the enclosing rect should be -100 to -10 for both x and y. However,
127 // if there is a bug where the initial xmin/xmax/ymin/ymax are initialized t o 128 // if there is a bug where the initial xmin/xmax/ymin/ymax are initialized t o
128 // numeric_limits<float>::min() (which is zero, not -flt_max) then the enclo sing 129 // numeric_limits<float>::min() (which is zero, not -flt_max) then the enclo sing
129 // clipped rect will be computed incorrectly. 130 // clipped rect will be computed incorrectly.
130 FloatRect result = MathUtil::computeEnclosingRectOfVertices(vertices, numVer tices); 131 gfx::RectF result = MathUtil::computeEnclosingRectOfVertices(vertices, numVe rtices);
131 132
132 EXPECT_FLOAT_RECT_EQ(FloatRect(FloatPoint(-100, -100), FloatSize(90, 90)), r esult); 133 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(-100, -100), gfx::SizeF(90, 90)) , result);
133 } 134 }
134 135
135 TEST(MathUtilTest, smallestAngleBetweenVectors) 136 TEST(MathUtilTest, smallestAngleBetweenVectors)
136 { 137 {
137 FloatSize x(1, 0); 138 FloatSize x(1, 0);
138 FloatSize y(0, 1); 139 FloatSize y(0, 1);
139 FloatSize testVector(0.5, 0.5); 140 FloatSize testVector(0.5, 0.5);
140 141
141 // Orthogonal vectors are at an angle of 90 degress. 142 // Orthogonal vectors are at an angle of 90 degress.
142 EXPECT_EQ(90, MathUtil::smallestAngleBetweenVectors(x, y)); 143 EXPECT_EQ(90, MathUtil::smallestAngleBetweenVectors(x, y));
(...skipping 30 matching lines...) Expand all
173 174
174 // Finally check than an arbitrary vector projected to another one gives a v ector parallel to 175 // Finally check than an arbitrary vector projected to another one gives a v ector parallel to
175 // the second vector. 176 // the second vector.
176 FloatSize targetVector(0.5, 0.2f); 177 FloatSize targetVector(0.5, 0.2f);
177 FloatSize projectedVector = MathUtil::projectVector(testVector, targetVector ); 178 FloatSize projectedVector = MathUtil::projectVector(testVector, targetVector );
178 EXPECT_EQ(projectedVector.width() / targetVector.width(), 179 EXPECT_EQ(projectedVector.width() / targetVector.width(),
179 projectedVector.height() / targetVector.height()); 180 projectedVector.height() / targetVector.height());
180 } 181 }
181 182
182 } // namespace 183 } // namespace
OLDNEW
« no previous file with comments | « cc/math_util.cc ('k') | cc/occlusion_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698