Correct the consecutive hyphen cost (#2190)

This just fixes a mistake previously made. `0.3` is the correct number that is proportional to the parameters in Knuth's paper. The previously choosed value `300` is due to my calculation mistake and is too large that essentially prevent any consecutive hyphens.
This commit is contained in:
Peng Guanwen 2023-09-19 23:05:32 +08:00 committed by GitHub
parent 7a46a85d3e
commit 50f354e989
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -903,7 +903,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
// Cost parameters. // Cost parameters.
const HYPH_COST: Cost = 0.5; const HYPH_COST: Cost = 0.5;
const RUNT_COST: Cost = 0.5; const RUNT_COST: Cost = 0.5;
const CONSECUTIVE_DASH_COST: Cost = 300.0; const CONSECUTIVE_DASH_COST: Cost = 0.3;
const MAX_COST: Cost = 1_000_000.0; const MAX_COST: Cost = 1_000_000.0;
const MIN_RATIO: f64 = -1.0; const MIN_RATIO: f64 = -1.0;
@ -993,7 +993,7 @@ fn linebreak_optimized<'a>(vt: &Vt, p: &'a Preparation<'a>, width: Abs) -> Vec<L
// In Knuth paper, cost = (1 + 100|r|^3 + p)^2 + a, // In Knuth paper, cost = (1 + 100|r|^3 + p)^2 + a,
// where r is the ratio, p=50 is the penalty, and a=3000 is consecutive the penalty. // where r is the ratio, p=50 is the penalty, and a=3000 is consecutive the penalty.
// We divide the whole formula by 10, resulting (0.01 + |r|^3 + p)^2 + a, // We divide the whole formula by 10, resulting (0.01 + |r|^3 + p)^2 + a,
// where p=0.5 and a=300 // where p=0.5 and a=0.3
cost = (0.01 + cost).powi(2); cost = (0.01 + cost).powi(2);
// Penalize two consecutive dashes (not necessarily hyphens) extra. // Penalize two consecutive dashes (not necessarily hyphens) extra.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 16 KiB