Skip to content

Commit

Permalink
Avoid math.sqrt and #table
Browse files Browse the repository at this point in the history
  • Loading branch information
boatbomber committed Nov 14, 2021
1 parent 13fd1d7 commit 4297825
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions src/GuiPool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@ local module = {}
local OFF_SCREEN = UDim2.fromOffset(0, 3000)

function module.new(original: GuiObject, initSize: number?)
initSize = initSize or 50

local Pool = {
_Available = table.create(initSize or 50),
_Available = table.create(initSize),
_Source = original:Clone(),
_Index = initSize,
}

for i = 1, initSize or 50 do
for i = 1, initSize do
Pool._Available[i] = Pool._Source:Clone()
end

function Pool:Get()
local index = #self._Available
if index > 0 then
local object = self._Available[index]
table.remove(self._Available, index)
if self._Index > 0 then
local object = self._Available[self._Index]
table.remove(self._Available, self._Index)
self._Index -= 1
return object
end

Expand All @@ -26,6 +29,7 @@ function module.new(original: GuiObject, initSize: number?)
function Pool:Return(object: GuiObject)
object.Position = OFF_SCREEN
table.insert(self._Available, object)
self._Index += 1
end

return Pool
Expand Down
6 changes: 3 additions & 3 deletions src/Util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ function Util.DeltaRGB(a: Color3, b: Color3)
local l1, a1, b1 = Util.RGBtoLAB(a)
local l2, a2, b2 = Util.RGBtoLAB(b)

local delta = math.sqrt((l2 - l1) ^ 2 + (a2 - a1) ^ 2 + (b2 - b1) ^ 2)
if delta < 30 then
local delta = (l2 - l1) ^ 2 + (a2 - a1) ^ 2 + (b2 - b1) ^ 2
if delta < 900 then
return 0.03
else
return delta / 200
return delta / 40000
end
end

Expand Down

0 comments on commit 4297825

Please sign in to comment.