physFromIndex method

double physFromIndex (double index, double physStart, double physWidth, int n, bool center, bool increasing, double calib)

Returns the physical unit for index. Assume you have a data array of n points. You want to assign each index of the array a "physical unit", e.g. seconds, Hertz, or whatever. Also assume that there is a linear relationship between indices and unit. physStart is the unit for index=0. physWidth is the unit range covered by all indices, from the first to the last one. center defines whether the computed unit value corresponds exactly to index (if false), or to the mean value between to subsequent indices (if true). Either choice can be convenient, depending on the application. increasing defines whether physXRangeStart will be the smallest value (true, increasing units), or the biggest one (false: decreasing unit). calib is an optional calibration factor. If not null, both physStart and physWidth are multiplied with calib.

Implementation

static double physFromIndex(double index, double physStart, double physWidth,
    int n, bool center, bool increasing, double calib) {
  if (calib != null) {
    physStart *= calib;
    physWidth *= calib;
  }
  double physX;
  double delta = physWidth / n; // we'll get n sections of length delta
  if (!increasing) delta = -delta;
  if (center) {
    physX = physStart + (index + 0.5) * delta;
  } else {
    // make increasing x values! (as expected by axis drawing)
    physX = physStart + index * delta;
  }
  return physX;
}