diff options
| author | Arne Dußin | 2020-11-06 00:53:46 +0100 |
|---|---|---|
| committer | Arne Dußin | 2020-11-06 00:53:46 +0100 |
| commit | 625d00bb0e9a374e7ecf4b91fde599307199f3b6 (patch) | |
| tree | 3dfdcc544c5b29f1f49d09a374d129bd825ade56 /src/grid.rs | |
| parent | 6d5db404416b93d22438efd45c7df7be2cc67d11 (diff) | |
| download | graf_karto-625d00bb0e9a374e7ecf4b91fde599307199f3b6.tar.gz graf_karto-625d00bb0e9a374e7ecf4b91fde599307199f3b6.zip | |
Add icon tool
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 |
