diff options
author | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 19:01:23 +0000 |
---|---|---|
committer | avi@chromium.org <avi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-24 19:01:23 +0000 |
commit | e64c67e93a147c2968bcc594dd78728faa6dc667 (patch) | |
tree | 38147883e5dc909fb14166f5e73f9e0f2eceebc8 /chrome | |
parent | 8626e9625ae5e4a343246c41417abed7c523ced8 (diff) | |
download | chromium_src-e64c67e93a147c2968bcc594dd78728faa6dc667.zip chromium_src-e64c67e93a147c2968bcc594dd78728faa6dc667.tar.gz chromium_src-e64c67e93a147c2968bcc594dd78728faa6dc667.tar.bz2 |
Fix pinning of gamma on Mac device orientation. It shouldn't switch signs.
BUG=73156
TEST=go to test page noted in bug, tilt laptop all the way to the right; it should show maximum 89.999... gamma. It should not flip to -90.
Review URL: http://codereview.chromium.org/6578011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75923 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/device_orientation/accelerometer_mac.cc | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/chrome/browser/device_orientation/accelerometer_mac.cc b/chrome/browser/device_orientation/accelerometer_mac.cc index a1601f0..e4ae516 100644 --- a/chrome/browser/device_orientation/accelerometer_mac.cc +++ b/chrome/browser/device_orientation/accelerometer_mac.cc @@ -50,7 +50,7 @@ #include "chrome/browser/device_orientation/accelerometer_mac.h" -#include <math.h> // For isfinite. +#include <math.h> #include <sys/sysctl.h> #include "base/logging.h" @@ -236,7 +236,7 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) { int size = kGenericSensor.axis_size; int index = sensor_->axis[i].index; - // Important Note: little endian is assumed as this code is mac-only + // Important Note: Little endian is assumed as this code is Mac-only // and PowerPC is currently not supported. memcpy(&sensor_value, &output_record_[index], size); @@ -287,12 +287,18 @@ bool AccelerometerMac::GetOrientation(Orientation* orientation) { orientation->beta_ = kRad2deg * atan2(-axis_value[1], axis_value[2]); orientation->gamma_ = kRad2deg * asin(axis_value[0]); - // Make sure that the interval boundaries comply with the specification. - if (orientation->beta_ >= 180.0) - orientation->beta_ -= 360.0; - if (orientation->gamma_ >= 90.0) - orientation->gamma_ -= 180.0; + // Make sure that the interval boundaries comply with the specification. At + // this point, beta is [-180, 180] and gamma is [-90, 90], but the spec has + // the upper bound open on both. + if (orientation->beta_ == 180.0) { + orientation->beta_ = -180.0; // -180 == 180 (upside-down) + } + if (orientation->gamma_ == 90.0) { + static double just_less_than_90 = nextafter(90, 0); + orientation->gamma_ = just_less_than_90; + } + // At this point, DCHECKing is paranoia. Never hurts. DCHECK_GE(orientation->beta_, -180.0); DCHECK_LT(orientation->beta_, 180.0); DCHECK_GE(orientation->gamma_, -90.0); |