local ____exports = {}
local isValidGridPositionNormal, isValidGridPositionLRoom
local ____LRoomShapeToRectangles = require("objects.LRoomShapeToRectangles")
local L_ROOM_SHAPE_TO_RECTANGLES = ____LRoomShapeToRectangles.L_ROOM_SHAPE_TO_RECTANGLES
local ____math = require("functions.math")
local inRectangle = ____math.inRectangle
local ____roomShape = require("functions.roomShape")
local getRoomShapeBottomRightPosition = ____roomShape.getRoomShapeBottomRightPosition
local getRoomShapeTopLeftPosition = ____roomShape.getRoomShapeTopLeftPosition
local getRoomShapeWidth = ____roomShape.getRoomShapeWidth
local isLRoomShape = ____roomShape.isLRoomShape
--- Helper function to convert a grid position `Vector` to a world position `Vector`.
-- 
-- For example, the coordinates of (0, 0) are equal to `Vector(80, 160)`.
function ____exports.gridPositionToWorldPosition(self, gridPosition)
    local x = (gridPosition.X + 2) * 40
    local y = (gridPosition.Y + 4) * 40
    return Vector(x, y)
end
function isValidGridPositionNormal(self, gridPosition, roomShape)
    local topLeft = getRoomShapeTopLeftPosition(nil, roomShape)
    local bottomRight = getRoomShapeBottomRightPosition(nil, roomShape)
    return inRectangle(nil, gridPosition, topLeft, bottomRight)
end
function isValidGridPositionLRoom(self, gridPosition, roomShape)
    local rectangles = L_ROOM_SHAPE_TO_RECTANGLES[roomShape]
    if rectangles == nil then
        return false
    end
    local verticalTopLeft = rectangles.verticalTopLeft
    local verticalBottomRight = rectangles.verticalBottomRight
    local horizontalTopLeft = rectangles.horizontalTopLeft
    local horizontalBottomRight = rectangles.horizontalBottomRight
    return inRectangle(nil, gridPosition, verticalTopLeft, verticalBottomRight) or inRectangle(nil, gridPosition, horizontalTopLeft, horizontalBottomRight)
end
--- Helper function to convert grid coordinates to a world position `Vector`.
-- 
-- For example, the coordinates of (0, 0) are equal to `Vector(80, 160)`.
function ____exports.gridCoordinatesToWorldPosition(self, x, y)
    local gridPosition = Vector(x, y)
    return ____exports.gridPositionToWorldPosition(nil, gridPosition)
end
--- Helper function to convert a grid index to a grid position.
-- 
-- For example, in a 1x1 room, grid index 0 is equal to "Vector(-1, -1) and grid index 16 is equal
-- to "Vector(0, 0)".
function ____exports.gridIndexToGridPosition(self, gridIndex, roomShape)
    local gridWidth = getRoomShapeWidth(nil, roomShape)
    local x = gridIndex % gridWidth - 1
    local y = math.floor(gridIndex / gridWidth) - 1
    return Vector(x, y)
end
--- Test if a grid position is actually in the given `RoomShape`.
-- 
-- In this context, the grid position of the top-left wall is "Vector(-1, -1)".
function ____exports.isValidGridPosition(self, gridPosition, roomShape)
    local ____isLRoomShape_result_0
    if isLRoomShape(nil, roomShape) then
        ____isLRoomShape_result_0 = isValidGridPositionLRoom(nil, gridPosition, roomShape)
    else
        ____isLRoomShape_result_0 = isValidGridPositionNormal(nil, gridPosition, roomShape)
    end
    return ____isLRoomShape_result_0
end
--- Helper function to convert a world position `Vector` to a grid position `Vector`.
-- 
-- In this context, the grid position of the top-left wall is "Vector(-1, -1)".
function ____exports.worldPositionToGridPosition(self, worldPos)
    local x = math.floor(worldPos.X / 40 - 2 + 0.5)
    local y = math.floor(worldPos.Y / 40 - 4 + 0.5)
    return Vector(x, y)
end
--- Helper function to convert a world position `Vector` to a grid position `Vector`.
-- 
-- In this context, the grid position of the top-left wall is "Vector(-1, -1)".
-- 
-- This is similar to the `worldPositionToGridPosition` function, but the values are not rounded.
function ____exports.worldPositionToGridPositionFast(self, worldPos)
    local x = worldPos.X / 40 - 2
    local y = worldPos.Y / 40 - 4
    return Vector(x, y)
end
return ____exports
