code cleanup: minor improvements to float/vector usage.
authorCampbell Barton <ideasman42@gmail.com>
Sat, 12 May 2012 22:13:38 +0000 (22:13 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 12 May 2012 22:13:38 +0000 (22:13 +0000)
13 files changed:
source/blender/blenkernel/intern/CCGSubSurf.c
source/blender/blenkernel/intern/armature.c
source/blender/blenkernel/intern/constraint.c
source/blender/blenkernel/intern/curve.c
source/blender/blenkernel/intern/dynamicpaint.c
source/blender/blenlib/BLI_graph.h
source/blender/blenlib/intern/graph.c
source/blender/bmesh/tools/BME_bevel.c
source/blender/editors/mesh/editmesh_bvh.c
source/blender/editors/sculpt_paint/paint_image.c
source/blender/editors/sculpt_paint/paint_vertex.c
source/blender/editors/transform/transform.c
source/blender/render/intern/source/zbuf.c

index 7676a645e7f3e44f51a3d861bd51d3c58bf2ad62..9bdb575bd4978accfc63a8906a59b8222b18ba0d 100644 (file)
@@ -777,7 +777,7 @@ static float *_face_getIFNoEdge(CCGFace *f, CCGEdge *e, int f_ed_idx, int lvl, i
 {
        return (float *) ((byte *) _face_getIFCoEdge(f, e, f_ed_idx, lvl, eX, eY, levels, dataSize) + normalDataOffset);
 }
-static void _face_calcIFNo(CCGFace *f, int lvl, int S, int x, int y, float *no, int levels, int dataSize)
+static void _face_calcIFNo(CCGFace *f, int lvl, int S, int x, int y, float no[3], int levels, int dataSize)
 {
        float *a = _face_getIFCo(f, lvl, S, x + 0, y + 0, levels, dataSize);
        float *b = _face_getIFCo(f, lvl, S, x + 1, y + 0, levels, dataSize);
index 599587cb15b240b4e14a9ba7cea6b00b54455c17..33cb0707316bc2a367a98efa33e24eb0042c486d 100644 (file)
@@ -2541,7 +2541,7 @@ int get_selected_defgroups(Object *ob, char *dg_selection, int defbase_tot)
 }
 
 /************** Bounding box ********************/
-int minmax_armature(Object *ob, float min[3], float max[3])
+static int minmax_armature(Object *ob, float min[3], float max[3])
 {
        bPoseChannel *pchan;
 
@@ -2554,7 +2554,7 @@ int minmax_armature(Object *ob, float min[3], float max[3])
        return (ob->pose->chanbase.first != NULL);
 }
 
-void boundbox_armature(Object *ob, float *loc, float *size)
+static void boundbox_armature(Object *ob, float loc[3], float size[3])
 {
        BoundBox *bb;
        float min[3], max[3];
index 868da0fda94b55ed163527c46b7c2f936ce7a30a..a1f87762db79da4211c96aa5920abb2af1c5a862 100644 (file)
@@ -961,7 +961,7 @@ static int basis_cross(int n, int m)
        }
 }
 
-static void vectomat(float *vec, float *target_up, short axis, short upflag, short flags, float m[][3])
+static void vectomat(const float vec[3], const float target_up[3], short axis, short upflag, short flags, float m[][3])
 {
        float n[3];
        float u[3]; /* vector specifying the up axis */
index 43cc63aefa6f0f337b52887306bee59ede94c737..d5dfcda77ce88b3aa1753a3cae7acdbace576a6b 100644 (file)
@@ -588,7 +588,7 @@ void BKE_nurb_test2D(Nurb *nu)
        }
 }
 
-void BKE_nurb_minmax(Nurb *nu, float *min, float *max)
+void BKE_nurb_minmax(Nurb *nu, float min[3], float max[3])
 {
        BezTriple *bezt;
        BPoint *bp;
@@ -1166,19 +1166,23 @@ void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float
        }
 }
 
-static void forward_diff_bezier_cotangent(float *p0, float *p1, float *p2, float *p3, float *p, int it, int stride)
+static void forward_diff_bezier_cotangent(const float p0[3], const float p1[3], const float p2[3], const float p3[3],
+                                          float p[3], int it, int stride)
 {
        /* note that these are not purpendicular to the curve
         * they need to be rotated for this,
         *
-        * This could also be optimized like forward_diff_bezier */
+        * This could also be optimized like BKE_curve_forward_diff_bezier */
        int a;
        for (a = 0; a <= it; a++) {
                float t = (float)a / (float)it;
 
                int i;
                for (i = 0; i < 3; i++) {
-                       p[i] = (-6 * t + 6) * p0[i] + (18 * t - 12) * p1[i] + (-18 * t + 6) * p2[i] + (6 * t) * p3[i];
+                       p[i] = (-6.0f  * t +  6.0f) * p0[i] +
+                              ( 18.0f * t - 12.0f) * p1[i] +
+                              (-18.0f * t +  6.0f) * p2[i] +
+                              ( 6.0f  * t)         * p3[i];
                }
                normalize_v3(p);
                p = (float *)(((char *)p) + stride);
index 5603ecfc7466736e87333d751ea3283657d348a0..bbd57a5478b3f329f51e5b0e636b411cf4b8201e 100644 (file)
@@ -424,7 +424,7 @@ static int surface_totalSamples(DynamicPaintSurface *surface)
        return surface->data->total_points;
 }
 
-static void blendColors(float t_color[3], float t_alpha, float s_color[3], float s_alpha, float result[4])
+static void blendColors(const float t_color[3], float t_alpha, const float s_color[3], float s_alpha, float result[4])
 {
        int i;
        float i_alpha = 1.0f - s_alpha;
@@ -2842,7 +2842,8 @@ static void mesh_faces_nearest_point_dp(void *userdata, int index, const float c
  *     timescale : value used to adjust time dependand
  *                         operations when using substeps
  */
-static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, int paintFlags, float *paintColor, float *paintAlpha, float *paintWetness, float *timescale)
+static void dynamicPaint_mixPaintColors(DynamicPaintSurface *surface, int index, int paintFlags,
+                                        const float paintColor[3], float *paintAlpha, float *paintWetness, float *timescale)
 {
        PaintPoint *pPoint = &((PaintPoint *)surface->data->type_data)[index];
 
index d45523aac7d208913cffd4dc4d570dfd80641b53..864e92d8cac175c94b9e42c9f0c1f50731f4a19a 100644 (file)
@@ -155,7 +155,7 @@ void BLI_calcGraphLength(BGraph *graph);
 void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced);
 void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced);
 void BLI_removeDoubleNodes(BGraph *graph, float limit);
-BNode *BLI_FindNodeByPosition(BGraph *graph, float *p, float limit);
+BNode *BLI_FindNodeByPosition(BGraph *graph, const float p[3], const float limit);
 
 BArc  *BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v);
 
index 8eaf793ad5e5eba34b706f8372dce6c7b1d93cd0..51d7cb58b009891844ec9d37d36b8bb445e5e331 100644 (file)
@@ -249,7 +249,7 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit)
        
 }
 
-BNode *BLI_FindNodeByPosition(BGraph *graph, float *p, float limit)
+BNode *BLI_FindNodeByPosition(BGraph *graph, const float p[3], const float limit)
 {
        BNode *closest_node = NULL, *node;
        float min_distance = 0.0f;
index e03df77a2900177ec4dfc531810811e0424a966a..df031a50d54613d2ae22345679d4f7dd6de58e67 100644 (file)
@@ -195,7 +195,7 @@ static int BME_bevel_is_split_vert(BMesh *bm, BMLoop *l)
  * the bevel operation as a whole based on the relationship between v1 and v2
  * (won't necessarily be a vec from v1->co to v2->co, though it probably will be);
  * the return value is -1 for failure, 0 if we used vert co's, and 1 if we used transform origins */
-static int BME_bevel_get_vec(float *vec, BMVert *v1, BMVert *v2, BME_TransData_Head *td)
+static int BME_bevel_get_vec(float vec[3], BMVert *v1, BMVert *v2, BME_TransData_Head *td)
 {
        BME_TransData *vtd1, *vtd2;
 
index 6d740812f275bf9dff9b7194fb2d740a44135b0a..16948a2372d8a79c127022cf740073309348da33 100644 (file)
@@ -201,12 +201,13 @@ void BMBVH_FreeBVH(BMBVHTree *tree)
 }
 
 /* taken from bvhutils.c */
-static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist), float *v0, 
-                                  float *v1, float *v2, float *uv, float UNUSED(e))
+static float ray_tri_intersection(const BVHTreeRay *ray, const float UNUSED(m_dist),
+                                  const float v0[3],  const float v1[3], const float v2[3],
+                                  float r_uv[2], float UNUSED(e))
 {
        float dist;
 
-       if (isect_ray_tri_v3((float *)ray->origin, (float *)ray->direction, v0, v1, v2, &dist, uv)) {
+       if (isect_ray_tri_v3((float *)ray->origin, (float *)ray->direction, v0, v1, v2, &dist, r_uv)) {
                return dist;
        }
 
@@ -343,7 +344,7 @@ BMVert *BMBVH_FindClosestVert(BMBVHTree *tree, float *co, float maxdist)
 
 /* UNUSED */
 #if 0
-static short winding(float *v1, float *v2, float *v3)
+static short winding(const float v1[3], const float v2[3], const float v3[3])
 /* is v3 to the right of (v1 - v2) ? With exception: v3 == v1 || v3 == v2 */
 {
        double inp;
index c46c153aa700c21dc0c866372a196afbd85ee7ea..ead85486ec073addbc493b4a8e7c8eda9d3a7033 100644 (file)
@@ -3769,7 +3769,7 @@ static void do_projectpaint_smear_f(ProjPaintState *ps, ProjPixel *projPixel, fl
        BLI_linklist_prepend_arena(smearPixels_f, (void *)projPixel, smearArena);
 }
 
-static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask)
+static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, const float rgba[4], float alpha, float mask)
 {
        unsigned char rgba_ub[4];
        
@@ -3793,7 +3793,7 @@ static void do_projectpaint_draw(ProjPaintState *ps, ProjPixel *projPixel, float
        }
 }
 
-static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, float *rgba, float alpha, float mask, int use_color_correction)
+static void do_projectpaint_draw_f(ProjPaintState *ps, ProjPixel *projPixel, float rgba[4], float alpha, float mask, int use_color_correction)
 {
        if (ps->is_texbrush) {
                /* rgba already holds a texture result here from higher level function */
@@ -4190,9 +4190,10 @@ static void imapaint_image_update(SpaceImage *sima, Image *image, ImBuf *ibuf, s
 
 /* Image Paint Operations */
 
-static void imapaint_ibuf_get_set_rgb(ImBuf *ibuf, int x, int y, short torus, short set, float *rgb)
+/* keep these functions in sync */
+static void imapaint_ibuf_rgb_get(ImBuf *ibuf, int x, int y, const short is_torus, float r_rgb[3])
 {
-       if (torus) {
+       if (is_torus) {
                x %= ibuf->x;
                if (x < 0) x += ibuf->x;
                y %= ibuf->y;
@@ -4201,23 +4202,29 @@ static void imapaint_ibuf_get_set_rgb(ImBuf *ibuf, int x, int y, short torus, sh
 
        if (ibuf->rect_float) {
                float *rrgbf = ibuf->rect_float + (ibuf->x * y + x) * 4;
-
-               if (set) {
-                       IMAPAINT_FLOAT_RGB_COPY(rrgbf, rgb);
-               }
-               else {
-                       IMAPAINT_FLOAT_RGB_COPY(rgb, rrgbf);
-               }
+               IMAPAINT_FLOAT_RGB_COPY(r_rgb, rrgbf);
        }
        else {
                char *rrgb = (char *)ibuf->rect + (ibuf->x * y + x) * 4;
+               IMAPAINT_CHAR_RGB_TO_FLOAT(r_rgb, rrgb)
+       }
+}
+static void imapaint_ibuf_rgb_set(ImBuf *ibuf, int x, int y, const short is_torus, const float rgb[3])
+{
+       if (is_torus) {
+               x %= ibuf->x;
+               if (x < 0) x += ibuf->x;
+               y %= ibuf->y;
+               if (y < 0) y += ibuf->y;
+       }
 
-               if (set) {
-                       IMAPAINT_FLOAT_RGB_TO_CHAR(rrgb, rgb)
-               }
-               else {
-                       IMAPAINT_CHAR_RGB_TO_FLOAT(rgb, rrgb)
-               }
+       if (ibuf->rect_float) {
+               float *rrgbf = ibuf->rect_float + (ibuf->x * y + x) * 4;
+               IMAPAINT_FLOAT_RGB_COPY(rrgbf, rgb);
+       }
+       else {
+               char *rrgb = (char *)ibuf->rect + (ibuf->x * y + x) * 4;
+               IMAPAINT_FLOAT_RGB_TO_CHAR(rrgb, rgb)
        }
 }
 
@@ -4227,10 +4234,10 @@ static int imapaint_ibuf_add_if(ImBuf *ibuf, unsigned int x, unsigned int y, flo
 
        // XXX: signed unsigned mismatch
        if ((x >= (unsigned int)(ibuf->x)) || (y >= (unsigned int)(ibuf->y))) {
-               if (torus) imapaint_ibuf_get_set_rgb(ibuf, x, y, 1, 0, inrgb);
+               if (torus) imapaint_ibuf_rgb_get(ibuf, x, y, 1, inrgb);
                else return 0;
        }
-       else imapaint_ibuf_get_set_rgb(ibuf, x, y, 0, 0, inrgb);
+       else imapaint_ibuf_rgb_get(ibuf, x, y, 0, inrgb);
 
        outrgb[0] += inrgb[0];
        outrgb[1] += inrgb[1];
@@ -4239,7 +4246,7 @@ static int imapaint_ibuf_add_if(ImBuf *ibuf, unsigned int x, unsigned int y, flo
        return 1;
 }
 
-static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, short torus)
+static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, const short is_torus)
 {
        int x, y, count, xi, yi, xo, yo;
        int out_off[2], in_off[2], dim[2];
@@ -4251,7 +4258,7 @@ static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, short toru
        in_off[1] = pos[1];
        out_off[0] = out_off[1] = 0;
 
-       if (!torus) {
+       if (!is_torus) {
                IMB_rectclip(ibuf, ibufb, &in_off[0], &in_off[1], &out_off[0],
                             &out_off[1], &dim[0], &dim[1]);
 
@@ -4266,27 +4273,25 @@ static void imapaint_lift_soften(ImBuf *ibuf, ImBuf *ibufb, int *pos, short toru
                        yi = in_off[1] + y;
 
                        count = 1;
-                       imapaint_ibuf_get_set_rgb(ibuf, xi, yi, torus, 0, outrgb);
+                       imapaint_ibuf_rgb_get(ibuf, xi, yi, is_torus, outrgb);
 
-                       count += imapaint_ibuf_add_if(ibuf, xi - 1, yi - 1, outrgb, torus);
-                       count += imapaint_ibuf_add_if(ibuf, xi - 1, yi, outrgb, torus);
-                       count += imapaint_ibuf_add_if(ibuf, xi - 1, yi + 1, outrgb, torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi - 1, yi - 1, outrgb, is_torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi - 1, yi, outrgb, is_torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi - 1, yi + 1, outrgb, is_torus);
 
-                       count += imapaint_ibuf_add_if(ibuf, xi, yi - 1, outrgb, torus);
-                       count += imapaint_ibuf_add_if(ibuf, xi, yi + 1, outrgb, torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi, yi - 1, outrgb, is_torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi, yi + 1, outrgb, is_torus);
 
-                       count += imapaint_ibuf_add_if(ibuf, xi + 1, yi - 1, outrgb, torus);
-                       count += imapaint_ibuf_add_if(ibuf, xi + 1, yi, outrgb, torus);
-                       count += imapaint_ibuf_add_if(ibuf, xi + 1, yi + 1, outrgb, torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi + 1, yi - 1, outrgb, is_torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi + 1, yi, outrgb, is_torus);
+                       count += imapaint_ibuf_add_if(ibuf, xi + 1, yi + 1, outrgb, is_torus);
 
-                       outrgb[0] /= count;
-                       outrgb[1] /= count;
-                       outrgb[2] /= count;
+                       mul_v3_fl(outrgb, 1.0f / (float)count);
 
                        /* write into brush buffer */
                        xo = out_off[0] + x;
                        yo = out_off[1] + y;
-                       imapaint_ibuf_get_set_rgb(ibufb, xo, yo, 0, 1, outrgb);
+                       imapaint_ibuf_rgb_set(ibufb, xo, yo, 0, outrgb);
                }
        }
 }
index c01da3a816fde15480304fb7984388f819903a62..3b74ae54810d1a02a4802d5448fe547fdb96724c 100644 (file)
@@ -844,7 +844,7 @@ static int sample_backbuf_area(ViewContext *vc, int *indexar, int totface, int x
 }
 
 /* whats _dl mean? */
-static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float *vert_nor,
+static float calc_vp_strength_dl(VPaint *vp, ViewContext *vc, const float vert_nor[3],
                                  const float mval[2], const float brush_size_pressure)
 {
        Brush *brush = paint_brush(&vp->paint);
index ae7d02e1cfb93bd9cc1513b29cc6ed680f7542e1..8b472fd987f820c6bfbd4381c1d22534c2468999 100644 (file)
@@ -260,7 +260,7 @@ void projectFloatView(TransInfo *t, const float vec[3], float adr[2])
        zero_v2(adr);
 }
 
-void applyAspectRatio(TransInfo *t, float *vec)
+void applyAspectRatio(TransInfo *t, float vec[2])
 {
        if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
                SpaceImage *sima= t->sa->spacedata.first;
@@ -293,7 +293,7 @@ void applyAspectRatio(TransInfo *t, float *vec)
        }
 }
 
-void removeAspectRatio(TransInfo *t, float *vec)
+void removeAspectRatio(TransInfo *t, float vec[2])
 {
        if ((t->spacetype==SPACE_IMAGE) && (t->mode==TFM_TRANSLATION)) {
                SpaceImage *sima= t->sa->spacedata.first;
index 4c3c9889d532920a4682d259410a94d273824fe5..78e0810fb7708119ba2aa482c77264bd41506f6e 100644 (file)
@@ -3853,13 +3853,6 @@ static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x,
        return 0;
 }
 
-static void addvecmul(float *v1, float *v2, float fac)
-{
-       v1[0]= v1[0]+fac*v2[0];
-       v1[1]= v1[1]+fac*v2[1];
-       v1[2]= v1[2]+fac*v2[2];
-}
-
 static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassflag)
 {
        int a, sample, osa = (R.osa? R.osa: 1), retval = osa;
@@ -3887,34 +3880,34 @@ static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassf
                                                addAlphaUnderFloat(samp_shr->col, shr->col);
                                        
                                        if (addpassflag & SCE_PASS_NORMAL)
-                                               addvecmul(samp_shr->nor, shr->nor, fac);
+                                               madd_v3_v3fl(samp_shr->nor, shr->nor, fac);
 
                                        if (addpassflag & SCE_PASS_EMIT)
-                                               addvecmul(samp_shr->emit, shr->emit, fac);
+                                               madd_v3_v3fl(samp_shr->emit, shr->emit, fac);
 
                                        if (addpassflag & SCE_PASS_DIFFUSE)
-                                               addvecmul(samp_shr->diff, shr->diff, fac);
+                                               madd_v3_v3fl(samp_shr->diff, shr->diff, fac);
                                        
                                        if (addpassflag & SCE_PASS_SPEC)
-                                               addvecmul(samp_shr->spec, shr->spec, fac);
+                                               madd_v3_v3fl(samp_shr->spec, shr->spec, fac);
 
                                        if (addpassflag & SCE_PASS_SHADOW)
-                                               addvecmul(samp_shr->shad, shr->shad, fac);
+                                               madd_v3_v3fl(samp_shr->shad, shr->shad, fac);
 
                                        if (addpassflag & SCE_PASS_AO)
-                                               addvecmul(samp_shr->ao, shr->ao, fac);
+                                               madd_v3_v3fl(samp_shr->ao, shr->ao, fac);
 
                                        if (addpassflag & SCE_PASS_ENVIRONMENT)
-                                               addvecmul(samp_shr->env, shr->env, fac);
+                                               madd_v3_v3fl(samp_shr->env, shr->env, fac);
 
                                        if (addpassflag & SCE_PASS_INDIRECT)
-                                               addvecmul(samp_shr->indirect, shr->indirect, fac);
+                                               madd_v3_v3fl(samp_shr->indirect, shr->indirect, fac);
 
                                        if (addpassflag & SCE_PASS_REFLECT)
-                                               addvecmul(samp_shr->refl, shr->refl, fac);
+                                               madd_v3_v3fl(samp_shr->refl, shr->refl, fac);
                                        
                                        if (addpassflag & SCE_PASS_REFRACT)
-                                               addvecmul(samp_shr->refr, shr->refr, fac);
+                                               madd_v3_v3fl(samp_shr->refr, shr->refr, fac);
                                        
                                        if (addpassflag & SCE_PASS_MIST)
                                                samp_shr->mist= samp_shr->mist+fac*shr->mist;