code cleanup: dont use function calls like dot_v3v3, pow and sqrt within macros which...
authorCampbell Barton <ideasman42@gmail.com>
Fri, 6 Jul 2012 22:48:28 +0000 (22:48 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Fri, 6 Jul 2012 22:48:28 +0000 (22:48 +0000)
also added some comments.

18 files changed:
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/collision.c
source/blender/blenkernel/intern/displist.c
source/blender/blenkernel/intern/font.c
source/blender/blenkernel/intern/smoke.c
source/blender/blenkernel/intern/softbody.c
source/blender/blenkernel/intern/tracking.c
source/blender/blenlib/intern/freetypefont.c
source/blender/bmesh/operators/bmo_hull.c
source/blender/editors/interface/interface_handlers.c
source/blender/editors/mesh/editmesh_knife.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/editors/transform/transform.c
source/blender/editors/transform/transform_conversions.c
source/blender/editors/uvedit/uvedit_smart_stitch.c
source/blender/render/intern/source/shadeoutput.c
source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
source/gameengine/Ketsji/KX_ObstacleSimulation.cpp

index 5822b29..c10b1e2 100644 (file)
@@ -2049,7 +2049,8 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o
                cross_v3_v3v3(raxis, rmat[1], splineVec);
 
                rangle = dot_v3v3(rmat[1], splineVec);
-               rangle = acos(MAX2(-1.0f, MIN2(1.0f, rangle)));
+               CLAMP(rangle, -1.0f, 1.0f);
+               rangle = acosf(rangle);
 
                /* multiply the magnitude of the angle by the influence of the constraint to
                 * control the influence of the SplineIK effect
index d99c36b..7acbcbf 100644 (file)
@@ -274,7 +274,7 @@ static int cloth_collision_response_static ( ClothModifierData *clmd, CollisionM
 
                        // Decrease in magnitude of relative tangential velocity due to coulomb friction
                        // in original formula "magrelVel" should be the "change of relative velocity in normal direction"
-                       magtangent = MIN2(clmd->coll_parms->friction * 0.01f * magrelVel, sqrtf(dot_v3v3(vrel_t_pre, vrel_t_pre)));
+                       magtangent = minf(clmd->coll_parms->friction * 0.01f * magrelVel, sqrtf(dot_v3v3(vrel_t_pre, vrel_t_pre)));
 
                        // Apply friction impulse.
                        if ( magtangent > ALMOST_ZERO ) {
index 2493507..6e5d6ff 100644 (file)
@@ -1386,17 +1386,18 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
                                                ListBase top_capbase = {NULL, NULL};
 
                                                for (dlb = dlbev.first; dlb; dlb = dlb->next) {
-                                                       int i, start, steps;
-                                                       float bevfac1 = MIN2(cu->bevfac1, cu->bevfac2), bevfac2 = MAX2(cu->bevfac1, cu->bevfac2);
+                                                       const float bevfac1 = minf(cu->bevfac1, cu->bevfac2);
+                                                       const float bevfac2 = maxf(cu->bevfac1, cu->bevfac2);
                                                        float firstblend = 0.0f, lastblend = 0.0f;
+                                                       int i, start, steps;
 
-                                                       if (cu->bevfac1 - cu->bevfac2 == 0.0f)
+                                                       if (bevfac2 - bevfac1 == 0.0f)
                                                                continue;
 
                                                        start = (int)(bevfac1 * (bl->nr - 1));
                                                        steps = 2 + (int)((bevfac2) * (bl->nr - 1)) - start;
-                                                       firstblend = 1.0f - ((float)bevfac1 * (bl->nr - 1) - (int)((float)bevfac1 * (bl->nr - 1)));
-                                                       lastblend  = (float)bevfac2 * (bl->nr - 1) - (int)((float)bevfac2 * (bl->nr - 1));
+                                                       firstblend = 1.0f - (bevfac1 * (bl->nr - 1) - (int)(bevfac1 * (bl->nr - 1)));
+                                                       lastblend  =         bevfac2 * (bl->nr - 1) - (int)(bevfac2 * (bl->nr - 1));
 
                                                        if (steps > bl->nr) {
                                                                steps = bl->nr;
index 0615309..5d33c8f 100644 (file)
@@ -699,7 +699,7 @@ makebreak:
 
                        yof -= linedist;
 
-                       maxlen = MAX2(maxlen, (xof - tb->x / cu->fsize));
+                       maxlen = maxf(maxlen, (xof - tb->x / cu->fsize));
                        linedata[lnr] = xof - tb->x / cu->fsize;
                        linedata2[lnr] = cnr;
                        linedata3[lnr] = tb->w / cu->fsize;
index 32def1b..ddcba50 100644 (file)
@@ -141,7 +141,7 @@ struct SmokeModifierData;
 
 /* forward declerations */
 static void calcTriangleDivs(Object *ob, MVert *verts, int numverts, MFace *tris, int numfaces, int numtris, int **tridivs, float cell_len);
-static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct);
+static void get_cell(const float p0[3], const int res[3], float dx, const float pos[3], int cell[3], int correct);
 static void fill_scs_points(Object *ob, DerivedMesh *dm, SmokeCollSettings *scs);
 
 #else /* WITH_SMOKE */
@@ -1977,7 +1977,7 @@ static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, f
        cb(result, input, res, pixel, tRay, correct);
 }
 
-static void get_cell(float *p0, int res[3], float dx, float *pos, int *cell, int correct)
+static void get_cell(const float p0[3], const int res[3], float dx, const float pos[3], int cell[3], int correct)
 {
        float tmp[3];
 
index 63f0a29..1d6895a 100644 (file)
@@ -1718,15 +1718,15 @@ static int choose_winner(float*w, float* pos, float*a, float*b, float*c, float*c
 {
        float mindist, cp;
        int winner =1;
-       mindist = ABS(dot_v3v3(pos, a));
+       mindist = fabsf(dot_v3v3(pos, a));
 
-       cp = ABS(dot_v3v3(pos, b));
+       cp = fabsf(dot_v3v3(pos, b));
        if ( mindist < cp ) {
                mindist = cp;
                winner =2;
        }
 
-       cp = ABS(dot_v3v3(pos, c));
+       cp = fabsf(dot_v3v3(pos, c));
        if (mindist < cp ) {
                mindist = cp;
                winner =3;
index 6167536..4342eb2 100644 (file)
@@ -2315,10 +2315,10 @@ static int tracking_check_marker_margin(MovieTrackingTrack *track, MovieTracking
        /* margin from frame boundaries */
        BKE_tracking_marker_pattern_minmax(marker, pat_min, pat_max);
        sub_v2_v2v2(dim, pat_max, pat_min);
-       margin[0] = margin[1] = MAX2(dim[0], dim[1]) / 2.0f;
+       margin[0] = margin[1] = maxf(dim[0], dim[1]) / 2.0f;
 
-       margin[0] = MAX2(margin[0], (float)track->margin / frame_width);
-       margin[1] = MAX2(margin[1], (float)track->margin / frame_height);
+       margin[0] = maxf(margin[0], (float)track->margin / frame_width);
+       margin[1] = maxf(margin[1], (float)track->margin / frame_height);
 
        /* do not track markers which are too close to boundary */
        if (marker->pos[0] < margin[0] || marker->pos[0] > 1.0f - margin[0] ||
index eb2070b..10eeda9 100644 (file)
@@ -266,17 +266,19 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf
                                                }
                                        }
 
-                                       // get the handles that are aligned, tricky...
-                                       // dist_to_line_v2, check if the three beztriple points are on one line
-                                       // len_squared_v2v2, see if there's a distance between the three points
-                                       // len_squared_v2v2 again, to check the angle between the handles 
-                                       // finally, check if one of them is a vector handle 
-                                       if ((dist_to_line_v2(bezt->vec[0], bezt->vec[1], bezt->vec[2]) < 0.001f) &&
+                                       /* get the handles that are aligned, tricky...
+                                        * dist_to_line_v2, check if the three beztriple points are on one line
+                                        * len_squared_v2v2, see if there's a distance between the three points
+                                        * len_squared_v2v2 again, to check the angle between the handles
+                                        * finally, check if one of them is a vector handle */
+                                       if ((bezt->h1 != HD_VECT && bezt->h2 != HD_VECT) &&
+                                           (dist_to_line_v2(bezt->vec[0], bezt->vec[1], bezt->vec[2]) < 0.001f) &&
                                            (len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001f * 0.0001f) &&
                                            (len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001f * 0.0001f) &&
                                            (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002f * 0.0001f) &&
-                                           (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > MAX2(len_squared_v2v2(bezt->vec[0], bezt->vec[1]), len_squared_v2v2(bezt->vec[1], bezt->vec[2]))) &&
-                                           bezt->h1 != HD_VECT && bezt->h2 != HD_VECT)
+                                           (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) >
+                                            maxf(len_squared_v2v2(bezt->vec[0], bezt->vec[1]),
+                                                 len_squared_v2v2(bezt->vec[1], bezt->vec[2]))))
                                        {
                                                bezt->h1 = bezt->h2 = HD_ALIGN;
                                        }
index d4f63ab..b22bdf6 100644 (file)
 #include "BLI_math.h"
 #include "BLI_utildefines.h"
 
+/*XXX: This operator doesn't work well (at all?) for flat surfaces with
+ * >3 sides - creating overlapping faces at times.
+ * An easy workaround is to add in some noise but this is
+ * weak and unreliable, ideally this would detect flat surfaces
+ * (possibly making them into ngons) - see
+ */
+
 /* XXX: using 128 for totelem and pchunk of mempool, no idea what good
  * values would be though */
 #include "BLI_mempool.h"
index 30c5f2f..3a64ad2 100644 (file)
@@ -3833,7 +3833,7 @@ static int ui_numedit_but_HISTOGRAM(uiBut *but, uiHandleButtonData *data, int mx
        }
        else {
                /* scale histogram values */
-               const float yfac = MIN2(powf(hist->ymax, 2.f), 1.f) * 0.5f;
+               const float yfac = minf(powf(hist->ymax, 2.0f), 1.0f) * 0.5f;
                hist->ymax += dy * yfac;
        
                CLAMP(hist->ymax, 1.f, 100.f);
index 2ceb8ae..882d311 100644 (file)
@@ -1400,9 +1400,10 @@ static float knife_snap_size(KnifeTool_OpData *kcd, float maxsize)
 {
        float density = (float)knife_sample_screen_density(kcd, maxsize * 2.0f);
 
-       density = MAX2(density, 1);
+       if (density < 1.0f)
+               density = 1.0f;
 
-       return MIN2(maxsize / (density * 0.5f), maxsize);
+       return minf(maxsize / (density * 0.5f), maxsize);
 }
 
 /* p is closest point on edge to the mouse cursor */
index e6ea42a..3079719 100644 (file)
@@ -1574,6 +1574,8 @@ static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
                        else if (bgpic->source == V3D_BGPIC_MOVIE) {
                                clip = NULL;
 
+                               /* TODO: skip drawing when out of frame range (as image sequences do above) */
+
                                if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
                                        if (scene->camera)
                                                clip = BKE_object_movieclip_get(scene, scene->camera, 1);
index 4486025..3528116 100644 (file)
@@ -1392,8 +1392,8 @@ 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 delta_angle = MIN2(15.0f / dist, (float)M_PI / 4.0f);
-                               float spacing_angle = MIN2(5.0f / dist, (float)M_PI / 12.0f);
+                               float delta_angle = minf(15.0f / dist, (float)M_PI / 4.0f);
+                               float spacing_angle = minf(5.0f / dist, (float)M_PI / 12.0f);
                                UI_ThemeColor(TH_WIRE);
 
                                setlinestyle(3);
index af0b33d..d724155 100644 (file)
@@ -1829,7 +1829,7 @@ static void editmesh_set_connectivity_distance(BMEditMesh *em, float mtx[][3], f
                        d2 = d + len_v3(vec);
                        
                        if (dists[BM_elem_index_get(v3)] != FLT_MAX)
-                               dists[BM_elem_index_get(v3)] = MIN2(d2, dists[BM_elem_index_get(v3)]);
+                               dists[BM_elem_index_get(v3)] = minf(d2, dists[BM_elem_index_get(v3)]);
                        else
                                dists[BM_elem_index_get(v3)] = d2;
                        
index 43f3e81..5c2e57c 100644 (file)
@@ -403,7 +403,9 @@ static void stitch_island_calculate_edge_rotation(UvEdge *edge, StitchState *sta
        edgecos = uv1[0] * uv2[0] + uv1[1] * uv2[1];
        edgesin = uv1[0] * uv2[1] - uv2[0] * uv1[1];
 
-       rotation = (edgesin > 0.0f) ? acosf(MAX2(-1.0f, MIN2(1.0f, edgecos))) : -acosf(MAX2(-1.0f, MIN2(1.0f, edgecos)));
+       rotation = (edgesin > 0.0f) ?
+                   +acosf(maxf(-1.0f, minf(1.0f, edgecos))) :
+                   -acosf(maxf(-1.0f, minf(1.0f, edgecos)));
 
        island_stitch_data[element1->island].num_rot_elements++;
        island_stitch_data[element1->island].rotation += rotation;
index 82f2add..b208df7 100644 (file)
@@ -798,7 +798,6 @@ static float OrenNayar_Diff(float nl, const float n[3], const float l[3], const
 /* Minnaert diffuse */
 static float Minnaert_Diff(float nl, const float n[3], const float v[3], float darkness)
 {
-
        float i, nv;
 
        /* nl = dot product between surface normal and light vector */
@@ -806,12 +805,12 @@ static float Minnaert_Diff(float nl, const float n[3], const float v[3], float d
                return 0.0f;
 
        /* nv = dot product between surface normal and view vector */
-       nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2];
+       nv = dot_v3v3(n, v);
        if (nv < 0.0f)
                nv = 0.0f;
 
        if (darkness <= 1.0f)
-               i = nl * pow(MAX2(nv*nl, 0.1f), (darkness - 1.0f) ); /*The Real model*/
+               i = nl * pow(maxf(nv * nl, 0.1f), (darkness - 1.0f) ); /*The Real model*/
        else
                i = nl * pow( (1.001f - nv), (darkness  - 1.0f) ); /*Nvidia model*/
 
index 46ebd0e..ea4ac1e 100644 (file)
@@ -311,7 +311,7 @@ int SCA_Joystick::pAxisTest(int axisnum)
        short i2= m_axis_array[(axisnum*2)+1];
        
        /* long winded way to do
-        *   return MAX2(abs(i1), abs(i2))
+        *   return maxf(absf(i1), absf(i2))
         * avoid abs from math.h */
        if (i1 < 0) i1 = -i1;
        if (i2 < 0) i2 = -i2;
index fd47587..a942f87 100644 (file)
@@ -378,13 +378,14 @@ static MT_Point3 nearestPointToObstacle(MT_Point3& pos ,KX_Obstacle* obstacle)
                MT_Vector3 ab = obstacle->m_pos2 - obstacle->m_pos;
                if (!ab.fuzzyZero())
                {
+                       const MT_Scalar dist = ab.length();
                        MT_Vector3 abdir = ab.normalized();
                        MT_Vector3  v = pos - obstacle->m_pos;
                        MT_Scalar proj = abdir.dot(v);
-                       CLAMP(proj, 0, ab.length());
+                       CLAMP(proj, 0, dist);
                        MT_Point3 res = obstacle->m_pos + abdir*proj;
                        return res;
-               }               
+               }
        }
        case KX_OBSTACLE_CIRCLE :
        default: