@itwin/core-frontend
Version:
iTwin.js frontend components
35 lines • 1.63 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* 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 = computeDimensions;
const core_bentley_1 = require("@itwin/core-bentley");
/** @internal */
function computeDimensions(nEntries, nRgbaPerEntry, nExtraRgba, maxSize) {
const nRgba = Math.ceil(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
const height = Math.ceil(nRgba / width);
(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 };
}
//# sourceMappingURL=VertexTable.js.map