Viewport clipping of geographic features using D3 version 3.1.
Hint: zoom by scrolling your mouse or pinching on a touch screen.
You can specify an arbitrary 2D clip rectangle in pixel coordinates. The benefits are twofold:
The Liang–Barsky algorithm is used to clip lines efficiently against a rectangular viewport.
For polygons, we rejoin these lines along the clip region edge using Greiner–Hormann, which can clip arbitrary polygons (the same algorithm is used to clip polygons on a sphere).