From d29d7b7a3dd2cfca151ce667a3290359d028911c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 1 Mar 2023 13:10:11 -0700 Subject: [PATCH] [algs] Adjust solve_itp --- src/hb-algs.hh | 11 +++++++---- src/hb-shape.cc | 4 ---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index cf9403134..13587eac0 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -1344,7 +1344,10 @@ struct HB_FUNCOBJ (hb_dec); -/* For documentation and implementation see: +/* Adapted from kurbo implementation with extra parameters added, + * and finding for a particular range instead of 0. + * + * For documentation and implementation see: * * [ITP method]: https://en.wikipedia.org/wiki/ITP_Method * [An Enhancement of the Bisection Method Average Performance Preserving Minmax Optimality]: https://dl.acm.org/doi/10.1145/3423597 @@ -1355,12 +1358,12 @@ template double solve_itp (func_t f, double a, double b, double epsilon, - unsigned n0, - double k1, double min_y, double max_y, double &ya, double &yb, double &y) { unsigned n1_2 = (unsigned) (hb_max (ceil (log2 ((b - a) / epsilon)) - 1.0, 0.0)); + const unsigned n0 = 1; // Hardwired + const double k1 = 0.2 / (b - a); // Hardwired. unsigned nmax = n0 + n1_2; double scaled_epsilon = epsilon * double (1llu << nmax); double _2_epsilon = 2.0 * epsilon; @@ -1370,8 +1373,8 @@ double solve_itp (func_t f, double r = scaled_epsilon - 0.5 * (b - a); double xf = (yb * a - ya * b) / (yb - ya); double sigma = x1_2 - xf; - // This has k2 = 2 hardwired for efficiency. double b_a = b - a; + // This has k2 = 2 hardwired for efficiency. double b_a_k2 = b_a * b_a; double delta = k1 * b_a_k2; int sigma_sign = sigma >= 0 ? +1 : -1; diff --git a/src/hb-shape.cc b/src/hb-shape.cc index 5aae008d7..3504288e4 100644 --- a/src/hb-shape.cc +++ b/src/hb-shape.cc @@ -334,8 +334,6 @@ hb_shape_justify (hb_font_t *font, } double epsilon = (b - a) / (1<<14); - const unsigned n0 = 1; - const double k1 = 0.2 / (b - a); bool failed = false; auto f = [&] (double x) @@ -361,8 +359,6 @@ hb_shape_justify (hb_font_t *font, double itp = solve_itp (f, a, b, epsilon, - n0, - k1, min_target_width, max_target_width, ya, yb, y);