diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-25 10:04:52 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-25 11:26:27 +0300 |
commit | 891949cbb47143420f4324cb60efc05ef5d70b39 (patch) | |
tree | fe70a45612ae96f9ce1f37378ef5ff035d3127f5 /source/blender/blenlib/intern/rand.cc | |
parent | c9e35c2ced92082c86f1ecb9ecd16c6230218c7c (diff) |
Cleanup: use 'u' prefixed integer types for brevity & cast style
To use function style cast '(unsigned char)x' can't be replaced by
'unsigned char(x)'.
Diffstat (limited to 'source/blender/blenlib/intern/rand.cc')
-rw-r--r-- | source/blender/blenlib/intern/rand.cc | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/source/blender/blenlib/intern/rand.cc b/source/blender/blenlib/intern/rand.cc index f6d91cdcc4f..40bbe14101b 100644 --- a/source/blender/blenlib/intern/rand.cc +++ b/source/blender/blenlib/intern/rand.cc @@ -24,7 +24,7 @@ #include "BLI_strict_flags.h" #include "BLI_sys_types.h" -extern "C" unsigned char BLI_noise_hash_uchar_512[512]; /* noise.c */ +extern "C" uchar BLI_noise_hash_uchar_512[512]; /* noise.c */ #define hash BLI_noise_hash_uchar_512 /** @@ -36,14 +36,14 @@ struct RNG { MEM_CXX_CLASS_ALLOC_FUNCS("RNG") }; -RNG *BLI_rng_new(unsigned int seed) +RNG *BLI_rng_new(uint seed) { RNG *rng = new RNG(); rng->rng.seed(seed); return rng; } -RNG *BLI_rng_new_srandom(unsigned int seed) +RNG *BLI_rng_new_srandom(uint seed) { RNG *rng = new RNG(); rng->rng.seed_random(seed); @@ -60,12 +60,12 @@ void BLI_rng_free(RNG *rng) delete rng; } -void BLI_rng_seed(RNG *rng, unsigned int seed) +void BLI_rng_seed(RNG *rng, uint seed) { rng->rng.seed(seed); } -void BLI_rng_srandom(RNG *rng, unsigned int seed) +void BLI_rng_srandom(RNG *rng, uint seed) { rng->rng.seed_random(seed); } @@ -80,7 +80,7 @@ int BLI_rng_get_int(RNG *rng) return rng->rng.get_int32(); } -unsigned int BLI_rng_get_uint(RNG *rng) +uint BLI_rng_get_uint(RNG *rng) { return rng->rng.get_uint32(); } @@ -117,21 +117,21 @@ void BLI_rng_get_tri_sample_float_v3( copy_v3_v3(r_pt, rng->rng.get_triangle_sample_3d(v1, v2, v3)); } -void BLI_rng_shuffle_array(RNG *rng, void *data, unsigned int elem_size_i, unsigned int elem_num) +void BLI_rng_shuffle_array(RNG *rng, void *data, uint elem_size_i, uint elem_num) { if (elem_num <= 1) { return; } const uint elem_size = elem_size_i; - unsigned int i = elem_num; + uint i = elem_num; void *temp = malloc(elem_size); while (i--) { - const unsigned int j = BLI_rng_get_uint(rng) % elem_num; + const uint j = BLI_rng_get_uint(rng) % elem_num; if (i != j) { - void *iElem = (unsigned char *)data + i * elem_size_i; - void *jElem = (unsigned char *)data + j * elem_size_i; + void *iElem = (uchar *)data + i * elem_size_i; + void *jElem = (uchar *)data + j * elem_size_i; memcpy(temp, iElem, elem_size); memcpy(iElem, jElem, elem_size); memcpy(jElem, temp, elem_size); @@ -141,15 +141,15 @@ void BLI_rng_shuffle_array(RNG *rng, void *data, unsigned int elem_size_i, unsig free(temp); } -void BLI_rng_shuffle_bitmap(struct RNG *rng, BLI_bitmap *bitmap, unsigned int bits_num) +void BLI_rng_shuffle_bitmap(struct RNG *rng, BLI_bitmap *bitmap, uint bits_num) { if (bits_num <= 1) { return; } - unsigned int i = bits_num; + uint i = bits_num; while (i--) { - const unsigned int j = BLI_rng_get_uint(rng) % bits_num; + const uint j = BLI_rng_get_uint(rng) % bits_num; if (i != j) { const bool i_bit = BLI_BITMAP_TEST(bitmap, i); const bool j_bit = BLI_BITMAP_TEST(bitmap, j); @@ -166,7 +166,7 @@ void BLI_rng_skip(RNG *rng, int n) /***/ -void BLI_array_frand(float *ar, int count, unsigned int seed) +void BLI_array_frand(float *ar, int count, uint seed) { RNG rng; @@ -177,7 +177,7 @@ void BLI_array_frand(float *ar, int count, unsigned int seed) } } -float BLI_hash_frand(unsigned int seed) +float BLI_hash_frand(uint seed) { RNG rng; @@ -185,10 +185,7 @@ float BLI_hash_frand(unsigned int seed) return BLI_rng_get_float(&rng); } -void BLI_array_randomize(void *data, - unsigned int elem_size, - unsigned int elem_num, - unsigned int seed) +void BLI_array_randomize(void *data, uint elem_size, uint elem_num, uint seed) { RNG rng; @@ -196,7 +193,7 @@ void BLI_array_randomize(void *data, BLI_rng_shuffle_array(&rng, data, elem_size, elem_num); } -void BLI_bitmap_randomize(BLI_bitmap *bitmap, unsigned int bits_num, unsigned int seed) +void BLI_bitmap_randomize(BLI_bitmap *bitmap, uint bits_num, uint seed) { RNG rng; @@ -208,7 +205,7 @@ void BLI_bitmap_randomize(BLI_bitmap *bitmap, unsigned int bits_num, unsigned in static RNG rng_tab[BLENDER_MAX_THREADS]; -void BLI_thread_srandom(int thread, unsigned int seed) +void BLI_thread_srandom(int thread, uint seed) { if (thread >= BLENDER_MAX_THREADS) { thread = 0; @@ -237,12 +234,12 @@ struct RNG_THREAD_ARRAY { RNG_THREAD_ARRAY *BLI_rng_threaded_new() { - unsigned int i; + uint i; RNG_THREAD_ARRAY *rngarr = (RNG_THREAD_ARRAY *)MEM_mallocN(sizeof(RNG_THREAD_ARRAY), "random_array"); for (i = 0; i < BLENDER_MAX_THREADS; i++) { - BLI_rng_srandom(&rngarr->rng_tab[i], (unsigned int)clock()); + BLI_rng_srandom(&rngarr->rng_tab[i], (uint)clock()); } return rngarr; @@ -284,7 +281,7 @@ BLI_INLINE double halton_ex(double invprimes, double *offset) return *offset; } -void BLI_halton_1d(unsigned int prime, double offset, int n, double *r) +void BLI_halton_1d(uint prime, double offset, int n, double *r) { const double invprime = 1.0 / (double)prime; @@ -295,7 +292,7 @@ void BLI_halton_1d(unsigned int prime, double offset, int n, double *r) } } -void BLI_halton_2d(const unsigned int prime[2], double offset[2], 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]}; @@ -308,7 +305,7 @@ void BLI_halton_2d(const unsigned int prime[2], double offset[2], int n, double } } -void BLI_halton_3d(const unsigned int prime[3], double offset[3], 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]}; @@ -322,7 +319,7 @@ void BLI_halton_3d(const unsigned int prime[3], double offset[3], int n, double } } -void BLI_halton_2d_sequence(const unsigned int prime[2], double offset[2], 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]}; @@ -335,7 +332,7 @@ void BLI_halton_2d_sequence(const unsigned int prime[2], double offset[2], int n /* From "Sampling with Hammersley and Halton Points" TT Wong * Appendix: Source Code 1 */ -BLI_INLINE double radical_inverse(unsigned int n) +BLI_INLINE double radical_inverse(uint n) { double u = 0; @@ -350,14 +347,14 @@ BLI_INLINE double radical_inverse(unsigned int n) return u; } -void BLI_hammersley_1d(unsigned int n, double *r) +void BLI_hammersley_1d(uint n, double *r) { *r = radical_inverse(n); } -void BLI_hammersley_2d_sequence(unsigned int n, double *r) +void BLI_hammersley_2d_sequence(uint n, double *r) { - for (unsigned int s = 0; s < n; s++) { + for (uint s = 0; s < n; s++) { r[s * 2 + 0] = (double)(s + 0.5) / (double)n; r[s * 2 + 1] = radical_inverse(s); } |