mirror of
https://github.com/vrld/HC.git
synced 2024-11-18 12:54:23 +00:00
Faster Polygon:unpack()
This commit is contained in:
parent
bf95f1e5fc
commit
c3011ad841
13
polygon.lua
13
polygon.lua
@ -156,15 +156,14 @@ end
|
|||||||
local newPolygon
|
local newPolygon
|
||||||
|
|
||||||
|
|
||||||
-- unpack vertex coordinates, i.e. {x=p, y=q}, ... -> p,q, ...
|
|
||||||
local function unpackHelper(v, ...)
|
|
||||||
if not v then return end
|
|
||||||
return v.x,v.y,unpackHelper(...)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- return vertices as x1,y1,x2,y2, ..., xn,yn
|
-- return vertices as x1,y1,x2,y2, ..., xn,yn
|
||||||
function Polygon:unpack()
|
function Polygon:unpack()
|
||||||
return unpackHelper( unpack(self.vertices) )
|
local v = {}
|
||||||
|
for i = 1,#self.vertices do
|
||||||
|
v[2*i-1] = self.vertices[i].x
|
||||||
|
v[2*i] = self.vertices[i].y
|
||||||
|
end
|
||||||
|
return unpack(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- deep copy of the polygon
|
-- deep copy of the polygon
|
||||||
|
Loading…
Reference in New Issue
Block a user