From 9ba948a4859da3308033fa6dc54f74433d7e6a21 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 27 Mar 2019 13:16:10 +1100 Subject: Cleanup: style, use braces for blenlib --- source/blender/blenlib/intern/BLI_args.c | 24 +- source/blender/blenlib/intern/BLI_dial_2d.c | 6 +- source/blender/blenlib/intern/BLI_dynstr.c | 48 ++-- source/blender/blenlib/intern/BLI_filelist.c | 59 +++-- source/blender/blenlib/intern/BLI_ghash.c | 16 +- source/blender/blenlib/intern/BLI_kdopbvh.c | 144 ++++++++---- source/blender/blenlib/intern/BLI_linklist.c | 24 +- source/blender/blenlib/intern/BLI_timer.c | 8 +- source/blender/blenlib/intern/DLRB_tree.c | 137 ++++++++---- source/blender/blenlib/intern/boxpack_2d.c | 17 +- source/blender/blenlib/intern/convexhull_2d.c | 14 +- source/blender/blenlib/intern/dynlib.c | 9 +- source/blender/blenlib/intern/easing.c | 57 +++-- source/blender/blenlib/intern/edgehash.c | 12 +- source/blender/blenlib/intern/expr_pylike_eval.c | 15 +- source/blender/blenlib/intern/fileops.c | 112 +++++++--- source/blender/blenlib/intern/freetypefont.c | 25 ++- source/blender/blenlib/intern/gsqueue.c | 6 +- source/blender/blenlib/intern/hash_md5.c | 9 +- source/blender/blenlib/intern/jitter_2d.c | 12 +- source/blender/blenlib/intern/lasso_2d.c | 24 +- source/blender/blenlib/intern/listbase.c | 116 +++++++--- source/blender/blenlib/intern/math_base.c | 12 +- source/blender/blenlib/intern/math_base_inline.c | 62 ++--- source/blender/blenlib/intern/math_color.c | 89 +++++--- source/blender/blenlib/intern/math_color_inline.c | 3 +- source/blender/blenlib/intern/math_geom.c | 261 +++++++++++++++------- source/blender/blenlib/intern/math_geom_inline.c | 9 +- source/blender/blenlib/intern/math_interp.c | 104 ++++++--- source/blender/blenlib/intern/math_matrix.c | 120 ++++++---- source/blender/blenlib/intern/math_rotation.c | 86 ++++--- source/blender/blenlib/intern/math_solvers.c | 12 +- source/blender/blenlib/intern/math_statistics.c | 3 +- source/blender/blenlib/intern/math_vector.c | 20 +- source/blender/blenlib/intern/noise.c | 44 ++-- source/blender/blenlib/intern/path_util.c | 106 ++++++--- source/blender/blenlib/intern/polyfill_2d.c | 13 +- source/blender/blenlib/intern/rand.c | 3 +- source/blender/blenlib/intern/rct.c | 168 ++++++++------ source/blender/blenlib/intern/scanfill.c | 91 +++++--- source/blender/blenlib/intern/smallhash.c | 3 +- source/blender/blenlib/intern/sort.c | 6 +- source/blender/blenlib/intern/sort_utils.c | 36 +-- source/blender/blenlib/intern/storage.c | 54 +++-- source/blender/blenlib/intern/string.c | 70 ++++-- source/blender/blenlib/intern/string_utf8.c | 64 +++--- source/blender/blenlib/intern/string_utils.c | 6 +- source/blender/blenlib/intern/task.c | 27 ++- source/blender/blenlib/intern/threads.c | 44 ++-- source/blender/blenlib/intern/uvproject.c | 6 +- source/blender/blenlib/intern/voronoi_2d.c | 96 +++++--- source/blender/blenlib/intern/winstuff.c | 31 ++- source/blender/blenlib/intern/winstuff_dir.c | 19 +- 53 files changed, 1705 insertions(+), 857 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index dbd609d914a..61619bc114b 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -71,8 +71,9 @@ static uint case_strhash(const void *ptr) uint i = 0; unsigned char c; - while ( (c = tolower(*s++)) ) + while ((c = tolower(*s++))) { i = i * 37 + c; + } return i; } @@ -150,8 +151,9 @@ static bArgDoc *internalDocs(struct bArgs *ba, const char *short_arg, const char d = MEM_callocN(sizeof(bArgDoc), "bArgDoc"); - if (doc == NULL) + if (doc == NULL) { doc = NO_DOCS; + } d->short_arg = short_arg; d->long_arg = long_arg; @@ -200,11 +202,13 @@ void BLI_argsAddCase(struct bArgs *ba, int pass, { bArgDoc *d = internalDocs(ba, short_arg, long_arg, doc); - if (short_arg) + if (short_arg) { internalAdd(ba, short_arg, pass, short_case, cb, data, d); + } - if (long_arg) + if (long_arg) { internalAdd(ba, long_arg, pass, long_case, cb, data, d); + } } void BLI_argsAdd(struct bArgs *ba, int pass, @@ -216,12 +220,15 @@ void BLI_argsAdd(struct bArgs *ba, int pass, static void internalDocPrint(bArgDoc *d) { - if (d->short_arg && d->long_arg) + if (d->short_arg && d->long_arg) { printf("%s or %s", d->short_arg, d->long_arg); - else if (d->short_arg) + } + else if (d->short_arg) { printf("%s", d->short_arg); - else if (d->long_arg) + } + else if (d->long_arg) { printf("%s", d->long_arg); + } printf(" %s\n\n", d->documentation); } @@ -284,8 +291,9 @@ void BLI_argsParse(struct bArgs *ba, int pass, BA_ArgCallback default_cb, void * } else if (retval == -1) { if (a) { - if (a->key->pass != -1) + if (a->key->pass != -1) { ba->passes[i] = pass; + } } break; } diff --git a/source/blender/blenlib/intern/BLI_dial_2d.c b/source/blender/blenlib/intern/BLI_dial_2d.c index 882d239aa4b..dd983fe7f8f 100644 --- a/source/blender/blenlib/intern/BLI_dial_2d.c +++ b/source/blender/blenlib/intern/BLI_dial_2d.c @@ -88,10 +88,12 @@ float BLI_dial_angle(Dial *dial, const float current_position[2]) if ((angle * dial->last_angle < 0.0f) && (fabsf(dial->last_angle) > (float)M_PI_2)) { - if (dial->last_angle < 0.0f) + if (dial->last_angle < 0.0f) { dial->rotations--; - else + } + else { dial->rotations++; + } } dial->last_angle = angle; diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index 98682101c65..ef45d7b2a47 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -112,10 +112,12 @@ void BLI_dynstr_append(DynStr *__restrict ds, const char *cstr) memcpy(dse->str, cstr, cstrlen + 1); dse->next = NULL; - if (!ds->last) + if (!ds->last) { ds->last = ds->elems = dse; - else + } + else { ds->last = ds->last->next = dse; + } ds->curlen += cstrlen; } @@ -137,10 +139,12 @@ void BLI_dynstr_nappend(DynStr *__restrict ds, const char *cstr, int len) dse->str[cstrlen] = '\0'; dse->next = NULL; - if (!ds->last) + if (!ds->last) { ds->last = ds->elems = dse; - else + } + else { ds->last = ds->last->next = dse; + } ds->curlen += cstrlen; } @@ -154,10 +158,12 @@ void BLI_dynstr_vappendf(DynStr *__restrict ds, const char *__restrict format, v while (1) { va_list args_cpy; - if (len == sizeof(fixedmessage)) + if (len == sizeof(fixedmessage)) { message = fixedmessage; - else + } + else { message = MEM_callocN(sizeof(char) * len, "BLI_dynstr_appendf"); + } /* cant reuse the same args, so work on a copy */ va_copy(args_cpy, args); @@ -167,8 +173,9 @@ void BLI_dynstr_vappendf(DynStr *__restrict ds, const char *__restrict format, v if (retval == -1) { /* -1 means not enough space, but on windows it may also mean * there is a formatting error, so we impose a maximum length */ - if (message != fixedmessage) + if (message != fixedmessage) { MEM_freeN(message); + } message = NULL; len *= 2; @@ -179,22 +186,25 @@ void BLI_dynstr_vappendf(DynStr *__restrict ds, const char *__restrict format, v } else if (retval >= len) { /* in C99 the actual length required is returned */ - if (message != fixedmessage) + if (message != fixedmessage) { MEM_freeN(message); + } message = NULL; /* retval doesn't include \0 terminator */ len = retval + 1; } - else + else { break; + } } if (message) { BLI_dynstr_append(ds, message); - if (message != fixedmessage) + if (message != fixedmessage) { MEM_freeN(message); + } } } @@ -217,10 +227,12 @@ void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format, .. * va_start/va_end have to be called for each vsnprintf call */ while (1) { - if (len == sizeof(fixedmessage)) + if (len == sizeof(fixedmessage)) { message = fixedmessage; - else + } + else { message = MEM_callocN(sizeof(char) * (len), "BLI_dynstr_appendf"); + } va_start(args, format); retval = vsnprintf(message, len, format, args); @@ -229,8 +241,9 @@ void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format, .. if (retval == -1) { /* -1 means not enough space, but on windows it may also mean * there is a formatting error, so we impose a maximum length */ - if (message != fixedmessage) + if (message != fixedmessage) { MEM_freeN(message); + } message = NULL; len *= 2; @@ -241,22 +254,25 @@ void BLI_dynstr_appendf(DynStr *__restrict ds, const char *__restrict format, .. } else if (retval >= len) { /* in C99 the actual length required is returned */ - if (message != fixedmessage) + if (message != fixedmessage) { MEM_freeN(message); + } message = NULL; /* retval doesn't include \0 terminator */ len = retval + 1; } - else + else { break; + } } if (message) { BLI_dynstr_append(ds, message); - if (message != fixedmessage) + if (message != fixedmessage) { MEM_freeN(message); + } } } diff --git a/source/blender/blenlib/intern/BLI_filelist.c b/source/blender/blenlib/intern/BLI_filelist.c index 8cbba2103d3..243c7d95da1 100644 --- a/source/blender/blenlib/intern/BLI_filelist.c +++ b/source/blender/blenlib/intern/BLI_filelist.c @@ -65,28 +65,36 @@ static int bli_compare(struct direntry *entry1, struct direntry *entry2) /* directories come before non-directories */ if (S_ISDIR(entry1->type)) { - if (S_ISDIR(entry2->type) == 0) return (-1); + if (S_ISDIR(entry2->type) == 0) { + return -1; + } } else { - if (S_ISDIR(entry2->type)) return (1); + if (S_ISDIR(entry2->type)) { + return 1; + } } /* non-regular files come after regular files */ if (S_ISREG(entry1->type)) { - if (S_ISREG(entry2->type) == 0) return (-1); + if (S_ISREG(entry2->type) == 0) { + return -1; + } } else { - if (S_ISREG(entry2->type)) return (1); + if (S_ISREG(entry2->type)) { + return 1; + } } /* arbitrary, but consistent, ordering of different types of non-regular files */ - if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); - if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); + if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) { return -1; } + if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) { return 1; } /* OK, now we know their S_IFMT fields are the same, go on to a name comparison */ /* make sure "." and ".." are always first */ - if (FILENAME_IS_CURRENT(entry1->relname)) return (-1); - if (FILENAME_IS_CURRENT(entry2->relname)) return (1); - if (FILENAME_IS_PARENT(entry1->relname)) return (-1); - if (FILENAME_IS_PARENT(entry2->relname)) return (1); + if (FILENAME_IS_CURRENT(entry1->relname)) { return -1; } + if (FILENAME_IS_CURRENT(entry2->relname)) { return 1; } + if (FILENAME_IS_PARENT(entry1->relname)) { return -1; } + if (FILENAME_IS_PARENT(entry2->relname)) { return 1; } return (BLI_natstrcmp(entry1->relname, entry2->relname)); } @@ -159,8 +167,9 @@ static void bli_builddir(struct BuildDirCtx *dir_ctx, const char *dirname) } } - if (dir_ctx->files == NULL) + if (dir_ctx->files == NULL) { dir_ctx->files = (struct direntry *)MEM_mallocN(newnum * sizeof(struct direntry), __func__); + } if (dir_ctx->files) { struct dirlink * dlink = (struct dirlink *) dirbase.first; @@ -253,7 +262,9 @@ void BLI_filelist_entry_size_to_string( if (size > 1024.0) { const char **u; - for (u = compact ? units_compact : units, size /= 1024.0; size > 1024.0 && *(u + 1); u++, size /= 1024.0); + for (u = compact ? units_compact : units, size /= 1024.0; size > 1024.0 && *(u + 1); u++, size /= 1024.0) { + /* pass */ + } fmt = size > 100.0 ? "%.0f %s" : (size > 10.0 ? "%.1f %s" : "%.2f %s"); unit = *u; } @@ -284,18 +295,30 @@ void BLI_filelist_entry_mode_to_string( BLI_strncpy(r_mode2, types[(mode & 0070) >> 3], sizeof(*r_mode2) * FILELIST_DIRENTRY_MODE_LEN); BLI_strncpy(r_mode3, types[(mode & 0007)], sizeof(*r_mode3) * FILELIST_DIRENTRY_MODE_LEN); - if (((mode & S_ISGID) == S_ISGID) && (r_mode2[2] == '-')) r_mode2[2] = 'l'; + if (((mode & S_ISGID) == S_ISGID) && (r_mode2[2] == '-')) { + r_mode2[2] = 'l'; + } if (mode & (S_ISUID | S_ISGID)) { - if (r_mode1[2] == 'x') r_mode1[2] = 's'; - else r_mode1[2] = 'S'; + if (r_mode1[2] == 'x') { + r_mode1[2] = 's'; + } + else { + r_mode1[2] = 'S'; + } - if (r_mode2[2] == 'x') r_mode2[2] = 's'; + if (r_mode2[2] == 'x') { + r_mode2[2] = 's'; + } } if (mode & S_ISVTX) { - if (r_mode3[2] == 'x') r_mode3[2] = 't'; - else r_mode3[2] = 'T'; + if (r_mode3[2] == 'x') { + r_mode3[2] = 't'; + } + else { + r_mode3[2] = 'T'; + } } #endif } diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index fc432c8c8b7..af3a7a4f68a 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -241,7 +241,9 @@ static void ghash_buckets_resize(GHash *gh, const uint nbuckets) const unsigned bucket_index = ghash_bucket_index(gh, i); BLI_assert(!buckets_old[i] || (bucket_index == ghash_bucket_index(gh, ghash_entryhash(gh, buckets_old[i])))); Entry *e; - for (e = buckets_old[i]; e && e->next; e = e->next); + for (e = buckets_old[i]; e && e->next; e = e->next) { + /* pass */ + } if (e) { e->next = buckets_new[bucket_index]; buckets_new[bucket_index] = buckets_old[i]; @@ -983,8 +985,9 @@ void BLI_ghash_clear_ex( GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp, const uint nentries_reserve) { - if (keyfreefp || valfreefp) + if (keyfreefp || valfreefp) { ghash_free_cb(gh, keyfreefp, valfreefp); + } ghash_buckets_reset(gh, nentries_reserve); BLI_mempool_clear_ex(gh->entrypool, nentries_reserve ? (int)nentries_reserve : -1); @@ -1008,8 +1011,9 @@ void BLI_ghash_clear(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfree void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp) { BLI_assert((int)gh->nentries == BLI_mempool_len(gh->entrypool)); - if (keyfreefp || valfreefp) + if (keyfreefp || valfreefp) { ghash_free_cb(gh, keyfreefp, valfreefp); + } MEM_freeN(gh->buckets); BLI_mempool_destroy(gh->entrypool); @@ -1069,8 +1073,9 @@ void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh) if (gh->nentries) { do { ghi->curBucket++; - if (UNLIKELY(ghi->curBucket == ghi->gh->nbuckets)) + if (UNLIKELY(ghi->curBucket == ghi->gh->nbuckets)) { break; + } ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; } while (!ghi->curEntry); } @@ -1087,8 +1092,9 @@ void BLI_ghashIterator_step(GHashIterator *ghi) ghi->curEntry = ghi->curEntry->next; while (!ghi->curEntry) { ghi->curBucket++; - if (ghi->curBucket == ghi->gh->nbuckets) + if (ghi->curBucket == ghi->gh->nbuckets) { break; + } ghi->curEntry = ghi->gh->buckets[ghi->curBucket]; } } diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 7199c4126d4..7887c55a907 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -272,24 +272,30 @@ static int bvh_partition(BVHNode **a, int lo, int hi, BVHNode *x, int axis) static BVHNode *bvh_medianof3(BVHNode **a, int lo, int mid, int hi, int axis) { if ((a[mid])->bv[axis] < (a[lo])->bv[axis]) { - if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) + if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) { return a[mid]; + } else { - if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) + if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { return a[hi]; - else + } + else { return a[lo]; + } } } else { if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) { - if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) + if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { return a[lo]; - else + } + else { return a[hi]; + } } - else + else { return a[mid]; + } } } @@ -320,10 +326,12 @@ static void build_skip_links(BVHTree *tree, BVHNode *node, BVHNode *left, BVHNod node->skip[1] = right; for (i = 0; i < node->totnode; i++) { - if (i + 1 < node->totnode) + if (i + 1 < node->totnode) { build_skip_links(tree, node->children[i], left, node->children[i + 1]); - else + } + else { build_skip_links(tree, node->children[i], left, right); + } left = node->children[i]; } @@ -349,10 +357,12 @@ static void create_kdop_hull(const BVHTree *tree, BVHNode *node, const float *co /* for all Axes. */ for (axis_iter = tree->start_axis; axis_iter < tree->stop_axis; axis_iter++) { newminmax = dot_v3v3(&co[k * 3], bvhtree_kdop_axes[axis_iter]); - if (newminmax < bv[2 * axis_iter]) + if (newminmax < bv[2 * axis_iter]) { bv[2 * axis_iter] = newminmax; - if (newminmax > bv[(2 * axis_iter) + 1]) + } + if (newminmax > bv[(2 * axis_iter) + 1]) { bv[(2 * axis_iter) + 1] = newminmax; + } } } } @@ -375,12 +385,14 @@ static void refit_kdop_hull(const BVHTree *tree, BVHNode *node, int start, int e /* for all Axes. */ for (axis_iter = tree->start_axis; axis_iter < tree->stop_axis; axis_iter++) { newmin = node_bv[(2 * axis_iter)]; - if ((newmin < bv[(2 * axis_iter)])) + if ((newmin < bv[(2 * axis_iter)])) { bv[(2 * axis_iter)] = newmin; + } newmax = node_bv[(2 * axis_iter) + 1]; - if ((newmax > bv[(2 * axis_iter) + 1])) + if ((newmax > bv[(2 * axis_iter) + 1])) { bv[(2 * axis_iter) + 1] = newmax; + } } } @@ -397,16 +409,20 @@ static char get_largest_axis(const float *bv) middle_point[1] = (bv[3]) - (bv[2]); /* y axis */ middle_point[2] = (bv[5]) - (bv[4]); /* z axis */ if (middle_point[0] > middle_point[1]) { - if (middle_point[0] > middle_point[2]) + if (middle_point[0] > middle_point[2]) { return 1; /* max x axis */ - else + } + else { return 5; /* max z axis */ + } } else { - if (middle_point[1] > middle_point[2]) + if (middle_point[1] > middle_point[2]) { return 3; /* max y axis */ - else + } + else { return 5; /* max z axis */ + } } } @@ -424,16 +440,19 @@ static void node_join(BVHTree *tree, BVHNode *node) if (node->children[i]) { for (axis_iter = tree->start_axis; axis_iter < tree->stop_axis; axis_iter++) { /* update minimum */ - if (node->children[i]->bv[(2 * axis_iter)] < node->bv[(2 * axis_iter)]) + if (node->children[i]->bv[(2 * axis_iter)] < node->bv[(2 * axis_iter)]) { node->bv[(2 * axis_iter)] = node->children[i]->bv[(2 * axis_iter)]; + } /* update maximum */ - if (node->children[i]->bv[(2 * axis_iter) + 1] > node->bv[(2 * axis_iter) + 1]) + if (node->children[i]->bv[(2 * axis_iter) + 1] > node->bv[(2 * axis_iter) + 1]) { node->bv[(2 * axis_iter) + 1] = node->children[i]->bv[(2 * axis_iter) + 1]; + } } } - else + else { break; + } } } @@ -448,7 +467,9 @@ static void bvhtree_print_tree(BVHTree *tree, BVHNode *node, int depth) int i; axis_t axis_iter; - for (i = 0; i < depth; i++) printf(" "); + for (i = 0; i < depth; i++) { + printf(" "); + } printf(" - %d (%ld): ", node->index, (long int)(node - tree->nodearray)); for (axis_iter = (axis_t)(2 * tree->start_axis); axis_iter < (axis_t)(2 * tree->stop_axis); @@ -458,9 +479,11 @@ static void bvhtree_print_tree(BVHTree *tree, BVHNode *node, int depth) } printf("\n"); - for (i = 0; i < tree->tree_type; i++) - if (node->children[i]) + for (i = 0; i < tree->tree_type; i++) { + if (node->children[i]) { bvhtree_print_tree(tree, node->children[i], depth + 1); + } + } } static void bvhtree_info(BVHTree *tree) @@ -498,8 +521,9 @@ static void bvhtree_verify(BVHTree *tree) } else { for (j = 0; j < tree->tree_type; j++) { - if (tree->nodes[i]->parent->children[j] == tree->nodes[i]) + if (tree->nodes[i]->parent->children[j] == tree->nodes[i]) { check = 1; + } } if (!check) { printf("Parent child relationship doesn't match: %d\n", i); @@ -515,8 +539,9 @@ static void bvhtree_verify(BVHTree *tree) } else { for (j = 0; j < tree->tree_type; j++) { - if (tree->nodearray[i].parent->children[j] == &tree->nodearray[i]) + if (tree->nodearray[i].parent->children[j] == &tree->nodearray[i]) { check = 1; + } } if (!check) { printf("Parent child relationship doesn't match: %d\n", i); @@ -580,12 +605,15 @@ static void build_implicit_tree_helper(const BVHTree *tree, BVHBuildHelper *data static int implicit_leafs_index(const BVHBuildHelper *data, const int depth, const int child_index) { int min_leaf_index = child_index * data->leafs_per_child[depth - 1]; - if (min_leaf_index <= data->remain_leafs) + if (min_leaf_index <= data->remain_leafs) { return min_leaf_index; - else if (data->leafs_per_child[depth]) + } + else if (data->leafs_per_child[depth]) { return data->totleafs - (data->branches_on_level[depth - 1] - child_index) * data->leafs_per_child[depth]; - else + } + else { return data->remain_leafs; + } } /** @@ -636,8 +664,9 @@ static void split_leafs(BVHNode **leafs_array, const int nth[], const int partit { int i; for (i = 0; i < partitions - 1; i++) { - if (nth[i] >= nth[partitions]) + if (nth[i] >= nth[partitions]) { break; + } partition_nth_element(leafs_array, nth[i], nth[partitions], nth[i + 1], split_axis); } @@ -970,15 +999,17 @@ bool BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const axis_t axis_iter; /* check if index exists */ - if (index > tree->totleaf) + if (index > tree->totleaf) { return false; + } node = tree->nodearray + index; create_kdop_hull(tree, node, co, numpoints, 0); - if (co_moving) + if (co_moving) { create_kdop_hull(tree, node, co_moving, numpoints, 1); + } /* inflate the bv with some epsilon */ for (axis_iter = tree->start_axis; axis_iter < tree->stop_axis; axis_iter++) { @@ -999,8 +1030,9 @@ void BLI_bvhtree_update_tree(BVHTree *tree) BVHNode **root = tree->nodes + tree->totleaf; BVHNode **index = tree->nodes + tree->totleaf + tree->totbranch - 1; - for (; index >= root; index--) + for (; index >= root; index--) { node_join(tree, *index); + } } /** * Number of times #BLI_bvhtree_insert has been called. @@ -1225,8 +1257,9 @@ BVHTreeOverlap *BLI_bvhtree_overlap( bvhtree_overlap_task_cb, &settings); - for (j = 0; j < thread_num; j++) + for (j = 0; j < thread_num; j++) { total += BLI_stack_count(data[j].overlap); + } to = overlap = MEM_mallocN(sizeof(BVHTreeOverlap) * total, "BVHTreeOverlap"); @@ -1258,10 +1291,12 @@ static float calc_nearest_point_squared(const float proj[3], BVHNode *node, floa /* nearest on AABB hull */ for (i = 0; i != 3; i++, bv += 2) { float val = proj[i]; - if (bv[0] > val) + if (bv[0] > val) { val = bv[0]; - if (bv[1] < val) + } + if (bv[1] < val) { val = bv[1]; + } nearest[i] = val; } @@ -1272,8 +1307,9 @@ static float calc_nearest_point_squared(const float proj[3], BVHNode *node, floa static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) { if (node->totnode == 0) { - if (data->callback) + if (data->callback) { data->callback(data->userdata, node->index, data->co, &data->nearest); + } else { data->nearest.index = node->index; data->nearest.dist_sq = calc_nearest_point_squared(data->proj, node, data->nearest.co); @@ -1287,15 +1323,17 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) if (data->proj[node->main_axis] <= node->children[0]->bv[node->main_axis * 2 + 1]) { for (i = 0; i != node->totnode; i++) { - if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >= data->nearest.dist_sq) + if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >= data->nearest.dist_sq) { continue; + } dfs_find_nearest_dfs(data, node->children[i]); } } else { for (i = node->totnode - 1; i >= 0; i--) { - if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >= data->nearest.dist_sq) + if (calc_nearest_point_squared(data->proj, node->children[i], nearest) >= data->nearest.dist_sq) { continue; + } dfs_find_nearest_dfs(data, node->children[i]); } } @@ -1316,8 +1354,9 @@ static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node) static void heap_find_nearest_inner(BVHNearestData *data, HeapSimple *heap, BVHNode *node) { if (node->totnode == 0) { - if (data->callback) + if (data->callback) { data->callback(data->userdata, node->index, data->co, &data->nearest); + } else { data->nearest.index = node->index; data->nearest.dist_sq = calc_nearest_point_squared(data->proj, node, data->nearest.co); @@ -1441,15 +1480,25 @@ static float ray_nearest_hit(const BVHRayCastData *data, const float bv[6]) float lu = (bv[1] + data->ray.radius - data->ray.origin[i]) / data->ray_dot_axis[i]; if (data->ray_dot_axis[i] > 0.0f) { - if (ll > low) low = ll; - if (lu < upper) upper = lu; + if (ll > low) { + low = ll; + } + if (lu < upper) { + upper = lu; + } } else { - if (lu > low) low = lu; - if (ll < upper) upper = ll; + if (lu > low) { + low = lu; + } + if (ll < upper) { + upper = ll; + } } - if (low > upper) return FLT_MAX; + if (low > upper) { + return FLT_MAX; + } } } return low; @@ -1622,8 +1671,9 @@ int BLI_bvhtree_ray_cast_ex( } - if (hit) + if (hit) { memcpy(hit, &data.hit, sizeof(*hit)); + } return data.hit.index; } @@ -1750,8 +1800,9 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node) data->hits++; data->callback(data->userdata, node->children[i]->index, data->center, dist_sq); } - else + else { dfs_range_query(data, node->children[i]); + } } } } @@ -1781,8 +1832,9 @@ int BLI_bvhtree_range_query( data.hits++; data.callback(data.userdata, root->index, co, dist_sq); } - else + else { dfs_range_query(&data, root); + } } } diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index 46499279659..3f99f65703f 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -41,8 +41,9 @@ int BLI_linklist_count(const LinkNode *list) { int len; - for (len = 0; list; list = list->next) + for (len = 0; list; list = list->next) { len++; + } return len; } @@ -51,9 +52,11 @@ int BLI_linklist_index(const LinkNode *list, void *ptr) { int index; - for (index = 0; list; list = list->next, index++) - if (list->link == ptr) + for (index = 0; list; list = list->next, index++) { + if (list->link == ptr) { return index; + } + } return -1; } @@ -62,9 +65,11 @@ LinkNode *BLI_linklist_find(LinkNode *list, int index) { int i; - for (i = 0; list; list = list->next, i++) - if (i == index) + for (i = 0; list; list = list->next, i++) { + if (i == index) { return list; + } + } return NULL; } @@ -268,8 +273,9 @@ void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) while (list) { LinkNode *next = list->next; - if (freefunc) + if (freefunc) { freefunc(list->link); + } MEM_freeN(list); list = next; @@ -281,8 +287,9 @@ void BLI_linklist_free_pool(LinkNode *list, LinkNodeFreeFP freefunc, struct BLI_ while (list) { LinkNode *next = list->next; - if (freefunc) + if (freefunc) { freefunc(list->link); + } BLI_mempool_free(mempool, list); list = next; @@ -303,8 +310,9 @@ void BLI_linklist_freeN(LinkNode *list) void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata) { - for (; list; list = list->next) + for (; list; list = list->next) { applyfunc(list->link, userdata); + } } /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenlib/intern/BLI_timer.c b/source/blender/blenlib/intern/BLI_timer.c index d361a1c563d..5fcdd85ba69 100644 --- a/source/blender/blenlib/intern/BLI_timer.c +++ b/source/blender/blenlib/intern/BLI_timer.c @@ -112,8 +112,12 @@ static void execute_functions_if_necessary(void) double current_time = GET_TIME(); LISTBASE_FOREACH(TimedFunction *, timed_func, &GlobalTimer.funcs) { - if (timed_func->tag_removal) continue; - if (timed_func->next_time > current_time) continue; + if (timed_func->tag_removal) { + continue; + } + if (timed_func->next_time > current_time) { + continue; + } double ret = timed_func->func(timed_func->uuid, timed_func->user_data); diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c index e74b1016bb1..46818c5a1b9 100644 --- a/source/blender/blenlib/intern/DLRB_tree.c +++ b/source/blender/blenlib/intern/DLRB_tree.c @@ -40,8 +40,9 @@ DLRBT_Tree *BLI_dlrbTree_new(void) /* Just zero out the pointers used */ void BLI_dlrbTree_init(DLRBT_Tree *tree) { - if (tree == NULL) + if (tree == NULL) { return; + } tree->first = tree->last = tree->root = NULL; } @@ -50,8 +51,9 @@ void BLI_dlrbTree_init(DLRBT_Tree *tree) static void recursive_tree_free_nodes(DLRBT_Node *node) { /* sanity check */ - if (node == NULL) + if (node == NULL) { return; + } /* free child nodes + subtrees */ recursive_tree_free_nodes(node->left); @@ -64,8 +66,9 @@ static void recursive_tree_free_nodes(DLRBT_Node *node) /* Free the given tree's data but not the tree itself */ void BLI_dlrbTree_free(DLRBT_Tree *tree) { - if (tree == NULL) + if (tree == NULL) { return; + } /* if the list-base stuff is set, just use that (and assume its set), * otherwise, we'll need to traverse the tree... @@ -89,8 +92,9 @@ void BLI_dlrbTree_free(DLRBT_Tree *tree) static void linkedlist_sync_add_node(DLRBT_Tree *tree, DLRBT_Node *node) { /* sanity checks */ - if ((tree == NULL) || (node == NULL)) + if ((tree == NULL) || (node == NULL)) { return; + } /* add left-node (and its subtree) */ linkedlist_sync_add_node(tree, node->left); @@ -110,8 +114,9 @@ static void linkedlist_sync_add_node(DLRBT_Tree *tree, DLRBT_Node *node) void BLI_dlrbTree_linkedlist_sync(DLRBT_Tree *tree) { /* sanity checks */ - if (tree == NULL) + if (tree == NULL) { return; + } /* clear list-base pointers so that the new list can be added properly */ tree->first = tree->last = NULL; @@ -131,8 +136,9 @@ DLRBT_Node *BLI_dlrbTree_search(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, vo /* check that there is a comparator to use */ /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ - if (cmp_cb == NULL) + if (cmp_cb == NULL) { return NULL; + } /* iteratively perform this search */ while (node && found == 0) { @@ -141,17 +147,21 @@ DLRBT_Node *BLI_dlrbTree_search(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, vo */ switch (cmp_cb(node, search_data)) { case -1: /* data less than node */ - if (node->left) + if (node->left) { node = node->left; - else + } + else { found = 1; + } break; case 1: /* data greater than node */ - if (node->right) + if (node->right) { node = node->right; - else + } + else { found = 1; + } break; default: /* data equals node */ @@ -172,8 +182,9 @@ DLRBT_Node *BLI_dlrbTree_search_exact(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_ /* check that there is a comparator to use */ /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ - if (cmp_cb == NULL) + if (cmp_cb == NULL) { return NULL; + } /* iteratively perform this search */ while (node && found == 0) { @@ -182,17 +193,21 @@ DLRBT_Node *BLI_dlrbTree_search_exact(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_ */ switch (cmp_cb(node, search_data)) { case -1: /* data less than node */ - if (node->left) + if (node->left) { node = node->left; - else + } + else { found = -1; + } break; case 1: /* data greater than node */ - if (node->right) + if (node->right) { node = node->right; - else + } + else { found = -1; + } break; default: /* data equals node */ @@ -212,16 +227,18 @@ DLRBT_Node *BLI_dlrbTree_search_prev(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_c /* check that there is a comparator to use */ /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ - if (cmp_cb == NULL) + if (cmp_cb == NULL) { return NULL; + } /* get the node which best matches this description */ node = BLI_dlrbTree_search(tree, cmp_cb, search_data); if (node) { /* if the item we're searching for is greater than the node found, we've found the match */ - if (cmp_cb(node, search_data) > 0) + if (cmp_cb(node, search_data) > 0) { return node; + } /* return the previous node otherwise */ /* NOTE: what happens if there is no previous node? */ @@ -239,16 +256,18 @@ DLRBT_Node *BLI_dlrbTree_search_next(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_c /* check that there is a comparator to use */ /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ - if (cmp_cb == NULL) + if (cmp_cb == NULL) { return NULL; + } /* get the node which best matches this description */ node = BLI_dlrbTree_search(tree, cmp_cb, search_data); if (node) { /* if the item we're searching for is less than the node found, we've found the match */ - if (cmp_cb(node, search_data) < 0) + if (cmp_cb(node, search_data) < 0) { return node; + } /* return the previous node otherwise */ /* NOTE: what happens if there is no previous node? */ @@ -273,20 +292,24 @@ short BLI_dlrbTree_contains(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void * /* get the 'grandparent' - the parent of the parent - of the given node */ static DLRBT_Node *get_grandparent(DLRBT_Node *node) { - if (node && node->parent) + if (node && node->parent) { return node->parent->parent; - else + } + else { return NULL; + } } /* get the sibling node (e.g. if node is left child of parent, return right child of parent) */ static DLRBT_Node *get_sibling(DLRBT_Node *node) { if (node && node->parent) { - if (node == node->parent->left) + if (node == node->parent->left) { return node->parent->right; - else + } + else { return node->parent->left; + } } /* sibling not found */ @@ -296,9 +319,10 @@ static DLRBT_Node *get_sibling(DLRBT_Node *node) /* get the 'uncle' - the sibling of the parent - of the given node */ static DLRBT_Node *get_uncle(DLRBT_Node *node) { - if (node) + if (node) { /* return the child of the grandparent which isn't the node's parent */ return get_sibling(node->parent); + } /* uncle not found */ return NULL; @@ -314,31 +338,38 @@ static void rotate_left(DLRBT_Tree *tree, DLRBT_Node *root) /* pivot is simply the root's right child, to become the root's parent */ pivot = root->right; - if (pivot == NULL) + if (pivot == NULL) { return; + } if (root->parent) { - if (root == root->parent->left) + if (root == root->parent->left) { root_slot = &root->parent->left; - else + } + else { root_slot = &root->parent->right; + } } - else + else { root_slot = ((DLRBT_Node **)&tree->root); /* &((DLRBT_Node *)tree->root); */ + } /* - pivot's left child becomes root's right child * - root now becomes pivot's left child */ root->right = pivot->left; - if (pivot->left) pivot->left->parent = root; + if (pivot->left) { + pivot->left->parent = root; + } pivot->left = root; pivot->parent = root->parent; root->parent = pivot; /* make the pivot the new root */ - if (root_slot) + if (root_slot) { *root_slot = pivot; + } } /* make the left child of the 'root' the new root */ @@ -348,31 +379,38 @@ static void rotate_right(DLRBT_Tree *tree, DLRBT_Node *root) /* pivot is simply the root's left child, to become the root's parent */ pivot = root->left; - if (pivot == NULL) + if (pivot == NULL) { return; + } if (root->parent) { - if (root == root->parent->left) + if (root == root->parent->left) { root_slot = &root->parent->left; - else + } + else { root_slot = &root->parent->right; + } } - else + else { root_slot = ((DLRBT_Node **)&tree->root); /* &((DLRBT_Node *)tree->root); */ + } /* - pivot's right child becomes root's left child * - root now becomes pivot's right child */ root->left = pivot->right; - if (pivot->right) pivot->right->parent = root; + if (pivot->right) { + pivot->right->parent = root; + } pivot->right = root; pivot->parent = root->parent; root->parent = pivot; /* make the pivot the new root */ - if (root_slot) + if (root_slot) { *root_slot = pivot; + } } /* *********************************************** */ @@ -390,10 +428,12 @@ static void insert_check_1(DLRBT_Tree *tree, DLRBT_Node *node) { if (node) { /* if this is the root, just ensure that it is black */ - if (node->parent == NULL) + if (node->parent == NULL) { node->tree_col = DLRBT_BLACK; - else + } + else { insert_check_2(tree, node); + } } } @@ -468,10 +508,12 @@ static void insert_check_3(DLRBT_Tree *tree, DLRBT_Node *node) /* if there are several nodes that all form a left chain, do a right rotation to correct * this (or a rotation in the opposite direction if they all form a right chain) */ - if ((node == node->parent->left) && (node->parent == gp->left)) + if ((node == node->parent->left) && (node->parent == gp->left)) { rotate_right(tree, gp); - else //if ((node == node->parent->right) && (node->parent == gp->right)) + } + else { //if ((node == node->parent->right) && (node->parent == gp->right)) rotate_left(tree, gp); + } } } } @@ -484,8 +526,9 @@ static void insert_check_3(DLRBT_Tree *tree, DLRBT_Node *node) void BLI_dlrbTree_insert(DLRBT_Tree *tree, DLRBT_Node *node) { /* sanity checks */ - if ((tree == NULL) || (node == NULL)) + if ((tree == NULL) || (node == NULL)) { return; + } /* firstly, the node we just added should be red by default */ node->tree_col = DLRBT_RED; @@ -506,15 +549,18 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, short new_node = 0; /* sanity checks */ - if (tree == NULL) + if (tree == NULL) { return NULL; + } /* TODO: if no comparator is supplied, try using the one supplied with the tree... */ - if (cmp_cb == NULL) + if (cmp_cb == NULL) { return NULL; + } /* TODO: if no allocator is supplied, try using the one supplied with the tree... */ - if (new_cb == NULL) + if (new_cb == NULL) { return NULL; + } /* TODO: if no updater is supplied, try using the one supplied with the tree... */ /* try to find the nearest node to this one */ @@ -548,8 +594,9 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, } default: /* update the duplicate node as appropriate */ { - if (update_cb) + if (update_cb) { update_cb(parNode, data); + } break; } } diff --git a/source/blender/blenlib/intern/boxpack_2d.c b/source/blender/blenlib/intern/boxpack_2d.c index 357fa57b144..c90038b78a1 100644 --- a/source/blender/blenlib/intern/boxpack_2d.c +++ b/source/blender/blenlib/intern/boxpack_2d.c @@ -214,8 +214,8 @@ static int box_areasort(const void *p1, const void *p2) const float a1 = box_area(b1); const float a2 = box_area(b2); - if (a1 < a2) return 1; - else if (a1 > a2) return -1; + if (a1 < a2) { return 1; } + else if (a1 > a2) { return -1; } return 0; } @@ -240,9 +240,9 @@ static int vertex_sort(const void *p1, const void *p2, void *vs_ctx_p) #ifdef USE_FREE_STRIP /* push free verts to the end so we can strip */ - if (UNLIKELY(v1->free == 0 && v2->free == 0)) return 0; - else if (UNLIKELY(v1->free == 0)) return 1; - else if (UNLIKELY(v2->free == 0)) return -1; + if (UNLIKELY(v1->free == 0 && v2->free == 0)) { return 0; } + else if (UNLIKELY(v1->free == 0)) { return 1; } + else if (UNLIKELY(v2->free == 0)) { return -1; } #endif a1 = max_ff(v1->x + vs_ctx->box_width, v1->y + vs_ctx->box_height); @@ -254,8 +254,8 @@ static int vertex_sort(const void *p1, const void *p2, void *vs_ctx_p) #endif /* sort largest to smallest */ - if (a1 > a2) return 1; - else if (a1 < a2) return -1; + if (a1 > a2) { return 1; } + else if (a1 < a2) { return -1; } return 0; } /** \} */ @@ -365,8 +365,9 @@ void BLI_box_pack_2d(BoxPack *boxarray, const uint len, float *r_tot_x, float *r #endif } - for (i = 0; i < 3; i++) + for (i = 0; i < 3; i++) { vertex_pack_indices[i] = box->v[i + 1]->index; + } verts_pack_len = 3; box++; /* next box, needed for the loop below */ /* ...done packing the first box */ diff --git a/source/blender/blenlib/intern/convexhull_2d.c b/source/blender/blenlib/intern/convexhull_2d.c index a59d44037f1..87471ea65a5 100644 --- a/source/blender/blenlib/intern/convexhull_2d.c +++ b/source/blender/blenlib/intern/convexhull_2d.c @@ -83,8 +83,10 @@ int BLI_convexhull_2d_sorted(const float (*points)[2], const int n, int r_points minmax = i - 1; if (minmax == n - 1) { /* degenerate case: all x-coords == xmin */ r_points[++top] = minmin; - if (points[minmax][1] != points[minmin][1]) /* a nontrivial segment */ + if (points[minmax][1] != points[minmin][1]) { + /* a nontrivial segment */ r_points[++top] = minmax; + } r_points[++top] = minmin; /* add polygon endpoint */ return top + 1; } @@ -168,13 +170,13 @@ static int pointref_cmp_yx(const void *a_, const void *b_) const struct PointRef *a = a_; const struct PointRef *b = b_; - if (a->pt[1] > b->pt[1]) return 1; - else if (a->pt[1] < b->pt[1]) return -1; + if (a->pt[1] > b->pt[1]) { return 1; } + else if (a->pt[1] < b->pt[1]) { return -1; } - if (a->pt[0] > b->pt[0]) return 1; - else if (a->pt[0] < b->pt[0]) return -1; + if (a->pt[0] > b->pt[0]) { return 1; } + else if (a->pt[0] < b->pt[0]) { return -1; } - else return 0; + else { return 0; } } /** diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c index b172ae7a518..31f8d9d3d57 100644 --- a/source/blender/blenlib/intern/dynlib.c +++ b/source/blender/blenlib/intern/dynlib.c @@ -51,8 +51,9 @@ DynamicLibrary *BLI_dynlib_open(const char *name) handle = LoadLibraryW(name_16); UTF16_UN_ENCODE(name); - if (!handle) + if (!handle) { return NULL; + } lib = MEM_callocN(sizeof(*lib), "Dynamic Library"); lib->handle = handle; @@ -71,8 +72,9 @@ char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib) /* if lib is NULL reset the last error code */ err = GetLastError(); - if (!lib) + if (!lib) { SetLastError(ERROR_SUCCESS); + } if (err) { static char buf[1024]; @@ -103,8 +105,9 @@ DynamicLibrary *BLI_dynlib_open(const char *name) DynamicLibrary *lib; void *handle = dlopen(name, RTLD_LAZY); - if (!handle) + if (!handle) { return NULL; + } lib = MEM_callocN(sizeof(*lib), "Dynamic Library"); lib->handle = handle; diff --git a/source/blender/blenlib/intern/easing.c b/source/blender/blenlib/intern/easing.c index b1df6e4c58e..99077eddc4e 100644 --- a/source/blender/blenlib/intern/easing.c +++ b/source/blender/blenlib/intern/easing.c @@ -91,10 +91,12 @@ float BLI_easing_bounce_ease_in(float time, float begin, float change, float dur float BLI_easing_bounce_ease_in_out(float time, float begin, float change, float duration) { - if (time < duration / 2) + if (time < duration / 2) { return BLI_easing_bounce_ease_in(time * 2, 0, change, duration) * 0.5f + begin; - else + } + else { return BLI_easing_bounce_ease_out(time * 2 - duration, 0, change, duration) * 0.5f + change * 0.5f + begin; + } } float BLI_easing_circ_ease_in(float time, float begin, float change, float duration) @@ -111,8 +113,9 @@ float BLI_easing_circ_ease_out(float time, float begin, float change, float dura float BLI_easing_circ_ease_in_out(float time, float begin, float change, float duration) { - if ((time /= duration / 2) < 1.0f) + if ((time /= duration / 2) < 1.0f) { return -change / 2 * (sqrtf(1 - time * time) - 1) + begin; + } time -= 2.0f; return change / 2 * (sqrtf(1 - time * time) + 1) + begin; } @@ -131,8 +134,9 @@ float BLI_easing_cubic_ease_out(float time, float begin, float change, float dur float BLI_easing_cubic_ease_in_out(float time, float begin, float change, float duration) { - if ((time /= duration / 2) < 1.0f) + if ((time /= duration / 2) < 1.0f) { return change / 2 * time * time * time + begin; + } time -= 2.0f; return change / 2 * (time * time * time + 2) + begin; } @@ -170,14 +174,17 @@ float BLI_easing_elastic_ease_in(float time, float begin, float change, float du float s; float f = 1.0f; - if (time == 0.0f) + if (time == 0.0f) { return begin; + } - if ((time /= duration) == 1.0f) + if ((time /= duration) == 1.0f) { return begin + change; + } time -= 1.0f; - if (!period) + if (!period) { period = duration * 0.3f; + } if (!amplitude || amplitude < fabsf(change)) { s = period / 4; #ifdef USE_ELASTIC_BLEND @@ -185,8 +192,9 @@ float BLI_easing_elastic_ease_in(float time, float begin, float change, float du #endif amplitude = change; } - else + else { s = period / (2 * (float)M_PI) * asinf(change / amplitude); + } return (-f * (amplitude * powf(2, 10 * time) * sinf((time * duration - s) * (2 * (float)M_PI) / period))) + begin; } @@ -196,13 +204,16 @@ float BLI_easing_elastic_ease_out(float time, float begin, float change, float d float s; float f = 1.0f; - if (time == 0.0f) + if (time == 0.0f) { return begin; - if ((time /= duration) == 1.0f) + } + if ((time /= duration) == 1.0f) { return begin + change; + } time = -time; - if (!period) + if (!period) { period = duration * 0.3f; + } if (!amplitude || amplitude < fabsf(change)) { s = period / 4; #ifdef USE_ELASTIC_BLEND @@ -210,8 +221,9 @@ float BLI_easing_elastic_ease_out(float time, float begin, float change, float d #endif amplitude = change; } - else + else { s = period / (2 * (float)M_PI) * asinf(change / amplitude); + } return (f * (amplitude * powf(2, 10 * time) * sinf((time * duration - s) * (2 * (float)M_PI) / period))) + change + begin; } @@ -221,13 +233,16 @@ float BLI_easing_elastic_ease_in_out(float time, float begin, float change, floa float s; float f = 1.0f; - if (time == 0.0f) + if (time == 0.0f) { return begin; - if ((time /= duration / 2) == 2.0f) + } + if ((time /= duration / 2) == 2.0f) { return begin + change; + } time -= 1.0f; - if (!period) + if (!period) { period = duration * (0.3f * 1.5f); + } if (!amplitude || amplitude < fabsf(change)) { s = period / 4; #ifdef USE_ELASTIC_BLEND @@ -235,8 +250,9 @@ float BLI_easing_elastic_ease_in_out(float time, float begin, float change, floa #endif amplitude = change; } - else + else { s = period / (2 * (float)M_PI) * asinf(change / amplitude); + } if (time < 0.0f) { f *= -0.5f; @@ -301,8 +317,9 @@ float BLI_easing_quad_ease_out(float time, float begin, float change, float dura float BLI_easing_quad_ease_in_out(float time, float begin, float change, float duration) { - if ((time /= duration / 2) < 1.0f) + if ((time /= duration / 2) < 1.0f) { return change / 2 * time * time + begin; + } time -= 1.0f; return -change / 2 * (time * (time - 2) - 1) + begin; } @@ -322,8 +339,9 @@ float BLI_easing_quart_ease_out(float time, float begin, float change, float dur float BLI_easing_quart_ease_in_out(float time, float begin, float change, float duration) { - if ((time /= duration / 2) < 1.0f) + if ((time /= duration / 2) < 1.0f) { return change / 2 * time * time * time * time + begin; + } time -= 2.0f; return -change / 2 * ( time * time * time * time - 2) + begin; } @@ -340,8 +358,9 @@ float BLI_easing_quint_ease_out(float time, float begin, float change, float dur } float BLI_easing_quint_ease_in_out(float time, float begin, float change, float duration) { - if ((time /= duration / 2) < 1.0f) + if ((time /= duration / 2) < 1.0f) { return change / 2 * time * time * time * time * time + begin; + } time -= 2.0f; return change / 2 * (time * time * time * time * time + 2) + begin; } diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index f3d69bc9795..55c9a189a20 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -113,7 +113,9 @@ BLI_INLINE bool edges_equal(Edge e1, Edge e2) static uint calc_capacity_exp_for_reserve(uint reserve) { uint result = 1; - while (reserve >>= 1) result++; + while (reserve >>= 1) { + result++; + } return result; } @@ -255,7 +257,9 @@ void BLI_edgehash_print(EdgeHash *eh) } printf(" Entries:\n"); for (uint i = 0; i < ENTRIES_CAPACITY(eh); i++) { - if (i == eh->length) printf(" **** below is rest capacity ****\n"); + if (i == eh->length) { + printf(" **** below is rest capacity ****\n"); + } EdgeHashEntry entry = eh->entries[i]; printf(" %u: (%u, %u) -> %p\n", i, entry.edge.v_low, entry.edge.v_high, entry.value); @@ -374,7 +378,9 @@ bool BLI_edgehash_remove(EdgeHash *eh, uint v0, uint v1, EdgeHashFreeFP free_val { uint old_length = eh->length; void *value = BLI_edgehash_popkey(eh, v0, v1); - if (free_value && value) free_value(value); + if (free_value && value) { + free_value(value); + } return old_length > eh->length; } diff --git a/source/blender/blenlib/intern/expr_pylike_eval.c b/source/blender/blenlib/intern/expr_pylike_eval.c index cd5b43fc224..51a004f846f 100644 --- a/source/blender/blenlib/intern/expr_pylike_eval.c +++ b/source/blender/blenlib/intern/expr_pylike_eval.c @@ -554,28 +554,32 @@ static bool parse_next_token(ExprParseState *state) char *end, *out = state->tokenbuf; bool is_float = false; - while (isdigit(*state->cur)) + while (isdigit(*state->cur)) { *out++ = *state->cur++; + } if (*state->cur == '.') { is_float = true; *out++ = *state->cur++; - while (isdigit(*state->cur)) + while (isdigit(*state->cur)) { *out++ = *state->cur++; + } } if (ELEM(*state->cur, 'e', 'E')) { is_float = true; *out++ = *state->cur++; - if (ELEM(*state->cur, '+', '-')) + if (ELEM(*state->cur, '+', '-')) { *out++ = *state->cur++; + } CHECK_ERROR(isdigit(*state->cur)); - while (isdigit(*state->cur)) + while (isdigit(*state->cur)) { *out++ = *state->cur++; + } } *out = 0; @@ -611,8 +615,9 @@ static bool parse_next_token(ExprParseState *state) if (isalpha(*state->cur) || ELEM(*state->cur, '_')) { char *out = state->tokenbuf; - while (isalnum(*state->cur) || ELEM(*state->cur, '_')) + while (isalnum(*state->cur) || ELEM(*state->cur, '_')) { *out++ = *state->cur++; + } *out = 0; diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 2339025307e..afedd19b6d5 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -140,8 +140,9 @@ char *BLI_file_ungzip_to_mem(const char *from_file, int *r_size) MEM_freeN(mem); mem = NULL; } - else if (alloc_size != size) + else if (alloc_size != size) { mem = MEM_reallocN(mem, size); + } *r_size = size; @@ -249,8 +250,9 @@ void *BLI_gzopen(const char *filename, const char *mode) BLI_assert(!BLI_path_is_rel(filename)); /* xxx Creates file before transcribing the path */ - if (mode[0] == 'w') + if (mode[0] == 'w') { fclose(ufopen(filename, "a")); + } /* temporary #if until we update all libraries to 1.2.7 * for correct wide char path handling */ @@ -293,11 +295,15 @@ static bool delete_unique(const char *path, const bool dir) if (dir) { err = !RemoveDirectoryW(path_16); - if (err) printf("Unable to remove directory\n"); + if (err) { + printf("Unable to remove directory\n"); + } } else { err = !DeleteFileW(path_16); - if (err) callLocalErrorCallBack("Unable to delete file"); + if (err) { + callLocalErrorCallBack("Unable to delete file"); + } } UTF16_UN_ENCODE(path); @@ -487,11 +493,16 @@ bool BLI_dir_create_recursive(const char *dirname) int BLI_rename(const char *from, const char *to) { - if (!BLI_exists(from)) return 0; + if (!BLI_exists(from)) { + return 0; + } /* make sure the filenames are different (case insensitive) before removing */ - if (BLI_exists(to) && BLI_strcasecmp(from, to)) - if (BLI_delete(to, false, false)) return 1; + if (BLI_exists(to) && BLI_strcasecmp(from, to)) { + if (BLI_delete(to, false, false)) { + return 1; + } + } return urename(from, to); } @@ -517,10 +528,12 @@ static void join_dirfile_alloc(char **dst, size_t *alloc_len, const char *dir, c { size_t len = strlen(dir) + strlen(file) + 1; - if (*dst == NULL) + if (*dst == NULL) { *dst = MEM_mallocN(len + 1, "join_dirfile_alloc path"); - else if (*alloc_len < len) + } + else if (*alloc_len < len) { *dst = MEM_reallocN(*dst, len + 1); + } *alloc_len = len; @@ -564,21 +577,24 @@ static int recursive_operation(const char *startfrom, const char *startto, do { /* once */ /* ensure there's no trailing slash in file path */ from = strip_last_slash(startfrom); - if (startto) + if (startto) { to = strip_last_slash(startto); + } ret = lstat(from, &st); - if (ret < 0) + if (ret < 0) { /* source wasn't found, nothing to operate with */ break; + } if (!S_ISDIR(st.st_mode)) { /* source isn't a directory, can't do recursive walking for it, * so just call file callback and leave */ if (callback_file != NULL) { ret = callback_file(from, to); - if (ret != RecursiveOp_Callback_OK) + if (ret != RecursiveOp_Callback_OK) { ret = -1; + } } break; } @@ -594,11 +610,13 @@ static int recursive_operation(const char *startfrom, const char *startto, if (callback_dir_pre != NULL) { ret = callback_dir_pre(from, to); if (ret != RecursiveOp_Callback_OK) { - if (ret == RecursiveOp_Callback_StopRecurs) + if (ret == RecursiveOp_Callback_StopRecurs) { /* callback requested not to perform recursive walking, not an error */ ret = 0; - else + } + else { ret = -1; + } break; } } @@ -606,12 +624,14 @@ static int recursive_operation(const char *startfrom, const char *startto, for (i = 0; i < n; i++) { const struct dirent * const dirent = dirlist[i]; - if (FILENAME_IS_CURRPAR(dirent->d_name)) + if (FILENAME_IS_CURRPAR(dirent->d_name)) { continue; + } join_dirfile_alloc(&from_path, &from_alloc_len, from, dirent->d_name); - if (to) + if (to) { join_dirfile_alloc(&to_path, &to_alloc_len, to, dirent->d_name); + } bool is_dir; @@ -633,23 +653,26 @@ static int recursive_operation(const char *startfrom, const char *startto, } else if (callback_file != NULL) { ret = callback_file(from_path, to_path); - if (ret != RecursiveOp_Callback_OK) + if (ret != RecursiveOp_Callback_OK) { ret = -1; + } } - if (ret != 0) + if (ret != 0) { break; + } } - if (ret != 0) + if (ret != 0) { break; + } if (callback_dir_post != NULL) { ret = callback_dir_post(from, to); - if (ret != RecursiveOp_Callback_OK) + if (ret != RecursiveOp_Callback_OK) { ret = -1; + } } - } - while (false); + } while (false); if (dirlist != NULL) { for (i = 0; i < n; i++) { @@ -657,14 +680,18 @@ static int recursive_operation(const char *startfrom, const char *startto, } free(dirlist); } - if (from_path != NULL) + if (from_path != NULL) { MEM_freeN(from_path); - if (to_path != NULL) + } + if (to_path != NULL) { MEM_freeN(to_path); - if (from != NULL) + } + if (from != NULL) { MEM_freeN(from); - if (to != NULL) + } + if (to != NULL) { MEM_freeN(to); + } return ret; } @@ -748,11 +775,13 @@ static bool check_the_same(const char *path_a, const char *path_b) { struct stat st_a, st_b; - if (lstat(path_a, &st_a)) + if (lstat(path_a, &st_a)) { return false; + } - if (lstat(path_b, &st_b)) + if (lstat(path_b, &st_b)) { return false; + } return st_a.st_dev == st_b.st_dev && st_a.st_ino == st_b.st_ino; } @@ -843,7 +872,9 @@ static int copy_single_file(const char *from, const char *to) if (link_len < 0) { perror("readlink"); - if (need_free) MEM_freeN(link_buffer); + if (need_free) { + MEM_freeN(link_buffer); + } return RecursiveOp_Callback_Error; } @@ -852,12 +883,15 @@ static int copy_single_file(const char *from, const char *to) if (symlink(link_buffer, to)) { perror("symlink"); - if (need_free) MEM_freeN(link_buffer); + if (need_free) { + MEM_freeN(link_buffer); + } return RecursiveOp_Callback_Error; } - if (need_free) + if (need_free) { MEM_freeN(link_buffer); + } return RecursiveOp_Callback_OK; } @@ -872,8 +906,9 @@ static int copy_single_file(const char *from, const char *to) return RecursiveOp_Callback_Error; } - if (set_permissions(to, &st)) + if (set_permissions(to, &st)) { return RecursiveOp_Callback_Error; + } return RecursiveOp_Callback_OK; } @@ -902,8 +937,9 @@ static int copy_single_file(const char *from, const char *to) fclose(to_stream); fclose(from_stream); - if (set_permissions(to, &st)) + if (set_permissions(to, &st)) { return RecursiveOp_Callback_Error; + } return RecursiveOp_Callback_OK; } @@ -985,8 +1021,9 @@ int BLI_copy(const char *file, const char *to) ret = recursive_operation(file, actual_to, copy_callback_pre, copy_single_file, NULL); - if (actual_to != to) + if (actual_to != to) { MEM_freeN((void *)actual_to); + } return ret; } @@ -1057,8 +1094,11 @@ int BLI_rename(const char *from, const char *to) return 1; } - if (BLI_exists(to)) - if (BLI_delete(to, false, false)) return 1; + if (BLI_exists(to)) { + if (BLI_delete(to, false, false)) { + return 1; + } + } return rename(from, to); } diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index fba3c825a1c..36051e3e7f0 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -104,10 +104,13 @@ static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData * for (k = 0; k < n; k++) { l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k; - if (k == 0) l_first = l; + if (k == 0) { + l_first = l; + } - if (ftoutline.tags[l] == FT_Curve_Tag_On) + if (ftoutline.tags[l] == FT_Curve_Tag_On) { onpoints[j]++; + } { const int l_next = (k < n - 1) ? (l + 1) : l_first; @@ -140,7 +143,9 @@ static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData * /* individual curve loop, start-end */ for (k = 0; k < n; k++) { l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k; - if (k == 0) l_first = l; + if (k == 0) { + l_first = l; + } /* virtual conic on-curve points */ { @@ -291,7 +296,9 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf) 0, &face); - if (err) return NULL; + if (err) { + return NULL; + } /* allocate blender font */ vfd = MEM_callocN(sizeof(*vfd), "FTVFontData"); @@ -319,8 +326,9 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf) err = FT_Set_Charmap(face, found); - if (err) + if (err) { return NULL; + } lcode = charcode = FT_Get_First_Char(face, &glyph_index); } @@ -362,8 +370,9 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile *pf) charcode = FT_Get_Next_Char(face, charcode, &glyph_index); /* Check that we won't start infinite loop */ - if (charcode <= lcode) + if (charcode <= lcode) { break; + } lcode = charcode; } @@ -460,7 +469,9 @@ VChar *BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character) { VChar *che = NULL; - if (!vfont) return NULL; + if (!vfont) { + return NULL; + } /* Init Freetype */ err = FT_Init_FreeType(&library); diff --git a/source/blender/blenlib/intern/gsqueue.c b/source/blender/blenlib/intern/gsqueue.c index 226e6cd34d5..40890222e55 100644 --- a/source/blender/blenlib/intern/gsqueue.c +++ b/source/blender/blenlib/intern/gsqueue.c @@ -78,8 +78,9 @@ int BLI_gsqueue_len(GSQueue *gq) GSQueueElem *elem; int size = 0; - for (elem = gq->head; elem; elem = elem->next) + for (elem = gq->head; elem; elem = elem->next) { size++; + } return size; } @@ -132,8 +133,9 @@ void BLI_gsqueue_push(GSQueue *gq, const void *item) /* compare: prevent events added double in row */ if (!BLI_gsqueue_is_empty(gq)) { - if (0 == memcmp(item, gq->head->data, gq->elem_size)) + if (0 == memcmp(item, gq->head->data, gq->elem_size)) { return; + } } elem = MEM_mallocN(sizeof(*elem) + gq->elem_size, "gqueue_push"); memcpy(elem->data, item, gq->elem_size); diff --git a/source/blender/blenlib/intern/hash_md5.c b/source/blender/blenlib/intern/hash_md5.c index 895b558dc82..1a8e78d4227 100644 --- a/source/blender/blenlib/intern/hash_md5.c +++ b/source/blender/blenlib/intern/hash_md5.c @@ -316,19 +316,22 @@ int BLI_hash_md5_stream(FILE *stream, void *resblock) sum += n; } while (sum < BLOCKSIZE && n != 0); - if (n == 0 && ferror(stream)) + if (n == 0 && ferror(stream)) { return 1; + } /* RFC 1321 specifies the possible length of the file up to 2^64 bits. * Here we only compute the number of bytes. Do a double word increment. */ len[0] += sum; - if (len[0] < sum) + if (len[0] < sum) { ++len[1]; + } /* If end of file is reached, end the loop. */ - if (n == 0) + if (n == 0) { break; + } /* Process buffer with BLOCKSIZE bytes. Note that BLOCKSIZE % 64 == 0. */ md5_process_block(buffer, BLOCKSIZE, &ctx); diff --git a/source/blender/blenlib/intern/jitter_2d.c b/source/blender/blenlib/intern/jitter_2d.c index 0a1ee08776e..bbf1948be4d 100644 --- a/source/blender/blenlib/intern/jitter_2d.c +++ b/source/blender/blenlib/intern/jitter_2d.c @@ -104,17 +104,17 @@ void BLI_jitterate2(float (*jit1)[2], float (*jit2)[2], int num, float rad2) vecx = jit1[j][0] - x - 1.0f; vecy = jit1[j][1] - y - 1.0f; - if (fabsf(vecx) < rad2) dvecx += vecx * rad2; + if (fabsf(vecx) < rad2) { dvecx += vecx * rad2; } vecx += 1.0f; - if (fabsf(vecx) < rad2) dvecx += vecx * rad2; + if (fabsf(vecx) < rad2) { dvecx += vecx * rad2; } vecx += 1.0f; - if (fabsf(vecx) < rad2) dvecx += vecx * rad2; + if (fabsf(vecx) < rad2) { dvecx += vecx * rad2; } - if (fabsf(vecy) < rad2) dvecy += vecy * rad2; + if (fabsf(vecy) < rad2) { dvecy += vecy * rad2; } vecy += 1.0f; - if (fabsf(vecy) < rad2) dvecy += vecy * rad2; + if (fabsf(vecy) < rad2) { dvecy += vecy * rad2; } vecy += 1.0f; - if (fabsf(vecy) < rad2) dvecy += vecy * rad2; + if (fabsf(vecy) < rad2) { dvecy += vecy * rad2; } } } diff --git a/source/blender/blenlib/intern/lasso_2d.c b/source/blender/blenlib/intern/lasso_2d.c index 37d4d6e1d1f..a8eb9f09041 100644 --- a/source/blender/blenlib/intern/lasso_2d.c +++ b/source/blender/blenlib/intern/lasso_2d.c @@ -36,10 +36,10 @@ void BLI_lasso_boundbox(rcti *rect, const int mcords[][2], const unsigned int mo rect->ymin = rect->ymax = mcords[0][1]; for (a = 1; a < moves; a++) { - if (mcords[a][0] < rect->xmin) rect->xmin = mcords[a][0]; - else if (mcords[a][0] > rect->xmax) rect->xmax = mcords[a][0]; - if (mcords[a][1] < rect->ymin) rect->ymin = mcords[a][1]; - else if (mcords[a][1] > rect->ymax) rect->ymax = mcords[a][1]; + if (mcords[a][0] < rect->xmin) { rect->xmin = mcords[a][0]; } + else if (mcords[a][0] > rect->xmax) { rect->xmax = mcords[a][0]; } + if (mcords[a][1] < rect->ymin) { rect->ymin = mcords[a][1]; } + else if (mcords[a][1] > rect->ymax) { rect->ymax = mcords[a][1]; } } } @@ -70,14 +70,22 @@ bool BLI_lasso_is_edge_inside(const int mcords[][2], const unsigned int moves, const int v1[2] = {x0, y0}, v2[2] = {x1, y1}; /* check points in lasso */ - if (BLI_lasso_is_point_inside(mcords, moves, v1[0], v1[1], error_value)) return true; - if (BLI_lasso_is_point_inside(mcords, moves, v2[0], v2[1], error_value)) return true; + if (BLI_lasso_is_point_inside(mcords, moves, v1[0], v1[1], error_value)) { + return true; + } + if (BLI_lasso_is_point_inside(mcords, moves, v2[0], v2[1], error_value)) { + return true; + } /* no points in lasso, so we have to intersect with lasso edge */ - if (isect_seg_seg_v2_int(mcords[0], mcords[moves - 1], v1, v2) > 0) return true; + if (isect_seg_seg_v2_int(mcords[0], mcords[moves - 1], v1, v2) > 0) { + return true; + } for (unsigned int a = 0; a < moves - 1; a++) { - if (isect_seg_seg_v2_int(mcords[a], mcords[a + 1], v1, v2) > 0) return true; + if (isect_seg_seg_v2_int(mcords[a], mcords[a + 1], v1, v2) > 0) { + return true; + } } return false; diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 5fd75643d60..8e6de3ab141 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -44,7 +44,9 @@ */ void BLI_movelisttolist(ListBase *dst, ListBase *src) { - if (src->first == NULL) return; + if (src->first == NULL) { + return; + } if (dst->first == NULL) { dst->first = src->first; @@ -63,7 +65,9 @@ void BLI_movelisttolist(ListBase *dst, ListBase *src) */ void BLI_movelisttolist_reverse(ListBase *dst, ListBase *src) { - if (src->first == NULL) return; + if (src->first == NULL) { + return; + } if (dst->first == NULL) { dst->first = src->first; @@ -85,13 +89,19 @@ void BLI_addhead(ListBase *listbase, void *vlink) { Link *link = vlink; - if (link == NULL) return; + if (link == NULL) { + return; + } link->next = listbase->first; link->prev = NULL; - if (listbase->first) ((Link *)listbase->first)->prev = link; - if (listbase->last == NULL) listbase->last = link; + if (listbase->first) { + ((Link *)listbase->first)->prev = link; + } + if (listbase->last == NULL) { + listbase->last = link; + } listbase->first = link; } @@ -103,13 +113,19 @@ void BLI_addtail(ListBase *listbase, void *vlink) { Link *link = vlink; - if (link == NULL) return; + if (link == NULL) { + return; + } link->next = NULL; link->prev = listbase->last; - if (listbase->last) ((Link *)listbase->last)->next = link; - if (listbase->first == NULL) listbase->first = link; + if (listbase->last) { + ((Link *)listbase->last)->next = link; + } + if (listbase->first == NULL) { + listbase->first = link; + } listbase->last = link; } @@ -121,13 +137,23 @@ void BLI_remlink(ListBase *listbase, void *vlink) { Link *link = vlink; - if (link == NULL) return; + if (link == NULL) { + return; + } - if (link->next) link->next->prev = link->prev; - if (link->prev) link->prev->next = link->next; + if (link->next) { + link->next->prev = link->prev; + } + if (link->prev) { + link->prev->next = link->next; + } - if (listbase->last == link) listbase->last = link->prev; - if (listbase->first == link) listbase->first = link->next; + if (listbase->last == link) { + listbase->last = link->prev; + } + if (listbase->first == link) { + listbase->first = link->next; + } } /** @@ -152,8 +178,9 @@ void BLI_listbase_swaplinks(ListBase *listbase, void *vlinka, void *vlinkb) Link *linka = vlinka; Link *linkb = vlinkb; - if (!linka || !linkb) + if (!linka || !linkb) { return; + } if (linkb->next == linka) { SWAP(Link *, linka, linkb); @@ -171,15 +198,32 @@ void BLI_listbase_swaplinks(ListBase *listbase, void *vlinka, void *vlinkb) } /* Update neighbors of linka and linkb. */ - if (linka->prev) linka->prev->next = linka; - if (linka->next) linka->next->prev = linka; - if (linkb->prev) linkb->prev->next = linkb; - if (linkb->next) linkb->next->prev = linkb; + if (linka->prev) { + linka->prev->next = linka; + } + if (linka->next) { + linka->next->prev = linka; + } + if (linkb->prev) { + linkb->prev->next = linkb; + } + if (linkb->next) { + linkb->next->prev = linkb; + } - if (listbase->last == linka) listbase->last = linkb; - else if (listbase->last == linkb) listbase->last = linka; - if (listbase->first == linka) listbase->first = linkb; - else if (listbase->first == linkb) listbase->first = linka; + if (listbase->last == linka) { + listbase->last = linkb; + } + else if (listbase->last == linkb) { + listbase->last = linka; + } + + if (listbase->first == linka) { + listbase->first = linkb; + } + else if (listbase->first == linkb) { + listbase->first = linka; + } } /** @@ -242,7 +286,9 @@ void BLI_freelinkN(ListBase *listbase, void *vlink) { Link *link = vlink; - if (link == NULL) return; + if (link == NULL) { + return; + } BLI_remlink(listbase, link); MEM_freeN(link); @@ -311,7 +357,9 @@ void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) Link *newlink = vnewlink; /* newlink before nextlink */ - if (newlink == NULL) return; + if (newlink == NULL) { + return; + } /* empty list */ if (listbase->first == NULL) { @@ -352,7 +400,9 @@ void BLI_insertlinkbefore(ListBase *listbase, void *vnextlink, void *vnewlink) Link *newlink = vnewlink; /* newlink before nextlink */ - if (newlink == NULL) return; + if (newlink == NULL) { + return; + } /* empty list */ if (listbase->first == NULL) { @@ -566,12 +616,15 @@ int BLI_findindex(const ListBase *listbase, const void *vlink) Link *link = NULL; int number = 0; - if (vlink == NULL) return -1; + if (vlink == NULL) { + return -1; + } link = listbase->first; while (link) { - if (link == vlink) + if (link == vlink) { return number; + } number++; link = link->next; @@ -589,8 +642,9 @@ void *BLI_findstring(const ListBase *listbase, const char *id, const int offset) Link *link = NULL; const char *id_iter; - if (id == NULL) + if (id == NULL) { return NULL; + } for (link = listbase->first; link; link = link->next) { id_iter = ((const char *)link) + offset; @@ -761,8 +815,9 @@ int BLI_findstringindex(const ListBase *listbase, const char *id, const int offs while (link) { id_iter = ((const char *)link) + offset; - if (id[0] == id_iter[0] && STREQ(id, id_iter)) + if (id[0] == id_iter[0] && STREQ(id, id_iter)) { return i; + } i++; link = link->next; } @@ -845,8 +900,9 @@ LinkData *BLI_genericNodeN(void *data) { LinkData *ld; - if (data == NULL) + if (data == NULL) { return NULL; + } /* create new link, and make it hold the given data */ ld = MEM_callocN(sizeof(LinkData), __func__); diff --git a/source/blender/blenlib/intern/math_base.c b/source/blender/blenlib/intern/math_base.c index c4b01729a6d..ed75cac2d0c 100644 --- a/source/blender/blenlib/intern/math_base.c +++ b/source/blender/blenlib/intern/math_base.c @@ -53,8 +53,9 @@ double double_round(double x, int ndigits) pow2 = 1.0; y = (x * pow1) * pow2; /* if y overflows, then rounded value is exactly x */ - if (!isfinite(y)) + if (!isfinite(y)) { return x; + } } else { pow1 = pow(10.0, (double)-ndigits); @@ -63,14 +64,17 @@ double double_round(double x, int ndigits) } z = round(y); - if (fabs(y - z) == 0.5) + if (fabs(y - z) == 0.5) { /* halfway between two integers; use round-half-even */ z = 2.0 * round(y / 2.0); + } - if (ndigits >= 0) + if (ndigits >= 0) { z = (z / pow2) / pow1; - else + } + else { z *= pow1; + } /* if computation resulted in overflow, raise OverflowError */ return z; diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 1ad0dc6a22f..b8a5a138eb4 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -65,16 +65,16 @@ MINLINE float pow7f(float x) MINLINE float sqrt3f(float f) { - if (UNLIKELY(f == 0.0f)) return 0.0f; - else if (UNLIKELY(f < 0.0f)) return -(float)(exp(log(-f) / 3.0)); - else return (float)(exp(log( f) / 3.0)); + if (UNLIKELY(f == 0.0f)) { return 0.0f; } + else if (UNLIKELY(f < 0.0f)) { return -(float)(exp(log(-f) / 3.0)); } + else { return (float)(exp(log( f) / 3.0)); } } MINLINE double sqrt3d(double d) { - if (UNLIKELY(d == 0.0)) return 0.0; - else if (UNLIKELY(d < 0.0)) return -exp(log(-d) / 3.0); - else return exp(log( d) / 3.0); + if (UNLIKELY(d == 0.0)) { return 0.0; } + else if (UNLIKELY(d < 0.0)) { return -exp(log(-d) / 3.0); } + else { return exp(log( d) / 3.0); } } MINLINE float sqrtf_signed(float f) @@ -84,42 +84,42 @@ MINLINE float sqrtf_signed(float f) MINLINE float saacos(float fac) { - if (UNLIKELY(fac <= -1.0f)) return (float)M_PI; - else if (UNLIKELY(fac >= 1.0f)) return 0.0f; - else return acosf(fac); + if (UNLIKELY(fac <= -1.0f)) { return (float)M_PI; } + else if (UNLIKELY(fac >= 1.0f)) { return 0.0f; } + else { return acosf(fac); } } MINLINE float saasin(float fac) { - if (UNLIKELY(fac <= -1.0f)) return (float)-M_PI / 2.0f; - else if (UNLIKELY(fac >= 1.0f)) return (float) M_PI / 2.0f; - else return asinf(fac); + if (UNLIKELY(fac <= -1.0f)) { return (float)-M_PI / 2.0f; } + else if (UNLIKELY(fac >= 1.0f)) { return (float) M_PI / 2.0f; } + else { return asinf(fac); } } MINLINE float sasqrt(float fac) { - if (UNLIKELY(fac <= 0.0f)) return 0.0f; - else return sqrtf(fac); + if (UNLIKELY(fac <= 0.0f)) { return 0.0f; } + else { return sqrtf(fac); } } MINLINE float saacosf(float fac) { - if (UNLIKELY(fac <= -1.0f)) return (float)M_PI; - else if (UNLIKELY(fac >= 1.0f)) return 0.0f; - else return acosf(fac); + if (UNLIKELY(fac <= -1.0f)) { return (float)M_PI; } + else if (UNLIKELY(fac >= 1.0f)) { return 0.0f; } + else { return acosf(fac); } } MINLINE float saasinf(float fac) { - if (UNLIKELY(fac <= -1.0f)) return (float)-M_PI / 2.0f; - else if (UNLIKELY(fac >= 1.0f)) return (float) M_PI / 2.0f; - else return asinf(fac); + if (UNLIKELY(fac <= -1.0f)) { return (float)-M_PI / 2.0f; } + else if (UNLIKELY(fac >= 1.0f)) { return (float) M_PI / 2.0f; } + else { return asinf(fac); } } MINLINE float sasqrtf(float fac) { - if (UNLIKELY(fac <= 0.0f)) return 0.0f; - else return sqrtf(fac); + if (UNLIKELY(fac <= 0.0f)) { return 0.0f; } + else { return sqrtf(fac); } } MINLINE float interpf(float target, float origin, float fac) @@ -140,8 +140,9 @@ MINLINE int is_power_of_2_i(int n) MINLINE int power_of_2_max_i(int n) { - if (is_power_of_2_i(n)) + if (is_power_of_2_i(n)) { return n; + } do { n = n & (n - 1); @@ -152,8 +153,9 @@ MINLINE int power_of_2_max_i(int n) MINLINE int power_of_2_min_i(int n) { - while (!is_power_of_2_i(n)) + while (!is_power_of_2_i(n)) { n = n & (n - 1); + } return n; } @@ -387,16 +389,16 @@ MINLINE float signf(float f) MINLINE int signum_i_ex(float a, float eps) { - if (a > eps) return 1; - if (a < -eps) return -1; - else return 0; + if (a > eps) { return 1; } + if (a < -eps) { return -1; } + else { return 0; } } MINLINE int signum_i(float a) { - if (a > 0.0f) return 1; - if (a < 0.0f) return -1; - else return 0; + if (a > 0.0f) { return 1; } + if (a < 0.0f) { return -1; } + else { return 0; } } /** Returns number of (base ten) *significant* digits of integer part of given float diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index dbc5ee11663..54698ddf7ca 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -201,7 +201,9 @@ void hex_to_rgb(char *hexcol, float *r, float *g, float *b) { unsigned int ri, gi, bi; - if (hexcol[0] == '#') hexcol++; + if (hexcol[0] == '#') { + hexcol++; + } if (sscanf(hexcol, "%02x%02x%02x", &ri, &gi, &bi) == 3) { /* six digit hex colors */ @@ -385,9 +387,9 @@ unsigned int rgb_to_cpack(float r, float g, float b) ig = (unsigned int)floorf(255.0f * max_ff(g, 0.0f)); ib = (unsigned int)floorf(255.0f * max_ff(b, 0.0f)); - if (ir > 255) ir = 255; - if (ig > 255) ig = 255; - if (ib > 255) ib = 255; + if (ir > 255) { ir = 255; } + if (ig > 255) { ig = 255; } + if (ib > 255) { ib = 255; } return (ir + (ig * 256) + (ib * 256 * 256)); } @@ -429,28 +431,46 @@ void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4]) float srgb_to_linearrgb(float c) { - if (c < 0.04045f) + if (c < 0.04045f) { return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f); - else + } + else { return powf((c + 0.055f) * (1.0f / 1.055f), 2.4f); + } } float linearrgb_to_srgb(float c) { - if (c < 0.0031308f) + if (c < 0.0031308f) { return (c < 0.0f) ? 0.0f : c * 12.92f; - else + } + else { return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f; + } } void minmax_rgb(short c[3]) { - if (c[0] > 255) c[0] = 255; - else if (c[0] < 0) c[0] = 0; - if (c[1] > 255) c[1] = 255; - else if (c[1] < 0) c[1] = 0; - if (c[2] > 255) c[2] = 255; - else if (c[2] < 0) c[2] = 0; + if (c[0] > 255) { + c[0] = 255; + } + else if (c[0] < 0) { + c[0] = 0; + } + + if (c[1] > 255) { + c[1] = 255; + } + else if (c[1] < 0) { + c[1] = 0; + } + + if (c[2] > 255) { + c[2] = 255; + } + else if (c[2] < 0) { + c[2] = 0; + } } /* If the requested RGB shade contains a negative weight for @@ -484,10 +504,12 @@ void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *o for (c = 0; c < 3; c++) { offset[c] = lift[c] * gain[c]; slope[c] = gain[c] * (1.0f - lift[c]); - if (gamma[c] == 0) + if (gamma[c] == 0) { power[c] = FLT_MAX; - else + } + else { power[c] = 1.0f / gamma[c]; + } } } @@ -501,8 +523,12 @@ void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset) rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2); hsv[0] += hue_offset; - if (hsv[0] > 1.0f) hsv[0] -= 1.0f; - else if (hsv[0] < 0.0f) hsv[0] += 1.0f; + if (hsv[0] > 1.0f) { + hsv[0] -= 1.0f; + } + else if (hsv[0] < 0.0f) { + hsv[0] += 1.0f; + } hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2); } @@ -551,10 +577,16 @@ static float index_to_float(const unsigned short i) } tmp; /* positive and negative zeros, and all gradual underflow, turn into zero: */ - if (i < 0x80 || (i >= 0x8000 && i < 0x8080)) return 0; + if (i < 0x80 || (i >= 0x8000 && i < 0x8080)) { + return 0; + } /* All NaN's and infinity turn into the largest possible legal float: */ - if (i >= 0x7f80 && i < 0x8000) return FLT_MAX; - if (i >= 0xff80) return -FLT_MAX; + if (i >= 0x7f80 && i < 0x8000) { + return FLT_MAX; + } + if (i >= 0xff80) { + return -FLT_MAX; + } #ifdef __BIG_ENDIAN__ tmp.us[0] = i; @@ -572,16 +604,23 @@ void BLI_init_srgb_conversion(void) static bool initialized = false; unsigned int i, b; - if (initialized) + if (initialized) { return; + } initialized = true; /* Fill in the lookup table to convert floats to bytes: */ for (i = 0; i < 0x10000; i++) { float f = linearrgb_to_srgb(index_to_float((unsigned short)i)) * 255.0f; - if (f <= 0) BLI_color_to_srgb_table[i] = 0; - else if (f < 255) BLI_color_to_srgb_table[i] = (unsigned short) (f * 0x100 + 0.5f); - else BLI_color_to_srgb_table[i] = 0xff00; + if (f <= 0) { + BLI_color_to_srgb_table[i] = 0; + } + else if (f < 255) { + BLI_color_to_srgb_table[i] = (unsigned short) (f * 0x100 + 0.5f); + } + else { + BLI_color_to_srgb_table[i] = 0xff00; + } } /* Fill in the lookup table to convert bytes to float: */ diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 5396f3a47f6..bfe060a8826 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -222,8 +222,9 @@ MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned return; } - for (i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { fsrgb[i] = srgb[i] * (1.0f / 255.0f); + } srgb_to_linearrgb_predivide_v4(linear, fsrgb); } diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 619a73f712f..7c9c3844843 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -133,8 +133,9 @@ float area_tri_signed_v3(const float v1[3], const float v2[3], const float v3[3] area = len_v3(n) * 0.5f; /* negate area for flipped triangles */ - if (dot_v3v3(n, normal) < 0.0f) + if (dot_v3v3(n, normal) < 0.0f) { area = -area; + } return area; } @@ -1075,14 +1076,18 @@ int isect_seg_seg_v2_int(const int v1[2], const int v2[2], const int v3[2], cons float div, lambda, mu; div = (float)((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0])); - if (div == 0.0f) return ISECT_LINE_LINE_COLINEAR; + if (div == 0.0f) { + return ISECT_LINE_LINE_COLINEAR; + } lambda = (float)((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; mu = (float)((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; if (lambda >= 0.0f && lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) { - if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) return ISECT_LINE_LINE_EXACT; + if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) { + return ISECT_LINE_LINE_EXACT; + } return ISECT_LINE_LINE_CROSS; } return ISECT_LINE_LINE_NONE; @@ -1118,14 +1123,18 @@ int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], co float div, lambda, mu; div = (v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0]); - if (div == 0.0f) return ISECT_LINE_LINE_COLINEAR; + if (div == 0.0f) { + return ISECT_LINE_LINE_COLINEAR; + } lambda = ((float)(v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; mu = ((float)(v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; if (lambda >= 0.0f && lambda <= 1.0f && mu >= 0.0f && mu <= 1.0f) { - if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) return ISECT_LINE_LINE_EXACT; + if (lambda == 0.0f || lambda == 1.0f || mu == 0.0f || mu == 1.0f) { + return ISECT_LINE_LINE_EXACT; + } return ISECT_LINE_LINE_CROSS; } return ISECT_LINE_LINE_NONE; @@ -1293,8 +1302,9 @@ int isect_seg_seg_v2_point_ex( u_a = dot_v2v2(s20, s10) / dot_v2v2(s10, s10); u_b = dot_v2v2(s30, s10) / dot_v2v2(s10, s10); - if (u_a > u_b) + if (u_a > u_b) { SWAP(float, u_a, u_b); + } if (u_a > endpoint_max || u_b < endpoint_min) { /* non-overlapping segments */ @@ -1573,21 +1583,29 @@ bool isect_line_segment_tri_v3( cross_v3_v3v3(p, d, e2); a = dot_v3v3(e1, p); - if (a == 0.0f) return false; + if (a == 0.0f) { + return false; + } f = 1.0f / a; sub_v3_v3v3(s, p1, v0); u = f * dot_v3v3(s, p); - if ((u < 0.0f) || (u > 1.0f)) return false; + if ((u < 0.0f) || (u > 1.0f)) { + return false; + } cross_v3_v3v3(q, s, e1); v = f * dot_v3v3(d, q); - if ((v < 0.0f) || ((u + v) > 1.0f)) return false; + if ((v < 0.0f) || ((u + v) > 1.0f)) { + return false; + } *r_lambda = f * dot_v3v3(e2, q); - if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) return false; + if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) { + return false; + } if (r_uv) { r_uv[0] = u; @@ -1613,21 +1631,29 @@ bool isect_line_segment_tri_epsilon_v3( cross_v3_v3v3(p, d, e2); a = dot_v3v3(e1, p); - if (a == 0.0f) return false; + if (a == 0.0f) { + return false; + } f = 1.0f / a; sub_v3_v3v3(s, p1, v0); u = f * dot_v3v3(s, p); - if ((u < -epsilon) || (u > 1.0f + epsilon)) return false; + if ((u < -epsilon) || (u > 1.0f + epsilon)) { + return false; + } cross_v3_v3v3(q, s, e1); v = f * dot_v3v3(d, q); - if ((v < -epsilon) || ((u + v) > 1.0f + epsilon)) return false; + if ((v < -epsilon) || ((u + v) > 1.0f + epsilon)) { + return false; + } *r_lambda = f * dot_v3v3(e2, q); - if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) return false; + if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) { + return false; + } if (r_uv) { r_uv[0] = u; @@ -1657,21 +1683,29 @@ bool isect_ray_tri_v3( cross_v3_v3v3(p, ray_direction, e2); a = dot_v3v3(e1, p); - if ((a > -epsilon) && (a < epsilon)) return false; + if ((a > -epsilon) && (a < epsilon)) { + return false; + } f = 1.0f / a; sub_v3_v3v3(s, ray_origin, v0); u = f * dot_v3v3(s, p); - if ((u < 0.0f) || (u > 1.0f)) return false; + if ((u < 0.0f) || (u > 1.0f)) { + return false; + } cross_v3_v3v3(q, s, e1); v = f * dot_v3v3(ray_direction, q); - if ((v < 0.0f) || ((u + v) > 1.0f)) return false; + if ((v < 0.0f) || ((u + v) > 1.0f)) { + return false; + } *r_lambda = f * dot_v3v3(e2, q); - if ((*r_lambda < 0.0f)) return false; + if ((*r_lambda < 0.0f)) { + return false; + } if (r_uv) { r_uv[0] = u; @@ -1721,21 +1755,29 @@ bool isect_ray_tri_epsilon_v3( cross_v3_v3v3(p, ray_direction, e2); a = dot_v3v3(e1, p); - if (a == 0.0f) return false; + if (a == 0.0f) { + return false; + } f = 1.0f / a; sub_v3_v3v3(s, ray_origin, v0); u = f * dot_v3v3(s, p); - if ((u < -epsilon) || (u > 1.0f + epsilon)) return false; + if ((u < -epsilon) || (u > 1.0f + epsilon)) { + return false; + } cross_v3_v3v3(q, s, e1); v = f * dot_v3v3(ray_direction, q); - if ((v < -epsilon) || ((u + v) > 1.0f + epsilon)) return false; + if ((v < -epsilon) || ((u + v) > 1.0f + epsilon)) { + return false; + } *r_lambda = f * dot_v3v3(e2, q); - if ((*r_lambda < 0.0f)) return false; + if ((*r_lambda < 0.0f)) { + return false; + } if (r_uv) { r_uv[0] = u; @@ -2264,8 +2306,9 @@ static bool getLowestRoot(const float a, const float b, const float c, const flo float r2 = (-b + sqrtD) / (2.0f * a); /* Sort so x1 <= x2 */ - if (r1 > r2) + if (r1 > r2) { SWAP(float, r1, r2); + } /* Get lowest root: */ if (r1 > 0.0f && r1 < maxR) { @@ -2335,7 +2378,9 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const fl normalize_v3(nor); /* flip normal */ - if (dot_v3v3(nor, vel) > 0.0f) negate_v3(nor); + if (dot_v3v3(nor, vel) > 0.0f) { + negate_v3(nor); + } a = dot_v3v3(p1, nor) - dot_v3v3(v0, nor); nordotv = dot_v3v3(nor, vel); @@ -2349,10 +2394,13 @@ bool isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const fl float t0 = (-a + radius) / nordotv; float t1 = (-a - radius) / nordotv; - if (t0 > t1) + if (t0 > t1) { SWAP(float, t0, t1); + } - if (t0 > 1.0f || t1 < 0.0f) return false; + if (t0 > 1.0f || t1 < 0.0f) { + return false; + } /* clamp to [0, 1] */ CLAMP(t0, 0.0f, 1.0f); @@ -2518,25 +2566,36 @@ bool isect_axial_line_segment_tri_v3( sub_v3_v3v3(p, v0, p1); f = (e2[a1] * e1[a2] - e2[a2] * e1[a1]); - if ((f > -epsilon) && (f < epsilon)) return false; + if ((f > -epsilon) && (f < epsilon)) { + return false; + } v = (p[a2] * e1[a1] - p[a1] * e1[a2]) / f; - if ((v < 0.0f) || (v > 1.0f)) return false; + if ((v < 0.0f) || (v > 1.0f)) { + return false; + } f = e1[a1]; if ((f > -epsilon) && (f < epsilon)) { f = e1[a2]; - if ((f > -epsilon) && (f < epsilon)) return false; + if ((f > -epsilon) && (f < epsilon)) { + return false; + } u = (-p[a2] - v * e2[a2]) / f; } - else + else { u = (-p[a1] - v * e2[a1]) / f; + } - if ((u < 0.0f) || ((u + v) > 1.0f)) return false; + if ((u < 0.0f) || ((u + v) > 1.0f)) { + return false; + } *r_lambda = (p[a0] + u * e1[a0] + v * e2[a0]) / (p2[a0] - p1[a0]); - if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) return false; + if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) { + return false; + } return true; } @@ -2661,7 +2720,9 @@ bool isect_line_line_strict_v3(const float v1[3], const float v2[3], mul_v3_fl(a, f1); add_v3_v3v3(vi, v1, a); - if (r_lambda) *r_lambda = f1; + if (r_lambda) { + *r_lambda = f1; + } return true; /* intersection found */ } @@ -2708,30 +2769,36 @@ bool isect_ray_aabb_v3( const float tymin = (bbox[data->sign[1]][1] - data->ray_origin[1]) * data->ray_inv_dir[1]; const float tymax = (bbox[1 - data->sign[1]][1] - data->ray_origin[1]) * data->ray_inv_dir[1]; - if ((tmin > tymax) || (tymin > tmax)) + if ((tmin > tymax) || (tymin > tmax)) { return false; + } - if (tymin > tmin) + if (tymin > tmin) { tmin = tymin; + } - if (tymax < tmax) + if (tymax < tmax) { tmax = tymax; + } const float tzmin = (bbox[data->sign[2]][2] - data->ray_origin[2]) * data->ray_inv_dir[2]; const float tzmax = (bbox[1 - data->sign[2]][2] - data->ray_origin[2]) * data->ray_inv_dir[2]; - if ((tmin > tzmax) || (tzmin > tmax)) + if ((tmin > tzmax) || (tzmin > tmax)) { return false; + } - if (tzmin > tmin) + if (tzmin > tmin) { tmin = tzmin; + } /* Note: tmax does not need to be updated since we don't use it * keeping this here for future reference - jwilkins */ //if (tzmax < tmax) tmax = tzmax; - if (tmin_out) + if (tmin_out) { (*tmin_out) = tmin; + } return true; } @@ -2764,10 +2831,12 @@ bool isect_ray_aabb_v3_simple( return false; } else { - if (tmin) + if (tmin) { *tmin = hit_dist[0]; - if (tmax) + } + if (tmax) { *tmax = hit_dist[1]; + } return true; } } @@ -2952,7 +3021,9 @@ static bool point_in_slice_as(float p[3], float origin[3], float normal[3]) float h, rp[3]; sub_v3_v3v3(rp, p, origin); h = dot_v3v3(normal, rp) / dot_v3v3(normal, normal); - if (h < 0.0f || h > 1.0f) return false; + if (h < 0.0f || h > 1.0f) { + return false; + } return true; } @@ -2967,9 +3038,9 @@ bool point_in_slice_seg(float p[3], float l1[3], float l2[3]) 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 false; - if (!point_in_slice(p, v2, v3, v1)) return false; - if (!point_in_slice(p, v3, v1, v2)) return false; + 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; } @@ -3010,8 +3081,10 @@ bool clip_segment_v3_plane( sub_v3_v3v3(dp, p2, p1); div = dot_v3v3(dp, plane); - if (div == 0.0f) /* parallel */ + if (div == 0.0f) { + /* parallel */ return true; + } float t = -plane_point_side_v3(plane, p1); @@ -3200,14 +3273,18 @@ void interp_weights_quad_v3(float w[4], const float v1[3], const float v2[3], co w[0] = w[1] = w[2] = w[3] = 0.0f; /* first check for exact match */ - if (equals_v3v3(co, v1)) + if (equals_v3v3(co, v1)) { w[0] = 1.0f; - else if (equals_v3v3(co, v2)) + } + else if (equals_v3v3(co, v2)) { w[1] = 1.0f; - else if (equals_v3v3(co, v3)) + } + else if (equals_v3v3(co, v3)) { w[2] = 1.0f; - else if (equals_v3v3(co, v4)) + } + else if (equals_v3v3(co, v4)) { w[3] = 1.0f; + } else { /* otherwise compute barycentric interpolation weights */ float n1[3], n2[3], n[3]; @@ -3487,10 +3564,12 @@ int interp_sparse_array(float *array, const int list_size, const float skipval) int i; for (i = 0; i < list_size; i++) { - if (array[i] == skipval) + if (array[i] == skipval) { found_invalid = 1; - else + } + else { found_valid = 1; + } } if (found_valid == 0) { @@ -3898,8 +3977,9 @@ void resolve_quad_uv_v2_deriv(float r_uv[2], float r_deriv[2][2], if (IS_ZERO(denom) != 0) { const double fDen = a - fC; - if (IS_ZERO(fDen) == 0) + if (IS_ZERO(fDen) == 0) { r_uv[0] = (float)(a / fDen); + } } else { const double desc_sq = b * b - a * fC; @@ -3922,8 +4002,9 @@ void resolve_quad_uv_v2_deriv(float r_uv[2], float r_deriv[2][2], denom = denom_t; } - if (IS_ZERO(denom) == 0) + if (IS_ZERO(denom) == 0) { r_uv[1] = (float)((double)((1.0f - r_uv[0]) * (st0[i] - st[i]) + r_uv[0] * (st1[i] - st[i])) / denom); + } } if (r_deriv) { @@ -3974,10 +4055,12 @@ float resolve_quad_u_v2( if (IS_ZERO(denom) != 0) { const double fDen = a - fC; - if (IS_ZERO(fDen) == 0) + if (IS_ZERO(fDen) == 0) { return (float)(a / fDen); - else + } + else { return 0.0f; + } } else { const double desc_sq = b * b - a * fC; @@ -4183,12 +4266,14 @@ static void i_multmatrix(float icand[4][4], float Vm[4][4]) int row, col; float temp[4][4]; - for (row = 0; row < 4; row++) - for (col = 0; col < 4; col++) + for (row = 0; row < 4; row++) { + for (col = 0; col < 4; col++) { temp[row][col] = (icand[row][0] * Vm[0][col] + icand[row][1] * Vm[1][col] + icand[row][2] * Vm[2][col] + icand[row][3] * Vm[3][col]); + } + } copy_m4_m4(Vm, temp); } @@ -4270,22 +4355,24 @@ int box_clip_bounds_m4(float boundbox[2][3], const float bounds[4], float winmat fl = 0; if (bounds) { - if (vec[0] > bounds[1] * vec[3]) fl |= 1; - if (vec[0] < bounds[0] * vec[3]) fl |= 2; - if (vec[1] > bounds[3] * vec[3]) fl |= 4; - if (vec[1] < bounds[2] * vec[3]) fl |= 8; + if (vec[0] > bounds[1] * vec[3]) { fl |= 1; } + if (vec[0] < bounds[0] * vec[3]) { fl |= 2; } + if (vec[1] > bounds[3] * vec[3]) { fl |= 4; } + if (vec[1] < bounds[2] * vec[3]) { fl |= 8; } } else { - if (vec[0] < -vec[3]) fl |= 1; - if (vec[0] > vec[3]) fl |= 2; - if (vec[1] < -vec[3]) fl |= 4; - if (vec[1] > vec[3]) fl |= 8; + if (vec[0] < -vec[3]) { fl |= 1; } + if (vec[0] > vec[3]) { fl |= 2; } + if (vec[1] < -vec[3]) { fl |= 4; } + if (vec[1] > vec[3]) { fl |= 8; } } - if (vec[2] < -vec[3]) fl |= 16; - if (vec[2] > vec[3]) fl |= 32; + if (vec[2] < -vec[3]) { fl |= 16; } + if (vec[2] > vec[3]) { fl |= 32; } flag &= fl; - if (flag == 0) return 0; + if (flag == 0) { + return 0; + } } return flag; @@ -4551,10 +4638,10 @@ void vcloud_estimate_transform_v3( int a; /* first set up a nice default response */ - if (lloc) zero_v3(lloc); - if (rloc) zero_v3(rloc); - if (lrot) unit_m3(lrot); - if (lscale) unit_m3(lscale); + if (lloc) { zero_v3(lloc); } + if (rloc) { zero_v3(rloc); } + if (lrot) { unit_m3(lrot); } + if (lscale) { unit_m3(lscale); } /* do com for both clouds */ if (pos && rpos && (list_size > 0)) { /* paranoya check */ /* do com for both clouds */ @@ -4587,8 +4674,12 @@ void vcloud_estimate_transform_v3( mul_v3_fl(accu_com, 1.0f / accu_weight); mul_v3_fl(accu_rcom, 1.0f / accu_rweight); - if (lloc) copy_v3_v3(lloc, accu_com); - if (rloc) copy_v3_v3(rloc, accu_rcom); + if (lloc) { + copy_v3_v3(lloc, accu_com); + } + if (rloc) { + copy_v3_v3(rloc, accu_rcom); + } if (lrot || lscale) { /* caller does not want rot nor scale, strange but legal */ /* so now do some reverse engineering and see if we can * split rotation from scale -> Polardecompose */ @@ -4657,12 +4748,16 @@ void vcloud_estimate_transform_v3( if (i) { float scale[3][3]; float irot[3][3]; - if (lrot) copy_m3_m3(lrot, q); + if (lrot) { + copy_m3_m3(lrot, q); + } invert_m3_m3(irot, q); invert_m3_m3(qi, mr); mul_m3_m3m3(q, m, qi); mul_m3_m3m3(scale, irot, q); - if (lscale) copy_m3_m3(lscale, scale); + if (lscale) { + copy_m3_m3(lscale, scale); + } } } @@ -4691,9 +4786,9 @@ bool form_factor_visible_quad(const float p[3], const float n[3], sd[1] = dot_v3v3(n, v1) - c; sd[2] = dot_v3v3(n, v2) - c; - if (fabsf(sd[0]) < epsilon) sd[0] = 0.0f; - if (fabsf(sd[1]) < epsilon) sd[1] = 0.0f; - if (fabsf(sd[2]) < epsilon) sd[2] = 0.0f; + if (fabsf(sd[0]) < epsilon) { sd[0] = 0.0f; } + if (fabsf(sd[1]) < epsilon) { sd[1] = 0.0f; } + if (fabsf(sd[2]) < epsilon) { sd[2] = 0.0f; } if (sd[0] > 0.0f) { if (sd[1] > 0.0f) { @@ -5085,11 +5180,13 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl * covered by a quad or triangle, cosine weighted */ float q0[3], q1[3], q2[3], q3[3], contrib = 0.0f; - if (form_factor_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3)) + if (form_factor_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3)) { contrib += form_factor_quad(p, n, q0, q1, q2, q3); + } - if (v4 && form_factor_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3)) + if (v4 && form_factor_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3)) { contrib += form_factor_quad(p, n, q0, q1, q2, q3); + } return contrib; } diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c index 58262b9a364..0922c47f553 100644 --- a/source/blender/blenlib/intern/math_geom_inline.c +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -73,16 +73,18 @@ MINLINE void mul_sh_fl(float r[9], const float f) { int i; - for (i = 0; i < 9; i++) + for (i = 0; i < 9; i++) { r[i] *= f; + } } MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9]) { int i; - for (i = 0; i < 9; i++) + for (i = 0; i < 9; i++) { r[i] = a[i] + b[i]; + } } MINLINE float dot_shsh(const float a[9], const float b[9]) @@ -90,8 +92,9 @@ MINLINE float dot_shsh(const float a[9], const float b[9]) float r = 0.0f; int i; - for (i = 0; i < 9; i++) + for (i = 0; i < 9; i++) { r += a[i] * b[i]; + } return r; } diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c index 5b3f6349703..ed2b48f6e62 100644 --- a/source/blender/blenlib/intern/math_interp.c +++ b/source/blender/blenlib/intern/math_interp.c @@ -273,8 +273,12 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f /* pixel value must be already wrapped, however values at boundaries may flip */ if (wrap_x) { - if (x1 < 0) x1 = width - 1; - if (x2 >= width) x2 = 0; + if (x1 < 0) { + x1 = width - 1; + } + if (x2 >= width) { + x2 = 0; + } } else if (x2 < 0 || x1 >= width) { copy_vn_fl(float_output, components, 0.0f); @@ -282,8 +286,12 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f } if (wrap_y) { - if (y1 < 0) y1 = height - 1; - if (y2 >= height) y2 = 0; + if (y1 < 0) { + y1 = height - 1; + } + if (y2 >= height) { + y2 = 0; + } } else if (y2 < 0 || y1 >= height) { copy_vn_fl(float_output, components, 0.0f); @@ -291,17 +299,33 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f } /* sample including outside of edges of image */ - if (x1 < 0 || y1 < 0) row1 = empty; - else row1 = float_buffer + width * y1 * components + components * x1; + if (x1 < 0 || y1 < 0) { + row1 = empty; + } + else { + row1 = float_buffer + width * y1 * components + components * x1; + } - if (x1 < 0 || y2 > height - 1) row2 = empty; - else row2 = float_buffer + width * y2 * components + components * x1; + if (x1 < 0 || y2 > height - 1) { + row2 = empty; + } + else { + row2 = float_buffer + width * y2 * components + components * x1; + } - if (x2 > width - 1 || y1 < 0) row3 = empty; - else row3 = float_buffer + width * y1 * components + components * x2; + if (x2 > width - 1 || y1 < 0) { + row3 = empty; + } + else { + row3 = float_buffer + width * y1 * components + components * x2; + } - if (x2 > width - 1 || y2 > height - 1) row4 = empty; - else row4 = float_buffer + width * y2 * components + components * x2; + if (x2 > width - 1 || y2 > height - 1) { + row4 = empty; + } + else { + row4 = float_buffer + width * y2 * components + components * x2; + } a = u - floorf(u); b = v - floorf(v); @@ -328,8 +352,12 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f /* pixel value must be already wrapped, however values at boundaries may flip */ if (wrap_x) { - if (x1 < 0) x1 = width - 1; - if (x2 >= width) x2 = 0; + if (x1 < 0) { + x1 = width - 1; + } + if (x2 >= width) { + x2 = 0; + } } else if (x2 < 0 || x1 >= width) { copy_vn_uchar(byte_output, components, 0); @@ -337,8 +365,12 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f } if (wrap_y) { - if (y1 < 0) y1 = height - 1; - if (y2 >= height) y2 = 0; + if (y1 < 0) { + y1 = height - 1; + } + if (y2 >= height) { + y2 = 0; + } } else if (y2 < 0 || y1 >= height) { copy_vn_uchar(byte_output, components, 0); @@ -346,17 +378,33 @@ BLI_INLINE void bilinear_interpolation(const unsigned char *byte_buffer, const f } /* sample including outside of edges of image */ - if (x1 < 0 || y1 < 0) row1 = empty; - else row1 = byte_buffer + width * y1 * components + components * x1; + if (x1 < 0 || y1 < 0) { + row1 = empty; + } + else { + row1 = byte_buffer + width * y1 * components + components * x1; + } - if (x1 < 0 || y2 > height - 1) row2 = empty; - else row2 = byte_buffer + width * y2 * components + components * x1; + if (x1 < 0 || y2 > height - 1) { + row2 = empty; + } + else { + row2 = byte_buffer + width * y2 * components + components * x1; + } - if (x2 > width - 1 || y1 < 0) row3 = empty; - else row3 = byte_buffer + width * y1 * components + components * x2; + if (x2 > width - 1 || y1 < 0) { + row3 = empty; + } + else { + row3 = byte_buffer + width * y1 * components + components * x2; + } - if (x2 > width - 1 || y2 > height - 1) row4 = empty; - else row4 = byte_buffer + width * y2 * components + components * x2; + if (x2 > width - 1 || y2 > height - 1) { + row4 = empty; + } + else { + row4 = byte_buffer + width * y2 * components + components * x2; + } a = u - floorf(u); b = v - floorf(v); @@ -548,10 +596,10 @@ void BLI_ewa_filter(const int width, const int height, /* note: if eccentricity gets clamped (see above), * the ue/ve limits can also be lowered accordingly */ - if (U0 - (float)u1 > EWA_MAXIDX) u1 = (int)U0 - EWA_MAXIDX; - if ((float)u2 - U0 > EWA_MAXIDX) u2 = (int)U0 + EWA_MAXIDX; - if (V0 - (float)v1 > EWA_MAXIDX) v1 = (int)V0 - EWA_MAXIDX; - if ((float)v2 - V0 > EWA_MAXIDX) v2 = (int)V0 + EWA_MAXIDX; + if (U0 - (float)u1 > EWA_MAXIDX) { u1 = (int)U0 - EWA_MAXIDX; } + if ((float)u2 - U0 > EWA_MAXIDX) { u2 = (int)U0 + EWA_MAXIDX; } + if (V0 - (float)v1 > EWA_MAXIDX) { v1 = (int)V0 - EWA_MAXIDX; } + if ((float)v2 - V0 > EWA_MAXIDX) { v2 = (int)V0 + EWA_MAXIDX; } /* Early output check for cases the whole region is outside of the buffer. */ if ((u2 < 0 || u1 >= width) || (v2 < 0 || v1 >= height)) { diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index 747d9a1337a..68c80beb005 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -177,12 +177,15 @@ void swap_m4m4(float m1[4][4], float m2[4][4]) void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4]) { - if (A == R) + if (A == R) { mul_m4_m4_post(R, B); - else if (B == R) + } + else if (B == R) { mul_m4_m4_pre(R, A); - else + } + else { mul_m4_m4m4_uniq(R, A, B); + } } void mul_m4_m4m4_uniq(float R[4][4], const float A[4][4], const float B[4][4]) @@ -249,12 +252,15 @@ void mul_m4_m4_post(float R[4][4], const float B[4][4]) void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3]) { - if (A == R) + if (A == R) { mul_m3_m3_post(R, B); - else if (B == R) + } + else if (B == R) { mul_m3_m3_pre(R, A); - else + } + else { mul_m3_m3m3_uniq(R, A, B); + } } void mul_m3_m3_pre(float R[3][3], const float A[3][3]) @@ -713,54 +719,66 @@ void mul_m3_fl(float m[3][3], float f) { int i, j; - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { m[i][j] *= f; + } + } } void mul_m4_fl(float m[4][4], float f) { int i, j; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { m[i][j] *= f; + } + } } void mul_mat3_m4_fl(float m[4][4], float f) { int i, j; - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { m[i][j] *= f; + } + } } void negate_m3(float m[3][3]) { int i, j; - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { m[i][j] *= -1.0f; + } + } } void negate_mat3_m4(float m[4][4]) { int i, j; - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { m[i][j] *= -1.0f; + } + } } void negate_m4(float m[4][4]) { int i, j; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { m[i][j] *= -1.0f; + } + } } void mul_m3_v3_double(const float mat[3][3], double vec[3]) @@ -777,36 +795,44 @@ void add_m3_m3m3(float m1[3][3], const float m2[3][3], const float m3[3][3]) { int i, j; - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { m1[i][j] = m2[i][j] + m3[i][j]; + } + } } void add_m4_m4m4(float m1[4][4], const float m2[4][4], const float m3[4][4]) { int i, j; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { m1[i][j] = m2[i][j] + m3[i][j]; + } + } } void sub_m3_m3m3(float m1[3][3], const float m2[3][3], const float m3[3][3]) { int i, j; - for (i = 0; i < 3; i++) - for (j = 0; j < 3; j++) + for (i = 0; i < 3; i++) { + for (j = 0; j < 3; j++) { m1[i][j] = m2[i][j] - m3[i][j]; + } + } } void sub_m4_m4m4(float m1[4][4], const float m2[4][4], const float m3[4][4]) { int i, j; - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { m1[i][j] = m2[i][j] - m3[i][j]; + } + } } float determinant_m3_array(const float m[3][3]) @@ -1002,11 +1028,15 @@ void transpose_m4_m4(float rmat[4][4], const float mat[4][4]) /* TODO: return bool */ int compare_m4m4(const float mat1[4][4], const float mat2[4][4], float limit) { - if (compare_v4v4(mat1[0], mat2[0], limit)) - if (compare_v4v4(mat1[1], mat2[1], limit)) - if (compare_v4v4(mat1[2], mat2[2], limit)) - if (compare_v4v4(mat1[3], mat2[3], limit)) + if (compare_v4v4(mat1[0], mat2[0], limit)) { + if (compare_v4v4(mat1[1], mat2[1], limit)) { + if (compare_v4v4(mat1[2], mat2[2], limit)) { + if (compare_v4v4(mat1[3], mat2[3], limit)) { return 1; + } + } + } + } return 0; } @@ -1194,8 +1224,9 @@ bool is_orthogonal_m3(const float m[3][3]) for (i = 0; i < 3; i++) { for (j = 0; j < i; j++) { - if (fabsf(dot_v3v3(m[i], m[j])) > 1e-5f) + if (fabsf(dot_v3v3(m[i], m[j])) > 1e-5f) { return false; + } } } @@ -1208,8 +1239,9 @@ bool is_orthogonal_m4(const float m[4][4]) for (i = 0; i < 4; i++) { for (j = 0; j < i; j++) { - if (fabsf(dot_v4v4(m[i], m[j])) > 1e-5f) + if (fabsf(dot_v4v4(m[i], m[j])) > 1e-5f) { return false; + } } } @@ -1222,9 +1254,11 @@ bool is_orthonormal_m3(const float m[3][3]) if (is_orthogonal_m3(m)) { int i; - for (i = 0; i < 3; i++) - if (fabsf(dot_v3v3(m[i], m[i]) - 1) > 1e-5f) + for (i = 0; i < 3; i++) { + if (fabsf(dot_v3v3(m[i], m[i]) - 1) > 1e-5f) { return false; + } + } return true; } @@ -1238,8 +1272,9 @@ bool is_orthonormal_m4(const float m[4][4]) int i; for (i = 0; i < 4; i++) - if (fabsf(dot_v4v4(m[i], m[i]) - 1) > 1e-5f) + if (fabsf(dot_v4v4(m[i], m[i]) - 1) > 1e-5f) { return false; + } return true; } @@ -2071,8 +2106,9 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) /* Place the transformation in U for subsequent back * multiplication. */ - for (i = k; i < m; i++) + for (i = k; i < m; i++) { U[i][k] = A[i][k]; + } } if (k < nrt) { @@ -2120,8 +2156,9 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) /* Place the transformation in V for subsequent * back multiplication. */ - for (i = k + 1; i < n; i++) + for (i = k + 1; i < n; i++) { V[i][k] = e[i]; + } } } @@ -2205,8 +2242,9 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) int kase = 0; /* Test for maximum iterations to avoid infinite loop */ - if (maxiter == 0) + if (maxiter == 0) { break; + } maxiter--; /* This section of the program inspects for @@ -2394,8 +2432,9 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) if (s[k] <= 0.0f) { s[k] = (s[k] < 0.0f ? -s[k] : 0.0f); - for (i = 0; i <= pp; i++) + for (i = 0; i <= pp; i++) { V[i][k] = -V[i][k]; + } } /* Order the singular values. */ @@ -2445,8 +2484,9 @@ void pseudoinverse_m4_m4(float Ainv[4][4], const float A_[4][4], float epsilon) transpose_m4(V); zero_m4(Wm); - for (i = 0; i < 4; i++) + for (i = 0; i < 4; i++) { Wm[i][i] = (W[i] < epsilon) ? 0.0f : 1.0f / W[i]; + } transpose_m4(V); diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 5f6bbcce3b3..90eb76f19d9 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -137,8 +137,9 @@ void invert_qt(float q[4]) { const float f = dot_qtqt(q, q); - if (f == 0.0f) + if (f == 0.0f) { return; + } conjugate_qt(q); mul_qt_fl(q, 1.0f / f); @@ -671,8 +672,9 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) nor[1] = -tvec[2]; nor[2] = tvec[1]; - if (fabsf(tvec[1]) + fabsf(tvec[2]) < eps) + if (fabsf(tvec[1]) + fabsf(tvec[2]) < eps) { nor[1] = 1.0f; + } co = tvec[0]; } @@ -681,8 +683,9 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) nor[1] = 0.0; nor[2] = -tvec[0]; - if (fabsf(tvec[0]) + fabsf(tvec[2]) < eps) + if (fabsf(tvec[0]) + fabsf(tvec[2]) < eps) { nor[2] = 1.0f; + } co = tvec[1]; } @@ -691,8 +694,9 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) nor[1] = tvec[0]; nor[2] = 0.0; - if (fabsf(tvec[0]) + fabsf(tvec[1]) < eps) + if (fabsf(tvec[0]) + fabsf(tvec[1]) < eps) { nor[0] = 1.0f; + } co = tvec[2]; } @@ -709,16 +713,16 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) quat_to_mat3(mat, q); if (axis == 0) { - if (upflag == 1) angle = 0.5f * atan2f(fp[2], fp[1]); - else angle = -0.5f * atan2f(fp[1], fp[2]); + if (upflag == 1) { angle = 0.5f * atan2f(fp[2], fp[1]); } + else { angle = -0.5f * atan2f(fp[1], fp[2]); } } else if (axis == 1) { - if (upflag == 0) angle = -0.5f * atan2f(fp[2], fp[0]); - else angle = 0.5f * atan2f(fp[0], fp[2]); + if (upflag == 0) { angle = -0.5f * atan2f(fp[2], fp[0]); } + else { angle = 0.5f * atan2f(fp[0], fp[2]); } } else { - if (upflag == 0) angle = 0.5f * atan2f(-fp[1], -fp[0]); - else angle = -0.5f * atan2f(-fp[0], -fp[1]); + if (upflag == 0) { angle = 0.5f * atan2f(-fp[1], -fp[0]); } + else { angle = -0.5f * atan2f(-fp[0], -fp[1]); } } co = cosf(angle); @@ -954,8 +958,9 @@ void quat_to_axis_angle(float axis[3], float *angle, const float q[4]) *angle = ha * 2; /* prevent division by zero for axis conversion */ - if (fabsf(si) < 0.0005f) + if (fabsf(si) < 0.0005f) { si = 1.0f; + } axis[0] = q[1] / si; axis[1] = q[2] / si; @@ -1380,9 +1385,15 @@ void rotate_eul(float beul[3], const char axis, const float ang) assert(axis >= 'X' && axis <= 'Z'); eul[0] = eul[1] = eul[2] = 0.0f; - if (axis == 'X') eul[0] = ang; - else if (axis == 'Y') eul[1] = ang; - else eul[2] = ang; + if (axis == 'X') { + eul[0] = ang; + } + else if (axis == 'Y') { + eul[1] = ang; + } + else { + eul[2] = ang; + } eul_to_mat3(mat1, eul); eul_to_mat3(mat2, beul); @@ -1418,16 +1429,16 @@ void compatible_eul(float eul[3], const float oldrot[3]) /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */ if (fabsf(deul[0]) > 3.2f && fabsf(deul[1]) < 1.6f && fabsf(deul[2]) < 1.6f) { - if (deul[0] > 0.0f) eul[0] -= pi_x2; - else eul[0] += pi_x2; + if (deul[0] > 0.0f) { eul[0] -= pi_x2; } + else { eul[0] += pi_x2; } } if (fabsf(deul[1]) > 3.2f && fabsf(deul[2]) < 1.6f && fabsf(deul[0]) < 1.6f) { - if (deul[1] > 0.0f) eul[1] -= pi_x2; - else eul[1] += pi_x2; + if (deul[1] > 0.0f) { eul[1] -= pi_x2; } + else { eul[1] += pi_x2; } } if (fabsf(deul[2]) > 3.2f && fabsf(deul[0]) < 1.6f && fabsf(deul[1]) < 1.6f) { - if (deul[2] > 0.0f) eul[2] -= pi_x2; - else eul[2] += pi_x2; + if (deul[2] > 0.0f) { eul[2] -= pi_x2; } + else { eul[2] += pi_x2; } } } @@ -1506,12 +1517,15 @@ static const RotOrderInfo rotOrders[] = { static const RotOrderInfo *get_rotation_order_info(const short order) { assert(order >= 0 && order <= 6); - if (order < 1) + if (order < 1) { return &rotOrders[0]; - else if (order < 6) + } + else if (order < 6) { return &rotOrders[order - 1]; - else + } + else { return &rotOrders[5]; + } } /* Construct quaternion from Euler angles (in radians). */ @@ -1547,7 +1561,9 @@ void eulO_to_quat(float q[4], const float e[3], const short order) q[2] = (float)(a[1]); q[3] = (float)(a[2]); - if (R->parity) q[j + 1] = -q[j + 1]; + if (R->parity) { + q[j + 1] = -q[j + 1]; + } } /* Convert quaternion to Euler angles (in radians). */ @@ -1761,12 +1777,15 @@ void rotate_eulO(float beul[3], const short order, char axis, float ang) zero_v3(eul); - if (axis == 'X') + if (axis == 'X') { eul[0] = ang; - else if (axis == 'Y') + } + else if (axis == 'Y') { eul[1] = ang; - else + } + else { eul[2] = ang; + } eulO_to_mat3(mat1, eul, order); eulO_to_mat3(mat2, beul, order); @@ -1943,8 +1962,10 @@ void add_weighted_dq_dq(DualQuat *dqsum, const DualQuat *dq, float weight) if (dq->scale_weight) { float wmat[4][4]; - if (flipped) /* we don't want negative weights for scaling */ + if (flipped) { + /* we don't want negative weights for scaling */ weight = -weight; + } copy_m4_m4(wmat, (float(*)[4])dq->scale); mul_m4_fl(wmat, weight); @@ -1995,8 +2016,9 @@ void mul_v3m3_dq(float co[3], float mat[3][3], DualQuat *dq) M[2][2] = w * w + z * z - x * x - y * y; len2 = dot_qtqt(dq->quat, dq->quat); - if (len2 > 0.0f) + if (len2 > 0.0f) { len2 = 1.0f / len2; + } /* translation */ t[0] = 2 * (-t0 * x + w * t1 - t2 * z + y * t3); @@ -2004,8 +2026,9 @@ void mul_v3m3_dq(float co[3], float mat[3][3], DualQuat *dq) t[2] = 2 * (-t0 * z + x * t2 + w * t3 - t1 * y); /* apply scaling */ - if (dq->scale_weight) + if (dq->scale_weight) { mul_m4_v3(dq->scale, co); + } /* apply rotation and translation */ mul_m3_v3(M, co); @@ -2019,8 +2042,9 @@ void mul_v3m3_dq(float co[3], float mat[3][3], DualQuat *dq) copy_m3_m4(scalemat, dq->scale); mul_m3_m3m3(mat, M, scalemat); } - else + else { copy_m3_m3(mat, M); + } mul_m3_fl(mat, len2); } } diff --git a/source/blender/blenlib/intern/math_solvers.c b/source/blender/blenlib/intern/math_solvers.c index efaa98fc4e7..2669ac89b25 100644 --- a/source/blender/blenlib/intern/math_solvers.c +++ b/source/blender/blenlib/intern/math_solvers.c @@ -81,15 +81,17 @@ void BLI_svd_m3(const float m3[3][3], float r_U[3][3], float r_S[3], float r_V[3 */ bool BLI_tridiagonal_solve(const float *a, const float *b, const float *c, const float *d, float *r_x, const int count) { - if (count < 1) + if (count < 1) { return false; + } size_t bytes = sizeof(double) * (unsigned)count; double *c1 = (double *)MEM_mallocN(bytes * 2, "tridiagonal_c1d1"); double *d1 = c1 + count; - if (!c1) + if (!c1) { return false; + } int i; double c_prev, d_prev, x_prev; @@ -129,8 +131,9 @@ bool BLI_tridiagonal_solve(const float *a, const float *b, const float *c, const */ bool BLI_tridiagonal_solve_cyclic(const float *a, const float *b, const float *c, const float *d, float *r_x, const int count) { - if (count < 1) + if (count < 1) { return false; + } float a0 = a[0], cN = c[count - 1]; @@ -143,8 +146,9 @@ bool BLI_tridiagonal_solve_cyclic(const float *a, const float *b, const float *c float *tmp = (float *)MEM_mallocN(bytes * 2, "tridiagonal_ex"); float *b2 = tmp + count; - if (!tmp) + if (!tmp) { return false; + } /* prepare the noncyclic system; relies on tridiagonal_solve ignoring values */ memcpy(b2, b, bytes); diff --git a/source/blender/blenlib/intern/math_statistics.c b/source/blender/blenlib/intern/math_statistics.c index e96638a4618..50fa7556134 100644 --- a/source/blender/blenlib/intern/math_statistics.c +++ b/source/blender/blenlib/intern/math_statistics.c @@ -67,8 +67,9 @@ static void covariance_m_vn_ex_task_cb( */ const int i = a / n; const int j = a % n; - if (j < i) + if (j < i) { return; + } if (center) { for (k = 0; k < nbr_cos_vn; k++) { diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index bf4cd702ea1..0aacfd6cde1 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -925,22 +925,22 @@ void print_vn(const char *str, const float v[], const int n) void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]) { - if (min[0] > vec[0]) min[0] = vec[0]; - if (min[1] > vec[1]) min[1] = vec[1]; - if (min[2] > vec[2]) min[2] = vec[2]; + if (min[0] > vec[0]) { min[0] = vec[0]; } + if (min[1] > vec[1]) { min[1] = vec[1]; } + if (min[2] > vec[2]) { min[2] = vec[2]; } - if (max[0] < vec[0]) max[0] = vec[0]; - if (max[1] < vec[1]) max[1] = vec[1]; - if (max[2] < vec[2]) max[2] = vec[2]; + if (max[0] < vec[0]) { max[0] = vec[0]; } + if (max[1] < vec[1]) { max[1] = vec[1]; } + if (max[2] < vec[2]) { max[2] = vec[2]; } } void minmax_v2v2_v2(float min[2], float max[2], const float vec[2]) { - if (min[0] > vec[0]) min[0] = vec[0]; - if (min[1] > vec[1]) min[1] = vec[1]; + if (min[0] > vec[0]) { min[0] = vec[0]; } + if (min[1] > vec[1]) { min[1] = vec[1]; } - if (max[0] < vec[0]) max[0] = vec[0]; - if (max[1] < vec[1]) max[1] = vec[1]; + if (max[0] < vec[0]) { max[0] = vec[0]; } + if (max[1] < vec[1]) { max[1] = vec[1]; } } void minmax_v3v3_v3_array(float r_min[3], float r_max[3], const float (*vec_arr)[3], int nbr) diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c index e999a509016..241c5ec954c 100644 --- a/source/blender/blenlib/intern/noise.c +++ b/source/blender/blenlib/intern/noise.c @@ -388,8 +388,8 @@ static float orgBlenderNoise(float x, float y, float z) h = hashvectf + 3 * hash[b21 + b11]; n += i * (h[0] * jx + h[1] * jy + h[2] * jz); - if (n < 0.0f) n = 0.0f; - else if (n > 1.0f) n = 1.0f; + if (n < 0.0f) { n = 0.0f; } + else if (n > 1.0f) { n = 1.0f; } return n; } @@ -402,7 +402,9 @@ static float orgBlenderNoiseS(float x, float y, float z) /* separated from orgBlenderNoise above, with scaling */ float BLI_hnoise(float noisesize, float x, float y, float z) { - if (noisesize == 0.0f) return 0.0f; + if (noisesize == 0.0f) { + return 0.0f; + } x = (1.0f + x) / noisesize; y = (1.0f + y) / noisesize; z = (1.0f + z) / noisesize; @@ -1294,7 +1296,9 @@ static float voronoi_F1F2(float x, float y, float z) static float voronoi_Cr(float x, float y, float z) { float t = 10 * voronoi_F1F2(x, y, z); - if (t > 1.f) return 1.f; + if (t > 1.f) { + return 1.f; + } return t; } @@ -1341,7 +1345,9 @@ static float voronoi_F1F2S(float x, float y, float z) static float voronoi_CrS(float x, float y, float z) { float t = 10 * voronoi_F1F2(x, y, z); - if (t > 1.f) return 1.f; + if (t > 1.f) { + return 1.f; + } return (2.0f * t - 1.0f); } @@ -1450,7 +1456,9 @@ float BLI_gNoise(float noisesize, float x, float y, float z, int hard, int noise z *= noisesize; } - if (hard) return fabsf(2.0f * noisefunc(x, y, z) - 1.0f); + if (hard) { + return fabsf(2.0f * noisefunc(x, y, z) - 1.0f); + } return noisefunc(x, y, z); } @@ -1508,7 +1516,9 @@ float BLI_gTurbulence(float noisesize, float x, float y, float z, int oct, int h sum = 0; for (i = 0; i <= oct; i++, amp *= 0.5f, fscale *= 2.0f) { t = noisefunc(fscale * x, fscale * y, fscale * z); - if (hard) t = fabsf(2.0f * t - 1.0f); + if (hard) { + t = fabsf(2.0f * t - 1.0f); + } sum += t * amp; } @@ -1583,7 +1593,9 @@ float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves } rmd = octaves - floorf(octaves); - if (rmd != 0.f) value += rmd * noisefunc(x, y, z) * pwr; + if (rmd != 0.0f) { + value += rmd * noisefunc(x, y, z) * pwr; + } return value; @@ -1654,7 +1666,9 @@ float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, floa z *= lacunarity; } rmd = octaves - floorf(octaves); - if (rmd != 0.0f) value *= (rmd * noisefunc(x, y, z) * pwr + 1.0f); + if (rmd != 0.0f) { + value *= (rmd * noisefunc(x, y, z) * pwr + 1.0f); + } return value; @@ -1796,7 +1810,9 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity z *= lacunarity; for (i = 1; (weight > 0.001f) && (i < (int)octaves); i++) { - if (weight > 1.0f) weight = 1.0f; + if (weight > 1.0f) { + weight = 1.0f; + } signal = (noisefunc(x, y, z) + offset) * pwr; pwr *= pwHL; result += weight * signal; @@ -1807,7 +1823,9 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity } rmd = octaves - floorf(octaves); - if (rmd != 0.f) result += rmd * ((noisefunc(x, y, z) + offset) * pwr); + if (rmd != 0.f) { + result += rmd * ((noisefunc(x, y, z) + offset) * pwr); + } return result; @@ -1876,8 +1894,8 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity y *= lacunarity; z *= lacunarity; weight = signal * gain; - if (weight > 1.0f) weight = 1.0f; - else if (weight < 0.0f) weight = 0.0f; + if (weight > 1.0f) { weight = 1.0f; } + else if (weight < 0.0f) { weight = 0.0f; } signal = offset - fabsf(noisefunc(x, y, z)); signal *= signal; signal *= weight; diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 5f66a1b9cb3..6a8be3fe107 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -104,7 +104,9 @@ int BLI_stringdec(const char *string, char *head, char *tail, ushort *r_num_len) } } else { - if (found_digit) break; + if (found_digit) { + break; + } } } @@ -192,7 +194,9 @@ void BLI_cleanup_path(const char *relabase, char *path) eind = start + strlen("\\..\\") - 1; a = start - path - 1; while (a > 0) { - if (path[a] == '\\') break; + if (path[a] == '\\') { + break; + } a--; } if (a < 0) { @@ -308,7 +312,9 @@ bool BLI_filename_make_safe(char *fname) } /* Forbid only dots. */ - for (fn = fname; *fn == '.'; fn++); + for (fn = fname; *fn == '.'; fn++) { + /* pass */ + } if (*fn == '\0') { *fname = '_'; changed = true; @@ -442,7 +448,9 @@ static bool BLI_path_is_abs(const char *name) static wchar_t *next_slash(wchar_t *path) { wchar_t *slash = path; - while (*slash && *slash != L'\\') slash++; + while (*slash && *slash != L'\\') { + slash++; + } return slash; } @@ -555,11 +563,13 @@ void BLI_path_rel(char *file, const char *relfile) int off; int slash = 0; for (off = 0; temp[off] && slash < 4; off++) { - if (temp[off] != file[off]) + if (temp[off] != file[off]) { return; + } - if (temp[off] == '\\') + if (temp[off] == '\\') { slash++; + } } } else if (temp[1] == ':' && file[1] == ':' && temp[0] != file[0]) { @@ -620,7 +630,9 @@ void BLI_path_rel(char *file, const char *relfile) * We count the number of directories we need to go up in the * hierarchy to arrive at the common 'prefix' of the path */ - if (p < temp) p = temp; + if (p < temp) { + p = temp; + } while (p && p < lslash) { if (*p == '/') { r += BLI_strcpy_rlen(r, "../"); @@ -662,8 +674,9 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char char extension[FILE_MAX]; bool has_extension = false; - if (string_len + sep_len + suffix_len >= maxlen) + if (string_len + sep_len + suffix_len >= maxlen) { return false; + } for (a = string_len - 1; a >= 0; a--) { if (string[a] == '.') { @@ -675,8 +688,9 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char } } - if (!has_extension) + if (!has_extension) { a = string_len; + } BLI_strncpy(extension, string + a, sizeof(extension)); sprintf(string + a, "%s%s%s", sep, suffix, extension); @@ -750,8 +764,9 @@ static void ensure_digits(char *path, int digits) { char *file = (char *)BLI_last_slash(path); - if (file == NULL) + if (file == NULL) { file = path; + } if (strrchr(file, '#') == NULL) { int len = strlen(file); @@ -771,8 +786,9 @@ bool BLI_path_frame(char *path, int frame, int digits) { int ch_sta, ch_end; - if (digits) + if (digits) { ensure_digits(path, digits); + } if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ char tmp[FILE_MAX]; @@ -794,8 +810,9 @@ bool BLI_path_frame_range(char *path, int sta, int end, int digits) { int ch_sta, ch_end; - if (digits) + if (digits) { ensure_digits(path, digits); + } if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ char tmp[FILE_MAX]; @@ -820,8 +837,9 @@ bool BLI_path_frame_get(char *path, int *r_frame, int *r_numdigits) numdigits = *r_numdigits = 0; - if (file == NULL) + if (file == NULL) { file = path; + } /* first get the extension part */ len = strlen(file); @@ -873,8 +891,9 @@ void BLI_path_frame_strip(char *path, char *r_ext) int len; int numdigits = 0; - if (file == NULL) + if (file == NULL) { file = path; + } /* first get the extension part */ len = strlen(file); @@ -1092,11 +1111,13 @@ bool BLI_path_cwd(char *path, const size_t maxlen) const int filelen = strlen(path); #ifdef WIN32 - if ((filelen >= 3 && BLI_path_is_abs(path)) || BLI_path_is_unc(path)) + if ((filelen >= 3 && BLI_path_is_abs(path)) || BLI_path_is_unc(path)) { wasrelative = false; + } #else - if (filelen >= 2 && path[0] == '/') + if (filelen >= 2 && path[0] == '/') { wasrelative = false; + } #endif if (wasrelative) { @@ -1239,10 +1260,12 @@ void BLI_setenv(const char *env, const char *val) #else /* linux/osx/bsd */ - if (val) + if (val) { setenv(env, val, 1); - else + } + else { unsetenv(env); + } #endif } @@ -1255,8 +1278,9 @@ void BLI_setenv(const char *env, const char *val) */ void BLI_setenv_if_new(const char *env, const char *val) { - if (BLI_getenv(env) == NULL) + if (BLI_getenv(env) == NULL) { BLI_setenv(env, val); + } } /** @@ -1266,10 +1290,12 @@ const char *BLI_getenv(const char *env) { #ifdef _MSC_VER static char buffer[32767]; /* 32767 is the total size of the environment block on windows*/ - if (GetEnvironmentVariableA(env, buffer, sizeof(buffer))) + if (GetEnvironmentVariableA(env, buffer, sizeof(buffer))) { return buffer; - else + } + else { return NULL; + } #else return getenv(env); #endif @@ -1285,7 +1311,9 @@ void BLI_make_exist(char *dir) bool valid_path = true; /* Loop as long as cur path is not a dir, and we can get a parent path. */ - while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_parent_dir(dir))); + while ((BLI_access(dir, R_OK) != 0) && (valid_path = BLI_parent_dir(dir))) { + /* pass */ + } /* If we could not find an existing dir, use default root... */ if (!valid_path || !dir[0]) { @@ -1344,7 +1372,9 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c strcpy(string, relabase); lslash = (char *)BLI_last_slash(string); - if (lslash) *(lslash + 1) = 0; + if (lslash) { + *(lslash + 1) = 0; + } dir += 2; /* Skip over the relative reference */ } @@ -1369,7 +1399,9 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c } /* ignore leading slashes */ - while (*dir == '/' || *dir == '\\') dir++; + while (*dir == '/' || *dir == '\\') { + dir++; + } } } #endif @@ -1386,8 +1418,10 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, c /* since we've now removed all slashes, put back one slash at the end. */ strcat(string, "/"); - while (*file && (*file == '/' || *file == '\\')) /* Trim slashes from the front of file */ + while (*file && (*file == '/' || *file == '\\')) { + /* Trim slashes from the front of file */ file++; + } strcat(string, file); @@ -1537,8 +1571,9 @@ bool BLI_path_extension_replace(char *path, size_t maxlen, const char *ext) a = path_len; } - if (a + ext_len >= maxlen) + if (a + ext_len >= maxlen) { return false; + } memcpy(path + a, ext, ext_len + 1); return true; @@ -1571,8 +1606,9 @@ bool BLI_path_extension_ensure(char *path, size_t maxlen, const char *ext) } a++; - if (a + ext_len >= maxlen) + if (a + ext_len >= maxlen) { return false; + } memcpy(path + a, ext, ext_len + 1); return true; @@ -1869,8 +1905,12 @@ const char *BLI_first_slash(const char *string) const char * const ffslash = strchr(string, '/'); const char * const fbslash = strchr(string, '\\'); - if (!ffslash) return fbslash; - else if (!fbslash) return ffslash; + if (!ffslash) { + return fbslash; + } + else if (!fbslash) { + return ffslash; + } return (ffslash < fbslash) ? ffslash : fbslash; } @@ -1883,8 +1923,12 @@ const char *BLI_last_slash(const char *string) const char * const lfslash = strrchr(string, '/'); const char * const lbslash = strrchr(string, '\\'); - if (!lfslash) return lbslash; - else if (!lbslash) return lfslash; + if (!lfslash) { + return lbslash; + } + else if (!lbslash) { + return lfslash; + } return (lfslash > lbslash) ? lfslash : lbslash; } diff --git a/source/blender/blenlib/intern/polyfill_2d.c b/source/blender/blenlib/intern/polyfill_2d.c index 5867cdee8bc..4044ebad56b 100644 --- a/source/blender/blenlib/intern/polyfill_2d.c +++ b/source/blender/blenlib/intern/polyfill_2d.c @@ -177,12 +177,15 @@ static void pf_ear_tip_cut(PolyFill *pf, PolyIndex *pi_ear_tip); BLI_INLINE eSign signum_enum(float a) { - if (UNLIKELY(a == 0.0f)) + if (UNLIKELY(a == 0.0f)) { return 0; - else if (a > 0.0f) + } + else if (a > 0.0f) { return 1; - else + } + else { return -1; + } } /** @@ -273,8 +276,8 @@ static uint kdtree2d_balance_recursive( j = pos; while (1) { - while (coords[nodes[++i].index][axis] < co) ; - while (coords[nodes[--j].index][axis] > co && j > neg) ; + while (coords[nodes[++i].index][axis] < co) { /* pass */ } + while (coords[nodes[--j].index][axis] > co && j > neg) { /* pass */ } if (i >= j) { break; diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 1c76361f22a..352bfe5dab6 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -297,8 +297,9 @@ static RNG rng_tab[BLENDER_MAX_THREADS]; void BLI_thread_srandom(int thread, unsigned int seed) { - if (thread >= BLENDER_MAX_THREADS) + if (thread >= BLENDER_MAX_THREADS) { thread = 0; + } BLI_rng_seed(&rng_tab[thread], seed + hash[seed & 255]); seed = BLI_rng_get_uint(&rng_tab[thread]); diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index 9b26ad24230..9437380a09d 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -57,65 +57,65 @@ bool BLI_rctf_is_empty(const rctf *rect) bool BLI_rcti_isect_x(const rcti *rect, const int x) { - if (x < rect->xmin) return false; - if (x > rect->xmax) return false; + if (x < rect->xmin) { return false; } + if (x > rect->xmax) { return false; } return true; } bool BLI_rcti_isect_y(const rcti *rect, const int y) { - if (y < rect->ymin) return false; - if (y > rect->ymax) return false; + if (y < rect->ymin) { return false; } + if (y > rect->ymax) { return false; } return true; } bool BLI_rcti_isect_pt(const rcti *rect, const int x, const int y) { - if (x < rect->xmin) return false; - if (x > rect->xmax) return false; - if (y < rect->ymin) return false; - if (y > rect->ymax) return false; + if (x < rect->xmin) { return false; } + if (x > rect->xmax) { return false; } + if (y < rect->ymin) { return false; } + if (y > rect->ymax) { return false; } return true; } bool BLI_rcti_isect_pt_v(const rcti *rect, const int xy[2]) { - if (xy[0] < rect->xmin) return false; - if (xy[0] > rect->xmax) return false; - if (xy[1] < rect->ymin) return false; - if (xy[1] > rect->ymax) return false; + if (xy[0] < rect->xmin) { return false; } + if (xy[0] > rect->xmax) { return false; } + if (xy[1] < rect->ymin) { return false; } + if (xy[1] > rect->ymax) { return false; } return true; } bool BLI_rctf_isect_x(const rctf *rect, const float x) { - if (x < rect->xmin) return false; - if (x > rect->xmax) return false; + if (x < rect->xmin) { return false; } + if (x > rect->xmax) { return false; } return true; } bool BLI_rctf_isect_y(const rctf *rect, const float y) { - if (y < rect->ymin) return false; - if (y > rect->ymax) return false; + if (y < rect->ymin) { return false; } + if (y > rect->ymax) { return false; } return true; } bool BLI_rctf_isect_pt(const rctf *rect, const float x, const float y) { - if (x < rect->xmin) return false; - if (x > rect->xmax) return false; - if (y < rect->ymin) return false; - if (y > rect->ymax) return false; + if (x < rect->xmin) { return false; } + if (x > rect->xmax) { return false; } + if (y < rect->ymin) { return false; } + if (y > rect->ymax) { return false; } return true; } bool BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2]) { - if (xy[0] < rect->xmin) return false; - if (xy[0] > rect->xmax) return false; - if (xy[1] < rect->ymin) return false; - if (xy[1] > rect->ymax) return false; + if (xy[0] < rect->xmin) { return false; } + if (xy[0] > rect->xmax) { return false; } + if (xy[1] < rect->ymin) { return false; } + if (xy[1] > rect->ymax) { return false; } return true; } @@ -125,29 +125,29 @@ bool BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2]) int BLI_rcti_length_x(const rcti *rect, const int x) { - if (x < rect->xmin) return rect->xmin - x; - if (x > rect->xmax) return x - rect->xmax; + if (x < rect->xmin) { return rect->xmin - x; } + if (x > rect->xmax) { return x - rect->xmax; } return 0; } int BLI_rcti_length_y(const rcti *rect, const int y) { - if (y < rect->ymin) return rect->ymin - y; - if (y > rect->ymax) return y - rect->ymax; + if (y < rect->ymin) { return rect->ymin - y; } + if (y > rect->ymax) { return y - rect->ymax; } return 0; } float BLI_rctf_length_x(const rctf *rect, const float x) { - if (x < rect->xmin) return rect->xmin - x; - if (x > rect->xmax) return x - rect->xmax; + if (x < rect->xmin) { return rect->xmin - x; } + if (x > rect->xmax) { return x - rect->xmax; } return 0.0f; } float BLI_rctf_length_y(const rctf *rect, const float y) { - if (y < rect->ymin) return rect->ymin - y; - if (y > rect->ymax) return y - rect->ymax; + if (y < rect->ymin) { return rect->ymin - y; } + if (y > rect->ymax) { return y - rect->ymax; } return 0.0f; } @@ -200,10 +200,10 @@ static int isect_segments_fl(const float v1[2], const float v2[2], const float v bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2]) { /* first do outside-bounds check for both points of the segment */ - if (s1[0] < rect->xmin && s2[0] < rect->xmin) return false; - if (s1[0] > rect->xmax && s2[0] > rect->xmax) return false; - if (s1[1] < rect->ymin && s2[1] < rect->ymin) return false; - if (s1[1] > rect->ymax && s2[1] > rect->ymax) return false; + if (s1[0] < rect->xmin && s2[0] < rect->xmin) { return false; } + if (s1[0] > rect->xmax && s2[0] > rect->xmax) { return false; } + if (s1[1] < rect->ymin && s2[1] < rect->ymin) { return false; } + if (s1[1] > rect->ymax && s2[1] > rect->ymax) { return false; } /* if either points intersect then we definetly intersect */ if (BLI_rcti_isect_pt_v(rect, s1) || BLI_rcti_isect_pt_v(rect, s2)) { @@ -235,10 +235,10 @@ bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2]) bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[2]) { /* first do outside-bounds check for both points of the segment */ - if (s1[0] < rect->xmin && s2[0] < rect->xmin) return false; - if (s1[0] > rect->xmax && s2[0] > rect->xmax) return false; - if (s1[1] < rect->ymin && s2[1] < rect->ymin) return false; - if (s1[1] > rect->ymax && s2[1] > rect->ymax) return false; + if (s1[0] < rect->xmin && s2[0] < rect->xmin) { return false; } + if (s1[0] > rect->xmax && s2[0] > rect->xmax) { return false; } + if (s1[1] < rect->ymin && s2[1] < rect->ymin) { return false; } + if (s1[1] > rect->ymax && s2[1] > rect->ymax) { return false; } /* if either points intersect then we definetly intersect */ if (BLI_rctf_isect_pt_v(rect, s1) || BLI_rctf_isect_pt_v(rect, s2)) { @@ -271,11 +271,19 @@ bool BLI_rcti_isect_circle(const rcti *rect, const float xy[2], const float radi { float dx, dy; - if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) dx = 0; - else dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax); + if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) { + dx = 0; + } + else { + dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax); + } - if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) dy = 0; - else dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax); + if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) { + dy = 0; + } + else { + dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax); + } return dx * dx + dy * dy <= radius * radius; } @@ -284,29 +292,37 @@ bool BLI_rctf_isect_circle(const rctf *rect, const float xy[2], const float radi { float dx, dy; - if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) dx = 0; - else dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax); + if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) { + dx = 0; + } + else { + dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax); + } - if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) dy = 0; - else dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax); + if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) { + dy = 0; + } + else { + dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax); + } return dx * dx + dy * dy <= radius * radius; } void BLI_rctf_union(rctf *rct1, const rctf *rct2) { - if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin; - if (rct1->xmax < rct2->xmax) rct1->xmax = rct2->xmax; - if (rct1->ymin > rct2->ymin) rct1->ymin = rct2->ymin; - if (rct1->ymax < rct2->ymax) rct1->ymax = rct2->ymax; + if (rct1->xmin > rct2->xmin) { rct1->xmin = rct2->xmin; } + if (rct1->xmax < rct2->xmax) { rct1->xmax = rct2->xmax; } + if (rct1->ymin > rct2->ymin) { rct1->ymin = rct2->ymin; } + if (rct1->ymax < rct2->ymax) { rct1->ymax = rct2->ymax; } } void BLI_rcti_union(rcti *rct1, const rcti *rct2) { - if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin; - if (rct1->xmax < rct2->xmax) rct1->xmax = rct2->xmax; - if (rct1->ymin > rct2->ymin) rct1->ymin = rct2->ymin; - if (rct1->ymax < rct2->ymax) rct1->ymax = rct2->ymax; + if (rct1->xmin > rct2->xmin) { rct1->xmin = rct2->xmin; } + if (rct1->xmax < rct2->xmax) { rct1->xmax = rct2->xmax; } + if (rct1->ymin > rct2->ymin) { rct1->ymin = rct2->ymin; } + if (rct1->ymax < rct2->ymax) { rct1->ymax = rct2->ymax; } } void BLI_rctf_init(rctf *rect, float xmin, float xmax, float ymin, float ymax) @@ -379,18 +395,18 @@ void BLI_rctf_init_minmax(rctf *rect) void BLI_rcti_do_minmax_v(rcti *rect, const int xy[2]) { - if (xy[0] < rect->xmin) rect->xmin = xy[0]; - if (xy[0] > rect->xmax) rect->xmax = xy[0]; - if (xy[1] < rect->ymin) rect->ymin = xy[1]; - if (xy[1] > rect->ymax) rect->ymax = xy[1]; + if (xy[0] < rect->xmin) { rect->xmin = xy[0]; } + if (xy[0] > rect->xmax) { rect->xmax = xy[0]; } + if (xy[1] < rect->ymin) { rect->ymin = xy[1]; } + if (xy[1] > rect->ymax) { rect->ymax = xy[1]; } } void BLI_rctf_do_minmax_v(rctf *rect, const float xy[2]) { - if (xy[0] < rect->xmin) rect->xmin = xy[0]; - if (xy[0] > rect->xmax) rect->xmax = xy[0]; - if (xy[1] < rect->ymin) rect->ymin = xy[1]; - if (xy[1] > rect->ymax) rect->ymax = xy[1]; + if (xy[0] < rect->xmin) { rect->xmin = xy[0]; } + if (xy[0] > rect->xmax) { rect->xmax = xy[0]; } + if (xy[1] < rect->ymin) { rect->ymin = xy[1]; } + if (xy[1] > rect->ymax) { rect->ymax = xy[1]; } } /* given 2 rectangles - transform a point from one to another */ @@ -620,22 +636,30 @@ bool BLI_rcti_clamp(rcti *rect, const rcti *rect_bounds, int r_xy[2]) bool BLI_rctf_compare(const rctf *rect_a, const rctf *rect_b, const float limit) { - if (fabsf(rect_a->xmin - rect_b->xmin) < limit) - if (fabsf(rect_a->xmax - rect_b->xmax) < limit) - if (fabsf(rect_a->ymin - rect_b->ymin) < limit) - if (fabsf(rect_a->ymax - rect_b->ymax) < limit) + if (fabsf(rect_a->xmin - rect_b->xmin) < limit) { + if (fabsf(rect_a->xmax - rect_b->xmax) < limit) { + if (fabsf(rect_a->ymin - rect_b->ymin) < limit) { + if (fabsf(rect_a->ymax - rect_b->ymax) < limit) { return true; + } + } + } + } return false; } bool BLI_rcti_compare(const rcti *rect_a, const rcti *rect_b) { - if (rect_a->xmin == rect_b->xmin) - if (rect_a->xmax == rect_b->xmax) - if (rect_a->ymin == rect_b->ymin) - if (rect_a->ymax == rect_b->ymax) + if (rect_a->xmin == rect_b->xmin) { + if (rect_a->xmax == rect_b->xmax) { + if (rect_a->ymin == rect_b->ymin) { + if (rect_a->ymax == rect_b->ymax) { return true; + } + } + } + } return false; } diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 12e1425837e..80b4acc90a7 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -93,10 +93,10 @@ static int vergscdata(const void *a1, const void *a2) { const ScanFillVertLink *x1 = a1, *x2 = a2; - if (x1->vert->xy[1] < x2->vert->xy[1]) return 1; - else if (x1->vert->xy[1] > x2->vert->xy[1]) return -1; - else if (x1->vert->xy[0] > x2->vert->xy[0]) return 1; - else if (x1->vert->xy[0] < x2->vert->xy[0]) return -1; + if (x1->vert->xy[1] < x2->vert->xy[1]) { return 1; } + else if (x1->vert->xy[1] > x2->vert->xy[1]) { return -1; } + else if (x1->vert->xy[0] > x2->vert->xy[0]) { return 1; } + else if (x1->vert->xy[0] < x2->vert->xy[0]) { return -1; } return 0; } @@ -105,10 +105,10 @@ static int vergpoly(const void *a1, const void *a2) { const PolyFill *x1 = a1, *x2 = a2; - if (x1->min_xy[0] > x2->min_xy[0]) return 1; - else if (x1->min_xy[0] < x2->min_xy[0]) return -1; - else if (x1->min_xy[1] > x2->min_xy[1]) return 1; - else if (x1->min_xy[1] < x2->min_xy[1]) return -1; + if (x1->min_xy[0] > x2->min_xy[0]) { return 1; } + else if (x1->min_xy[0] < x2->min_xy[0]) { return -1; } + else if (x1->min_xy[1] > x2->min_xy[1]) { return 1; } + else if (x1->min_xy[1] < x2->min_xy[1]) { return -1; } return 0; } @@ -174,20 +174,20 @@ static bool boundisect(PolyFill *pf2, PolyFill *pf1) /* has pf2 been touched (intersected) by pf1 ? with bounding box */ /* test first if polys exist */ - if (pf1->edges == 0 || pf2->edges == 0) return false; + if (pf1->edges == 0 || pf2->edges == 0) { return false; } - if (pf2->max_xy[0] < pf1->min_xy[0]) return false; - if (pf2->max_xy[1] < pf1->min_xy[1]) return false; + if (pf2->max_xy[0] < pf1->min_xy[0]) { return false; } + if (pf2->max_xy[1] < pf1->min_xy[1]) { return false; } - if (pf2->min_xy[0] > pf1->max_xy[0]) return false; - if (pf2->min_xy[1] > pf1->max_xy[1]) return false; + if (pf2->min_xy[0] > pf1->max_xy[0]) { return false; } + if (pf2->min_xy[1] > pf1->max_xy[1]) { return false; } /* join */ - if (pf2->max_xy[0] < pf1->max_xy[0]) pf2->max_xy[0] = pf1->max_xy[0]; - if (pf2->max_xy[1] < pf1->max_xy[1]) pf2->max_xy[1] = pf1->max_xy[1]; + if (pf2->max_xy[0] < pf1->max_xy[0]) { pf2->max_xy[0] = pf1->max_xy[0]; } + if (pf2->max_xy[1] < pf1->max_xy[1]) { pf2->max_xy[1] = pf1->max_xy[1]; } - if (pf2->min_xy[0] > pf1->min_xy[0]) pf2->min_xy[0] = pf1->min_xy[0]; - if (pf2->min_xy[1] > pf1->min_xy[1]) pf2->min_xy[1] = pf1->min_xy[1]; + if (pf2->min_xy[0] > pf1->min_xy[0]) { pf2->min_xy[0] = pf1->min_xy[0]; } + if (pf2->min_xy[1] > pf1->min_xy[1]) { pf2->min_xy[1] = pf1->min_xy[1]; } return true; } @@ -230,8 +230,12 @@ static bool testedgeside(const float v1[2], const float v2[2], const float v3[2] return false; } else if (inp == 0.0f) { - if (v1[0] == v3[0] && v1[1] == v3[1]) return false; - if (v2[0] == v3[0] && v2[1] == v3[1]) return false; + if (v1[0] == v3[0] && v1[1] == v3[1]) { + return false; + } + if (v2[0] == v3[0] && v2[1] == v3[1]) { + return false; + } } return true; } @@ -278,8 +282,12 @@ static bool addedgetoscanvert(ScanFillVertLink *sc, ScanFillEdge *eed) break; } } - if (ed) BLI_insertlinkbefore((ListBase *)&(sc->edge_first), ed, eed); - else BLI_addtail((ListBase *)&(sc->edge_first), eed); + if (ed) { + BLI_insertlinkbefore((ListBase *)&(sc->edge_first), ed, eed); + } + else { + BLI_addtail((ListBase *)&(sc->edge_first), eed); + } return true; } @@ -519,13 +527,15 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl */ if (eed->v1->f == SF_VERT_ZERO_LEN) { v1 = eed->v1; - while ((eed->v1->f == SF_VERT_ZERO_LEN) && (eed->v1->tmp.v != v1) && (eed->v1 != eed->v1->tmp.v)) + while ((eed->v1->f == SF_VERT_ZERO_LEN) && (eed->v1->tmp.v != v1) && (eed->v1 != eed->v1->tmp.v)) { eed->v1 = eed->v1->tmp.v; + } } if (eed->v2->f == SF_VERT_ZERO_LEN) { v2 = eed->v2; - while ((eed->v2->f == SF_VERT_ZERO_LEN) && (eed->v2->tmp.v != v2) && (eed->v2 != eed->v2->tmp.v)) + while ((eed->v2->f == SF_VERT_ZERO_LEN) && (eed->v2->tmp.v != v2) && (eed->v2 != eed->v2->tmp.v)) { eed->v2 = eed->v2->tmp.v; + } } if (eed->v1 != eed->v2) { addedgetoscanlist(scdata, eed, verts); @@ -555,8 +565,9 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl /* STEP 2: FILL LOOP */ - if (pf->f == SF_POLY_NEW) + if (pf->f == SF_POLY_NEW) { twoconnected = true; + } /* (temporal) security: never much more faces than vertices */ totface = 0; @@ -577,8 +588,12 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl if (ed1->v1->edge_tot == 1 || ed1->v2->edge_tot == 1) { BLI_remlink((ListBase *)&(sc->edge_first), ed1); BLI_addtail(&sf_ctx->filledgebase, ed1); - if (ed1->v1->edge_tot > 1) ed1->v1->edge_tot--; - if (ed1->v2->edge_tot > 1) ed1->v2->edge_tot--; + if (ed1->v1->edge_tot > 1) { + ed1->v1->edge_tot--; + } + if (ed1->v2->edge_tot > 1) { + ed1->v2->edge_tot--; + } } else { ed1->v2->f = SF_VERT_AVAILABLE; @@ -616,7 +631,9 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl v3 = ed2->v2; /* this happens with a serial of overlapping edges */ - if (v1 == v2 || v2 == v3) break; + if (v1 == v2 || v2 == v3) { + break; + } /* printf("test verts %d %d %d\n", v1->tmp.u, v2->tmp.u, v3->tmp.u); */ miny = min_ff(v1->xy[1], v3->xy[1]); @@ -624,7 +641,9 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl for (b = a + 1; b < verts; b++, sc1++) { if (sc1->vert->f == SF_VERT_NEW) { - if (sc1->vert->xy[1] <= miny) break; + if (sc1->vert->xy[1] <= miny) { + break; + } if (testedgeside(v1->xy, v2->xy, sc1->vert->xy)) { if (testedgeside(v2->xy, v3->xy, sc1->vert->xy)) { if (testedgeside(v3->xy, v1->xy, sc1->vert->xy)) { @@ -724,8 +743,12 @@ static unsigned int scanfill(ScanFillContext *sf_ctx, PolyFill *pf, const int fl if (ed1->v1->edge_tot < 2 || ed1->v2->edge_tot < 2) { BLI_remlink((ListBase *)&(sc->edge_first), ed1); BLI_addtail(&sf_ctx->filledgebase, ed1); - if (ed1->v1->edge_tot > 1) ed1->v1->edge_tot--; - if (ed1->v2->edge_tot > 1) ed1->v2->edge_tot--; + if (ed1->v1->edge_tot > 1) { + ed1->v1->edge_tot--; + } + if (ed1->v2->edge_tot > 1) { + ed1->v2->edge_tot--; + } } } /* done with loose edges */ @@ -934,8 +957,12 @@ unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const if (flag & BLI_SCANFILL_CALC_LOOSE) { unsigned int toggle = 0; for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) { - if (eed->v1->edge_tot++ > 250) break; - if (eed->v2->edge_tot++ > 250) break; + if (eed->v1->edge_tot++ > 250) { + break; + } + if (eed->v2->edge_tot++ > 250) { + break; + } } if (eed) { /* otherwise it's impossible to be sure you can clear vertices */ diff --git a/source/blender/blenlib/intern/smallhash.c b/source/blender/blenlib/intern/smallhash.c index b012ff36bf1..7da5ff114be 100644 --- a/source/blender/blenlib/intern/smallhash.c +++ b/source/blender/blenlib/intern/smallhash.c @@ -405,8 +405,9 @@ double BLI_smallhash_calc_quality(SmallHash *sh) uint64_t sum = 0; uint i; - if (sh->nentries == 0) + if (sh->nentries == 0) { return -1.0; + } for (i = 0; i < sh->nbuckets; i++) { if (sh->buckets[i].key != SMHASH_KEY_UNUSED) { diff --git a/source/blender/blenlib/intern/sort.c b/source/blender/blenlib/intern/sort.c index af206975e16..921eec5ddc4 100644 --- a/source/blender/blenlib/intern/sort.c +++ b/source/blender/blenlib/intern/sort.c @@ -141,8 +141,9 @@ loop: } pc -= es; } - if (pb > pc) + if (pb > pc) { break; + } swap(pb, pc); swap_cnt = 1; pb += es; @@ -165,8 +166,9 @@ loop: vecswap((char *)a, pb - r, r); r = min(pd - pc, pn - pd - es); vecswap(pb, pn - r, r); - if ((r = pb - pa) > es) + if ((r = pb - pa) > es) { BLI_qsort_r(a, r / es, es, cmp, thunk); + } if ((r = pd - pc) > es) { /* Iterate rather than recurse to save stack space */ a = pn - r; diff --git a/source/blender/blenlib/intern/sort_utils.c b/source/blender/blenlib/intern/sort_utils.c index 7166b7753aa..3220f753397 100644 --- a/source/blender/blenlib/intern/sort_utils.c +++ b/source/blender/blenlib/intern/sort_utils.c @@ -41,52 +41,52 @@ int BLI_sortutil_cmp_float(const void *a_, const void *b_) { const struct SortAnyByFloat *a = a_; const struct SortAnyByFloat *b = b_; - if (a->sort_value > b->sort_value) return 1; - else if (a->sort_value < b->sort_value) return -1; - else return 0; + if (a->sort_value > b->sort_value) { return 1; } + else if (a->sort_value < b->sort_value) { return -1; } + else { return 0; } } int BLI_sortutil_cmp_float_reverse(const void *a_, const void *b_) { const struct SortAnyByFloat *a = a_; const struct SortAnyByFloat *b = b_; - if (a->sort_value < b->sort_value) return 1; - else if (a->sort_value > b->sort_value) return -1; - else return 0; + if (a->sort_value < b->sort_value) { return 1; } + else if (a->sort_value > b->sort_value) { return -1; } + else { return 0; } } int BLI_sortutil_cmp_int(const void *a_, const void *b_) { const struct SortAnyByInt *a = a_; const struct SortAnyByInt *b = b_; - if (a->sort_value > b->sort_value) return 1; - else if (a->sort_value < b->sort_value) return -1; - else return 0; + if (a->sort_value > b->sort_value) { return 1; } + else if (a->sort_value < b->sort_value) { return -1; } + else { return 0; } } int BLI_sortutil_cmp_int_reverse(const void *a_, const void *b_) { const struct SortAnyByInt *a = a_; const struct SortAnyByInt *b = b_; - if (a->sort_value < b->sort_value) return 1; - else if (a->sort_value > b->sort_value) return -1; - else return 0; + if (a->sort_value < b->sort_value) { return 1; } + else if (a->sort_value > b->sort_value) { return -1; } + else { return 0; } } int BLI_sortutil_cmp_ptr(const void *a_, const void *b_) { const struct SortAnyByPtr *a = a_; const struct SortAnyByPtr *b = b_; - if (a->sort_value > b->sort_value) return 1; - else if (a->sort_value < b->sort_value) return -1; - else return 0; + if (a->sort_value > b->sort_value) { return 1; } + else if (a->sort_value < b->sort_value) { return -1; } + else { return 0; } } int BLI_sortutil_cmp_ptr_reverse(const void *a_, const void *b_) { const struct SortAnyByPtr *a = a_; const struct SortAnyByPtr *b = b_; - if (a->sort_value < b->sort_value) return 1; - else if (a->sort_value > b->sort_value) return -1; - else return 0; + if (a->sort_value < b->sort_value) { return 1; } + else if (a->sort_value > b->sort_value) { return -1; } + else { return 0; } } diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 4fb519e7f26..7b460c77fa8 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -127,25 +127,35 @@ double BLI_dir_free_space(const char *dir) char name[FILE_MAXDIR], *slash; int len = strlen(dir); - if (len >= FILE_MAXDIR) /* path too long */ + if (len >= FILE_MAXDIR) { + /* path too long */ return -1; + } strcpy(name, dir); if (len) { slash = strrchr(name, '/'); - if (slash) slash[1] = 0; + if (slash) { + slash[1] = 0; + } } else { strcpy(name, "/"); } #if defined(USE_STATFS_STATVFS) - if (statvfs(name, &disk)) return -1; + if (statvfs(name, &disk)) { + return -1; + } #elif defined(USE_STATFS_4ARGS) - if (statfs(name, &disk, sizeof(struct statfs), 0)) return -1; + if (statfs(name, &disk, sizeof(struct statfs), 0)) { + return -1; + } #else - if (statfs(name, &disk)) return -1; + if (statfs(name, &disk)) { + return -1; + } #endif return ( ((double) disk.f_bsize) * ((double) disk.f_bfree)); @@ -159,8 +169,9 @@ double BLI_dir_free_space(const char *dir) size_t BLI_file_descriptor_size(int file) { struct stat st; - if ((file < 0) || (fstat(file, &st) == -1)) + if ((file < 0) || (fstat(file, &st) == -1)) { return -1; + } return st.st_size; } @@ -170,8 +181,9 @@ size_t BLI_file_descriptor_size(int file) size_t BLI_file_size(const char *path) { BLI_stat_t stats; - if (BLI_stat(path, &stats) == -1) + if (BLI_stat(path, &stats) == -1) { return -1; + } return stats.st_size; } @@ -216,11 +228,15 @@ int BLI_exists(const char *name) SetErrorMode(old_error_mode); free(tmp_16); - if (res == -1) return(0); + if (res == -1) { + return(0); + } #else struct stat st; BLI_assert(!BLI_path_is_rel(name)); - if (stat(name, &st)) return(0); + if (stat(name, &st)) { + return(0); + } #endif return(st.st_mode); } @@ -356,7 +372,9 @@ LinkNode *BLI_file_read_as_lines(const char *name) char *buf; size_t size; - if (!fp) return NULL; + if (!fp) { + return NULL; + } fseek(fp, 0, SEEK_END); size = (size_t)ftell(fp); @@ -410,16 +428,24 @@ bool BLI_file_older(const char *file1, const char *file2) UTF16_ENCODE(file1); UTF16_ENCODE(file2); - if (_wstat(file1_16, &st1)) return false; - if (_wstat(file2_16, &st2)) return false; + if (_wstat(file1_16, &st1)) { + return false; + } + if (_wstat(file2_16, &st2)) { + return false; + } UTF16_UN_ENCODE(file2); UTF16_UN_ENCODE(file1); #else struct stat st1, st2; - if (stat(file1, &st1)) return false; - if (stat(file2, &st2)) return false; + if (stat(file1, &st1)) { + return false; + } + if (stat(file2, &st2)) { + return false; + } #endif return (st1.st_mtime < st2.st_mtime); } diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index a1228045a4d..dfb32e5b76c 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -423,8 +423,9 @@ char *BLI_str_replaceN(const char *__restrict str, const char *__restrict substr */ while ((match = strstr(str, substr_old))) { /* the assembly buffer only gets created when we actually need to rebuild the string */ - if (ds == NULL) + if (ds == NULL) { ds = BLI_dynstr_new(); + } /* if the match position does not match the current position in the string, * copy the text up to this position and advance the current position in the string @@ -508,8 +509,9 @@ char *BLI_strcasestr(const char *s, const char *find) len = strlen(find); do { do { - if ((sc = *s++) == 0) + if ((sc = *s++) == 0) { return (NULL); + } sc = tolower(sc); } while (sc != c); } while (BLI_strncasecmp(s, find, len) != 0); @@ -530,8 +532,9 @@ char *BLI_strncasestr(const char *s, const char *find, size_t len) if (len > 1) { do { do { - if ((sc = *s++) == 0) + if ((sc = *s++) == 0) { return NULL; + } sc = tolower(sc); } while (sc != c); } while (BLI_strncasecmp(s, find, len - 1) != 0); @@ -539,8 +542,9 @@ char *BLI_strncasestr(const char *s, const char *find, size_t len) else { { do { - if ((sc = *s++) == 0) + if ((sc = *s++) == 0) { return NULL; + } sc = tolower(sc); } while (sc != c); } @@ -612,30 +616,37 @@ static int left_number_strcmp(const char *s1, const char *s2, int *tiebreaker) /* find number of consecutive digits */ for (numdigit = 0; ; numdigit++) { - if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) + if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) { continue; - else if (isdigit(*(p1 + numdigit))) + } + else if (isdigit(*(p1 + numdigit))) { return 1; /* s2 is bigger */ - else if (isdigit(*(p2 + numdigit))) + } + else if (isdigit(*(p2 + numdigit))) { return -1; /* s1 is bigger */ - else + } + else { break; + } } /* same number of digits, compare size of number */ if (numdigit > 0) { int compare = (int)strncmp(p1, p2, (size_t)numdigit); - if (compare != 0) + if (compare != 0) { return compare; + } } /* use number of leading zeros as tie breaker if still equal */ if (*tiebreaker == 0) { - if (numzero1 > numzero2) + if (numzero1 > numzero2) { *tiebreaker = 1; - else if (numzero1 < numzero2) + } + else if (numzero1 < numzero2) { *tiebreaker = -1; + } } return 0; @@ -659,25 +670,30 @@ int BLI_natstrcmp(const char *s1, const char *s2) if (isdigit(c1) && isdigit(c2)) { int numcompare = left_number_strcmp(s1 + d1, s2 + d2, &tiebreaker); - if (numcompare != 0) + if (numcompare != 0) { return numcompare; + } d1++; - while (isdigit(s1[d1])) + while (isdigit(s1[d1])) { d1++; + } d2++; - while (isdigit(s2[d2])) + while (isdigit(s2[d2])) { d2++; + } c1 = tolower(s1[d1]); c2 = tolower(s2[d2]); } /* first check for '.' so "foo.bar" comes before "foo 1.bar" */ - if (c1 == '.' && c2 != '.') + if (c1 == '.' && c2 != '.') { return -1; - if (c1 != '.' && c2 == '.') + } + if (c1 != '.' && c2 == '.') { return 1; + } else if (c1 < c2) { return -1; } @@ -691,8 +707,9 @@ int BLI_natstrcmp(const char *s1, const char *s2) d2++; } - if (tiebreaker) + if (tiebreaker) { return tiebreaker; + } /* we might still have a different string because of lower/upper case, in * that case fall back to regular string comparison */ @@ -749,8 +766,9 @@ size_t BLI_strnlen(const char *s, const size_t maxlen) size_t len; for (len = 0; len < maxlen; len++, s++) { - if (!*s) + if (!*s) { break; + } } return len; } @@ -759,18 +777,22 @@ void BLI_str_tolower_ascii(char *str, const size_t len) { size_t i; - for (i = 0; (i < len) && str[i]; i++) - if (str[i] >= 'A' && str[i] <= 'Z') + for (i = 0; (i < len) && str[i]; i++) { + if (str[i] >= 'A' && str[i] <= 'Z') { str[i] += 'a' - 'A'; + } + } } void BLI_str_toupper_ascii(char *str, const size_t len) { size_t i; - for (i = 0; (i < len) && str[i]; i++) - if (str[i] >= 'a' && str[i] <= 'z') + for (i = 0; (i < len) && str[i]; i++) { + if (str[i] >= 'a' && str[i] <= 'z') { str[i] -= 'a' - 'A'; + } + } } /** @@ -941,7 +963,9 @@ size_t BLI_str_partition_ex( if (end) { if (from_right) { - for (tmp = end - 1; (tmp >= str) && (*tmp != *d); tmp--); + for (tmp = end - 1; (tmp >= str) && (*tmp != *d); tmp--) { + /* pass */ + } if (tmp < str) { tmp = NULL; } diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 12ada9b6fd9..0c07d1c361a 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -77,12 +77,16 @@ ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length) for (p = (const unsigned char *)str; p < pend; p++, length--) { c = *p; perr = p; /* Erroneous char is always the first of an invalid utf8 sequence... */ - if (ELEM(c, 0xfe, 0xff, 0x00)) /* Those three values are not allowed in utf8 string. */ + if (ELEM(c, 0xfe, 0xff, 0x00)) { + /* Those three values are not allowed in utf8 string. */ goto utf8_error; - if (c < 128) + } + if (c < 128) { continue; - if ((c & 0xc0) != 0xc0) + } + if ((c & 0xc0) != 0xc0) { goto utf8_error; + } /* Note that since we always increase p (and decrease length) by one byte in main loop, * we only add/subtract extra utf8 bytes in code below @@ -95,51 +99,52 @@ ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length) /* Check top bits in the second byte */ p++; length--; - if ((*p & 0xc0) != 0x80) + if ((*p & 0xc0) != 0x80) { goto utf8_error; + } /* Check for overlong sequences for each different length */ switch (ab) { case 1: /* Check for xx00 000x */ - if ((c & 0x3e) == 0) goto utf8_error; + if ((c & 0x3e) == 0) { goto utf8_error; } continue; /* We know there aren't any more bytes to check */ case 2: /* Check for 1110 0000, xx0x xxxx */ - if (c == 0xe0 && (*p & 0x20) == 0) goto utf8_error; + if (c == 0xe0 && (*p & 0x20) == 0) { goto utf8_error; } /* Some special cases, see section 5 of utf-8 decoder stress-test by Markus Kuhn * (https://www.cl.cam.ac.uk/~mgk25/ucs/examples/UTF-8-test.txt). */ /* From section 5.1 (and 5.2) */ if (c == 0xed) { - if (*p == 0xa0 && *(p + 1) == 0x80) goto utf8_error; - if (*p == 0xad && *(p + 1) == 0xbf) goto utf8_error; - if (*p == 0xae && *(p + 1) == 0x80) goto utf8_error; - if (*p == 0xaf && *(p + 1) == 0xbf) goto utf8_error; - if (*p == 0xb0 && *(p + 1) == 0x80) goto utf8_error; - if (*p == 0xbe && *(p + 1) == 0x80) goto utf8_error; - if (*p == 0xbf && *(p + 1) == 0xbf) goto utf8_error; + if (*p == 0xa0 && *(p + 1) == 0x80) { goto utf8_error; } + if (*p == 0xad && *(p + 1) == 0xbf) { goto utf8_error; } + if (*p == 0xae && *(p + 1) == 0x80) { goto utf8_error; } + if (*p == 0xaf && *(p + 1) == 0xbf) { goto utf8_error; } + if (*p == 0xb0 && *(p + 1) == 0x80) { goto utf8_error; } + if (*p == 0xbe && *(p + 1) == 0x80) { goto utf8_error; } + if (*p == 0xbf && *(p + 1) == 0xbf) { goto utf8_error; } } /* From section 5.3 */ if (c == 0xef) { - if (*p == 0xbf && *(p + 1) == 0xbe) goto utf8_error; - if (*p == 0xbf && *(p + 1) == 0xbf) goto utf8_error; + if (*p == 0xbf && *(p + 1) == 0xbe) { goto utf8_error; } + if (*p == 0xbf && *(p + 1) == 0xbf) { goto utf8_error; } } break; case 3: /* Check for 1111 0000, xx00 xxxx */ - if (c == 0xf0 && (*p & 0x30) == 0) goto utf8_error; + if (c == 0xf0 && (*p & 0x30) == 0) { goto utf8_error; } break; case 4: /* Check for 1111 1000, xx00 0xxx */ - if (c == 0xf8 && (*p & 0x38) == 0) goto utf8_error; + if (c == 0xf8 && (*p & 0x38) == 0) { goto utf8_error; } break; case 5: /* Check for 1111 1100, xx00 00xx */ - if (c == 0xfc && (*p & 0x3c) == 0) goto utf8_error; + if (c == 0xfc && (*p & 0x3c) == 0) { goto utf8_error; } break; } @@ -147,7 +152,7 @@ ptrdiff_t BLI_utf8_invalid_byte(const char *str, size_t length) while (--ab > 0) { p++; length--; - if ((*p & 0xc0) != 0x80) goto utf8_error; + if ((*p & 0xc0) != 0x80) { goto utf8_error; } } } @@ -315,8 +320,9 @@ size_t BLI_strlen_utf8_ex(const char *strc, size_t *r_len_bytes) size_t len; const char *strc_orig = strc; - for (len = 0; *strc; len++) + for (len = 0; *strc; len++) { strc += BLI_str_utf8_size_safe(strc); + } *r_len_bytes = (size_t)(strc - strc_orig); return len; @@ -326,8 +332,9 @@ size_t BLI_strlen_utf8(const char *strc) { size_t len; - for (len = 0; *strc; len++) + for (len = 0; *strc; len++) { strc += BLI_str_utf8_size_safe(strc); + } return len; } @@ -412,8 +419,9 @@ int BLI_wcswidth(const wchar_t *pwcs, size_t n) int BLI_str_utf8_char_width(const char *p) { uint unicode = BLI_str_utf8_as_unicode(p); - if (unicode == BLI_UTF8_ERR) + if (unicode == BLI_UTF8_ERR) { return -1; + } return BLI_wcwidth((wchar_t)unicode); } @@ -423,8 +431,9 @@ int BLI_str_utf8_char_width_safe(const char *p) int columns; uint unicode = BLI_str_utf8_as_unicode(p); - if (unicode == BLI_UTF8_ERR) + if (unicode == BLI_UTF8_ERR) { return 1; + } columns = BLI_wcwidth((wchar_t)unicode); @@ -528,8 +537,9 @@ uint BLI_str_utf8_as_unicode(const char *p) const unsigned char c = (unsigned char) *p; UTF8_COMPUTE(c, mask, len, -1); - if (UNLIKELY(len == -1)) + if (UNLIKELY(len == -1)) { return BLI_UTF8_ERR; + } UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR); return result; @@ -544,8 +554,9 @@ uint BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restri const unsigned char c = (unsigned char) *p; UTF8_COMPUTE(c, mask, len, -1); - if (UNLIKELY(len == -1)) + if (UNLIKELY(len == -1)) { return BLI_UTF8_ERR; + } UTF8_GET(result, p, i, mask, len, BLI_UTF8_ERR); *index += (size_t)len; return result; @@ -788,8 +799,9 @@ size_t BLI_str_partition_ex_utf8( for (d = delim; *d != '\0'; ++d) { if (*d == c) { /* *suf is already correct in case from_right is true. */ - if (!from_right) + if (!from_right) { *suf = (char *)(str + index); + } return (size_t)(*sep - str); } } diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c index 3e13b0d3a31..46472d8125d 100644 --- a/source/blender/blenlib/intern/string_utils.c +++ b/source/blender/blenlib/intern/string_utils.c @@ -68,8 +68,9 @@ size_t BLI_split_name_num(char *left, int *nr, const char *name, const char deli left[a] = '\0'; /* truncate left part here */ *nr = atol(name + a + 1); /* casting down to an int, can overflow for large numbers */ - if (*nr < 0) + if (*nr < 0) { *nr = 0; + } return a; } else if (isdigit(name[a]) == 0) { @@ -368,8 +369,9 @@ bool BLI_uniquename(ListBase *list, void *vlink, const char *defname, char delim BLI_assert(name_len > 1); /* See if we are given an empty string */ - if (ELEM(NULL, vlink, defname)) + if (ELEM(NULL, vlink, defname)) { return false; + } return BLI_uniquename_cb(uniquename_unique_check, &data, defname, delim, GIVE_STRADDR(vlink, name_offs), name_len); } diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c index e2feef16049..3a6613b2612 100644 --- a/source/blender/blenlib/intern/task.c +++ b/source/blender/blenlib/intern/task.c @@ -333,8 +333,9 @@ static void task_pool_num_decrease(TaskPool *pool, size_t done) pool->num -= done; - if (pool->num == 0) + if (pool->num == 0) { BLI_condition_notify_all(&pool->num_cond); + } BLI_mutex_unlock(&pool->num_mutex); } @@ -354,8 +355,9 @@ static bool task_scheduler_thread_wait_pop(TaskScheduler *scheduler, Task **task bool found_task = false; BLI_mutex_lock(&scheduler->queue_mutex); - while (!scheduler->queue.first && !scheduler->do_exit) + while (!scheduler->queue.first && !scheduler->do_exit) { BLI_condition_wait(&scheduler->queue_cond, &scheduler->queue_mutex); + } do { Task *current_task; @@ -391,8 +393,9 @@ static bool task_scheduler_thread_wait_pop(TaskScheduler *scheduler, Task **task BLI_remlink(&scheduler->queue, *task); break; } - if (!found_task) + if (!found_task) { BLI_condition_wait(&scheduler->queue_cond, &scheduler->queue_mutex); + } } while (!found_task); BLI_mutex_unlock(&scheduler->queue_mutex); @@ -525,8 +528,9 @@ void BLI_task_scheduler_free(TaskScheduler *scheduler) int i; for (i = 0; i < scheduler->num_threads; i++) { - if (pthread_join(scheduler->threads[i], NULL) != 0) + if (pthread_join(scheduler->threads[i], NULL) != 0) { fprintf(stderr, "TaskScheduler failed to join thread %d/%d\n", i, scheduler->num_threads); + } } MEM_freeN(scheduler->threads); @@ -567,10 +571,12 @@ static void task_scheduler_push(TaskScheduler *scheduler, Task *task, TaskPriori /* add task to queue */ BLI_mutex_lock(&scheduler->queue_mutex); - if (priority == TASK_PRIORITY_HIGH) + if (priority == TASK_PRIORITY_HIGH) { BLI_addhead(&scheduler->queue, task); - else + } + else { BLI_addtail(&scheduler->queue, task); + } BLI_condition_notify_one(&scheduler->queue_cond); BLI_mutex_unlock(&scheduler->queue_mutex); @@ -908,11 +914,13 @@ void BLI_task_pool_work_and_wait(TaskPool *pool) } BLI_mutex_lock(&pool->num_mutex); - if (pool->num == 0) + if (pool->num == 0) { break; + } - if (!found_task) + if (!found_task) { BLI_condition_wait(&pool->num_cond, &pool->num_mutex); + } } BLI_mutex_unlock(&pool->num_mutex); @@ -936,8 +944,9 @@ void BLI_task_pool_cancel(TaskPool *pool) /* wait until all entries are cleared */ BLI_mutex_lock(&pool->num_mutex); - while (pool->num) + while (pool->num) { BLI_condition_wait(&pool->num_cond, &pool->num_mutex); + } BLI_mutex_unlock(&pool->num_mutex); pool->do_cancel = false; diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 89574dd395f..df2e50233d1 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -99,8 +99,9 @@ static TaskScheduler *task_scheduler = NULL; * } * // conditions to exit loop * if (if escape loop event) { - * if (BLI_available_threadslots(&lb) == maxthreads) + * if (BLI_available_threadslots(&lb) == maxthreads) { * break; + * } * } * } * @@ -188,8 +189,12 @@ void BLI_threadpool_init(ListBase *threadbase, void *(*do_thread)(void *), int t if (threadbase != NULL && tot > 0) { BLI_listbase_clear(threadbase); - if (tot > RE_MAX_THREAD) tot = RE_MAX_THREAD; - else if (tot < 1) tot = 1; + if (tot > RE_MAX_THREAD) { + tot = RE_MAX_THREAD; + } + else if (tot < 1) { + tot = 1; + } for (a = 0; a < tot; a++) { ThreadSlot *tslot = MEM_callocN(sizeof(ThreadSlot), "threadslot"); @@ -219,8 +224,9 @@ int BLI_available_threads(ListBase *threadbase) int counter = 0; for (tslot = threadbase->first; tslot; tslot = tslot->next) { - if (tslot->avail) + if (tslot->avail) { counter++; + } } return counter; } @@ -232,8 +238,9 @@ int BLI_threadpool_available_thread_index(ListBase *threadbase) int counter = 0; for (tslot = threadbase->first; tslot; tslot = tslot->next, counter++) { - if (tslot->avail) + if (tslot->avail) { return counter; + } } return 0; } @@ -527,10 +534,12 @@ void BLI_rw_mutex_init(ThreadRWMutex *mutex) void BLI_rw_mutex_lock(ThreadRWMutex *mutex, int mode) { - if (mode == THREAD_LOCK_READ) + if (mode == THREAD_LOCK_READ) { pthread_rwlock_rdlock(mutex); - else + } + else { pthread_rwlock_wrlock(mutex); + } } void BLI_rw_mutex_unlock(ThreadRWMutex *mutex) @@ -588,8 +597,9 @@ void BLI_ticket_mutex_lock(TicketMutex *ticket) pthread_mutex_lock(&ticket->mutex); queue_me = ticket->queue_tail++; - while (queue_me != ticket->queue_head) + while (queue_me != ticket->queue_head) { pthread_cond_wait(&ticket->cond, &ticket->mutex); + } pthread_mutex_unlock(&ticket->mutex); } @@ -690,15 +700,17 @@ void *BLI_thread_queue_pop(ThreadQueue *queue) /* wait until there is work */ pthread_mutex_lock(&queue->mutex); - while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) + while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) { pthread_cond_wait(&queue->push_cond, &queue->mutex); + } /* if we have something, pop it */ if (!BLI_gsqueue_is_empty(queue->queue)) { BLI_gsqueue_pop(queue->queue, &work); - if (BLI_gsqueue_is_empty(queue->queue)) + if (BLI_gsqueue_is_empty(queue->queue)) { pthread_cond_broadcast(&queue->finish_cond); + } } pthread_mutex_unlock(&queue->mutex); @@ -753,18 +765,21 @@ void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms) /* wait until there is work */ pthread_mutex_lock(&queue->mutex); while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) { - if (pthread_cond_timedwait(&queue->push_cond, &queue->mutex, &timeout) == ETIMEDOUT) + if (pthread_cond_timedwait(&queue->push_cond, &queue->mutex, &timeout) == ETIMEDOUT) { break; - else if (PIL_check_seconds_timer() - t >= ms * 0.001) + } + else if (PIL_check_seconds_timer() - t >= ms * 0.001) { break; + } } /* if we have something, pop it */ if (!BLI_gsqueue_is_empty(queue->queue)) { BLI_gsqueue_pop(queue->queue, &work); - if (BLI_gsqueue_is_empty(queue->queue)) + if (BLI_gsqueue_is_empty(queue->queue)) { pthread_cond_broadcast(&queue->finish_cond); + } } pthread_mutex_unlock(&queue->mutex); @@ -810,8 +825,9 @@ void BLI_thread_queue_wait_finish(ThreadQueue *queue) /* wait for finish condition */ pthread_mutex_lock(&queue->mutex); - while (!BLI_gsqueue_is_empty(queue->queue)) + while (!BLI_gsqueue_is_empty(queue->queue)) { pthread_cond_wait(&queue->finish_cond, &queue->mutex); + } pthread_mutex_unlock(&queue->mutex); } diff --git a/source/blender/blenlib/intern/uvproject.c b/source/blender/blenlib/intern/uvproject.c index 5ba295cb997..c08f0d5e32b 100644 --- a/source/blender/blenlib/intern/uvproject.c +++ b/source/blender/blenlib/intern/uvproject.c @@ -46,8 +46,9 @@ void BLI_uvproject_from_camera(float target[2], float source[3], ProjCameraInfo pv4[3] = 1.0; /* rotmat is the object matrix in this case */ - if (uci->do_rotmat) + if (uci->do_rotmat) { mul_m4_v4(uci->rotmat, pv4); + } /* caminv is the inverse camera matrix */ mul_m4_v4(uci->caminv, pv4); @@ -67,8 +68,9 @@ void BLI_uvproject_from_camera(float target[2], float source[3], ProjCameraInfo } } else { - if (pv4[2] == 0.0f) + if (pv4[2] == 0.0f) { pv4[2] = 0.00001f; /* don't allow div by 0 */ + } if (uci->do_persp == false) { target[0] = (pv4[0] / uci->camsize); diff --git a/source/blender/blenlib/intern/voronoi_2d.c b/source/blender/blenlib/intern/voronoi_2d.c index cf502a33774..248e07eae35 100644 --- a/source/blender/blenlib/intern/voronoi_2d.c +++ b/source/blender/blenlib/intern/voronoi_2d.c @@ -136,8 +136,9 @@ static VoronoiParabola *voronoiParabola_getLeftChild(VoronoiParabola *parabola) { VoronoiParabola *current_parabola; - if (!parabola) + if (!parabola) { return NULL; + } current_parabola = parabola->left; while (!current_parabola->is_leaf) { @@ -152,8 +153,9 @@ static VoronoiParabola *voronoiParabola_getRightChild(VoronoiParabola *parabola) { VoronoiParabola *current_parabola; - if (!parabola) + if (!parabola) { return NULL; + } current_parabola = parabola->right; while (!current_parabola->is_leaf) { @@ -170,8 +172,9 @@ static VoronoiParabola *voronoiParabola_getLeftParent(VoronoiParabola *parabola) VoronoiParabola *last_parabola = parabola; while (current_par->left == last_parabola) { - if (!current_par->parent) + if (!current_par->parent) { return NULL; + } last_parabola = current_par; current_par = current_par->parent; @@ -187,8 +190,9 @@ static VoronoiParabola *voronoiParabola_getRightParent(VoronoiParabola *parabola VoronoiParabola *last_parabola = parabola; while (current_parabola->right == last_parabola) { - if (!current_parabola->parent) + if (!current_parabola->parent) { return NULL; + } last_parabola = current_parabola; current_parabola = current_parabola->parent; @@ -250,10 +254,12 @@ static float voronoi_getXOfEdge(VoronoiProcess *process, VoronoiParabola *par, f x1 = (-b + sqrtf(disc)) / (2 * a); x2 = (-b - sqrtf(disc)) / (2 * a); - if (p[1] < r[1]) + if (p[1] < r[1]) { ry = max_ff(x1, x2); - else + } + else { ry = min_ff(x1, x2); + } return ry; } @@ -267,10 +273,12 @@ static VoronoiParabola *voronoi_getParabolaByX(VoronoiProcess *process, float xx while (!par->is_leaf) { x = voronoi_getXOfEdge(process, par, ly); - if (x > xx) + if (x > xx) { par = par->left; - else + } + else { par = par->right; + } } return par; @@ -281,17 +289,21 @@ static int voronoi_getEdgeIntersection(VoronoiEdge *a, VoronoiEdge *b, float p[2 float x = (b->g - a->g) / (a->f - b->f); float y = a->f * x + a->g; - if ((x - a->start[0]) / a->direction[0] < 0) + if ((x - a->start[0]) / a->direction[0] < 0) { return 0; + } - if ((y - a->start[1]) / a->direction[1] < 0) + if ((y - a->start[1]) / a->direction[1] < 0) { return 0; + } - if ((x - b->start[0]) / b->direction[0] < 0) + if ((x - b->start[0]) / b->direction[0] < 0) { return 0; + } - if ((y - b->start[1]) / b->direction[1] < 0) + if ((y - b->start[1]) / b->direction[1] < 0) { return 0; + } p[0] = x; p[1] = y; @@ -312,19 +324,22 @@ static void voronoi_checkCircle(VoronoiProcess *process, VoronoiParabola *b) float ly = process->current_y; float s[2], dx, dy, d; - if (!a || !c || len_squared_v2v2(a->site, c->site) < VORONOI_EPS) + if (!a || !c || len_squared_v2v2(a->site, c->site) < VORONOI_EPS) { return; + } - if (!voronoi_getEdgeIntersection(lp->edge, rp->edge, s)) + if (!voronoi_getEdgeIntersection(lp->edge, rp->edge, s)) { return; + } dx = a->site[0] - s[0]; dy = a->site[1] - s[1]; d = sqrtf((dx * dx) + (dy * dy)); - if (s[1] - d >= ly) + if (s[1] - d >= ly) { return; + } event = MEM_callocN(sizeof(VoronoiEvent), "voronoi circle event"); @@ -363,10 +378,12 @@ static void voronoi_addParabola(VoronoiProcess *process, float site[2]) s[0] = (site[0] + fp[0]) / 2.0f; s[1] = process->height; - if (site[0] > fp[0]) + if (site[0] > fp[0]) { root->edge = voronoiEdge_new(s, fp, site); - else + } + else { root->edge = voronoiEdge_new(s, site, fp); + } BLI_addtail(&process->edges, root->edge); @@ -442,10 +459,12 @@ static void voronoi_removeParabola(VoronoiProcess *process, VoronoiEvent *event) while (par != process->root) { par = par->parent; - if (par == xl) + if (par == xl) { higher = xl; - if (par == xr) + } + if (par == xr) { higher = xr; + } } higher->edge = voronoiEdge_new(p, p0->site, p2->site); @@ -453,16 +472,20 @@ static void voronoi_removeParabola(VoronoiProcess *process, VoronoiEvent *event) gparent = p1->parent->parent; if (p1->parent->left == p1) { - if (gparent->left == p1->parent) + if (gparent->left == p1->parent) { voronoiParabola_setLeft(gparent, p1->parent->right); - if (gparent->right == p1->parent) + } + if (gparent->right == p1->parent) { voronoiParabola_setRight(gparent, p1->parent->right); + } } else { - if (gparent->left == p1->parent) + if (gparent->left == p1->parent) { voronoiParabola_setLeft(gparent, p1->parent->left); - if (gparent->right == p1->parent) + } + if (gparent->right == p1->parent) { voronoiParabola_setRight(gparent, p1->parent->left); + } } MEM_freeN(p1->parent); @@ -481,10 +504,12 @@ static void voronoi_finishEdge(VoronoiProcess *process, VoronoiParabola *parabol return; } - if (parabola->edge->direction[0] > 0.0f) + if (parabola->edge->direction[0] > 0.0f) { mx = max_ff(process->width, parabola->edge->start[0] + 10); - else + } + else { mx = min_ff(0.0f, parabola->edge->start[0] - 10.0f); + } parabola->edge->end[0] = mx; parabola->edge->end[1] = mx * parabola->edge->f + parabola->edge->g; @@ -513,20 +538,26 @@ static void voronoi_clampEdgeVertex(int width, int height, float *coord, float * copy_v2_v2(v1, corners[i]); - if (i == 3) + if (i == 3) { copy_v2_v2(v2, corners[0]); - else + } + else { copy_v2_v2(v2, corners[i + 1]); + } if (isect_seg_seg_v2_point(v1, v2, coord, other_coord, p) == 1) { - if (i == 0 && coord[1] > p[1]) + if (i == 0 && coord[1] > p[1]) { continue; - if (i == 1 && coord[0] < p[0]) + } + if (i == 1 && coord[0] < p[0]) { continue; - if (i == 2 && coord[1] < p[1]) + } + if (i == 2 && coord[1] < p[1]) { continue; - if (i == 3 && coord[0] > p[0]) + } + if (i == 3 && coord[0] > p[0]) { continue; + } copy_v2_v2(coord, p); } @@ -630,8 +661,9 @@ static void voronoi_createBoundaryEdges(ListBase *edges, int width, int height) } dim = dim ? 0 : 1; - if (i == 1) + if (i == 1) { dir = -1; + } } } diff --git a/source/blender/blenlib/intern/winstuff.c b/source/blender/blenlib/intern/winstuff.c index fb16ccb36bd..483351801f4 100644 --- a/source/blender/blenlib/intern/winstuff.c +++ b/source/blender/blenlib/intern/winstuff.c @@ -52,7 +52,9 @@ int BLI_getInstallationDir(char *str) GetModuleFileName(NULL, str, FILE_MAX); BLI_split_dir_part(str, dir, sizeof(dir)); /* shouldn't be relative */ a = strlen(dir); - if (dir[a - 1] == '\\') dir[a - 1] = 0; + if (dir[a - 1] == '\\') { + dir[a - 1] = 0; + } strcpy(str, dir); @@ -62,10 +64,12 @@ int BLI_getInstallationDir(char *str) static void RegisterBlendExtension_Fail(HKEY root) { printf("failed\n"); - if (root) + if (root) { RegCloseKey(root); - if (!G.background) + } + if (!G.background) { MessageBox(0, "Could not register file extension.", "Blender error", MB_OK | MB_ICONERROR); + } TerminateProcess(GetCurrentProcess(), 1); } @@ -104,8 +108,9 @@ void RegisterBlendExtension(void) /* try HKCU on failure */ usr_mode = true; lresult = RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\Classes", 0, KEY_ALL_ACCESS, &root); - if (lresult != ERROR_SUCCESS) + if (lresult != ERROR_SUCCESS) { RegisterBlendExtension_Fail(0); + } } lresult = RegCreateKeyEx(root, "blendfile", 0, @@ -115,8 +120,9 @@ void RegisterBlendExtension(void) lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } - if (lresult != ERROR_SUCCESS) + if (lresult != ERROR_SUCCESS) { RegisterBlendExtension_Fail(root); + } lresult = RegCreateKeyEx(root, "blendfile\\shell\\open\\command", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); @@ -125,8 +131,9 @@ void RegisterBlendExtension(void) lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } - if (lresult != ERROR_SUCCESS) + if (lresult != ERROR_SUCCESS) { RegisterBlendExtension_Fail(root); + } lresult = RegCreateKeyEx(root, "blendfile\\DefaultIcon", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); @@ -135,8 +142,9 @@ void RegisterBlendExtension(void) lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } - if (lresult != ERROR_SUCCESS) + if (lresult != ERROR_SUCCESS) { RegisterBlendExtension_Fail(root); + } lresult = RegCreateKeyEx(root, ".blend", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hkey, &dwd); @@ -145,8 +153,9 @@ void RegisterBlendExtension(void) lresult = RegSetValueEx(hkey, NULL, 0, REG_SZ, (BYTE *)buffer, strlen(buffer) + 1); RegCloseKey(hkey); } - if (lresult != ERROR_SUCCESS) + if (lresult != ERROR_SUCCESS) { RegisterBlendExtension_Fail(root); + } BLI_getInstallationDir(InstallDir); GetSystemDirectory(SysDir, FILE_MAXDIR); @@ -154,10 +163,12 @@ void RegisterBlendExtension(void) ThumbHandlerDLL = "BlendThumb64.dll"; #else IsWow64Process(GetCurrentProcess(), &IsWOW64); - if (IsWOW64 == true) + if (IsWOW64 == true) { ThumbHandlerDLL = "BlendThumb64.dll"; - else + } + else { ThumbHandlerDLL = "BlendThumb.dll"; + } #endif snprintf(RegCmd, MAX_PATH * 2, "%s\\regsvr32 /s \"%s\\%s\"", SysDir, InstallDir, ThumbHandlerDLL); system(RegCmd); diff --git a/source/blender/blenlib/intern/winstuff_dir.c b/source/blender/blenlib/intern/winstuff_dir.c index 0b3cf07883d..b302eaea9de 100644 --- a/source/blender/blenlib/intern/winstuff_dir.c +++ b/source/blender/blenlib/intern/winstuff_dir.c @@ -89,7 +89,9 @@ static char *BLI_alloc_utf_8_from_16(wchar_t *in16, size_t add) { size_t bsize = count_utf_8_from_16(in16); char *out8 = NULL; - if (!bsize) return NULL; + if (!bsize) { + return NULL; + } out8 = (char *)MEM_mallocN(sizeof(char) * (bsize + add), "UTF-8 String"); conv_utf_16_to_8(in16, out8, bsize); return out8; @@ -99,7 +101,9 @@ static wchar_t *UNUSED_FUNCTION(BLI_alloc_utf16_from_8) (char *in8, size_t add) { size_t bsize = count_utf_16_from_8(in8); wchar_t *out16 = NULL; - if (!bsize) return NULL; + if (!bsize) { + return NULL; + } out16 = (wchar_t *) MEM_mallocN(sizeof(wchar_t) * (bsize + add), "UTF-16 String"); conv_utf_8_to_16(in8, out16, bsize); return out16; @@ -118,8 +122,9 @@ struct dirent *readdir(DIR *dp) wchar_t *path_16 = alloc_utf16_from_8(dp->path, 0); dp->handle = FindFirstFileW(path_16, &(dp->data)); free(path_16); - if (dp->handle == INVALID_HANDLE_VALUE) + if (dp->handle == INVALID_HANDLE_VALUE) { return NULL; + } dp->direntry.d_name = BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); @@ -137,8 +142,12 @@ struct dirent *readdir(DIR *dp) int closedir(DIR *dp) { - if (dp->direntry.d_name) MEM_freeN(dp->direntry.d_name); - if (dp->handle != INVALID_HANDLE_VALUE) FindClose(dp->handle); + if (dp->direntry.d_name) { + MEM_freeN(dp->direntry.d_name); + } + if (dp->handle != INVALID_HANDLE_VALUE) { + FindClose(dp->handle); + } MEM_freeN(dp); -- cgit v1.2.3