Chromium Code Reviews| Index: content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java |
| diff --git a/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java b/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java |
| index 76e77f4fef05590f73291705e359cd58f3b79b41..c78b52189bed735e10ac3318385c00ab47c5bae5 100644 |
| --- a/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java |
| +++ b/content/public/android/java/src/org/chromium/content/browser/DeviceSensors.java |
| @@ -271,7 +271,7 @@ class DeviceSensors implements SensorEventListener { |
| * </ul> |
| * <p> |
| * |
| - * @param R |
| + * @param r |
|
riju_
2014/10/14 06:25:58
Please check with Tim for this change.
Have a loo
timvolodine
2014/10/14 13:12:57
The use of R was to make code consistent with Andr
aurimas (slooooooooow)
2014/10/14 14:48:17
According to the style guide the method parameter
timvolodine
2014/10/14 16:29:40
I would argue for an exception for math functions
aurimas (slooooooooow)
2014/10/14 16:38:00
I agree that it is kind of silly, but this is the
|
| * a 3x3 rotation matrix {@see SensorManager.getRotationMatrix}. |
| * |
| * @param values |
| @@ -280,7 +280,7 @@ class DeviceSensors implements SensorEventListener { |
| * @return the array values passed as argument. |
| */ |
| @VisibleForTesting |
| - public static double[] computeDeviceOrientationFromRotationMatrix(float[] R, double[] values) { |
| + public static double[] computeDeviceOrientationFromRotationMatrix(float[] r, double[] values) { |
| /* |
| * 3x3 (length=9) case: |
| * / R[ 0] R[ 1] R[ 2] \ |
| @@ -288,39 +288,39 @@ class DeviceSensors implements SensorEventListener { |
| * \ R[ 6] R[ 7] R[ 8] / |
| * |
| */ |
| - if (R.length != 9) |
| - return values; |
| - |
| - if (R[8] > 0) { // cos(beta) > 0 |
| - values[0] = Math.atan2(-R[1], R[4]); |
| - values[1] = Math.asin(R[7]); // beta (-pi/2, pi/2) |
| - values[2] = Math.atan2(-R[6], R[8]); // gamma (-pi/2, pi/2) |
| - } else if (R[8] < 0) { // cos(beta) < 0 |
| - values[0] = Math.atan2(R[1], -R[4]); |
| - values[1] = -Math.asin(R[7]); |
| + if (r.length != 9) return values; |
| + |
| + if (r[8] > 0) { // cos(beta) > 0 |
| + values[0] = Math.atan2(-r[1], r[4]); |
| + values[1] = Math.asin(r[7]); // beta (-pi/2, pi/2) |
| + values[2] = Math.atan2(-r[6], r[8]); // gamma (-pi/2, pi/2) |
| + } else if (r[8] < 0) { // cos(beta) < 0 |
| + values[0] = Math.atan2(r[1], -r[4]); |
| + values[1] = -Math.asin(r[7]); |
| values[1] += (values[1] >= 0) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) |
| - values[2] = Math.atan2(R[6], -R[8]); // gamma (-pi/2, pi/2) |
| + values[2] = Math.atan2(r[6], -r[8]); // gamma (-pi/2, pi/2) |
| } else { // R[8] == 0 |
| - if (R[6] > 0) { // cos(gamma) == 0, cos(beta) > 0 |
| - values[0] = Math.atan2(-R[1], R[4]); |
| - values[1] = Math.asin(R[7]); // beta [-pi/2, pi/2] |
| + if (r[6] > 0) { // cos(gamma) == 0, cos(beta) > 0 |
| + values[0] = Math.atan2(-r[1], r[4]); |
| + values[1] = Math.asin(r[7]); // beta [-pi/2, pi/2] |
| values[2] = -Math.PI / 2; // gamma = -pi/2 |
| - } else if (R[6] < 0) { // cos(gamma) == 0, cos(beta) < 0 |
| - values[0] = Math.atan2(R[1], -R[4]); |
| - values[1] = -Math.asin(R[7]); |
| + } else if (r[6] < 0) { // cos(gamma) == 0, cos(beta) < 0 |
| + values[0] = Math.atan2(r[1], -r[4]); |
| + values[1] = -Math.asin(r[7]); |
| values[1] += (values[1] >= 0) ? -Math.PI : Math.PI; // beta [-pi,-pi/2) U (pi/2,pi) |
| values[2] = -Math.PI / 2; // gamma = -pi/2 |
| } else { // R[6] == 0, cos(beta) == 0 |
| // gimbal lock discontinuity |
| - values[0] = Math.atan2(R[3], R[0]); |
| - values[1] = (R[7] > 0) ? Math.PI / 2 : -Math.PI / 2; // beta = +-pi/2 |
| + values[0] = Math.atan2(r[3], r[0]); |
| + values[1] = (r[7] > 0) ? Math.PI / 2 : -Math.PI / 2; // beta = +-pi/2 |
| values[2] = 0; // gamma = 0 |
| } |
| } |
| // alpha is in [-pi, pi], make sure it is in [0, 2*pi). |
| - if (values[0] < 0) |
| + if (values[0] < 0) { |
| values[0] += 2 * Math.PI; // alpha [0, 2*pi) |
| + } |
| return values; |
| } |