/// Evolver Copyright 2000, Morgan McGuire
/// matrix@alum.mit.edu   http://graphics3d.com/matrix
import java.awt.*;

public abstract class OneArgumentOperator extends AbstractELOperator implements ELOperator
{
  public void apply(ELMatrix argument[], ELMatrix out, ELEnvironment environment)
  {
    checkArguments(argument);
        
    // For extra performance, pull the arrays into locals so we avoid
    // excess dereferences.
    float red[] = out.red;
    float grn[] = out.grn;
    float blu[] = out.blu;

    ELMatrix arg = argument[0];
    float ared[] = arg.red;
    float agrn[] = arg.grn;
    float ablu[] = arg.blu;
    
    for(int i = red.length - 1; i >= 0; i--) {
      red[i] = function(ared[i]);
      grn[i] = function(agrn[i]);
      blu[i] = function(ablu[i]);
    }
  }

  /**
   * Your element wise operator.
   */
  protected float function(float f)
  {
    throw new Error("Override apply() or function()");
  }

  public int getMaxNumArguments()
  {
    return 1;
  }

  public int getMinNumArguments()
  {
    return 1;
  }

  public String unparse()
  {
    return name();
  }

}
