mirror of
https://github.com/typst/typst
synced 2025-05-21 04:25:28 +08:00
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:
parent
7a46a85d3e
commit
50f354e989
@ -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 |
Loading…
x
Reference in New Issue
Block a user