diff options
Diffstat (limited to 'src/grid.rs')
| -rw-r--r-- | src/grid.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/grid.rs b/src/grid.rs index d5fac6d..ecc59c3 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -1,3 +1,4 @@ +use crate::math::{self, Vec2}; use crate::transform::Transform; use raylib::drawing::RaylibDraw; use raylib::ffi::Color; @@ -9,6 +10,15 @@ pub const LINE_COLOUR: Color = Color { a: 75, }; +/// 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<f32>, snap_fraction: f32) -> Vec2<f32> { + vec.x = math::round(vec.x, snap_fraction); + vec.y = math::round(vec.y, snap_fraction); + + vec +} + /// Draw an infinite grid that can be moved around on the screen and zoomed in and out of. pub fn draw_grid<D>(rld: &mut D, screen_width: i32, screen_height: i32, transform: &Transform) where |
