mbostock/d3 — pull request #336 by jasondavies (2011-10-08 17:06:13+00:00)
Title: Add tests for d3.geom.polygon and fix centroid bug.

d3.geom.polygon(…).area() assumes screen pixel coordinates with (0, 0) at the top left, and y increasing going downwards. This results in a positive area for counterclockwise coordinates. Howver, the default centroid calculation was assuming "usual" Cartesian coordinates with y increasing going upwards, hence the centroid coordinates were incorrectly multiplied by -1.

This fix won't affect d3.geo.path(…).centroid() as it passes a constant to d3.geom.centroid.

This includes a *really* simple test, I'm sure we can flesh these out as time goes on. :)

Also, I wasn't sure if polygon coordinates should end at the start point or not, so I've tested both for now.