mbostock/d3 — Issue #443: Incoherent behavior of polygon methods
Author: bbroeksema
Created: 2012-01-16 15:50:46+00:00
State: open

I noticed that the behavior of the clip and centroid methods of d3.geom.polygon is incoherent. The former, clip, does not work correctly when the passed polygon is a closed polygon, i.e. when the last element is the same as the first element. However, the latter, centroid, does not work correctly when being passed an open polygon. It took me some time to figure out why my code didn't behave as expected due to this inconsistency. I'd suggest either one of these options:

1) Make both methods rely on either closed or open polygons (and clearly state what is expected in the documentation)
2) Make both methods work with both closed and open polygons. Though this would give a performance penalty as you'd need to do the checking and addition/removal of the last element.

Consequently, methods returning a d3.geom.polygon should be fixed to have the correct behavior. (I ran into this with d3.geom.voronoi which returns open polygons).