浏览代码

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
 /// latitude: [-90.0, 90.0]
8
 /// latitude: [-90.0, 90.0]
9
 /// longitude: [-180, 180.0]
9
 /// longitude: [-180, 180.0]
10
 #[derive(Copy, Debug, PartialEq, Clone)]
10
 #[derive(Copy, Debug, PartialEq, Clone)]
11
-pub struct LatLon {
11
+pub struct LatLonDeg {
12
     pub lat: f64,
12
     pub lat: f64,
13
     pub lon: f64,
13
     pub lon: f64,
14
 }
14
 }
15
 
15
 
16
-impl LatLon {
16
+impl LatLonDeg {
17
     pub fn new(lat: f64, lon: f64) -> Self {
17
     pub fn new(lat: f64, lon: f64) -> Self {
18
-        LatLon { lat, lon }
18
+        LatLonDeg { lat, lon }
19
     }
19
     }
20
 
20
 
21
     pub fn to_radians(&self) -> LatLonRad {
21
     pub fn to_radians(&self) -> LatLonRad {
42
         LatLonRad { lat, lon }
42
         LatLonRad { lat, lon }
43
     }
43
     }
44
 
44
 
45
-    pub fn to_degrees(&self) -> LatLon {
45
+    pub fn to_degrees(&self) -> LatLonDeg {
46
         let f = 180.0 * FRAC_1_PI;
46
         let f = 180.0 * FRAC_1_PI;
47
-        LatLon {
47
+        LatLonDeg {
48
             lat: self.lat * f,
48
             lat: self.lat * f,
49
             lon: self.lon * f,
49
             lon: self.lon * f,
50
         }
50
         }
89
     pub y: f64,
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
         let x = pos.lon * (1.0 / 360.0) + 0.5;
95
         let x = pos.lon * (1.0 / 360.0) + 0.5;
96
         let pi_lat = pos.lat * (PI / 180.0);
96
         let pi_lat = pos.lat * (PI / 180.0);
97
         let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 * FRAC_1_PI) + 0.5;
97
         let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 * FRAC_1_PI) + 0.5;
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
             lat: (PI - self.y * (2.0 * PI)).sinh().atan() * (180.0 * FRAC_1_PI),
151
             lat: (PI - self.y * (2.0 * PI)).sinh().atan() * (180.0 * FRAC_1_PI),
152
             lon: self.x * 360.0 - 180.0,
152
             lon: self.x * 360.0 - 180.0,
153
         }
153
         }
476
     #[test]
476
     #[test]
477
     fn degree_radians() {
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
             assert!(approx_eq(rad.lat, 0.0));
480
             assert!(approx_eq(rad.lat, 0.0));
481
             assert!(approx_eq(rad.lon, 0.0));
481
             assert!(approx_eq(rad.lon, 0.0));
482
             let deg = rad.to_degrees();
482
             let deg = rad.to_degrees();
484
             assert!(approx_eq(deg.lon, 0.0));
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
             assert!(approx_eq(rad.lat, -PI / 4.0));
488
             assert!(approx_eq(rad.lat, -PI / 4.0));
489
             assert!(approx_eq(rad.lon, PI));
489
             assert!(approx_eq(rad.lon, PI));
490
             let deg = rad.to_degrees();
490
             let deg = rad.to_degrees();
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
             let deg = mc.to_latlon_rad().to_degrees();
497
             let deg = mc.to_latlon_rad().to_degrees();
498
             assert!(approx_eq(deg.lat, 23.45));
498
             assert!(approx_eq(deg.lat, 23.45));
499
             assert!(approx_eq(deg.lon, 123.45));
499
             assert!(approx_eq(deg.lon, 123.45));

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

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

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

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