Browse Source

Fix clippy warnings

Johannes Hofmann 7 years ago
parent
commit
2651bfe138
6 changed files with 36 additions and 36 deletions
  1. 2
    2
      src/coord.rs
  2. 1
    1
      src/main.rs
  3. 2
    2
      src/ortho_tile_layer.rs
  4. 19
    25
      src/orthografic_view.rs
  5. 10
    5
      src/projection.rs
  6. 2
    1
      src/session.rs

+ 2
- 2
src/coord.rs View File

429
 
429
 
430
         TileCoord {
430
         TileCoord {
431
             zoom: self.zoom,
431
             zoom: self.zoom,
432
-            x: x,
433
-            y: y,
432
+            x,
433
+            y,
434
         }
434
         }
435
     }
435
     }
436
 
436
 

+ 1
- 1
src/main.rs View File

151
                             input_state.mouse_position.x * input_state.dpi_factor,
151
                             input_state.mouse_position.x * input_state.dpi_factor,
152
                             input_state.mouse_position.y * input_state.dpi_factor,
152
                             input_state.mouse_position.y * input_state.dpi_factor,
153
                         ),
153
                         ),
154
-                        f64::from(delta.y) * (1.0 / 320.0),
154
+                        delta.y * (1.0 / 320.0),
155
                     );
155
                     );
156
                 }
156
                 }
157
                 Action::Redraw
157
                 Action::Redraw

+ 2
- 2
src/ortho_tile_layer.rs View File

31
     fn new(view_center: LatLonRad, viewport_size: (u32, u32), sphere_radius: f64, lat: f64) -> Self {
31
     fn new(view_center: LatLonRad, viewport_size: (u32, u32), sphere_radius: f64, lat: f64) -> Self {
32
         LatScreenEllipse {
32
         LatScreenEllipse {
33
             center: ScreenCoord {
33
             center: ScreenCoord {
34
-                x: viewport_size.0 as f64 * 0.5,
35
-                y: viewport_size.1 as f64 * 0.5 * (lat - view_center.lat).sin() * sphere_radius,
34
+                x: f64::from(viewport_size.0) * 0.5,
35
+                y: f64::from(viewport_size.1) * 0.5 * (lat - view_center.lat).sin() * sphere_radius,
36
             },
36
             },
37
             radius_x: lat.cos() * sphere_radius,
37
             radius_x: lat.cos() * sphere_radius,
38
             radius_y: lat.cos() * -view_center.lat.sin() * sphere_radius,
38
             radius_y: lat.cos() * -view_center.lat.sin() * sphere_radius,

+ 19
- 25
src/orthografic_view.rs View File

126
         //TODO Add a little safety margin since the rendered globe is not a perfect sphere and its
126
         //TODO Add a little safety margin since the rendered globe is not a perfect sphere and its
127
         // screen area is underestimated by the tesselation.
127
         // screen area is underestimated by the tesselation.
128
         let sphere_diameter = 2.0f64.powf(map_view.zoom) *
128
         let sphere_diameter = 2.0f64.powf(map_view.zoom) *
129
-            (f64::consts::FRAC_1_PI * map_view.tile_size as f64);
129
+            (f64::consts::FRAC_1_PI * f64::from(map_view.tile_size));
130
 
130
 
131
-        return map_view.width.hypot(map_view.height) < sphere_diameter;
131
+        map_view.width.hypot(map_view.height) < sphere_diameter
132
     }
132
     }
133
 
133
 
134
     /// Returns the tile zoom value that is used for rendering with the current zoom.
134
     /// Returns the tile zoom value that is used for rendering with the current zoom.
175
 
175
 
176
             if vertices.iter().all(|v| v.z > 0.0) {
176
             if vertices.iter().all(|v| v.z > 0.0) {
177
                 // Tile is on the backside of the sphere
177
                 // Tile is on the backside of the sphere
178
-                return false;
178
+                false
179
             } else {
179
             } else {
180
-                return vertices.iter().any(&point_on_screen);
180
+                vertices.iter().any(&point_on_screen)
181
             }
181
             }
182
         };
182
         };
183
 
183
 
192
 
192
 
193
         let mut neighbors = Vec::with_capacity(4);
193
         let mut neighbors = Vec::with_capacity(4);
194
 
194
 
195
-        loop {
196
-            if let Some(tn) = stack.pop() {
197
-                match tn {
198
-                    TileNeighbor::Coord(tc) => {
199
-                        if tile_is_visible(tc) {
200
-                            tiles.push(tc.into());
201
-                            tile_neighbors(tc, &mut neighbors);
202
-                            for tn in &neighbors {
203
-                                if !visited.contains(tn) {
204
-                                    visited.insert(*tn);
205
-                                    stack.push(*tn);
206
-                                }
207
-                            }
195
+        while let Some(tn) = stack.pop() {
196
+            if let TileNeighbor::Coord(tc) = tn {
197
+                if tile_is_visible(tc) {
198
+                    tiles.push(tc.into());
199
+                    tile_neighbors(tc, &mut neighbors);
200
+                    for tn in &neighbors {
201
+                        if !visited.contains(tn) {
202
+                            visited.insert(*tn);
203
+                            stack.push(*tn);
208
                         }
204
                         }
209
-                    },
210
-                    _ => {},
205
+                    }
211
                 }
206
                 }
212
-            } else {
213
-                break;
214
             }
207
             }
215
         }
208
         }
216
 
209
 
218
     }
211
     }
219
 
212
 
220
     pub fn radius_physical_pixels(map_view: &MapView) -> f64 {
213
     pub fn radius_physical_pixels(map_view: &MapView) -> f64 {
221
-        2.0f64.powf(map_view.zoom) * (FRAC_1_PI * map_view.tile_size as f64)
214
+        2.0f64.powf(map_view.zoom) * (FRAC_1_PI * f64::from(map_view.tile_size))
222
     }
215
     }
223
 
216
 
224
     pub fn transformation_matrix(map_view: &MapView) -> Matrix3<f64> {
217
     pub fn transformation_matrix(map_view: &MapView) -> Matrix3<f64> {
257
             )
250
             )
258
         };
251
         };
259
 
252
 
260
-        let transform = Transform::<Point3<f64>>::concat(&rot_mat_y, &rot_mat_x);
261
-        let transform = Transform::<Point3<f64>>::concat(&scale_mat, &transform);
262
-        transform
253
+        Transform::<Point3<f64>>::concat(
254
+            &scale_mat,
255
+            &Transform::<Point3<f64>>::concat(&rot_mat_y, &rot_mat_x)
256
+        )
263
     }
257
     }
264
 }
258
 }
265
 
259
 

+ 10
- 5
src/projection.rs View File

1
+use std::str::FromStr;
2
+
1
 
3
 
2
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
4
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
3
 pub enum Projection {
5
 pub enum Projection {
7
     Orthografic,
9
     Orthografic,
8
 }
10
 }
9
 
11
 
10
-
11
 impl Projection {
12
 impl Projection {
12
     pub fn to_str(&self) -> &str {
13
     pub fn to_str(&self) -> &str {
13
         match *self {
14
         match *self {
15
             Projection::Orthografic => "orthografic",
16
             Projection::Orthografic => "orthografic",
16
         }
17
         }
17
     }
18
     }
19
+}
20
+
21
+impl FromStr for Projection {
22
+    type Err = ();
18
 
23
 
19
-    pub fn from_str(s: &str) -> Option<Projection> {
24
+    fn from_str(s: &str) -> Result<Self, ()> {
20
         match s {
25
         match s {
21
-            "mercator" => Some(Projection::Mercator),
22
-            "orthografic" => Some(Projection::Orthografic),
23
-            _ => None,
26
+            "mercator" => Ok(Projection::Mercator),
27
+            "orthografic" => Ok(Projection::Orthografic),
28
+            _ => Err(()),
24
         }
29
         }
25
     }
30
     }
26
 }
31
 }

+ 2
- 1
src/session.rs View File

3
 use std::fs::File;
3
 use std::fs::File;
4
 use std::io::Read;
4
 use std::io::Read;
5
 use std::path::Path;
5
 use std::path::Path;
6
+use std::str::FromStr;
6
 use toml::Value;
7
 use toml::Value;
7
 use toml::value::Table;
8
 use toml::value::Table;
8
 use toml;
9
 use toml;
65
 
66
 
66
                 let projection = match view.get("projection") {
67
                 let projection = match view.get("projection") {
67
                     Some(&Value::String(ref s)) => {
68
                     Some(&Value::String(ref s)) => {
68
-                        Projection::from_str(s).unwrap_or_else(|| Projection::Mercator)
69
+                        Projection::from_str(s).unwrap_or_else(|_| Projection::Mercator)
69
                     },
70
                     },
70
                     Some(_) => return Err("projection has to be a string.".to_string()),
71
                     Some(_) => return Err("projection has to be a string.".to_string()),
71
                     None => Projection::Mercator,
72
                     None => Projection::Mercator,