net.returnvoid.tools

## Class RMath

- java.lang.Object
- - net.returnvoid.tools.RMath

-     public class RMath
      extends java.lang.Object

  A class for mathematical operations.
  Author:
    Diana Lange

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static float` | `PI` float of Math.PI ~ 3.1416.
    `static float` | `TWO_PI` float of 2 * Math.PI ~ 6.2832.

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static float` | `abs(float val)` Returns the absolute value of the input.
    `static int` | `abs(int val)` Returns the absolute value of the input.
    `static float` | `constrain(float input, float min, float max)` Constrains a float value to the give min and max. min and max are both included in the range.
    `static java.lang.Integer` | `constrain(int input, int min, int max)` Constrains a float value to the give min and max. min and max are both included in the range.
    `static float` | `map(float input, float inputStart, float inputEnd, float outputStart, float outputEnd)` Maps (interpolates) the given input value, which has a known range of inputStart and inputEnd, to another range.
    `static float` | `max(char channel, RColor... vals)` Returns the maximal color value found in the set of the input.
    `static float[]` | `max(ColorSpace space, RColor... vals)` Calculates the the maximal values of all color channels of the given color set.
    `static float` | `max(float... vals)` Returns the maximal value found in the set of the input.
    `static int` | `max(int... vals)` Returns the maximal value found in the set of the input.
    `static int` | `maxIndex(float... vals)` Returns the index of the maximal value found in the set of the input.
    `static int` | `maxIndex(int... vals)` Returns the index of the maximal value found in the set of the input.
    `static float` | `min(char channel, RColor... vals)` Returns the minimal color value found in the set of the input.
    `static float[]` | `min(ColorSpace space, RColor... vals)` Calculates the the minimal values of all color channels of the given color set.
    `static float` | `min(float... vals)` Returns the minimal value found in the set of the input.
    `static int` | `min(int... vals)` Returns the minimal value found in the set of the input.
    `static int` | `minIndex(float... vals)` Returns the index of the minimal value found in the set of the input.
    `static int` | `minIndex(int... vals)` Returns the index of the minimal value found in the set of the input.
    `static processing.core.PVector` | `polarToCartesian(java.lang.Float a, float r)` Converts polar coordinates (angle and radius) to Cartesian coordinates (x, y).
    `static processing.core.PVector` | `polarToCartesian(float basex, float basey, float a, float r)` Converts polar coordinates (angle and radius) to Cartesian coordinates (x, y).
    `static processing.core.PVector` | `polarToCartesian(processing.core.PVector base, float a, float r)` Converts polar coordinates (angle and radius) to Cartesian coordinates (x, y).
    `static float` | `random(float max)` Returns a random float value with range of [0, max).
    `static float` | `random(float min, float max)` Returns a random float value with range of [min, max).
    `static int` | `random(int max)` Returns a random int value with range of [0, max).
    `static int` | `random(int min, int max)` Returns a random int value with range of [min, max).
    `static float[]` | `range(ColorSpace space, RColor... vals)` Calculates the range (minimum and maximum values) of all color channels the given color set.
    `static float[]` | `range(float... vals)` Calculates the range (minimum and maximum values) of the given set.
    `static int[]` | `range(int... vals)` Calculates the range (minimum and maximum values) of the given set.
    `static float[]` | `range(processing.core.PVector... vals)` Calculates the range (minimum x / y and maximum x / y values) of the given set.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### PI

          public static final float PI

      float of Math.PI ~ 3.1416.
      See Also:
        Constant Field Values

    - #### TWO_PI

          public static final float TWO_PI

      float of 2 * Math.PI ~ 6.2832.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### polarToCartesian

          public static processing.core.PVector polarToCartesian(java.lang.Float a,
                                                                 float r)

      Converts polar coordinates (angle and radius) to Cartesian coordinates (x, y).
      Parameters:
        `a` - The angle.
        `r` - The radius.
      Returns:
        The Cartesian coordinates.

    - #### polarToCartesian

          public static processing.core.PVector polarToCartesian(processing.core.PVector base,
                                                                 float a,
                                                                 float r)

      Converts polar coordinates (angle and radius) to Cartesian coordinates (x, y). The coordinates will be translated by the vector base.
      Parameters:
        `base` - The base (translation vector).
        `a` - The angle.
        `r` - The radius.
      Returns:
        The Cartesian coordinates.

    - #### polarToCartesian

          public static processing.core.PVector polarToCartesian(float basex,
                                                                 float basey,
                                                                 float a,
                                                                 float r)

      Converts polar coordinates (angle and radius) to Cartesian coordinates (x, y). The coordinates will be translated by the vector base.
      Parameters:
        `basex` - The x coordinate of a translation vector.
        `basey` - The y coordinate of a translation vector.
        `a` - The angle.
        `r` - The radius.
      Returns:
        The Cartesian coordinates.

    - #### constrain

          public static float constrain(float input,
                                        float min,
                                        float max)

      Constrains a float value to the give min and max. min and max are both included in the range. If the input value is smaller that min, the output will be min. If the input value is higher than max, the output will be max.
      Parameters:
        `input` - The value that should be constrained to a range.
        `min` - The minimum of the range (value is included in the range). min < max.
        `max` - The maximum of the range (value is included in the range). min < max.
      Returns:
        The constrained value which will be in the range of [min, max].

    - #### constrain

          public static java.lang.Integer constrain(int input,
                                                    int min,
                                                    int max)

      Constrains a float value to the give min and max. min and max are both included in the range. If the input value is smaller that min, the output will be min. If the input value is higher than max, the output will be max.
      Parameters:
        `input` - The value that should be constrained to a range.
        `min` - The minimum of the range (value is included in the range). min < max.
        `max` - The maximum of the range (value is included in the range). min < max.
      Returns:
        The constrained value which will be in the range of [min, max].

    - #### map

          public static float map(float input,
                                  float inputStart,
                                  float inputEnd,
                                  float outputStart,
                                  float outputEnd)

      Maps (interpolates) the given input value, which has a known range of inputStart and inputEnd, to another range. If the input is out of bounds to the input range, the output will be out of bounds to the output range as well. But the input value will still be interpolated.
      Parameters:
        `input` - The value that should be interpolated.
        `inputStart` - The first value that describes the input range (inputStart <= inputEnd or inputStart >= inputEnd). If inputStart = inputEnd, outputStart will be returned.
        `inputEnd` - The second value that describes the input range (inputStart <= inputEnd or inputStart >= inputEnd).
        `outputStart` - The first value that describes the output range (outputStart <= outputEnd or outputStart >= outputEnd). If outputStart = outputEnd, outputStart will be returned.
        `outputEnd` - The second value that describes the output range (outputStart <= outputEnd or outputStart >= outputEnd). If outputStart = outputEnd, outputStart will be returned.
      Returns:
        The mapped value.

    - #### random

          public static float random(float max)

      Returns a random float value with range of [0, max).
      Parameters:
        `max` - The maximum of the range. max will be not included for 0 < max. if max < 0, the output will have a range of [max, 0).
      Returns:
        The random float value.

    - #### random

          public static float random(float min,
                                     float max)

      Returns a random float value with range of [min, max).
      Parameters:
        `min` - The minimum of the range. min will be included for min < max. if max < min, the output will have a range of [max, min).
        `max` - The maximum of the range. max will be not included for min < max. if max < min, the output will have a range of [max, min).
      Returns:
        The random float value.

    - #### random

          public static int random(int max)

      Returns a random int value with range of [0, max).
      Parameters:
        `max` - The maximum of the range. max will be not included for 0 < max. if max < 0, the output will have a range of [max, 0).
      Returns:
        The random int value.

    - #### random

          public static int random(int min,
                                   int max)

      Returns a random int value with range of [min, max).
      Parameters:
        `min` - The minimum of the range. min will be included for min < max. if max < min, the output will have a range of [max, min).
        `max` - The maximum of the range. max will be not included for min < max. if max < min, the output will have a range of [max, min).
      Returns:
        The random int value.

    - #### abs

          public static float abs(float val)

      Returns the absolute value of the input.
      Parameters:
        `val` - Any float value.
      Returns:
        The absolute float value of the input.

    - #### abs

          public static int abs(int val)

      Returns the absolute value of the input.
      Parameters:
        `val` - Any int value.
      Returns:
        The absolute int value of the input.

    - #### min

          public static float min(float... vals)

      Returns the minimal value found in the set of the input.
      Parameters:
        `vals` - A set of float values.
      Returns:
        The minimal float value of the given set. -1 will be returned if the input is empty.

    - #### min

          public static int min(int... vals)

      Returns the minimal value found in the set of the input.
      Parameters:
        `vals` - A set of int values.
      Returns:
        The minimal int value of the given set. -1 will be returned if the input is empty.

    - #### min

          public static float[] min(ColorSpace space,
                                    RColor... vals)

      Calculates the the minimal values of all color channels of the given color set. The color set will be converted to the given color space and the color space will define which minimal values should be calculated. Example: If ColorSpace.RGBColor is the given color space then the output will be the minimal red, green, blue and alpha.
      Parameters:
        `space` - The color space which defines which minimal values should be calculated.
        `vals` - A set of colors.
      Returns:
        The minimal values of the channels. Depending on the given color spaces these are: [r, g, b, alpha], [h, s, b, alpha], [x, y, z, alpha], [l, a, b, alpha], [l, c, h, alpha]. null will be returned if the input is empty.

    - #### min

          public static float min(char channel,
                                  RColor... vals)

      Returns the minimal color value found in the set of the input.
      Parameters:
        `channel` - The color channel. Either 'r', 'g' or 'b' when first color of vals is a RGBColor, 'h', 's' or 'b' when first color of vals is a HSBColor, 'x', 'y' or 'z' if first color of vals is a XYZColor, 'l', 'a' or 'b' if first color is a LabColor, 'l', 'c' or 'h' if the first color is a LCHColor. For any color space the parameter 't' will return the minimal transparency.
        `vals` - A set of colors. Best case: All colors are members of the same color space and this color space correlates to the color channel which the minimum should be calculated. Example: All colors are RGBColor and the channel is 'r' for minimal red. Minimal case: The first color of the set is member of the color space which correlates to the given channel. Example: First color of vals is a LabColor and the channel is 'l' for minimal luminance.
      Returns:
        The minimal color value of the given set. -1 will be returned if the input is empty.

    - #### max

          public static float max(float... vals)

      Returns the maximal value found in the set of the input.
      Parameters:
        `vals` - A set of float values.
      Returns:
        The maximal float value of the given set. -1 will be returned if the input is empty.

    - #### max

          public static int max(int... vals)

      Returns the maximal value found in the set of the input.
      Parameters:
        `vals` - A set of int values.
      Returns:
        The maximal int value of the given set. -1 will be returned if the input is empty.

    - #### max

          public static float max(char channel,
                                  RColor... vals)

      Returns the maximal color value found in the set of the input.
      Parameters:
        `channel` - The color channel. Either 'r', 'g' or 'b' when first color of vals is a RGBColor, 'h', 's' or 'b' when first color of vals is a HSBColor, 'x', 'y' or 'z' if first color of vals is a XYZColor, 'l', 'a' or 'b' if first color is a LabColor, 'l', 'c' or 'h' if the first color is a LCHColor. For any color space the parameter 't' will return the maximal transparency.
        `vals` - A set of colors. Best case: All colors are members of the same color space and this color space correlates to the color channel which the minimum should be calculated. Example: All colors are RGBColor and the channel is 'r' for maximal red. Minimal case: The first color of the set is member of the color space which correlates to the given channel. Example: First color of vals is a LabColor and the channel is 'l' for maximal luminance.
      Returns:
        The maximal color value of the given set. -1 will be returned if the input is empty.

    - #### max

          public static float[] max(ColorSpace space,
                                    RColor... vals)

      Calculates the the maximal values of all color channels of the given color set. The color set will be converted to the given color space and the color space will define which minimal values should be calculated. Example: If ColorSpace.RGBColor is the given color space then the output will be the maximal red, green, blue and alpha.
      Parameters:
        `space` - The color space which defines which maximal values should be calculated.
        `vals` - A set of colors.
      Returns:
        The maximal values of the channels. Depending on the given color spaces these are: [r, g, b, alpha], [h, s, b, alpha], [x, y, z, alpha], [l, a, b, alpha], [l, c, h, alpha]. null will be returned if the input is empty.

    - #### range

          public static int[] range(int... vals)

      Calculates the range (minimum and maximum values) of the given set.
      Parameters:
        `vals` - A set of int values.
      Returns:
        The minimum and maximum values found in the set [min, max]. null will be returned if the input is empty.

    - #### range

          public static float[] range(float... vals)

      Calculates the range (minimum and maximum values) of the given set.
      Parameters:
        `vals` - A set of float values.
      Returns:
        The minimum and maximum values found in the set [min, max]. null will be returned if the input is empty.

    - #### range

          public static float[] range(ColorSpace space,
                                      RColor... vals)

      Calculates the range (minimum and maximum values) of all color channels the given color set. The color set will be converted to the given color space and the color space will define which minimal values should be calculated. Example: If ColorSpace.RGBColor is the given color space then the output will be the minimal red, green, blue and alpha.
      Parameters:
        `space` - The color space which defines which minimal values should be calculated.
        `vals` - A set of colors.
      Returns:
        The range of the channels. Depending on the given color spaces these are: [minR, minG, minB, minAlpha, maxR, maxG, maxB, maxAlpha], [minH, minS, minV, minAlpha, maxH, maxS, maxV, maxAlpha], [[minX, minY, minZ, minAlpha], [maxX, maxY, maxZ, maxAlpha], [minL, minA, minB, minAlpha, maxL, maxA, maxB, maxAlpha], [minL, minC, minH, minAlpha, maxL, maxC, maxH, maxAlpha]. The first four elements of the output array will always be the minimal values, the last for elements will be the maximum values. null will be returned if the input is empty.

    - #### range

          public static float[] range(processing.core.PVector... vals)

      Calculates the range (minimum x / y and maximum x / y values) of the given set.
      Parameters:
        `vals` - A set of PVector values.
      Returns:
        The minimum and maximum values found in the set [minX, minY, maxX, maxY]. null will be returned if the input is empty.

    - #### minIndex

          public static int minIndex(int... vals)

      Returns the index of the minimal value found in the set of the input.
      Parameters:
        `vals` - A set of int values.
      Returns:
        The index where the minimal value is found or -1 if input was empty. If the input set contains the minimum more than once, the first occurrence is returned.

    - #### minIndex

          public static int minIndex(float... vals)

      Returns the index of the minimal value found in the set of the input.
      Parameters:
        `vals` - A set of float values.
      Returns:
        The index where the minimal value is found or -1 if input was empty. If the input set contains the minimum more than once, the first occurrence is returned.

    - #### maxIndex

          public static int maxIndex(int... vals)

      Returns the index of the maximal value found in the set of the input.
      Parameters:
        `vals` - A set of int values.
      Returns:
        The index where the maximal value is found or -1 if input was empty. If the input set contains the maximum more than once, the first occurrence is returned.

    - #### maxIndex

          public static int maxIndex(float... vals)

      Returns the index of the maximal value found in the set of the input.
      Parameters:
        `vals` - A set of float values.
      Returns:
        The index where the maximal value is found or -1 if input was empty. If the input set contains the maximum more than once, the first occurrence is returned.