math for 2D rectangles in Lua