Code cleanup: use sqrtf when input and output are float
authorCampbell Barton <ideasman42@gmail.com>
Fri, 28 Mar 2014 03:53:37 +0000 (14:53 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 28 Mar 2014 03:53:37 +0000 (14:53 +1100)
20 files changed:
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/seqeffects.c
source/blender/blenlib/intern/math_geom.c
source/blender/blenlib/intern/math_rotation.c
source/blender/blenlib/intern/math_vector.c
source/blender/editors/armature/editarmature_generate.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/interface/interface_layout.c
source/blender/editors/interface/interface_panel.c
source/blender/editors/interface/interface_widgets.c
source/blender/editors/space_view3d/drawarmature.c
source/blender/editors/space_view3d/view3d_edit.c
source/blender/editors/transform/transform_generics.c
source/blender/editors/transform/transform_input.c
source/blender/modifiers/intern/MOD_warp.c
source/blender/modifiers/intern/MOD_weightvg_util.c
source/blender/python/mathutils/mathutils_Matrix.c
source/blender/render/intern/source/shadbuf.c
source/blender/windowmanager/intern/wm_operators.c

index 580a8a7a505470ea36cef0cbc1654ab72c314d16..243b99a31e40d2ec042ff6c477173f034f73a3ad 100644 (file)
@@ -2689,7 +2689,7 @@ static void stretchto_evaluate(bConstraint *con, bConstraintOb *cob, ListBase *t
                switch (data->volmode) {
                        /* volume preserving scaling */
                        case VOLUME_XZ:
-                               scale[0] = 1.0f - (float)sqrt(data->bulge) + (float)sqrt(data->bulge * (data->orglength / dist));
+                               scale[0] = 1.0f - sqrtf(data->bulge) + sqrtf(data->bulge * (data->orglength / dist));
                                scale[2] = scale[0];
                                break;
                        case VOLUME_X:
index bc65e5bf749df6f055930ebd659d72cc1bba9dd6..864682c560712e2ee87638d5a78347c3e62fda4e 100644 (file)
@@ -1931,8 +1931,8 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
 {
        float t01, t02, x3, y3;
 
-       t01 = (float)sqrt(x1 * x1 + y1 * y1);
-       t02 = (float)sqrt(x2 * x2 + y2 * y2);
+       t01 = sqrtf(x1 * x1 + y1 * y1);
+       t02 = sqrtf(x2 * x2 + y2 * y2);
        if (t01 == 0.0f)
                t01 = 1.0f;
        if (t02 == 0.0f)
@@ -1960,7 +1960,7 @@ static void calc_bevel_sin_cos(float x1, float y1, float x2, float y2, float *si
                y3 = -x1;
        }
        else {
-               t01 = (float)sqrt(x3 * x3 + y3 * y3);
+               t01 = sqrtf(x3 * x3 + y3 * y3);
                x3 /= t01;
                y3 /= t01;
        }
index ab44cf720d0b6aaf00821b78a1a261034229769b..9e59ec8d8d55b70b9300759d6538de29538526a6 100644 (file)
@@ -678,8 +678,10 @@ static void gamtabs(float gamma)
                val = a;
                val /= 65535.0f;
                
-               if (gamma == 2.0f) val = sqrt(val);
-               else if (gamma != 1.0f) val = pow(val, igamma);
+               if (gamma == 2.0f)
+                       val = sqrtf(val);
+               else if (gamma != 1.0f)
+                       val = powf(val, igamma);
                
                gamtab[a] = (65535.99f * val);
        }
@@ -1443,7 +1445,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 = sqrt(temp1 * temp1 + temp2 * temp2);
+                       pointdist = sqrtf(temp1 * temp1 + temp2 * temp2);
 
                        if (b2 < b1 && b2 < b3) {
                                if (hwidth < pointdist)
@@ -1500,9 +1502,9 @@ static float check_zone(WipeZone *wipezone, int x, int y, Sequence *seq, float f
                        hwidth = width * 0.5f;
 
                        temp1 = (halfx - (halfx) * facf0);
-                       pointdist = sqrt(temp1 * temp1 + temp1 * temp1);
+                       pointdist = sqrtf(temp1 * temp1 + temp1 * temp1);
 
-                       temp2 = sqrt((halfx - x) * (halfx - x) + (halfy - y) * (halfy - y));
+                       temp2 = sqrtf((halfx - x) * (halfx - x) + (halfy - y) * (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 ca9d3bb413f969f1bd96fb1a179f449b240f0b83..3daa74180ea9ff591a8de31267ec94acd02369eb 100644 (file)
@@ -1244,7 +1244,7 @@ static bool getLowestRoot(const float a, const float b, const float c, const flo
        if (determinant >= 0.0f) {
                /* calculate the two roots: (if determinant == 0 then
                 * x1==x2 but lets disregard that slight optimization) */
-               float sqrtD = (float)sqrt(determinant);
+               float sqrtD = sqrtf(determinant);
                float r1 = (-b - sqrtD) / (2.0f * a);
                float r2 = (-b + sqrtD) / (2.0f * a);
 
@@ -2974,8 +2974,8 @@ void lookat_m4(float mat[4][4], float vx, float vy, float vz, float px, float py
        dy = py - vy;
        dz = pz - vz;
        hyp = dx * dx + dz * dz; /* hyp squared */
-       hyp1 = (float)sqrt(dy * dy + hyp);
-       hyp = (float)sqrt(hyp); /* the real hyp */
+       hyp1 = sqrtf(dy * dy + hyp);
+       hyp = sqrtf(hyp); /* the real hyp       */
 
        if (hyp1 != 0.0f) { /* rotate X */
                sine = -dy / hyp1;
@@ -3097,7 +3097,7 @@ void map_to_sphere(float *r_u, float *r_v, const float x, const float y, const f
                if (x == 0.0f && y == 0.0f) *r_u = 0.0f;  /* othwise domain error */
                else *r_u = (1.0f - atan2f(x, y) / (float)M_PI) / 2.0f;
 
-               *r_v = 1.0f - (float)saacos(z / len) / (float)M_PI;
+               *r_v = 1.0f - saacos(z / len) / (float)M_PI;
        }
        else {
                *r_v = *r_u = 0.0f; /* to avoid un-initialized variables */
index d7daa23c087621c97a6108aea92de6ef3384f659..1136020a4f791341bff93faf187aea70db9d4d06 100644 (file)
@@ -1011,7 +1011,7 @@ static void mat3_to_eul2(float tmat[3][3], float eul1[3], float eul2[3])
        copy_m3_m3(mat, tmat);
        normalize_m3(mat);
 
-       cy = (float)sqrt(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
+       cy = sqrtf(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
 
        if (cy > 16.0f * FLT_EPSILON) {
 
index b189fc32284ba4f5f519b36b176ed215279170d8..d3869f307fbd2c416260a41527697e5ce9d7d22c 100644 (file)
@@ -494,7 +494,7 @@ void reflect_v3_v3v3(float out[3], const float v1[3], const float v2[3])
 
 void ortho_basis_v3v3_v3(float v1[3], float v2[3], const float v[3])
 {
-       const float f = (float)sqrt(v[0] * v[0] + v[1] * v[1]);
+       const float f = sqrtf(v[0] * v[0] + v[1] * v[1]);
 
        if (f < 1e-35f) {
                // degenerate case
index 41ec144bd9870c460dfbff44c635e8c3bd6f6ac8..179e0a97c9d69e5ad284dff281598603856178e3 100644 (file)
@@ -203,7 +203,7 @@ int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int st
                                
                                c = dot_v3v3(off, off) - (lengthLimit * lengthLimit);
                                
-                               f = (-b + (float)sqrt(b * b - 4 * a * c)) / (2 * a);
+                               f = (-b + sqrtf(b * b - 4 * a * c)) / (2 * a);
                                
                                //printf("a %f, b %f, c %f, f %f\n", a, b, c, f);
                                
index 4eb138e07cb12dd8411c5172bc32c3c12b03fba9..b58c86fca5d39eedfc4e6bf6e273ba00bb6c987c 100644 (file)
@@ -4142,7 +4142,7 @@ static bool ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data,
        if (mrad < radsq) { /* inner circle */
                fp[0] = dx;
                fp[1] = dy;
-               fp[2] = sqrt(radsq - dx * dx - dy * dy);
+               fp[2] = sqrtf(radsq - dx * dx - dy * dy);
        }
        else {  /* outer circle */
                
@@ -4155,7 +4155,7 @@ static bool ui_numedit_but_NORMAL(uiBut *but, uiHandleButtonData *data,
                if (mrad < radsq) {
                        fp[0] = dx;
                        fp[1] = dy;
-                       fp[2] = -sqrt(radsq - dx * dx - dy * dy);
+                       fp[2] = -sqrtf(radsq - dx * dx - dy * dy);
                }
        }
        normalize_v3(fp);
index fa56dc1a2756a91651fd6e9261441f4ad31a411d..be57987ee3cde97db85ac4f65f72335f0a1b3d2f 100644 (file)
@@ -1132,7 +1132,7 @@ static void ui_item_rna_size(uiLayout *layout, const char *name, int icon, Point
                if (ELEM(subtype, PROP_LAYER, PROP_LAYER_MEMBER))
                        h += 2 * UI_UNIT_Y;
                else if (subtype == PROP_MATRIX)
-                       h += ceil(sqrt(len)) * UI_UNIT_Y;
+                       h += ceilf(sqrtf(len)) * UI_UNIT_Y;
                else
                        h += len * UI_UNIT_Y;
        }
index f5e2bfb6c29843d146dfe9645b4ab57e330868d1..e9a4119ac7ed02c55ce5cc7886cedfb689c2b9f3 100644 (file)
@@ -892,7 +892,7 @@ static void ui_do_animate(const bContext *C, Panel *panel)
        float fac;
 
        fac = (PIL_check_seconds_timer() - data->starttime) / ANIMATION_TIME;
-       fac = min_ff(sqrt(fac), 1.0f);
+       fac = min_ff(sqrtf(fac), 1.0f);
 
        /* for max 1 second, interpolate positions */
        if (uiAlignPanelStep(sa, ar, fac, false)) {
index 4a830e3302725918e45e5f2b27d109193cff43bd..5f970e4ef3a4e22bee482cc466781810513a7cd7 100644 (file)
@@ -1944,7 +1944,7 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r
        glEnableClientState(GL_VERTEX_ARRAY);
 
        for (step = 1; step <= (int)radout; step++) {
-               float expfac = sqrt(step / radout);
+               float expfac = sqrtf(step / radout);
                
                round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step);
                
index 8793dff4bac5b15ad6a0d2e82b59e76c028435b4..4a2fd5f700404e2d9661f4595ed779603dc8f1b9 100644 (file)
@@ -1456,7 +1456,7 @@ static void bgl_sphere_project(float ax, float az)
        float dir[3], sine, q3;
 
        sine = 1.0f - ax * ax - az * az;
-       q3 = (sine < 0.0f) ? 0.0f : (float)(2.0 * sqrt(sine));
+       q3 = (sine < 0.0f) ? 0.0f : (2.0f * sqrtf(sine));
 
        dir[0] = -az * q3;
        dir[1] = 1.0f - 2.0f * sine;
@@ -2393,7 +2393,7 @@ static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base
        /* draw from first frame of range to last */
        for (CFRA = (int)start; CFRA < end; CFRA += (int)stepsize) {
                colfac = (end - (float)CFRA) / range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
                
                BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
                BKE_pose_where_is(scene, ob);
@@ -2473,7 +2473,7 @@ static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *
        /* draw from first frame of range to last */
        for (ak = keys.first, i = 0; ak; ak = ak->next, i++) {
                colfac = i / range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
                
                CFRA = (int)ak->cfra;
                
@@ -2543,7 +2543,7 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
        for (cur = stepsize; cur < range; cur += stepsize) {
                ctime = cur - (float)fmod(cfrao, stepsize);  /* ensures consistent stepping */
                colfac = ctime / range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
                
                /* only within action range */
                if (actframe + ctime >= start && actframe + ctime <= end) {
@@ -2558,7 +2558,7 @@ static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
                
                ctime = cur + (float)fmod((float)cfrao, stepsize) - stepsize + 1.0f;   /* ensures consistent stepping */
                colfac = ctime / range;
-               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0 * sqrt(colfac)));
+               UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
                
                /* only within action range */
                if ((actframe - ctime >= start) && (actframe - ctime <= end)) {
index b60e2e42c7d6df1068f87c06d44a146e768a48ad..fe84e3e79a00159e7088db04bcae3b810aea7dc9 100644 (file)
@@ -492,9 +492,9 @@ static void calctrackballvec(const rcti *rect, int mx, int my, float vec[3])
        y = BLI_rcti_cent_y(rect) - my;
        y /= (float)(BLI_rcti_size_y(rect) / 2);
 
-       d = sqrt(x * x + y * y);
+       d = sqrtf(x * x + y * y);
        if (d < radius * (float)M_SQRT1_2) { /* Inside sphere */
-               z = sqrt(radius * radius - d * d);
+               z = sqrtf(radius * radius - d * d);
        }
        else { /* On hyperbola */
                t = radius / (float)M_SQRT2;
index 79ae0efbcb3bd8551e5237e6697d1307db546b3a..4ee9f6bd6a6f90fe9407d8f1e5833f1ae04fc1b3 100644 (file)
@@ -1818,7 +1818,7 @@ void calculatePropRatio(TransInfo *t)
                                                td->factor = 3.0f * dist * dist - 2.0f * dist * dist * dist;
                                                break;
                                        case PROP_ROOT:
-                                               td->factor = (float)sqrt(dist);
+                                               td->factor = sqrtf(dist);
                                                break;
                                        case PROP_LIN:
                                                td->factor = dist;
@@ -1827,7 +1827,7 @@ void calculatePropRatio(TransInfo *t)
                                                td->factor = 1.0f;
                                                break;
                                        case PROP_SPHERE:
-                                               td->factor = (float)sqrt(2 * dist - dist * dist);
+                                               td->factor = sqrtf(2 * dist - dist * dist);
                                                break;
                                        case PROP_RANDOM:
                                                td->factor = BLI_frand() * dist;
index 39c7b4b5c1c941e7c9b775fb22413b479ab12bca..02f9c636ab4424d0c90c216d2b5e0916f3a299ca 100644 (file)
@@ -68,7 +68,7 @@ static void InputSpring(TransInfo *UNUSED(t), MouseInput *mi, const int mval[2],
 
                dx = (float)(mi->center[0] - mval[0]);
                dy = (float)(mi->center[1] - mval[1]);
-               precise_ratio = (float)sqrt(dx * dx + dy * dy);
+               precise_ratio = sqrtf(dx * dx + dy * dy);
 
                ratio = (ratio + (precise_ratio - ratio) / 10.0f) / mi->factor;
        }
index 93be31bcad794f1649749c0d3f82d889a1882ff7..b9c89f404bb4231efd7ad5bb0f2282abcb3aff24 100644 (file)
@@ -253,7 +253,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
                                        fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
                                        break;
                                case eWarp_Falloff_Root:
-                                       fac = (float)sqrt(fac);
+                                       fac = sqrtf(fac);
                                        break;
                                case eWarp_Falloff_Linear:
                                        /* pass */
@@ -262,7 +262,7 @@ static void warpModifier_do(WarpModifierData *wmd, Object *ob,
                                        fac = 1.0f;
                                        break;
                                case eWarp_Falloff_Sphere:
-                                       fac = (float)sqrt(2 * fac - fac * fac);
+                                       fac = sqrtf(2 * fac - fac * fac);
                                        break;
                        }
 
index 348b036146403256a661600a1e28777c85979252..12ecae8ad4f6523d5996dbaf50469eb7884e4b24 100644 (file)
@@ -94,10 +94,10 @@ void weightvg_do_map(int num, float *new_w, short falloff_type, CurveMapping *cm
                                fac = 3.0f * fac * fac - 2.0f * fac * fac * fac;
                                break;
                        case MOD_WVG_MAPPING_ROOT:
-                               fac = (float)sqrt(fac);
+                               fac = sqrtf(fac);
                                break;
                        case MOD_WVG_MAPPING_SPHERE:
-                               fac = (float)sqrt(2 * fac - fac * fac);
+                               fac = sqrtf(2 * fac - fac * fac);
                                break;
                        case MOD_WVG_MAPPING_RANDOM:
                                fac = BLI_rng_get_float(rng) * fac;
index aa035aa05a6fa1f10032f762f112dd84cc4229ea..1c8718aa122df4b46d31d096c18ae8a912d18c0e 100644 (file)
@@ -621,7 +621,7 @@ static PyObject *C_Matrix_Scale(PyObject *cls, PyObject *args)
                for (x = 0; x < vec_size; x++) {
                        norm += tvec[x] * tvec[x];
                }
-               norm = (float) sqrt(norm);
+               norm = sqrtf(norm);
                for (x = 0; x < vec_size; x++) {
                        tvec[x] /= norm;
                }
@@ -742,7 +742,7 @@ static PyObject *C_Matrix_OrthoProjection(PyObject *cls, PyObject *args)
                for (x = 0; x < vec_size; x++) {
                        norm += tvec[x] * tvec[x];
                }
-               norm = (float) sqrt(norm);
+               norm = sqrtf(norm);
                for (x = 0; x < vec_size; x++) {
                        tvec[x] /= norm;
                }
index 9010cf8917e05c10f58050edef6575485bb1256f..f534acd838d71e90d9d6b4fb9449be6f3eef4f44 100644 (file)
@@ -1702,7 +1702,7 @@ static int point_behind_strand(const float p[3], BSPFace *face)
                        
                        rc[0]= pt[0]-p[0];
                        rc[1]= pt[1]-p[1];
-                       dist= (float)sqrt(rc[0]*rc[0]+ rc[1]*rc[1]);
+                       dist= sqrtf(rc[0]*rc[0]+ rc[1]*rc[1]);
                        
                        if (dist < face->radline) {
                                float zval= face->vec1[2] + lambda*face->rc[2];
index 897ffa4ebd491a752ea346f06884ab7d4852a6bf..259324935e6d4a6eeed201acbe2b833beb020788 100644 (file)
@@ -4106,7 +4106,7 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
                                delta[1] /= zoom[1];
                        }
 
-                       dist = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
+                       dist = len_v2(delta);
 
                        /* calculate new value and apply snapping  */
                        switch (rc->subtype) {