@@ -58,7 +58,7 @@ export interface NumberArrayView {
5858 * These functions are not defined on vectors,
5959 * but are instead assigned to `VecBase` after both `data` and `std` are initialized.
6060 */
61- export interface vecInfixNotation < T extends AnyNumericVecInstance > {
61+ export interface vecInfixNotation < T extends vecBase > {
6262 add ( other : T | number ) : T ;
6363 sub ( other : T | number ) : T ;
6464 mul ( other : mBaseForVec < T > | T | number ) : T ;
@@ -82,7 +82,7 @@ export interface vecInfixNotation<T extends AnyNumericVecInstance> {
8282 * These functions are not defined on matrices,
8383 * but are instead assigned to `MatBase` after both `data` and `std` are initialized.
8484 */
85- export interface matInfixNotation < T extends AnyMatInstance > {
85+ export interface matInfixNotation < T extends matBase > {
8686 add ( other : T ) : T ;
8787 sub ( other : T ) : T ;
8888 mul ( other : T | number ) : T ;
@@ -184,6 +184,38 @@ type Tuple2<S> = [S, S];
184184type Tuple3 < S > = [ S , S , S ] ;
185185type Tuple4 < S > = [ S , S , S , S ] ;
186186
187+ /**
188+ * A type which every numeric vector is assignable to. In most cases the union v2f | v3f | v4f | v2h | v3h | v4h | v2i | v3i | v4i | v2u | v3u | v4u
189+ * is preferred, but when an implementation uses overloaded operators and is generic on the type,
190+ * this makes the type checking much more laid back.
191+ *
192+ * @example
193+ * ```ts
194+ * export function quinticInterpolation(t: d.v2f): d.v2f;
195+ * export function quinticInterpolation(t: d.v3f): d.v3f;
196+ * export function quinticInterpolation(t: d.vecBase): d.vecBase {
197+ * 'use gpu';
198+ * return t * t * t * (t * (t * 6 - 15) + 10);
199+ * }
200+ * ```
201+ */
202+ export interface vecBase extends vecInfixNotation < vecBase > {
203+ readonly [ $internal ] : true ;
204+ readonly kind :
205+ | 'vec2f'
206+ | 'vec3f'
207+ | 'vec4f'
208+ | 'vec2h'
209+ | 'vec3h'
210+ | 'vec4h'
211+ | 'vec2i'
212+ | 'vec3i'
213+ | 'vec4i'
214+ | 'vec2u'
215+ | 'vec3u'
216+ | 'vec4u' ;
217+ }
218+
187219/**
188220 * Interface representing its WGSL vector type counterpart: vec2f or vec2<f32>.
189221 * A vector with 2 elements of type f32
@@ -479,6 +511,16 @@ export type AnyVecInstance =
479511
480512export type VecKind = AnyVecInstance [ 'kind' ] ;
481513
514+ /**
515+ * A type which every matrix is assignable to. In most cases the union m2x2f | m3x3f | m4x4f
516+ * is preferred, but when an implementation uses overloaded operators and is generic on the type,
517+ * this makes the type checking much more laid back.
518+ */
519+ export interface matBase extends matInfixNotation < matBase > {
520+ readonly [ $internal ] : true ;
521+ readonly kind : 'mat2x2f' | 'mat3x3f' | 'mat4x4f' ;
522+ }
523+
482524/**
483525 * Interface representing its WGSL matrix type counterpart: mat2x2
484526 * A matrix with 2 rows and 2 columns, with elements of type `TColumn`
@@ -546,14 +588,15 @@ export interface m4x4f extends mat4x4<v4f>, matInfixNotation<m4x4f> {
546588
547589export type AnyMatInstance = m2x2f | m3x3f | m4x4f ;
548590
549- export type vBaseForMat < T extends AnyMatInstance > = T extends m2x2f ? v2f
591+ export type vBaseForMat < T extends matBase > = T extends m2x2f ? v2f
550592 : T extends m3x3f ? v3f
551- : v4f ;
593+ : T extends m4x4f ? v4f
594+ : vecBase ;
552595
553- export type mBaseForVec < T extends AnyVecInstance > = T extends v2f ? m2x2f
596+ export type mBaseForVec < T extends vecBase > = T extends v2f ? m2x2f
554597 : T extends v3f ? m3x3f
555598 : T extends v4f ? m4x4f
556- : never ;
599+ : matBase ;
557600
558601// #endregion
559602
0 commit comments