/// Evolver Copyright 2000, Morgan McGuire
/// matrix@alum.mit.edu   http://graphics3d.com/matrix
public class Trail extends OneArgumentOperator implements ELOperator
{
    // Trail is a function of one argument, "X".  The body of trail
    // (which may NOT be recursive) is:
    final private static String exprString = 
	"Max([X], Max(Sub(Hysteresis(), 0.02), 0.0))";

    private static ELExpression expression = null;

    static synchronized private void lazyInit() 
    {
	if (expression == null) {
	    // Compile this into an EL Expression.
	    expression = new GeneticParameters(".").parseELExpression(exprString);
	}
    }

    public void apply(ELMatrix argument[], ELMatrix out, ELEnvironment environment)
    {
	lazyInit();

	checkArguments(argument);
	
	// Apply to the argument.
	expression.evaluate(out, environment, new ParameterList(new Object[]{"X", argument[0]}));
    }
    
    public String name()
    {
	return "Trail";
    }
    
    public String description()
    {
	return exprString;
    }  
}

