Move constants for pi from cc to base and use them more widely.
Bug: none Cq-Include-Trybots: master.tryserver.blink:linux_trusty_blink_rel;master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel Change-Id: I440e0a3f09839a3b69db243737ba4ff4e90288c8 Reviewed-on: https://chromium-review.googlesource.com/658604 Commit-Queue: Peter Kasting <pkasting@chromium.org> Reviewed-by: Min Qin <qinmin@chromium.org> Reviewed-by: danakj <danakj@chromium.org> Reviewed-by: Fredrik Hubinette <hubbe@chromium.org> Reviewed-by: Mike Klein <mtklein@chromium.org> Reviewed-by: Simon Que <sque@chromium.org> Reviewed-by: Timothy Dresser <tdresser@chromium.org> Reviewed-by: Mark Cogan <marq@chromium.org> Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org> Reviewed-by: Yuwei Huang <yuweih@chromium.org> Reviewed-by: Rebekah Potter <rbpotter@chromium.org> Reviewed-by: Ian Vollick <vollick@chromium.org> Cr-Commit-Position: refs/heads/master@{#501901}
This commit is contained in:

committed by
Commit Bot

parent
4018982385
commit
76ed066d30
base/numerics
cc
animation
base
quads
chrome/browser
components/metrics/leak_detector
content/browser/renderer_host/input
ios/chrome/browser/ui
media
audio
base
filters
printing
remoting
codec
host
protocol
test
skia/ext
ui
compositor
events
gesture_detection
gfx
geometry
ozone
demo
@ -20,6 +20,7 @@ source_set("base_numerics") {
|
||||
public = [
|
||||
"checked_math.h",
|
||||
"clamped_math.h",
|
||||
"math_constants.h",
|
||||
"ranges.h",
|
||||
"safe_conversions.h",
|
||||
"safe_math.h",
|
||||
|
15
base/numerics/math_constants.h
Normal file
15
base/numerics/math_constants.h
Normal file
@ -0,0 +1,15 @@
|
||||
// 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 BASE_NUMERICS_MATH_CONSTANTS_H_
|
||||
#define BASE_NUMERICS_MATH_CONSTANTS_H_
|
||||
|
||||
namespace base {
|
||||
|
||||
constexpr double kPiDouble = 3.14159265358979323846;
|
||||
constexpr float kPiFloat = 3.14159265358979323846f;
|
||||
|
||||
} // namespace base
|
||||
|
||||
#endif // BASE_NUMERICS_MATH_CONSTANTS_H_
|
@ -2,16 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Needed on Windows to get |M_PI| from <cmath>
|
||||
#ifdef _WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "cc/animation/transform_operation.h"
|
||||
#include "cc/animation/transform_operations.h"
|
||||
#include "cc/base/math_util.h"
|
||||
@ -72,7 +67,7 @@ static bool ShareSameAxis(const TransformOperation* from,
|
||||
to->rotate.axis.y * from->rotate.axis.y +
|
||||
to->rotate.axis.z * from->rotate.axis.z;
|
||||
SkMScalar error =
|
||||
std::abs(SK_MScalar1 - (dot * dot) / (length_2 * other_length_2));
|
||||
SkMScalarAbs(SK_MScalar1 - (dot * dot) / (length_2 * other_length_2));
|
||||
bool result = error < kAngleEpsilon;
|
||||
if (result) {
|
||||
*axis_x = to->rotate.axis.x;
|
||||
@ -293,7 +288,7 @@ static void FindCandidatesInPlane(float px,
|
||||
*num_candidates = 4;
|
||||
candidates[0] = phi;
|
||||
for (int i = 1; i < *num_candidates; ++i)
|
||||
candidates[i] = candidates[i - 1] + M_PI_2;
|
||||
candidates[i] = candidates[i - 1] + base::kPiDouble / 2;
|
||||
if (nz < 0.f) {
|
||||
for (int i = 0; i < *num_candidates; ++i)
|
||||
candidates[i] *= -1.f;
|
||||
@ -301,11 +296,11 @@ static void FindCandidatesInPlane(float px,
|
||||
}
|
||||
|
||||
static float RadiansToDegrees(float radians) {
|
||||
return (180.f * radians) / M_PI;
|
||||
return (180.f * radians) / base::kPiFloat;
|
||||
}
|
||||
|
||||
static float DegreesToRadians(float degrees) {
|
||||
return (M_PI * degrees) / 180.f;
|
||||
return (base::kPiFloat * degrees) / 180.f;
|
||||
}
|
||||
|
||||
static void BoundingBoxForArc(const gfx::Point3F& point,
|
||||
@ -411,13 +406,13 @@ static void BoundingBoxForArc(const gfx::Point3F& point,
|
||||
// maximum/minimum x, y, z values.
|
||||
// x'(t) = r*cos(t)*v2.x - r*sin(t)*v1.x = 0
|
||||
// tan(t) = v2.x/v1.x
|
||||
// t = atan2(v2.x, v1.x) + n*M_PI;
|
||||
// t = atan2(v2.x, v1.x) + n*pi;
|
||||
candidates[0] = atan2(v2.x(), v1.x());
|
||||
candidates[1] = candidates[0] + M_PI;
|
||||
candidates[1] = candidates[0] + base::kPiDouble;
|
||||
candidates[2] = atan2(v2.y(), v1.y());
|
||||
candidates[3] = candidates[2] + M_PI;
|
||||
candidates[3] = candidates[2] + base::kPiDouble;
|
||||
candidates[4] = atan2(v2.z(), v1.z());
|
||||
candidates[5] = candidates[4] + M_PI;
|
||||
candidates[5] = candidates[4] + base::kPiDouble;
|
||||
}
|
||||
|
||||
double min_radians = DegreesToRadians(min_degrees);
|
||||
@ -426,9 +421,9 @@ static void BoundingBoxForArc(const gfx::Point3F& point,
|
||||
for (int i = 0; i < num_candidates; ++i) {
|
||||
double radians = candidates[i];
|
||||
while (radians < min_radians)
|
||||
radians += 2.0 * M_PI;
|
||||
radians += 2.0 * base::kPiDouble;
|
||||
while (radians > max_radians)
|
||||
radians -= 2.0 * M_PI;
|
||||
radians -= 2.0 * base::kPiDouble;
|
||||
if (radians < min_radians)
|
||||
continue;
|
||||
|
||||
|
@ -23,9 +23,6 @@
|
||||
|
||||
namespace cc {
|
||||
|
||||
const double MathUtil::kPiDouble = 3.14159265358979323846;
|
||||
const float MathUtil::kPiFloat = 3.14159265358979323846f;
|
||||
|
||||
static HomogeneousCoordinate ProjectHomogeneousPoint(
|
||||
const gfx::Transform& transform,
|
||||
const gfx::PointF& p) {
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "build/build_config.h"
|
||||
#include "cc/base/base_export.h"
|
||||
#include "ui/gfx/geometry/box_f.h"
|
||||
@ -81,14 +82,11 @@ struct HomogeneousCoordinate {
|
||||
|
||||
class CC_BASE_EXPORT MathUtil {
|
||||
public:
|
||||
static const double kPiDouble;
|
||||
static const float kPiFloat;
|
||||
static double Deg2Rad(double deg) { return deg * base::kPiDouble / 180.0; }
|
||||
static double Rad2Deg(double rad) { return rad * 180.0 / base::kPiDouble; }
|
||||
|
||||
static double Deg2Rad(double deg) { return deg * kPiDouble / 180.0; }
|
||||
static double Rad2Deg(double rad) { return rad * 180.0 / kPiDouble; }
|
||||
|
||||
static float Deg2Rad(float deg) { return deg * kPiFloat / 180.0f; }
|
||||
static float Rad2Deg(float rad) { return rad * 180.0f / kPiFloat; }
|
||||
static float Deg2Rad(float deg) { return deg * base::kPiFloat / 180.0f; }
|
||||
static float Rad2Deg(float rad) { return rad * 180.0f / base::kPiFloat; }
|
||||
|
||||
// Returns true if rounded up value does not overflow, false otherwise.
|
||||
template <typename T>
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "cc/base/filter_operation.h"
|
||||
#include "cc/base/filter_operations.h"
|
||||
#include "third_party/skia/include/core/SkImageFilter.h"
|
||||
@ -69,10 +70,8 @@ void GetSaturateMatrix(float amount, SkScalar matrix[20]) {
|
||||
}
|
||||
|
||||
void GetHueRotateMatrix(float hue, SkScalar matrix[20]) {
|
||||
const float kPi = 3.1415926535897932384626433832795f;
|
||||
|
||||
float cos_hue = cosf(hue * kPi / 180.f);
|
||||
float sin_hue = sinf(hue * kPi / 180.f);
|
||||
float cos_hue = cosf(hue * base::kPiFloat / 180.f);
|
||||
float sin_hue = sinf(hue * base::kPiFloat / 180.f);
|
||||
matrix[0] = 0.213f + cos_hue * 0.787f - sin_hue * 0.213f;
|
||||
matrix[1] = 0.715f - cos_hue * 0.715f - sin_hue * 0.715f;
|
||||
matrix[2] = 0.072f - cos_hue * 0.072f + sin_hue * 0.928f;
|
||||
|
@ -2,17 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// We would like to use M_PI on windows too.
|
||||
#ifdef _WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <limits>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/stl_util.h"
|
||||
#include "cc/output/bsp_compare_result.h"
|
||||
#include "cc/quads/draw_polygon.h"
|
||||
@ -160,10 +156,10 @@ TEST(DrawPolygonConstructionTest, ManyVertexNormal) {
|
||||
std::vector<gfx::Point3F> vertices_c;
|
||||
std::vector<gfx::Point3F> vertices_d;
|
||||
for (int i = 0; i < 100; i++) {
|
||||
vertices_c.push_back(
|
||||
gfx::Point3F(cos(i * M_PI / 50), sin(i * M_PI / 50), 0.0f));
|
||||
vertices_d.push_back(gfx::Point3F(cos(i * M_PI / 50) + 99.0f,
|
||||
sin(i * M_PI / 50) + 99.0f, 100.0f));
|
||||
const double step = i * base::kPiDouble / 50;
|
||||
vertices_c.push_back(gfx::Point3F(cos(step), sin(step), 0.0f));
|
||||
vertices_d.push_back(
|
||||
gfx::Point3F(cos(step) + 99.0f, sin(step) + 99.0f, 100.0f));
|
||||
}
|
||||
CREATE_TEST_DRAW_FORWARD_POLYGON(polygon_c, vertices_c, 3);
|
||||
EXPECT_NORMAL(polygon_c, 0.0f, 0.0f, 1.0f);
|
||||
|
@ -5,11 +5,11 @@
|
||||
#include "chrome/browser/android/vr_shell/vr_controller.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/numerics/ranges.h"
|
||||
#include "third_party/WebKit/public/platform/WebGestureEvent.h"
|
||||
#include "third_party/WebKit/public/platform/WebInputEvent.h"
|
||||
@ -39,7 +39,7 @@ constexpr float kSlopHorizontal = 0.15f;
|
||||
constexpr float kDelta = 1.0e-7f;
|
||||
|
||||
constexpr float kCutoffHz = 10.0f;
|
||||
constexpr float kRC = static_cast<float>(1.0 / (2.0 * M_PI * kCutoffHz));
|
||||
constexpr float kRC = 1.0f / (2.0f * base::kPiFloat * kCutoffHz);
|
||||
constexpr float kNanoSecondsPerSecond = 1.0e9f;
|
||||
|
||||
constexpr int kMaxNumOfExtrapolations = 2;
|
||||
|
@ -2,15 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
|
||||
|
||||
#include "chrome/browser/download/download_shelf.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/callback.h"
|
||||
#include "base/location.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
@ -50,7 +47,8 @@ int GetOpacity(double animation_progress) {
|
||||
// How many times to cycle the complete animation. This should be an odd
|
||||
// number so that the animation ends faded out.
|
||||
static const int kCompleteAnimationCycles = 5;
|
||||
double temp = animation_progress * kCompleteAnimationCycles * M_PI + M_PI_2;
|
||||
double temp =
|
||||
((animation_progress * kCompleteAnimationCycles) + 0.5) * base::kPiDouble;
|
||||
temp = sin(temp) / 2 + 0.5;
|
||||
return static_cast<int>(255.0 * temp);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#include "components/metrics/leak_detector/leak_detector_impl.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
@ -15,6 +14,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "components/metrics/leak_detector/custom_allocator.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -407,7 +407,7 @@ void LeakDetectorImplTest::JuliaSet(bool enable_leaks) {
|
||||
double angle = arg(root);
|
||||
// To generate other roots, rotate the principal root by increments of
|
||||
// 1/N of a full circle.
|
||||
const double kAngleIncrement = M_PI * 2 / 5;
|
||||
const double kAngleIncrement = base::kPiDouble * 2 / 5;
|
||||
|
||||
// Second root.
|
||||
root = std::polar(magnitude, angle + kAngleIncrement);
|
||||
|
@ -2,14 +2,10 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "content/browser/renderer_host/input/motion_event_web.h"
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "content/common/input/web_touch_event_traits.h"
|
||||
#include "ui/events/blink/blink_event_util.h"
|
||||
|
||||
@ -133,8 +129,8 @@ float MotionEventWeb::GetOrientation(size_t pointer_index) const {
|
||||
DCHECK_LT(pointer_index, GetPointerCount());
|
||||
|
||||
float orientation_rad =
|
||||
event_.touches[pointer_index].rotation_angle * M_PI / 180.f;
|
||||
DCHECK(0 <= orientation_rad && orientation_rad <= M_PI_2)
|
||||
event_.touches[pointer_index].rotation_angle * base::kPiFloat / 180.f;
|
||||
DCHECK(0 <= orientation_rad && orientation_rad <= base::kPiFloat / 2)
|
||||
<< "Unexpected touch rotation angle";
|
||||
|
||||
if (GetToolType(pointer_index) == TOOL_TYPE_STYLUS) {
|
||||
@ -143,22 +139,22 @@ float MotionEventWeb::GetOrientation(size_t pointer_index) const {
|
||||
if (pointer.tilt_y <= 0 && pointer.tilt_x < 0) {
|
||||
// Stylus is tilted to the left away from the user or straight
|
||||
// to the left thus the orientation should be within [pi/2,pi).
|
||||
orientation_rad += static_cast<float>(M_PI_2);
|
||||
orientation_rad += base::kPiFloat / 2;
|
||||
} else if (pointer.tilt_y < 0 && pointer.tilt_x >= 0) {
|
||||
// Stylus is tilted to the right away from the user or straight away
|
||||
// from the user thus the orientation should be within [-pi,-pi/2).
|
||||
orientation_rad -= static_cast<float>(M_PI);
|
||||
orientation_rad -= base::kPiFloat;
|
||||
} else if (pointer.tilt_y >= 0 && pointer.tilt_x > 0) {
|
||||
// Stylus is tilted to the right towards the user or straight
|
||||
// to the right thus the orientation should be within [-pi/2,0).
|
||||
orientation_rad -= static_cast<float>(M_PI_2);
|
||||
orientation_rad -= base::kPiFloat / 2;
|
||||
}
|
||||
} else if (event_.touches[pointer_index].radius_x >
|
||||
event_.touches[pointer_index].radius_y) {
|
||||
// The case radiusX == radiusY is omitted from here on purpose: for circles,
|
||||
// we want to pass the angle (which could be any value in such cases but
|
||||
// always seems to be set to zero) unchanged.
|
||||
orientation_rad -= static_cast<float>(M_PI_2);
|
||||
orientation_rad -= base::kPiFloat / 2;
|
||||
}
|
||||
|
||||
return orientation_rad;
|
||||
|
@ -2,13 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "content/browser/renderer_host/input/motion_event_web.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/events/blink/blink_event_util.h"
|
||||
@ -22,7 +18,7 @@ using ui::PointerProperties;
|
||||
namespace content {
|
||||
|
||||
TEST(MotionEventWebTest, Constructor) {
|
||||
const float pi = static_cast<float>(M_PI);
|
||||
const float pi = base::kPiFloat;
|
||||
const float orientations[] = {-pi, -2.f * pi / 3, -pi / 2};
|
||||
const float tilts_x[] = {0.f, -180 / 4, -180 / 3};
|
||||
const float tilts_y[] = {0.5f, 180 / 2, 180 / 3};
|
||||
@ -72,8 +68,10 @@ TEST(MotionEventWebTest, Constructor) {
|
||||
} else {
|
||||
// For non-stylus pointers and for styluses with a zero tilt angle,
|
||||
// orientation quadrant information is lost.
|
||||
EXPECT_NEAR(fmod(orientation + M_PI + 1e-4, M_PI_2) - 1e-4,
|
||||
event.GetOrientation(pointer_index), 1e-4);
|
||||
EXPECT_NEAR(
|
||||
fmod(orientation + base::kPiFloat + 1e-4, base::kPiFloat / 2) -
|
||||
1e-4,
|
||||
event.GetOrientation(pointer_index), 1e-4);
|
||||
}
|
||||
|
||||
generic_event.RemovePointerAt(pointer_index);
|
||||
|
@ -2,15 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// Needed on Windows to get |M_PI| from <cmath>.
|
||||
#ifdef _WIN32
|
||||
#define _USE_MATH_DEFINES
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "content/common/input/synthetic_web_input_event_builders.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/events/blink/blink_event_util.h"
|
||||
@ -40,7 +34,7 @@ TEST(WebInputEventUtilTest, MotionEventConversion) {
|
||||
pointer.raw_y = 25;
|
||||
pointer.pressure = 30;
|
||||
pointer.touch_minor = 35;
|
||||
pointer.orientation = static_cast<float>(-M_PI / 2);
|
||||
pointer.orientation = -base::kPiFloat / 2;
|
||||
pointer.tilt_x = 60;
|
||||
pointer.tilt_y = 70;
|
||||
for (MotionEvent::ToolType tool_type : tool_types) {
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include "ios/chrome/browser/ui/ntp/recent_tabs/views/disclosure_view.h"
|
||||
|
||||
#include "base/numerics/math_constants.h"
|
||||
|
||||
#if !defined(__has_feature) || !__has_feature(objc_arc)
|
||||
#error "This file requires ARC support."
|
||||
#endif
|
||||
@ -18,7 +20,7 @@ const NSTimeInterval kDisclosureIconRotateDuration = 0.25;
|
||||
// |kCollapsedIconAngle| to a value slightly less then 0 forces the animation to
|
||||
// always happen in the same half-plane.
|
||||
const CGFloat kCollapsedIconAngle = -0.00001;
|
||||
const CGFloat kExpandedIconAngle = M_PI;
|
||||
const CGFloat kExpandedIconAngle = base::kPiFloat;
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#import <QuartzCore/QuartzCore.h>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "ios/chrome/browser/ui/rtl_geometry.h"
|
||||
#include "ios/chrome/browser/ui/uikit_ui_util.h"
|
||||
#include "ios/chrome/grit/ios_theme_resources.h"
|
||||
@ -496,7 +497,8 @@ enum class OverscrollViewState {
|
||||
[UIView beginAnimations:@"transform" context:NULL];
|
||||
[UIView setAnimationDuration:0.1];
|
||||
CATransform3D rotation = CATransform3DMakeRotation(
|
||||
MapValueToRange({kFullThreshold / 2.0, kFullThreshold}, {-M_PI_2, M_PI_4},
|
||||
MapValueToRange({kFullThreshold / 2.0, kFullThreshold},
|
||||
{-base::kPiFloat / 2, base::kPiFloat / 4},
|
||||
self.verticalOffset),
|
||||
0, 0, 1);
|
||||
self.refreshActionImageView.layer.transform = rotation;
|
||||
@ -806,7 +808,7 @@ enum class OverscrollViewState {
|
||||
CGFloat deformationDirection = dx > 0 ? 1 : -1;
|
||||
for (int i = 0; i < kBezierPathPointCount; i++) {
|
||||
CGPoint p;
|
||||
float angle = i * 2 * M_PI / kBezierPathPointCount;
|
||||
float angle = i * 2 * base::kPiFloat / kBezierPathPointCount;
|
||||
|
||||
// Circle centered on 0.
|
||||
p.x = cos(angle) * radius;
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "ios/chrome/browser/ui/icons/chrome_icon.h"
|
||||
#include "ios/chrome/browser/ui/ui_util.h"
|
||||
#include "ios/chrome/grit/ios_strings.h"
|
||||
@ -361,8 +362,9 @@ CGFloat GetViewportSize() {
|
||||
// Check that the current transform is either an identity or a 90, -90, or 180
|
||||
// degree rotation.
|
||||
DCHECK(fabs(atan2f(rotation.b, rotation.a)) < 0.001 ||
|
||||
fabs(fabs(atan2f(rotation.b, rotation.a)) - M_PI) < 0.001 ||
|
||||
fabs(fabs(atan2f(rotation.b, rotation.a)) - M_PI / 2) < 0.001);
|
||||
fabs(fabs(atan2f(rotation.b, rotation.a)) - base::kPiFloat) < 0.001 ||
|
||||
fabs(fabs(atan2f(rotation.b, rotation.a)) - base::kPiFloat / 2) <
|
||||
0.001);
|
||||
rotation.a = round(rotation.a);
|
||||
rotation.b = round(rotation.b);
|
||||
rotation.c = round(rotation.c);
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "base/ios/ios_util.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "ios/chrome/browser/experimental_flags.h"
|
||||
#include "ios/chrome/browser/ui/rtl_geometry.h"
|
||||
#include "ios/chrome/browser/ui/ui_util.h"
|
||||
@ -338,7 +339,8 @@ UIImage* BlurImage(UIImage* image,
|
||||
// output pixel.
|
||||
//
|
||||
CGFloat inputRadius = blurRadius * [[UIScreen mainScreen] scale];
|
||||
NSUInteger radius = floor(inputRadius * 3. * sqrt(2 * M_PI) / 4 + 0.5);
|
||||
NSUInteger radius =
|
||||
floor(inputRadius * 3. * sqrt(2 * base::kPiDouble) / 4 + 0.5);
|
||||
if (radius % 2 != 1) {
|
||||
// force radius to be odd so that the three box-blur methodology works.
|
||||
radius += 1;
|
||||
|
@ -1,18 +1,16 @@
|
||||
// Copyright (c) 2012 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.
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "media/audio/simple_sources.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "base/files/file.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/time/time.h"
|
||||
#include "media/audio/sounds/wav_audio_handler.h"
|
||||
#include "media/base/audio_bus.h"
|
||||
@ -132,7 +130,7 @@ int SineWaveAudioSource::OnMoreData(base::TimeDelta /* delay */,
|
||||
int max_frames =
|
||||
cap_ > 0 ? std::min(dest->frames(), cap_ - time_state_) : dest->frames();
|
||||
for (int i = 0; i < max_frames; ++i)
|
||||
dest->channel(0)[i] = sin(2.0 * M_PI * f_ * time_state_++);
|
||||
dest->channel(0)[i] = sin(2.0 * base::kPiDouble * f_ * time_state_++);
|
||||
for (int i = 1; i < dest->channels(); ++i) {
|
||||
memcpy(dest->channel(i), dest->channel(0),
|
||||
max_frames * sizeof(*dest->channel(i)));
|
||||
|
@ -2,14 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
#include <cmath>
|
||||
#include <sstream>
|
||||
|
||||
#include "media/base/audio_hash.h"
|
||||
|
||||
#include "base/macros.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/strings/stringprintf.h"
|
||||
#include "media/base/audio_bus.h"
|
||||
|
||||
@ -36,7 +35,8 @@ void AudioHash::Update(const AudioBus* audio_bus, int frames) {
|
||||
// buffers don't result in an empty hash.
|
||||
if (ch == 0) {
|
||||
audio_hash_[kHashIndex] +=
|
||||
channel[i] + sin(2.0 * M_PI * M_PI * kSampleIndex);
|
||||
channel[i] +
|
||||
std::sin(2.0 * base::kPiDouble * base::kPiDouble * kSampleIndex);
|
||||
} else {
|
||||
audio_hash_[kHashIndex] += channel[i];
|
||||
}
|
||||
@ -60,7 +60,7 @@ bool AudioHash::IsEquivalent(const std::string& other, double tolerance) const {
|
||||
std::stringstream is(other);
|
||||
for (size_t i = 0; i < arraysize(audio_hash_); ++i) {
|
||||
is >> other_hash >> comma;
|
||||
if (fabs(audio_hash_[i] - other_hash) > tolerance)
|
||||
if (std::fabs(audio_hash_[i] - other_hash) > tolerance)
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -2,14 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "media/base/audio_timestamp_helper.h"
|
||||
#include "media/base/fake_audio_render_callback.h"
|
||||
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "media/base/audio_timestamp_helper.h"
|
||||
|
||||
namespace media {
|
||||
|
||||
FakeAudioRenderCallback::FakeAudioRenderCallback(double step, int sample_rate)
|
||||
@ -53,7 +50,8 @@ int FakeAudioRenderCallback::RenderInternal(AudioBus* audio_bus,
|
||||
|
||||
// Fill first channel with a sine wave.
|
||||
for (int i = 0; i < number_of_frames; ++i)
|
||||
audio_bus->channel(0)[i] = sin(2 * M_PI * (x_ + step_ * i)) * volume;
|
||||
audio_bus->channel(0)[i] =
|
||||
sin(2 * base::kPiDouble * (x_ + step_ * i)) * volume;
|
||||
x_ += number_of_frames * step_;
|
||||
|
||||
// Copy first channel into the rest of the channels.
|
||||
|
@ -73,15 +73,12 @@
|
||||
// Note: we're glossing over how the sub-sample handling works with
|
||||
// |virtual_source_idx_|, etc.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "media/base/sinc_resampler.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "build/build_config.h"
|
||||
|
||||
#if defined(ARCH_CPU_X86_FAMILY)
|
||||
@ -185,13 +182,14 @@ void SincResampler::InitializeKernel() {
|
||||
for (int i = 0; i < kKernelSize; ++i) {
|
||||
const int idx = i + offset_idx * kKernelSize;
|
||||
const float pre_sinc =
|
||||
static_cast<float>(M_PI * (i - kKernelSize / 2 - subsample_offset));
|
||||
base::kPiFloat * (i - kKernelSize / 2 - subsample_offset);
|
||||
kernel_pre_sinc_storage_[idx] = pre_sinc;
|
||||
|
||||
// Compute Blackman window, matching the offset of the sinc().
|
||||
const float x = (i - subsample_offset) / kKernelSize;
|
||||
const float window = static_cast<float>(kA0 - kA1 * cos(2.0 * M_PI * x) +
|
||||
kA2 * cos(4.0 * M_PI * x));
|
||||
const float window =
|
||||
static_cast<float>(kA0 - kA1 * cos(2.0 * base::kPiDouble * x) +
|
||||
kA2 * cos(4.0 * base::kPiDouble * x));
|
||||
kernel_window_storage_[idx] = window;
|
||||
|
||||
// Compute the sinc with offset, then window the sinc() function and store
|
||||
|
@ -2,15 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/bind_helpers.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/time/time.h"
|
||||
#include "build/build_config.h"
|
||||
@ -226,7 +223,8 @@ class SinusoidalLinearChirpSource {
|
||||
double t = static_cast<double>(current_index_) / sample_rate_;
|
||||
|
||||
// Sinusoidal linear chirp.
|
||||
destination[i] = sin(2 * M_PI * (kMinFrequency * t + (k_ / 2) * t * t));
|
||||
destination[i] =
|
||||
sin(2 * base::kPiDouble * (kMinFrequency * t + (k_ / 2) * t * t));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -295,7 +293,7 @@ TEST_P(SincResamplerTest, Resample) {
|
||||
std::unique_ptr<float[]> kernel(new float[SincResampler::kKernelStorageSize]);
|
||||
memcpy(kernel.get(), resampler.get_kernel_for_testing(),
|
||||
SincResampler::kKernelStorageSize);
|
||||
resampler.SetRatio(M_PI);
|
||||
resampler.SetRatio(base::kPiDouble);
|
||||
ASSERT_NE(0, memcmp(kernel.get(), resampler.get_kernel_for_testing(),
|
||||
SincResampler::kKernelStorageSize));
|
||||
resampler.SetRatio(io_ratio);
|
||||
|
@ -2,9 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "media/filters/wsola_internals.h"
|
||||
|
||||
#include <algorithm>
|
||||
@ -13,6 +10,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "media/base/audio_bus.h"
|
||||
|
||||
#if defined(ARCH_CPU_X86_FAMILY)
|
||||
@ -38,8 +36,8 @@ float MultiChannelSimilarityMeasure(const float* dot_prod_a_b,
|
||||
const float kEpsilon = 1e-12f;
|
||||
float similarity_measure = 0.0f;
|
||||
for (int n = 0; n < channels; ++n) {
|
||||
similarity_measure += dot_prod_a_b[n] / sqrt(energy_a[n] * energy_b[n] +
|
||||
kEpsilon);
|
||||
similarity_measure +=
|
||||
dot_prod_a_b[n] / std::sqrt(energy_a[n] * energy_b[n] + kEpsilon);
|
||||
}
|
||||
return similarity_measure;
|
||||
}
|
||||
@ -309,9 +307,9 @@ int OptimalIndex(const AudioBus* search_block,
|
||||
}
|
||||
|
||||
void GetSymmetricHanningWindow(int window_length, float* window) {
|
||||
const float scale = 2.0f * M_PI / window_length;
|
||||
const float scale = 2.0f * base::kPiFloat / window_length;
|
||||
for (int n = 0; n < window_length; ++n)
|
||||
window[n] = 0.5f * (1.0f - cosf(n * scale));
|
||||
window[n] = 0.5f * (1.0f - std::cos(n * scale));
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "base/logging.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/numerics/safe_conversions.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "ui/gfx/geometry/rect.h"
|
||||
@ -30,7 +31,7 @@ void RotatePage(CGContextRef context, const CGRect rect, int num_rotations) {
|
||||
// content is now "off screen". Shift it right to move it back on screen.
|
||||
CGContextTranslateCTM(context, rect.size.width, 0);
|
||||
// Rotates counter-clockwise by 90 degrees.
|
||||
CGContextRotateCTM(context, M_PI_2);
|
||||
CGContextRotateCTM(context, base::kPiDouble / 2);
|
||||
break;
|
||||
case 2:
|
||||
// After rotating by 180 degrees with the axis at the origin, the page
|
||||
@ -38,14 +39,14 @@ void RotatePage(CGContextRef context, const CGRect rect, int num_rotations) {
|
||||
// screen.
|
||||
CGContextTranslateCTM(context, rect.size.width, rect.size.height);
|
||||
// Rotates counter-clockwise by 90 degrees.
|
||||
CGContextRotateCTM(context, M_PI);
|
||||
CGContextRotateCTM(context, base::kPiDouble);
|
||||
break;
|
||||
case 3:
|
||||
// After rotating by 270 degrees with the axis at the origin, the page
|
||||
// content is now "off screen". Shift it right to move it back on screen.
|
||||
CGContextTranslateCTM(context, 0, rect.size.height);
|
||||
// Rotates counter-clockwise by 90 degrees.
|
||||
CGContextRotateCTM(context, -M_PI_2);
|
||||
CGContextRotateCTM(context, -base::kPiDouble / 2);
|
||||
break;
|
||||
default:
|
||||
NOTREACHED();
|
||||
|
@ -2,18 +2,16 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "remoting/codec/audio_encoder_opus.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "remoting/codec/audio_decoder_opus.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
|
||||
@ -27,7 +25,7 @@ const int kMaxSampleValue = 32767;
|
||||
const int kChannels = 2;
|
||||
|
||||
// Phase shift between left and right channels.
|
||||
const double kChannelPhaseShift = 2 * M_PI / 3;
|
||||
const double kChannelPhaseShift = 2 * base::kPiDouble / 3;
|
||||
|
||||
// The sampling rate that OPUS uses internally and that we expect to get
|
||||
// from the decoder.
|
||||
@ -60,9 +58,9 @@ class OpusAudioEncoderTest : public testing::Test {
|
||||
double frequency_hz,
|
||||
double pos,
|
||||
int channel) {
|
||||
double angle = pos * 2 * M_PI * frequency_hz / rate +
|
||||
kChannelPhaseShift * channel;
|
||||
return static_cast<int>(sin(angle) * kMaxSampleValue + 0.5);
|
||||
double angle = pos * 2 * base::kPiDouble * frequency_hz / rate +
|
||||
kChannelPhaseShift * channel;
|
||||
return static_cast<int>(std::sin(angle) * kMaxSampleValue + 0.5);
|
||||
}
|
||||
|
||||
// Creates audio packet filled with a test signal with the specified
|
||||
@ -121,8 +119,8 @@ class OpusAudioEncoderTest : public testing::Test {
|
||||
GetSampleValue(rate, frequency_hz, i - shift, 1);
|
||||
diff_sqare_sum += d * d;
|
||||
}
|
||||
double deviation = sqrt(diff_sqare_sum / received_data.size())
|
||||
/ kMaxSampleValue;
|
||||
double deviation =
|
||||
std::sqrt(diff_sqare_sum / received_data.size()) / kMaxSampleValue;
|
||||
LOG(ERROR) << "Decoded signal deviation: " << deviation;
|
||||
EXPECT_LE(deviation, kMaxSignalDeviation);
|
||||
}
|
||||
|
@ -3,12 +3,12 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <math.h>
|
||||
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "base/strings/utf_string_conversions.h"
|
||||
#include "remoting/base/string_resources.h"
|
||||
@ -74,10 +74,14 @@ class DisconnectWindowGtk : public HostWindow {
|
||||
void AddRoundRectPath(cairo_t* cairo_context, int width, int height,
|
||||
int radius) {
|
||||
cairo_new_sub_path(cairo_context);
|
||||
cairo_arc(cairo_context, width - radius, radius, radius, -M_PI_2, 0);
|
||||
cairo_arc(cairo_context, width - radius, height - radius, radius, 0, M_PI_2);
|
||||
cairo_arc(cairo_context, radius, height - radius, radius, M_PI_2, 2 * M_PI_2);
|
||||
cairo_arc(cairo_context, radius, radius, radius, 2 * M_PI_2, 3 * M_PI_2);
|
||||
cairo_arc(cairo_context, width - radius, radius, radius, -base::kPiDouble / 2,
|
||||
0);
|
||||
cairo_arc(cairo_context, width - radius, height - radius, radius, 0,
|
||||
base::kPiDouble / 2);
|
||||
cairo_arc(cairo_context, radius, height - radius, radius, base::kPiDouble / 2,
|
||||
base::kPiDouble);
|
||||
cairo_arc(cairo_context, radius, radius, radius, base::kPiDouble,
|
||||
3 * base::kPiDouble / 2);
|
||||
cairo_close_path(cairo_context);
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,12 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "base/bind.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/run_loop.h"
|
||||
#include "base/test/scoped_task_environment.h"
|
||||
#include "base/threading/thread.h"
|
||||
@ -150,7 +149,8 @@ class TestAudioSource : public AudioSource {
|
||||
static int16_t GetSampleValue(double pos, int frequency) {
|
||||
const int kMaxSampleValue = 32767;
|
||||
return static_cast<int>(
|
||||
sin(pos * 2 * M_PI * frequency / kAudioSampleRate) * kMaxSampleValue +
|
||||
sin(pos * 2 * base::kPiDouble * frequency / kAudioSampleRate) *
|
||||
kMaxSampleValue +
|
||||
0.5);
|
||||
}
|
||||
|
||||
|
@ -2,13 +2,9 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "remoting/test/fake_socket_factory.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
@ -17,6 +13,7 @@
|
||||
#include "base/callback.h"
|
||||
#include "base/location.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/single_thread_task_runner.h"
|
||||
#include "base/threading/thread_task_runner_handle.h"
|
||||
#include "base/time/time.h"
|
||||
@ -40,9 +37,8 @@ double RandDouble() {
|
||||
double GetNormalRandom(double average, double stddev) {
|
||||
// Based on Box-Muller transform, see
|
||||
// http://en.wikipedia.org/wiki/Box_Muller_transform .
|
||||
return average +
|
||||
stddev * sqrt(-2.0 * log(1.0 - RandDouble())) *
|
||||
cos(RandDouble() * 2.0 * M_PI);
|
||||
return average + stddev * sqrt(-2.0 * log(1.0 - RandDouble())) *
|
||||
cos(RandDouble() * 2.0 * base::kPiDouble);
|
||||
}
|
||||
|
||||
class FakeUdpSocket : public rtc::AsyncPacketSocket {
|
||||
|
@ -2,22 +2,19 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#include "skia/ext/image_operations.h"
|
||||
|
||||
// TODO(pkasting): skia/ext should not depend on base/!
|
||||
#include "base/containers/stack_container.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/metrics/histogram_macros.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/time/time.h"
|
||||
#include "base/trace_event/trace_event.h"
|
||||
#include "build/build_config.h"
|
||||
@ -59,7 +56,7 @@ float EvalLanczos(int filter_size, float x) {
|
||||
if (x > -std::numeric_limits<float>::epsilon() &&
|
||||
x < std::numeric_limits<float>::epsilon())
|
||||
return 1.0f; // Special case the discontinuity at the origin.
|
||||
float xpi = x * static_cast<float>(M_PI);
|
||||
float xpi = x * base::kPiFloat;
|
||||
return (sin(xpi) / xpi) * // sinc(x)
|
||||
sin(xpi / filter_size) / (xpi / filter_size); // sinc(x/filter_size)
|
||||
}
|
||||
@ -85,7 +82,7 @@ float EvalHamming(int filter_size, float x) {
|
||||
if (x > -std::numeric_limits<float>::epsilon() &&
|
||||
x < std::numeric_limits<float>::epsilon())
|
||||
return 1.0f; // Special case the sinc discontinuity at the origin.
|
||||
const float xpi = x * static_cast<float>(M_PI);
|
||||
const float xpi = x * base::kPiFloat;
|
||||
|
||||
return ((sin(xpi) / xpi) * // sinc(x)
|
||||
(0.54f + 0.46f * cos(xpi / filter_size))); // hamming(x)
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "base/compiler_specific.h"
|
||||
#include "base/files/file_util.h"
|
||||
#include "base/macros.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "base/strings/string_util.h"
|
||||
#include "skia/ext/image_operations.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
@ -497,15 +498,9 @@ TEST(ImageOperations, ResizeShouldAverageColors) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifndef M_PI
|
||||
// No M_PI in math.h on windows? No problem.
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
|
||||
static double sinc(double x) {
|
||||
if (x == 0.0) return 1.0;
|
||||
x *= M_PI;
|
||||
x *= base::kPiDouble;
|
||||
return sin(x) / x;
|
||||
}
|
||||
|
||||
|
@ -2,18 +2,16 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
|
||||
|
||||
#include "ui/compositor/debug_utils.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <iomanip>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "ui/compositor/layer.h"
|
||||
#include "ui/gfx/geometry/point.h"
|
||||
#include "ui/gfx/geometry/point_conversions.h"
|
||||
@ -92,7 +90,7 @@ void PrintLayerHierarchyImp(const Layer* layer,
|
||||
|
||||
*out << '\n' << property_indent_str;
|
||||
*out << "rotation: ";
|
||||
*out << std::acos(decomp.quaternion.w()) * 360.0 / M_PI;
|
||||
*out << std::acos(decomp.quaternion.w()) * 360.0 / base::kPiDouble;
|
||||
|
||||
*out << '\n' << property_indent_str;
|
||||
*out << "scale: " << decomp.scale[0];
|
||||
|
@ -2,16 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "ui/events/gesture_detection/motion_event_generic.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "base/memory/ptr_util.h"
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "ui/events/base_event_utils.h"
|
||||
|
||||
namespace ui {
|
||||
@ -57,16 +54,16 @@ void PointerProperties::SetAxesAndOrientation(float radius_x,
|
||||
float radius_y,
|
||||
float rotation_angle_degree) {
|
||||
DCHECK(!touch_major && !touch_minor && !orientation);
|
||||
float rotation_angle_rad = rotation_angle_degree * M_PI / 180.f;
|
||||
float rotation_angle_rad = rotation_angle_degree * base::kPiFloat / 180.f;
|
||||
DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0 (" << radius_x << ")";
|
||||
DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0 (" << radius_y << ")";
|
||||
DCHECK(0 <= rotation_angle_rad && rotation_angle_rad < M_PI)
|
||||
DCHECK(0 <= rotation_angle_rad && rotation_angle_rad < base::kPiFloat)
|
||||
<< "Unexpected touch rotation angle " << rotation_angle_rad << " rad";
|
||||
|
||||
// Make the angle acute to ease subsequent logic. The angle range effectively
|
||||
// changes from [0, pi) to [0, pi/2).
|
||||
if (rotation_angle_rad >= M_PI_2) {
|
||||
rotation_angle_rad -= static_cast<float>(M_PI_2);
|
||||
if (rotation_angle_rad >= base::kPiFloat / 2) {
|
||||
rotation_angle_rad -= base::kPiFloat / 2;
|
||||
std::swap(radius_x, radius_y);
|
||||
}
|
||||
|
||||
@ -76,7 +73,7 @@ void PointerProperties::SetAxesAndOrientation(float radius_x,
|
||||
// cases but always seem to be set to zero) unchanged.
|
||||
touch_major = 2.f * radius_x;
|
||||
touch_minor = 2.f * radius_y;
|
||||
orientation = rotation_angle_rad - M_PI_2;
|
||||
orientation = rotation_angle_rad - base::kPiFloat / 2;
|
||||
} else {
|
||||
touch_major = 2.f * radius_y;
|
||||
touch_minor = 2.f * radius_x;
|
||||
|
@ -2,14 +2,11 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// MSVC++ requires this to be set before any other includes to get M_PI.
|
||||
#define _USE_MATH_DEFINES
|
||||
|
||||
#include "ui/events/gesture_detection/motion_event_generic.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <utility>
|
||||
|
||||
#include "base/numerics/math_constants.h"
|
||||
#include "testing/gtest/include/gtest/gtest.h"
|
||||
#include "ui/events/event_constants.h"
|
||||
#include "ui/events/test/motion_event_test_utils.h"
|
||||
@ -193,7 +190,7 @@ TEST(MotionEventGenericTest, AxisAndOrientation) {
|
||||
properties.SetAxesAndOrientation(radius_x, radius_y, rotation_angle_deg);
|
||||
EXPECT_EQ(20, properties.touch_major);
|
||||
EXPECT_EQ(10, properties.touch_minor);
|
||||
EXPECT_NEAR(-M_PI_2, properties.orientation, 0.001);
|
||||
EXPECT_NEAR(-base::kPiDouble / 2, properties.orientation, 0.001);
|
||||
}
|
||||
{
|
||||
PointerProperties properties;
|
||||
@ -213,7 +210,7 @@ TEST(MotionEventGenericTest, AxisAndOrientation) {
|
||||
properties.SetAxesAndOrientation(radius_x, radius_y, rotation_angle_deg);
|
||||
EXPECT_EQ(20, properties.touch_major);
|
||||
EXPECT_EQ(10, properties.touch_minor);
|
||||
EXPECT_NEAR(M_PI_2, properties.orientation, 0.001);
|
||||
EXPECT_NEAR(base::kPiDouble / 2, properties.orientation, 0.001);
|
||||
}
|
||||
{
|
||||
PointerProperties properties;
|
||||
|
@ -8,9 +8,7 @@
|
||||
#include <cmath>
|
||||
#include <limits>
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.14159265358979323846
|
||||
#endif
|
||||
#include "base/numerics/math_constants.h"
|
||||
|
||||
namespace {
|
||||
|
||||
@ -171,13 +169,13 @@ Vector3dF Matrix3F::SolveEigenproblem(Matrix3F* eigenvectors) const {
|
||||
// half_det_b should be in <-1, 1>, but beware of rounding error.
|
||||
double phi = 0.0f;
|
||||
if (half_det_b <= -1.0)
|
||||
phi = M_PI / 3;
|
||||
phi = base::kPiDouble / 3;
|
||||
else if (half_det_b < 1.0)
|
||||
phi = acos(half_det_b) / 3;
|
||||
|
||||
eigenvalues[0] = q + 2 * p * static_cast<float>(cos(phi));
|
||||
eigenvalues[2] = q + 2 * p *
|
||||
static_cast<float>(cos(phi + 2.0 * M_PI / 3.0));
|
||||
eigenvalues[2] =
|
||||
q + 2 * p * static_cast<float>(cos(phi + 2.0 * base::kPiDouble / 3.0));
|
||||
eigenvalues[1] = 3 * q - eigenvalues[0] - eigenvalues[2];
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
#include "ui/ozone/demo/renderer_base.h"
|
||||
|
||||
#include <cmath>
|
||||
#include "base/numerics/math_constants.h"
|
||||
|
||||
namespace ui {
|
||||
|
||||
@ -20,7 +20,8 @@ RendererBase::~RendererBase() {
|
||||
}
|
||||
|
||||
float RendererBase::NextFraction() {
|
||||
float fraction = (sinf(iteration_ * 2 * M_PI / kAnimationSteps) + 1) / 2;
|
||||
float fraction =
|
||||
(sinf(iteration_ * 2 * base::kPiFloat / kAnimationSteps) + 1) / 2;
|
||||
|
||||
iteration_++;
|
||||
iteration_ %= kAnimationSteps;
|
||||
|
Reference in New Issue
Block a user