Ver código fonte

Fix clippy warnings

Johannes Hofmann 7 anos atrás
pai
commit
2651bfe138
6 arquivos alterados com 36 adições e 36 exclusões
  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 Ver arquivo

@@ -429,8 +429,8 @@ impl TileCoord {
429 429
 
430 430
         TileCoord {
431 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 Ver arquivo

@@ -151,7 +151,7 @@ fn handle_event(
151 151
                             input_state.mouse_position.x * input_state.dpi_factor,
152 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 157
                 Action::Redraw

+ 2
- 2
src/ortho_tile_layer.rs Ver arquivo

@@ -31,8 +31,8 @@ impl LatScreenEllipse {
31 31
     fn new(view_center: LatLonRad, viewport_size: (u32, u32), sphere_radius: f64, lat: f64) -> Self {
32 32
         LatScreenEllipse {
33 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 37
             radius_x: lat.cos() * sphere_radius,
38 38
             radius_y: lat.cos() * -view_center.lat.sin() * sphere_radius,

+ 19
- 25
src/orthografic_view.rs Ver arquivo

@@ -126,9 +126,9 @@ impl OrthograficView {
126 126
         //TODO Add a little safety margin since the rendered globe is not a perfect sphere and its
127 127
         // screen area is underestimated by the tesselation.
128 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 134
     /// Returns the tile zoom value that is used for rendering with the current zoom.
@@ -175,9 +175,9 @@ impl OrthograficView {
175 175
 
176 176
             if vertices.iter().all(|v| v.z > 0.0) {
177 177
                 // Tile is on the backside of the sphere
178
-                return false;
178
+                false
179 179
             } else {
180
-                return vertices.iter().any(&point_on_screen);
180
+                vertices.iter().any(&point_on_screen)
181 181
             }
182 182
         };
183 183
 
@@ -192,25 +192,18 @@ impl OrthograficView {
192 192
 
193 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,7 +211,7 @@ impl OrthograficView {
218 211
     }
219 212
 
220 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 217
     pub fn transformation_matrix(map_view: &MapView) -> Matrix3<f64> {
@@ -257,9 +250,10 @@ impl OrthograficView {
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 Ver arquivo

@@ -1,3 +1,5 @@
1
+use std::str::FromStr;
2
+
1 3
 
2 4
 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
3 5
 pub enum Projection {
@@ -7,7 +9,6 @@ pub enum Projection {
7 9
     Orthografic,
8 10
 }
9 11
 
10
-
11 12
 impl Projection {
12 13
     pub fn to_str(&self) -> &str {
13 14
         match *self {
@@ -15,12 +16,16 @@ impl Projection {
15 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 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 Ver arquivo

@@ -3,6 +3,7 @@ use projection::Projection;
3 3
 use std::fs::File;
4 4
 use std::io::Read;
5 5
 use std::path::Path;
6
+use std::str::FromStr;
6 7
 use toml::Value;
7 8
 use toml::value::Table;
8 9
 use toml;
@@ -65,7 +66,7 @@ impl Session {
65 66
 
66 67
                 let projection = match view.get("projection") {
67 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 71
                     Some(_) => return Err("projection has to be a string.".to_string()),
71 72
                     None => Projection::Mercator,