From 329dd528ab79531d884c0ba131e97d43f872ab5d Mon Sep 17 00:00:00 2001
From: ruc_zhangxiaohui <553441439@qq.com>
Date: Thu, 4 Feb 2021 04:19:08 +0800
Subject: [PATCH] uses the PerceptibleReciprocal() to prevent the
 divide-by-zero from occurring (#3194)

Co-authored-by: Zhang Xiaohui <ruc_zhangxiaohui@163.com>
---
 magick/fx.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/magick/fx.c b/magick/fx.c
index 07a54eb..5041de6 100644
--- a/magick/fx.c
+++ b/magick/fx.c
@@ -3403,11 +3403,11 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
   center.y=0.5*image->rows;
   radius=center.x;
   if (image->columns > image->rows)
-    scale.y=(double) image->columns/(double) image->rows;
+    scale.y=(double) image->columns*PerceptibleReciprocal((double) image->rows);
   else
     if (image->columns < image->rows)
       {
-        scale.x=(double) image->rows/(double) image->columns;
+        scale.x=(double) image->rows*PerceptibleReciprocal((double) image->columns);
         radius=center.y;
       }
   /*
@@ -3471,11 +3471,11 @@ MagickExport Image *ImplodeImage(const Image *image,const double amount,
           */
           factor=1.0;
           if (distance > 0.0)
-            factor=pow(sin((double) (MagickPI*sqrt((double) distance)/
-              radius/2)),-amount);
+            factor=pow(sin((double) (MagickPI*sqrt((double) distance)*PerceptibleReciprocal(
+              radius)/2)),-amount);
           status=InterpolateMagickPixelPacket(image,image_view,
-            UndefinedInterpolatePixel,(double) (factor*delta.x/scale.x+
-            center.x),(double) (factor*delta.y/scale.y+center.y),&pixel,
+            UndefinedInterpolatePixel,(double) (factor*delta.x*PerceptibleReciprocal(scale.x)+
+            center.x),(double) (factor*delta.y*PerceptibleReciprocal(scale.y)+center.y),&pixel,
             exception);
           if (status == MagickFalse)
             break;
-- 
2.23.0

