MAIDR Documentation - v3.72.1
    Preparing search index...

    Class MathUtilAbstract

    Mathematical utility functions for common operations across the codebase. These utilities help reduce code duplication while maintaining type safety.

    Index

    Methods

    • Safely finds the minimum value from an array of numbers. Returns Infinity for empty arrays (mathematically correct: empty set has no minimum). This prevents subtle bugs where 0 might be confused with actual data.

      Parameters

      • values: number[]

        Array of numbers to find minimum from

      Returns number

      The minimum value or Infinity if array is empty

    • Safely finds the maximum value from an array of numbers. Returns -Infinity for empty arrays (mathematically correct: empty set has no maximum). This prevents subtle bugs where 0 might be confused with actual data.

      Parameters

      • values: number[]

        Array of numbers to find maximum from

      Returns number

      The maximum value or -Infinity if array is empty

    • Finds the minimum value from a 2D array of numbers.

      Parameters

      • values: number[][]

        2D array of numbers

      Returns number

      The minimum value across all nested arrays

    • Finds the maximum value from a 2D array of numbers.

      Parameters

      • values: number[][]

        2D array of numbers

      Returns number

      The maximum value across all nested arrays

    • Finds min and max from an array in a single pass. More efficient than separate min/max calls for large arrays. Returns { min: Infinity, max: -Infinity } for empty arrays.

      Parameters

      • values: number[]

        Array of numbers

      Returns { min: number; max: number }

      Object with min and max properties

    • Finds min and max from a 2D array in a single pass.

      Parameters

      • values: number[][]

        2D array of numbers

      Returns { min: number; max: number }

      Object with min and max properties

    • Clamps a value into the inclusive [min, max] range.

      Parameters

      • value: number

        The value to clamp

      • min: number

        Lower bound (inclusive)

      • max: number

        Upper bound (inclusive)

      Returns number

    • Linearly maps a value from one numeric range to another. Collapses to toMin when the source range is zero-width to avoid NaN.

      Parameters

      • value: number

        The value in the source range

      • fromMin: number

        Lower bound of the source range

      • fromMax: number

        Upper bound of the source range

      • toMin: number

        Lower bound of the target range

      • toMax: number

        Upper bound of the target range

      Returns number