Do not scale WidthHeuristics when max_width less than 100

This commit is contained in:
Trevor Spiteri 2018-05-02 10:36:02 +02:00
parent 36c49d703a
commit 9b36156020

View file

@ -242,8 +242,14 @@ impl WidthHeuristics {
// scale the default WidthHeuristics according to max_width // scale the default WidthHeuristics according to max_width
pub fn scaled(max_width: usize) -> WidthHeuristics { pub fn scaled(max_width: usize) -> WidthHeuristics {
let mut max_width_ratio: f32 = max_width as f32 / 100.0; // 100 is the default width -> default ratio is 1 const DEFAULT_MAX_WIDTH: usize = 100;
max_width_ratio = (max_width_ratio * 10.0).round() / 10.0; // round to the closest 0.1 let max_width_ratio = if max_width > DEFAULT_MAX_WIDTH {
let ratio = max_width as f32 / DEFAULT_MAX_WIDTH as f32;
// round to the closest 0.1
(ratio * 10.0).round() / 10.0
} else {
1.0
};
WidthHeuristics { WidthHeuristics {
fn_call_width: (60.0 * max_width_ratio).round() as usize, fn_call_width: (60.0 * max_width_ratio).round() as usize,
struct_lit_width: (18.0 * max_width_ratio).round() as usize, struct_lit_width: (18.0 * max_width_ratio).round() as usize,