rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
130 lines • 5.08 kB
TypeScript
import { ATypedArrayTuple, TTypedArrayTupleMutativeMethods } from "../a-typed-array-tuple.js";
import { TTypedArray } from "../t-typed-array.js";
import { IReadonlyMat3 } from "../mat3/mat3.js";
import { ITypedArrayTupleFactory } from "../i-typed-array-tuple-factory.js";
import { TTypedArrayCtor } from "../t-typed-array-ctor.js";
import { IReadonlyRange2d } from "../2d/range2d/range2d.js";
import { TPickExcept } from "../../../typescript/t-pick-except.js";
/**
* @public
*/
export type TVec2CtorArgs = [x: number, y: number];
/**
* @public
* Constructor for {@link Vec2}.
*/
export interface IVec2Ctor<TArray extends TTypedArray> {
readonly BASE: TTypedArrayCtor;
/**
* The size in bytes of each element in the array.
*/
readonly BYTES_PER_ELEMENT: number;
readonly prototype: Vec2<TArray>;
readonly factory: ITypedArrayTupleFactory<Vec2<TArray>, TVec2CtorArgs>;
new (): Vec2<TArray>;
}
/**
* @public
* {@link Vec2}.
*/
export interface IReadonlyVec2<TArray extends TTypedArray> extends TPickExcept<Readonly<Vec2<TArray>>, "update" | "setX" | "setY" | "bound2d" | "translate2d" | "copyFromBuffer" | TTypedArrayTupleMutativeMethods> {
}
/**
* @public
* Vector 2.
*
* @remarks
* See static properties for constructors. Instances are not an extension of this class, but of the static members.
*/
export declare abstract class Vec2<TArray extends TTypedArray> extends ATypedArrayTuple<2, TArray> {
static f64: IVec2Ctor<Float64Array>;
static f32: IVec2Ctor<Float32Array>;
static i64: null;
static u64: null;
static u32: IVec2Ctor<Uint32Array>;
static i32: IVec2Ctor<Int32Array>;
static u16: IVec2Ctor<Uint16Array>;
static i16: IVec2Ctor<Int16Array>;
static u8c: IVec2Ctor<Uint8ClampedArray>;
static u8: IVec2Ctor<Uint8Array>;
static i8: IVec2Ctor<Int8Array>;
static getCtor<TCtor extends TTypedArrayCtor>(ctor: TCtor): IVec2Ctor<InstanceType<TCtor>>;
protected static constructors: Map<import("../t-typed-array-ctor.js").TFullSetTypedArrayCtor, Function>;
["constructor"]: IVec2Ctor<TArray>;
/**
* x
*/
0: number;
/**
* y
*/
1: number;
/**
* Component-wise equals.
*/
isEqualTo(_other: Vec2<TTypedArray>): boolean;
getX(): number;
getY(): number;
getMagnitude(): number;
getMagnitudeSquared(): number;
update(_x: number, _y: number): void;
setX(_x: number): void;
setY(_y: number): void;
add<TResult extends TTypedArray = TArray>(_vec: IReadonlyVec2<TTypedArray>, _result?: Vec2<TResult>): Vec2<TResult>;
subtract<TResult extends TTypedArray = TArray>(_vec: IReadonlyVec2<TTypedArray>, _result?: Vec2<TResult>): Vec2<TResult>;
scalarMultiply<TResult extends TTypedArray = TArray>(_value: number, _result?: Vec2<TResult>): Vec2<TResult>;
/**
* Multiply `this` by `_value`.
*/
vec2Multiply<TResult extends TTypedArray = TArray>(_value: IReadonlyVec2<TTypedArray>, _result?: Vec2<TResult>): Vec2<TResult>;
scalarDivide<TResult extends TTypedArray = TArray>(_value: number, _result?: Vec2<TResult>): Vec2<TResult>;
/**
* Divide `this` by `_value`.
*/
vec2Divide<TResult extends TTypedArray = TArray>(_value: IReadonlyVec2<TTypedArray>, _result?: Vec2<TResult>): Vec2<TResult>;
/**
* Returns a unit vector in the direction of this vector.
*/
normalize<TResult extends TTypedArray = TArray>(_result?: Vec2<TResult>): Vec2<TResult>;
/**
* Returns the normal to this vector.
*/
getNormal<TResult extends TTypedArray = TArray>(_result?: Vec2<TResult>): Vec2<TResult>;
dotProduct(_vec: IReadonlyVec2<TTypedArray>): number;
mat3Multiply<TResult extends TTypedArray = TArray>(_mat: IReadonlyMat3<TTypedArray>, _result?: Vec2<TResult>): Vec2<TResult>;
/**
* If this point is outside of the range, set that dimension to the extrema of the range.
* @param _range - The range to be bound to, inclusive.
*/
bound2d(_range: IReadonlyRange2d<TTypedArray>): void;
/**
* Shifts this position by the arguments.
*/
translate2d(_dx: number, _dy: number): void;
getLoggableValue(): number[][];
/**
* If endianness is not supplied the platform's endianness will be used.
*/
copyFromBuffer(_memoryDataView: DataView, _pointer: number, _littleEndian?: boolean): void;
/**
* If endianness is not supplied the platform's endianness will be used.
*/
copyToBuffer(_memoryDataView: DataView, _pointer: number, _littleEndian?: boolean): void;
/**
* Although the typed array tuples extend a typed array, they are not structurally compatible.
* This function returns the argument passed without modification but cast as the underlying storage type, e.g. Float32Array.
*/
castToBaseType(): TArray;
TTypeGuardVec2: true;
}
/**
* @public
* Float32 {@link Vec2}.
*/
export type TF32Vec2 = Vec2<Float32Array>;
/**
* @public
* Float64 {@link Vec2}.
*/
export type TF64Vec2 = Vec2<Float64Array>;
//# sourceMappingURL=vec2.d.ts.map