@itwin/core-frontend
Version:
iTwin.js frontend components
32 lines • 1.38 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
*/
import { assert } from "@itwin/core-bentley";
/** @internal */
export 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);
assert(height <= maxSize);
assert(width <= maxSize);
assert(width * height >= nRgba);
assert(Math.floor(height) === height);
assert(Math.floor(width) === width);
// Row padding should never be necessary...
assert(0 === width % nRgbaPerEntry);
return { width, height };
}
//# sourceMappingURL=VertexTable.js.map