calculateSpaceThreshold method
Calculates an appropriate threshold for determining if a gap should be considered a space
This method analyzes the distribution of gaps between artifacts to determine a suitable threshold for identifying spaces.
Returns: An integer representing the minimum gap width to be considered a space
Implementation
int calculateSpaceThreshold(List<int> gaps) {
if (gaps.isEmpty) {
return _minSpaceWidth;
}
gaps.sort();
final int jumpThreshold = _tryJumpThreshold(gaps);
if (jumpThreshold > 0) {
return max(_minSpaceWidth, jumpThreshold);
}
final int medianGap = gaps[gaps.length ~/ 2];
final int thresholdFromGaps = (medianGap * _spaceMedianMultiplier).round();
final int thresholdFromWidth = (averageWidth * _spaceMinWidthRatio).round();
return max(_minSpaceWidth, max(thresholdFromGaps, thresholdFromWidth));
}