addArrays method

Float64List addArrays (Float64List a1, Float64List a2, int type)

Returns the index-wise sum of a1 and a2 according to type: type = POS: adds the positive or zero values of a1 and a2 only type = NEG: adds the negative or zero values of a1 and a2 only type = POSNEG: normal add of all values Application: Building "projections".

Implementation

static Float64List addArrays(Float64List a1, Float64List a2, int type) {
  assert(a1.length == a2.length);

  Float64List result = new Float64List(a1.length);
  double sum;
  bool doSum;

  for (int i = 0; i < a1.length; i++) {
    sum = 0.0;
    doSum = false;
    if (type == POSNEG)
      doSum = true;
    else if (type == POS && a1[i] >= 0 && a2[i] >= 0)
      doSum = true;
    else if (type == NEG && a1[i] <= 0 && a2[i] <= 0) doSum = true;

    if (doSum) sum = a1[i] + a2[i];

    result[i] = sum;
  }

  return result;
}