From 0d59d7952c334f6a3760a5b63456ede74dbf2351 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Wed, 22 Jun 2022 16:39:36 -0600 Subject: [PATCH] [ansi-print] Precision --- util/ansi-print.hh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/ansi-print.hh b/util/ansi-print.hh index ed0dafb9f..c519813a8 100644 --- a/util/ansi-print.hh +++ b/util/ansi-print.hh @@ -196,11 +196,11 @@ struct biimage_t color_t bgc = color_t::from_ansi (bg); color_t fgc = color_t::from_ansi (fg); color_diff_t diff = fgc.diff (bgc); - int dd = sqrt (diff.dot (diff)); + double dd = sqrt (diff.dot (diff)); for (unsigned int y = 0; y < height; y++) for (unsigned int x = 0; x < width; x++) { - int d = sqrt (diff.dot (image (x, y).diff (bgc))); - (*this)(x, y) = d < 0 ? 0 : d > dd ? 255 : lround (d * 255. / dd); + double d = sqrt (diff.dot (image (x, y).diff (bgc))); + (*this)(x, y) = d <= 0 ? 0 : d >= dd ? 255 : lround (d / dd * 255.); } }