Reshape + rotate() + contentToLocal()

Hello. Trying to edit the form in the simulator, moving the red dots. Everything works if you do not change the angle. Please help fix it.

class\_cutBody = {} function class\_cutBody:new(prop) local object = {} setmetatable(object,self) self.\_\_index = self self.g=display.newGroup() self.skin=display.newPolygon(self.g,0,0,prop.shape) self.skin:addEventListener( "touch", self) self.skin.fill={0,1,0} self.skin.s=prop.shape group = prop.group or display.currentStage group:insert(self.g) self.g.x = prop.x or 0 self.g.y = prop.y or 0 --verts self.verts=display.newGroup() self.g:insert(self.verts) for i=1,#self.skin.s/2 do display.newCircle(self.verts,self.skin.s[i\*2-1],self.skin.s[i\*2],4) self.verts[i].fill= {1,0,0} self.verts[i]:addEventListener( "touch", self) self.verts[i].id=i end return object end function class\_cutBody:touch( event ) local target = event.target local id = event.id local phase = event.phase if( phase == "began" ) then display.currentStage:setFocus( target, id ) self.isFocus = true self.iX=target.id\*2-1 self.iY=target.id\*2 elseif( self.isFocus ) then if phase == "moved" then local tempS=self.skin.s tempS[self.iX],tempS[self.iY]=self.g:contentToLocal(event.x,event.y) local xmax, ymax, xmin, ymin = -math.huge, -math.huge, math.huge, math.huge for i=1,#tempS, 2 do xmax, ymax = math.max(xmax, tempS[i]), math.max(ymax, tempS[i+1]) xmin, ymin = math.min(xmin, tempS[i]), math.min(ymin, tempS[i+1]) end width=xmax -xmin height=ymax - ymin cX= .5 \* width cY=.5 \* height local \_tempS={} for i=1,#tempS, 2 do \_tempS[i]=tempS[i]-xmin-cX \_tempS[i+1]=tempS[i+1]-ymin-cY end tempS=\_tempS self.skin:removeSelf() self.skin=display.newPolygon(self.g ,0,0, tempS) self.skin.fill={1,1,1,.3} self.skin.s=tempS self.g.x=event.x-self.skin.s[self.iX] self.g.y=event.y-self.skin.s[self.iY] for i=1,self.verts.numChildren do self.verts[i].x=self.skin.s[i\*2-1] self.verts[i].y=self.skin.s[i\*2] end elseif( phase == "ended" or phase == cancelled ) then display.currentStage:setFocus( target, nil ) self.isFocus = nil end end end hh=class\_cutBody:new({shape={-40,-40, 40,-40, 40,40, -40,40},x=100,y=100}) --!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --hh.g:rotate(45) -- uncomment to see the problem !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!