Tercio@58: Tercio@58: Tercio@58: local DF = _G ["DetailsFramework"] Tercio@58: if (not DF or not DetailsFrameworkCanLoad) then Tercio@58: return Tercio@58: end Tercio@58: Tercio@58: local UnitExists = UnitExists Tercio@58: local atan2 = math.atan2 Tercio@58: local pi = math.pi Tercio@58: local abs = math.abs Tercio@58: Tercio@58: SMALL_FLOAT = 0.000001 Tercio@58: Tercio@58: --find distance between two players Tercio@58: function DF:GetDistance_Unit (unit1, unit2) Tercio@58: if (UnitExists (unit1) and UnitExists (unit2)) then Tercio@58: local u1X, u1Y = UnitPosition (unit1) Tercio@58: local u2X, u2Y = UnitPosition (unit2) Tercio@58: Tercio@58: local dX = u2X - u1X Tercio@58: local dY = u2Y - u1Y Tercio@58: Tercio@58: return ((dX*dX) + (dY*dY)) ^ .5 Tercio@58: end Tercio@58: return 0 Tercio@58: end Tercio@58: Tercio@58: --find distance between two points Tercio@58: function DF:GetDistance_Point (x1, y1, x2, y2) Tercio@58: local dx = x2 - x1 Tercio@58: local dy = y2 - y1 Tercio@58: return ((dx * dx) + (dy * dy)) ^ .5 Tercio@58: end Tercio@58: Tercio@58: --find a rotation for an object from a point to another point Tercio@58: function DF:FindLookAtRotation (x1, y1, x2, y2) Tercio@58: return atan2 (y2 - y1, x2 - x1) + pi Tercio@58: end Tercio@58: Tercio@58: --find the value scale between two given values. e.g: value of 500 in a range 0-100 result in 10 in a scale for 0-10 Tercio@58: function DF:MapRangeClamped (inputX, inputY, outputX, outputY, value) Tercio@58: return DF:GetRangeValue (outputX, outputY, Clamp (DF:GetRangePercent (inputX, inputY, value), 0, 1)) Tercio@58: end Tercio@58: Tercio@58: --find the value scale between two given values. e.g: value of 75 in a range 0-100 result in 7.5 in a scale for 0-10 Tercio@58: function DF:MapRangeUnclamped (inputX, inputY, outputX, outputY, value) Tercio@58: return DF:GetRangeValue (outputX, outputY, DF:GetRangePercent (inputX, inputY, value)) Tercio@58: end Tercio@58: Tercio@58: --find the normalized percent of the value in the range. e.g range of 200-400 and a value of 250 result in 0.25 Tercio@58: function DF:GetRangePercent (minValue, maxValue, value) Tercio@58: return (value - minValue) / (maxValue - minValue) Tercio@58: end Tercio@58: Tercio@58: --find the value in the range given from a normalized percent. e.g range of 200-400 and a percent of 0.8 result in 360 Tercio@58: function DF:GetRangeValue (minValue, maxValue, percent) Tercio@58: return Lerp (minValue, maxValue, percent) Tercio@58: end Tercio@58: Tercio@58: --dot product of two 2D Vectors Tercio@58: function DF:GetDotProduct (value1, value2) Tercio@58: return (value1.x * value2.x) + (value1.y * value2.y) Tercio@58: end Tercio@58: Tercio@58: --normalized value 0-1 result in the value on the range given, e.g 200-400 range with a value of .5 result in 300 Tercio@58: function DF:LerpNorm (minValue, maxValue, value) Tercio@58: return (minValue + value * (maxValue - minValue)) Tercio@58: end Tercio@58: Tercio@58: --change the color by the deltaTime Tercio@58: function DF:LerpLinearColor (deltaTime, interpSpeed, r1, g1, b1, r2, g2, b2) Tercio@58: deltaTime = deltaTime * interpSpeed Tercio@58: local r = r1 + (r2 - r1) * deltaTime Tercio@58: local g = g1 + (g2 - g1) * deltaTime Tercio@58: local b = b1 + (b2 - b1) * deltaTime Tercio@58: return r, g, b Tercio@58: end Tercio@58: Tercio@58: --check if a number is near another number by a tolerance Tercio@58: function DF:IsNearlyEqual (value1, value2, tolerance) Tercio@58: tolerance = tolerance or SMALL_FLOAT Tercio@58: return abs (value1 - value2) <= tolerance Tercio@58: end Tercio@58: Tercio@58: --check if a number is near zero Tercio@58: function DF:IsNearlyZero (value, tolerance) Tercio@58: tolerance = tolerance or SMALL_FLOAT Tercio@58: return abs (value) <= tolerance Tercio@58: end Tercio@58: Tercio@58: --check if a number is within a two other numbers, if isInclusive is true, it'll include the max value Tercio@58: function DF:IsWithin (minValue, maxValue, value, isInclusive) Tercio@58: if (isInclusive) then Tercio@58: return ((value >= minValue) and (value <= maxValue)) Tercio@58: else Tercio@58: return ((value >= minValue) and (value < maxValue)) Tercio@58: end Tercio@58: end Tercio@58: Tercio@58: --dont allow a number ot be lower or bigger than a certain range Tercio@58: function DF:Clamp (minValue, maxValue, value) Tercio@58: return value < minValue and minValue or value < maxValue and value or maxValue Tercio@58: end Tercio@58: Tercio@58: function DF:ScaleBack () Tercio@58: Tercio@58: end