Variable MathUtilConst

MathUtil: Readonly<{
    computeEigenValuesAndVectors: ((A: MutableMatrix33, Q: MutableMatrix33, w: MutableVector3) => -1 | 0);
    computeGaussianDistributionRatioWhoseSumIsOne: ((params: {
        effectiveDigit?: number;
        kernelSize: number;
        mean?: number;
        variance: number;
    }) => number[]);
    convertToStringAsGLSLFloat: ((value: number) => string);
    degreeToRadian: ((deg: number) => number);
    financial: ((val: string | number) => string);
    gaussianCdf: ((x: number, mu: number, sigma: number) => number);
    invGaussianCdf: ((U: number, mu: number, sigma: number) => number);
    isPowerOfTwo: ((x: number) => boolean);
    isPowerOfTwoTexture: ((width: number, height: number) => boolean);
    lerp: ((a: number, b: number, t: number) => number);
    nearZeroToZero: ((value: number) => number);
    packNormalizedVec4ToVec2: ((x: number, y: number, z: number, w: number, criteria: number) => number[]);
    radianToDegree: ((rad: number) => number);
    roundAsFloat: ((value: number) => number);
    toHalfFloat: (() => ((val: number) => number));
}> = ...

A utility class containing various mathematical functions and operations. This class provides static methods for common mathematical computations including:

  • Angle conversions (radians/degrees)
  • Floating point operations and conversions
  • Power-of-two checks
  • Vector packing utilities
  • Statistical functions (Gaussian distributions, error functions)
  • Matrix eigenvalue computations
  • Interpolation and formatting utilities

Type declaration

  • computeEigenValuesAndVectors: ((A: MutableMatrix33, Q: MutableMatrix33, w: MutableVector3) => -1 | 0)
      • (A, Q, w): -1 | 0
      • Computes eigenvalues and eigenvectors of a 3x3 symmetric matrix using the Jacobi method.

        Parameters

        • A: MutableMatrix33

          The input 3x3 symmetric matrix (will be modified during computation)

        • Q: MutableMatrix33

          The output matrix that will contain the eigenvectors

        • w: MutableVector3

          The output vector that will contain the eigenvalues

        Returns -1 | 0

        0 on success, -1 if maximum iterations exceeded

  • computeGaussianDistributionRatioWhoseSumIsOne: ((params: {
        effectiveDigit?: number;
        kernelSize: number;
        mean?: number;
        variance: number;
    }) => number[])
      • (params): number[]
      • Computes a normalized discrete Gaussian distribution where the sum of all ratios equals 1. The sampling points are positioned at integer intervals around the mean.

        Parameters

        • params: {
              effectiveDigit?: number;
              kernelSize: number;
              mean?: number;
              variance: number;
          }

          Configuration object for the Gaussian distribution

          • OptionaleffectiveDigit?: number

            Number of decimal places for precision (default: 4)

          • kernelSize: number

            Number of sampling points in the distribution

          • Optionalmean?: number

            Mean of the Gaussian distribution (default: 0)

          • variance: number

            Variance of the Gaussian distribution

        Returns number[]

        An array of normalized ratios that sum to 1

        // For kernelSize = 2 (mean=0): sampling points are at -0.5 and 0.5
        // For kernelSize = 3 (mean=1): sampling points are at 0.0, 1.0, and 2.0
  • convertToStringAsGLSLFloat: ((value: number) => string)
      • (value): string
      • Converts a numeric value to a string formatted for GLSL float literals. Ensures that integer values are suffixed with ".0" for proper GLSL syntax.

        Parameters

        • value: number

          The numeric value to convert

        Returns string

        A string representation suitable for GLSL float literals

  • degreeToRadian: ((deg: number) => number)
      • (deg): number
      • Converts degrees to radians.

        Parameters

        • deg: number

          The angle in degrees

        Returns number

        The angle in radians

  • financial: ((val: string | number) => string)
      • (val): string
      • Formats a numeric value as a fixed-width financial string with 7 decimal places. Positive values are prefixed with a space for alignment.

        Parameters

        • val: string | number

          The numeric value to format

        Returns string

        A formatted string with consistent width for financial display

  • gaussianCdf: ((x: number, mu: number, sigma: number) => number)
      • (x, mu, sigma): number
      • Calculates the cumulative distribution function (CDF) for a Gaussian distribution.

        Parameters

        • x: number

          The value at which to evaluate the CDF

        • mu: number

          The mean of the Gaussian distribution

        • sigma: number

          The standard deviation of the Gaussian distribution

        Returns number

        The cumulative probability up to x

  • invGaussianCdf: ((U: number, mu: number, sigma: number) => number)
      • (U, mu, sigma): number
      • Calculates the inverse cumulative distribution function (inverse CDF) for a Gaussian distribution.

        Parameters

        • U: number

          The cumulative probability (should be in range [0, 1])

        • mu: number

          The mean of the Gaussian distribution

        • sigma: number

          The standard deviation of the Gaussian distribution

        Returns number

        The value x such that CDF(x) = U

  • isPowerOfTwo: ((x: number) => boolean)
      • (x): boolean
      • Checks whether a number is a power of two.

        Parameters

        • x: number

          The number to check

        Returns boolean

        True if the number is a power of two, false otherwise

  • isPowerOfTwoTexture: ((width: number, height: number) => boolean)
      • (width, height): boolean
      • Checks whether the given texture dimensions are both powers of two.

        Parameters

        • width: number

          The width of the texture

        • height: number

          The height of the texture

        Returns boolean

        True if both dimensions are powers of two, false otherwise

  • lerp: ((a: number, b: number, t: number) => number)
      • (a, b, t): number
      • Performs linear interpolation between two values.

        Parameters

        • a: number

          The starting value

        • b: number

          The ending value

        • t: number

          The interpolation parameter (0 returns a, 1 returns b)

        Returns number

        The interpolated value

  • nearZeroToZero: ((value: number) => number)
      • (value): number
      • Rounds very small values to zero and values very close to ±1 to exactly ±1. This helps reduce floating-point precision errors in calculations.

        Parameters

        • value: number

          The value to normalize

        Returns number

        The normalized value with small errors corrected

  • packNormalizedVec4ToVec2: ((x: number, y: number, z: number, w: number, criteria: number) => number[])
      • (x, y, z, w, criteria): number[]
      • Packs a normalized 4D vector into a 2D vector using a specific encoding scheme. All input values must be in the range [-1, 1].

        Parameters

        • x: number

          The x component of the vector (range: [-1, 1])

        • y: number

          The y component of the vector (range: [-1, 1])

        • z: number

          The z component of the vector (range: [-1, 1])

        • w: number

          The w component of the vector (range: [-1, 1])

        • criteria: number

          The encoding criteria/resolution

        Returns number[]

        A 2-element array containing the packed values

  • radianToDegree: ((rad: number) => number)
      • (rad): number
      • Converts radians to degrees.

        Parameters

        • rad: number

          The angle in radians

        Returns number

        The angle in degrees

  • roundAsFloat: ((value: number) => number)
      • (value): number
      • Rounds a floating-point number to 7 decimal places to reduce precision errors.

        Parameters

        • value: number

          The value to round

        Returns number

        The rounded value

  • toHalfFloat: (() => ((val: number) => number))