From 4c4b57dc24bc36b3091931c9dcc36f6b1894a017 Mon Sep 17 00:00:00 2001 From: Arne Dußin Date: Fri, 27 Nov 2020 22:55:00 +0100 Subject: Change to f64 as the preferred floating point number --- src/grid.rs | 38 +++++++++----------------------------- 1 file changed, 9 insertions(+), 29 deletions(-) (limited to 'src/grid.rs') diff --git a/src/grid.rs b/src/grid.rs index 72a849a..c885f19 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -4,7 +4,7 @@ use raylib::drawing::RaylibDraw; use raylib::ffi::Color; /// The internal grid length which will be used to snap things to it. -pub const SNAP_SIZE: f32 = 0.5; +pub const SNAP_SIZE: f64 = 0.5; pub const LINE_COLOUR: Color = Color { r: 255, @@ -15,7 +15,7 @@ pub const LINE_COLOUR: Color = Color { /// Snap a vector to the grid with the factor being the sub-grid accuracy. For instance, 0.5 will /// snap to half a grid cell, while 2.0 would snap to every second grid cell -pub fn snap_to_grid(mut vec: Vec2, snap_fraction: f32) -> Vec2 { +pub fn snap_to_grid(mut vec: Vec2, snap_fraction: f64) -> Vec2 { vec.x = math::round(vec.x, snap_fraction); vec.y = math::round(vec.y, snap_fraction); @@ -35,37 +35,17 @@ 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 { + // Draw the row lines. Add back the subpixels to the translation + let mut line_y: f64 = translation_y_px as f64 + + (transform.translation_px().y - transform.translation_px().y as i32 as f64); + while line_y <= screen_height as f64 { 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 { + let mut line_x: f64 = translation_x_px as f64 + + (transform.translation_px().x - transform.translation_px().x as i32 as f64); + while line_x <= screen_width as f64 { rld.draw_line(line_x as i32, 0, line_x as i32, screen_height, LINE_COLOUR); line_x += transform.pixels_per_m(); } -- cgit v1.2.3-70-g09d2