rhodonite
    Preparing search index...

    Class MathClassUtil

    Utility class providing various mathematical operations and conversions for vector, matrix, and quaternion types. This class contains static methods for converting between different mathematical representations, performing arithmetic operations, and manipulating mathematical objects.

    Index

    Constructors

    Methods

    • Forcefully sets the internal values of a mathematical object to match another object's values. This method directly modifies the internal array representation for performance. Performs equality check to avoid unnecessary operations.

      Parameters

      • objForDetectType: any

        Target object to modify

      • val: any

        Source object or value to copy from

      Returns boolean

      True if values were changed, false if they were already equal

    • Performs addition operation on various mathematical types. Supports numbers, vectors, quaternions, and arrays.

      Parameters

      • lhs: any

        Left-hand side operand

      • rhs: any

        Right-hand side operand

      Returns any

      Result of the addition operation, type depends on input types

    • Converts a 4-element array to a Quaternion instance.

      Parameters

      • element: number[]

        Array of 4 numbers representing quaternion components [x, y, z, w]

      Returns Quaternion

      Quaternion instance created from the array elements

    • Converts an array of numbers to the appropriate Vector or Matrix type based on array length. Supports conversion to Matrix44, Matrix33, Vector4, Vector3, or Vector2.

      Parameters

      • element: number[]

        Array of numbers to convert

      Returns Matrix33 | Vector3 | Matrix44 | Vector4 | Vector2

      Matrix44, Matrix33, Vector4, Vector3, or Vector2 instance based on array length, or the original element if not an array

    • Creates a deep clone of mathematical objects (matrices and vectors).

      Parameters

      • element: any

        The mathematical object to clone

      Returns any

      A cloned instance of the input object, or the original element if it's not a mathematical object

    • Divides various mathematical types by a scalar number. Supports numbers, vectors, quaternions, and arrays.

      Parameters

      • lhs: any

        Mathematical object to divide

      • rhs: number

        Scalar divisor

      Returns number | number[] | Vector3 | Vector4 | Quaternion | Vector2 | undefined

      Result of the scalar division, type depends on input type

    • Gets the immutable value class constructor for a given composition type.

      Parameters

      Returns Function | undefined

      Constructor function for the corresponding immutable math class, or undefined if not supported

    • Gets the mutable value class constructor for a given composition type.

      Parameters

      Returns Function | undefined

      Constructor function for the corresponding mutable math class, or undefined if not supported

    • Initializes a mutable mathematical object from a value using a provided Float32Array as storage. This method efficiently reuses memory by using the provided array as the backing store.

      Parameters

      • val: any

        Value to initialize from (can be various mathematical types)

      • floatArray: Float32Array

        Float32Array to use as backing storage

      Returns any

      Mutable mathematical object using the provided array as storage

    • Initializes a mathematical object of the same type as the input with a scalar value. For vectors and arrays, all components are set to the scalar value. For quaternions, creates an identity quaternion.

      Parameters

      • objForDetectType: any

        Object used to determine the target type

      • val: number

        Scalar value to initialize with

      Returns number | number[] | Vector3 | Vector4 | Quaternion | Vector2 | undefined

      New instance of the same type as objForDetectType initialized with val

    • Checks if an array is suitable for quaternion conversion (has 4 elements).

      Parameters

      • element: number[]

        Array to check

      Returns boolean

      True if the array has 4 elements and can be converted to a quaternion

    • Creates a sub-array with the specified number of components from the beginning of the input array.

      Parameters

      • array: any[]

        Source array to extract elements from

      • componentN: number

        Number of components to extract (1-4)

      Returns any

      Sub-array with the specified number of elements, or single element if componentN is 1

    • Multiplies various mathematical types by a scalar number. Supports numbers, vectors, quaternions, and arrays.

      Parameters

      • lhs: any

        Mathematical object to multiply

      • rhs: number

        Scalar multiplier

      Returns number | number[] | Vector3 | Vector4 | Quaternion | Vector2 | undefined

      Result of the scalar multiplication, type depends on input type

    • Packs a normalized 4D vector into a 2D vector using a grid-based encoding scheme. Input values must be in the range [-1, 1] and are converted to [0, 1] internally.

      Parameters

      • x: number

        X component of the 4D vector (must be in range [-1, 1])

      • y: number

        Y component of the 4D vector (must be in range [-1, 1])

      • z: number

        Z component of the 4D vector (must be in range [-1, 1])

      • w: number

        W component of the 4D vector (must be in range [-1, 1])

      • criteria: number

        Grid resolution for encoding (determines precision)

      Returns number[]

      Array of 2 values representing the packed vector

    • Performs subtraction operation on various mathematical types. Supports numbers, vectors, quaternions, and arrays.

      Parameters

      • lhs: any

        Left-hand side operand (minuend)

      • rhs: any

        Right-hand side operand (subtrahend)

      Returns number | number[] | Vector3 | Vector4 | Quaternion | Vector2 | undefined

      Result of the subtraction operation, type depends on input types

    • Unprojects a window coordinate to world space using the inverse projection-view matrix. Converts 2D screen coordinates with depth to 3D world coordinates.

      Parameters

      • windowPosX: number

        X coordinate in window space

      • windowPosY: number

        Y coordinate in window space

      • windowPosZ: number

        Z coordinate (depth) in window space

      • inversePVMat44: Matrix44

        Inverse of the projection-view matrix

      • viewportVec4: Vector4

        Viewport parameters [x, y, width, height]

      • out: MutableVector3

        Output vector to store the result

      Returns IMutableVector3

      The unprojected 3D world position