Replace sqrt with hypot for wipe-effect & transform code
authorCampbell Barton <ideasman42@gmail.com>
Sat, 14 Jun 2014 07:27:50 +0000 (17:27 +1000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 14 Jun 2014 07:34:52 +0000 (17:34 +1000)
source/blender/blenkernel/intern/seqeffects.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_input.c

index 7ed9af8b87f3b1de704808a1c4de51447be2e24c..2b14b92217bb69bff285aa9b9ce7c6fa9312f5e7 100644 (file)
@@ -1398,7 +1398,7 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
                        x = x - halfx;
                        y = y - halfy;
 
-                       temp2 = asin(abs(y) / sqrt(x * x + y * y));
+                       temp2 = asin(abs(y) / hypot(x, y));
                        if (x <= 0 && y >= 0) temp2 = (float)M_PI - temp2;
                        else if (x <= 0 && y <= 0) temp2 += (float)M_PI;
                        else if (x >= 0 && y <= 0) temp2 = 2.0f * (float)M_PI - temp2;
@@ -1441,7 +1441,7 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
 
                        temp1 = xo * (1 - facf0 / 2) - xo * facf0 / 2;
                        temp2 = yo * (1 - facf0 / 2) - yo * facf0 / 2;
-                       pointdist = sqrtf(temp1 * temp1 + temp2 * temp2);
+                       pointdist = hypot(temp1, temp2);
 
                        if (b2 < b1 && b2 < b3) {
                                if (hwidth < pointdist)
@@ -1498,9 +1498,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
                        hwidth = width * 0.5f;
 
                        temp1 = (halfx - (halfx) * facf0);
-                       pointdist = sqrtf(temp1 * temp1 + temp1 * temp1);
+                       pointdist = hypotf(temp1, temp1);
 
-                       temp2 = sqrtf((halfx - x) * (halfx - x) + (halfy - y) * (halfy - y));
+                       temp2 = hypotf(halfx - x, halfy - y);
                        if (temp2 > pointdist) output = in_band(hwidth, fabsf(temp2 - pointdist), 0, 1);
                        else output = in_band(hwidth, fabsf(temp2 - pointdist), 1, 1);
 
index 899f1191e338704e0caf5d346474d57478c1519f..ab0bc061c32767184f51c3f71480137ab3d7c225 100644 (file)
@@ -1718,7 +1718,7 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
                        {
                                float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
                                float angle = atan2f(dy, dx);
-                               float dist = sqrtf(dx * dx + dy * dy);
+                               float dist = hypotf(dx, dy);
                                float delta_angle = min_ff(15.0f / dist, (float)M_PI / 4.0f);
                                float spacing_angle = min_ff(5.0f / dist, (float)M_PI / 12.0f);
                                UI_ThemeColor(TH_VIEW_OVERLAY);
index 6546a05aeddf7ca635564a4a018493ae957de3fd..61b2deabe1212dc18f0ae47bd25e658791f0051e 100644 (file)
@@ -64,18 +64,18 @@ static void InputSpring(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2],
                /* calculate ratio for shiftkey pos, and for total, and blend these for precision */
                dx = (float)(mi->center[0] - mi->precision_mval[0]);
                dy = (float)(mi->center[1] - mi->precision_mval[1]);
-               ratio = sqrtf(dx * dx + dy * dy);
+               ratio = hypotf(dx, dy);
 
                dx = (float)(mi->center[0] - mval[0]);
                dy = (float)(mi->center[1] - mval[1]);
-               precise_ratio = sqrtf(dx * dx + dy * dy);
+               precise_ratio = hypotf(dx, dy);
 
                ratio = (ratio + (precise_ratio - ratio) / 10.0f) / mi->factor;
        }
        else {
                dx = (float)(mi->center[0] - mval[0]);
                dy = (float)(mi->center[1] - mval[1]);
-               ratio = sqrtf(dx * dx + dy * dy) / mi->factor;
+               ratio = hypotf(dx, dy) / mi->factor;
        }
 
        output[0] = ratio;
@@ -195,7 +195,7 @@ static void InputCustomRatioFlip(TransInfo *UNUSED(t), MouseInput *mi, const int
                dx = data[2] - data[0];
                dy = data[3] - data[1];
                
-               length = sqrt(dx * dx + dy * dy);
+               length = hypot(dx, dy);
                
                if (mi->precision) {
                        /* deal with Shift key by adding motion / 10 to motion before shift press */