From c3011ad84124515026a3f0d4ffad43cd7872da4a Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Sat, 19 May 2012 12:41:25 +0200 Subject: [PATCH] Faster Polygon:unpack() --- polygon.lua | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/polygon.lua b/polygon.lua index 78469e0..f7f6a77 100644 --- a/polygon.lua +++ b/polygon.lua @@ -156,15 +156,14 @@ end 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 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 -- deep copy of the polygon