---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by HUAFEI2.
--- DateTime: 2020/6/28 16:06
---

math.tointeger = function (val)
    return math.ceil(val + 0.5)
end

math.isNan = function (x)
    return type(x) == 'number' and x ~= x
end

math.clamp = function (val, min, max)
    if val < min then
        val = min
    end
    if val > max then
        val = max
    end
    return val;
end

local vec3Array = {};
---@return LVec3
function AllocVec3(x,y,z)
    local ret;
    local ln = #vec3Array;
    if ln == 0 then
        ret = LVec3:new();
    else
        ret = vec4Array[ln];
        table.remove(vec4Array, ln);
    end
    ret.x = x or 0;
    ret.y = y or 0;
    ret.z = z or 0;
    return ret;
end

---@param vec3 LVec3
function FreeVec3(vec3)
    table.insert(vec3Array, vec3);
end

local vec4Array = {};
---@returns {LVec4}
function AllocVec4(x,y,z,w)
    local ret;
    local ln = #vec4Array;
    if ln == 0 then
        ret = LVec4:new();
    else
        ret = vec4Array[ln];
        table.remove(vec4Array, ln);
    end
    ret.x = x or 0;
    ret.y = y or 0;
    ret.z = z or 0;
    ret.w = w or 0;
    return ret;
end

---@param vec4 LVec4
function FreeVec4(vec4)
    table.insert(vec4Array, vec4);
end

local quaternionArray = {};
---@return LQuaternion
function AllocQuaternion(x, y, z, w)
    local ret;
    local ln = #quaternionArray;
    if ln == 0 then
        ret = LQuaternion:new();
    else
        ret = quaternionArray[ln];
        table.remove(quaternionArray, ln);
    end
    ret.x = x or 0;
    ret.y = y or 0;
    ret.z = z or 0;
    ret.w = w or 0;
    return ret;
end

---@param quat LQuaternion
function FreeQuaternion(quat)
    table.insert(quaternionArray, quat);
end

local matrixArray = {};
---@return LMatrix
function AllocMatrix()
    local ret;
    local ln = #matrixArray;
    if ln == 0 then
        ret = LMatrix:new();
    else
        ret = matrixArray[ln];
        table.remove(matrixArray, ln);
    end
    return ret;
end

---@param {KMATRIX} mat
function FreeMatrix(mat)
    table.insert(matrixArray, mat);
end
