videx-3d
Version:
React 3D component library designed for sub surface visualizations in the browser
53 lines (52 loc) • 3.35 kB
TypeScript
/**
* This class makes it easier to worked with typed arrray used in a 2d grid.
* It allow you to read from and write to a flat typed array using columns, rows
* and blocks. It alow you to specify the stride per grid cell, so if you need
* a grid og RGB colors, you set the stride to 3.
*
* Another useful feature of this class is that it will use bilinear interpolation
* if you reference columns and/or rows with decimal indexes.
*
* @author Kjerand Pedersen
*/
export type TypedArrayArrayType = Float32Array | Uint8Array | Uint16Array | Uint32Array;
export type TypedArrayOutputArray = TypedArrayArrayType | undefined;
export type TypedArrayInputArray = number[];
export type TypedArrayMapFunction = (input: number | TypedArrayArrayType) => number | TypedArrayArrayType;
export type InterpolationFunction = (a: number, b: number, c: number, d: number, t1: number, t2: number) => number;
export declare class Typed2DArray {
data: TypedArrayArrayType;
columns: number;
rows: number;
stride: number;
private _rowLength;
private _lerpFn;
private arrayConstructor;
constructor(data: TypedArrayArrayType, columns: number, stride?: number);
static readWriteBlock(source: Typed2DArray, sourceCol: number, sourceRow: number, sourceColumns: number, sourceRows: number, target: Typed2DArray, targetCol: number, targetRow: number, targetColumns: number, targetRows: number, mapFunction?: TypedArrayMapFunction | null): typeof Typed2DArray;
static logInterp(a: number, b: number, c: number, d: number, t1: number, t2: number): number;
static linearInterp(a: number, b: number, c: number, d: number, t1: number, t2: number): number;
static nearestInterp(a: number, b: number, c: number, d: number, t1: number, t2: number): number;
get width(): number;
get height(): number;
index(col: number, row: number): number;
positionOf(index: number): {
row: number;
col: number;
} | undefined;
setInterpolator(...interpolatorFunction: InterpolationFunction[]): this;
getInterpolator(component: number): InterpolationFunction;
col(col: number, out: TypedArrayOutputArray): TypedArrayArrayType;
row(row: number, out: TypedArrayOutputArray): Float32Array<ArrayBufferLike> | Uint8Array<ArrayBufferLike> | Uint16Array<ArrayBufferLike> | Uint32Array<ArrayBufferLike>;
setValue(col: number, row: number, ...value: TypedArrayInputArray): this;
readBlock(fromCol: number, fromRow: number, columns: number, rows: number, targetColumns?: number, targetRows?: number, out?: TypedArrayOutputArray): TypedArrayArrayType;
upscale(newColumns: number, newRows: number): this;
writeBlock(fromCol: number, fromRow: number, columns: number, rows: number, values: number[]): this;
fillBlock(fromCol: number, fromRow: number, cols: number, rows: number, value: number | ((c: number, r: number, i: number) => number | number[])): this;
valueOf(index: number, out?: TypedArrayOutputArray): number | TypedArrayArrayType;
valueAt(col: number, row: number, out?: TypedArrayOutputArray): number | TypedArrayArrayType;
swapRows(r1: number, r2: number, temp: TypedArrayArrayType): this;
invertRows(): this;
copyInto(target: TypedArrayArrayType, fromCol?: number, fromRow?: number, columns?: number, rows?: number): this;
toJsArray(): any[];
}