All luals findings solved
This commit is contained in:
+40
-17
@@ -22,7 +22,7 @@ do -- INIT UTIL
|
||||
end
|
||||
|
||||
---comment
|
||||
---@param table any
|
||||
---@param table table<any, any>
|
||||
---@return number
|
||||
function UTIL.tableLength(table)
|
||||
if table == nil then return 0 end
|
||||
@@ -35,23 +35,34 @@ do -- INIT UTIL
|
||||
---@param orig table
|
||||
---@return table copy
|
||||
function UTIL.deepCopyTable(orig)
|
||||
local orig_type = type(orig)
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
copy = {}
|
||||
for orig_key, orig_value in next, orig, nil do
|
||||
copy[UTIL.deepCopyTable(orig_key)] = UTIL.deepCopyTable(orig_value)
|
||||
|
||||
---@param original any
|
||||
---@return any
|
||||
local function deepCopy(original)
|
||||
local orig_type = type(original)
|
||||
---@type any
|
||||
local copy
|
||||
if orig_type == 'table' then
|
||||
original = original --[[@as table<any, any>]]
|
||||
copy = {} --[[@as table<any, any>]]
|
||||
for orig_key, orig_value in pairs(original) do
|
||||
local copiedKey = deepCopy(orig_key) --[[@as any]]
|
||||
copy[copiedKey] = deepCopy(orig_value)
|
||||
end
|
||||
setmetatable(copy, deepCopy(getmetatable(original)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = original --[[@as any]]
|
||||
end
|
||||
setmetatable(copy, UTIL.deepCopyTable(getmetatable(orig)))
|
||||
else -- number, string, boolean, etc
|
||||
copy = orig
|
||||
return copy
|
||||
end
|
||||
return copy
|
||||
|
||||
return deepCopy(orig)
|
||||
end
|
||||
|
||||
---Gets a random from the list
|
||||
---@param list Array
|
||||
---@return any @random element from the list
|
||||
---@generic T
|
||||
---@param list Array<T>
|
||||
---@return T @random element from the list
|
||||
function UTIL.randomFromList(list)
|
||||
local max = #list
|
||||
|
||||
@@ -65,11 +76,13 @@ do -- INIT UTIL
|
||||
return list[random]
|
||||
end
|
||||
|
||||
---@param list Array
|
||||
---@generic T
|
||||
---@param list Array<T>
|
||||
---@param start number start
|
||||
---@param n number length
|
||||
---@return Array
|
||||
---@return Array<T>
|
||||
function UTIL.sublist(list, start, n)
|
||||
---@type table<number, any>
|
||||
local result = {}
|
||||
for i = start, n do
|
||||
result[#result + 1] = list[i]
|
||||
@@ -90,9 +103,10 @@ do -- INIT UTIL
|
||||
end
|
||||
|
||||
local function table_print(tt, indent, done)
|
||||
done = done or {}
|
||||
done = done or {} --[[@as table<any, boolean>]]
|
||||
indent = indent or 0
|
||||
if type(tt) == "table" then
|
||||
tt = tt --[[@as table<any, any>]]
|
||||
local sb = {}
|
||||
for key, value in pairs(tt) do
|
||||
table.insert(sb, string.rep(" ", indent)) -- indent it
|
||||
@@ -146,7 +160,7 @@ do -- INIT UTIL
|
||||
|
||||
---comment
|
||||
---@param str string
|
||||
---@param findableTable table
|
||||
---@param findableTable table<any,any>
|
||||
---@return boolean
|
||||
UTIL.startswithAny = function(str, findableTable)
|
||||
for _, value in pairs(findableTable) do
|
||||
@@ -244,6 +258,7 @@ do -- INIT UTIL
|
||||
---@return boolean
|
||||
local function isInComplexPolygon(polygon, x, y)
|
||||
---@param poly Array<Vec2> of pairs { x, y }
|
||||
---@return Array<{ x1: number, z1: number, x2: number, z2: number }>
|
||||
local function getEdges(poly)
|
||||
local result = {}
|
||||
for i = 1, #poly do
|
||||
@@ -280,6 +295,7 @@ do -- INIT UTIL
|
||||
|
||||
---@param point Vec3
|
||||
---@param zone SpearheadTriggerZone
|
||||
---@return boolean
|
||||
function UTIL.is3dPointInZone(point, zone)
|
||||
if zone.zone_type == "Polygon" and zone.verts then
|
||||
if UTIL.IsPointInPolygon(zone.verts, point.x, point.z) == true then
|
||||
@@ -296,6 +312,7 @@ do -- INIT UTIL
|
||||
|
||||
---@param point Vec2
|
||||
---@param zone SpearheadTriggerZone
|
||||
---@return boolean
|
||||
function UTIL.is2dPointInZone(point, zone)
|
||||
if zone.zone_type == "Polygon" and zone.verts then
|
||||
if UTIL.IsPointInPolygon(zone.verts, point.x, point.y) == true then
|
||||
@@ -447,6 +464,8 @@ do -- INIT UTIL
|
||||
end
|
||||
|
||||
---@param points Array<Vec2>
|
||||
---@param meters number
|
||||
---@return Array<Vec2>
|
||||
function UTIL.enlargeConvexHull(points, meters)
|
||||
if points == nil or #points == 0 then
|
||||
return {}
|
||||
@@ -524,6 +543,10 @@ function UTIL.GetTangentHullPointsFromOrigin(hull, origin)
|
||||
return {}
|
||||
end
|
||||
|
||||
---@param a Vec2
|
||||
---@param b Vec2
|
||||
---@param c Vec2
|
||||
---@return number
|
||||
local function orientation(a, b, c)
|
||||
-- Returns >0 if c is to the left of ab, <0 if to the right, 0 if colinear
|
||||
return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)
|
||||
|
||||
Reference in New Issue
Block a user