block by mbostock ece50c027bdf8cc20003a17d93e4f60e

Polygon Clipping III

Full Screen

If your clip polygon is more complicated than an axis-aligned rectangle, projection.clipExtent as shown previously won’t be sufficient. This example implements Sutherland–Hodgman clipping, which works for any convex clip polygon. Note, however, that this implementation only clips exterior polygon rings; you’ll need to do some additional work to handle any holes.

index.html

d3-polygon-clip.js