Add ICU message format support
[chromium-blink-merge.git] / ui / chromeos / accelerometer / accelerometer_util.cc
blob9368b81dd57cfd079c6de5586af497dc2503c93b
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ui/chromeos/accelerometer/accelerometer_util.h"
7 #include <cmath>
9 #include "chromeos/accelerometer/accelerometer_types.h"
10 #include "ui/gfx/geometry/vector3d_f.h"
12 namespace {
14 // The maximum deviation from the acceleration expected due to gravity for which
15 // the device will be considered stable: 1g.
16 const float kDeviationFromGravityThreshold = 1.0f;
18 // The mean acceleration due to gravity on Earth in m/s^2.
19 const float kMeanGravity = 9.80665f;
21 } // namespace
23 namespace ui {
25 const gfx::Vector3dF ConvertAccelerometerReadingToVector3dF(
26 const chromeos::AccelerometerReading& reading) {
27 return gfx::Vector3dF(reading.x, reading.y, reading.z);
30 bool IsAccelerometerReadingStable(const chromeos::AccelerometerUpdate& update,
31 chromeos::AccelerometerSource source) {
32 return update.has(source) &&
33 std::abs(ConvertAccelerometerReadingToVector3dF(update.get(source))
34 .Length() -
35 kMeanGravity) <= kDeviationFromGravityThreshold;
38 } // namespace ui