separate rectangle calculation from drawing