"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module Rendering
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.computeDimensions = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
/** @internal */
function computeDimensions(nEntries, nRgbaPerEntry, nExtraRgba, maxSize) {
    const nRgba = nEntries * nRgbaPerEntry + nExtraRgba;
    if (nRgba < maxSize)
        return { width: nRgba, height: 1 };
    // Make roughly square to reduce unused space in last row
    let width = Math.ceil(Math.sqrt(nRgba));
    // Ensure a given entry's RGBA values all fit on the same row.
    const remainder = width % nRgbaPerEntry;
    if (0 !== remainder) {
        width += nRgbaPerEntry - remainder;
    }
    // Compute height
    let height = Math.ceil(nRgba / width);
    if (width * height < nRgba)
        ++height;
    (0, core_bentley_1.assert)(height <= maxSize);
    (0, core_bentley_1.assert)(width <= maxSize);
    (0, core_bentley_1.assert)(width * height >= nRgba);
    (0, core_bentley_1.assert)(Math.floor(height) === height);
    (0, core_bentley_1.assert)(Math.floor(width) === width);
    // Row padding should never be necessary...
    (0, core_bentley_1.assert)(0 === width % nRgbaPerEntry);
    return { width, height };
}
exports.computeDimensions = computeDimensions;
//# sourceMappingURL=VertexTable.js.map