{
//This function is known as a "stitching" function. Based on the input, it decides which child function to call.
//See PDF Reference section 3.9.3.
PDFunction function = null;
float x = ((COSFloat)input.get(0)).floatValue();
PDRange domain = getDomainForInput(1);
// clip input value to domain
x = clipToRange(x, domain.getMin(), domain.getMax());
float[] boundsValues = getBounds().toFloatArray();
int boundsSize = boundsValues.length;
if (boundsSize == 0 || x < boundsValues[0])
{
function = PDFunction.create(getFunctions().get(0));
PDRange encode = getEncodeForParameter(0);
if (boundsSize == 0)
{
x = interpolate(x, domain.getMin(), domain.getMax(), encode.getMin(), encode.getMax());
}
else
{
x = interpolate(x, domain.getMin(), boundsValues[0], encode.getMin(), encode.getMax());
}
}
else
{
for (int i=0; i<boundsSize-1; i++)
{
if ( x >= boundsValues[i] && x < boundsValues[i+1] )
{
function = PDFunction.create(getFunctions().get(i+1));
PDRange encode = getEncodeForParameter(i+1);
x = interpolate(x, boundsValues[i], boundsValues[i+1], encode.getMin(), encode.getMax());
break;
}
}
if(function==null) //must be in last partition
{
function = PDFunction.create(getFunctions().get(boundsSize+1));
PDRange encode = getEncodeForParameter(boundsSize+1);
x = interpolate(x, boundsValues[boundsSize-1], domain.getMax(), encode.getMin(), encode.getMax());
}
}
COSArray functionValues = new COSArray();
functionValues.add(new COSFloat(x));
COSArray functionResult = function.eval(functionValues);