瀏覽代碼

Rename coord::LatLon -> coord::LatLonDeg

Johannes Hofmann 7 年之前
父節點
當前提交
408f7da93e
共有 3 個文件被更改,包括 21 次插入21 次删除
  1. 12
    12
      src/coord.rs
  2. 2
    2
      src/main.rs
  3. 7
    7
      src/search.rs

+ 12
- 12
src/coord.rs 查看文件

@@ -8,14 +8,14 @@ use cgmath::{Point3};
8 8
 /// latitude: [-90.0, 90.0]
9 9
 /// longitude: [-180, 180.0]
10 10
 #[derive(Copy, Debug, PartialEq, Clone)]
11
-pub struct LatLon {
11
+pub struct LatLonDeg {
12 12
     pub lat: f64,
13 13
     pub lon: f64,
14 14
 }
15 15
 
16
-impl LatLon {
16
+impl LatLonDeg {
17 17
     pub fn new(lat: f64, lon: f64) -> Self {
18
-        LatLon { lat, lon }
18
+        LatLonDeg { lat, lon }
19 19
     }
20 20
 
21 21
     pub fn to_radians(&self) -> LatLonRad {
@@ -42,9 +42,9 @@ impl LatLonRad {
42 42
         LatLonRad { lat, lon }
43 43
     }
44 44
 
45
-    pub fn to_degrees(&self) -> LatLon {
45
+    pub fn to_degrees(&self) -> LatLonDeg {
46 46
         let f = 180.0 * FRAC_1_PI;
47
-        LatLon {
47
+        LatLonDeg {
48 48
             lat: self.lat * f,
49 49
             lon: self.lon * f,
50 50
         }
@@ -89,9 +89,9 @@ pub struct MapCoord {
89 89
     pub y: f64,
90 90
 }
91 91
 
92
-impl From<LatLon> for MapCoord
92
+impl From<LatLonDeg> for MapCoord
93 93
 {
94
-    fn from(pos: LatLon) -> MapCoord {
94
+    fn from(pos: LatLonDeg) -> MapCoord {
95 95
         let x = pos.lon * (1.0 / 360.0) + 0.5;
96 96
         let pi_lat = pos.lat * (PI / 180.0);
97 97
         let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 * FRAC_1_PI) + 0.5;
@@ -146,8 +146,8 @@ impl MapCoord {
146 146
         }
147 147
     }
148 148
 
149
-    pub fn to_latlon_deg(&self) -> LatLon {
150
-        LatLon {
149
+    pub fn to_latlon_deg(&self) -> LatLonDeg {
150
+        LatLonDeg {
151 151
             lat: (PI - self.y * (2.0 * PI)).sinh().atan() * (180.0 * FRAC_1_PI),
152 152
             lon: self.x * 360.0 - 180.0,
153 153
         }
@@ -476,7 +476,7 @@ mod tests {
476 476
     #[test]
477 477
     fn degree_radians() {
478 478
         {
479
-            let rad = LatLon::new(0.0, 0.0).to_radians();
479
+            let rad = LatLonDeg::new(0.0, 0.0).to_radians();
480 480
             assert!(approx_eq(rad.lat, 0.0));
481 481
             assert!(approx_eq(rad.lon, 0.0));
482 482
             let deg = rad.to_degrees();
@@ -484,7 +484,7 @@ mod tests {
484 484
             assert!(approx_eq(deg.lon, 0.0));
485 485
         }
486 486
         {
487
-            let rad = LatLon::new(-45.0, 180.0).to_radians();
487
+            let rad = LatLonDeg::new(-45.0, 180.0).to_radians();
488 488
             assert!(approx_eq(rad.lat, -PI / 4.0));
489 489
             assert!(approx_eq(rad.lon, PI));
490 490
             let deg = rad.to_degrees();
@@ -493,7 +493,7 @@ mod tests {
493 493
         }
494 494
 
495 495
         {
496
-            let mc = MapCoord::from(LatLon::new(23.45, 123.45));
496
+            let mc = MapCoord::from(LatLonDeg::new(23.45, 123.45));
497 497
             let deg = mc.to_latlon_rad().to_degrees();
498 498
             assert!(approx_eq(deg.lat, 23.45));
499 499
             assert!(approx_eq(deg.lon, 123.45));

+ 2
- 2
src/main.rs 查看文件

@@ -40,7 +40,7 @@ pub mod tile_source;
40 40
 pub mod url_template;
41 41
 pub mod vertex_attrib;
42 42
 
43
-use coord::{LatLon, ScreenCoord};
43
+use coord::{LatLonDeg, ScreenCoord};
44 44
 use glutin::{ControlFlow, ElementState, Event, GlContext, MouseButton, MouseScrollDelta, VirtualKeyCode, WindowEvent};
45 45
 use map_view_gl::MapViewGl;
46 46
 use std::error::Error;
@@ -80,7 +80,7 @@ fn handle_event(
80 80
     map: &mut MapViewGl,
81 81
     input_state: &mut InputState,
82 82
     sources: &mut TileSources,
83
-    marker_rx: &mpsc::Receiver<Vec<LatLon>>,
83
+    marker_rx: &mpsc::Receiver<Vec<LatLonDeg>>,
84 84
 ) -> Action {
85 85
     match *event {
86 86
         Event::Awakened => {

+ 7
- 7
src/search.rs 查看文件

@@ -1,4 +1,4 @@
1
-use coord::LatLon;
1
+use coord::LatLonDeg;
2 2
 use osmpbf::{Blob, BlobDecode, BlobReader, PrimitiveBlock};
3 3
 use regex::Regex;
4 4
 use scoped_threadpool::Pool;
@@ -36,7 +36,7 @@ pub fn par_search<P, F, G>(
36 36
     finished_func: G,
37 37
 ) -> Result<thread::JoinHandle<()>, String>
38 38
 where P: AsRef<Path>,
39
-      F: Fn(Vec<LatLon>) -> ControlFlow + Send + 'static,
39
+      F: Fn(Vec<LatLonDeg>) -> ControlFlow + Send + 'static,
40 40
       G: Fn(Result<(), String>) + Send + 'static,
41 41
 {
42 42
     let pbf_path = PathBuf::from(pbf_path.as_ref());
@@ -55,7 +55,7 @@ pub fn par_search_blocking<P, F>(
55 55
     found_func: F,
56 56
 ) -> Result<(), String>
57 57
 where P: AsRef<Path>,
58
-      F: Fn(Vec<LatLon>) -> ControlFlow + Send + 'static,
58
+      F: Fn(Vec<LatLonDeg>) -> ControlFlow + Send + 'static,
59 59
 {
60 60
     let re = Regex::new(search_pattern)
61 61
         .map_err(|e| format!("{}", e))?;
@@ -68,7 +68,7 @@ where P: AsRef<Path>,
68 68
         for node in block.groups().flat_map(|g| g.nodes()) {
69 69
             for (_key, val) in node.tags() {
70 70
                 if re.is_match(val) {
71
-                    let pos = LatLon::new(node.lat(), node.lon());
71
+                    let pos = LatLonDeg::new(node.lat(), node.lon());
72 72
                     matches.push(pos);
73 73
                     break;
74 74
                 }
@@ -78,7 +78,7 @@ where P: AsRef<Path>,
78 78
         for node in block.groups().flat_map(|g| g.dense_nodes()) {
79 79
             for (_key, val) in node.tags() {
80 80
                 if re.is_match(val) {
81
-                    let pos = LatLon::new(node.lat(), node.lon());
81
+                    let pos = LatLonDeg::new(node.lat(), node.lon());
82 82
                     matches.push(pos);
83 83
                     break;
84 84
                 }
@@ -117,14 +117,14 @@ where P: AsRef<Path>,
117 117
 
118 118
         for node in block.groups().flat_map(|g| g.nodes()) {
119 119
             if way_node_ids.contains(&node.id()) {
120
-                let pos = LatLon::new(node.lat(), node.lon());
120
+                let pos = LatLonDeg::new(node.lat(), node.lon());
121 121
                 matches.push(pos);
122 122
             }
123 123
         }
124 124
 
125 125
         for node in block.groups().flat_map(|g| g.dense_nodes()) {
126 126
             if way_node_ids.contains(&node.id) {
127
-                let pos = LatLon::new(node.lat(), node.lon());
127
+                let pos = LatLonDeg::new(node.lat(), node.lon());
128 128
                 matches.push(pos);
129 129
             }
130 130
         }