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

Unified Diff: ui/gfx/geometry/vector3d_f.cc

Issue 759063002: Move Screen Rotation from MaximizeModeController to ScreenOrientationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix Linux Compile Created 5 years, 11 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/gfx/geometry/vector3d_f.h ('k') | ui/gfx/geometry/vector3d_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/geometry/vector3d_f.cc
diff --git a/ui/gfx/geometry/vector3d_f.cc b/ui/gfx/geometry/vector3d_f.cc
index a30f9db5cbe35cc7fe0c9224dadbca5baf9736df..87223880669ed51a4bd15cc1302d31a14d16a4fa 100644
--- a/ui/gfx/geometry/vector3d_f.cc
+++ b/ui/gfx/geometry/vector3d_f.cc
@@ -8,6 +8,10 @@
#include "base/strings/stringprintf.h"
+namespace {
+const float kRadiansToDegrees = 180.0f / 3.14159265f;
+}
+
namespace gfx {
Vector3dF::Vector3dF()
@@ -85,4 +89,25 @@ Vector3dF ScaleVector3d(const Vector3dF& v,
return scaled_v;
}
+float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
+ const gfx::Vector3dF& other) {
+ return acos(gfx::DotProduct(base, other) / base.Length() / other.Length()) *
+ kRadiansToDegrees;
+}
+
+float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
+ const gfx::Vector3dF& other,
+ const gfx::Vector3dF& normal) {
+ float angle = AngleBetweenVectorsInDegrees(base, other);
+ gfx::Vector3dF cross(base);
+ cross.Cross(other);
+
+ // If the dot product of this cross product is normal, it means that the
+ // shortest angle between |base| and |other| was counterclockwise with respect
+ // to the surface represented by |normal| and this angle must be reversed.
+ if (gfx::DotProduct(cross, normal) > 0.0f)
+ angle = 360.0f - angle;
+ return angle;
+}
+
} // namespace gfx
« no previous file with comments | « ui/gfx/geometry/vector3d_f.h ('k') | ui/gfx/geometry/vector3d_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698