| OLD | NEW |
| 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 "FloatSize.h" | 9 #include <cmath> |
| 10 |
| 10 #include "cc/test/geometry_test_utils.h" | 11 #include "cc/test/geometry_test_utils.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 14 #include "ui/gfx/rect_f.h" | 15 #include "ui/gfx/rect_f.h" |
| 15 #include <public/WebTransformationMatrix.h> | 16 #include <public/WebTransformationMatrix.h> |
| 16 | 17 |
| 17 using namespace cc; | 18 using namespace cc; |
| 18 using WebKit::WebTransformationMatrix; | 19 using WebKit::WebTransformationMatrix; |
| 19 | 20 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 // if there is a bug where the initial xmin/xmax/ymin/ymax are initialized t
o | 130 // if there is a bug where the initial xmin/xmax/ymin/ymax are initialized t
o |
| 130 // numeric_limits<float>::min() (which is zero, not -flt_max) then the enclo
sing | 131 // numeric_limits<float>::min() (which is zero, not -flt_max) then the enclo
sing |
| 131 // clipped rect will be computed incorrectly. | 132 // clipped rect will be computed incorrectly. |
| 132 gfx::RectF result = MathUtil::computeEnclosingRectOfVertices(vertices, numVe
rtices); | 133 gfx::RectF result = MathUtil::computeEnclosingRectOfVertices(vertices, numVe
rtices); |
| 133 | 134 |
| 134 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(-100, -100), gfx::SizeF(90, 90))
, result); | 135 EXPECT_FLOAT_RECT_EQ(gfx::RectF(gfx::PointF(-100, -100), gfx::SizeF(90, 90))
, result); |
| 135 } | 136 } |
| 136 | 137 |
| 137 TEST(MathUtilTest, smallestAngleBetweenVectors) | 138 TEST(MathUtilTest, smallestAngleBetweenVectors) |
| 138 { | 139 { |
| 139 FloatSize x(1, 0); | 140 gfx::Vector2dF x(1, 0); |
| 140 FloatSize y(0, 1); | 141 gfx::Vector2dF y(0, 1); |
| 141 FloatSize testVector(0.5, 0.5); | 142 gfx::Vector2dF testVector(0.5, 0.5); |
| 142 | 143 |
| 143 // Orthogonal vectors are at an angle of 90 degress. | 144 // Orthogonal vectors are at an angle of 90 degress. |
| 144 EXPECT_EQ(90, MathUtil::smallestAngleBetweenVectors(x, y)); | 145 EXPECT_EQ(90, MathUtil::smallestAngleBetweenVectors(x, y)); |
| 145 | 146 |
| 146 // A vector makes a zero angle with itself. | 147 // A vector makes a zero angle with itself. |
| 147 EXPECT_EQ(0, MathUtil::smallestAngleBetweenVectors(x, x)); | 148 EXPECT_EQ(0, MathUtil::smallestAngleBetweenVectors(x, x)); |
| 148 EXPECT_EQ(0, MathUtil::smallestAngleBetweenVectors(y, y)); | 149 EXPECT_EQ(0, MathUtil::smallestAngleBetweenVectors(y, y)); |
| 149 EXPECT_EQ(0, MathUtil::smallestAngleBetweenVectors(testVector, testVector)); | 150 EXPECT_EQ(0, MathUtil::smallestAngleBetweenVectors(testVector, testVector)); |
| 150 | 151 |
| 151 // Parallel but reversed vectors are at 180 degrees. | 152 // Parallel but reversed vectors are at 180 degrees. |
| 152 EXPECT_FLOAT_EQ(180, MathUtil::smallestAngleBetweenVectors(x, -x)); | 153 EXPECT_FLOAT_EQ(180, MathUtil::smallestAngleBetweenVectors(x, -x)); |
| 153 EXPECT_FLOAT_EQ(180, MathUtil::smallestAngleBetweenVectors(y, -y)); | 154 EXPECT_FLOAT_EQ(180, MathUtil::smallestAngleBetweenVectors(y, -y)); |
| 154 EXPECT_FLOAT_EQ(180, MathUtil::smallestAngleBetweenVectors(testVector, -test
Vector)); | 155 EXPECT_FLOAT_EQ(180, MathUtil::smallestAngleBetweenVectors(testVector, -test
Vector)); |
| 155 | 156 |
| 156 // The test vector is at a known angle. | 157 // The test vector is at a known angle. |
| 157 EXPECT_FLOAT_EQ(45, floor(MathUtil::smallestAngleBetweenVectors(testVector,
x))); | 158 EXPECT_FLOAT_EQ(45, std::floor(MathUtil::smallestAngleBetweenVectors(testVec
tor, x))); |
| 158 EXPECT_FLOAT_EQ(45, floor(MathUtil::smallestAngleBetweenVectors(testVector,
y))); | 159 EXPECT_FLOAT_EQ(45, std::floor(MathUtil::smallestAngleBetweenVectors(testVec
tor, y))); |
| 159 } | 160 } |
| 160 | 161 |
| 161 TEST(MathUtilTest, vectorProjection) | 162 TEST(MathUtilTest, vectorProjection) |
| 162 { | 163 { |
| 163 FloatSize x(1, 0); | 164 gfx::Vector2dF x(1, 0); |
| 164 FloatSize y(0, 1); | 165 gfx::Vector2dF y(0, 1); |
| 165 FloatSize testVector(0.3f, 0.7f); | 166 gfx::Vector2dF testVector(0.3f, 0.7f); |
| 166 | 167 |
| 167 // Orthogonal vectors project to a zero vector. | 168 // Orthogonal vectors project to a zero vector. |
| 168 EXPECT_EQ(FloatSize(0, 0), MathUtil::projectVector(x, y)); | 169 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), MathUtil::projectVector(x, y)); |
| 169 EXPECT_EQ(FloatSize(0, 0), MathUtil::projectVector(y, x)); | 170 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, 0), MathUtil::projectVector(y, x)); |
| 170 | 171 |
| 171 // Projecting a vector onto the orthonormal basis gives the corresponding co
mponent of the | 172 // Projecting a vector onto the orthonormal basis gives the corresponding co
mponent of the |
| 172 // vector. | 173 // vector. |
| 173 EXPECT_EQ(FloatSize(testVector.width(), 0), MathUtil::projectVector(testVect
or, x)); | 174 EXPECT_VECTOR_EQ(gfx::Vector2dF(testVector.x(), 0), MathUtil::projectVector(
testVector, x)); |
| 174 EXPECT_EQ(FloatSize(0, testVector.height()), MathUtil::projectVector(testVec
tor, y)); | 175 EXPECT_VECTOR_EQ(gfx::Vector2dF(0, testVector.y()), MathUtil::projectVector(
testVector, y)); |
| 175 | 176 |
| 176 // Finally check than an arbitrary vector projected to another one gives a v
ector parallel to | 177 // Finally check than an arbitrary vector projected to another one gives a v
ector parallel to |
| 177 // the second vector. | 178 // the second vector. |
| 178 FloatSize targetVector(0.5, 0.2f); | 179 gfx::Vector2dF targetVector(0.5, 0.2f); |
| 179 FloatSize projectedVector = MathUtil::projectVector(testVector, targetVector
); | 180 gfx::Vector2dF projectedVector = MathUtil::projectVector(testVector, targetV
ector); |
| 180 EXPECT_EQ(projectedVector.width() / targetVector.width(), | 181 EXPECT_EQ(projectedVector.x() / targetVector.x(), |
| 181 projectedVector.height() / targetVector.height()); | 182 projectedVector.y() / targetVector.y()); |
| 182 } | 183 } |
| 183 | 184 |
| 184 } // namespace | 185 } // namespace |
| OLD | NEW |