computeMoments method
Implementation
void computeMoments() {
for (var r = 1; r < sideLength; ++r) {
List<int> area = List.filled(sideLength, 0, growable: false);
List<int> areaR = List.filled(sideLength, 0, growable: false);
List<int> areaG = List.filled(sideLength, 0, growable: false);
List<int> areaB = List.filled(sideLength, 0, growable: false);
List<double> area2 = List.filled(sideLength, 0.0, growable: false);
for (var g = 1; g < sideLength; g++) {
int line = 0;
int lineR = 0;
int lineG = 0;
int lineB = 0;
double line2 = 0.0;
for (var b = 1; b < sideLength; b++) {
int index = getIndex(r, g, b);
line += weights[index];
lineR += momentsR[index];
lineG += momentsG[index];
lineB += momentsB[index];
line2 += moments[index];
area[b] += line;
areaR[b] += lineR;
areaG[b] += lineG;
areaB[b] += lineB;
area2[b] += line2;
int previousIndex = getIndex(r - 1, g, b);
weights[index] = weights[previousIndex] + area[b];
momentsR[index] = momentsR[previousIndex] + areaR[b];
momentsG[index] = momentsG[previousIndex] + areaG[b];
momentsB[index] = momentsB[previousIndex] + areaB[b];
moments[index] = moments[previousIndex] + area2[b];
}
}
}
}