diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-25 11:33:28 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-25 13:17:08 +0300 |
commit | f68cfd6bb078482c4a779a6e26a56e2734edb5b8 (patch) | |
tree | 2878e5b80dba5bdeba186d99661d604eb38879cd /source/blender/blenlib | |
parent | c7b247a118e302a3afc6473797e53b6af28b69e2 (diff) |
Cleanup: replace C-style casts with functional casts for numeric types
Diffstat (limited to 'source/blender/blenlib')
20 files changed, 112 insertions, 112 deletions
diff --git a/source/blender/blenlib/intern/dot_export.cc b/source/blender/blenlib/intern/dot_export.cc index 796fd6a934a..d577de9bc34 100644 --- a/source/blender/blenlib/intern/dot_export.cc +++ b/source/blender/blenlib/intern/dot_export.cc @@ -93,7 +93,7 @@ void Graph::set_random_cluster_bgcolors() void Cluster::set_random_cluster_bgcolors() { - float hue = rand() / (float)RAND_MAX; + float hue = rand() / float(RAND_MAX); float staturation = 0.3f; float value = 0.8f; this->attributes.set("bgcolor", color_attr_from_hsv(hue, staturation, value)); @@ -227,7 +227,7 @@ void Attributes::export__as_bracket_list(std::stringstream &ss) const void Node::export__as_id(std::stringstream &ss) const { - ss << '"' << (uintptr_t)this << '"'; + ss << '"' << uintptr_t(this) << '"'; } void Node::export__as_declaration(std::stringstream &ss) const diff --git a/source/blender/blenlib/intern/math_boolean.cc b/source/blender/blenlib/intern/math_boolean.cc index 132d5dfda65..871ea815e90 100644 --- a/source/blender/blenlib/intern/math_boolean.cc +++ b/source/blender/blenlib/intern/math_boolean.cc @@ -193,7 +193,7 @@ static RobustInitCaller init_caller; y = b - bvirt #define Fast_Two_Sum(a, b, x, y) \ - x = (double)(a + b); \ + x = double(a + b); \ Fast_Two_Sum_Tail(a, b, x, y) #define Fast_Two_Diff_Tail(a, b, x, y) \ @@ -205,30 +205,30 @@ static RobustInitCaller init_caller; Fast_Two_Diff_Tail(a, b, x, y) #define Two_Sum_Tail(a, b, x, y) \ - bvirt = (double)(x - a); \ + bvirt = double(x - a); \ avirt = x - bvirt; \ bround = b - bvirt; \ around = a - avirt; \ y = around + bround #define Two_Sum(a, b, x, y) \ - x = (double)(a + b); \ + x = double(a + b); \ Two_Sum_Tail(a, b, x, y) #define Two_Diff_Tail(a, b, x, y) \ - bvirt = (double)(a - x); \ + bvirt = double(a - x); \ avirt = x + bvirt; \ bround = bvirt - b; \ around = a - avirt; \ y = around + bround #define Two_Diff(a, b, x, y) \ - x = (double)(a - b); \ + x = double(a - b); \ Two_Diff_Tail(a, b, x, y) #define Split(a, ahi, alo) \ - c = (double)(splitter * a); \ - abig = (double)(c - a); \ + c = double(splitter * a); \ + abig = double(c - a); \ ahi = c - abig; \ alo = a - ahi @@ -241,11 +241,11 @@ static RobustInitCaller init_caller; y = (alo * blo) - err3 #define Two_Product(a, b, x, y) \ - x = (double)(a * b); \ + x = double(a * b); \ Two_Product_Tail(a, b, x, y) #define Two_Product_Presplit(a, b, bhi, blo, x, y) \ - x = (double)(a * b); \ + x = double(a * b); \ Split(a, ahi, alo); \ err1 = x - (ahi * bhi); \ err2 = err1 - (alo * bhi); \ @@ -266,7 +266,7 @@ static RobustInitCaller init_caller; y = (alo * alo) - err3 #define Square(a, x, y) \ - x = (double)(a * a); \ + x = double(a * a); \ Square_Tail(a, x, y) #define Two_One_Sum(a1, a0, b, x2, x1, x0) \ @@ -647,10 +647,10 @@ static double orient2dadapt(const double *pa, const double *pb, const double *pc INEXACT double _i, _j; double _0; - acx = (double)(pa[0] - pc[0]); - bcx = (double)(pb[0] - pc[0]); - acy = (double)(pa[1] - pc[1]); - bcy = (double)(pb[1] - pc[1]); + acx = double(pa[0] - pc[0]); + bcx = double(pb[0] - pc[0]); + acy = double(pa[1] - pc[1]); + bcy = double(pb[1] - pc[1]); Two_Product(acx, bcy, detleft, detlefttail); Two_Product(acy, bcx, detright, detrighttail); @@ -834,15 +834,15 @@ static double orient3dadapt( INEXACT double _i, _j, _k; double _0; - adx = (double)(pa[0] - pd[0]); - bdx = (double)(pb[0] - pd[0]); - cdx = (double)(pc[0] - pd[0]); - ady = (double)(pa[1] - pd[1]); - bdy = (double)(pb[1] - pd[1]); - cdy = (double)(pc[1] - pd[1]); - adz = (double)(pa[2] - pd[2]); - bdz = (double)(pb[2] - pd[2]); - cdz = (double)(pc[2] - pd[2]); + adx = double(pa[0] - pd[0]); + bdx = double(pb[0] - pd[0]); + cdx = double(pc[0] - pd[0]); + ady = double(pa[1] - pd[1]); + bdy = double(pb[1] - pd[1]); + cdy = double(pc[1] - pd[1]); + adz = double(pa[2] - pd[2]); + bdz = double(pb[2] - pd[2]); + cdz = double(pc[2] - pd[2]); Two_Product(bdx, cdy, bdxcdy1, bdxcdy0); Two_Product(cdx, bdy, cdxbdy1, cdxbdy0); @@ -1358,12 +1358,12 @@ static double incircleadapt( INEXACT double _i, _j; double _0; - adx = (double)(pa[0] - pd[0]); - bdx = (double)(pb[0] - pd[0]); - cdx = (double)(pc[0] - pd[0]); - ady = (double)(pa[1] - pd[1]); - bdy = (double)(pb[1] - pd[1]); - cdy = (double)(pc[1] - pd[1]); + adx = double(pa[0] - pd[0]); + bdx = double(pb[0] - pd[0]); + cdx = double(pc[0] - pd[0]); + ady = double(pa[1] - pd[1]); + bdy = double(pb[1] - pd[1]); + cdy = double(pc[1] - pd[1]); Two_Product(bdx, cdy, bdxcdy1, bdxcdy0); Two_Product(cdx, bdy, cdxbdy1, cdxbdy0); diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index 19c4b92a315..65a6f102a7b 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -379,7 +379,7 @@ BLI_INLINE float noise_grad(uint32_t hash, float x, float y, float z, float w) BLI_INLINE float floor_fraction(float x, int &i) { - i = (int)x - ((x < 0) ? 1 : 0); + i = int(x) - ((x < 0) ? 1 : 0); return x - i; } @@ -729,7 +729,7 @@ float musgrave_fBm(const float co, const float pwHL = std::pow(lacunarity, -H); const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value += perlin_signed(p) * pwr; pwr *= pwHL; p *= lacunarity; @@ -754,7 +754,7 @@ float musgrave_multi_fractal(const float co, const float pwHL = std::pow(lacunarity, -H); const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value *= (pwr * perlin_signed(p) + 1.0f); pwr *= pwHL; p *= lacunarity; @@ -783,7 +783,7 @@ float musgrave_hetero_terrain(const float co, float value = offset + perlin_signed(p); p *= lacunarity; - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { float increment = (perlin_signed(p) + offset) * pwr * value; value += increment; pwr *= pwHL; @@ -815,7 +815,7 @@ float musgrave_hybrid_multi_fractal(const float co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; (weight > 0.001f) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -857,7 +857,7 @@ float musgrave_ridged_multi_fractal(const float co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { p *= lacunarity; weight = CLAMPIS(signal * gain, 0.0f, 1.0f); signal = offset - std::abs(perlin_signed(p)); @@ -883,7 +883,7 @@ float musgrave_fBm(const float2 co, const float pwHL = std::pow(lacunarity, -H); const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value += perlin_signed(p) * pwr; pwr *= pwHL; p *= lacunarity; @@ -908,7 +908,7 @@ float musgrave_multi_fractal(const float2 co, const float pwHL = std::pow(lacunarity, -H); const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value *= (pwr * perlin_signed(p) + 1.0f); pwr *= pwHL; p *= lacunarity; @@ -938,7 +938,7 @@ float musgrave_hetero_terrain(const float2 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { float increment = (perlin_signed(p) + offset) * pwr * value; value += increment; pwr *= pwHL; @@ -970,7 +970,7 @@ float musgrave_hybrid_multi_fractal(const float2 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; (weight > 0.001f) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -1012,7 +1012,7 @@ float musgrave_ridged_multi_fractal(const float2 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { p *= lacunarity; weight = CLAMPIS(signal * gain, 0.0f, 1.0f); signal = offset - std::abs(perlin_signed(p)); @@ -1039,7 +1039,7 @@ float musgrave_fBm(const float3 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value += perlin_signed(p) * pwr; pwr *= pwHL; p *= lacunarity; @@ -1065,7 +1065,7 @@ float musgrave_multi_fractal(const float3 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value *= (pwr * perlin_signed(p) + 1.0f); pwr *= pwHL; p *= lacunarity; @@ -1095,7 +1095,7 @@ float musgrave_hetero_terrain(const float3 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { float increment = (perlin_signed(p) + offset) * pwr * value; value += increment; pwr *= pwHL; @@ -1127,7 +1127,7 @@ float musgrave_hybrid_multi_fractal(const float3 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; (weight > 0.001f) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -1169,7 +1169,7 @@ float musgrave_ridged_multi_fractal(const float3 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { p *= lacunarity; weight = CLAMPIS(signal * gain, 0.0f, 1.0f); signal = offset - std::abs(perlin_signed(p)); @@ -1196,7 +1196,7 @@ float musgrave_fBm(const float4 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value += perlin_signed(p) * pwr; pwr *= pwHL; p *= lacunarity; @@ -1222,7 +1222,7 @@ float musgrave_multi_fractal(const float4 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; i < (int)octaves; i++) { + for (int i = 0; i < int(octaves); i++) { value *= (pwr * perlin_signed(p) + 1.0f); pwr *= pwHL; p *= lacunarity; @@ -1252,7 +1252,7 @@ float musgrave_hetero_terrain(const float4 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { float increment = (perlin_signed(p) + offset) * pwr * value; value += increment; pwr *= pwHL; @@ -1284,7 +1284,7 @@ float musgrave_hybrid_multi_fractal(const float4 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 0; (weight > 0.001f) && (i < (int)octaves); i++) { + for (int i = 0; (weight > 0.001f) && (i < int(octaves)); i++) { if (weight > 1.0f) { weight = 1.0f; } @@ -1326,7 +1326,7 @@ float musgrave_ridged_multi_fractal(const float4 co, const float octaves = CLAMPIS(octaves_unclamped, 0.0f, 15.0f); - for (int i = 1; i < (int)octaves; i++) { + for (int i = 1; i < int(octaves); i++) { p *= lacunarity; weight = CLAMPIS(signal * gain, 0.0f, 1.0f); signal = offset - std::abs(perlin_signed(p)); diff --git a/source/blender/blenlib/intern/rand.cc b/source/blender/blenlib/intern/rand.cc index b5db0d6b473..2e9b15c623e 100644 --- a/source/blender/blenlib/intern/rand.cc +++ b/source/blender/blenlib/intern/rand.cc @@ -161,7 +161,7 @@ void BLI_rng_shuffle_bitmap(struct RNG *rng, BLI_bitmap *bitmap, uint bits_num) void BLI_rng_skip(RNG *rng, int n) { - rng->rng.skip((uint)n); + rng->rng.skip(uint(n)); } /***/ @@ -239,7 +239,7 @@ RNG_THREAD_ARRAY *BLI_rng_threaded_new() "random_array"); for (i = 0; i < BLENDER_MAX_THREADS; i++) { - BLI_rng_srandom(&rngarr->rng_tab[i], (uint)clock()); + BLI_rng_srandom(&rngarr->rng_tab[i], uint(clock())); } return rngarr; @@ -283,7 +283,7 @@ BLI_INLINE double halton_ex(double invprimes, double *offset) void BLI_halton_1d(uint prime, double offset, int n, double *r) { - const double invprime = 1.0 / (double)prime; + const double invprime = 1.0 / double(prime); *r = 0.0; @@ -294,7 +294,7 @@ void BLI_halton_1d(uint prime, double offset, int n, double *r) void BLI_halton_2d(const uint prime[2], double offset[2], int n, double *r) { - const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]}; + const double invprimes[2] = {1.0 / double(prime[0]), 1.0 / double(prime[1])}; r[0] = r[1] = 0.0; @@ -308,7 +308,7 @@ void BLI_halton_2d(const uint prime[2], double offset[2], int n, double *r) void BLI_halton_3d(const uint prime[3], double offset[3], int n, double *r) { const double invprimes[3] = { - 1.0 / (double)prime[0], 1.0 / (double)prime[1], 1.0 / (double)prime[2]}; + 1.0 / double(prime[0]), 1.0 / double(prime[1]), 1.0 / double(prime[2])}; r[0] = r[1] = r[2] = 0.0; @@ -321,7 +321,7 @@ void BLI_halton_3d(const uint prime[3], double offset[3], int n, double *r) void BLI_halton_2d_sequence(const uint prime[2], double offset[2], int n, double *r) { - const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]}; + const double invprimes[2] = {1.0 / double(prime[0]), 1.0 / double(prime[1])}; for (int s = 0; s < n; s++) { for (int i = 0; i < 2; i++) { @@ -355,7 +355,7 @@ void BLI_hammersley_1d(uint n, double *r) void BLI_hammersley_2d_sequence(uint n, double *r) { for (uint s = 0; s < n; s++) { - r[s * 2 + 0] = (double)(s + 0.5) / (double)n; + r[s * 2 + 0] = double(s + 0.5) / double(n); r[s * 2 + 1] = radical_inverse(s); } } @@ -377,12 +377,12 @@ int RandomNumberGenerator::round_probabilistic(float x) BLI_assert(x >= 0.0f); const float round_up_probability = fractf(x); const bool round_up = round_up_probability > this->get_float(); - return (int)x + (int)round_up; + return int(x) + int(round_up); } float2 RandomNumberGenerator::get_unit_float2() { - float a = (float)(M_PI * 2.0) * this->get_float(); + float a = float(M_PI * 2.0) * this->get_float(); return {cosf(a), sinf(a)}; } @@ -391,7 +391,7 @@ float3 RandomNumberGenerator::get_unit_float3() float z = (2.0f * this->get_float()) - 1.0f; float r = 1.0f - z * z; if (r > 0.0f) { - float a = (float)(M_PI * 2.0) * this->get_float(); + float a = float(M_PI * 2.0) * this->get_float(); r = sqrtf(r); float x = r * cosf(a); float y = r * sinf(a); diff --git a/source/blender/blenlib/intern/string_search.cc b/source/blender/blenlib/intern/string_search.cc index 6eeae307fc1..f87304863c9 100644 --- a/source/blender/blenlib/intern/string_search.cc +++ b/source/blender/blenlib/intern/string_search.cc @@ -345,7 +345,7 @@ void extract_normalized_words(StringRef str, LinearAllocator<> &allocator, Vector<StringRef, 64> &r_words) { - const uint32_t unicode_space = (uint32_t)' '; + const uint32_t unicode_space = uint32_t(' '); const uint32_t unicode_right_triangle = UI_MENU_ARROW_SEP_UNICODE; BLI_assert(unicode_space == BLI_str_utf8_as_unicode(" ")); @@ -418,7 +418,7 @@ void BLI_string_search_add(StringSearch *search, StringRef str_ref{str}; string_search::extract_normalized_words(str_ref, search->allocator, words); search->items.append({search->allocator.construct_array_copy(words.as_span()), - (int)str_ref.size(), + int(str_ref.size()), user_data, weight}); } diff --git a/source/blender/blenlib/intern/threads.cc b/source/blender/blenlib/intern/threads.cc index e7470ed86f8..156f2a7b338 100644 --- a/source/blender/blenlib/intern/threads.cc +++ b/source/blender/blenlib/intern/threads.cc @@ -293,7 +293,7 @@ int BLI_system_thread_count() #ifdef WIN32 SYSTEM_INFO info; GetSystemInfo(&info); - t = (int)info.dwNumberOfProcessors; + t = int(info.dwNumberOfProcessors); #else # ifdef __APPLE__ int mib[2]; @@ -304,7 +304,7 @@ int BLI_system_thread_count() len = sizeof(t); sysctl(mib, 2, &t, &len, nullptr, 0); # else - t = (int)sysconf(_SC_NPROCESSORS_ONLN); + t = int(sysconf(_SC_NPROCESSORS_ONLN)); # endif #endif } diff --git a/source/blender/blenlib/tests/BLI_edgehash_test.cc b/source/blender/blenlib/tests/BLI_edgehash_test.cc index 301fa226016..f6e987c7060 100644 --- a/source/blender/blenlib/tests/BLI_edgehash_test.cc +++ b/source/blender/blenlib/tests/BLI_edgehash_test.cc @@ -308,7 +308,7 @@ TEST(edgehash, StressTest) std::vector<Edge> edges; for (int i = 0; i < amount; i++) { - edges.push_back({(uint)i, amount + (uint)std::rand() % 12345}); + edges.push_back({uint(i), amount + uint(std::rand()) % 12345}); } EdgeHash *eh = BLI_edgehash_new(__func__); diff --git a/source/blender/blenlib/tests/BLI_generic_array_test.cc b/source/blender/blenlib/tests/BLI_generic_array_test.cc index 52bc7728a6a..25e08f59f94 100644 --- a/source/blender/blenlib/tests/BLI_generic_array_test.cc +++ b/source/blender/blenlib/tests/BLI_generic_array_test.cc @@ -20,7 +20,7 @@ TEST(generic_array, TypeConstructor) TEST(generic_array, MoveConstructor) { - GArray array_a(CPPType::get<int32_t>(), (int64_t)10); + GArray array_a(CPPType::get<int32_t>(), int64_t(10)); GMutableSpan span_a = array_a.as_mutable_span(); MutableSpan<int32_t> typed_span_a = span_a.typed<int32_t>(); typed_span_a.fill(42); @@ -40,7 +40,7 @@ TEST(generic_array, MoveConstructor) TEST(generic_array, CopyConstructor) { - GArray array_a(CPPType::get<int32_t>(), (int64_t)10); + GArray array_a(CPPType::get<int32_t>(), int64_t(10)); GMutableSpan span_a = array_a.as_mutable_span(); MutableSpan<int32_t> typed_span_a = span_a.typed<int32_t>(); typed_span_a.fill(42); @@ -79,7 +79,7 @@ TEST(generic_array, BufferAndSizeConstructor) TEST(generic_array, Reinitialize) { - GArray array(CPPType::get<int32_t>(), (int64_t)5); + GArray array(CPPType::get<int32_t>(), int64_t(5)); EXPECT_FALSE(array.data() == nullptr); GMutableSpan span = array.as_mutable_span(); MutableSpan<int32_t> typed_span = span.typed<int32_t>(); @@ -106,7 +106,7 @@ TEST(generic_array, InContainer) { blender::Array<GArray<>> arrays; for (GArray<> &array : arrays) { - array = GArray(CPPType::get<int32_t>(), (int64_t)5); + array = GArray(CPPType::get<int32_t>(), int64_t(5)); array.as_mutable_span().typed<int32_t>().fill(55); } for (GArray<> &array : arrays) { diff --git a/source/blender/blenlib/tests/BLI_heap_simple_test.cc b/source/blender/blenlib/tests/BLI_heap_simple_test.cc index 818de67740b..96a5e42374e 100644 --- a/source/blender/blenlib/tests/BLI_heap_simple_test.cc +++ b/source/blender/blenlib/tests/BLI_heap_simple_test.cc @@ -18,7 +18,7 @@ static void range_fl(float *array_tar, const int size) float *array_pt = array_tar + (size - 1); int i = size; while (i--) { - *(array_pt--) = (float)i; + *(array_pt--) = float(i); } } @@ -53,7 +53,7 @@ TEST(heap, SimpleRange) const int items_total = SIZE; HeapSimple *heap = BLI_heapsimple_new(); for (int in = 0; in < items_total; in++) { - BLI_heapsimple_insert(heap, (float)in, POINTER_FROM_INT(in)); + BLI_heapsimple_insert(heap, float(in), POINTER_FROM_INT(in)); } for (int out_test = 0; out_test < items_total; out_test++) { EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap))); @@ -67,7 +67,7 @@ TEST(heap, SimpleRangeReverse) const int items_total = SIZE; HeapSimple *heap = BLI_heapsimple_new(); for (int in = 0; in < items_total; in++) { - BLI_heapsimple_insert(heap, (float)-in, POINTER_FROM_INT(-in)); + BLI_heapsimple_insert(heap, float(-in), POINTER_FROM_INT(-in)); } for (int out_test = items_total - 1; out_test >= 0; out_test--) { EXPECT_EQ(-out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap))); @@ -97,7 +97,7 @@ static void random_heapsimple_helper(const int items_total, const int random_see range_fl(values, items_total); BLI_array_randomize(values, sizeof(float), items_total, random_seed); for (int i = 0; i < items_total; i++) { - BLI_heapsimple_insert(heap, values[i], POINTER_FROM_INT((int)values[i])); + BLI_heapsimple_insert(heap, values[i], POINTER_FROM_INT(int(values[i]))); } for (int out_test = 0; out_test < items_total; out_test++) { EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heapsimple_pop_min(heap))); diff --git a/source/blender/blenlib/tests/BLI_heap_test.cc b/source/blender/blenlib/tests/BLI_heap_test.cc index 333a1530b6d..f2368ce4abf 100644 --- a/source/blender/blenlib/tests/BLI_heap_test.cc +++ b/source/blender/blenlib/tests/BLI_heap_test.cc @@ -17,7 +17,7 @@ static void range_fl(float *array_tar, const int size) float *array_pt = array_tar + (size - 1); int i = size; while (i--) { - *(array_pt--) = (float)i; + *(array_pt--) = float(i); } } @@ -52,7 +52,7 @@ TEST(heap, Range) const int items_total = SIZE; Heap *heap = BLI_heap_new(); for (int in = 0; in < items_total; in++) { - BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in)); + BLI_heap_insert(heap, float(in), POINTER_FROM_INT(in)); } for (int out_test = 0; out_test < items_total; out_test++) { EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap))); @@ -66,7 +66,7 @@ TEST(heap, RangeReverse) const int items_total = SIZE; Heap *heap = BLI_heap_new(); for (int in = 0; in < items_total; in++) { - BLI_heap_insert(heap, (float)-in, POINTER_FROM_INT(-in)); + BLI_heap_insert(heap, float(-in), POINTER_FROM_INT(-in)); } for (int out_test = items_total - 1; out_test >= 0; out_test--) { EXPECT_EQ(-out_test, POINTER_AS_INT(BLI_heap_pop_min(heap))); @@ -81,7 +81,7 @@ TEST(heap, RangeRemove) Heap *heap = BLI_heap_new(); HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__); for (int in = 0; in < items_total; in++) { - nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in)); + nodes[in] = BLI_heap_insert(heap, float(in), POINTER_FROM_INT(in)); } for (int i = 0; i < items_total; i += 2) { BLI_heap_remove(heap, nodes[i]); @@ -116,7 +116,7 @@ static void random_heap_helper(const int items_total, const int random_seed) range_fl(values, items_total); BLI_array_randomize(values, sizeof(float), items_total, random_seed); for (int i = 0; i < items_total; i++) { - BLI_heap_insert(heap, values[i], POINTER_FROM_INT((int)values[i])); + BLI_heap_insert(heap, values[i], POINTER_FROM_INT(int(values[i]))); } for (int out_test = 0; out_test < items_total; out_test++) { EXPECT_EQ(out_test, POINTER_AS_INT(BLI_heap_pop_min(heap))); @@ -145,10 +145,10 @@ TEST(heap, ReInsertSimple) Heap *heap = BLI_heap_new(); HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__); for (int in = 0; in < items_total; in++) { - nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in)); + nodes[in] = BLI_heap_insert(heap, float(in), POINTER_FROM_INT(in)); } for (int i = 0; i < items_total; i++) { - BLI_heap_node_value_update(heap, nodes[i], (float)(items_total + i)); + BLI_heap_node_value_update(heap, nodes[i], float(items_total + i)); } for (int out_test = 0; out_test < items_total; out_test++) { @@ -165,11 +165,11 @@ static void random_heap_reinsert_helper(const int items_total, const int random_ Heap *heap = BLI_heap_new(); HeapNode **nodes = (HeapNode **)MEM_mallocN(sizeof(HeapNode *) * items_total, __func__); for (int in = 0; in < items_total; in++) { - nodes[in] = BLI_heap_insert(heap, (float)in, POINTER_FROM_INT(in)); + nodes[in] = BLI_heap_insert(heap, float(in), POINTER_FROM_INT(in)); } BLI_array_randomize(nodes, sizeof(HeapNode *), items_total, random_seed); for (int i = 0; i < items_total; i++) { - BLI_heap_node_value_update(heap, nodes[i], (float)i); + BLI_heap_node_value_update(heap, nodes[i], float(i)); } EXPECT_TRUE(BLI_heap_is_valid(heap)); @@ -177,7 +177,7 @@ static void random_heap_reinsert_helper(const int items_total, const int random_ HeapNode *node_top = BLI_heap_top(heap); float out = BLI_heap_node_value(node_top); EXPECT_EQ(out, BLI_heap_top_value(heap)); - EXPECT_EQ((float)out_test, out); + EXPECT_EQ(float(out_test), out); BLI_heap_pop_min(heap); } EXPECT_TRUE(BLI_heap_is_empty(heap)); diff --git a/source/blender/blenlib/tests/BLI_kdopbvh_test.cc b/source/blender/blenlib/tests/BLI_kdopbvh_test.cc index 756219cd733..83eeabaea40 100644 --- a/source/blender/blenlib/tests/BLI_kdopbvh_test.cc +++ b/source/blender/blenlib/tests/BLI_kdopbvh_test.cc @@ -18,7 +18,7 @@ static void rng_v3_round(float *coords, int coords_len, struct RNG *rng, int rou { for (int i = 0; i < coords_len; i++) { float f = BLI_rng_get_float(rng) * 2.0f - 1.0f; - coords[i] = ((float)((int)(f * round)) / (float)round) * scale; + coords[i] = (float(int(f * round)) / float(round)) * scale; } } @@ -90,7 +90,7 @@ static void find_nearest_points_test( if (j != i) { #if 0 const float dist = len_v3v3(points[i], points[j]); - if (dist > (1.0f / (float)round)) { + if (dist > (1.0f / float(round))) { printf("%.15f (%d %d)\n", dist, i, j); print_v3_id(points[i]); print_v3_id(points[j]); diff --git a/source/blender/blenlib/tests/BLI_linear_allocator_test.cc b/source/blender/blenlib/tests/BLI_linear_allocator_test.cc index b67683d0558..8f707789954 100644 --- a/source/blender/blenlib/tests/BLI_linear_allocator_test.cc +++ b/source/blender/blenlib/tests/BLI_linear_allocator_test.cc @@ -36,13 +36,13 @@ TEST(linear_allocator, PackedAllocation) blender::AlignedBuffer<256, 32> buffer; allocator.provide_buffer(buffer); - uintptr_t ptr1 = (uintptr_t)allocator.allocate(10, 4); /* 0 - 10 */ - uintptr_t ptr2 = (uintptr_t)allocator.allocate(10, 4); /* 12 - 22 */ - uintptr_t ptr3 = (uintptr_t)allocator.allocate(8, 32); /* 32 - 40 */ - uintptr_t ptr4 = (uintptr_t)allocator.allocate(16, 8); /* 40 - 56 */ - uintptr_t ptr5 = (uintptr_t)allocator.allocate(1, 8); /* 56 - 57 */ - uintptr_t ptr6 = (uintptr_t)allocator.allocate(1, 4); /* 60 - 61 */ - uintptr_t ptr7 = (uintptr_t)allocator.allocate(1, 1); /* 61 - 62 */ + uintptr_t ptr1 = uintptr_t(allocator.allocate(10, 4)); /* 0 - 10 */ + uintptr_t ptr2 = uintptr_t(allocator.allocate(10, 4)); /* 12 - 22 */ + uintptr_t ptr3 = uintptr_t(allocator.allocate(8, 32)); /* 32 - 40 */ + uintptr_t ptr4 = uintptr_t(allocator.allocate(16, 8)); /* 40 - 56 */ + uintptr_t ptr5 = uintptr_t(allocator.allocate(1, 8)); /* 56 - 57 */ + uintptr_t ptr6 = uintptr_t(allocator.allocate(1, 4)); /* 60 - 61 */ + uintptr_t ptr7 = uintptr_t(allocator.allocate(1, 1)); /* 61 - 62 */ EXPECT_EQ(ptr2 - ptr1, 12); /* 12 - 0 = 12 */ EXPECT_EQ(ptr3 - ptr2, 20); /* 32 - 12 = 20 */ diff --git a/source/blender/blenlib/tests/BLI_math_color_test.cc b/source/blender/blenlib/tests/BLI_math_color_test.cc index 4d928477870..0b6f9340379 100644 --- a/source/blender/blenlib/tests/BLI_math_color_test.cc +++ b/source/blender/blenlib/tests/BLI_math_color_test.cc @@ -68,7 +68,7 @@ TEST(math_color, LinearRGBTosRGBRoundtrip) const int N = 50; int i; for (i = 0; i < N; ++i) { - float orig_linear_color = (float)i / N; + float orig_linear_color = float(i) / N; float srgb_color = linearrgb_to_srgb(orig_linear_color); float linear_color = srgb_to_linearrgb(srgb_color); EXPECT_NEAR(orig_linear_color, linear_color, 1e-5); diff --git a/source/blender/blenlib/tests/BLI_math_rotation_test.cc b/source/blender/blenlib/tests/BLI_math_rotation_test.cc index 460cfd2d36c..e37b212e1df 100644 --- a/source/blender/blenlib/tests/BLI_math_rotation_test.cc +++ b/source/blender/blenlib/tests/BLI_math_rotation_test.cc @@ -161,7 +161,7 @@ static void test_sin_cos_from_fraction_accuracy(const int range, const float exp for (int i = 0; i < range; i++) { float sin_cos_fl[2]; sin_cos_from_fraction(i, range, &sin_cos_fl[0], &sin_cos_fl[1]); - const float phi = (float)(2.0 * M_PI) * ((float)i / (float)range); + const float phi = float(2.0 * M_PI) * (float(i) / float(range)); const float sin_cos_test_fl[2] = {sinf(phi), cosf(phi)}; EXPECT_V2_NEAR(sin_cos_fl, sin_cos_test_fl, expected_eps); } diff --git a/source/blender/blenlib/tests/BLI_path_util_test.cc b/source/blender/blenlib/tests/BLI_path_util_test.cc index 54afc3d975d..5ea6524f835 100644 --- a/source/blender/blenlib/tests/BLI_path_util_test.cc +++ b/source/blender/blenlib/tests/BLI_path_util_test.cc @@ -651,7 +651,7 @@ TEST(path_util, PathRelPath) abs_path_in[FILE_MAX - 1] = '\0'; abs_path_out[0] = '/'; abs_path_out[1] = '/'; - for (int i = 2; i < FILE_MAX - ((int)ref_path_in_len - 1); i++) { + for (int i = 2; i < FILE_MAX - (int(ref_path_in_len) - 1); i++) { abs_path_out[i] = 'A'; } abs_path_out[FILE_MAX - (ref_path_in_len - 1)] = '\0'; diff --git a/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc b/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc index 69c60c5bdb9..95fd664217f 100644 --- a/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc +++ b/source/blender/blenlib/tests/BLI_polyfill_2d_test.cc @@ -94,10 +94,10 @@ static void test_polyfill_topology(const float /*poly*/[][2], const uint v2 = tris[i][(j + 1) % 3]; void **p = BLI_edgehash_lookup_p(edgehash, v1, v2); if (p) { - *p = (void *)((intptr_t)*p + (intptr_t)1); + *p = (void *)(intptr_t(*p) + intptr_t(1)); } else { - BLI_edgehash_insert(edgehash, v1, v2, (void *)(intptr_t)1); + BLI_edgehash_insert(edgehash, v1, v2, (void *)intptr_t(1)); } } } diff --git a/source/blender/blenlib/tests/BLI_string_utf8_test.cc b/source/blender/blenlib/tests/BLI_string_utf8_test.cc index 2da439dad18..7179eef5adb 100644 --- a/source/blender/blenlib/tests/BLI_string_utf8_test.cc +++ b/source/blender/blenlib/tests/BLI_string_utf8_test.cc @@ -274,7 +274,7 @@ TEST(string, Utf8InvalidBytes) for (int i = 0; utf8_invalid_tests[i][0] != nullptr; i++) { const char *tst = utf8_invalid_tests[i][0]; const char *tst_stripped = utf8_invalid_tests[i][1]; - const int errors_num = (int)utf8_invalid_tests[i][2][0]; + const int errors_num = int(utf8_invalid_tests[i][2][0]); char buff[80]; memcpy(buff, tst, sizeof(buff)); @@ -352,13 +352,13 @@ template<size_t Size> void utf8_as_char32_test_at_buffer_size() /* Offset trailing bytes up and down in steps of 1, 2, 4 .. etc. */ if (Size > 1) { for (int mul = 1; mul < 256; mul *= 2) { - for (int ofs = 1; ofs < (int)Size; ofs++) { - utf8_src[ofs] = (char)(i + (ofs * mul)); + for (int ofs = 1; ofs < int(Size); ofs++) { + utf8_src[ofs] = char(i + (ofs * mul)); } utf8_as_char32_test_compare<Size>(utf8_src); - for (int ofs = 1; ofs < (int)Size; ofs++) { - utf8_src[ofs] = (char)(i - (ofs * mul)); + for (int ofs = 1; ofs < int(Size); ofs++) { + utf8_src[ofs] = char(i - (ofs * mul)); } utf8_as_char32_test_compare<Size>(utf8_src); } diff --git a/source/blender/blenlib/tests/BLI_virtual_array_test.cc b/source/blender/blenlib/tests/BLI_virtual_array_test.cc index 14f5480f751..6d6580c52d4 100644 --- a/source/blender/blenlib/tests/BLI_virtual_array_test.cc +++ b/source/blender/blenlib/tests/BLI_virtual_array_test.cc @@ -98,7 +98,7 @@ TEST(virtual_array, VectorSet) TEST(virtual_array, Func) { - auto func = [](int64_t index) { return (int)(index * index); }; + auto func = [](int64_t index) { return int(index * index); }; VArray<int> varray = VArray<int>::ForFunc(10, func); EXPECT_EQ(varray.size(), 10); EXPECT_EQ(varray[0], 0); @@ -108,7 +108,7 @@ TEST(virtual_array, Func) TEST(virtual_array, AsSpan) { - auto func = [](int64_t index) { return (int)(10 * index); }; + auto func = [](int64_t index) { return int(10 * index); }; VArray<int> func_varray = VArray<int>::ForFunc(10, func); VArraySpan span_varray{func_varray}; EXPECT_EQ(span_varray.size(), 10); @@ -210,7 +210,7 @@ TEST(virtual_array, MaterializeCompressed) EXPECT_EQ(compressed_array[2], 4); } { - VArray<int> varray = VArray<int>::ForFunc(10, [](const int64_t i) { return (int)(i * i); }); + VArray<int> varray = VArray<int>::ForFunc(10, [](const int64_t i) { return int(i * i); }); std::array<int, 3> compressed_array; varray.materialize_compressed({5, 7, 8}, compressed_array); EXPECT_EQ(compressed_array[0], 25); diff --git a/source/blender/blenlib/tests/performance/BLI_ghash_performance_test.cc b/source/blender/blenlib/tests/performance/BLI_ghash_performance_test.cc index e1d3adc6e78..efcf8dea922 100644 --- a/source/blender/blenlib/tests/performance/BLI_ghash_performance_test.cc +++ b/source/blender/blenlib/tests/performance/BLI_ghash_performance_test.cc @@ -270,7 +270,7 @@ static void randint_ghash_tests(GHash *ghash, const char *id, const uint count) { printf("\n========== STARTING %s ==========\n", id); - uint *data = (uint *)MEM_mallocN(sizeof(*data) * (size_t)count, __func__); + uint *data = (uint *)MEM_mallocN(sizeof(*data) * size_t(count), __func__); uint *dt; uint i; @@ -379,7 +379,7 @@ static void int4_ghash_tests(GHash *ghash, const char *id, const uint count) { printf("\n========== STARTING %s ==========\n", id); - void *data_v = MEM_mallocN(sizeof(uint[4]) * (size_t)count, __func__); + void *data_v = MEM_mallocN(sizeof(uint[4]) * size_t(count), __func__); uint(*data)[4] = (uint(*)[4])data_v; uint(*dt)[4]; uint i, j; @@ -485,7 +485,7 @@ TEST(ghash, Int2NoHash50000000) static void multi_small_ghash_tests_one(GHash *ghash, RNG *rng, const uint count) { - uint *data = (uint *)MEM_mallocN(sizeof(*data) * (size_t)count, __func__); + uint *data = (uint *)MEM_mallocN(sizeof(*data) * size_t(count), __func__); uint *dt; uint i; diff --git a/source/blender/blenlib/tests/performance/BLI_task_performance_test.cc b/source/blender/blenlib/tests/performance/BLI_task_performance_test.cc index a86e9b0b86d..adebb1edb8b 100644 --- a/source/blender/blenlib/tests/performance/BLI_task_performance_test.cc +++ b/source/blender/blenlib/tests/performance/BLI_task_performance_test.cc @@ -69,7 +69,7 @@ static void task_listbase_heavy_iter_func(void *UNUSED(userdata), LinkData *data = (LinkData *)item; /* 'Random' number of iterations. */ - const uint num = gen_pseudo_random_number((uint)index); + const uint num = gen_pseudo_random_number(uint(index)); for (uint i = 0; i < num; i++) { data->data = POINTER_FROM_INT(POINTER_AS_INT(data->data) + ((i % 2) ? -index : index)); @@ -86,7 +86,7 @@ static void task_listbase_heavy_membarrier_iter_func(void *userdata, int *count = (int *)userdata; /* 'Random' number of iterations. */ - const uint num = gen_pseudo_random_number((uint)index); + const uint num = gen_pseudo_random_number(uint(index)); for (uint i = 0; i < num; i++) { data->data = POINTER_FROM_INT(POINTER_AS_INT(data->data) + ((i % 2) ? -index : index)); |