Kaynağa Gözat

Move TextureRect to coord.rs

Johannes Hofmann 8 yıl önce
ebeveyn
işleme
129f9c85fe
2 değiştirilmiş dosya ile 32 ekleme ve 32 silme
  1. 31
    0
      src/coord.rs
  2. 1
    32
      src/tile_cache_gl.rs

+ 31
- 0
src/coord.rs Dosyayı Görüntüle

@@ -117,6 +117,37 @@ impl ScreenRect {
117 117
     }
118 118
 }
119 119
 
120
+#[derive(Copy, Clone, Debug)]
121
+pub struct TextureRect {
122
+    pub x1: f64,
123
+    pub y1: f64,
124
+    pub x2: f64,
125
+    pub y2: f64,
126
+}
127
+
128
+impl TextureRect {
129
+    pub fn inset(self, margin_x: f64, margin_y: f64) -> TextureRect {
130
+        TextureRect {
131
+            x1: self.x1 + margin_x,
132
+            y1: self.y1 + margin_y,
133
+            x2: self.x2 - margin_x,
134
+            y2: self.y2 - margin_y,
135
+        }
136
+    }
137
+
138
+    pub fn subdivide(&self, sub_tile: &SubTileCoord) -> TextureRect {
139
+        let scale = 1.0 / f64::from(sub_tile.size);
140
+        let w = (self.x2 - self.x1) * scale;
141
+        let h = (self.y2 - self.y1) * scale;
142
+        TextureRect {
143
+            x1: self.x1 + f64::from(sub_tile.x) * w,
144
+            y1: self.y1 + f64::from(sub_tile.y) * h,
145
+            x2: self.x1 + f64::from(sub_tile.x + 1) * w,
146
+            y2: self.y1 + f64::from(sub_tile.y + 1) * h,
147
+        }
148
+    }
149
+}
150
+
120 151
 #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
121 152
 pub struct SubTileCoord {
122 153
     pub size: u32,

+ 1
- 32
src/tile_cache_gl.rs Dosyayı Görüntüle

@@ -1,4 +1,4 @@
1
-use coord::{ScreenRect, SubTileCoord, TileCoord};
1
+use coord::{ScreenRect, SubTileCoord, TileCoord, TextureRect};
2 2
 use linked_hash_map::LinkedHashMap;
3 3
 use map_view::VisibleTile;
4 4
 use std::collections::HashMap;
@@ -8,37 +8,6 @@ use tile::Tile;
8 8
 use tile_cache::TileCache;
9 9
 use tile_source::TileSource;
10 10
 
11
-#[derive(Copy, Clone, Debug)]
12
-pub struct TextureRect {
13
-    pub x1: f64,
14
-    pub y1: f64,
15
-    pub x2: f64,
16
-    pub y2: f64,
17
-}
18
-
19
-impl TextureRect {
20
-    pub fn inset(self, margin_x: f64, margin_y: f64) -> TextureRect {
21
-        TextureRect {
22
-            x1: self.x1 + margin_x,
23
-            y1: self.y1 + margin_y,
24
-            x2: self.x2 - margin_x,
25
-            y2: self.y2 - margin_y,
26
-        }
27
-    }
28
-
29
-    pub fn subdivide(&self, sub_tile: &SubTileCoord) -> TextureRect {
30
-        let scale = 1.0 / f64::from(sub_tile.size);
31
-        let w = (self.x2 - self.x1) * scale;
32
-        let h = (self.y2 - self.y1) * scale;
33
-        TextureRect {
34
-            x1: self.x1 + f64::from(sub_tile.x) * w,
35
-            y1: self.y1 + f64::from(sub_tile.y) * h,
36
-            x2: self.x1 + f64::from(sub_tile.x + 1) * w,
37
-            y2: self.y1 + f64::from(sub_tile.y + 1) * h,
38
-        }
39
-    }
40
-}
41
-
42 11
 #[derive(Clone, Debug)]
43 12
 pub struct TexturedVisibleTile {
44 13
     pub screen_rect: ScreenRect,