//This function is known as a "stitching" function. Based on the input, it decides which child function to call.
// All functions in the array are 1-value-input functions
//See PDF Reference section 3.9.3.
PDFunction function = null;
float x = input[0];
PDRange domain = getDomainForInput(0);
// clip input value to domain
x = clipToRange(x, domain.getMin(), domain.getMax());
COSArray functionsArray = getFunctions();
int numberOfFunctions = functionsArray.size();
// This doesn't make sense but it may happen ...
if (numberOfFunctions == 1)
{
function = PDFunction.create(functionsArray.get(0));
PDRange encRange = getEncodeForParameter(0);
x = interpolate(x, domain.getMin(), domain.getMax(), encRange.getMin(), encRange.getMax());
}
else
{
float[] boundsValues = getBounds().toFloatArray();
int boundsSize = boundsValues.length;
// create a combined array containing the domain and the bounds values
// domain.min, bounds[0], bounds[1], ...., bounds[boundsSize-1], domain.max
float[] partitionValues = new float[boundsSize+2];
int partitionValuesSize = partitionValues.length;
partitionValues[0] = domain.getMin();
partitionValues[partitionValuesSize-1] = domain.getMax();
System.arraycopy(boundsValues, 0, partitionValues, 1, boundsSize);
// find the partition
for (int i=0; i < partitionValuesSize-1; i++)
{
if ( x >= partitionValues[i] &&
(x < partitionValues[i+1] || (i == partitionValuesSize - 2 && x == partitionValues[i+1])))
{
function = PDFunction.create(functionsArray.get(i));
PDRange encRange = getEncodeForParameter(i);
x = interpolate(x, partitionValues[i], partitionValues[i+1], encRange.getMin(), encRange.getMax());
break;
}
}
}
float[] functionValues = new float[]{x};