mbostock/d3 — pull request #1549 by jasondavies (2013-09-26 15:53:08+00:00)
Title: Fix clipping bug for complex polygons.

Intersection points are sorted along the clipping region edge relative
to a particular point. In the case of antimeridian clipping, this point
is the South pole. Previously, the first intersection was assumed to be
an entering intersection, but this is not always the case.

The fix is to see whether the clip region start point (the point
relative to which sorting occurs) is inside or outside the polygon being
drawn. If it is inside, then the first intersection point must be
outside, and so forth.

The same applies to d3.geo.clipExtent. Provision was already made for
this, but this has now been optimised to use a single point instead of
picking one of the four corners.

Another optimisation was to reuse this clip region start point to
determine whether to interpolate all the way around the clip region
edge. Previously, this was done by testing an arbitrary point in the
clip region.

The above fix seemed to have broken one of the tests, and this has been
fixed by modifying the point-in-polygon routine slightly to handle
points that might lie exactly on the polygon edge.

Finally, I noticed a regression with the recent clipExtent fix, where a
polygon incorrectly being marked as “clean” (no intersections) on a
per-ring instead of per-polygon basis.