AlgART Home
net.algart.math.functions

## Interface Func

• ### Nested Class Summary

Nested Classes
Modifier and Type Interface and Description
`static interface ` `Func.Updatable`
"Updatable" mathematical function: an extension of `Func` interface allowing assigning values to the function result, that leads to corresponding correction of arguments.
• ### Field Summary

Fields
Modifier and Type Field and Description
`static Func` `ABS`
Absolute value function: f(x0) = |x0|.
`static Func` `ABS_DIFF`
Absolute value of the difference of 2 numbers: f(x0, x1) = |x0-x1|.
`static 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)`.
`static 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)`.
`static 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)`.
`static Func` `IDENTITY`
Identity function, just returning its first argument: f(x0, x1, ..., xn-1) = x0.
`static Func` `MAX`
Maximum from several numbers: f(x0, x1, ..., xn-1) = max(x0, x1, ..., xn-1).
`static Func` `MIN`
Minimum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1).
`static Func` `POSITIVE_DIFF`
Positive difference of 2 numbers: f(x0, x1) = max(x0-x1,0).
`static LinearFunc` `REVERSE`
An instance of `LinearFunc` class, describing the linear function 1.0 - x0: `LinearFunc.getInstance(1.0, -1.0)`.
`static Func` `SELECT`
Select function: f(x0, x1, ..., xn-1) = xi+1, where i is x0 cast to integer type: i=(int)x[0].
`static Func` `SELECT_FROM_8_DIRECTIONS_2D`
Selecting from 8 "integer" directions on 2D plane: f(x0, x1) = integer code from 1 to 8.
`static Func` `SELECT_IF_GREATER`
Select function: f(x0, x1, x2, x3) = x0 > x1 ? x2 : x3.
`static Func` `SELECT_IF_GREATER_OR_EQUAL`
Select function: f(x0, x1, x2, x3) = x0 >= x1 ? x2 : x3.
`static java.util.List<IPoint>` `SHIFTS_ALONG_8_DIRECTIONS_2D`
Vectors, corresponding to 8 directions recognized by `SELECT_FROM_8_DIRECTIONS_2D` function.
`static Func.Updatable` `UPDATABLE_IDENTITY`
Updatable version of `IDENTITY` function.
`static LinearFunc` `X_MINUS_Y`
An instance of `LinearFunc` class, describing the linear function x0 - x1: `LinearFunc.getInstance(0.0, 1.0, -1.0)`.
`static LinearFunc` `X_PLUS_Y`
An instance of `LinearFunc` class, describing the linear function x0 + x1: `LinearFunc.getInstance(0.0, 1.0, 1.0)`.
`static LinearFunc` `Y_MINUS_X`
An instance of `LinearFunc` class, describing the linear function x1 - x0: `LinearFunc.getInstance(0.0, -1.0, 1.0)`.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`double` `get()`
Equivalent to `get`(new double[0]).
`double` `get(double... x)`
Returns the result of this function for the given arguments: f(x0, x1, ..., xx.length-1).
`double` `get(double x0)`
Equivalent to `get`(new double[] {x0}).
`double` ```get(double x0, double x1)```
Equivalent to `get`(new double[] {x0, x1}).
`double` ```get(double x0, double x1, double x2)```
Equivalent to `get`(new double[] {x0, x1, x2}).
`double` ```get(double x0, double x1, double x2, double x3)```
Equivalent to `get`(new double[] {x0, x1, x2, x3}).
• ### Field Detail

• #### 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. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

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. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

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. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

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. All calculations are performed in strictfp mode, so the result is absolutely identical on all platforms.

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

• ### Method Detail

• #### 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:
`java.lang.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:
`java.lang.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:
`java.lang.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:
`java.lang.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:
`java.lang.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:
`java.lang.IndexOutOfBoundsException` - may be thrown this function requires at least 5 arguments.