summaryrefslogtreecommitdiff
path: root/ui
diff options
context:
space:
mode:
authorPeter Kasting <pkasting@chromium.org>2017-09-20 15:22:23 +0900
committerQijiang Fan <fqj@google.com>2020-06-05 07:17:10 +0900
commitb38c833a2bdca89d69e7be8000a06fceff8d2903 (patch)
tree5bf59b68d43109bc0e6d2d9ef923094d6cfe130b /ui
parent480e43bac9f67e20b237b5cede5d99f022f5095a (diff)
downloadlibchrome-b38c833a2bdca89d69e7be8000a06fceff8d2903.tar.gz
Move deg<->rad conversions from cc to ui/gfx/geometry and use them more.
This also aims to eliminate _USE_MATH_DEFINES entirely by removing the last vestiges of M_PI (at least, from the directories that can depend on ui/gfx). Bug: none Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel Change-Id: Iae16aa804aeb80a750af34b457d426b92dd6c302 Reviewed-on: https://chromium-review.googlesource.com/657905 Reviewed-by: Tim Volodine <timvolodine@chromium.org> Reviewed-by: Dirk Pranke <dpranke@chromium.org> Reviewed-by: Timothy Dresser <tdresser@chromium.org> Reviewed-by: James Cook <jamescook@chromium.org> Reviewed-by: Rohit Rao (ping after 24h) <rohitrao@chromium.org> Reviewed-by: danakj <danakj@chromium.org> Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org> Reviewed-by: Ian Vollick <vollick@chromium.org> Commit-Queue: Peter Kasting <pkasting@chromium.org> Cr-Commit-Position: refs/heads/master@{#503069} CrOS-Libchrome-Original-Commit: f9f3cebe6abf575ef8bda227a7dee4faa6cd312b
Diffstat (limited to 'ui')
-rw-r--r--ui/gfx/geometry/angle_conversions.h29
-rw-r--r--ui/gfx/geometry/vector3d_f.cc6
2 files changed, 32 insertions, 3 deletions
diff --git a/ui/gfx/geometry/angle_conversions.h b/ui/gfx/geometry/angle_conversions.h
new file mode 100644
index 0000000000..68e9209f72
--- /dev/null
+++ b/ui/gfx/geometry/angle_conversions.h
@@ -0,0 +1,29 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_GEOMETRY_ANGLE_CONVERSIONS_H_
+#define UI_GFX_GEOMETRY_ANGLE_CONVERSIONS_H_
+
+#include "base/numerics/math_constants.h"
+#include "ui/gfx/gfx_export.h"
+
+namespace gfx {
+
+GFX_EXPORT constexpr double DegToRad(double deg) {
+ return deg * base::kPiDouble / 180.0;
+}
+GFX_EXPORT constexpr float DegToRad(float deg) {
+ return deg * base::kPiFloat / 180.0f;
+}
+
+GFX_EXPORT constexpr double RadToDeg(double rad) {
+ return rad * 180.0 / base::kPiDouble;
+}
+GFX_EXPORT constexpr float RadToDeg(float rad) {
+ return rad * 180.0f / base::kPiFloat;
+}
+
+} // namespace gfx
+
+#endif // UI_GFX_GEOMETRY_ANGLE_CONVERSIONS_H_
diff --git a/ui/gfx/geometry/vector3d_f.cc b/ui/gfx/geometry/vector3d_f.cc
index c516172eba..749e330f27 100644
--- a/ui/gfx/geometry/vector3d_f.cc
+++ b/ui/gfx/geometry/vector3d_f.cc
@@ -7,9 +7,9 @@
#include <cmath>
#include "base/strings/stringprintf.h"
+#include "ui/gfx/geometry/angle_conversions.h"
namespace {
-const float kRadiansToDegrees = 180.0f / 3.14159265f;
const double kEpsilon = 1.0e-6;
}
@@ -86,8 +86,8 @@ Vector3dF ScaleVector3d(const Vector3dF& v,
float AngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
const gfx::Vector3dF& other) {
- return acos(gfx::DotProduct(base, other) / base.Length() / other.Length()) *
- kRadiansToDegrees;
+ return gfx::RadToDeg(
+ std::acos(gfx::DotProduct(base, other) / base.Length() / other.Length()));
}
float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,