Commit: 74758576fc9c1220563c86ce47a17c51d08a6d4f
Author: Bastien Montagne
Date:   Wed Jul 30 11:00:59 2014 +0200
Branches: master
https://developer.blender.org/rB74758576fc9c1220563c86ce47a17c51d08a6d4f

Cleanup: general cleanup in BLI_math code (mostly, use 'const' where possible, 
true/false for booleans, format for float litterals).

===================================================================

M       source/blender/blenlib/intern/math_color.c
M       source/blender/blenlib/intern/math_color_inline.c
M       source/blender/blenlib/intern/math_geom.c
M       source/blender/blenlib/intern/math_matrix.c
M       source/blender/blenlib/intern/math_rotation.c
M       source/blender/blenlib/intern/math_vector.c
M       source/blender/blenlib/intern/math_vector_inline.c

===================================================================

diff --git a/source/blender/blenlib/intern/math_color.c 
b/source/blender/blenlib/intern/math_color.c
index eb9e36b..828a84d 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -113,7 +113,7 @@ void yuv_to_rgb(float y, float u, float v, float *lr, float 
*lg, float *lb)
 void rgb_to_ycc(float r, float g, float b, float *ly, float *lcb, float *lcr, 
int colorspace)
 {
        float sr, sg, sb;
-       float y = 128.f, cr = 128.f, cb = 128.f;
+       float y = 128.0f, cr = 128.0f, cb = 128.0f;
 
        sr = 255.0f * r;
        sg = 255.0f * g;
@@ -152,7 +152,7 @@ void rgb_to_ycc(float r, float g, float b, float *ly, float 
*lcb, float *lcr, in
 /* FIXME comment above must be wrong because BLI_YCC_ITU_BT601 y 16.0 cr 16.0 
-> r -0.7009 */
 void ycc_to_rgb(float y, float cb, float cr, float *lr, float *lg, float *lb, 
int colorspace)
 {
-       float r = 128.f, g = 128.f, b = 128.f;
+       float r = 128.0f, g = 128.0f, b = 128.0f;
 
        switch (colorspace) {
                case BLI_YCC_ITU_BT601:
@@ -269,8 +269,8 @@ void rgb_to_hsl(float r, float g, float b, float *lh, float 
*ls, float *ll)
 
 void rgb_to_hsl_compat(float r, float g, float b, float *lh, float *ls, float 
*ll)
 {
-       float orig_s = *ls;
-       float orig_h = *lh;
+       const float orig_s = *ls;
+       const float orig_h = *lh;
 
        rgb_to_hsl(r, g, b, lh, ls, ll);
 
@@ -302,8 +302,8 @@ void rgb_to_hsl_v(const float rgb[3], float r_hsl[3])
 
 void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float 
*lv)
 {
-       float orig_h = *lh;
-       float orig_s = *ls;
+       const float orig_h = *lh;
+       const float orig_s = *ls;
 
        rgb_to_hsv(r, g, b, lh, ls, lv);
 
@@ -598,11 +598,12 @@ static float index_to_float(const unsigned short i)
 
 void BLI_init_srgb_conversion(void)
 {
-       static int initialized = 0;
+       static bool initialized = false;
        unsigned int i, b;
 
-       if (initialized) return;
-       initialized = 1;
+       if (initialized)
+               return;
+       initialized = true;
 
        /* Fill in the lookup table to convert floats to bytes: */
        for (i = 0; i < 0x10000; i++) {
@@ -657,13 +658,13 @@ static float xyz_to_lab_component(float v)
 
 void xyz_to_lab(float x, float y, float z, float *l, float *a, float *b)
 {
-       float xr = x / 95.047f;
-       float yr = y / 100.0f;
-       float zr = z / 108.883f;
+       const float xr = x / 95.047f;
+       const float yr = y / 100.0f;
+       const float zr = z / 108.883f;
 
-       float fx = xyz_to_lab_component(xr);
-       float fy = xyz_to_lab_component(yr);
-       float fz = xyz_to_lab_component(zr);
+       const float fx = xyz_to_lab_component(xr);
+       const float fy = xyz_to_lab_component(yr);
+       const float fz = xyz_to_lab_component(zr);
 
        *l = 116.0f * fy - 16.0f;
        *a = 500.0f * (fx - fy);
diff --git a/source/blender/blenlib/intern/math_color_inline.c 
b/source/blender/blenlib/intern/math_color_inline.c
index bb22015..9233749 100644
--- a/source/blender/blenlib/intern/math_color_inline.c
+++ b/source/blender/blenlib/intern/math_color_inline.c
@@ -255,11 +255,11 @@ MINLINE float rgb_to_luma_y(const float rgb[3])
 
 MINLINE int compare_rgb_uchar(const unsigned char col_a[3], const unsigned 
char col_b[3], const int limit)
 {
-       int r = (int)col_a[0] - (int)col_b[0];
+       const int r = (int)col_a[0] - (int)col_b[0];
        if (ABS(r) < limit) {
-               int g = (int)col_a[1] - (int)col_b[1];
+               const int g = (int)col_a[1] - (int)col_b[1];
                if (ABS(g) < limit) {
-                       int b = (int)col_a[2] - (int)col_b[2];
+                       const int b = (int)col_a[2] - (int)col_b[2];
                        if (ABS(b) < limit) {
                                return 1;
                        }
@@ -280,7 +280,7 @@ MINLINE void premul_to_straight_v4_v4(float straight[4], 
const float premul[4])
                straight[3] = premul[3];
        }
        else {
-               float alpha_inv = 1.0f / premul[3];
+               const float alpha_inv = 1.0f / premul[3];
                straight[0] = premul[0] * alpha_inv;
                straight[1] = premul[1] * alpha_inv;
                straight[2] = premul[2] * alpha_inv;
@@ -295,7 +295,7 @@ MINLINE void premul_to_straight_v4(float color[4])
 
 MINLINE void straight_to_premul_v4_v4(float premul[4], const float straight[4])
 {
-       float alpha = straight[3];
+       const float alpha = straight[3];
        premul[0] = straight[0] * alpha;
        premul[1] = straight[1] * alpha;
        premul[2] = straight[2] * alpha;
@@ -309,8 +309,8 @@ MINLINE void straight_to_premul_v4(float color[4])
 
 MINLINE void straight_uchar_to_premul_float(float result[4], const unsigned 
char color[4])
 {
-       float alpha = color[3] * (1.0f / 255.0f);
-       float fac = alpha * (1.0f / 255.0f);
+       const float alpha = color[3] * (1.0f / 255.0f);
+       const float fac = alpha * (1.0f / 255.0f);
 
        result[0] = color[0] * fac;
        result[1] = color[1] * fac;
@@ -327,7 +327,7 @@ MINLINE void premul_float_to_straight_uchar(unsigned char 
*result, const float c
                result[3] = FTOCHAR(color[3]);
        }
        else {
-               float alpha_inv = 1.0f / color[3];
+               const float alpha_inv = 1.0f / color[3];
 
                /* hopefully this would be optimized */
                result[0] = FTOCHAR(color[0] * alpha_inv);
diff --git a/source/blender/blenlib/intern/math_geom.c 
b/source/blender/blenlib/intern/math_geom.c
index 2cd32b3..54e3545 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -568,7 +568,7 @@ int isect_seg_seg_v2_point(const float v1[2], const float 
v2[2], const float v3[
 {
        float a1, a2, b1, b2, c1, c2, d;
        float u, v;
-       const float eps = 0.000001f;
+       const float eps = 1e-6f;
        const float eps_sq = eps * eps;
 
        a1 = v2[0] - v1[0];
@@ -1278,13 +1278,13 @@ bool isect_plane_plane_v3(float r_isect_co[3], float 
r_isect_no[3],
 static bool getLowestRoot(const float a, const float b, const float c, const 
float maxR, float *root)
 {
        /* Check if a solution exists */
-       float determinant = b * b - 4.0f * a * c;
+       const float determinant = b * b - 4.0f * a * c;
 
        /* If determinant is negative it means no solutions. */
        if (determinant >= 0.0f) {
                /* calculate the two roots: (if determinant == 0 then
                 * x1==x2 but lets disregard that slight optimization) */
-               float sqrtD = sqrtf(determinant);
+               const float sqrtD = sqrtf(determinant);
                float r1 = (-b - sqrtD) / (2.0f * a);
                float r2 = (-b + sqrtD) / (2.0f * a);
 
@@ -1295,18 +1295,18 @@ static bool getLowestRoot(const float a, const float b, 
const float c, const flo
                /* Get lowest root: */
                if (r1 > 0.0f && r1 < maxR) {
                        *root = r1;
-                       return 1;
+                       return true;
                }
 
                /* It is possible that we want x2 - this can happen */
                /* if x1 < 0 */
                if (r2 > 0.0f && r2 < maxR) {
                        *root = r2;
-                       return 1;
+                       return true;
                }
        }
        /* No (valid) solutions */
-       return 0;
+       return false;
 }
 
 bool isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const 
float radius,
@@ -1335,7 +1335,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
 
        if (fabsf(nordotv) < 0.000001f) {
                if (fabsf(a) >= radius) {
-                       return 0;
+                       return false;
                }
        }
        else {
@@ -1377,7 +1377,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
                        //(((unsigned int)z)& ~(((unsigned int)x)|((unsigned 
int)y))) & 0x80000000) {
                        *r_lambda = t0;
                        copy_v3_v3(ipoint, point);
-                       return 1;
+                       return true;
                }
        }
 
@@ -1394,7 +1394,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
 
        if (getLowestRoot(a, b, c, *r_lambda, r_lambda)) {
                copy_v3_v3(ipoint, v0);
-               found_by_sweep = 1;
+               found_by_sweep = true;
        }
 
        /*v1*/
@@ -1404,7 +1404,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
 
        if (getLowestRoot(a, b, c, *r_lambda, r_lambda)) {
                copy_v3_v3(ipoint, v1);
-               found_by_sweep = 1;
+               found_by_sweep = true;
        }
 
        /*v2*/
@@ -1414,7 +1414,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
 
        if (getLowestRoot(a, b, c, *r_lambda, r_lambda)) {
                copy_v3_v3(ipoint, v2);
-               found_by_sweep = 1;
+               found_by_sweep = true;
        }
 
        /*---test edges---*/
@@ -1440,7 +1440,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
                        copy_v3_v3(ipoint, e1);
                        mul_v3_fl(ipoint, e);
                        add_v3_v3(ipoint, v0);
-                       found_by_sweep = 1;
+                       found_by_sweep = true;
                }
        }
 
@@ -1462,7 +1462,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
                        copy_v3_v3(ipoint, e2);
                        mul_v3_fl(ipoint, e);
                        add_v3_v3(ipoint, v0);
-                       found_by_sweep = 1;
+                       found_by_sweep = true;
                }
        }
 
@@ -1489,7 +1489,7 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], 
const float p2[3], const fl
                        copy_v3_v3(ipoint, e3);
                        mul_v3_fl(ipoint, e);
                        add_v3_v3(ipoint, v1);
-                       found_by_sweep = 1;
+                       found_by_sweep = true;
                }
        }
 
@@ -1508,10 +1508,10 @@ bool isect_axial_line_tri_v3(const int axis, const 
float p1[3], const float p2[3
        return isect_line_tri_v3(p1, p2, v0, v1, v2, lambda);
 
        /* first a simple bounding box test */
-       if (min_fff(v0[a1], v1[a1], v2[a1]) > p1[a1]) return 0;
-       if (min_fff(v0[a2], v1[a2], v2[a2]) > p1[a2]) return 0;
-       if (max_fff(v0[a1], v1[a1], v2[a1]) < p1[a1]) return 0;
-       if (max_fff(v0[a2], v1[a2], v2[a2]) < p1[a2]) return 0;
+       if (min_fff(v0[a1], v1[a1], v2[a1]) > p1[a1]) return false;
+       if (min_fff(v0[a2], v1[a2], v2[a2]) > p1[a2]) return false;
+       if (max_fff(v0[a1], v1[a1], v2[a1]) < p1[a1]) return false;
+       if (max_fff(v0[a2], v1[a2], v2[a2]) < p1[a2]) return false;
 
        /* then a full intersection test */
 #endif
@@ -1521,7 +1521,7 @@ bool isect_axial_line_tri_v3(const int axis, const float 
p1[3], const float p2[3
        sub_v3_v3v3(p, v0, p1);
 
        f = (e2[a1] * e1[a2] - e2[a2] * e1[a1]);
-       if ((f > -0.000001f) && (f < 0.000001f)) return 0;
+       if ((f > -0.000001f) && (f < 0.000001f)) return false;
 
        v = (p[a2] * e1[a1] - p[a1] * e1[a2]) / f;
        if ((v < 0.0f) || (v > 1.0f)) return 0;
@@ -1529,7 +1529,7 @@ bool isect_axial_line_tri_v3(const int axis, const float 
p1[3], const float p2[3
        f = e1[a1];
        if ((f > -0.000001f) && (f < 0.000001f)) {
                f = e1[a2];
-               if ((f > -0.000001f) && (f < 0.000001f)) return 0;
+               if ((f > -0.000001f) && (f < 0.000001f)) return false;
                u = (-p[a2] - v * e2[a2]) / f;
        }
        else
@@ -1539,9 +1539,9 @@ bool isect_axial_line_tri_v3(const int axis, const float 
p1[3], const float p2[3
 
        *r_lambda = (p[a0] + u * e1[a0] + v * e2[a0]) / (p2[a0] - p1[a0]);
 
-       if ((*r_lambda < 0.0f) || (*r_l

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to