sbool iiSumRect_debug; static double iiSumRect(double[][] ii, Rect r) { if (r.y2() == 0 || r.x2() == 0) ret 0; double bottomLeft = r.x == 0 ? 0 : ii[r.y2()-1][r.x-1]; double bottomRight = ii[r.y2()-1][r.x2()-1]; double topLeft = r.x == 0 || r.y == 0 ? 0 : ii[r.y-1][r.x-1]; double topRight = r.y == 0 ? 0 : ii[r.y-1][r.x2()-1]; double result = bottomRight+topLeft-topRight-bottomLeft; if (iiSumRect_debug) printVars(+topLeft, +topRight, +bottomLeft, +bottomRight, +result); //ret bottomRight-topLeft-(topRight-topLeft)-(bottomLeft-topLeft); //ret bottomRight+topLeft-(topRight+bottomLeft); ret result; }