Use hypot for Pythagorean addition
authorArkadiy Illarionov <qarkai@gmail.com>
Sun, 24 Sep 2023 18:25:41 +0000 (21:25 +0300)
committerColin Clark <colin.clark@cclark.uk>
Mon, 25 Sep 2023 08:08:30 +0000 (09:08 +0100)
src/exif-common.cc
src/pan-view/pan-folder.cc
src/pixbuf-util.cc

index 67f864b..ef80a6d 100644 (file)
@@ -115,12 +115,11 @@ static gdouble get_crop_factor(ExifData *exif)
 
        if (ratio < 0.5 || ratio > 2.0) return 0.0; /* reasonable ratio */
 
-       size = sqrt(xsize * xsize + ysize * ysize);
+       size = hypot(xsize, ysize);
 
        if (size < 1.0 || size > 100.0) return 0.0; /* reasonable sensor size in mm */
 
-       return sqrt(36*36+24*24) / size;
-
+       return hypot(36, 24) / size;
 }
 
 static gboolean remove_suffix(gchar *str, const gchar *suffix, gint suffix_len)
index 4e0b00b..c61adcf 100644 (file)
@@ -305,7 +305,7 @@ static FlowerGroup *pan_flower_group(PanWindow *pw, FileData *dir_fd, gint x, gi
 
        group->width = pi_box->width;
        group->height = pi_box->y + pi_box->height;
-       group->diameter = static_cast<gint>(sqrt(group->width * group->width + group->height * group->height));
+       group->diameter = static_cast<gint>(hypot(group->width, group->height));
 
        group->children = nullptr;
 
index ab1548e..c5f16ae 100644 (file)
@@ -1344,7 +1344,7 @@ static void pixbuf_draw_fade_radius(guchar *p_pix, gint prs, gboolean has_alpha,
                        guint8 n;
                        gint r;
 
-                       r = MIN(border, (gint)sqrt((i-sx)*(i-sx) + (j-sy)*(j-sy)));
+                       r = MIN(border, (gint)hypot(i - sx, j - sy));
                        n = a - a * r / border;
                        *pp = (r * n + *pp * (256-n)) >> 8;
                        pp++;