static Dimensions ofGrid(List<Bounds> bounds, double[] yOffset, double[] xOffset) {
        int nRow = yOffset.length - 1;
        int nCol = xOffset.length - 1;

        int nBounds = bounds.size();
        for (int i = 0; i < nBounds; i++) {
            // +1 because first offset is always 0
            int col = 1 + i % nCol;
            int row = 1 + i / nCol;
            final Bounds bound = bounds.get(i);
            if (bound.isEmpty())
                continue;
            double width  = bound.width();
            double height = bound.height();
            if (width > xOffset[col])
                xOffset[col] = width;
            if (height > yOffset[row])
                yOffset[row] = height;
        }

        for (int i = 1; i < yOffset.length; i++)
            yOffset[i] += yOffset[i - 1];
        for (int i = 1; i < xOffset.length; i++)
            xOffset[i] += xOffset[i - 1];

        return new Dimensions(xOffset[nCol], yOffset[nRow]);
    }
static Dimensions ofGrid ( List < Bounds > bounds , double [ ] yOffset , double [ ] xOffset ) { int nRow = yOffset . length - 1 ; int nCol = xOffset . length - 1 ; int nBounds = bounds . size ( ) ; for ( int i = 0 ; i < nBounds ; i ++ ) { int col = 1 + i % nCol ; int row = 1 + i / nCol ; final Bounds bound = bounds . get ( i ) ; if ( bound . isEmpty ( ) ) continue ; double width = bound . width ( ) ; double height = bound . height ( ) ; if ( width > xOffset [ col ] ) xOffset [ col ] = width ; if ( height > yOffset [ row ] ) yOffset [ row ] = height ; } for ( int i = 1 ; i < yOffset . length ; i ++ ) yOffset [ i ] += yOffset [ i - 1 ] ; for ( int i = 1 ; i < xOffset . length ; i ++ ) xOffset [ i ] += xOffset [ i - 1 ] ; return new Dimensions ( xOffset [ nCol ] , yOffset [ nRow ] ) ; }
Determine how much space is needed to depiction the bound {@link IRenderingElements} if
they were aligned in a grid without padding or margins. The method takes arrays
for for the offset which are one item bigger than the size of the gird
(e.g. 3x2 would need arrays of length 4 and 2). The arrays are filled with the
cumulative width/heights for each grid point allowing easy alignment.

@param bounds  bound rendering elements
@param yOffset array for col offsets
@param xOffset array for row offset
@return the dimensions required