int TileBoundsCalculator::_calculateSplitY(const PixelBox& b) { double total = _sumPixels(b); double bottom = _sumPixels(b.getRowBox(b.minY)); int best = (b.maxY + b.minY) / 2; double bestSum = numeric_limits<double>::max(); double thisSlop = _slop + 1.0 / (double)(b.maxY - b.minY); if (b.getHeight() < 6) { throw HootException("The input box must be at least six pixels high."); } for (int r = b.minY + 2; r < b.maxY - 2; r++) { double rowSum = _sumPixels(b.getRowBox(r)); double rowSumMin = _sumPixels(b.getRowBox(r), _min) + _sumPixels(b.getRowBox(r + 1), _min); bottom += rowSum; double slop = abs(0.5 - bottom / total); if ((slop < thisSlop) && rowSumMin < bestSum) { best = r; bestSum = rowSumMin; } } if (bestSum == numeric_limits<double>::max()) { LOG_WARN("bestSum isn't valid. " << b.toString() << " total: " << total << " size: " << b.maxY - b.minY); } return best; }