int TileBoundsCalculator::_calculateSplitX(PixelBox& b) { double total = _sumPixels(b); double left = _sumPixels(b.getColumnBox(b.minX)); int best = (b.maxX + b.minX) / 2; double bestSum = numeric_limits<double>::max(); double thisSlop = _slop + 1.0 / (double)(b.maxX - b.minX); if (b.getWidth() < 6) { throw HootException("The input box must be at least six pixels high."); } for (int c = b.minX + 2; c < b.maxX - 2; c++) { double colSum = _sumPixels(b.getColumnBox(c)); double colSumMin = _sumPixels(b.getColumnBox(c), _min) + _sumPixels(b.getColumnBox(c + 1), _min); left += colSum; double slop = abs(0.5 - left / total); if ((slop < thisSlop) && colSumMin < bestSum) { best = c; bestSum = colSumMin; } } if (bestSum == numeric_limits<double>::max()) { LOG_WARN("bestSum isn't valid. " << b.toString()); } return best; }