An Euler-MacLaurin formula for polygonal sums