summaryrefslogtreecommitdiff
path: root/Source/WebKit/chromium/tests/CCMathUtilTest.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2012-08-21 10:57:44 +0200
committerSimon Hausmann <simon.hausmann@nokia.com>2012-08-21 10:57:44 +0200
commit5ef7c8a6a70875d4430752d146bdcb069605d71d (patch)
treef6256640b6c46d7da221435803cae65326817ba2 /Source/WebKit/chromium/tests/CCMathUtilTest.cpp
parentdecad929f578d8db641febc8740649ca6c574638 (diff)
downloadqtwebkit-5ef7c8a6a70875d4430752d146bdcb069605d71d.tar.gz
Imported WebKit commit 356d83016b090995d08ad568f2d2c243aa55e831 (http://svn.webkit.org/repository/webkit/trunk@126147)
New snapshot including various build fixes for newer Qt 5
Diffstat (limited to 'Source/WebKit/chromium/tests/CCMathUtilTest.cpp')
-rw-r--r--Source/WebKit/chromium/tests/CCMathUtilTest.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/Source/WebKit/chromium/tests/CCMathUtilTest.cpp b/Source/WebKit/chromium/tests/CCMathUtilTest.cpp
index 44a68b9eb..416e1b56d 100644
--- a/Source/WebKit/chromium/tests/CCMathUtilTest.cpp
+++ b/Source/WebKit/chromium/tests/CCMathUtilTest.cpp
@@ -24,7 +24,7 @@
#include "config.h"
-#include "cc/CCMathUtil.h"
+#include "CCMathUtil.h"
#include "CCLayerTreeTestCommon.h"
#include "FloatRect.h"
@@ -152,4 +152,51 @@ TEST(CCMathUtilTest, verifyEnclosingRectOfVerticesUsesCorrectInitialBounds)
EXPECT_FLOAT_RECT_EQ(FloatRect(FloatPoint(-100, -100), FloatSize(90, 90)), result);
}
+TEST(CCMathUtilTest, smallestAngleBetweenVectors)
+{
+ FloatSize x(1, 0);
+ FloatSize y(0, 1);
+ FloatSize testVector(0.5, 0.5);
+
+ // Orthogonal vectors are at an angle of 90 degress.
+ EXPECT_EQ(90, CCMathUtil::smallestAngleBetweenVectors(x, y));
+
+ // A vector makes a zero angle with itself.
+ EXPECT_EQ(0, CCMathUtil::smallestAngleBetweenVectors(x, x));
+ EXPECT_EQ(0, CCMathUtil::smallestAngleBetweenVectors(y, y));
+ EXPECT_EQ(0, CCMathUtil::smallestAngleBetweenVectors(testVector, testVector));
+
+ // Parallel but reversed vectors are at 180 degrees.
+ EXPECT_FLOAT_EQ(180, CCMathUtil::smallestAngleBetweenVectors(x, -x));
+ EXPECT_FLOAT_EQ(180, CCMathUtil::smallestAngleBetweenVectors(y, -y));
+ EXPECT_FLOAT_EQ(180, CCMathUtil::smallestAngleBetweenVectors(testVector, -testVector));
+
+ // The test vector is at a known angle.
+ EXPECT_FLOAT_EQ(45, floor(CCMathUtil::smallestAngleBetweenVectors(testVector, x)));
+ EXPECT_FLOAT_EQ(45, floor(CCMathUtil::smallestAngleBetweenVectors(testVector, y)));
+}
+
+TEST(CCMathUtilTest, vectorProjection)
+{
+ FloatSize x(1, 0);
+ FloatSize y(0, 1);
+ FloatSize testVector(0.3f, 0.7f);
+
+ // Orthogonal vectors project to a zero vector.
+ EXPECT_EQ(FloatSize(0, 0), CCMathUtil::projectVector(x, y));
+ EXPECT_EQ(FloatSize(0, 0), CCMathUtil::projectVector(y, x));
+
+ // Projecting a vector onto the orthonormal basis gives the corresponding component of the
+ // vector.
+ EXPECT_EQ(FloatSize(testVector.width(), 0), CCMathUtil::projectVector(testVector, x));
+ EXPECT_EQ(FloatSize(0, testVector.height()), CCMathUtil::projectVector(testVector, y));
+
+ // Finally check than an arbitrary vector projected to another one gives a vector parallel to
+ // the second vector.
+ FloatSize targetVector(0.5, 0.2f);
+ FloatSize projectedVector = CCMathUtil::projectVector(testVector, targetVector);
+ EXPECT_EQ(projectedVector.width() / targetVector.width(),
+ projectedVector.height() / targetVector.height());
+}
+
} // namespace