From b2a351e67d6dcdc2c1a3d903bc0f110c320d6489 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Sat, 5 Nov 2022 14:03:38 +0100 Subject: [PATCH] UTILS --- Moose Development/Moose/Utilities/Utils.lua | 35 ++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index 2486f6070..214bf8a69 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -740,7 +740,9 @@ function UTILS.RemoveMark(MarkID, Delay) if Delay and Delay>0 then TIMER:New(UTILS.RemoveMark, MarkID):Start(Delay) else - trigger.action.removeMark(MarkID) + if MarkID then + trigger.action.removeMark(MarkID) + end end end @@ -1062,9 +1064,13 @@ end -- @return #number Distance between the vectors. function UTILS.VecDist2D(a, b) + local d = math.huge + + if (not a) or (not b) then return d end + local c={x=b.x-a.x, y=b.y-a.y} - local d=math.sqrt(c.x*c.x+c.y*c.y) + d=math.sqrt(c.x*c.x+c.y*c.y) return d end @@ -1075,10 +1081,15 @@ end -- @param DCS#Vec3 b Vector in 3D with x, y, z components. -- @return #number Distance between the vectors. function UTILS.VecDist3D(a, b) - + + + local d = math.huge + + if (not a) or (not b) then return d end + local c={x=b.x-a.x, y=b.y-a.y, z=b.z-a.z} - local d=math.sqrt(UTILS.VecDot(c, c)) + d=math.sqrt(UTILS.VecDot(c, c)) return d end @@ -2006,6 +2017,22 @@ function UTILS.GenerateLaserCodes() return jtacGeneratedLaserCodes end +--- Ensure the passed object is a table. +-- @param #table Object The object that should be a table. +-- @return #table The object that is a table. Note that if the Object is `#nil` initially, and empty table `{}` is returned. +function UTILS.EnsureTable(Object) + + if Object then + if type(Object)~="table" then + Object={Object} + end + else + Object={} + end + + return Object +end + --- Function to save an object to a file -- @param #string Path The path to use. Use double backslashes \\\\ on Windows filesystems. -- @param #string Filename The name of the file. Existing file will be overwritten.