~opensatnav-admins/opensatnav/nice-package-rename

« back to all changes in this revision

Viewing changes to src/org/andnav/osm/views/util/Util.java

  • Committer: evolvedlight
  • Date: 2010-08-09 18:47:33 UTC
  • mfrom: (146.4.13 osn-small-tweaks)
  • mto: This revision was merged to the branch mainline in revision 163.
  • Revision ID: steve@evolvedlight.co.uk-20100809184733-sx3q5tw8txnc8eme
Merged in Kizza's branch

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 
20
20
import org.andnav.osm.util.BoundingBoxE6;
21
21
import org.andnav.osm.views.util.constants.OpenStreetMapViewConstants;
 
22
import org.opensatnav.OpenSatNavConstants;
 
23
 
22
24
 
23
25
/**
24
26
 * 
79
81
                final double n = Math.PI - ((2.0 * Math.PI * y) / Math.pow(2.0, aZoom));
80
82
                return 180.0 / Math.PI * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)));
81
83
        }
 
84
        
 
85
         /**
 
86
           * Checks to see if this is a valid speed.
 
87
           * 
 
88
           * @param updateTime The time at the current reading
 
89
           * @param speed The current speed
 
90
           * @param lastLocationTime The time at the last location
 
91
           * @param lastLocationSpeed Speed at the last location
 
92
           * @param speedBuffer A buffer of recent readings
 
93
           * @return True if this is likely a valid speed
 
94
           */
 
95
          public static boolean isValidSpeed(long updateTime, double speed,
 
96
              long lastLocationTime, double lastLocationSpeed
 
97
              ) {
 
98
 
 
99
            // We don't want to count 0 towards the speed.
 
100
            if (speed == 0) {
 
101
              return false;
 
102
            }
 
103
 
 
104
            // We are now sure the user is moving.
 
105
            long timeDifference = updateTime - lastLocationTime;
 
106
 
 
107
            // There are a lot of noisy speed readings.
 
108
            // Do the cheapest checks first, most expensive last.
 
109
            // The following code will ignore unlikely to be real readings.
 
110
            // - 128 m/s seems to be an internal android error code.
 
111
            if (Math.abs(speed - 128) < 1) {
 
112
              return false;
 
113
            }
 
114
 
 
115
            // Another check for a spurious reading. See if the path seems physically
 
116
            // likely. Ignore any speeds that imply accelaration greater than 2g's
 
117
            // Really who can accelerate faster?
 
118
            double speedDifference = Math.abs(lastLocationSpeed - speed);
 
119
            if (speedDifference > OpenSatNavConstants.MAX_ACCELERATION * timeDifference) {
 
120
              return false;
 
121
            }
 
122
 
 
123
          return true;
 
124
          }
82
125
 
83
126
        // ===========================================================
84
127
        // Inner and Anonymous Classes