A minimum bounding box in geographic coordinates is an area defined by minimum and maximum longitudes and latitudes.
Computing bounding boxes in 2D is simple: track the minimum and maximum x- and y-coordinates point by point. Assuming line segments are straight for both polylines and polygons, nothing else needs to be done.
Why doesn’t this work for a sphere?
Imagine a set of points clustered around the antimeridian at 180°E. A 2D algorithm will find a bounding box with longitudes extending all the way from around -180° to around +180°, even if the true minimum bounding box has a much smaller width.
A better approach is to compute the true minimum-width bounding box, even if it crosses the antimeridian.
D3 treats line segments as great-circle arcs: two successive points define the minor arc of the great circle going through those points.
Here we need to be even more careful than for points, since it matters whether or not the line crosses the antimeridian.
In addition, intermediate points between the segment endpoints may have latitudes extending beyond the maximum or minimum endpoint latitude.
A polygon may contain any number of holes, and the location of its interior depends on the winding order of its vertices.
In D3, if a polygon’s vertices wind around a point in a counter-clockwise direction, this means the point is outside the polygon. Otherwise, it is inside .
If a polygons vertices wind around either pole, this means the longitudes have maximum extent from 180°W to +180°E.
Lastly, a polygon may contain either pole, even if its vertices do not extend to the pole, in which case the latitude extent is extended to the pole.
The described behaviour is supported by d3.geo.bounds
as of D3 version 3.1.7.