diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-30 13:00:59 +0400 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2014-07-30 14:19:41 +0400 |
commit | 74758576fc9c1220563c86ce47a17c51d08a6d4f (patch) | |
tree | 2291df8ac132913345f87322a473d19f650ce25c | |
parent | eea7521e21f9aed1c996dde5b248c5c8d5926440 (diff) |
Cleanup: general cleanup in BLI_math code (mostly, use 'const' where possible, true/false for booleans, format for float litterals).
-rw-r--r-- | source/blender/blenlib/intern/math_color.c | 31 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_color_inline.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 230 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 96 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 16 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 21 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 8 |
7 files changed, 197 insertions, 221 deletions
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index eb9e36bcbf4..828a84da6e1 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 bb2201541d9..9233749d5df 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 2cd32b3dca9..54e3545a3f1 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_lambda > 1.0f)) return 0; + if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) return false; - return 1; + return true; } /** @@ -1616,9 +1616,9 @@ int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], } } -/* Intersection point strictly between the two lines - * 0 when no intersection is found - * */ +/** Intersection point strictly between the two lines + * \return false when no intersection is found + */ bool isect_line_line_strict_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float vi[3], float *r_lambda) @@ -1635,7 +1635,7 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3], d = dot_v3v3(dir1, dir2); if (d == 1.0f || d == -1.0f || d == 0) { /* colinear or one vector is zero-length*/ - return 0; + return false; } cross_v3_v3v3(ab, a, b); @@ -1644,7 +1644,7 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3], /* test zero length line */ if (UNLIKELY(div == 0.0f)) { - return 0; + return false; } /* test if the two lines are coplanar */ else if (d > -0.000001f && d < 0.000001f) { @@ -1663,14 +1663,14 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3], if (r_lambda) *r_lambda = f1; - return 1; /* intersection found */ + return true; /* intersection found */ } else { - return 0; + return false; } } else { - return 0; + return false; } } @@ -1688,9 +1688,9 @@ void isect_ray_aabb_initialize(IsectRayAABBData *data, const float ray_start[3], data->ray_inv_dir[1] = 1.0f / ray_direction[1]; data->ray_inv_dir[2] = 1.0f / ray_direction[2]; - data->sign[0] = data->ray_inv_dir[0] < 0; - data->sign[1] = data->ray_inv_dir[1] < 0; - data->sign[2] = data->ray_inv_dir[2] < 0; + data->sign[0] = data->ray_inv_dir[0] < 0.0f; + data->sign[1] = data->ray_inv_dir[1] < 0.0f; + data->sign[2] = data->ray_inv_dir[2] < 0.0f; } /* Adapted from http://www.gamedev.net/community/forums/topic.asp?topic_id=459973 */ @@ -1808,8 +1808,9 @@ float line_plane_factor_v3(const float plane_co[3], const float plane_no[3], return (dot != 0.0f) ? -dot_v3v3(plane_no, h) / dot : 0.0f; } -/* ensure the distance between these points is no greater then 'dist' - * if it is, scale then both into the center */ +/** Ensure the distance between these points is no greater then 'dist'. + * If it is, scale then both into the center. + */ void limit_dist_v3(float v1[3], float v2[3], const float dist) { const float dist_old = len_v3v3(v1, v2); @@ -1874,8 +1875,7 @@ static bool point_in_slice(const float p[3], const float v1[3], const float l1[3 sub_v3_v3v3(rp, p, v1); h = dot_v3v3(q, rp) / dot_v3v3(q, q); - if (h < 0.0f || h > 1.0f) return 0; - return 1; + return (h < 0.0f || h > 1.0f) ? false : true; } #if 0 @@ -1904,10 +1904,10 @@ static int point_in_slice_m(float p[3], float origin[3], float normal[3], float bool isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3]) { - if (!point_in_slice(p, v1, v2, v3)) return 0; - if (!point_in_slice(p, v2, v3, v1)) return 0; - if (!point_in_slice(p, v3, v1, v2)) return 0; - return 1; + if (!point_in_slice(p, v1, v2, v3)) return false; + if (!point_in_slice(p, v2, v3, v1)) return false; + if (!point_in_slice(p, v3, v1, v2)) return false; + return true; } /** @@ -1951,7 +1951,7 @@ bool clip_segment_v3_plane(float p1[3], float p2[3], const float plane[4]) div = dot_v3v3(dp, plane); if (div == 0.0f) /* parallel */ - return 1; + return true; t = -plane_point_side_v3(plane, p1) / div; @@ -1960,34 +1960,34 @@ bool clip_segment_v3_plane(float p1[3], float p2[3], const float plane[4]) if (t >= 1.0f) { zero_v3(p1); zero_v3(p2); - return 0; + return false; } /* intersect plane */ if (t > 0.0f) { madd_v3_v3v3fl(pc, p1, dp, t); copy_v3_v3(p1, pc); - return 1; + return true; } - return 1; + return true; } else { /* behind plane, completely clipped */ if (t <= 0.0f) { zero_v3(p1); zero_v3(p2); - return 0; + return false; } /* intersect plane */ if (t < 1.0f) { madd_v3_v3v3fl(pc, p1, dp, t); copy_v3_v3(p2, pc); - return 1; + return true; } - return 1; + return true; } } @@ -2216,12 +2216,12 @@ static bool barycentric_weights(const float v1[3], const float v2[3], const floa if (fabsf(wtot) > FLT_EPSILON) { mul_v3_fl(w, 1.0f / wtot); - return 0; + return false; } else { /* zero area triangle */ copy_v3_fl(w, 1.0f / 3.0f); - return 1; + return true; } } @@ -2272,8 +2272,9 @@ void interp_weights_face_v3(float w[4], const float v1[3], const float v2[3], co } } } - else + else { barycentric_weights(v1, v2, v3, co, n, w); + } } } @@ -2299,11 +2300,11 @@ int barycentric_inside_triangle_v2(const float w[3]) /* returns 0 for degenerated triangles */ bool barycentric_coords_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3]) { - float x = co[0], y = co[1]; - float x1 = v1[0], y1 = v1[1]; - float x2 = v2[0], y2 = v2[1]; - float x3 = v3[0], y3 = v3[1]; - float det = (y2 - y3) * (x1 - x3) + (x3 - x2) * (y1 - y3); + const float x = co[0], y = co[1]; + const float x1 = v1[0], y1 = v1[1]; + const float x2 = v2[0], y2 = v2[1]; + const float x3 = v3[0], y3 = v3[1]; + const float det = (y2 - y3) * (x1 - x3) + (x3 - x2) * (y1 - y3); if (fabsf(det) > FLT_EPSILON) { w[0] = ((y2 - y3) * (x - x3) + (x3 - x2) * (y - y3)) / det; @@ -2352,8 +2353,9 @@ void barycentric_weights_v2_persp(const float v1[4], const float v2[4], const fl if (wtot != 0.0f) { mul_v3_fl(w, 1.0f / wtot); } - else /* dummy values for zero area face */ + else { /* dummy values for zero area face */ w[0] = w[1] = w[2] = 1.0f / 3.0f; + } } /* same as #barycentric_weights_v2 but works with a quad, @@ -2388,8 +2390,7 @@ void barycentric_weights_v2_quad(const float v1[2], const float v2[2], const flo if (UNLIKELY(lens[0] < FLT_EPSILON)) { w[0] = 1.0f; w[1] = w[2] = w[3] = 0.0f; } else if (UNLIKELY(lens[1] < FLT_EPSILON)) { w[1] = 1.0f; w[0] = w[2] = w[3] = 0.0f; } else if (UNLIKELY(lens[2] < FLT_EPSILON)) { w[2] = 1.0f; w[0] = w[1] = w[3] = 0.0f; } - else if (UNLIKELY(lens[3] < FLT_EPSILON)) { w[3] = 1.0f; w[0] = w[1] = w[2] = 0.0f; - } + else if (UNLIKELY(lens[3] < FLT_EPSILON)) { w[3] = 1.0f; w[0] = w[1] = w[2] = 0.0f; } else { float wtot, area; @@ -2596,7 +2597,7 @@ static float mean_value_half_tan_v2(const float v1[2], const float v2[2], const void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[3]) { - const float eps = 0.00001f; /* take care, low values cause [#36105] */ + const float eps = 1e-5f; /* take care, low values cause [#36105] */ const float eps_sq = eps * eps; const float *v_curr, *v_next; float ht_prev, ht; /* half tangents */ @@ -2665,7 +2666,7 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[2]) { - const float eps = 0.00001f; /* take care, low values cause [#36105] */ + const float eps = 1e-5f; /* take care, low values cause [#36105] */ const float eps_sq = eps * eps; const float *v_curr, *v_next; float ht_prev, ht; /* half tangents */ @@ -2735,8 +2736,8 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[ void interp_cubic_v3(float x[3], float v[3], const float x1[3], const float v1[3], const float x2[3], const float v2[3], const float t) { float a[3], b[3]; - float t2 = t * t; - float t3 = t2 * t; + const float t2 = t * t; + const float t3 = t2 * t; /* cubic interpolation */ a[0] = v1[0] + v2[0] + 2 * (x1[0] - x2[0]); @@ -2961,11 +2962,9 @@ void orthographic_m4(float matrix[4][4], const float left, const float right, co void perspective_m4(float mat[4][4], const float left, const float right, const float bottom, const float top, const float nearClip, const float farClip) { - float Xdelta, Ydelta, Zdelta; - - Xdelta = right - left; - Ydelta = top - bottom; - Zdelta = farClip - nearClip; + const float Xdelta = right - left; + const float Ydelta = top - bottom; + const float Zdelta = farClip - nearClip; if (Xdelta == 0.0f || Ydelta == 0.0f || Zdelta == 0.0f) { return; @@ -2979,7 +2978,7 @@ void perspective_m4(float mat[4][4], const float left, const float right, const mat[3][2] = (-2.0f * nearClip * farClip) / Zdelta; mat[0][1] = mat[0][2] = mat[0][3] = mat[1][0] = mat[1][2] = mat[1][3] = - mat[3][0] = mat[3][1] = mat[3][3] = 0.0; + mat[3][0] = mat[3][1] = mat[3][3] = 0.0f; } @@ -3028,7 +3027,6 @@ static void i_multmatrix(float icand[4][4], float Vm[4][4]) void polarview_m4(float Vm[4][4], float dist, float azimuth, float incidence, float twist) { - unit_m4(Vm); translate_m4(Vm, 0.0, 0.0, -dist); @@ -3050,16 +3048,16 @@ void lookat_m4(float mat[4][4], float vx, float vy, float vz, float px, float py dx = px - vx; dy = py - vy; dz = pz - vz; - hyp = dx * dx + dz * dz; /* hyp squared */ + hyp = dx * dx + dz * dz; /* hyp squared */ hyp1 = sqrtf(dy * dy + hyp); - hyp = sqrtf(hyp); /* the real hyp */ + hyp = sqrtf(hyp); /* the real hyp */ - if (hyp1 != 0.0f) { /* rotate X */ + if (hyp1 != 0.0f) { /* rotate X */ sine = -dy / hyp1; cosine = hyp / hyp1; } else { - sine = 0; + sine = 0.0f; cosine = 1.0f; } mat1[1][1] = cosine; @@ -3069,16 +3067,16 @@ void lookat_m4(float mat[4][4], float vx, float vy, float vz, float px, float py i_multmatrix(mat1, mat); - mat1[1][1] = mat1[2][2] = 1.0f; /* be careful here to reinit */ - mat1[1][2] = mat1[2][1] = 0.0; /* those modified by the last */ + mat1[1][1] = mat1[2][2] = 1.0f; /* be careful here to reinit */ + mat1[1][2] = mat1[2][1] = 0.0f; /* those modified by the last */ - /* paragraph */ - if (hyp != 0.0f) { /* rotate Y */ + /* paragraph */ + if (hyp != 0.0f) { /* rotate Y */ sine = dx / hyp; cosine = -dz / hyp; } else { - sine = 0; + sine = 0.0f; cosine = 1.0f; } mat1[0][0] = cosine; @@ -3259,10 +3257,10 @@ void accumulate_vertex_normals_poly(float **vertnos, const float polyno[3], void tangent_from_uv(float uv1[2], float uv2[2], float uv3[3], float co1[3], float co2[3], float co3[3], float n[3], float tang[3]) { - float s1 = uv2[0] - uv1[0]; - float s2 = uv3[0] - uv1[0]; - float t1 = uv2[1] - uv1[1]; - float t2 = uv3[1] - uv1[1]; + const float s1 = uv2[0] - uv1[0]; + const float s2 = uv3[0] - uv1[0]; + const float t1 = uv2[1] - uv1[1]; + const float t2 = uv3[1] - uv1[1]; float det = (s1 * t2 - s2 * t1); if (det != 0.0f) { /* otherwise 'tang' becomes nan */ @@ -3287,7 +3285,7 @@ void tangent_from_uv(float uv1[2], float uv2[2], float uv3[3], float co1[3], flo } } else { - tang[0] = tang[1] = tang[2] = 0.0; + tang[0] = tang[1] = tang[2] = 0.0f; } } @@ -3320,7 +3318,8 @@ void vcloud_estimate_transform(int list_size, float (*pos)[3], float *weight, fl float lloc[3], float rloc[3], float lrot[3][3], float lscale[3][3]) { float accu_com[3] = {0.0f, 0.0f, 0.0f}, accu_rcom[3] = {0.0f, 0.0f, 0.0f}; - float accu_weight = 0.0f, accu_rweight = 0.0f, eps = 0.000001f; + float accu_weight = 0.0f, accu_rweight = 0.0f; + const float eps = 1e-6f; int a; /* first set up a nice default response */ @@ -3414,7 +3413,7 @@ void vcloud_estimate_transform(int list_size, float (*pos)[3], float *weight, fl /* this is pretty much Polardecompose 'inline' the algo based on Higham's thesis */ /* without the far case ... but seems to work here pretty neat */ - odet = 0.f; + odet = 0.0f; ndet = determinant_m3_array(q); while ((odet - ndet) * (odet - ndet) > eps && i < imax) { invert_m3_m3(qi, q); @@ -3455,9 +3454,8 @@ bool form_factor_visible_quad(const float p[3], const float n[3], float q0[3], float q1[3], float q2[3], float q3[3]) { static const float epsilon = 1e-6f; - float c, sd[3]; - - c = dot_v3v3(n, p); + float sd[3]; + const float c = dot_v3v3(n, p); /* signed distances from the vertices to the plane. */ sd[0] = dot_v3v3(n, v0) - c; @@ -3468,16 +3466,16 @@ bool form_factor_visible_quad(const float p[3], const float n[3], if (fabsf(sd[1]) < epsilon) sd[1] = 0.0f; if (fabsf(sd[2]) < epsilon) sd[2] = 0.0f; - if (sd[0] > 0) { - if (sd[1] > 0) { - if (sd[2] > 0) { + if (sd[0] > 0.0f) { + if (sd[1] > 0.0f) { + if (sd[2] > 0.0f) { /* +++ */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* ++- */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -3492,15 +3490,15 @@ bool form_factor_visible_quad(const float p[3], const float n[3], copy_v3_v3(q3, q2); } } - else if (sd[1] < 0) { - if (sd[2] > 0) { + else if (sd[1] < 0.0f) { + if (sd[2] > 0.0f) { /* +-+ */ copy_v3_v3(q0, v0); vec_add_dir(q1, v0, v1, (sd[0] / (sd[0] - sd[1]))); vec_add_dir(q2, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q3, v2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* +-- */ copy_v3_v3(q0, v0); vec_add_dir(q1, v0, v1, (sd[0] / (sd[0] - sd[1]))); @@ -3516,14 +3514,14 @@ bool form_factor_visible_quad(const float p[3], const float n[3], } } else { - if (sd[2] > 0) { + if (sd[2] > 0.0f) { /* +0+ */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* +0- */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -3539,16 +3537,16 @@ bool form_factor_visible_quad(const float p[3], const float n[3], } } } - else if (sd[0] < 0) { - if (sd[1] > 0) { - if (sd[2] > 0) { + else if (sd[0] < 0.0f) { + if (sd[1] > 0.0f) { + if (sd[2] > 0.0f) { /* -++ */ vec_add_dir(q0, v0, v1, (sd[0] / (sd[0] - sd[1]))); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); vec_add_dir(q3, v0, v2, (sd[0] / (sd[0] - sd[2]))); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* -+- */ vec_add_dir(q0, v0, v1, (sd[0] / (sd[0] - sd[1]))); copy_v3_v3(q1, v1); @@ -3563,15 +3561,15 @@ bool form_factor_visible_quad(const float p[3], const float n[3], copy_v3_v3(q3, q2); } } - else if (sd[1] < 0) { - if (sd[2] > 0) { + else if (sd[1] < 0.0f) { + if (sd[2] > 0.0f) { /* --+ */ vec_add_dir(q0, v0, v2, (sd[0] / (sd[0] - sd[2]))); vec_add_dir(q1, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* --- */ return false; } @@ -3581,14 +3579,14 @@ bool form_factor_visible_quad(const float p[3], const float n[3], } } else { - if (sd[2] > 0) { + if (sd[2] > 0.0f) { /* -0+ */ vec_add_dir(q0, v0, v2, (sd[0] / (sd[0] - sd[2]))); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* -0- */ return false; } @@ -3599,15 +3597,15 @@ bool form_factor_visible_quad(const float p[3], const float n[3], } } else { - if (sd[1] > 0) { - if (sd[2] > 0) { + if (sd[1] > 0.0f) { + if (sd[2] > 0.0f) { /* 0++ */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* 0+- */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -3622,15 +3620,15 @@ bool form_factor_visible_quad(const float p[3], const float n[3], copy_v3_v3(q3, q2); } } - else if (sd[1] < 0) { - if (sd[2] > 0) { + else if (sd[1] < 0.0f) { + if (sd[2] > 0.0f) { /* 0-+ */ copy_v3_v3(q0, v0); vec_add_dir(q1, v1, v2, (sd[1] / (sd[1] - sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* 0-- */ return false; } @@ -3640,14 +3638,14 @@ bool form_factor_visible_quad(const float p[3], const float n[3], } } else { - if (sd[2] > 0) { + if (sd[2] > 0.0f) { /* 00+ */ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if (sd[2] < 0) { + else if (sd[2] < 0.0f) { /* 00- */ return false; } @@ -3802,7 +3800,7 @@ static void ff_normalize(float n[3]) d = dot_v3v3(n, n); - if (d > 1.0e-35F) { + if (d > 1.0e-35f) { d = 1.0f / sqrtf(d); n[0] *= d; diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index bc39150b767..54bee803f9c 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -47,19 +47,19 @@ void zero_m4(float m[4][4]) void unit_m3(float m[3][3]) { - m[0][0] = m[1][1] = m[2][2] = 1.0; - m[0][1] = m[0][2] = 0.0; - m[1][0] = m[1][2] = 0.0; - m[2][0] = m[2][1] = 0.0; + m[0][0] = m[1][1] = m[2][2] = 1.0f; + m[0][1] = m[0][2] = 0.0f; + m[1][0] = m[1][2] = 0.0f; + m[2][0] = m[2][1] = 0.0f; } void unit_m4(float m[4][4]) { - m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0; - m[0][1] = m[0][2] = m[0][3] = 0.0; - m[1][0] = m[1][2] = m[1][3] = 0.0; - m[2][0] = m[2][1] = m[2][3] = 0.0; - m[3][0] = m[3][1] = m[3][2] = 0.0; + m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0f; + m[0][1] = m[0][2] = m[0][3] = 0.0f; + m[1][0] = m[1][2] = m[1][3] = 0.0f; + m[2][0] = m[2][1] = m[2][3] = 0.0f; + m[3][0] = m[3][1] = m[3][2] = 0.0f; } void copy_m3_m3(float m1[3][3], float m2[3][3]) @@ -103,14 +103,14 @@ void copy_m4_m3(float m1[4][4], float m2[3][3]) /* no clear */ m1[2][2] = m2[2][2]; /* Reevan's Bugfix */ - m1[0][3] = 0.0F; - m1[1][3] = 0.0F; - m1[2][3] = 0.0F; + m1[0][3] = 0.0f; + m1[1][3] = 0.0f; + m1[2][3] = 0.0f; - m1[3][0] = 0.0F; - m1[3][1] = 0.0F; - m1[3][2] = 0.0F; - m1[3][3] = 1.0F; + m1[3][0] = 0.0f; + m1[3][1] = 0.0f; + m1[3][2] = 0.0f; + m1[3][3] = 1.0f; } @@ -437,10 +437,9 @@ void mul_m3_v2(float m[3][3], float r[2]) void mul_m4_v3(float mat[4][4], float vec[3]) { - float x, y; + const float x = vec[0]; + const float y = vec[1]; - x = vec[0]; - y = vec[1]; vec[0] = x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; vec[1] = x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; vec[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; @@ -448,10 +447,9 @@ void mul_m4_v3(float mat[4][4], float vec[3]) void mul_v3_m4v3(float r[3], float mat[4][4], const float vec[3]) { - float x, y; + const float x = vec[0]; + const float y = vec[1]; - x = vec[0]; - y = vec[1]; r[0] = x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; r[1] = x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2]; @@ -459,18 +457,16 @@ void mul_v3_m4v3(float r[3], float mat[4][4], const float vec[3]) void mul_v2_m4v3(float r[2], float mat[4][4], const float vec[3]) { - float x; + const float x = vec[0]; - x = vec[0]; r[0] = x * mat[0][0] + vec[1] * mat[1][0] + mat[2][0] * vec[2] + mat[3][0]; r[1] = x * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + mat[3][1]; } void mul_v2_m2v2(float r[2], float mat[2][2], const float vec[2]) { - float x; + const float x = vec[0]; - x = vec[0]; r[0] = mat[0][0] * x + mat[1][0] * vec[1]; r[1] = mat[0][1] * x + mat[1][1] * vec[1]; } @@ -483,10 +479,9 @@ void mul_m2v2(float mat[2][2], float vec[2]) /* same as mul_m4_v3() but doesnt apply translation component */ void mul_mat3_m4_v3(float mat[4][4], float vec[3]) { - float x, y; + const float x = vec[0]; + const float y = vec[1]; - x = vec[0]; - y = vec[1]; vec[0] = x * mat[0][0] + y * mat[1][0] + mat[2][0] * vec[2]; vec[1] = x * mat[0][1] + y * mat[1][1] + mat[2][1] * vec[2]; vec[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2]; @@ -513,11 +508,9 @@ void mul_v2_project_m4_v3(float r[2], float mat[4][4], const float vec[3]) void mul_v4_m4v4(float r[4], float mat[4][4], const float v[4]) { - float x, y, z; - - x = v[0]; - y = v[1]; - z = v[2]; + const float x = v[0]; + const float y = v[1]; + const float z = v[2]; r[0] = x * mat[0][0] + y * mat[1][0] + z * mat[2][0] + mat[3][0] * v[3]; r[1] = x * mat[0][1] + y * mat[1][1] + z * mat[2][1] + mat[3][1] * v[3]; @@ -532,11 +525,9 @@ void mul_m4_v4(float mat[4][4], float r[4]) void mul_v4d_m4v4d(double r[4], float mat[4][4], double v[4]) { - double x, y, z; - - x = v[0]; - y = v[1]; - z = v[2]; + const double x = v[0]; + const double y = v[1]; + const double z = v[2]; r[0] = x * (double)mat[0][0] + y * (double)mat[1][0] + z * (double)mat[2][0] + (double)mat[3][0] * v[3]; r[1] = x * (double)mat[0][1] + y * (double)mat[1][1] + z * (double)mat[2][1] + (double)mat[3][1] * v[3]; @@ -576,10 +567,9 @@ void mul_m3_v3(float M[3][3], float r[3]) void mul_transposed_m3_v3(float mat[3][3], float vec[3]) { - float x, y; + const float x = vec[0]; + const float y = vec[1]; - x = vec[0]; - y = vec[1]; vec[0] = x * mat[0][0] + y * mat[0][1] + mat[0][2] * vec[2]; vec[1] = x * mat[1][0] + y * mat[1][1] + mat[1][2] * vec[2]; vec[2] = x * mat[2][0] + y * mat[2][1] + mat[2][2] * vec[2]; @@ -587,10 +577,9 @@ void mul_transposed_m3_v3(float mat[3][3], float vec[3]) void mul_transposed_mat3_m4_v3(float mat[4][4], float vec[3]) { - float x, y; + const float x = vec[0]; + const float y = vec[1]; - x = vec[0]; - y = vec[1]; vec[0] = x * mat[0][0] + y * mat[0][1] + mat[0][2] * vec[2]; vec[1] = x * mat[1][0] + y * mat[1][1] + mat[1][2] * vec[2]; vec[2] = x * mat[2][0] + y * mat[2][1] + mat[2][2] * vec[2]; @@ -643,10 +632,9 @@ void negate_m4(float m[4][4]) void mul_m3_v3_double(float mat[3][3], double vec[3]) { - double x, y; + const double x = vec[0]; + const double y = vec[1]; - x = vec[0]; - y = vec[1]; vec[0] = x * (double)mat[0][0] + y * (double)mat[1][0] + (double)mat[2][0] * vec[2]; vec[1] = x * (double)mat[0][1] + y * (double)mat[1][1] + (double)mat[2][1] * vec[2]; vec[2] = x * (double)mat[0][2] + y * (double)mat[1][2] + (double)mat[2][2] * vec[2]; @@ -698,11 +686,9 @@ float determinant_m3_array(float m[3][3]) bool invert_m3_ex(float m[3][3], const float epsilon) { float tmp[3][3]; - bool success; + const bool success = invert_m3_m3_ex(tmp, m, epsilon); - success = invert_m3_m3_ex(tmp, m, epsilon); copy_m3_m3(m, tmp); - return success; } @@ -736,11 +722,9 @@ bool invert_m3_m3_ex(float m1[3][3], float m2[3][3], const float epsilon) bool invert_m3(float m[3][3]) { float tmp[3][3]; - bool success; + const bool success = invert_m3_m3(tmp, m); - success = invert_m3_m3(tmp, m); copy_m3_m3(m, tmp); - return success; } @@ -773,11 +757,9 @@ bool invert_m3_m3(float m1[3][3], float m2[3][3]) bool invert_m4(float m[4][4]) { float tmp[4][4]; - bool success; + const bool success = invert_m4_m4(tmp, m); - success = invert_m4_m4(tmp, m); copy_m4_m4(m, tmp); - return success; } diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index df3c4fb8336..141f9201689 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -139,7 +139,7 @@ float dot_qtqt(const float q1[4], const float q2[4]) void invert_qt(float q[4]) { - float f = dot_qtqt(q, q); + const float f = dot_qtqt(q, q); if (f == 0.0f) return; @@ -380,9 +380,8 @@ void mat3_to_quat_is_ok(float q[4], float wmat[3][3]) float normalize_qt(float q[4]) { - float len; + const float len = sqrtf(dot_qtqt(q, q)); - len = sqrtf(dot_qtqt(q, q)); if (len != 0.0f) { mul_qt_fl(q, 1.0f / len); } @@ -520,7 +519,7 @@ float angle_qtqt(const float q1[4], const float q2[4]) void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) { - const float eps = 0.0001f; + const float eps = 1e-4f; float nor[3], tvec[3]; float angle, si, co, len; @@ -669,7 +668,7 @@ void QuatInterpolW(float *result, float quat1[4], float quat2[4], float t) */ void interp_dot_slerp(const float t, const float cosom, float r_w[2]) { - const float eps = 0.0001f; + const float eps = 1e-4f; BLI_assert(IN_RANGE_INCL(cosom, -1.0001f, 1.0001f)); @@ -783,9 +782,8 @@ void tri_to_quat_ex(float quat[4], const float v1[3], const float v2[3], const f float tri_to_quat(float quat[4], const float v1[3], const float v2[3], const float v3[3]) { float vec[3]; - float len; + const float len = normal_tri_v3(vec, v1, v2, v3); - len = normal_tri_v3(vec, v1, v2, v3); tri_to_quat_ex(quat, v1, v2, v3, vec); return len; } @@ -1658,7 +1656,7 @@ void add_weighted_dq_dq(DualQuat *dqsum, const DualQuat *dq, float weight) /* make sure we interpolate quats in the right direction */ if (dot_qtqt(dq->quat, dqsum->quat) < 0) { - flipped = 1; + flipped = true; weight = -weight; } @@ -1689,7 +1687,7 @@ void add_weighted_dq_dq(DualQuat *dqsum, const DualQuat *dq, float weight) void normalize_dq(DualQuat *dq, float totweight) { - float scale = 1.0f / totweight; + const float scale = 1.0f / totweight; mul_qt_fl(dq->quat, scale); mul_qt_fl(dq->trans, scale); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 15b88fe0c7f..6b37b0d5d32 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -35,7 +35,7 @@ void interp_v2_v2v2(float target[2], const float a[2], const float b[2], const float t) { - float s = 1.0f - t; + const float s = 1.0f - t; target[0] = s * a[0] + t * b[0]; target[1] = s * a[1] + t * b[1]; @@ -51,7 +51,7 @@ void interp_v2_v2v2v2(float p[2], const float v1[2], const float v2[2], const fl void interp_v3_v3v3(float target[3], const float a[3], const float b[3], const float t) { - float s = 1.0f - t; + const float s = 1.0f - t; target[0] = s * a[0] + t * b[0]; target[1] = s * a[1] + t * b[1]; @@ -60,7 +60,7 @@ void interp_v3_v3v3(float target[3], const float a[3], const float b[3], const f void interp_v4_v4v4(float target[4], const float a[4], const float b[4], const float t) { - float s = 1.0f - t; + const float s = 1.0f - t; target[0] = s * a[0] + t * b[0]; target[1] = s * a[1] + t * b[1]; @@ -119,8 +119,7 @@ bool interp_v2_v2v2_slerp(float target[2], const float a[2], const float b[2], c } /** - * Same as #interp_v3_v3v3_slerp buy uses fallback values - * for opposite vectors. + * Same as #interp_v3_v3v3_slerp but uses fallback values for opposite vectors. */ void interp_v3_v3v3_slerp_safe(float target[3], const float a[3], const float b[3], const float t) { @@ -208,7 +207,7 @@ void interp_v3_v3v3v3_uv(float p[3], const float v1[3], const float v2[3], const void interp_v3_v3v3_uchar(char unsigned target[3], const unsigned char a[3], const unsigned char b[3], const float t) { - float s = 1.0f - t; + const float s = 1.0f - t; target[0] = (char)floorf(s * a[0] + t * b[0]); target[1] = (char)floorf(s * a[1] + t * b[1]); @@ -221,7 +220,7 @@ void interp_v3_v3v3_char(char target[3], const char a[3], const char b[3], const void interp_v4_v4v4_uchar(char unsigned target[4], const unsigned char a[4], const unsigned char b[4], const float t) { - float s = 1.0f - t; + const float s = 1.0f - t; target[0] = (char)floorf(s * a[0] + t * b[0]); target[1] = (char)floorf(s * a[1] + t * b[1]); @@ -550,8 +549,7 @@ void angle_poly_v3(float *angles, const float *verts[3], int len) /* Project v1 on v2 */ void project_v2_v2v2(float c[2], const float v1[2], const float v2[2]) { - float mul; - mul = dot_v2v2(v1, v2) / dot_v2v2(v2, v2); + const float mul = dot_v2v2(v1, v2) / dot_v2v2(v2, v2); c[0] = mul * v2[0]; c[1] = mul * v2[1]; @@ -560,8 +558,7 @@ void project_v2_v2v2(float c[2], const float v1[2], const float v2[2]) /* Project v1 on v2 */ void project_v3_v3v3(float c[3], const float v1[3], const float v2[3]) { - float mul; - mul = dot_v3v3(v1, v2) / dot_v3v3(v2, v2); + const float mul = dot_v3v3(v1, v2) / dot_v3v3(v2, v2); c[0] = mul * v2[0]; c[1] = mul * v2[1]; @@ -837,7 +834,7 @@ double len_squared_vn(const float *array, const int size) float normalize_vn_vn(float *array_tar, const float *array_src, const int size) { - double d = len_squared_vn(array_src, size); + const double d = len_squared_vn(array_src, size); float d_sqrt; if (d > 1.0e-35) { d_sqrt = (float)sqrt(d); diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 135050f4a3f..0a990e0d63d 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -850,17 +850,17 @@ MINLINE void normal_float_to_short_v3(short out[3], const float in[3]) MINLINE bool is_zero_v2(const float v[2]) { - return (v[0] == 0 && v[1] == 0); + return (v[0] == 0.0f && v[1] == 0.0f); } MINLINE bool is_zero_v3(const float v[3]) { - return (v[0] == 0 && v[1] == 0 && v[2] == 0); + return (v[0] == 0.0f && v[1] == 0.0f && v[2] == 0.0f); } MINLINE bool is_zero_v4(const float v[4]) { - return (v[0] == 0 && v[1] == 0 && v[2] == 0 && v[3] == 0); + return (v[0] == 0.0f && v[1] == 0.0f && v[2] == 0.0f && v[3] == 0.0f); } MINLINE bool is_finite_v2(const float v[2]) @@ -880,7 +880,7 @@ MINLINE bool is_finite_v4(const float v[4]) MINLINE bool is_one_v3(const float v[3]) { - return (v[0] == 1 && v[1] == 1 && v[2] == 1); + return (v[0] == 1.0f && v[1] == 1.0f && v[2] == 1.0f); } |