local addonName, LRH = ...

LRH = LRH or {}
LRH.Utils = LRH.Utils or {}

local U = LRH.Utils

function U.Clamp(v, lo, hi)
    if v < lo then return lo end
    if v > hi then return hi end
    return v
end

function U.EnsureColorTable(t, dr, dg, db)
    if type(t) ~= "table" then return { r = dr, g = dg, b = db } end
    if type(t.r) ~= "number" or type(t.g) ~= "number" or type(t.b) ~= "number" then
        return { r = dr, g = dg, b = db }
    end
    return t
end

function U.PxToUI(px)
    local s = UIParent:GetEffectiveScale() or 1
    return px / s
end

function U.SnapPx(v, snap)
    snap = snap or 16
    return math.floor(v / snap + 0.5) * snap
end

-- Rendering Fix für skalierende Texturen
function U.FixTexture(tex)
    if not tex then return end
    if tex.SetSnapToPixelGrid then
        tex:SetSnapToPixelGrid(false)
    end
    if tex.SetTexelSnappingBias then
        tex:SetTexelSnappingBias(0)
    end
end