aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArne Dußin2020-11-01 20:48:05 +0100
committerArne Dußin2020-11-01 20:48:05 +0100
commit678406b21c14af2d1f1bd955368637f83f049011 (patch)
treed9d9e46c61176fb6542aa4d4550f66877078c830 /src
parent09ffb11f07e964fc1232a49047746afa3b92dd81 (diff)
downloadgraf_karto-678406b21c14af2d1f1bd955368637f83f049011.tar.gz
graf_karto-678406b21c14af2d1f1bd955368637f83f049011.zip
Make zoom-levels whole numbers to combat round-err
The grid was offset at certain zoom-levels and lower positions, so for now I just made only whole zoom-levels possible, which removes the offset. However, I consider this a band-aid-solution. Maybe change from f32 to f64 and try out if that fixes it? Otherwise, a different algorithm might work.
Diffstat (limited to 'src')
-rw-r--r--src/grid.rs23
-rw-r--r--src/transform.rs7
2 files changed, 28 insertions, 2 deletions
diff --git a/src/grid.rs b/src/grid.rs
index 1ec49a3..d5fac6d 100644
--- a/src/grid.rs
+++ b/src/grid.rs
@@ -22,13 +22,34 @@ where
let translation_y_px: i32 =
transform.translation_px().y as i32 % transform.pixels_per_m() as i32;
+ /*
+ let mut row = 0;
+ loop {
+ let line_y = translation_y_px + (transform.pixels_per_m() * row as f32) as i32;
+ if line_y > screen_height {
+ break;
+ }
+ rld.draw_line(0, line_y as i32, screen_width, line_y as i32, LINE_COLOUR);
+ row += 1;
+ }
+
+ let mut column = 0;
+ loop {
+ let line_x = translation_x_px + (transform.pixels_per_m() * column as f32) as i32;
+ if line_x > screen_width {
+ break;
+ }
+ rld.draw_line(line_x as i32, 0, line_x as i32, screen_height, LINE_COLOUR);
+ column += 1;
+ }
+ */
+
// Draw the row lines.
let mut line_y: f32 = translation_y_px as f32;
while line_y <= screen_height as f32 {
rld.draw_line(0, line_y as i32, screen_width, line_y as i32, LINE_COLOUR);
line_y += transform.pixels_per_m();
}
-
// Draw the column lines.
let mut line_x: f32 = translation_x_px as f32;
while line_x <= screen_width as f32 {
diff --git a/src/transform.rs b/src/transform.rs
index f44888b..ca359f0 100644
--- a/src/transform.rs
+++ b/src/transform.rs
@@ -6,7 +6,7 @@
use crate::math::{Rect, Vec2};
const STANDARD_PIXELS_PER_M: f32 = 64.;
-const MIN_PIXELS_PER_M: f32 = 0.5;
+const MIN_PIXELS_PER_M: f32 = 5.;
const MAX_PIXELS_PER_M: f32 = 10_000.;
pub struct Transform {
@@ -82,6 +82,11 @@ impl Transform {
* pass the standard zoom factor.
*/
fn normalise_zoom(&mut self) {
+ self.pixels_per_m = self.pixels_per_m as u32 as f32;
+ if self.pixels_per_m < MIN_PIXELS_PER_M {
+ self.pixels_per_m = MIN_PIXELS_PER_M;
+ }
+
if self.pixels_per_m > STANDARD_PIXELS_PER_M - 5.
&& self.pixels_per_m < STANDARD_PIXELS_PER_M + 5.
{