1234567891011121314151617181920212223242526272829303132 |
- /**
- * Copyright (c) 2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
- *
- * @author Alexander Rose <alexander.rose@weirdbyte.de>
- */
- export function calculateTextureInfo (n: number, itemSize: number) {
- const sqN = Math.sqrt(n * itemSize)
- let width = Math.ceil(sqN)
- width = width + (itemSize - (width % itemSize)) % itemSize
- const height = width > 0 ? Math.ceil(n * itemSize / width) : 0
- return { width, height, length: width * height * itemSize }
- }
- export interface TextureImage {
- array: Uint8Array
- width: number
- height: number
- }
- export function createColorTexture (n: number): TextureImage {
- const { length, width, height } = calculateTextureInfo(n, 3)
- return { array: new Uint8Array(length), width, height }
- }
- export const emptyTexture = { array: new Uint8Array(0), width: 0, height: 0 }
- export function fillSerial<T extends Helpers.NumberArray> (array: T) {
- const n = array.length
- for (let i = 0; i < n; ++i) array[ i ] = i
- return array
- }
|