def _get_boxes(pos, size=None, margin=0, keep_aspect_ratio=True):
    """Generate non-overlapping boxes in NDC from a set of positions."""

    # Get x, y.
    pos = np.asarray(pos, dtype=np.float64)
    x, y = pos.T
    x = x[:, np.newaxis]
    y = y[:, np.newaxis]

    w, h = size if size is not None else _get_box_size(x, y, margin=margin)

    x0, y0 = x - w, y - h
    x1, y1 = x + w, y + h

    # Renormalize the whole thing by keeping the aspect ratio.
    x0min, y0min, x1max, y1max = x0.min(), y0.min(), x1.max(), y1.max()
    if not keep_aspect_ratio:
        b = (x0min, y0min, x1max, y1max)
    else:
        dx = x1max - x0min
        dy = y1max - y0min
        if dx > dy:
            b = (x0min, (y1max + y0min) / 2. - dx / 2.,
                 x1max, (y1max + y0min) / 2. + dx / 2.)
        else:
            b = ((x1max + x0min) / 2. - dy / 2., y0min,
                 (x1max + x0min) / 2. + dy / 2., y1max)
    r = Range(from_bounds=b,
              to_bounds=(-1, -1, 1, 1))
    return np.c_[r.apply(np.c_[x0, y0]), r.apply(np.c_[x1, y1])]
Generate non-overlapping boxes in NDC from a set of positions.