Centered grid
This commit is contained in:
parent
e04b8e523e
commit
71f98fd831
3 changed files with 8 additions and 5 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue