physToIndex method

double physToIndex (double physX, double physStart, double physWidth, int n, bool center, bool increasing, double calib)

This is the inverse of getPhysXFromDataIndex: Returns the index corresponding to the physcial unit physX.

Implementation

static double physToIndex(double physX, double physStart, double physWidth,
    int n, bool center, bool increasing, double calib) {
  if (calib != null) {
    physStart *= calib;
    physWidth *= calib;
  }
  double index;
  double delta = physWidth / n; // we'll get n sections of length delta
  if (!increasing) delta = -delta;

  if (center)
    index = (physX - physStart) / delta - 0.5;
  else
    index = (physX - physStart) / delta;

  return index;
}