Auto threshold regression: refactor type range checks
As stated in 0bee4e20 the introduced range checks could be improved.
This change makes the code more readable and more DRY by factoring the
clamping into its own function. Two more places could be simplified
additionally.