-- viewport
v = {x=0, y=0, w=Safe_width, h=Safe_height, zoom=1.0}
f,s = nil -- ids of first and second touches
start, curr = {}, {} -- coords of touches
initzoom = nil
initpos = nil -- for panning
function centroid(a, b)
return{x=(a.x+b.x)/2, y=(a.y+b.y)/2}
end
function vx(sx) return scale(sx-v.x) end
function vy(sy) return scale(sy-v.y) end
function sx(vx) return v.x + iscale(vx) end
function sy(vy) return v.y + iscale(vy) end
function scale(d) return d*v.zoom end
function iscale(d) return d/v.zoom end
function dist(p1, p2)
return ((p2.x-p1.x)^2 + (p2.y-p1.y)^2) ^ 0.5
end