package nxm.sys.libm;

import nxm.sys.inc.Constants;

/**
   Performs the ArcTan2 operation on arrays. <br>
   See {@link Operator} for a description of the available I/O Modes.
   @author  Auto-Generated
   @see     Operator
*/
@SuppressWarnings("cast")
public final class ArcTan2 extends Operator implements Constants {

  /** Create a new instance. */
  public ArcTan2() {
    super();
  }

  /** Create a new instance.
      @param flags The processing flags to use.
   */
  public ArcTan2 (int flags) {
    super(flags);
  }

  /** Create a new instance.
      @param scale The scale factor to use.
   */
  public ArcTan2 (double scale) {
    super(scale);
  }

  /** Create a new instance.
      @param flags The processing flags to use.
      @param scale The scale factor to use.
   */
  public ArcTan2 (int flags, double scale) {
    super(flags,scale);
  }

  public final int validate (char type, int n, int mode) {
    switch (mode) {
      case SSS: return n;
      default: return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode) {
    switch (mode) {
      case SSS: SSS(v[0],v[1],v[2],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (double[][] v, int n, int mode, double scale) {
    switch (mode) {
      case SSS: SSS(v[0],v[1],v[2],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#SSS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(double[][],int,int,double)
   */
  public static final void SSS (double[] a, double[] b, double[] c, int n, double scale) {
    if (b.length == 1) {
      for (int i=0; i<n; i++) {
        c[i]=(double)(scale*Math.atan2((double)b[0],(double)a[i]));
      }
    } else if (a.length == 1) {
      for (int i=0; i<n; i++) {
        c[i]=(double)(scale*Math.atan2((double)b[i],(double)a[0]));
      }
    } else {
      for (int i=0; i<n; i++) {
        c[i]=(double)(scale*Math.atan2((double)b[i],(double)a[i]));
      }
    }
  }

  public final int process (float[][] v, int n, int mode) {
    switch (mode) {
      case SSS: SSS(v[0],v[1],v[2],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (float[][] v, int n, int mode, double scale) {
    switch (mode) {
      case SSS: SSS(v[0],v[1],v[2],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#SSS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(float[][],int,int,double)
   */
  public static final void SSS (float[] a, float[] b, float[] c, int n, double scale) {
    if (b.length == 1) {
      for (int i=0; i<n; i++) {
        c[i]=(float)(scale*Math.atan2((double)b[0],(double)a[i]));
      }
    } else if (a.length == 1) {
      for (int i=0; i<n; i++) {
        c[i]=(float)(scale*Math.atan2((double)b[i],(double)a[0]));
      }
    } else {
      for (int i=0; i<n; i++) {
        c[i]=(float)(scale*Math.atan2((double)b[i],(double)a[i]));
      }
    }
  }

  public final int process (int[][] v, int n, int mode) {
    switch (mode) {
      case SSS: SSS(v[0],v[1],v[2],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  public final int process (int[][] v, int n, int mode, double scale) {
    switch (mode) {
      case SSS: SSS(v[0],v[1],v[2],n, scale); return n;
      default:  return NOSUPPORT;
    }
  }

  /** Apply this operator to mode {@link Operator#SSS} data.
      @param a     The first  operand.
      @param b     The second  operand.
      @param c     The third  operand.
      @param n     The number of elements to operate on.
      @param scale The scale factor.
      @see #process(int[][],int,int,double)
   */
  public static final void SSS (int[] a, int[] b, int[] c, int n, double scale) {
    if (b.length == 1) {
      for (int i=0; i<n; i++) {
        c[i]=(int)(scale*Math.atan2((double)b[0],(double)a[i]));
      }
    } else if (a.length == 1) {
      for (int i=0; i<n; i++) {
        c[i]=(int)(scale*Math.atan2((double)b[i],(double)a[0]));
      }
    } else {
      for (int i=0; i<n; i++) {
        c[i]=(int)(scale*Math.atan2((double)b[i],(double)a[i]));
      }
    }
  }

  public int getInputs() { return 2; }
  public int getOutputs() { return 1; }
}
