Public feed
#727339
local circle_cache = {}
local offsetcircle_cache = {}
local function _GetCircle( cx, cy, radius, seg )
local key = radius .. "/" .. seg
local key2 = "(" .. cx .. "," .. cy .. ") " .. key
-- did we already calculate the offset of this type of circle?
if offsetcircle_cache[key2] ~= nil then return offsetcircle_cache[key2] end
-- did we already calculate this type of circle?
local c = nil
if circle_cache[key] ~= nil then
c = circle_cache[key]
else
c = {}
-- calculate this type of circle.
local radsperseg = math.rad( 360 / seg )
for i = seg, 1, -1 do
local r = radsperseg * i - 1
table.insert( c, { x = math.sin( r ) * radius, y = math.cos( r ) * radius } )
end
-- cache it for later
circle_cache[key] = c
end
local co = {}
-- offset the circle
for i, v in ipairs( c ) do
co[i] = {}
co[i].x = v.x + cx
co[i].y = v.y + cy
end
-- cache it
offsetcircle_cache[key2] = co
return co
end
local function _DrawCircle( cx, cy, r, seg )
local c = _GetCircle( cx, cy, r, seg )
surface.DrawPoly( c )
end