浏览代码

Add integer coordinate functions

Dan Larkin 6 年前
父节点
当前提交
60a2c54876
共有 3 个文件被更改,包括 69 次插入12 次删除
  1. 22
    6
      src/dense.rs
  2. 22
    6
      src/elements.rs
  3. 25
    0
      tests/read.rs

+ 22
- 6
src/dense.rs 查看文件

36
 
36
 
37
     /// Returns the latitude coordinate in degrees.
37
     /// Returns the latitude coordinate in degrees.
38
     pub fn lat(&self) -> f64 {
38
     pub fn lat(&self) -> f64 {
39
-        0.000_000_001_f64 * (self.block.get_lat_offset() +
40
-                             (i64::from(self.block.get_granularity()) *
41
-                              self.lat)) as f64
39
+        1e-9 * self.nano_lat() as f64
40
+    }
41
+
42
+    /// Returns the latitude coordinate in nanodegrees (10⁻⁹).
43
+    pub fn nano_lat(&self) -> i64 {
44
+        self.block.get_lat_offset() + i64::from(self.block.get_granularity()) * self.lat
45
+    }
46
+
47
+    /// Returns the latitude coordinate in decimicrodegrees (10⁻⁷).
48
+    pub fn decimicro_lat(&self) -> i32 {
49
+        (self.nano_lat() / 100) as i32
42
     }
50
     }
43
 
51
 
44
     /// Returns the longitude coordinate in degrees.
52
     /// Returns the longitude coordinate in degrees.
45
     pub fn lon(&self) -> f64 {
53
     pub fn lon(&self) -> f64 {
46
-        0.000_000_001_f64 * (self.block.get_lon_offset() +
47
-                             (i64::from(self.block.get_granularity()) *
48
-                              self.lon)) as f64
54
+        1e-9 * self.nano_lon() as f64
55
+    }
56
+
57
+    /// Returns the longitude in nanodegrees (10⁻⁹).
58
+    pub fn nano_lon(&self) -> i64 {
59
+        self.block.get_lon_offset() + i64::from(self.block.get_granularity()) * self.lon
60
+    }
61
+
62
+    /// Returns the longitude coordinate in decimicrodegrees (10⁻⁷).
63
+    pub fn decimicro_lon(&self) -> i32 {
64
+        (self.nano_lon() / 100) as i32
49
     }
65
     }
50
 
66
 
51
     /// Returns the time stamp in milliseconds since the epoch.
67
     /// Returns the time stamp in milliseconds since the epoch.

+ 22
- 6
src/elements.rs 查看文件

85
 
85
 
86
     /// Returns the latitude coordinate in degrees.
86
     /// Returns the latitude coordinate in degrees.
87
     pub fn lat(&self) -> f64 {
87
     pub fn lat(&self) -> f64 {
88
-        0.000_000_001_f64 * (self.block.get_lat_offset() +
89
-                             (i64::from(self.block.get_granularity()) *
90
-                              self.osmnode.get_lat())) as f64
88
+        1e-9 * self.nano_lat() as f64
89
+    }
90
+
91
+    /// Returns the latitude coordinate in nanodegrees (10⁻⁹).
92
+    pub fn nano_lat(&self) -> i64 {
93
+        self.block.get_lat_offset() + i64::from(self.block.get_granularity()) * self.osmnode.get_lat()
94
+    }
95
+
96
+    /// Returns the latitude coordinate in decimicrodegrees (10⁻⁷).
97
+    pub fn decimicro_lat(&self) -> i32 {
98
+        (self.nano_lat() / 100) as i32
91
     }
99
     }
92
 
100
 
93
     /// Returns the longitude coordinate in degrees.
101
     /// Returns the longitude coordinate in degrees.
94
     pub fn lon(&self) -> f64 {
102
     pub fn lon(&self) -> f64 {
95
-        0.000_000_001_f64 * (self.block.get_lon_offset() +
96
-                             (i64::from(self.block.get_granularity()) *
97
-                              self.osmnode.get_lon())) as f64
103
+        1e-9 * self.nano_lon() as f64
104
+    }
105
+
106
+    /// Returns the longitude in nanodegrees (10⁻⁹).
107
+    pub fn nano_lon(&self) -> i64 {
108
+        self.block.get_lon_offset() + i64::from(self.block.get_granularity()) * self.osmnode.get_lon()
109
+    }
110
+
111
+    /// Returns the longitude coordinate in decimicrodegrees (10⁻⁷).
112
+    pub fn decimicro_lon(&self) -> i32 {
113
+        (self.nano_lon() / 100) as i32
98
     }
114
     }
99
 
115
 
100
     /// Returns an iterator over the tags of this node
116
     /// Returns an iterator over the tags of this node

+ 25
- 0
tests/read.rs 查看文件

28
     if !nodes.is_empty() {
28
     if !nodes.is_empty() {
29
         assert_eq!(nodes.len(), 3);
29
         assert_eq!(nodes.len(), 3);
30
 
30
 
31
+        // node 1 lat
31
         assert!(approx_eq(nodes[1].lat(), 52.11992359584));
32
         assert!(approx_eq(nodes[1].lat(), 52.11992359584));
33
+        assert_eq!(nodes[1].nano_lat(), 52119923500);
34
+        assert_eq!(nodes[1].decimicro_lat(), 521199235);
35
+        // node 1 lon
32
         assert!(approx_eq(nodes[1].lon(), 11.62564468943));
36
         assert!(approx_eq(nodes[1].lon(), 11.62564468943));
37
+        assert_eq!(nodes[1].nano_lon(), 11625644600);
38
+        assert_eq!(nodes[1].decimicro_lon(), 116256446);
33
 
39
 
40
+        // node 2 lat
34
         assert!(approx_eq(nodes[2].lat(), 52.11989910567));
41
         assert!(approx_eq(nodes[2].lat(), 52.11989910567));
42
+        assert_eq!(nodes[2].nano_lat(), 52119899100);
43
+        assert_eq!(nodes[2].decimicro_lat(), 521198991);
44
+        //node 2 lon
35
         assert!(approx_eq(nodes[2].lon(), 11.63101926915));
45
         assert!(approx_eq(nodes[2].lon(), 11.63101926915));
46
+        assert_eq!(nodes[2].nano_lon(), 11631019200);
47
+        assert_eq!(nodes[2].decimicro_lon(), 116310192);
48
+
36
 
49
 
37
         assert_eq!(nodes[0].id(), 105);
50
         assert_eq!(nodes[0].id(), 105);
38
         assert_eq!(nodes[1].id(), 106);
51
         assert_eq!(nodes[1].id(), 106);
47
     if !dense_nodes.is_empty() {
60
     if !dense_nodes.is_empty() {
48
         assert_eq!(dense_nodes.len(), 3);
61
         assert_eq!(dense_nodes.len(), 3);
49
 
62
 
63
+        // node 1 lat
50
         assert!(approx_eq(dense_nodes[1].lat(), 52.11992359584));
64
         assert!(approx_eq(dense_nodes[1].lat(), 52.11992359584));
65
+        assert_eq!(dense_nodes[1].nano_lat(), 52119923500);
66
+        assert_eq!(dense_nodes[1].decimicro_lat(), 521199235);
67
+        //node 1 lon
51
         assert!(approx_eq(dense_nodes[1].lon(), 11.62564468943));
68
         assert!(approx_eq(dense_nodes[1].lon(), 11.62564468943));
69
+        assert_eq!(dense_nodes[1].nano_lon(), 11625644600);
70
+        assert_eq!(dense_nodes[1].decimicro_lon(), 116256446);
52
 
71
 
72
+        //node 2 lat
53
         assert!(approx_eq(dense_nodes[2].lat(), 52.11989910567));
73
         assert!(approx_eq(dense_nodes[2].lat(), 52.11989910567));
74
+        assert_eq!(dense_nodes[2].nano_lat(), 52119899100);
75
+        assert_eq!(dense_nodes[2].decimicro_lat(), 521198991);
76
+        // node 2 lon
54
         assert!(approx_eq(dense_nodes[2].lon(), 11.63101926915));
77
         assert!(approx_eq(dense_nodes[2].lon(), 11.63101926915));
78
+        assert_eq!(dense_nodes[2].nano_lon(), 11631019200);
79
+        assert_eq!(dense_nodes[2].decimicro_lon(), 116310192);
55
 
80
 
56
         assert_eq!(dense_nodes[0].id, 105);
81
         assert_eq!(dense_nodes[0].id, 105);
57
         assert_eq!(dense_nodes[1].id, 106);
82
         assert_eq!(dense_nodes[1].id, 106);