summaryrefslogtreecommitdiffstats
path: root/cc/math_util.cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-05 20:46:13 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-05 20:46:13 +0000
commitc9c1ebe24790fb34fa9f0704b7963cea511c6f2a (patch)
treefdd43e025e44ae4d9515ebe03a3e4c54f7133d51 /cc/math_util.cc
parent6e3d7e7d274a3e8347e49910ab6f873f37e15989 (diff)
downloadchromium_src-c9c1ebe24790fb34fa9f0704b7963cea511c6f2a.zip
chromium_src-c9c1ebe24790fb34fa9f0704b7963cea511c6f2a.tar.gz
chromium_src-c9c1ebe24790fb34fa9f0704b7963cea511c6f2a.tar.bz2
cc: Remove all remaining use of WebCore Rect/Point/Size types from the compositor.
This change removes all IntPoint/FloatRect/IntSize/etc from the compositor. There remains an indirect dependency on these types through the WebCore::Region class, which we wrap but need to replace. However, the wrapper there hides the WebCore types inside it, so there are now no references to the types from anywhere else in the compositor. I went back and forth on how to deal with scroll "positions". The name suggested that they should be Points, and that the deltas should be Vectors. However this lent itself to super awkward math at times. In the end, it was much cleaner to make all scroll "positions" into scroll "offsets" and represent everything as Vectors. Covered by existing tests; no change in behaviour. R=enne BUG=147395 Relanding: https://codereview.chromium.org/11367080/ Review URL: https://codereview.chromium.org/11366089 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166027 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc/math_util.cc')
-rw-r--r--cc/math_util.cc27
1 files changed, 17 insertions, 10 deletions
diff --git a/cc/math_util.cc b/cc/math_util.cc
index 6ae41e6..83d156c 100644
--- a/cc/math_util.cc
+++ b/cc/math_util.cc
@@ -6,12 +6,14 @@
#include "cc/math_util.h"
-#include "FloatSize.h"
+#include <cmath>
+#include <limits>
+
#include "ui/gfx/quad_f.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_conversions.h"
#include "ui/gfx/rect_f.h"
-#include <cmath>
+#include "ui/gfx/vector2d_f.h"
#include <public/WebTransformationMatrix.h>
using WebKit::WebTransformationMatrix;
@@ -378,19 +380,24 @@ gfx::Vector2dF MathUtil::computeTransform2dScaleComponents(const WebTransformati
return gfx::Vector2dF(xScale, yScale);
}
-float MathUtil::smallestAngleBetweenVectors(const FloatSize& v1, const FloatSize& v2)
+static inline double rad2deg(double r)
+{
+ double pi = 3.14159265358979323846;
+ return r * 180.0 / pi;
+}
+
+float MathUtil::smallestAngleBetweenVectors(gfx::Vector2dF v1, gfx::Vector2dF v2)
{
- float dotProduct = (v1.width() * v2.width() + v1.height() * v2.height()) / (v1.diagonalLength() * v2.diagonalLength());
+ double dotProduct = gfx::DotProduct(v1, v2) / v1.Length() / v2.Length();
// Clamp to compensate for rounding errors.
- dotProduct = std::max(-1.f, std::min(1.f, dotProduct));
- return rad2deg(acosf(dotProduct));
+ dotProduct = std::max(-1.0, std::min(1.0, dotProduct));
+ return static_cast<float>(rad2deg(std::acos(dotProduct)));
}
-FloatSize MathUtil::projectVector(const FloatSize& source, const FloatSize& destination)
+gfx::Vector2dF MathUtil::projectVector(gfx::Vector2dF source, gfx::Vector2dF destination)
{
- float sourceDotDestination = source.width() * destination.width() + source.height() * destination.height();
- float projectedLength = sourceDotDestination / destination.diagonalLengthSquared();
- return FloatSize(projectedLength * destination.width(), projectedLength * destination.height());
+ float projectedLength = gfx::DotProduct(source, destination) / destination.LengthSquared();
+ return gfx::Vector2dF(projectedLength * destination.x(), projectedLength * destination.y());
}
} // namespace cc