diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-25 11:30:50 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-25 11:31:10 +0300 |
commit | c7b247a118e302a3afc6473797e53b6af28b69e2 (patch) | |
tree | d11149a165bfd8f3b3b791f24547499f041b133b /source/blender/blenlib | |
parent | 891949cbb47143420f4324cb60efc05ef5d70b39 (diff) |
Cleanup: replace static_casts with functional casts for numeric types
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/delaunay_2d.cc | 14 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vec.cc | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/mesh_intersect.cc | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/noise.cc | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rand.cc | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_search.cc | 13 | ||||
-rw-r--r-- | source/blender/blenlib/intern/uuid.cc | 8 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_delaunay_2d_test.cc | 18 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_mesh_intersect_test.cc | 2 | ||||
-rw-r--r-- | source/blender/blenlib/tests/BLI_span_test.cc | 2 |
10 files changed, 34 insertions, 35 deletions
diff --git a/source/blender/blenlib/intern/delaunay_2d.cc b/source/blender/blenlib/intern/delaunay_2d.cc index db6cb0824dc..6280fe1010f 100644 --- a/source/blender/blenlib/intern/delaunay_2d.cc +++ b/source/blender/blenlib/intern/delaunay_2d.cc @@ -520,10 +520,10 @@ template<typename T> void cdt_draw(const std::string &label, const CDTArrangemen double height = maxy - miny; double aspect = height / width; int view_width = max_draw_width; - int view_height = static_cast<int>(view_width * aspect); + int view_height = int(view_width * aspect); if (view_height > max_draw_height) { view_height = max_draw_height; - view_width = static_cast<int>(view_height / aspect); + view_width = int(view_height / aspect); } double scale = view_width / width; @@ -2822,8 +2822,8 @@ extern "C" ::CDT_result *BLI_delaunay_2d_cdt_calc(const ::CDT_input *input, in.edge = blender::Array<std::pair<int, int>>(input->edges_len); in.face = blender::Array<blender::Vector<int>>(input->faces_len); for (int v = 0; v < input->verts_len; ++v) { - double x = static_cast<double>(input->vert_coords[v][0]); - double y = static_cast<double>(input->vert_coords[v][1]); + double x = double(input->vert_coords[v][0]); + double y = double(input->vert_coords[v][1]); in.vert[v] = blender::meshintersect::vec2<double>(x, y); } for (int e = 0; e < input->edges_len; ++e) { @@ -2836,7 +2836,7 @@ extern "C" ::CDT_result *BLI_delaunay_2d_cdt_calc(const ::CDT_input *input, in.face[f][j] = input->faces[fstart + j]; } } - in.epsilon = static_cast<double>(input->epsilon); + in.epsilon = double(input->epsilon); in.need_ids = input->need_ids; blender::meshintersect::CDT_result<double> res = blender::meshintersect::delaunay_2d_calc( @@ -2903,8 +2903,8 @@ extern "C" ::CDT_result *BLI_delaunay_2d_cdt_calc(const ::CDT_input *input, int v_orig_index = 0; for (int v = 0; v < nv; ++v) { - output->vert_coords[v][0] = static_cast<float>(res.vert[v][0]); - output->vert_coords[v][1] = static_cast<float>(res.vert[v][1]); + output->vert_coords[v][0] = float(res.vert[v][0]); + output->vert_coords[v][1] = float(res.vert[v][1]); if (input->need_ids) { int this_start = v_orig_index; output->verts_orig_start_table[v] = this_start; diff --git a/source/blender/blenlib/intern/math_vec.cc b/source/blender/blenlib/intern/math_vec.cc index 99c873299fe..8d1f850d8e5 100644 --- a/source/blender/blenlib/intern/math_vec.cc +++ b/source/blender/blenlib/intern/math_vec.cc @@ -108,7 +108,7 @@ isect_result<mpq2> isect_seg_seg(const mpq2 &v1, const mpq2 &v2, const mpq2 &v3, uint64_t hash_mpq_class(const mpq_class &value) { /* TODO: better/faster implementation of this. */ - return get_default_hash(static_cast<float>(value.get_d())); + return get_default_hash(float(value.get_d())); } #endif diff --git a/source/blender/blenlib/intern/mesh_intersect.cc b/source/blender/blenlib/intern/mesh_intersect.cc index a48df0aa977..7553898f5d3 100644 --- a/source/blender/blenlib/intern/mesh_intersect.cc +++ b/source/blender/blenlib/intern/mesh_intersect.cc @@ -2419,7 +2419,7 @@ class TriOverlaps { } } first_overlap_ = Array<int>(tm.face_size(), -1); - for (int i = 0; i < static_cast<int>(overlap_num_); ++i) { + for (int i = 0; i < int(overlap_num_); ++i) { int t = overlap_[i].indexA; if (first_overlap_[t] == -1) { first_overlap_[t] = i; diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc index 8a073239b31..19c4b92a315 100644 --- a/source/blender/blenlib/intern/noise.cc +++ b/source/blender/blenlib/intern/noise.cc @@ -150,7 +150,7 @@ uint32_t hash_float(float4 k) BLI_INLINE float uint_to_float_01(uint32_t k) { - return static_cast<float>(k) / static_cast<float>(0xFFFFFFFFu); + return float(k) / float(0xFFFFFFFFu); } float hash_to_float(uint32_t kx) @@ -536,7 +536,7 @@ template<typename T> float perlin_fractal_template(T position, float octaves, fl float maxamp = 0.0f; float sum = 0.0f; octaves = CLAMPIS(octaves, 0.0f, 15.0f); - int n = static_cast<int>(octaves); + int n = int(octaves); for (int i = 0; i <= n; i++) { float t = perlin(fscale * position); sum += t * amp; diff --git a/source/blender/blenlib/intern/rand.cc b/source/blender/blenlib/intern/rand.cc index 40bbe14101b..b5db0d6b473 100644 --- a/source/blender/blenlib/intern/rand.cc +++ b/source/blender/blenlib/intern/rand.cc @@ -72,7 +72,7 @@ void BLI_rng_srandom(RNG *rng, uint seed) void BLI_rng_get_char_n(RNG *rng, char *bytes, size_t bytes_len) { - rng->rng.get_bytes(blender::MutableSpan(bytes, static_cast<int64_t>(bytes_len))); + rng->rng.get_bytes(blender::MutableSpan(bytes, int64_t(bytes_len))); } int BLI_rng_get_int(RNG *rng) @@ -441,7 +441,7 @@ float3 RandomNumberGenerator::get_triangle_sample_3d(float3 v1, float3 v2, float void RandomNumberGenerator::get_bytes(MutableSpan<char> r_bytes) { constexpr int64_t mask_bytes = 2; - constexpr int64_t rand_stride = static_cast<int64_t>(sizeof(x_)) - mask_bytes; + constexpr int64_t rand_stride = int64_t(sizeof(x_)) - mask_bytes; int64_t last_len = 0; int64_t trim_len = r_bytes.size(); diff --git a/source/blender/blenlib/intern/string_search.cc b/source/blender/blenlib/intern/string_search.cc index 96e2ad33619..6eeae307fc1 100644 --- a/source/blender/blenlib/intern/string_search.cc +++ b/source/blender/blenlib/intern/string_search.cc @@ -18,7 +18,7 @@ namespace blender::string_search { static int64_t count_utf8_code_points(StringRef str) { - return static_cast<int64_t>(BLI_strnlen_utf8(str.data(), static_cast<size_t>(str.size()))); + return int64_t(BLI_strnlen_utf8(str.data(), size_t(str.size()))); } int damerau_levenshtein_distance(StringRef a, StringRef b) @@ -205,7 +205,7 @@ static bool match_word_initials(StringRef query, StringRef word = words[word_index]; /* Try to match the current character with the current word. */ - if (static_cast<int>(char_index) < word.size()) { + if (int(char_index) < word.size()) { const uint32_t char_unicode = BLI_str_utf8_as_unicode_step( word.data(), word.size(), &char_index); if (query_unicode == char_unicode) { @@ -358,7 +358,7 @@ void extract_normalized_words(StringRef str, /* Make a copy of the string so that we can edit it. */ StringRef str_copy = allocator.copy_string(str); char *mutable_copy = const_cast<char *>(str_copy.data()); - const size_t str_size_in_bytes = static_cast<size_t>(str.size()); + const size_t str_size_in_bytes = size_t(str.size()); BLI_str_tolower_ascii(mutable_copy, str_size_in_bytes); /* Iterate over all unicode code points to split individual words. */ @@ -371,8 +371,7 @@ void extract_normalized_words(StringRef str, size -= offset; if (is_separator(unicode)) { if (is_in_word) { - r_words.append( - str_copy.substr(static_cast<int>(word_start), static_cast<int>(offset - word_start))); + r_words.append(str_copy.substr(int(word_start), int(offset - word_start))); is_in_word = false; } } @@ -386,7 +385,7 @@ void extract_normalized_words(StringRef str, } /* If the last word is not followed by a separator, it has to be handled separately. */ if (is_in_word) { - r_words.append(str_copy.drop_prefix(static_cast<int>(word_start))); + r_words.append(str_copy.drop_prefix(int(word_start))); } } @@ -472,7 +471,7 @@ int BLI_string_search_query(StringSearch *search, const char *query, void ***r_d } void **sorted_data = static_cast<void **>( - MEM_malloc_arrayN(static_cast<size_t>(sorted_result_indices.size()), sizeof(void *), AT)); + MEM_malloc_arrayN(size_t(sorted_result_indices.size()), sizeof(void *), AT)); for (const int i : sorted_result_indices.index_range()) { const int result_index = sorted_result_indices[i]; SearchItem &item = search->items[result_index]; diff --git a/source/blender/blenlib/intern/uuid.cc b/source/blender/blenlib/intern/uuid.cc index 890a721a9d1..023dd1ec409 100644 --- a/source/blender/blenlib/intern/uuid.cc +++ b/source/blender/blenlib/intern/uuid.cc @@ -136,10 +136,10 @@ bUUID::bUUID(const std::initializer_list<uint32_t> field_values) const auto *field_iter = field_values.begin(); this->time_low = *field_iter++; - this->time_mid = static_cast<uint16_t>(*field_iter++); - this->time_hi_and_version = static_cast<uint16_t>(*field_iter++); - this->clock_seq_hi_and_reserved = static_cast<uint8_t>(*field_iter++); - this->clock_seq_low = static_cast<uint8_t>(*field_iter++); + this->time_mid = uint16_t(*field_iter++); + this->time_hi_and_version = uint16_t(*field_iter++); + this->clock_seq_hi_and_reserved = uint8_t(*field_iter++); + this->clock_seq_low = uint8_t(*field_iter++); std::copy(field_iter, field_values.end(), this->node); } diff --git a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc index 25ee523ebc0..adcfe7f5d2d 100644 --- a/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc +++ b/source/blender/blenlib/tests/BLI_delaunay_2d_test.cc @@ -99,7 +99,7 @@ template<typename T> CDT_input<T> fill_input_from_string(const char *spec) */ static int get_orig_index(const Array<Vector<int>> &out_to_orig, int orig_index) { - int n = static_cast<int>(out_to_orig.size()); + int n = int(out_to_orig.size()); for (int i = 0; i < n; ++i) { for (int orig : out_to_orig[i]) { if (orig == orig_index) { @@ -147,7 +147,7 @@ template<> double math_abs(const double v) */ template<typename T> int get_vertex_by_coord(const CDT_result<T> &out, double x, double y) { - int nv = static_cast<int>(out.vert.size()); + int nv = int(out.vert.size()); for (int i = 0; i < nv; ++i) { double vx = math_to_double(out.vert[i][0]); double vy = math_to_double(out.vert[i][1]); @@ -162,7 +162,7 @@ template<typename T> int get_vertex_by_coord(const CDT_result<T> &out, double x, template<typename T> int get_output_edge_index(const CDT_result<T> &out, int out_index_1, int out_index_2) { - int ne = static_cast<int>(out.edge.size()); + int ne = int(out.edge.size()); for (int i = 0; i < ne; ++i) { if ((out.edge[i].first == out_index_1 && out.edge[i].second == out_index_2) || (out.edge[i].first == out_index_2 && out.edge[i].second == out_index_1)) { @@ -175,7 +175,7 @@ int get_output_edge_index(const CDT_result<T> &out, int out_index_1, int out_ind template<typename T> bool output_edge_has_input_id(const CDT_result<T> &out, int out_edge_index, int in_edge_index) { - return out_edge_index < static_cast<int>(out.edge_orig.size()) && + return out_edge_index < int(out.edge_orig.size()) && out.edge_orig[out_edge_index].contains(in_edge_index); } @@ -184,8 +184,8 @@ bool output_edge_has_input_id(const CDT_result<T> &out, int out_edge_index, int */ template<typename T> int get_output_face_index(const CDT_result<T> &out, const Array<int> &poly) { - int nf = static_cast<int>(out.face.size()); - int npolyv = static_cast<int>(poly.size()); + int nf = int(out.face.size()); + int npolyv = int(poly.size()); for (int f = 0; f < nf; ++f) { if (out.face[f].size() != poly.size()) { continue; @@ -218,7 +218,7 @@ int get_output_tri_index(const CDT_result<T> &out, template<typename T> bool output_face_has_input_id(const CDT_result<T> &out, int out_face_index, int in_face_index) { - return out_face_index < static_cast<int>(out.face_orig.size()) && + return out_face_index < int(out.face_orig.size()) && out.face_orig[out_face_index].contains(in_face_index); } @@ -310,10 +310,10 @@ void graph_draw(const std::string &label, double height = maxy - miny; double aspect = height / width; int view_width = max_draw_width; - int view_height = static_cast<int>(view_width * aspect); + int view_height = int(view_width * aspect); if (view_height > max_draw_height) { view_height = max_draw_height; - view_width = static_cast<int>(view_height / aspect); + view_width = int(view_height / aspect); } double scale = view_width / width; diff --git a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc index c155068b94a..67a5771593a 100644 --- a/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc +++ b/source/blender/blenlib/tests/BLI_mesh_intersect_test.cc @@ -153,7 +153,7 @@ static int find_edge_pos_in_tri(const Vert *v0, const Vert *v1, const Face *f) for (int pos : f->index_range()) { int nextpos = f->next_pos(pos); if (((*f)[pos] == v0 && (*f)[nextpos] == v1) || ((*f)[pos] == v1 && (*f)[nextpos] == v0)) { - return static_cast<int>(pos); + return int(pos); } } return -1; diff --git a/source/blender/blenlib/tests/BLI_span_test.cc b/source/blender/blenlib/tests/BLI_span_test.cc index 0bd34250deb..0d974786a1a 100644 --- a/source/blender/blenlib/tests/BLI_span_test.cc +++ b/source/blender/blenlib/tests/BLI_span_test.cc @@ -237,7 +237,7 @@ TEST(span, SizeInBytes) { std::array<int, 10> a{}; Span<int> a_span(a); - EXPECT_EQ(a_span.size_in_bytes(), static_cast<int64_t>(sizeof(a))); + EXPECT_EQ(a_span.size_in_bytes(), int64_t(sizeof(a))); EXPECT_EQ(a_span.size_in_bytes(), 40); } |