MCPcopy
hub / github.com/sparkjsdev/spark / mulOutputType

Function mulOutputType

src/dyno/mathTypes.ts:395–526  ·  view source on GitHub ↗
(
  a: A,
  b: B,
)

Source from the content-addressed store, hash-verified

393}
394
395export function mulOutputType<A extends AllValueTypes, B extends AllValueTypes>(
396 a: A,
397 b: B,
398): MulOutput<A, B> {
399 const error = () => {
400 throw new Error(`Invalid mul types: ${a}, ${b}`);
401 };
402 const result = (value: unknown) => value as MulOutput<A, B>;
403 if (a === "int") {
404 if (isIntType(b)) return result(b);
405 error();
406 }
407 if (b === "int") {
408 if (isIntType(a)) return result(a);
409 error();
410 }
411 if (a === "uint") {
412 if (isUintType(b)) return result(b);
413 error();
414 }
415 if (b === "uint") {
416 if (isUintType(a)) return result(a);
417 error();
418 }
419 if (a === "float") {
420 if (isAllFloatType(b)) return result(b);
421 error();
422 }
423 if (b === "float") {
424 if (isAllFloatType(a)) return result(a);
425 error();
426 }
427 if (isIntType(a) || isUintType(a) || isIntType(b) || isUintType(b)) {
428 // @ts-ignore
429 if (a === b) return result(a);
430 error();
431 }
432 // Vector * Matrix/Vector
433 if (a === "vec2") {
434 if (b === "vec2" || isMat2(b)) return result("vec2");
435 if (b === "mat3x2") return result("vec3");
436 if (b === "mat4x2") return result("vec4");
437 error();
438 }
439 if (a === "vec3") {
440 if (b === "mat2x3") return result("vec2");
441 if (b === "vec3" || isMat3(b)) return result("vec3");
442 if (b === "mat4x3") return result("vec4");
443 error();
444 }
445 if (a === "vec4") {
446 if (b === "mat2x4") return result("vec2");
447 if (b === "mat3x4") return result("vec3");
448 if (b === "vec4" || isMat4(b)) return result("vec4");
449 error();
450 }
451 // Matrix * Vector
452 if (b === "vec2") {

Callers

nothing calls this directly

Calls 8

isIntTypeFunction · 0.90
isUintTypeFunction · 0.90
isAllFloatTypeFunction · 0.90
isMat2Function · 0.90
isMat3Function · 0.90
isMat4Function · 0.90
errorFunction · 0.85
resultFunction · 0.70

Tested by

no test coverage detected