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
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
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic interface
"Updatable" mathematical function: an extension ofFunc
interface allowing assigning values to the function result, that leads to corresponding correction of arguments. -
Field Summary
Modifier and TypeFieldDescriptionstatic final Func
Absolute value function: f(x0) = |x0|.static final Func
Absolute value of the difference of 2 numbers: f(x0, x1) = |x0-x1|.static final LinearFunc
An instance ofLinearFunc
class, describing the linear function (x0 - x1)/2:LinearFunc.getInstance(0.0, 0.5, -0.5)
.static final LinearFunc
An instance ofLinearFunc
class, describing the linear function (x0 + x1)/2:LinearFunc.getInstance(0.0, 0.5, 0.5)
.static final LinearFunc
An instance ofLinearFunc
class, describing the linear function (x1 - x0)/2:LinearFunc.getInstance(0.0, -0.5, 0.5)
.static final Func
Identity function, just returning its first argument: f(x0, x1, ..., xn-1) = x0.static final Func
Maximum from several numbers: f(x0, x1, ..., xn-1) = max(x0, x1, ..., xn-1).static final Func
Minimum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1).static final Func
Positive difference of 2 numbers: f(x0, x1) = max(x0-x1,0).static final LinearFunc
An instance ofLinearFunc
class, describing the linear function 1.0 - x0:LinearFunc.getInstance(1.0, -1.0)
.static final Func
Select function: f(x0, x1, ..., xn-1) = xi+1, where i is x0 cast to integer type: i=(int)x[0].static final Func
Selecting from 8 "integer" directions on 2D plane: f(x0, x1) =integer code from 1 to 8 .static final Func
Select function: f(x0, x1, x2, x3) = x0 > x1 ? x2 : x3.static final Func
Select function: f(x0, x1, x2, x3) = x0 >= x1 ? x2 : x3.Vectors, corresponding to 8 directions recognized bySELECT_FROM_8_DIRECTIONS_2D
function.static final Func.Updatable
Updatable version ofIDENTITY
function.static final LinearFunc
An instance ofLinearFunc
class, describing the linear function x0 - x1:LinearFunc.getInstance(0.0, 1.0, -1.0)
.static final LinearFunc
An instance ofLinearFunc
class, describing the linear function x0 + x1:LinearFunc.getInstance(0.0, 1.0, 1.0)
.static final LinearFunc
An instance ofLinearFunc
class, describing the linear function x1 - x0:LinearFunc.getInstance(0.0, -1.0, 1.0)
. -
Method Summary
Modifier and TypeMethodDescriptiondouble
get()
Equivalent toget
(new double[0]).double
get
(double x0) Equivalent toget
(new double[] {x0}).double
get
(double... x) Returns the result of this function for the given arguments: f(x0, x1, ..., xx.length-1).double
get
(double x0, double x1) Equivalent toget
(new double[] {x0, x1}).double
get
(double x0, double x1, double x2) Equivalent toget
(new double[] {x0, x1, x2}).double
get
(double x0, double x1, double x2, double x3) Equivalent toget
(new double[] {x0, x1, x2, x3}).
-
Field Details
-
IDENTITY
Identity function, just returning its first argument: f(x0, x1, ..., xn-1) = x0. Theget(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
Updatable version ofIDENTITY
function.This instance is immutable and thread-safe: there are no ways to modify its settings.
-
MAX
Maximum from several numbers: f(x0, x1, ..., xn-1) = max(x0, x1, ..., xn-1). Theget(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
Minimum from several numbers: f(x0, x1, ..., xn-1) = min(x0, x1, ..., xn-1). Theget(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
Absolute value function: f(x0) = |x0|. More precisely, the result of this function is StrictMath.abs(x[0]). Theget(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
Absolute value of the difference of 2 numbers: f(x0, x1) = |x0-x1|. Theget(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
Positive difference of 2 numbers: f(x0, x1) = max(x0-x1,0). Theget(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
An instance ofLinearFunc
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
An instance ofLinearFunc
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
An instance ofLinearFunc
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
An instance ofLinearFunc
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
An instance ofLinearFunc
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
An instance ofLinearFunc
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
An instance ofLinearFunc
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
Select function: f(x0, x1, ..., xn-1) = xi+1, where i is x0 cast to integer type: i=(int)x[0]. Theget(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
Select function: f(x0, x1, x2, x3) = x0 > x1 ? x2 : x3. Theget(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 isx1 >= 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 ofSELECT_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
Select function: f(x0, x1, x2, x3) = x0 >= x1 ? x2 : x3. Theget(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 isx1 > 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 ofSELECT_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
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
Vectors, corresponding to 8 directions recognized bySELECT_FROM_8_DIRECTIONS_2D
function. More precisely, if is an unmodifiable list consisting of the following elements:IPoint.valueOf(1,0)
,IPoint.valueOf(1,1)
,IPoint.valueOf(0,1)
,IPoint.valueOf(-1,1)
,IPoint.valueOf(-1,0)
,IPoint.valueOf(-1,-1)
,IPoint.valueOf(0,-1)
,IPoint.valueOf(1,-1)
.
So, if the direction returned by
SELECT_FROM_8_DIRECTIONS_2D
is n, then the corresponding "rounding" direction is described bySHIFTS_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 toget
(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 toget
(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 toget
(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 toget
(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 toget
(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.
-