OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/geoposition.h" | 5 #include "content/public/common/geoposition.h" |
6 | 6 |
7 namespace { | 7 namespace { |
8 // Sentinel values to mark invalid data. (WebKit carries companion is_valid | 8 // Sentinel values to mark invalid data. (WebKit carries companion is_valid |
9 // bools for this purpose; we may eventually follow that approach, but | 9 // bools for this purpose; we may eventually follow that approach, but |
10 // sentinels worked OK in the Gears code this is based on.) | 10 // sentinels worked OK in the Gears code this is based on.) |
11 const double kBadLatitudeLongitude = 200; | 11 const double kBadLatitudeLongitude = 200; |
12 // Lowest point on land is at approximately -400 meters. | 12 // Lowest point on land is at approximately -400 meters. |
13 const int kBadAltitude = -10000; | 13 const int kBadAltitude = -10000; |
14 const int kBadAccuracy = -1; // Accuracy must be non-negative. | 14 const int kBadAccuracy = -1; // Accuracy must be non-negative. |
15 const int64 kBadTimestamp = kint64min; | |
16 const int kBadHeading = -1; // Heading must be non-negative. | 15 const int kBadHeading = -1; // Heading must be non-negative. |
17 const int kBadSpeed = -1; | 16 const int kBadSpeed = -1; |
18 } | 17 } |
19 | 18 |
| 19 namespace content { |
| 20 |
20 Geoposition::Geoposition() | 21 Geoposition::Geoposition() |
21 : latitude(kBadLatitudeLongitude), | 22 : latitude(kBadLatitudeLongitude), |
22 longitude(kBadLatitudeLongitude), | 23 longitude(kBadLatitudeLongitude), |
23 altitude(kBadAltitude), | 24 altitude(kBadAltitude), |
24 accuracy(kBadAccuracy), | 25 accuracy(kBadAccuracy), |
25 altitude_accuracy(kBadAccuracy), | 26 altitude_accuracy(kBadAccuracy), |
26 heading(kBadHeading), | 27 heading(kBadHeading), |
27 speed(kBadSpeed), | 28 speed(kBadSpeed), |
28 error_code(ERROR_CODE_NONE) { | 29 error_code(ERROR_CODE_NONE) { |
29 } | 30 } |
30 | 31 |
31 bool Geoposition::is_valid_latlong() const { | 32 bool Geoposition::Validate() const { |
32 return latitude >= -90.0 && latitude <= 90.0 && | 33 return latitude >= -90. && latitude <= 90. && |
33 longitude >= -180.0 && longitude <= 180.0; | 34 longitude >= -180. && longitude <= 180. && |
| 35 accuracy >= 0. && |
| 36 !timestamp.is_null(); |
34 } | 37 } |
35 | 38 |
36 bool Geoposition::is_valid_altitude() const { | 39 } // namespace content |
37 return altitude > kBadAltitude; | |
38 } | |
39 | |
40 bool Geoposition::is_valid_accuracy() const { | |
41 return accuracy >= 0.0; | |
42 } | |
43 | |
44 bool Geoposition::is_valid_altitude_accuracy() const { | |
45 return altitude_accuracy >= 0.0; | |
46 } | |
47 | |
48 bool Geoposition::is_valid_heading() const { | |
49 return heading >= 0 && heading <= 360; | |
50 } | |
51 | |
52 bool Geoposition::is_valid_speed() const { | |
53 return speed >= 0; | |
54 } | |
55 | |
56 bool Geoposition::is_valid_timestamp() const { | |
57 return !timestamp.is_null(); | |
58 } | |
59 | |
60 bool Geoposition::IsValidFix() const { | |
61 return is_valid_latlong() && is_valid_accuracy() && is_valid_timestamp(); | |
62 } | |
63 | |
64 bool Geoposition::IsInitialized() const { | |
65 return error_code != ERROR_CODE_NONE || IsValidFix(); | |
66 } | |
OLD | NEW |