Advertisement
kemonologic

ds_grid_trim

Oct 15th, 2020 (edited)
1,141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// @func ds_grid_trim
  2. /// @arg {grid} grid
  3. /// @desc Resizes the grid, trimming empty (non-zero) contiguous rows/columns
  4. // Requires ds_grid_get_bounds
  5.  
  6. enum rect{
  7.     x1,
  8.     y1,
  9.     x2,
  10.     y2
  11. }
  12. var _grid = argument[0];
  13.  
  14. var _dimArr = ds_grid_get_bounds(_grid);
  15. var _trimmedGridW = _dimArr[rect.x2] - _dimArr[rect.x1] + 1;
  16. var _trimmedGridH = _dimArr[rect.y2] - _dimArr[rect.y1] + 1;
  17. var _trimmedGrid = ds_grid_create(_trimmedGridW,_trimmedGridH);
  18.  
  19. ds_grid_set_grid_region(_trimmedGrid,_grid,_dimArr[rect.x1],_dimArr[rect.y1],_dimArr[rect.x2],_dimArr[rect.y2],0,0);
  20. ds_grid_resize(_grid,_trimmedGridW,_trimmedGridH);
  21. ds_grid_clear(_grid,0);
  22. ds_grid_copy(_grid,_trimmedGrid);
  23.  
  24. ds_grid_destroy(_trimmedGrid);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement