Package de.sciss.util
Class NumberSpace
- java.lang.Object
-
- de.sciss.util.NumberSpace
-
- Direct Known Subclasses:
ParamSpace
public class NumberSpace extends java.lang.ObjectA number space describes a field of possible numeric values with a minimum and maximum (which can be infinity), a central value (usually zero) a quantization size which can be used to describe integers or to limit the numeric resolution.
-
-
Field Summary
Fields Modifier and Type Field Description static NumberSpacegenericDoubleSpaceReady-made NumberField for double values, without boundaries.static NumberSpacegenericIntSpaceReady-made NumberField for integer values, without boundaries.doublemaxMaximum allowed value or Double.POSITIVE_INFINITYintmaxFracDigitsdoubleminMinimum allowed value or Double.NEGATIVE_INFINITYintminFracDigitsdoublequantQuantization of values or zerodoubleresetReset value, i.e.
-
Constructor Summary
Constructors Constructor Description NumberSpace(double min, double max, double quant)Creates a new NumberSpace with the given values.NumberSpace(double min, double max, double quant, int minFracDigits, int maxFracDigits)Creates a new NumberSpace with the given values.NumberSpace(double min, double max, double quant, int minFracDigits, int maxFracDigits, double reset)Creates a newNumberSpacewith the given values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static NumberSpacecreateIntSpace(int min, int max)Utility method for creating a generic integer space for a given minimum and maximum value.doublefitValue(double value)Validates a value for this number space.static doublefitValue(double value, double min, double max, double quant)Validates a value for an ad-hoc number space.static intfracDigitsFromQuant(double quant)booleanisInteger()States if the NumberSpace's quant is integer (and not zero).
-
-
-
Field Detail
-
min
public final double min
Minimum allowed value or Double.NEGATIVE_INFINITY
-
max
public final double max
Maximum allowed value or Double.POSITIVE_INFINITY
-
quant
public final double quant
Quantization of values or zero
-
reset
public final double reset
Reset value, i.e. a kind of default value.
-
minFracDigits
public final int minFracDigits
-
maxFracDigits
public final int maxFracDigits
-
genericDoubleSpace
public static NumberSpace genericDoubleSpace
Ready-made NumberField for double values, without boundaries.
-
genericIntSpace
public static NumberSpace genericIntSpace
Ready-made NumberField for integer values, without boundaries.
-
-
Constructor Detail
-
NumberSpace
public NumberSpace(double min, double max, double quant, int minFracDigits, int maxFracDigits, double reset)Creates a newNumberSpacewith the given values.- Parameters:
min- minimum allowed value or a special value like Double.NEGATIVE_INFINITY or Integer.MIN_VALUEmax- maximum allowed value or a special value like Float.POSITIVE_INFINITY or Long.MAX_VALUEquant- coarsity for each allowed value. E.g. if quant is 0.1, then a value of 0.12 becomes 0.1 if you call fitValue. If quant is 0.0, no quantization is used. If quant is integer, the number space is marked integer and calling isInteger returns true.reset- central value for initializations of unknown values. Usually zero.
-
NumberSpace
public NumberSpace(double min, double max, double quant, int minFracDigits, int maxFracDigits)Creates a new NumberSpace with the given values. Reset is zero or on of min/max, increment is max( 1, quant )
-
NumberSpace
public NumberSpace(double min, double max, double quant)Creates a new NumberSpace with the given values. Reset is zero or on of min/max, increment is max( 1, quant )
-
-
Method Detail
-
fracDigitsFromQuant
public static int fracDigitsFromQuant(double quant)
-
isInteger
public boolean isInteger()
States if the NumberSpace's quant is integer (and not zero).- Returns:
- true if the quantization is integer and hence all valid values are integers
-
createIntSpace
public static NumberSpace createIntSpace(int min, int max)
Utility method for creating a generic integer space for a given minimum and maximum value. Quant will be set to 1.0.
-
fitValue
public double fitValue(double value)
Validates a value for this number space. First, it is quantized (rounded) if necessary. Then it is limited to the minimum and maximum value.- Parameters:
value- a value to validate- Returns:
- the input value possibly quantisized and limited the space's bounds.
-
fitValue
public static double fitValue(double value, double min, double max, double quant)Validates a value for an ad-hoc number space. First, it is quantized (rounded) if necessary. Then it is limited to the minimum and maximum value.- Parameters:
value- a value to validatemin- the minimum limitationmax- the maximum limitationquant- the quantization to apply- Returns:
- the input value possibly quantisized and limited the described space's bounds.
-
-