summaryrefslogtreecommitdiffstats
path: root/ui/gfx/vector2d_f.cc
diff options
context:
space:
mode:
authordanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 17:01:24 +0000
committerdanakj@chromium.org <danakj@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 17:01:24 +0000
commit38b6f04314682f2db1105dd6ffafb138204200f4 (patch)
tree74944c5ac68827aafdb46279596b9bfe24c53749 /ui/gfx/vector2d_f.cc
parent2e6c6fc23a88c24a4760cbe62334f8f4ea661c4f (diff)
downloadchromium_src-38b6f04314682f2db1105dd6ffafb138204200f4.zip
chromium_src-38b6f04314682f2db1105dd6ffafb138204200f4.tar.gz
chromium_src-38b6f04314682f2db1105dd6ffafb138204200f4.tar.bz2
ui: Create the gfx::QuadF class.
This class is composed of four points representing its corners. It does not have to be axis-aligned, unlike a rectangle. The class supports the following operations: IsRectilinear() - True if the quad is an axis-aligned rectangle. IsCounterClockwise() - True if the points of the quad are in counter-clockwise order. Contains(Point) - True if Point is inside the quad or on its boundary. BoundingBox() - A Rectangle whose edges are defined by the four points of the quad. Scale() - Scales each point on the quad by the given scale factors. operator+/- - Moves each point in the quad by the given offset. The operations on this class are inspired by, but not copied from, the FloatQuad class in WebCore. I've written my own implementation to match those in WebCore for each of them, with exception of IsRectilinear() as I also wrote the current method in WebCore. Tests: ui_unittests:QuadTest.Construction ui_unittests:QuadTest.AddingVectors ui_unittests:QuadTest.IsRectilinear ui_unittests:QuadTest.IsCounterClockwise ui_unittests:QuadTest.BoundingBox ui_unittests:QuadTest.ContainsPoint ui_unittests:QuadTest.Scale BUG=147395 R=sky,pkasting Review URL: https://codereview.chromium.org/11369043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165689 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx/vector2d_f.cc')
-rw-r--r--ui/gfx/vector2d_f.cc10
1 files changed, 10 insertions, 0 deletions
diff --git a/ui/gfx/vector2d_f.cc b/ui/gfx/vector2d_f.cc
index f628421..3671c62 100644
--- a/ui/gfx/vector2d_f.cc
+++ b/ui/gfx/vector2d_f.cc
@@ -51,4 +51,14 @@ void Vector2dF::Scale(float x_scale, float y_scale) {
y_ *= y_scale;
}
+double CrossProduct(const Vector2dF& lhs, const Vector2dF& rhs) {
+ return static_cast<double>(lhs.x()) * rhs.y() -
+ static_cast<double>(lhs.y()) * rhs.x();
+}
+
+double DotProduct(const Vector2dF& lhs, const Vector2dF& rhs) {
+ return static_cast<double>(lhs.x()) * rhs.x() +
+ static_cast<double>(lhs.y()) * rhs.y();
+}
+
} // namespace gfx