Interface Func

All Known Subinterfaces:
Func.Updatable
All Known Implementing Classes:
AbstractFunc, ApertureFilteredFunc, AverageExceptingNaN, ConstantFunc, ContrastingFunc, CoordinateTransformedFunc, DividingFunc, ExpFunc, FirstExceptingNaN, HyperboloidOfRevolutionFunc, InverseNumberFunc, InverseNumberFunc.Updatable, LastExceptingNaN, LinearFunc, LinearFunc.Updatable, LogFunc, MaxExceptingNaN, MaxFromTwoSelectedNumbersFunc, MinExceptingNaN, MinFromTwoSelectedNumbersFunc, MultiplyingFunc, ParaboloidOfRevolutionFunc, PowerFunc, PowerFunc.Updatable, RectangularFunc, SelectConstantFunc, UpperHalfEllipsoidOfRevolutionFunc, WeightedMeanFunc

public interface Func

Abstract mathematical function f(x0, x1, ..., xn-1), or f(x), where x is a point of the n-dimensional space.

Implementations of this interface are usually immutable and always thread-safe: get methods of this interface may be freely used while simultaneous accessing to the same instance from several threads. All implementations of this interface from this package are immutable.

Author:
Daniel Alievsky
  • Field Details

    • IDENTITY

      static final Func IDENTITY
      Identity function, just returning its first argument: f(x0, x1, ..., xn-1) = x0. The get(double...) method of this object requires at least 1 argument and throws IndexOutOfBoundsException if the number of arguments is 0.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • UPDATABLE_IDENTITY

      static final Func.Updatable UPDATABLE_IDENTITY
      Updatable version of IDENTITY function.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • MAX

      static final Func MAX
      Maximum from several numbers: f(x0, x1, ..., xn-1) = max(x0, x1, ..., xn-1). The get(double...) method of this object may process any number of arguments. If the number of arguments is 0, it returns Double.NEGATIVE_INFINITY.

      Unlike standard Math.max method, this function supposes that max(x,y) = x>y ? x : y

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • MIN

      static final Func MIN
      Minimum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1). The get(double...) method of this object may process any number of arguments. If the number of arguments is 0, it returns Double.POSITIVE_INFINITY.

      Unlike standard Math.min method, this function supposes that min(x,y) = x<y ? x : y

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • ABS

      static final Func ABS
      Absolute value function: f(x0) = |x0|. More precisely, the result of this function is StrictMath.abs(x[0]). The get(double...) method of this object requires at least 1 argument and throws IndexOutOfBoundsException if the number of arguments is 0.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • ABS_DIFF

      static final Func ABS_DIFF
      Absolute value of the difference of 2 numbers: f(x0, x1) = |x0-x1|. The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • POSITIVE_DIFF

      static final Func POSITIVE_DIFF
      Positive difference of 2 numbers: f(x0, x1) = max(x0-x1,0). The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • X_PLUS_Y

      static final LinearFunc X_PLUS_Y
      An instance of LinearFunc class, describing the linear function x0 + x1: LinearFunc.getInstance(0.0, 1.0, 1.0).

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • X_MINUS_Y

      static final LinearFunc X_MINUS_Y
      An instance of LinearFunc class, describing the linear function x0 - x1: LinearFunc.getInstance(0.0, 1.0, -1.0).

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • Y_MINUS_X

      static final LinearFunc Y_MINUS_X
      An instance of LinearFunc class, describing the linear function x1 - x0: LinearFunc.getInstance(0.0, -1.0, 1.0).

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • HALF_X_PLUS_Y

      static final LinearFunc HALF_X_PLUS_Y
      An instance of LinearFunc class, describing the linear function (x0 + x1)/2: LinearFunc.getInstance(0.0, 0.5, 0.5).

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • HALF_X_MINUS_Y

      static final LinearFunc HALF_X_MINUS_Y
      An instance of LinearFunc class, describing the linear function (x0 - x1)/2: LinearFunc.getInstance(0.0, 0.5, -0.5).

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • HALF_Y_MINUS_X

      static final LinearFunc HALF_Y_MINUS_X
      An instance of LinearFunc class, describing the linear function (x1 - x0)/2: LinearFunc.getInstance(0.0, -0.5, 0.5).

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • REVERSE

      static final LinearFunc REVERSE
      An instance of LinearFunc class, describing the linear function 1.0 - x0: LinearFunc.getInstance(1.0, -1.0). This instance describes logical NOT operation in a case when the arguments are bits (0 and 1 values).

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • SELECT

      static final Func SELECT
      Select function: f(x0, x1, ..., xn-1) = xi+1, where i is x0 cast to integer type: i=(int)x[0]. The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • SELECT_IF_GREATER

      static final Func SELECT_IF_GREATER
      Select function: f(x0, x1, x2, x3) = x0 > x1 ? x2 : x3. The get(double...) method of this object requires at least 4 arguments and throws IndexOutOfBoundsException if the number of arguments is 0, 1, 2 or 3.

      Note: call of this function is almost equivalent to calling SELECT_IF_GREATER_OR_EQUAL function with another order of the arguments: f(x1, x0, x3, x2), that is x1 >= x0 ? x3 : x2. The only difference is connected with processing Double.NaN values of x0 and x1: this function will choose x3, but the corresponding call of SELECT_IF_GREATER_OR_EQUAL will choose x2, because in Java any comparison with Double.NaN returns false.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • SELECT_IF_GREATER_OR_EQUAL

      static final Func SELECT_IF_GREATER_OR_EQUAL
      Select function: f(x0, x1, x2, x3) = x0 >= x1 ? x2 : x3. The get(double...) method of this object requires at least 4 arguments and throws IndexOutOfBoundsException if the number of arguments is 0, 1, 2 or 3.

      Note: call of this function is almost equivalent to calling SELECT_IF_GREATER function with another order of the arguments: f(x1, x0, x3, x2), that is x1 > x0 ? x3 : x2. The only difference is connected with processing Double.NaN values of x0 and x1: this function will choose x3, but the corresponding call of SELECT_IF_GREATER will choose x2, because in Java any comparison with Double.NaN returns false.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • SELECT_FROM_8_DIRECTIONS_2D

      static final Func SELECT_FROM_8_DIRECTIONS_2D
      Selecting from 8 "integer" directions on 2D plane: f(x0, x1) = integer code from 1 to 8. The result of this function is the index of one of 8 sectors, where the 2-dimensional vector (x0,x1) lies. Namely, let φ=Math.atan2(x1,x0), more precisely, an equivalent angle in 0°..360° range. The result of this function is:
      • 0, if 337.5° < φ ≤ 22.5° and also in the special case x0=x1=0.0;
      • 1, if 22.5° < φ ≤ 67.5°;
      • 2, if 67.5° < φ ≤ 112.5°;
      • 3, if 112.5° < φ ≤ 157.5°;
      • 4, if 157.5° < φ ≤ 202.5°;
      • 5, if 202.5° < φ ≤ 247.5°;
      • 6, if 247.5° < φ ≤ 292.5°;
      • 7, if 292.5° < φ ≤ 337.5°.

      (A strange formula "337.5° < φ ≤ 22.5°" just means that the direction lies between 337.5°=-22.5° and +22.5° — in other words, "almost rightward" along X axis.)

      This function is useful while processing 2-dimensional matrices, for example, in algorithms like Canny edge detector.

      The get(double...) method of this object requires at least 2 arguments and throws IndexOutOfBoundsException if the number of arguments is 0 or 1.

      This instance is immutable and thread-safe: there are no ways to modify its settings.

    • SHIFTS_ALONG_8_DIRECTIONS_2D

      static final List<IPoint> SHIFTS_ALONG_8_DIRECTIONS_2D
      Vectors, corresponding to 8 directions recognized by SELECT_FROM_8_DIRECTIONS_2D function. More precisely, if is an unmodifiable list consisting of the following elements:
      1. IPoint.valueOf(1,0),
      2. IPoint.valueOf(1,1),
      3. IPoint.valueOf(0,1),
      4. IPoint.valueOf(-1,1),
      5. IPoint.valueOf(-1,0),
      6. IPoint.valueOf(-1,-1),
      7. IPoint.valueOf(0,-1),
      8. IPoint.valueOf(1,-1).

      So, if the direction returned by SELECT_FROM_8_DIRECTIONS_2D is n, then the corresponding "rounding" direction is described by SHIFTS_ALONG_8_DIRECTIONS_2D.get(n).

      This instance is immutable and thread-safe: there are no ways to modify it.

  • Method Details

    • get

      double get(double... x)
      Returns the result of this function for the given arguments: f(x0, x1, ..., xx.length-1).

      This method must not change the values of x elements!

      Parameters:
      x - the function arguments.
      Returns:
      the function result.
      Throws:
      IndexOutOfBoundsException - may be thrown if the number of passed arguments is less than the required number of this function arguments.
    • get

      double get()
      Equivalent to get(new double[0]). Provides better performance because it does not require Java array creation.
      Returns:
      the function result.
      Throws:
      IndexOutOfBoundsException - may be thrown this function requires at least 1 argument.
    • get

      double get(double x0)
      Equivalent to get(new double[] {x0}). Provides better performance because it does not require Java array creation.
      Parameters:
      x0 - the function argument.
      Returns:
      the function result.
      Throws:
      IndexOutOfBoundsException - may be thrown this function requires at least 2 arguments.
    • get

      double get(double x0, double x1)
      Equivalent to get(new double[] {x0, x1}). Provides better performance because it does not require Java array creation.
      Parameters:
      x0 - the first function argument.
      x1 - the second function argument.
      Returns:
      the function result.
      Throws:
      IndexOutOfBoundsException - may be thrown this function requires at least 3 arguments.
    • get

      double get(double x0, double x1, double x2)
      Equivalent to get(new double[] {x0, x1, x2}). Provides better performance because it does not require Java array creation.
      Parameters:
      x0 - the first function argument.
      x1 - the second function argument.
      x2 - the third function argument.
      Returns:
      the function result.
      Throws:
      IndexOutOfBoundsException - may be thrown this function requires at least 4 arguments.
    • get

      double get(double x0, double x1, double x2, double x3)
      Equivalent to get(new double[] {x0, x1, x2, x3}). Provides better performance because it does not require Java array creation.
      Parameters:
      x0 - the first function argument.
      x1 - the second function argument.
      x2 - the third function argument.
      x3 - the fourth function argument.
      Returns:
      the function result.
      Throws:
      IndexOutOfBoundsException - may be thrown this function requires at least 5 arguments.