Options
All
  • Public
  • Public/Protected
  • All
Menu

Module utils/numeric

Index

Functions

adjustAlpha

  • adjustAlpha(alpha: number): number
  • Helper function to correctly determine or clamp the alpha channel value

    note

    This utility function is provided to provide identical logic for alpha channel value determination. Unlike other channels, the alpha channel is optional, thus it needs to be handled differently.

    Parameters

    • alpha: number

      A numeric value corresponding to the alpha channel

    Returns number

    A valid alpha channel value in range [0, 1]

adjustHue

  • adjustHue(value: number): number
  • Given a hue (value) - ensure that it is in range [0, 359]

    Parameters

    • value: number

      The value that needs to be rounded

    Returns number

    A positively bounded hue value

channelWiseDifference

  • Given two RGB arrays, this computes the sum of their channel wise difference

    Parameters

    Returns number

    The sum of absolute differences between the channels of the two input RGB arrays

clamp

  • clamp(min: number, val: number, max: number): number
  • Restricts the value of val to be between min and max for number inputs

    Parameters

    • min: number

      Lower bound (0)

    • val: number

      Current value

    • max: number

      Upper bound (typically 100, 255, 359)

    Returns number

    A number in the range [min, max] such that min <= val <= max

getRGBArr

  • getRGBArr(str: string, alternative?: number[]): Required<TNumArr>
  • Transforms an input RGBA string into an RGBA ([r, g, b, a]) numeric array

    Parameters

    • str: string

      Input RGBA string from which the RGB values are extracted

    • alternative: number[] = ...

      If the string is not RGBA, this array is returned instead

    Returns Required<TNumArr>

    An RGBA array based on the input string in the form [r, g, b, a]

rng

  • rng(max: number): number
  • Helper for generating random numbers (integer) from an upper bounded range

    Parameters

    • max: number

      Output will be bounded to [0, max]

    Returns number

    A positive integer that is randomly generated and guaranteed to be less than max

round

  • round(value: number, precision: number): number
  • Given a value, rounds the value to a given precision (number of decimal places)

    note

    Providing a negative precision value will skip this conversion

    Parameters

    • value: number

      The value that needs to be rounded

    • precision: number

      How many decimal places to include in the result

    Returns number

    The input value with "precision" amount of decimal places

sRGB

  • sRGB(value: number): number

sRGBInv

  • sRGBInv(value: number): number