Centered grid

This commit is contained in:
Alexey 2025-10-24 12:52:33 +03:00
commit 71f98fd831
3 changed files with 8 additions and 5 deletions

View file

@ -9,7 +9,7 @@ GridPoint = Point
---@return Point
function GridPoint:absolute()
return Point:new(
self.x * Config.cellSize,
self.x * Config.cellSize + Config.gridOffset,
self.y * Config.cellSize
)
end
@ -17,7 +17,7 @@ end
-- Same as coords, but converted to global coords
---@return number, number
function GridPoint:globalCoords()
return self.x * Config.cellSize - Config.cellSize / 2,
return self.x * Config.cellSize - Config.cellSize / 2 + Config.gridOffset,
self.y * Config.cellSize - Config.cellSize / 2
end
@ -25,7 +25,7 @@ end
---@param point Point
---@return GridPoint
function GridPoint.snapCoords( point )
local x = math.ceil( point.x / Config.cellSize )
local x = math.ceil( (point.x - Config.gridOffset) / Config.cellSize )
local y = math.ceil( point.y / Config.cellSize )
return GridPoint:new( x, y )
end