From df18518f62ef378c8fd40bcd4c0d67c39ba9cb20 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 15 Sep 2025 17:14:31 -0600 Subject: [PATCH] [iup] Don't sqrt --- src/hb-subset-instancer-iup.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/hb-subset-instancer-iup.cc b/src/hb-subset-instancer-iup.cc index 074657aca..61f30194d 100644 --- a/src/hb-subset-instancer-iup.cc +++ b/src/hb-subset-instancer-iup.cc @@ -264,12 +264,13 @@ static bool _can_iup_in_between (const hb_array_t contour unsigned num = contour_points.length; + double tolerance_sq = tolerance * tolerance; for (unsigned i = 0; i < num; i++) { double dx = static_cast (x_deltas.arrayZ[i]) - interp_x_deltas.arrayZ[i]; double dy = static_cast (y_deltas.arrayZ[i]) - interp_y_deltas.arrayZ[i]; - - if (sqrt (dx * dx + dy * dy) > tolerance) + + if (dx * dx + dy * dy > tolerance_sq) return false; } return true; @@ -294,7 +295,7 @@ static bool _iup_contour_optimize_dp (const contour_point_vector_t& contour_poin for (unsigned i = 0; i < n; i++) { unsigned best_cost = (i == 0 ? 1 : costs.arrayZ[i-1] + 1); - + costs.arrayZ[i] = best_cost; chain.arrayZ[i] = (i == 0 ? -1 : i - 1); @@ -342,11 +343,12 @@ static bool _iup_contour_optimize (const hb_array_t conto return false; bool all_within_tolerance = true; + double tolerance_sq = tolerance * tolerance; for (unsigned i = 0; i < n; i++) { int dx = x_deltas.arrayZ[i]; int dy = y_deltas.arrayZ[i]; - if (sqrt ((double) dx * dx + (double) dy * dy) > tolerance) + if ((double) dx * dx + (double) dy * dy > tolerance_sq) { all_within_tolerance = false; break;