mbostock/d3 — Issue #438: d3.geom.voronoi fails with N=2
Author: mbostock
Created: 2012-01-12 16:23:18+00:00
State: open
Labels: bug

"""
I've been playing around with the voronoi implementation and found
that it has a bug (well at least IMHO). The problem arises the case
when the number of sites is two *and* you want to clip the cells.
Context, the documentation at https://github.com/mbostock/d3/wiki/Voronoi-Geom#wiki-voronoi
states that when you want clipped cells, you have to post process the
results using polygon.clip. However, when you pass only two sites to
the voronoi function, the return value will basically be two lines
(instead of closed polygons). Using polygon.clip on a line has
undefined results. This whole behavior is demonstrated here:
https://gist.github.com/3cf58c5609be64db8c9f (Tried to make a
bl.ocks.org out of it but that didn't work for me).
I do understand that clipping is not a default action in the voronoi
implementation for performance reasons. However, clipping should work
for all results of a voronoi tessalation. A possible solution would be
to add an extra vertex to all polygons, resulting from a call to
voronoi, which have only two vertices. I'm not sure if adding one
vertex is enough though as this might result into missing corners in
due to the clip in some cases.
"""