findLargestFittingResizePx static method
Binary search for the largest fitting step; 0.0 when nothing fits.
Implementation
static double findLargestFittingResizePx(
List<double> sortedStepsPx, bool Function(double) fits) {
if (sortedStepsPx.isEmpty) return 0.0;
if (sortedStepsPx.length == 1) {
return fits(sortedStepsPx.first) ? sortedStepsPx.first : 0.0;
}
var low = 0;
var high = sortedStepsPx.length - 1;
var best = 0.0;
while (low <= high) {
final mid = (low + high) >> 1;
final candidate = sortedStepsPx[mid];
if (fits(candidate)) {
best = candidate;
low = mid + 1;
} else {
high = mid - 1;
}
}
return best;
}