Browse Source

Fix clippy warnings

Johannes Hofmann 7 years ago
parent
commit
fcbad65155
14 changed files with 62 additions and 79 deletions
  1. 2
    4
      src/args.rs
  2. 3
    3
      src/buffer.rs
  3. 4
    4
      src/config.rs
  4. 1
    1
      src/context.rs
  5. 9
    24
      src/coord.rs
  6. 1
    1
      src/main.rs
  7. 9
    9
      src/map_view.rs
  8. 4
    4
      src/map_view_gl.rs
  9. 4
    4
      src/program.rs
  10. 8
    8
      src/texture.rs
  11. 2
    2
      src/tile.rs
  12. 5
    5
      src/tile_atlas.rs
  13. 6
    6
      src/tile_loader.rs
  14. 4
    4
      src/tile_source.rs

+ 2
- 4
src/args.rs View File

3
 
3
 
4
 
4
 
5
 pub fn parse<'a>() -> clap::ArgMatches<'a> {
5
 pub fn parse<'a>() -> clap::ArgMatches<'a> {
6
-    let matches = clap::App::new("DeltaMap")
6
+    clap::App::new("DeltaMap")
7
         .version(crate_version!())
7
         .version(crate_version!())
8
         .author(crate_authors!())
8
         .author(crate_authors!())
9
         .about(crate_description!())
9
         .about(crate_description!())
38
             .long("sync")
38
             .long("sync")
39
             .help("Load tiles in a synchronous fashion. \
39
             .help("Load tiles in a synchronous fashion. \
40
                 The UI is blocked while tiles are loading."))
40
                 The UI is blocked while tiles are loading."))
41
-        .get_matches();
42
-
43
-    matches
41
+        .get_matches()
44
 }
42
 }

+ 3
- 3
src/buffer.rs View File

41
         }
41
         }
42
 
42
 
43
         Buffer {
43
         Buffer {
44
-            cx: cx,
45
-            buffer_obj: buffer_obj,
46
-            num_elements: num_elements,
44
+            cx,
45
+            buffer_obj,
46
+            num_elements,
47
         }
47
         }
48
     }
48
     }
49
 
49
 

+ 4
- 4
src/config.rs View File

156
 
156
 
157
                 Ok(
157
                 Ok(
158
                     Config {
158
                     Config {
159
-                        tile_cache_dir: tile_cache_dir,
159
+                        tile_cache_dir,
160
                         sources: vec![],
160
                         sources: vec![],
161
-                        fps: fps,
162
-                        use_network: use_network,
163
-                        async: async,
161
+                        fps,
162
+                        use_network,
163
+                        async,
164
                     }
164
                     }
165
                 )
165
                 )
166
             },
166
             },

+ 1
- 1
src/context.rs View File

34
 impl Context {
34
 impl Context {
35
     pub fn from_gl_window(window: &glutin::GlWindow) -> Context {
35
     pub fn from_gl_window(window: &glutin::GlWindow) -> Context {
36
         let gl = gl::Gl::load_with(|ptr| window.get_proc_address(ptr) as *const _);
36
         let gl = gl::Gl::load_with(|ptr| window.get_proc_address(ptr) as *const _);
37
-        let cx = Context { gl: gl };
37
+        let cx = Context { gl };
38
 
38
 
39
         // Initialize a vertex array object (VAO) if the current OpenGL context supports it. VAOs are
39
         // Initialize a vertex array object (VAO) if the current OpenGL context supports it. VAOs are
40
         // not OpenGL ES 2.0 compatible, but are required for rendering with a core context.
40
         // not OpenGL ES 2.0 compatible, but are required for rendering with a core context.

+ 9
- 24
src/coord.rs View File

11
 
11
 
12
 impl MapCoord {
12
 impl MapCoord {
13
     pub fn new(x: f64, y: f64) -> MapCoord {
13
     pub fn new(x: f64, y: f64) -> MapCoord {
14
-        MapCoord {
15
-            x: x,
16
-            y: y,
17
-        }
14
+        MapCoord { x, y }
18
     }
15
     }
19
 
16
 
20
     pub fn from_latlon(latitude: f64, longitude: f64) -> MapCoord {
17
     pub fn from_latlon(latitude: f64, longitude: f64) -> MapCoord {
22
         let pi_lat = latitude * (PI / 180.0);
19
         let pi_lat = latitude * (PI / 180.0);
23
         let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 / PI) + 0.5;
20
         let y = f64::ln(f64::tan(pi_lat) + 1.0 / f64::cos(pi_lat)) * (-0.5 / PI) + 0.5;
24
 
21
 
25
-        MapCoord {
26
-            x: x,
27
-            y: y,
28
-        }
22
+        MapCoord { x, y }
29
     }
23
     }
30
 
24
 
31
     //TODO differ between normalized and not normalized tiles
25
     //TODO differ between normalized and not normalized tiles
32
     pub fn on_tile_at_zoom(&self, zoom: u32) -> TileCoord {
26
     pub fn on_tile_at_zoom(&self, zoom: u32) -> TileCoord {
33
         let zoom_factor = f64::powi(2.0, zoom as i32);
27
         let zoom_factor = f64::powi(2.0, zoom as i32);
34
-        let ix = (self.x * zoom_factor).floor() as i32;
35
-        let iy = (self.y * zoom_factor).floor() as i32;
28
+        let x = (self.x * zoom_factor).floor() as i32;
29
+        let y = (self.y * zoom_factor).floor() as i32;
36
 
30
 
37
-        let x = ix;
38
-        let y = iy;
39
-
40
-        TileCoord {
41
-            zoom: zoom,
42
-            x: x,
43
-            y: y,
44
-        }
31
+        TileCoord { zoom, x, y }
45
     }
32
     }
46
 
33
 
47
     pub fn normalize_x(&mut self) {
34
     pub fn normalize_x(&mut self) {
68
 
55
 
69
 impl ScreenCoord {
56
 impl ScreenCoord {
70
     pub fn new(x: f64, y: f64) -> Self {
57
     pub fn new(x: f64, y: f64) -> Self {
71
-        ScreenCoord {
72
-            x: x,
73
-            y: y,
74
-        }
58
+        ScreenCoord { x, y }
75
     }
59
     }
60
+
76
     pub fn snap_to_pixel(&mut self) {
61
     pub fn snap_to_pixel(&mut self) {
77
         self.x = self.x.floor();
62
         self.x = self.x.floor();
78
         self.y = self.y.floor();
63
         self.y = self.y.floor();
168
 impl TileCoord {
153
 impl TileCoord {
169
     pub fn new(zoom: u32, x: i32, y: i32) -> TileCoord {
154
     pub fn new(zoom: u32, x: i32, y: i32) -> TileCoord {
170
         TileCoord {
155
         TileCoord {
171
-            zoom: zoom,
156
+            zoom,
172
             x: Self::normalize_coord(x, zoom),
157
             x: Self::normalize_coord(x, zoom),
173
-            y: y,
158
+            y,
174
         }
159
         }
175
     }
160
     }
176
 
161
 

+ 1
- 1
src/main.rs View File

334
         } else {
334
         } else {
335
             Some(TileSources {
335
             Some(TileSources {
336
                 current_index: 0,
336
                 current_index: 0,
337
-                sources: sources,
337
+                sources,
338
             })
338
             })
339
         }
339
         }
340
     }
340
     }

+ 9
- 9
src/map_view.rs View File

31
     /// Constructs a new `MapView`.
31
     /// Constructs a new `MapView`.
32
     pub fn new(width: f64, height: f64, tile_size: u32, center: MapCoord, zoom: f64) -> MapView {
32
     pub fn new(width: f64, height: f64, tile_size: u32, center: MapCoord, zoom: f64) -> MapView {
33
         MapView {
33
         MapView {
34
-            width: width,
35
-            height: height,
36
-            tile_size: tile_size,
37
-            center: center,
38
-            zoom: zoom,
34
+            width,
35
+            height,
36
+            tile_size,
37
+            center,
38
+            zoom,
39
             tile_zoom_offset: 0.0,
39
             tile_zoom_offset: 0.0,
40
         }
40
         }
41
     }
41
     }
46
         let min_dimension = width.min(height);
46
         let min_dimension = width.min(height);
47
         let zoom = (min_dimension / f64::from(tile_size)).log2().ceil();
47
         let zoom = (min_dimension / f64::from(tile_size)).log2().ceil();
48
         MapView {
48
         MapView {
49
-            width: width,
50
-            height: height,
51
-            tile_size: tile_size,
49
+            width,
50
+            height,
51
+            tile_size,
52
             center: MapCoord::new(0.5, 0.5),
52
             center: MapCoord::new(0.5, 0.5),
53
-            zoom: zoom,
53
+            zoom,
54
             tile_zoom_offset: 0.0,
54
             tile_zoom_offset: 0.0,
55
         }
55
         }
56
     }
56
     }

+ 4
- 4
src/map_view_gl.rs View File

73
         let map_view = MapView::with_filling_zoom(f64::from(initial_size.0), f64::from(initial_size.1), tile_size);
73
         let map_view = MapView::with_filling_zoom(f64::from(initial_size.0), f64::from(initial_size.1), tile_size);
74
 
74
 
75
         MapViewGl {
75
         MapViewGl {
76
-            cx: cx,
77
-            program: program,
78
-            buf: buf,
76
+            cx,
77
+            program,
78
+            buf,
79
             viewport_size: initial_size,
79
             viewport_size: initial_size,
80
-            map_view: map_view,
80
+            map_view,
81
             tile_cache: TileCache::new(move |_tile| update_func(), use_network),
81
             tile_cache: TileCache::new(move |_tile| update_func(), use_network),
82
             tile_atlas: TileAtlas::new(tex, 256, use_async),
82
             tile_atlas: TileAtlas::new(tex, 256, use_async),
83
         }
83
         }

+ 4
- 4
src/program.rs View File

92
             };
92
             };
93
 
93
 
94
             Ok(Program {
94
             Ok(Program {
95
-                cx: cx,
96
-                vert_obj: vert_obj,
97
-                frag_obj: frag_obj,
98
-                program_obj: program_obj,
95
+                cx,
96
+                vert_obj,
97
+                frag_obj,
98
+                program_obj,
99
                 tex_ids: vec![],
99
                 tex_ids: vec![],
100
                 tex_locations: vec![],
100
                 tex_locations: vec![],
101
             })
101
             })

+ 8
- 8
src/texture.rs View File

38
     }
38
     }
39
 
39
 
40
     fn from_ptr(cx: &'a Context, width: u32, height: u32, format: TextureFormat, data_ptr: *const c_void) -> Texture<'a> {
40
     fn from_ptr(cx: &'a Context, width: u32, height: u32, format: TextureFormat, data_ptr: *const c_void) -> Texture<'a> {
41
-        let mut tex_obj = 0_u32;
41
+        let mut texture_obj = 0_u32;
42
         unsafe {
42
         unsafe {
43
-            cx.gl.GenTextures(1, &mut tex_obj);
44
-            cx.gl.BindTexture(context::gl::TEXTURE_2D, tex_obj);
43
+            cx.gl.GenTextures(1, &mut texture_obj);
44
+            cx.gl.BindTexture(context::gl::TEXTURE_2D, texture_obj);
45
 
45
 
46
             cx.gl.TexParameteri(context::gl::TEXTURE_2D, context::gl::TEXTURE_MIN_FILTER, context::gl::LINEAR as i32);
46
             cx.gl.TexParameteri(context::gl::TEXTURE_2D, context::gl::TEXTURE_MIN_FILTER, context::gl::LINEAR as i32);
47
             cx.gl.TexParameteri(context::gl::TEXTURE_2D, context::gl::TEXTURE_MAG_FILTER, context::gl::LINEAR as i32);
47
             cx.gl.TexParameteri(context::gl::TEXTURE_2D, context::gl::TEXTURE_MAG_FILTER, context::gl::LINEAR as i32);
61
         }
61
         }
62
 
62
 
63
         Texture {
63
         Texture {
64
-            cx: cx,
65
-            texture_obj: tex_obj,
66
-            width: width,
67
-            height: height,
68
-            format: format,
64
+            cx,
65
+            texture_obj,
66
+            width,
67
+            height,
68
+            format,
69
         }
69
         }
70
     }
70
     }
71
 
71
 

+ 2
- 2
src/tile.rs View File

11
 impl Tile {
11
 impl Tile {
12
     pub fn new(coord: TileCoord, source_id: TileSourceId) -> Tile {
12
     pub fn new(coord: TileCoord, source_id: TileSourceId) -> Tile {
13
         Tile {
13
         Tile {
14
-            coord: coord,
15
-            source_id: source_id,
14
+            coord,
15
+            source_id,
16
         }
16
         }
17
     }
17
     }
18
 }
18
 }

+ 5
- 5
src/tile_atlas.rs View File

43
         self.slots_lru.reserve(num_slots);
43
         self.slots_lru.reserve(num_slots);
44
         for x in 0..slots_x {
44
         for x in 0..slots_x {
45
             for y in 0..slots_y {
45
             for y in 0..slots_y {
46
-                let slot = CacheSlot { x: x, y: y };
46
+                let slot = CacheSlot { x, y };
47
                 self.slots_lru.insert(slot, None);
47
                 self.slots_lru.insert(slot, None);
48
             }
48
             }
49
         }
49
         }
56
     pub fn new(tex: Texture<'a>, tile_size: u32, use_async: bool) -> Self {
56
     pub fn new(tex: Texture<'a>, tile_size: u32, use_async: bool) -> Self {
57
         let mut atlas = TileAtlas {
57
         let mut atlas = TileAtlas {
58
             texture: tex,
58
             texture: tex,
59
-            tile_size: tile_size,
59
+            tile_size,
60
             slots_lru: LinkedHashMap::new(),
60
             slots_lru: LinkedHashMap::new(),
61
             tile_to_slot: HashMap::new(),
61
             tile_to_slot: HashMap::new(),
62
-            use_async: use_async,
62
+            use_async,
63
         };
63
         };
64
 
64
 
65
         atlas.init();
65
         atlas.init();
172
                 tvt.push(
172
                 tvt.push(
173
                     TexturedVisibleTile {
173
                     TexturedVisibleTile {
174
                         screen_rect: vt.rect,
174
                         screen_rect: vt.rect,
175
-                        tex_rect: tex_rect,
175
+                        tex_rect,
176
                         tex_minmax: tex_rect.inset(inset_x, inset_y),
176
                         tex_minmax: tex_rect.inset(inset_x, inset_y),
177
                     }
177
                     }
178
                 );
178
                 );
210
                         tvt.push(
210
                         tvt.push(
211
                             TexturedVisibleTile {
211
                             TexturedVisibleTile {
212
                                 screen_rect: vt.rect.subdivide(&child_sub_coord),
212
                                 screen_rect: vt.rect.subdivide(&child_sub_coord),
213
-                                tex_rect: tex_rect,
213
+                                tex_rect,
214
                                 tex_minmax: tex_rect.inset(inset_x, inset_y),
214
                                 tex_minmax: tex_rect.inset(inset_x, inset_y),
215
                             }
215
                             }
216
                         );
216
                         );

+ 6
- 6
src/tile_loader.rs View File

37
         TileLoader {
37
         TileLoader {
38
             client: None,
38
             client: None,
39
             join_handle: thread::spawn(move || Self::work(&request_rx, &result_tx, notice_func, use_network)),
39
             join_handle: thread::spawn(move || Self::work(&request_rx, &result_tx, notice_func, use_network)),
40
-            request_tx: request_tx,
41
-            result_rx: result_rx,
40
+            request_tx,
41
+            result_rx,
42
             pending: HashSet::new(),
42
             pending: HashSet::new(),
43
-            use_network: use_network,
43
+            use_network,
44
         }
44
         }
45
     }
45
     }
46
 
46
 
225
             if let Some(url) = source.remote_tile_url(tile_coord) {
225
             if let Some(url) = source.remote_tile_url(tile_coord) {
226
                 if self.request_tx.send(LoaderMessage::GetTile(
226
                 if self.request_tx.send(LoaderMessage::GetTile(
227
                         TileRequest {
227
                         TileRequest {
228
-                            tile: tile,
229
-                            url: url,
228
+                            tile,
229
+                            url,
230
                             path: source.local_tile_path(tile_coord),
230
                             path: source.local_tile_path(tile_coord),
231
-                            write_to_file: write_to_file,
231
+                            write_to_file,
232
                         }
232
                         }
233
                     )).is_ok()
233
                     )).is_ok()
234
                 {
234
                 {

+ 4
- 4
src/tile_source.rs View File

27
         max_zoom: u32,
27
         max_zoom: u32,
28
     ) -> Self {
28
     ) -> Self {
29
         TileSource {
29
         TileSource {
30
-            id: id,
30
+            id,
31
             url_template: url_template.into(),
31
             url_template: url_template.into(),
32
             directory: directory.into(),
32
             directory: directory.into(),
33
-            extension: extension,
34
-            min_zoom: min_zoom,
35
-            max_zoom: max_zoom,
33
+            extension,
34
+            min_zoom,
35
+            max_zoom,
36
         }
36
         }
37
     }
37
     }
38
 
38