--- get texture UV
---@param x number y
---@param y number x
---@param frameSizeX number size Frame X
---@param frameSizeY number size Frame Y
---@param sw number size Width
---@param sh number size Height
---@return number, number, number, number
local function getUV(x, y, frameSizeX, frameSizeY, sw, sh)
  return
    x / sw,
    y / sh,
    (x + 1 * frameSizeX) / sw,
    (y + 1 * frameSizeY) / sh
end

--- get uv from quad
---@param quad love.Quad
local function quadToUV(quad)
  local sw, sh = quad:getTextureDimensions()
  local x, y, w, h = quad:getViewport()
  local u, v, nu, nv = getUV(x, y, w, h, sw, sh)
  return u, v, nu, nv
end

--- get uv from image
---@param image love.Image
local function imageToUV(image)
  local u, v, nu, nv = getUV(0, 0, image:getWidth(), image:getHeight(),image:getWidth(), image:getHeight())
  return u, v, nu, nv
end

return {
  getUV = getUV,
  imageToUV = imageToUV,
  quadToUV = quadToUV
}
