From a29686eeb3af051a00fbb8a8b9be06bcd050ec8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 7 Aug 2020 11:23:02 +0200 Subject: Cleanup: Blenlib, Clang-Tidy else-after-return fixes (incomplete) This addresses warnings from Clang-Tidy's `readability-else-after-return` rule in the `source/blender/blenlib` module. Not all warnings are addressed in this commit. No functional changes. --- source/blender/blenlib/intern/BLI_args.c | 8 +- source/blender/blenlib/intern/BLI_ghash.c | 42 +- source/blender/blenlib/intern/BLI_kdopbvh.c | 90 ++-- source/blender/blenlib/intern/BLI_linklist.c | 2 +- source/blender/blenlib/intern/BLI_memiter.c | 16 +- source/blender/blenlib/intern/DLRB_tree.c | 8 +- source/blender/blenlib/intern/array_store.c | 26 +- source/blender/blenlib/intern/array_utils.c | 2 +- source/blender/blenlib/intern/bitmap_draw_2d.c | 28 +- source/blender/blenlib/intern/boxpack_2d.c | 8 +- source/blender/blenlib/intern/convexhull_2d.c | 17 +- source/blender/blenlib/intern/delaunay_2d.c | 48 +- source/blender/blenlib/intern/dot_export.cc | 4 +- source/blender/blenlib/intern/easing.c | 35 +- source/blender/blenlib/intern/edgehash.c | 14 +- source/blender/blenlib/intern/fileops.c | 15 +- source/blender/blenlib/intern/lasso_2d.c | 7 +- source/blender/blenlib/intern/listbase.c | 5 +- source/blender/blenlib/intern/math_color.c | 10 +- source/blender/blenlib/intern/math_geom.c | 584 ++++++++++----------- source/blender/blenlib/intern/math_rotation.c | 30 +- source/blender/blenlib/intern/math_vector.c | 18 +- source/blender/blenlib/intern/path_util.c | 73 ++- source/blender/blenlib/intern/polyfill_2d.c | 14 +- .../blender/blenlib/intern/polyfill_2d_beautify.c | 15 +- source/blender/blenlib/intern/quadric.c | 10 +- source/blender/blenlib/intern/rct.c | 194 ++++--- source/blender/blenlib/intern/scanfill.c | 96 ++-- source/blender/blenlib/intern/scanfill_utils.c | 5 +- source/blender/blenlib/intern/smallhash.c | 7 +- source/blender/blenlib/intern/sort_utils.c | 42 +- source/blender/blenlib/intern/storage.c | 4 +- source/blender/blenlib/intern/string.c | 32 +- source/blender/blenlib/intern/string_utf8.c | 8 +- source/blender/blenlib/intern/string_utils.c | 2 +- source/blender/blenlib/intern/threads.cc | 4 +- source/blender/editors/object/object_modifier.c | 18 +- source/blender/editors/object/object_relations.c | 3 +- source/blender/editors/sculpt_paint/sculpt.c | 3 +- source/blender/editors/uvedit/uvedit_rip.c | 25 +- source/blender/editors/uvedit/uvedit_unwrap_ops.c | 6 +- .../gpencil_modifiers/intern/MOD_gpenciltime.c | 2 +- .../blender/windowmanager/gizmo/intern/wm_gizmo.c | 4 +- .../windowmanager/gizmo/intern/wm_gizmo_group.c | 23 +- .../windowmanager/gizmo/intern/wm_gizmo_map.c | 16 +- .../gizmo/intern/wm_gizmo_target_props.c | 12 +- source/blender/windowmanager/intern/wm_cursors.c | 6 +- source/blender/windowmanager/intern/wm_dragdrop.c | 4 +- source/blender/windowmanager/intern/wm_draw.c | 6 +- .../blender/windowmanager/intern/wm_event_system.c | 311 ++++++----- source/blender/windowmanager/intern/wm_files.c | 26 +- .../blender/windowmanager/intern/wm_files_link.c | 6 +- source/blender/windowmanager/intern/wm_jobs.c | 4 +- source/blender/windowmanager/intern/wm_keymap.c | 14 +- .../windowmanager/intern/wm_operator_type.c | 8 +- source/blender/windowmanager/intern/wm_operators.c | 329 ++++++------ source/blender/windowmanager/intern/wm_stereo.c | 15 +- source/blender/windowmanager/intern/wm_window.c | 36 +- .../windowmanager/xr/intern/wm_xr_session.c | 15 +- 59 files changed, 1072 insertions(+), 1343 deletions(-) (limited to 'source') diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index 2b078b3bae5..91aabca7747 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -92,13 +92,9 @@ static bool keycmp(const void *a, const void *b) if (ka->case_str == 1 || kb->case_str == 1) { return (BLI_strcasecmp(ka->arg, kb->arg) != 0); } - else { - return (!STREQ(ka->arg, kb->arg)); - } - } - else { - return BLI_ghashutil_intcmp((const void *)ka->pass, (const void *)kb->pass); + return (!STREQ(ka->arg, kb->arg)); } + return BLI_ghashutil_intcmp((const void *)ka->pass, (const void *)kb->pass); } static bArgument *lookUp(struct bArgs *ba, const char *arg, int pass, int case_str) diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 09dbf18acd0..69602cd4209 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -538,10 +538,8 @@ BLI_INLINE bool ghash_insert_safe(GHash *gh, } return false; } - else { - ghash_insert_ex(gh, key, val, bucket_index); - return true; - } + ghash_insert_ex(gh, key, val, bucket_index); + return true; } BLI_INLINE bool ghash_insert_safe_keyonly(GHash *gh, @@ -564,10 +562,8 @@ BLI_INLINE bool ghash_insert_safe_keyonly(GHash *gh, } return false; } - else { - ghash_insert_ex_keyonly(gh, key, bucket_index); - return true; - } + ghash_insert_ex_keyonly(gh, key, bucket_index); + return true; } /** @@ -792,9 +788,7 @@ void *BLI_ghash_replace_key(GHash *gh, void *key) e->e.key = key; return key_prev; } - else { - return NULL; - } + return NULL; } /** @@ -915,9 +909,7 @@ bool BLI_ghash_remove(GHash *gh, BLI_mempool_free(gh->entrypool, e); return true; } - else { - return false; - } + return false; } /* same as above but return the value, @@ -940,9 +932,7 @@ void *BLI_ghash_popkey(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp) BLI_mempool_free(gh->entrypool, e); return val; } - else { - return NULL; - } + return NULL; } /** @@ -975,10 +965,9 @@ bool BLI_ghash_pop(GHash *gh, GHashIterState *state, void **r_key, void **r_val) BLI_mempool_free(gh->entrypool, e); return true; } - else { - *r_key = *r_val = NULL; - return false; - } + + *r_key = *r_val = NULL; + return false; } /** @@ -1246,10 +1235,9 @@ bool BLI_gset_pop(GSet *gs, GSetIterState *state, void **r_key) BLI_mempool_free(((GHash *)gs)->entrypool, e); return true; } - else { - *r_key = NULL; - return false; - } + + *r_key = NULL; + return false; } void BLI_gset_clear_ex(GSet *gs, GSetKeyFreeFP keyfreefp, const uint nentries_reserve) @@ -1309,9 +1297,7 @@ void *BLI_gset_pop_key(GSet *gs, const void *key) BLI_mempool_free(((GHash *)gs)->entrypool, e); return key_ret; } - else { - return NULL; - } + return NULL; } /** \} */ diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index a3f93ccc753..f63a523ca60 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -284,28 +284,19 @@ static BVHNode *bvh_medianof3(BVHNode **a, int lo, int mid, int hi, int axis) if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) { return a[mid]; } - else { - if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { - return a[hi]; - } - else { - return a[lo]; - } + if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { + return a[hi]; } + return a[lo]; } - else { - if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) { - if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { - return a[lo]; - } - else { - return a[hi]; - } - } - else { - return a[mid]; + + if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) { + if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { + return a[lo]; } + return a[hi]; } + return a[mid]; } /** @@ -422,18 +413,12 @@ static char get_largest_axis(const float *bv) if (middle_point[0] > middle_point[2]) { return 1; /* max x axis */ } - else { - return 5; /* max z axis */ - } + return 5; /* max z axis */ } - else { - if (middle_point[1] > middle_point[2]) { - return 3; /* max y axis */ - } - else { - return 5; /* max z axis */ - } + if (middle_point[1] > middle_point[2]) { + return 3; /* max y axis */ } + return 5; /* max z axis */ } /** @@ -619,13 +604,11 @@ static int implicit_leafs_index(const BVHBuildHelper *data, const int depth, con if (min_leaf_index <= data->remain_leafs) { return min_leaf_index; } - else if (data->leafs_per_child[depth]) { + if (data->leafs_per_child[depth]) { return data->totleafs - (data->branches_on_level[depth - 1] - child_index) * data->leafs_per_child[depth]; } - else { - return data->remain_leafs; - } + return data->remain_leafs; } /** @@ -1668,10 +1651,8 @@ static bool dfs_find_duplicate_fast_dfs(BVHNearestData *data, BVHNode *node) data->callback(data->userdata, node->index, data->co, &data->nearest); return (data->nearest.dist_sq < dist_sq); } - else { - data->nearest.index = node->index; - return true; - } + data->nearest.index = node->index; + return true; } } else { @@ -1805,9 +1786,7 @@ static float fast_ray_nearest_hit(const BVHRayCastData *data, const BVHNode *nod (t1x > data->hit.dist || t1y > data->hit.dist || t1z > data->hit.dist)) { return FLT_MAX; } - else { - return max_fff(t1x, t1y, t1z); - } + return max_fff(t1x, t1y, t1z); } static void dfs_raycast(BVHRayCastData *data, BVHNode *node) @@ -2354,26 +2333,25 @@ static bool bvhtree_walk_dfs_recursive(BVHTree_WalkData *walk_data, const BVHNod return walk_data->walk_leaf_cb( (const BVHTreeAxisRange *)node->bv, node->index, walk_data->userdata); } - else { - /* First pick the closest node to recurse into */ - if (walk_data->walk_order_cb( - (const BVHTreeAxisRange *)node->bv, node->main_axis, walk_data->userdata)) { - for (int i = 0; i != node->totnode; i++) { - if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv, - walk_data->userdata)) { - if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) { - return false; - } + + /* First pick the closest node to recurse into */ + if (walk_data->walk_order_cb( + (const BVHTreeAxisRange *)node->bv, node->main_axis, walk_data->userdata)) { + for (int i = 0; i != node->totnode; i++) { + if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv, + walk_data->userdata)) { + if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) { + return false; } } } - else { - for (int i = node->totnode - 1; i >= 0; i--) { - if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv, - walk_data->userdata)) { - if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) { - return false; - } + } + else { + for (int i = node->totnode - 1; i >= 0; i--) { + if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv, + walk_data->userdata)) { + if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) { + return false; } } } diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index dc5d20ece99..4cac526088b 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -147,7 +147,7 @@ void BLI_linklist_move_item(LinkNode **listp, int curr_index, int new_index) lnk_pdst = lnk; break; } - else if (i == curr_index - 1) { + if (i == curr_index - 1) { lnk_psrc = lnk; } } diff --git a/source/blender/blenlib/intern/BLI_memiter.c b/source/blender/blenlib/intern/BLI_memiter.c index 1b9509e36d8..428dd1e2ad8 100644 --- a/source/blender/blenlib/intern/BLI_memiter.c +++ b/source/blender/blenlib/intern/BLI_memiter.c @@ -269,9 +269,7 @@ void *BLI_memiter_elem_first(BLI_memiter *mi) BLI_memiter_elem *elem = (BLI_memiter_elem *)chunk->data; return elem->data; } - else { - return NULL; - } + return NULL; } void *BLI_memiter_elem_first_size(BLI_memiter *mi, uint *r_size) @@ -282,9 +280,7 @@ void *BLI_memiter_elem_first_size(BLI_memiter *mi, uint *r_size) *r_size = (uint)elem->size; return elem->data; } - else { - return NULL; - } + return NULL; } /** \} */ @@ -334,9 +330,7 @@ void *BLI_memiter_iter_step_size(BLI_memiter_handle *iter, uint *r_size) iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)]; return (void *)data; } - else { - return NULL; - } + return NULL; } void *BLI_memiter_iter_step(BLI_memiter_handle *iter) @@ -352,9 +346,7 @@ void *BLI_memiter_iter_step(BLI_memiter_handle *iter) iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)]; return (void *)data; } - else { - return NULL; - } + return NULL; } /** \} */ diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c index 6810601d527..b0c3379ac97 100644 --- a/source/blender/blenlib/intern/DLRB_tree.c +++ b/source/blender/blenlib/intern/DLRB_tree.c @@ -299,9 +299,7 @@ static DLRBT_Node *get_grandparent(DLRBT_Node *node) if (node && node->parent) { return node->parent->parent; } - else { - return NULL; - } + return NULL; } /* get the sibling node (e.g. if node is left child of parent, return right child of parent) */ @@ -311,9 +309,7 @@ static DLRBT_Node *get_sibling(DLRBT_Node *node) if (node == node->parent->left) { return node->parent->right; } - else { - return node->parent->left; - } + return node->parent->left; } /* sibling not found */ diff --git a/source/blender/blenlib/intern/array_store.c b/source/blender/blenlib/intern/array_store.c index 85fbe7ece0f..387f9837159 100644 --- a/source/blender/blenlib/intern/array_store.c +++ b/source/blender/blenlib/intern/array_store.c @@ -355,9 +355,7 @@ static bool bchunk_data_compare(const BChunk *chunk, if (offset + (size_t)chunk->data_len <= data_base_len) { return (memcmp(&data_base[offset], chunk->data, chunk->data_len) == 0); } - else { - return false; - } + return false; } /** \} */ @@ -893,20 +891,18 @@ static hash_key key_from_chunk_ref(const BArrayInfo *info, # endif return key; } - else { - /* corner case - we're too small, calculate the key each time. */ + /* corner case - we're too small, calculate the key each time. */ - hash_array_from_cref(info, cref, info->accum_read_ahead_bytes, hash_store); - hash_accum_single(hash_store, hash_store_len, info->accum_steps); - hash_key key = hash_store[0]; + hash_array_from_cref(info, cref, info->accum_read_ahead_bytes, hash_store); + hash_accum_single(hash_store, hash_store_len, info->accum_steps); + hash_key key = hash_store[0]; # ifdef USE_HASH_TABLE_KEY_CACHE - if (UNLIKELY(key == HASH_TABLE_KEY_UNSET)) { - key = HASH_TABLE_KEY_FALLBACK; - } -# endif - return key; + if (UNLIKELY(key == HASH_TABLE_KEY_UNSET)) { + key = HASH_TABLE_KEY_FALLBACK; } +# endif + return key; } static const BChunkRef *table_lookup(const BArrayInfo *info, @@ -1083,9 +1079,7 @@ static BChunkList *bchunk_list_from_data_merge(const BArrayInfo *info, if (cref == cref_match_first) { break; } - else { - cref = cref->next; - } + cref = cref->next; } /* happens when bytes are removed from the end of the array */ if (chunk_size_step == data_len_original) { diff --git a/source/blender/blenlib/intern/array_utils.c b/source/blender/blenlib/intern/array_utils.c index 5dec10a5756..e9ef5e2a927 100644 --- a/source/blender/blenlib/intern/array_utils.c +++ b/source/blender/blenlib/intern/array_utils.c @@ -208,7 +208,7 @@ bool _bli_array_iter_span(const void *arr, if (arr_len == 0) { return false; } - else if (use_wrap && (span_step[0] != arr_len) && (span_step[0] > span_step[1])) { + if (use_wrap && (span_step[0] != arr_len) && (span_step[0] > span_step[1])) { return false; } diff --git a/source/blender/blenlib/intern/bitmap_draw_2d.c b/source/blender/blenlib/intern/bitmap_draw_2d.c index 17debb38326..33250105c79 100644 --- a/source/blender/blenlib/intern/bitmap_draw_2d.c +++ b/source/blender/blenlib/intern/bitmap_draw_2d.c @@ -316,27 +316,25 @@ static int draw_poly_v2i_n__span_y_sort(const void *a_p, const void *b_p, void * if (co_a[1] < co_b[1]) { return -1; } - else if (co_a[1] > co_b[1]) { + if (co_a[1] > co_b[1]) { return 1; } - else if (co_a[0] < co_b[0]) { + if (co_a[0] < co_b[0]) { return -1; } - else if (co_a[0] > co_b[0]) { + if (co_a[0] > co_b[0]) { return 1; } - else { - /* co_a & co_b are identical, use the line closest to the x-min */ - const int *co = co_a; - co_a = verts[a[1]]; - co_b = verts[b[1]]; - int ord = (((co_b[0] - co[0]) * (co_a[1] - co[1])) - ((co_a[0] - co[0]) * (co_b[1] - co[1]))); - if (ord > 0) { - return -1; - } - if (ord < 0) { - return 1; - } + /* co_a & co_b are identical, use the line closest to the x-min */ + const int *co = co_a; + co_a = verts[a[1]]; + co_b = verts[b[1]]; + int ord = (((co_b[0] - co[0]) * (co_a[1] - co[1])) - ((co_a[0] - co[0]) * (co_b[1] - co[1]))); + if (ord > 0) { + return -1; + } + if (ord < 0) { + return 1; } return 0; } diff --git a/source/blender/blenlib/intern/boxpack_2d.c b/source/blender/blenlib/intern/boxpack_2d.c index 83866f766df..5bcb0c0322a 100644 --- a/source/blender/blenlib/intern/boxpack_2d.c +++ b/source/blender/blenlib/intern/boxpack_2d.c @@ -216,7 +216,7 @@ static int box_areasort(const void *p1, const void *p2) if (a1 < a2) { return 1; } - else if (a1 > a2) { + if (a1 > a2) { return -1; } return 0; @@ -246,10 +246,10 @@ static int vertex_sort(const void *p1, const void *p2, void *vs_ctx_p) if (UNLIKELY(v1->free == 0 && v2->free == 0)) { return 0; } - else if (UNLIKELY(v1->free == 0)) { + if (UNLIKELY(v1->free == 0)) { return 1; } - else if (UNLIKELY(v2->free == 0)) { + if (UNLIKELY(v2->free == 0)) { return -1; } #endif @@ -266,7 +266,7 @@ static int vertex_sort(const void *p1, const void *p2, void *vs_ctx_p) if (a1 > a2) { return 1; } - else if (a1 < a2) { + if (a1 < a2) { return -1; } return 0; diff --git a/source/blender/blenlib/intern/convexhull_2d.c b/source/blender/blenlib/intern/convexhull_2d.c index b37dc73db29..6e4a8623077 100644 --- a/source/blender/blenlib/intern/convexhull_2d.c +++ b/source/blender/blenlib/intern/convexhull_2d.c @@ -115,9 +115,7 @@ int BLI_convexhull_2d_sorted(const float (*points)[2], const int n, int r_points if (is_left(points[r_points[top - 1]], points[r_points[top]], points[i]) > 0.0f) { break; /* points[i] is a new hull vertex */ } - else { - top--; /* pop top point off stack */ - } + top--; /* pop top point off stack */ } r_points[++top] = i; /* push points[i] onto stack */ @@ -141,9 +139,7 @@ int BLI_convexhull_2d_sorted(const float (*points)[2], const int n, int r_points if (is_left(points[r_points[top - 1]], points[r_points[top]], points[i]) > 0.0f) { break; /* points[i] is a new hull vertex */ } - else { - top--; /* pop top point off stack */ - } + top--; /* pop top point off stack */ } if (points[i][0] == points[r_points[0]][0] && points[i][1] == points[r_points[0]][1]) { @@ -172,20 +168,17 @@ static int pointref_cmp_yx(const void *a_, const void *b_) if (a->pt[1] > b->pt[1]) { return 1; } - else if (a->pt[1] < b->pt[1]) { + 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]) { + if (a->pt[0] < b->pt[0]) { return -1; } - - else { - return 0; - } + return 0; } /** diff --git a/source/blender/blenlib/intern/delaunay_2d.c b/source/blender/blenlib/intern/delaunay_2d.c index 5f663dcb2e1..7199e461c6c 100644 --- a/source/blender/blenlib/intern/delaunay_2d.c +++ b/source/blender/blenlib/intern/delaunay_2d.c @@ -600,19 +600,19 @@ static int site_lexicographic_cmp(const void *a, const void *b) if (co1[0] < co2[0]) { return -1; } - else if (co1[0] > co2[0]) { + if (co1[0] > co2[0]) { return 1; } - else if (co1[1] < co2[1]) { + if (co1[1] < co2[1]) { return -1; } - else if (co1[1] > co2[1]) { + if (co1[1] > co2[1]) { return 1; } - else if (s1->orig_index < s2->orig_index) { + if (s1->orig_index < s2->orig_index) { return -1; } - else if (s1->orig_index > s2->orig_index) { + if (s1->orig_index > s2->orig_index) { return 1; } return 0; @@ -974,7 +974,7 @@ static void initial_triangulation(CDT_state *cdt) if (jco[0] > xend) { break; /* No more j's to process. */ } - else if (jco[1] > yend) { + if (jco[1] > yend) { /* Get past any string of v's with the same x and too-big y. */ xcur = jco[0]; while (++j < n) { @@ -1414,7 +1414,7 @@ static bool get_next_crossing_from_vert(CDT_state *cdt, ok = true; break; } - else if (t->face != cdt->outer_face) { + if (t->face != cdt->outer_face) { orient2 = orient2d(vcur->co, vb->co, v2->co); #ifdef DEBUG_CDT if (dbg_level > 1) { @@ -1683,14 +1683,12 @@ static void add_edge_constraint( (cd_prev->lambda != 0.0 && cd_prev->in->vert != v && cd_prev->in->next->vert != v)) { break; } - else { - cd_prev->lambda = -1.0; /* Mark cd_prev as 'deleted'. */ + cd_prev->lambda = -1.0; /* Mark cd_prev as 'deleted'. */ #ifdef DEBUG_CDT - if (dbg_level > 0) { - fprintf(stderr, "deleted crossing %d\n", j); - } -#endif + if (dbg_level > 0) { + fprintf(stderr, "deleted crossing %d\n", j); } +#endif } if (j < i - 1) { /* Some crossings were deleted. Fix the in and out edges across gap. */ @@ -2002,19 +2000,19 @@ static int evl_cmp(const void *a, const void *b) if (area->e_id < sb->e_id) { return -1; } - else if (area->e_id > sb->e_id) { + if (area->e_id > sb->e_id) { return 1; } - else if (area->lambda < sb->lambda) { + if (area->lambda < sb->lambda) { return -1; } - else if (area->lambda > sb->lambda) { + if (area->lambda > sb->lambda) { return 1; } - else if (area->v_id < sb->v_id) { + if (area->v_id < sb->v_id) { return -1; } - else if (area->v_id > sb->v_id) { + if (area->v_id > sb->v_id) { return 1; } return 0; @@ -2386,9 +2384,7 @@ static const CDT_input *modify_input_for_near_edge_ends(const CDT_input *input, if (new_input != NULL) { return (const CDT_input *)new_input; } - else { - return input; - } + return input; } static void free_modified_input(CDT_input *input) @@ -2745,7 +2741,7 @@ static int edge_to_sort_cmp(const void *a, const void *b) if (e1->len_squared > e2->len_squared) { return -1; } - else if (e1->len_squared < e2->len_squared) { + if (e1->len_squared < e2->len_squared) { return 1; } return 0; @@ -4570,17 +4566,13 @@ static double orient2d(const double *pa, const double *pb, const double *pc) if (detright <= 0.0) { return det; } - else { - detsum = detleft + detright; - } + detsum = detleft + detright; } else if (detleft < 0.0) { if (detright >= 0.0) { return det; } - else { - detsum = -detleft - detright; - } + detsum = -detleft - detright; } else { return det; diff --git a/source/blender/blenlib/intern/dot_export.cc b/source/blender/blenlib/intern/dot_export.cc index 8e4aafa4bb8..9ffb1895d04 100644 --- a/source/blender/blenlib/intern/dot_export.cc +++ b/source/blender/blenlib/intern/dot_export.cc @@ -60,7 +60,7 @@ void Cluster::set_parent_cluster(Cluster *new_parent) if (parent_ == new_parent) { return; } - else if (parent_ == nullptr) { + if (parent_ == nullptr) { graph_.top_level_clusters_.remove(this); new_parent->children_.add_new(this); } @@ -80,7 +80,7 @@ void Node::set_parent_cluster(Cluster *cluster) if (cluster_ == cluster) { return; } - else if (cluster_ == nullptr) { + if (cluster_ == nullptr) { graph_.top_level_nodes_.remove(this); cluster->nodes_.add_new(this); } diff --git a/source/blender/blenlib/intern/easing.c b/source/blender/blenlib/intern/easing.c index 9532f78bd44..07aafc1b57b 100644 --- a/source/blender/blenlib/intern/easing.c +++ b/source/blender/blenlib/intern/easing.c @@ -72,18 +72,16 @@ float BLI_easing_bounce_ease_out(float time, float begin, float change, float du if (time < (1 / 2.75f)) { return change * (7.5625f * time * time) + begin; } - else if (time < (2 / 2.75f)) { + if (time < (2 / 2.75f)) { time -= (1.5f / 2.75f); return change * ((7.5625f * time) * time + 0.75f) + begin; } - else if (time < (2.5f / 2.75f)) { + if (time < (2.5f / 2.75f)) { time -= (2.25f / 2.75f); return change * ((7.5625f * time) * time + 0.9375f) + begin; } - else { - time -= (2.625f / 2.75f); - return change * ((7.5625f * time) * time + 0.984375f) + begin; - } + time -= (2.625f / 2.75f); + return change * ((7.5625f * time) * time + 0.984375f) + begin; } float BLI_easing_bounce_ease_in(float time, float begin, float change, float duration) @@ -96,10 +94,8 @@ float BLI_easing_bounce_ease_in_out(float time, float begin, float change, float if (time < duration / 2) { return BLI_easing_bounce_ease_in(time * 2, 0, change, duration) * 0.5f + begin; } - else { - return BLI_easing_bounce_ease_out(time * 2 - duration, 0, change, duration) * 0.5f + - change * 0.5f + begin; - } + 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) @@ -271,13 +267,12 @@ float BLI_easing_elastic_ease_in_out( sinf((time * duration - s) * (2 * (float)M_PI) / period))) + begin; } - else { - time = -time; - f *= 0.5f; - return (f * (amplitude * powf(2, 10 * time) * - sinf((time * duration - s) * (2 * (float)M_PI) / period))) + - change + begin; - } + + time = -time; + f *= 0.5f; + return (f * (amplitude * powf(2, 10 * time) * + sinf((time * duration - s) * (2 * (float)M_PI) / period))) + + change + begin; } static const float pow_min = 0.0009765625f; /* = 2^(-10) */ @@ -306,10 +301,8 @@ float BLI_easing_expo_ease_in_out(float time, float begin, float change, float d if (time <= duration_half) { return BLI_easing_expo_ease_in(time, begin, change_half, duration_half); } - else { - return BLI_easing_expo_ease_out( - time - duration_half, begin + change_half, change_half, duration_half); - } + return BLI_easing_expo_ease_out( + time - duration_half, begin + change_half, change_half, duration_half); } float BLI_easing_linear_ease(float time, float begin, float change, float duration) diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 56529581dd3..05ee02ad869 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -185,7 +185,7 @@ BLI_INLINE EdgeHashEntry *edgehash_insert(EdgeHash *eh, Edge edge, void *value) if (index == SLOT_EMPTY) { return edgehash_insert_at_slot(eh, slot, edge, value); } - else if (index == SLOT_DUMMY) { + if (index == SLOT_DUMMY) { eh->dummy_count--; return edgehash_insert_at_slot(eh, slot, edge, value); } @@ -200,7 +200,7 @@ BLI_INLINE EdgeHashEntry *edgehash_lookup_entry(EdgeHash *eh, uint v0, uint v1) if (EH_INDEX_HAS_EDGE(eh, index, edge)) { return &eh->entries[index]; } - else if (index == SLOT_EMPTY) { + if (index == SLOT_EMPTY) { return NULL; } } @@ -294,7 +294,7 @@ bool BLI_edgehash_reinsert(EdgeHash *eh, uint v0, uint v1, void *value) eh->entries[index].value = value; return false; } - else if (index == SLOT_EMPTY) { + if (index == SLOT_EMPTY) { if (edgehash_ensure_can_insert(eh)) { edgehash_insert(eh, edge, value); } @@ -360,7 +360,7 @@ bool BLI_edgehash_ensure_p(EdgeHash *eh, uint v0, uint v1, void ***r_value) *r_value = &eh->entries[index].value; return true; } - else if (index == SLOT_EMPTY) { + if (index == SLOT_EMPTY) { if (edgehash_ensure_can_insert(eh)) { *r_value = &edgehash_insert(eh, edge, NULL)->value; } @@ -413,7 +413,7 @@ void *BLI_edgehash_popkey(EdgeHash *eh, uint v0, uint v1) } return value; } - else if (index == SLOT_EMPTY) { + if (index == SLOT_EMPTY) { return NULL; } } @@ -583,7 +583,7 @@ bool BLI_edgeset_add(EdgeSet *es, uint v0, uint v1) if (ES_INDEX_HAS_EDGE(es, index, edge)) { return false; } - else if (index == SLOT_EMPTY) { + if (index == SLOT_EMPTY) { edgeset_insert_at_slot(es, slot, edge); return true; } @@ -615,7 +615,7 @@ bool BLI_edgeset_haskey(EdgeSet *es, uint v0, uint v1) if (ES_INDEX_HAS_EDGE(es, index, edge)) { return true; } - else if (index == SLOT_EMPTY) { + if (index == SLOT_EMPTY) { return false; } } diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index e61cbd318fc..6c7383bc297 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -980,7 +980,7 @@ static int delete_soft(const char *file, const char **error_message) "Blender may not support moving files or directories to trash on your system."; return -1; } - else if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus)) { + if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus)) { *error_message = process_failed; return -1; } @@ -1036,12 +1036,10 @@ int BLI_delete(const char *file, bool dir, bool recursive) if (recursive) { return recursive_operation(file, NULL, NULL, delete_single_file, delete_callback_post); } - else if (dir) { + if (dir) { return rmdir(file); } - else { - return remove(file); - } + return remove(file); } /** @@ -1184,8 +1182,7 @@ static int copy_single_file(const char *from, const char *to) return RecursiveOp_Callback_OK; } - else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || S_ISFIFO(st.st_mode) || - S_ISSOCK(st.st_mode)) { + if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) { /* copy special type of file */ if (mknod(to, st.st_mode, st.st_rdev)) { perror("mknod"); @@ -1198,7 +1195,7 @@ static int copy_single_file(const char *from, const char *to) return RecursiveOp_Callback_OK; } - else if (!S_ISREG(st.st_mode)) { + if (!S_ISREG(st.st_mode)) { fprintf(stderr, "Copying of this kind of files isn't supported yet\n"); return RecursiveOp_Callback_Error; } @@ -1337,7 +1334,7 @@ bool BLI_dir_create_recursive(const char *dirname) if (BLI_is_dir(dirname)) { return true; } - else if (BLI_exists(dirname)) { + if (BLI_exists(dirname)) { return false; } diff --git a/source/blender/blenlib/intern/lasso_2d.c b/source/blender/blenlib/intern/lasso_2d.c index a01adf4fa6a..f2cc8d42de7 100644 --- a/source/blender/blenlib/intern/lasso_2d.c +++ b/source/blender/blenlib/intern/lasso_2d.c @@ -60,10 +60,9 @@ bool BLI_lasso_is_point_inside(const int mcoords[][2], if (sx == error_value || mcoords_len == 0) { return false; } - else { - int pt[2] = {sx, sy}; - return isect_point_poly_v2_int(pt, mcoords, mcoords_len, true); - } + + int pt[2] = {sx, sy}; + return isect_point_poly_v2_int(pt, mcoords, mcoords_len, true); } /* edge version for lasso select. we assume boundbox check was done */ diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 892eca768b3..5e88f8f3e44 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -162,9 +162,8 @@ bool BLI_remlink_safe(ListBase *listbase, void *vlink) BLI_remlink(listbase, vlink); return true; } - else { - return false; - } + + return false; } /** diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 651a062e3d5..09bb7ea5711 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -439,9 +439,8 @@ float srgb_to_linearrgb(float c) if (c < 0.04045f) { return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f); } - else { - return powf((c + 0.055f) * (1.0f / 1.055f), 2.4f); - } + + return powf((c + 0.055f) * (1.0f / 1.055f), 2.4f); } float linearrgb_to_srgb(float c) @@ -449,9 +448,8 @@ float linearrgb_to_srgb(float c) if (c < 0.0031308f) { return (c < 0.0f) ? 0.0f : c * 12.92f; } - else { - return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f; - } + + return 1.055f * powf(c, 1.0f / 2.4f) - 0.055f; } void minmax_rgb(short c[3]) diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index 7c187679ad1..ce83b522178 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -231,9 +231,8 @@ float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float if (c_len > FLT_EPSILON) { return dot_v3v3(a, b) / c_len; } - else { - return 0.0f; - } + + return 0.0f; } /********************************* Planes **********************************/ @@ -589,9 +588,8 @@ float dist_signed_squared_to_corner_v3v3v3(const float p[3], if (flip) { return min_ff(dist_a, dist_b); } - else { - return max_ff(dist_a, dist_b); - } + + return max_ff(dist_a, dist_b); } /** @@ -1146,9 +1144,8 @@ int isect_line_line_v2_point( return ISECT_LINE_LINE_CROSS; } - else { - return ISECT_LINE_LINE_COLINEAR; - } + + return ISECT_LINE_LINE_COLINEAR; } /* intersect Line-Line, floats */ @@ -1304,55 +1301,54 @@ int isect_seg_seg_v2_point_ex(const float v0[2], /* out of segment intersection */ return -1; } - else { - if ((cross_v2v2(s10, s30) == 0.0f) && (cross_v2v2(s32, s30) == 0.0f)) { - /* equal lines */ - float s20[2]; - float u_a, u_b; - - if (equals_v2v2(v0, v1)) { - if (len_squared_v2v2(v2, v3) > square_f(eps)) { - /* use non-point segment as basis */ - SWAP(const float *, v0, v2); - SWAP(const float *, v1, v3); - - sub_v2_v2v2(s10, v1, v0); - sub_v2_v2v2(s30, v3, v0); - } - else { /* both of segments are points */ - if (equals_v2v2(v0, v2)) { /* points are equal */ - copy_v2_v2(r_vi, v0); - return 1; - } - /* two different points */ - return -1; - } - } + if ((cross_v2v2(s10, s30) == 0.0f) && (cross_v2v2(s32, s30) == 0.0f)) { + /* equal lines */ + float s20[2]; + float u_a, u_b; - sub_v2_v2v2(s20, v2, v0); + if (equals_v2v2(v0, v1)) { + if (len_squared_v2v2(v2, v3) > square_f(eps)) { + /* use non-point segment as basis */ + SWAP(const float *, v0, v2); + SWAP(const float *, v1, v3); - 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) { - SWAP(float, u_a, u_b); + sub_v2_v2v2(s10, v1, v0); + sub_v2_v2v2(s30, v3, v0); } + else { /* both of segments are points */ + if (equals_v2v2(v0, v2)) { /* points are equal */ + copy_v2_v2(r_vi, v0); + return 1; + } - if (u_a > endpoint_max || u_b < endpoint_min) { - /* non-overlapping segments */ + /* two different points */ return -1; } - else if (max_ff(0.0f, u_a) == min_ff(1.0f, u_b)) { - /* one common point: can return result */ - madd_v2_v2v2fl(r_vi, v0, s10, max_ff(0, u_a)); - return 1; - } } - /* lines are collinear */ - return -1; + sub_v2_v2v2(s20, v2, v0); + + 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) { + SWAP(float, u_a, u_b); + } + + if (u_a > endpoint_max || u_b < endpoint_min) { + /* non-overlapping segments */ + return -1; + } + if (max_ff(0.0f, u_a) == min_ff(1.0f, u_b)) { + /* one common point: can return result */ + madd_v2_v2v2fl(r_vi, v0, s10, max_ff(0, u_a)); + return 1; + } } + + /* lines are collinear */ + return -1; } int isect_seg_seg_v2_point( @@ -1472,13 +1468,13 @@ int isect_line_sphere_v3(const float l1[3], /* no intersections */ return 0; } - else if (i == 0.0f) { + if (i == 0.0f) { /* one intersection */ mu = -b / (2.0f * a); madd_v3_v3v3fl(r_p1, l1, ldir, mu); return 1; } - else if (i > 0.0f) { + if (i > 0.0f) { const float i_sqrt = sqrtf(i); /* avoid calc twice */ /* first intersection */ @@ -1490,10 +1486,9 @@ int isect_line_sphere_v3(const float l1[3], madd_v3_v3v3fl(r_p2, l1, ldir, mu); return 2; } - else { - /* math domain error - nan */ - return -1; - } + + /* math domain error - nan */ + return -1; } /* keep in sync with isect_line_sphere_v3 */ @@ -1520,13 +1515,13 @@ int isect_line_sphere_v2(const float l1[2], /* no intersections */ return 0; } - else if (i == 0.0f) { + if (i == 0.0f) { /* one intersection */ mu = -b / (2.0f * a); madd_v2_v2v2fl(r_p1, l1, ldir, mu); return 1; } - else if (i > 0.0f) { + if (i > 0.0f) { const float i_sqrt = sqrtf(i); /* avoid calc twice */ /* first intersection */ @@ -1538,10 +1533,9 @@ int isect_line_sphere_v2(const float l1[2], madd_v2_v2v2fl(r_p2, l1, ldir, mu); return 2; } - else { - /* math domain error - nan */ - return -1; - } + + /* math domain error - nan */ + return -1; } /* point in polygon (keep float and int versions in sync) */ @@ -1957,34 +1951,32 @@ bool isect_ray_tri_watertight_v3(const float ray_origin[3], if (UNLIKELY(det == 0.0f || !isfinite(det))) { return false; } - else { - /* Calculate scaled z-coordinates of vertices and use them to calculate - * the hit distance. - */ - const int sign_det = (float_as_int(det) & (int)0x80000000); - const float t = (u * a_kz + v * b_kz + w * c_kz) * sz; - const float sign_t = xor_fl(t, sign_det); - if ((sign_t < 0.0f) - /* Differ from Cycles, don't read r_lambda's original value - * otherwise we won't match any of the other intersect functions here... - * which would be confusing. */ + + /* Calculate scaled z-coordinates of vertices and use them to calculate + * the hit distance. + */ + const int sign_det = (float_as_int(det) & (int)0x80000000); + const float t = (u * a_kz + v * b_kz + w * c_kz) * sz; + const float sign_t = xor_fl(t, sign_det); + if ((sign_t < 0.0f) + /* Differ from Cycles, don't read r_lambda's original value + * otherwise we won't match any of the other intersect functions here... + * which would be confusing. */ #if 0 || (sign_T > *r_lambda * xor_signmask(det, sign_mask)) #endif - ) { - return false; - } - else { - /* Normalize u, v and t. */ - const float inv_det = 1.0f / det; - if (r_uv) { - r_uv[0] = u * inv_det; - r_uv[1] = v * inv_det; - } - *r_lambda = t * inv_det; - return true; - } + ) { + return false; + } + + /* Normalize u, v and t. */ + const float inv_det = 1.0f / det; + if (r_uv) { + r_uv[0] = u * inv_det; + r_uv[1] = v * inv_det; } + *r_lambda = t * inv_det; + return true; } bool isect_ray_tri_watertight_v3_simple(const float ray_origin[3], @@ -2215,10 +2207,9 @@ bool isect_line_plane_v3(float r_isect_co[3], madd_v3_v3v3fl(r_isect_co, l1, u, lambda); return true; } - else { - /* The segment is parallel to plane */ - return false; - } + + /* The segment is parallel to plane */ + return false; } /** @@ -2257,9 +2248,8 @@ bool isect_plane_plane_plane_v3(const float plane_a[4], return true; } - else { - return false; - } + + return false; } /** @@ -2303,9 +2293,8 @@ bool isect_plane_plane_v3(const float plane_a[4], return true; } - else { - return false; - } + + return false; } /** @@ -2436,65 +2425,54 @@ static bool isect_tri_tri_v2_impl_vert(const float t_a0[2], if (line_point_side_v2(t_a0, t_b1, t_a1) <= 0.0f) { return 1; } - else { - return 0; - } + + return 0; } - else { - if (line_point_side_v2(t_a0, t_b0, t_a2) >= 0.0f) { - if (line_point_side_v2(t_a1, t_a2, t_b0) >= 0.0f) { - return 1; - } - else { - return 0; - } - } - else { - return 0; + + if (line_point_side_v2(t_a0, t_b0, t_a2) >= 0.0f) { + if (line_point_side_v2(t_a1, t_a2, t_b0) >= 0.0f) { + return 1; } + + return 0; } + + return 0; } - else if (line_point_side_v2(t_a0, t_b1, t_a1) <= 0.0f) { + if (line_point_side_v2(t_a0, t_b1, t_a1) <= 0.0f) { if (line_point_side_v2(t_b2, t_b1, t_a2) <= 0.0f) { if (line_point_side_v2(t_a1, t_a2, t_b1) >= 0.0f) { return 1; } - else { - return 0; - } - } - else { + return 0; } - } - else { + return 0; } + + return 0; } - else if (line_point_side_v2(t_b2, t_b0, t_a2) >= 0.0f) { + if (line_point_side_v2(t_b2, t_b0, t_a2) >= 0.0f) { if (line_point_side_v2(t_a1, t_a2, t_b2) >= 0.0f) { if (line_point_side_v2(t_a0, t_b0, t_a2) >= 0.0f) { return 1; } - else { - return 0; - } + + return 0; } - else if (line_point_side_v2(t_a1, t_a2, t_b1) >= 0.0f) { + if (line_point_side_v2(t_a1, t_a2, t_b1) >= 0.0f) { if (line_point_side_v2(t_b2, t_a2, t_b1) >= 0.0f) { return 1; } - else { - return 0; - } - } - else { + return 0; } - } - else { + return 0; } + + return 0; } static bool isect_tri_tri_v2_impl_edge(const float t_a0[2], @@ -2511,47 +2489,38 @@ static bool isect_tri_tri_v2_impl_edge(const float t_a0[2], if (line_point_side_v2(t_a0, t_a1, t_b2) >= 0.0f) { return 1; } - else { - return 0; - } + + return 0; } - else { - if (line_point_side_v2(t_a1, t_a2, t_b0) >= 0.0f) { - if (line_point_side_v2(t_a2, t_a0, t_b0) >= 0.0f) { - return 1; - } - else { - return 0; - } - } - else { - return 0; + + if (line_point_side_v2(t_a1, t_a2, t_b0) >= 0.0f) { + if (line_point_side_v2(t_a2, t_a0, t_b0) >= 0.0f) { + return 1; } + + return 0; } + + return 0; } - else { - if (line_point_side_v2(t_b2, t_b0, t_a2) >= 0.0f) { - if (line_point_side_v2(t_a0, t_b0, t_a2) >= 0.0f) { - if (line_point_side_v2(t_a0, t_a2, t_b2) >= 0.0f) { - return 1; - } - else { - if (line_point_side_v2(t_a1, t_a2, t_b2) >= 0.0f) { - return 1; - } - else { - return 0; - } - } + + if (line_point_side_v2(t_b2, t_b0, t_a2) >= 0.0f) { + if (line_point_side_v2(t_a0, t_b0, t_a2) >= 0.0f) { + if (line_point_side_v2(t_a0, t_a2, t_b2) >= 0.0f) { + return 1; } - else { - return 0; + + if (line_point_side_v2(t_a1, t_a2, t_b2) >= 0.0f) { + return 1; } - } - else { + return 0; } + + return 0; } + + return 0; } static int isect_tri_tri_impl_ccw_v2(const float t_a0[2], @@ -2566,32 +2535,26 @@ static int isect_tri_tri_impl_ccw_v2(const float t_a0[2], if (line_point_side_v2(t_b2, t_b0, t_a0) >= 0.0f) { return 1; } - else { - return isect_tri_tri_v2_impl_edge(t_a0, t_a1, t_a2, t_b0, t_b1, t_b2); - } + + return isect_tri_tri_v2_impl_edge(t_a0, t_a1, t_a2, t_b0, t_b1, t_b2); } - else { - if (line_point_side_v2(t_b2, t_b0, t_a0) >= 0.0f) { - return isect_tri_tri_v2_impl_edge(t_a0, t_a1, t_a2, t_b2, t_b0, t_b1); - } - else { - return isect_tri_tri_v2_impl_vert(t_a0, t_a1, t_a2, t_b0, t_b1, t_b2); - } + + if (line_point_side_v2(t_b2, t_b0, t_a0) >= 0.0f) { + return isect_tri_tri_v2_impl_edge(t_a0, t_a1, t_a2, t_b2, t_b0, t_b1); } + + return isect_tri_tri_v2_impl_vert(t_a0, t_a1, t_a2, t_b0, t_b1, t_b2); } - else { - if (line_point_side_v2(t_b1, t_b2, t_a0) >= 0.0f) { - if (line_point_side_v2(t_b2, t_b0, t_a0) >= 0.0f) { - return isect_tri_tri_v2_impl_edge(t_a0, t_a1, t_a2, t_b1, t_b2, t_b0); - } - else { - return isect_tri_tri_v2_impl_vert(t_a0, t_a1, t_a2, t_b1, t_b2, t_b0); - } - } - else { - return isect_tri_tri_v2_impl_vert(t_a0, t_a1, t_a2, t_b2, t_b0, t_b1); + + if (line_point_side_v2(t_b1, t_b2, t_a0) >= 0.0f) { + if (line_point_side_v2(t_b2, t_b0, t_a0) >= 0.0f) { + return isect_tri_tri_v2_impl_edge(t_a0, t_a1, t_a2, t_b1, t_b2, t_b0); } + + return isect_tri_tri_v2_impl_vert(t_a0, t_a1, t_a2, t_b1, t_b2, t_b0); } + + return isect_tri_tri_v2_impl_vert(t_a0, t_a1, t_a2, t_b2, t_b0, t_b1); } bool isect_tri_tri_v2(const float t_a0[2], @@ -2605,18 +2568,15 @@ bool isect_tri_tri_v2(const float t_a0[2], if (line_point_side_v2(t_b0, t_b1, t_b2) < 0.0f) { return isect_tri_tri_impl_ccw_v2(t_a0, t_a2, t_a1, t_b0, t_b2, t_b1); } - else { - return isect_tri_tri_impl_ccw_v2(t_a0, t_a2, t_a1, t_b0, t_b1, t_b2); - } + + return isect_tri_tri_impl_ccw_v2(t_a0, t_a2, t_a1, t_b0, t_b1, t_b2); } - else { - if (line_point_side_v2(t_b0, t_b1, t_b2) < 0.0f) { - return isect_tri_tri_impl_ccw_v2(t_a0, t_a1, t_a2, t_b0, t_b2, t_b1); - } - else { - return isect_tri_tri_impl_ccw_v2(t_a0, t_a1, t_a2, t_b0, t_b1, t_b2); - } + + if (line_point_side_v2(t_b0, t_b1, t_b2) < 0.0f) { + return isect_tri_tri_impl_ccw_v2(t_a0, t_a1, t_a2, t_b0, t_b2, t_b1); } + + return isect_tri_tri_impl_ccw_v2(t_a0, t_a1, t_a2, t_b0, t_b1, t_b2); } /** \} */ @@ -2682,8 +2642,7 @@ int isect_aabb_planes_v3(const float (*planes)[4], if (plane_point_side_v3(planes[i], bb_far) < 0.0f) { return ISECT_AABB_PLANE_BEHIND_ANY; } - else if ((ret != ISECT_AABB_PLANE_CROSS_ANY) && - (plane_point_side_v3(planes[i], bb_near) < 0.0f)) { + if ((ret != ISECT_AABB_PLANE_CROSS_ANY) && (plane_point_side_v3(planes[i], bb_near) < 0.0f)) { ret = ISECT_AABB_PLANE_CROSS_ANY; } } @@ -2967,7 +2926,7 @@ int isect_line_line_epsilon_v3(const float v1[3], return 0; } /* test if the two lines are coplanar */ - else if (UNLIKELY(fabsf(d) <= epsilon)) { + if (UNLIKELY(fabsf(d) <= epsilon)) { cross_v3_v3v3(cb, c, b); mul_v3_fl(a, dot_v3v3(cb, ab) / div); @@ -2977,34 +2936,33 @@ int isect_line_line_epsilon_v3(const float v1[3], return 1; /* one intersection only */ } /* if not */ - else { - float n[3], t[3]; - float v3t[3], v4t[3]; - sub_v3_v3v3(t, v1, v3); - /* offset between both plane where the lines lies */ - cross_v3_v3v3(n, a, b); - project_v3_v3v3(t, t, n); + float n[3], t[3]; + float v3t[3], v4t[3]; + sub_v3_v3v3(t, v1, v3); - /* for the first line, offset the second line until it is coplanar */ - add_v3_v3v3(v3t, v3, t); - add_v3_v3v3(v4t, v4, t); + /* offset between both plane where the lines lies */ + cross_v3_v3v3(n, a, b); + project_v3_v3v3(t, t, n); - sub_v3_v3v3(c, v3t, v1); - sub_v3_v3v3(a, v2, v1); - sub_v3_v3v3(b, v4t, v3t); + /* for the first line, offset the second line until it is coplanar */ + add_v3_v3v3(v3t, v3, t); + add_v3_v3v3(v4t, v4, t); - cross_v3_v3v3(ab, a, b); - cross_v3_v3v3(cb, c, b); + sub_v3_v3v3(c, v3t, v1); + sub_v3_v3v3(a, v2, v1); + sub_v3_v3v3(b, v4t, v3t); - mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab)); - add_v3_v3v3(r_i1, v1, a); + cross_v3_v3v3(ab, a, b); + cross_v3_v3v3(cb, c, b); - /* for the second line, just subtract the offset from the first intersection point */ - sub_v3_v3v3(r_i2, r_i1, t); + mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab)); + add_v3_v3v3(r_i1, v1, a); - return 2; /* two nearest points */ - } + /* for the second line, just subtract the offset from the first intersection point */ + sub_v3_v3v3(r_i2, r_i1, t); + + return 2; /* two nearest points */ } int isect_line_line_v3(const float v1[3], @@ -3047,31 +3005,29 @@ bool isect_line_line_strict_v3(const float v1[3], return false; } /* test if the two lines are coplanar */ - else if (UNLIKELY(fabsf(d) < epsilon)) { + if (UNLIKELY(fabsf(d) < epsilon)) { return false; } - else { - float f1, f2; - cross_v3_v3v3(cb, c, b); - cross_v3_v3v3(ca, c, a); - f1 = dot_v3v3(cb, ab) / div; - f2 = dot_v3v3(ca, ab) / div; + float f1, f2; + cross_v3_v3v3(cb, c, b); + cross_v3_v3v3(ca, c, a); - if (f1 >= 0 && f1 <= 1 && f2 >= 0 && f2 <= 1) { - mul_v3_fl(a, f1); - add_v3_v3v3(vi, v1, a); + f1 = dot_v3v3(cb, ab) / div; + f2 = dot_v3v3(ca, ab) / div; - if (r_lambda) { - *r_lambda = f1; - } + if (f1 >= 0 && f1 <= 1 && f2 >= 0 && f2 <= 1) { + mul_v3_fl(a, f1); + add_v3_v3v3(vi, v1, a); - return true; /* intersection found */ - } - else { - return false; + if (r_lambda) { + *r_lambda = f1; } + + return true; /* intersection found */ } + + return false; } /** @@ -3237,15 +3193,14 @@ bool isect_ray_aabb_v3_simple(const float orig[3], if ((hit_dist[1] < 0.0f || hit_dist[0] > hit_dist[1])) { return false; } - else { - if (tmin) { - *tmin = hit_dist[0]; - } - if (tmax) { - *tmax = hit_dist[1]; - } - return true; + + if (tmin) { + *tmin = hit_dist[0]; + } + if (tmax) { + *tmax = hit_dist[1]; } + return true; } float closest_to_ray_v3(float r_close[3], @@ -3522,9 +3477,8 @@ bool isect_point_tri_v3( return true; } - else { - return false; - } + + return false; } bool clip_segment_v3_plane( @@ -3547,7 +3501,7 @@ bool clip_segment_v3_plane( if (t >= div) { return false; } - else if (t > 0.0f) { + if (t > 0.0f) { const float p1_copy[3] = {UNPACK3(p1)}; copy_v3_v3(r_p2, p2); madd_v3_v3v3fl(r_p1, p1_copy, dp, t / div); @@ -3559,7 +3513,7 @@ bool clip_segment_v3_plane( if (t >= 0.0f) { return false; } - else if (t > div) { + if (t > div) { const float p1_copy[3] = {UNPACK3(p1)}; copy_v3_v3(r_p1, p1); madd_v3_v3v3fl(r_p2, p1_copy, dp, t / div); @@ -3598,7 +3552,7 @@ bool clip_segment_v3_plane_n(const float p1[3], if (t >= div) { return false; } - else if (t > 0.0f) { + if (t > 0.0f) { t /= div; if (t > p1_fac) { p1_fac = t; @@ -3613,7 +3567,7 @@ bool clip_segment_v3_plane_n(const float p1[3], if (t >= 0.0f) { return false; } - else if (t > div) { + if (t > div) { t /= div; if (t < p2_fac) { p2_fac = t; @@ -3797,8 +3751,8 @@ int barycentric_inside_triangle_v2(const float w[3]) if (IN_RANGE(w[0], 0.0f, 1.0f) && IN_RANGE(w[1], 0.0f, 1.0f) && IN_RANGE(w[2], 0.0f, 1.0f)) { return 1; } - else if (IN_RANGE_INCL(w[0], 0.0f, 1.0f) && IN_RANGE_INCL(w[1], 0.0f, 1.0f) && - IN_RANGE_INCL(w[2], 0.0f, 1.0f)) { + if (IN_RANGE_INCL(w[0], 0.0f, 1.0f) && IN_RANGE_INCL(w[1], 0.0f, 1.0f) && + IN_RANGE_INCL(w[2], 0.0f, 1.0f)) { return 2; } @@ -4095,68 +4049,67 @@ int interp_sparse_array(float *array, const int list_size, const float skipval) if (found_valid == 0) { return -1; } - else if (found_invalid == 0) { + if (found_invalid == 0) { return 0; } - else { - /* found invalid depths, interpolate */ - float valid_last = skipval; - int valid_ofs = 0; - float *array_up = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up"); - float *array_down = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up"); + /* found invalid depths, interpolate */ + float valid_last = skipval; + int valid_ofs = 0; - int *ofs_tot_up = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tup"); - int *ofs_tot_down = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tdown"); + float *array_up = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up"); + float *array_down = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up"); - for (i = 0; i < list_size; i++) { - if (array[i] == skipval) { - array_up[i] = valid_last; - ofs_tot_up[i] = ++valid_ofs; - } - else { - valid_last = array[i]; - valid_ofs = 0; - } + int *ofs_tot_up = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tup"); + int *ofs_tot_down = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tdown"); + + for (i = 0; i < list_size; i++) { + if (array[i] == skipval) { + array_up[i] = valid_last; + ofs_tot_up[i] = ++valid_ofs; + } + else { + valid_last = array[i]; + valid_ofs = 0; } + } - valid_last = skipval; - valid_ofs = 0; + valid_last = skipval; + valid_ofs = 0; - for (i = list_size - 1; i >= 0; i--) { - if (array[i] == skipval) { - array_down[i] = valid_last; - ofs_tot_down[i] = ++valid_ofs; - } - else { - valid_last = array[i]; - valid_ofs = 0; - } + for (i = list_size - 1; i >= 0; i--) { + if (array[i] == skipval) { + array_down[i] = valid_last; + ofs_tot_down[i] = ++valid_ofs; + } + else { + valid_last = array[i]; + valid_ofs = 0; } + } - /* now blend */ - for (i = 0; i < list_size; i++) { - if (array[i] == skipval) { - if (array_up[i] != skipval && array_down[i] != skipval) { - array[i] = ((array_up[i] * (float)ofs_tot_down[i]) + - (array_down[i] * (float)ofs_tot_up[i])) / - (float)(ofs_tot_down[i] + ofs_tot_up[i]); - } - else if (array_up[i] != skipval) { - array[i] = array_up[i]; - } - else if (array_down[i] != skipval) { - array[i] = array_down[i]; - } + /* now blend */ + for (i = 0; i < list_size; i++) { + if (array[i] == skipval) { + if (array_up[i] != skipval && array_down[i] != skipval) { + array[i] = ((array_up[i] * (float)ofs_tot_down[i]) + + (array_down[i] * (float)ofs_tot_up[i])) / + (float)(ofs_tot_down[i] + ofs_tot_up[i]); + } + else if (array_up[i] != skipval) { + array[i] = array_up[i]; + } + else if (array_down[i] != skipval) { + array[i] = array_down[i]; } } + } - MEM_freeN(array_up); - MEM_freeN(array_down); + MEM_freeN(array_up); + MEM_freeN(array_down); - MEM_freeN(ofs_tot_up); - MEM_freeN(ofs_tot_down); - } + MEM_freeN(ofs_tot_up); + MEM_freeN(ofs_tot_down); return 1; } @@ -4279,7 +4232,7 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[ ix_flag = IS_POINT_IX; break; } - else if (UNLIKELY(dist_squared_to_line_segment_v3(co, v_curr, v_next) < eps_sq)) { + if (UNLIKELY(dist_squared_to_line_segment_v3(co, v_curr, v_next) < eps_sq)) { ix_flag = IS_SEGMENT_IX; break; } @@ -4364,7 +4317,7 @@ void interp_weights_poly_v2(float *w, float v[][2], const int n, const float co[ ix_flag = IS_POINT_IX; break; } - else if (UNLIKELY(dist_squared_to_line_segment_v2(co, v_curr, v_next) < eps_sq)) { + if (UNLIKELY(dist_squared_to_line_segment_v2(co, v_curr, v_next) < eps_sq)) { ix_flag = IS_SEGMENT_IX; break; } @@ -4647,17 +4600,15 @@ float resolve_quad_u_v2(const float st[2], if (IS_ZERO(fDen) == 0) { return (float)(a / fDen); } - else { - return 0.0f; - } - } - else { - const double desc_sq = b * b - a * fC; - const double desc = sqrt(desc_sq < 0.0 ? 0.0 : desc_sq); - const double s = signed_area > 0 ? (-1.0) : 1.0; - return (float)(((a - b) + s * desc) / denom); + return 0.0f; } + + const double desc_sq = b * b - a * fC; + const double desc = sqrt(desc_sq < 0.0 ? 0.0 : desc_sq); + const double s = signed_area > 0 ? (-1.0) : 1.0; + + return (float)(((a - b) + s * desc) / denom); } #undef IS_ZERO @@ -6139,17 +6090,16 @@ float cubic_tangent_factor_circle_v3(const float tan_l[3], const float tan_r[3]) /* no angle difference (use fallback, length wont make any difference) */ return (1.0f / 3.0f) * 0.75f; } - else if (tan_dot < -1.0f + eps) { + if (tan_dot < -1.0f + eps) { /* parallele tangents (half-circle) */ return (1.0f / 2.0f); } - else { - /* non-aligned tangents, calculate handle length */ - const float angle = acosf(tan_dot) / 2.0f; - /* could also use 'angle_sin = len_vnvn(tan_l, tan_r, dims) / 2.0' */ - const float angle_sin = sinf(angle); - const float angle_cos = cosf(angle); - return ((1.0f - angle_cos) / (angle_sin * 2.0f)) / angle_sin; - } + /* non-aligned tangents, calculate handle length */ + const float angle = acosf(tan_dot) / 2.0f; + + /* could also use 'angle_sin = len_vnvn(tan_l, tan_r, dims) / 2.0' */ + const float angle_sin = sinf(angle); + const float angle_cos = cosf(angle); + return ((1.0f - angle_cos) / (angle_sin * 2.0f)) / angle_sin; } diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index a2f7cc24dd3..a6368981050 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -644,9 +644,8 @@ float angle_signed_normalized_qt(const float q[4]) if (q[0] >= 0.0f) { return 2.0f * saacos(q[0]); } - else { - return -2.0f * saacos(-q[0]); - } + + return -2.0f * saacos(-q[0]); } float angle_signed_normalized_qtqt(const float q1[4], const float q2[4]) @@ -654,11 +653,10 @@ float angle_signed_normalized_qtqt(const float q1[4], const float q2[4]) if (dot_qtqt(q1, q2) >= 0.0f) { return angle_normalized_qtqt(q1, q2); } - else { - float q2_copy[4]; - negate_v4_v4(q2_copy, q2); - return -angle_normalized_qtqt(q1, q2_copy); - } + + float q2_copy[4]; + negate_v4_v4(q2_copy, q2); + return -angle_normalized_qtqt(q1, q2_copy); } float angle_signed_qt(const float q[4]) @@ -675,11 +673,10 @@ float angle_signed_qtqt(const float q1[4], const float q2[4]) if (dot_qtqt(q1, q2) >= 0.0f) { return angle_qtqt(q1, q2); } - else { - float q2_copy[4]; - negate_v4_v4(q2_copy, q2); - return -angle_qtqt(q1, q2_copy); - } + + float q2_copy[4]; + negate_v4_v4(q2_copy, q2); + return -angle_qtqt(q1, q2_copy); } /** \} */ @@ -1594,12 +1591,11 @@ static const RotOrderInfo *get_rotation_order_info(const short order) if (order < 1) { return &rotOrders[0]; } - else if (order < 6) { + if (order < 6) { return &rotOrders[order - 1]; } - else { - return &rotOrders[5]; - } + + return &rotOrders[5]; } /* Construct quaternion from Euler angles (in radians). */ diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 7f1840228e2..909d508e262 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -506,11 +506,10 @@ float angle_normalized_v3v3(const float v1[3], const float v2[3]) if (dot_v3v3(v1, v2) >= 0.0f) { return 2.0f * saasin(len_v3v3(v1, v2) / 2.0f); } - else { - float v2_n[3]; - negate_v3_v3(v2_n, v2); - return (float)M_PI - 2.0f * saasin(len_v3v3(v1, v2_n) / 2.0f); - } + + float v2_n[3]; + negate_v3_v3(v2_n, v2); + return (float)M_PI - 2.0f * saasin(len_v3v3(v1, v2_n) / 2.0f); } float angle_normalized_v2v2(const float v1[2], const float v2[2]) @@ -523,11 +522,10 @@ float angle_normalized_v2v2(const float v1[2], const float v2[2]) if (dot_v2v2(v1, v2) >= 0.0f) { return 2.0f * saasin(len_v2v2(v1, v2) / 2.0f); } - else { - float v2_n[2]; - negate_v2_v2(v2_n, v2); - return (float)M_PI - 2.0f * saasin(len_v2v2(v1, v2_n) / 2.0f); - } + + float v2_n[2]; + negate_v2_v2(v2_n, v2); + return (float)M_PI - 2.0f * saasin(len_v2v2(v1, v2_n) / 2.0f); } /** diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index d912cb8d464..67d41ffb779 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -427,9 +427,8 @@ static int BLI_path_unc_prefix_len(const char *path) /* we assume long UNC path like \\?\server\share\folder etc... */ return 4; } - else { - return 2; - } + + return 2; } return 0; @@ -683,7 +682,7 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char has_extension = true; break; } - else if (ELEM(string[a], '/', '\\')) { + if (ELEM(string[a], '/', '\\')) { break; } } @@ -713,9 +712,8 @@ bool BLI_path_parent_dir(char *path) strcpy(path, tmp); /* We assume pardir is always shorter... */ return true; } - else { - return false; - } + + return false; } /** @@ -764,11 +762,10 @@ static bool stringframe_chars(const char *path, int *char_start, int *char_end) *char_end = ch_end; return true; } - else { - *char_start = -1; - *char_end = -1; - return false; - } + + *char_start = -1; + *char_end = -1; + return false; } /** @@ -1731,9 +1728,8 @@ void BLI_join_dirfile(char *__restrict dst, dst[dirlen - 1] = '\0'; return; /* dir fills the path */ } - else { - memcpy(dst, dir, dirlen + 1); - } + + memcpy(dst, dir, dirlen + 1); if (dirlen + 1 >= maxlen) { return; /* fills the path */ @@ -1891,32 +1887,31 @@ bool BLI_path_name_at_index(const char *__restrict path, } return false; } - else { - /* negative number, reverse where -1 is the last element */ - int index_step = -1; - int prev = strlen(path); - int i = prev - 1; - while (true) { - const char c = i >= 0 ? path[i] : '\0'; - if (ELEM(c, SEP, ALTSEP, '\0')) { - if (prev - 1 != i) { - i += 1; - if (index_step == index) { - *r_offset = i; - *r_len = prev - i; - return true; - } - index_step -= 1; - } - if (c == '\0') { - break; + + /* negative number, reverse where -1 is the last element */ + int index_step = -1; + int prev = strlen(path); + int i = prev - 1; + while (true) { + const char c = i >= 0 ? path[i] : '\0'; + if (ELEM(c, SEP, ALTSEP, '\0')) { + if (prev - 1 != i) { + i += 1; + if (index_step == index) { + *r_offset = i; + *r_len = prev - i; + return true; } - prev = i; + index_step -= 1; } - i -= 1; + if (c == '\0') { + break; + } + prev = i; } - return false; + i -= 1; } + return false; } /** @@ -1930,7 +1925,7 @@ const char *BLI_path_slash_find(const char *string) if (!ffslash) { return fbslash; } - else if (!fbslash) { + if (!fbslash) { return ffslash; } @@ -1948,7 +1943,7 @@ const char *BLI_path_slash_rfind(const char *string) if (!lfslash) { return lbslash; } - else if (!lbslash) { + if (!lbslash) { return lfslash; } diff --git a/source/blender/blenlib/intern/polyfill_2d.c b/source/blender/blenlib/intern/polyfill_2d.c index 90a4a4f4c2d..d1e2bd58909 100644 --- a/source/blender/blenlib/intern/polyfill_2d.c +++ b/source/blender/blenlib/intern/polyfill_2d.c @@ -177,12 +177,11 @@ BLI_INLINE eSign signum_enum(float a) if (UNLIKELY(a == 0.0f)) { return 0; } - else if (a > 0.0f) { + if (a > 0.0f) { return 1; } - else { - return -1; - } + + return -1; } /** @@ -250,7 +249,7 @@ static uint kdtree2d_balance_recursive( if (totnode <= 0) { return KDNODE_UNSET; } - else if (totnode == 1) { + if (totnode == 1) { return 0 + ofs; } @@ -330,9 +329,8 @@ static void kdtree2d_node_remove(struct KDTree2D *tree, uint index) if (node_index == KDNODE_UNSET) { return; } - else { - tree->nodes_map[index] = KDNODE_UNSET; - } + + tree->nodes_map[index] = KDNODE_UNSET; node = &tree->nodes[node_index]; tree->totnode -= 1; diff --git a/source/blender/blenlib/intern/polyfill_2d_beautify.c b/source/blender/blenlib/intern/polyfill_2d_beautify.c index 41364c5a3a9..7bfca149ffb 100644 --- a/source/blender/blenlib/intern/polyfill_2d_beautify.c +++ b/source/blender/blenlib/intern/polyfill_2d_beautify.c @@ -64,14 +64,14 @@ static int oedge_cmp(const void *a1, const void *a2) if (x1->verts[0] > x2->verts[0]) { return 1; } - else if (x1->verts[0] < x2->verts[0]) { + if (x1->verts[0] < x2->verts[0]) { return -1; } if (x1->verts[1] > x2->verts[1]) { return 1; } - else if (x1->verts[1] < x2->verts[1]) { + if (x1->verts[1] < x2->verts[1]) { return -1; } @@ -79,7 +79,7 @@ static int oedge_cmp(const void *a1, const void *a2) if (x1->e_half > x2->e_half) { return 1; } - else if (x1->e_half < x2->e_half) { + if (x1->e_half < x2->e_half) { return -1; } /* Should never get here, no two edges should be the same. */ @@ -141,7 +141,7 @@ float BLI_polyfill_beautify_quad_rotate_calc_ex(const float v1[2], if ((area_2x_123 >= 0.0f) != (area_2x_134 >= 0.0f)) { break; } - else if ((fabsf(area_2x_123) <= eps_zero_area) || (fabsf(area_2x_134) <= eps_zero_area)) { + if ((fabsf(area_2x_123) <= eps_zero_area) || (fabsf(area_2x_134) <= eps_zero_area)) { break; } @@ -150,11 +150,10 @@ float BLI_polyfill_beautify_quad_rotate_calc_ex(const float v1[2], if (lock_degenerate) { break; } - else { - return -FLT_MAX; /* always rotate */ - } + + return -FLT_MAX; /* always rotate */ } - else if ((fabsf(area_2x_234) <= eps_zero_area) || (fabsf(area_2x_241) <= eps_zero_area)) { + if ((fabsf(area_2x_234) <= eps_zero_area) || (fabsf(area_2x_241) <= eps_zero_area)) { return -FLT_MAX; /* always rotate */ } diff --git a/source/blender/blenlib/intern/quadric.c b/source/blender/blenlib/intern/quadric.c index 3ad1844cfe1..ac522171951 100644 --- a/source/blender/blenlib/intern/quadric.c +++ b/source/blender/blenlib/intern/quadric.c @@ -107,9 +107,8 @@ static bool quadric_to_tensor_m3_inverse(const Quadric *q, double m[3][3], doubl return true; } - else { - return false; - } + + return false; } void BLI_quadric_to_vector_v3(const Quadric *q, double v[3]) @@ -161,7 +160,6 @@ bool BLI_quadric_optimize(const Quadric *q, double v[3], const double epsilon) negate_v3_db(v); return true; } - else { - return false; - } + + return false; } diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index bf3c8730b01..f952b62cb61 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -238,15 +238,14 @@ static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], c if (div == 0.0) { return 1; /* co-linear */ } - else { - const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - - (v1[0] - v3[0]) * (v4[1] - v3[1])) / - div; - const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - - (v1[0] - v3[0]) * (v2[1] - v1[1])) / - div; - return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0); - } + + const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - + (v1[0] - v3[0]) * (v4[1] - v3[1])) / + div; + const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - + (v1[0] - v3[0]) * (v2[1] - v1[1])) / + div; + return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0); } static int isect_segments_fl(const float v1[2], const float v2[2], @@ -258,15 +257,14 @@ static int isect_segments_fl(const float v1[2], if (div == 0.0) { return 1; /* co-linear */ } - else { - const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - - (v1[0] - v3[0]) * (v4[1] - v3[1])) / - div; - const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - - (v1[0] - v3[0]) * (v2[1] - v1[1])) / - div; - return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0); - } + + const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - + (v1[0] - v3[0]) * (v4[1] - v3[1])) / + div; + const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - + (v1[0] - v3[0]) * (v2[1] - v1[1])) / + div; + return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0); } bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2]) @@ -289,31 +287,30 @@ bool BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2]) if (BLI_rcti_isect_pt_v(rect, s1) || BLI_rcti_isect_pt_v(rect, s2)) { return true; } - else { - /* both points are outside but may intersect the rect */ - int tvec1[2]; - int tvec2[2]; - /* diagonal: [/] */ - tvec1[0] = rect->xmin; - tvec1[1] = rect->ymin; - tvec2[0] = rect->xmin; - tvec2[1] = rect->ymax; - if (isect_segments_i(s1, s2, tvec1, tvec2)) { - return true; - } - /* diagonal: [\] */ - tvec1[0] = rect->xmin; - tvec1[1] = rect->ymax; - tvec2[0] = rect->xmax; - tvec2[1] = rect->ymin; - if (isect_segments_i(s1, s2, tvec1, tvec2)) { - return true; - } + /* both points are outside but may intersect the rect */ + int tvec1[2]; + int tvec2[2]; + /* diagonal: [/] */ + tvec1[0] = rect->xmin; + tvec1[1] = rect->ymin; + tvec2[0] = rect->xmin; + tvec2[1] = rect->ymax; + if (isect_segments_i(s1, s2, tvec1, tvec2)) { + return true; + } - /* no intersection */ - return false; + /* diagonal: [\] */ + tvec1[0] = rect->xmin; + tvec1[1] = rect->ymax; + tvec2[0] = rect->xmax; + tvec2[1] = rect->ymin; + if (isect_segments_i(s1, s2, tvec1, tvec2)) { + return true; } + + /* no intersection */ + return false; } bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[2]) @@ -336,31 +333,30 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[ if (BLI_rctf_isect_pt_v(rect, s1) || BLI_rctf_isect_pt_v(rect, s2)) { return true; } - else { - /* both points are outside but may intersect the rect */ - float tvec1[2]; - float tvec2[2]; - /* diagonal: [/] */ - tvec1[0] = rect->xmin; - tvec1[1] = rect->ymin; - tvec2[0] = rect->xmin; - tvec2[1] = rect->ymax; - if (isect_segments_fl(s1, s2, tvec1, tvec2)) { - return true; - } - /* diagonal: [\] */ - tvec1[0] = rect->xmin; - tvec1[1] = rect->ymax; - tvec2[0] = rect->xmax; - tvec2[1] = rect->ymin; - if (isect_segments_fl(s1, s2, tvec1, tvec2)) { - return true; - } + /* both points are outside but may intersect the rect */ + float tvec1[2]; + float tvec2[2]; + /* diagonal: [/] */ + tvec1[0] = rect->xmin; + tvec1[1] = rect->ymin; + tvec2[0] = rect->xmin; + tvec2[1] = rect->ymax; + if (isect_segments_fl(s1, s2, tvec1, tvec2)) { + return true; + } - /* no intersection */ - return false; + /* diagonal: [\] */ + tvec1[0] = rect->xmin; + tvec1[1] = rect->ymax; + tvec2[0] = rect->xmax; + tvec2[1] = rect->ymin; + if (isect_segments_fl(s1, s2, tvec1, tvec2)) { + return true; } + + /* no intersection */ + return false; } bool BLI_rcti_isect_circle(const rcti *rect, const float xy[2], const float radius) @@ -890,15 +886,14 @@ bool BLI_rctf_isect(const rctf *src1, const rctf *src2, rctf *dest) } return true; } - else { - if (dest) { - dest->xmin = 0; - dest->xmax = 0; - dest->ymin = 0; - dest->ymax = 0; - } - return false; + + if (dest) { + dest->xmin = 0; + dest->xmax = 0; + dest->ymin = 0; + dest->ymax = 0; } + return false; } bool BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest) @@ -920,15 +915,14 @@ bool BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest) } return true; } - else { - if (dest) { - dest->xmin = 0; - dest->xmax = 0; - dest->ymin = 0; - dest->ymax = 0; - } - return false; + + if (dest) { + dest->xmin = 0; + dest->xmax = 0; + dest->ymin = 0; + dest->ymax = 0; } + return false; } bool BLI_rctf_isect_rect_x(const rctf *src1, const rctf *src2, float range_x[2]) @@ -943,13 +937,12 @@ bool BLI_rctf_isect_rect_x(const rctf *src1, const rctf *src2, float range_x[2]) } return true; } - else { - if (range_x) { - range_x[0] = 0; - range_x[1] = 0; - } - return false; + + if (range_x) { + range_x[0] = 0; + range_x[1] = 0; } + return false; } bool BLI_rctf_isect_rect_y(const rctf *src1, const rctf *src2, float range_y[2]) @@ -964,13 +957,12 @@ bool BLI_rctf_isect_rect_y(const rctf *src1, const rctf *src2, float range_y[2]) } return true; } - else { - if (range_y) { - range_y[0] = 0; - range_y[1] = 0; - } - return false; + + if (range_y) { + range_y[0] = 0; + range_y[1] = 0; } + return false; } bool BLI_rcti_isect_rect_x(const rcti *src1, const rcti *src2, int range_x[2]) @@ -985,13 +977,12 @@ bool BLI_rcti_isect_rect_x(const rcti *src1, const rcti *src2, int range_x[2]) } return true; } - else { - if (range_x) { - range_x[0] = 0; - range_x[1] = 0; - } - return false; + + if (range_x) { + range_x[0] = 0; + range_x[1] = 0; } + return false; } bool BLI_rcti_isect_rect_y(const rcti *src1, const rcti *src2, int range_y[2]) @@ -1006,13 +997,12 @@ bool BLI_rcti_isect_rect_y(const rcti *src1, const rcti *src2, int range_y[2]) } return true; } - else { - if (range_y) { - range_y[0] = 0; - range_y[1] = 0; - } - return false; + + if (range_y) { + range_y[0] = 0; + range_y[1] = 0; } + return false; } void BLI_rcti_rctf_copy(rcti *dst, const rctf *src) diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 4723a3532ac..8b536354af2 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -91,13 +91,13 @@ static int vergscdata(const void *a1, const void *a2) if (x1->vert->xy[1] < x2->vert->xy[1]) { return 1; } - else if (x1->vert->xy[1] > x2->vert->xy[1]) { + if (x1->vert->xy[1] > x2->vert->xy[1]) { return -1; } - else if (x1->vert->xy[0] > x2->vert->xy[0]) { + if (x1->vert->xy[0] > x2->vert->xy[0]) { return 1; } - else if (x1->vert->xy[0] < x2->vert->xy[0]) { + if (x1->vert->xy[0] < x2->vert->xy[0]) { return -1; } @@ -111,13 +111,13 @@ static int vergpoly(const void *a1, const void *a2) if (x1->min_xy[0] > x2->min_xy[0]) { return 1; } - else if (x1->min_xy[0] < x2->min_xy[0]) { + if (x1->min_xy[0] < x2->min_xy[0]) { return -1; } - else if (x1->min_xy[1] > x2->min_xy[1]) { + if (x1->min_xy[1] > x2->min_xy[1]) { return 1; } - else if (x1->min_xy[1] < x2->min_xy[1]) { + if (x1->min_xy[1] < x2->min_xy[1]) { return -1; } @@ -259,7 +259,7 @@ static bool testedgeside(const float v1[2], const float v2[2], const float v3[2] if (inp < 0.0f) { return false; } - else if (inp == 0.0f) { + if (inp == 0.0f) { if (v1[0] == v3[0] && v1[1] == v3[1]) { return false; } @@ -417,25 +417,24 @@ static void testvertexnearedge(ScanFillContext *sf_ctx) eve->edge_tot = 0; break; } - else if (compare_v2v2(eve->xy, eed->v2->xy, SF_EPSILON)) { + if (compare_v2v2(eve->xy, eed->v2->xy, SF_EPSILON)) { ed1->v2 = eed->v2; eed->v2->edge_tot++; eve->edge_tot = 0; break; } - else { - if (boundinsideEV(eed, eve)) { - const float dist = dist_squared_to_line_v2(eed->v1->xy, eed->v2->xy, eve->xy); - if (dist < SF_EPSILON_SQ) { - /* new edge */ - ed1 = BLI_scanfill_edge_add(sf_ctx, eed->v1, eve); - - /* printf("fill: vertex near edge %x\n", eve); */ - ed1->poly_nr = eed->poly_nr; - eed->v1 = eve; - eve->edge_tot = 3; - break; - } + + if (boundinsideEV(eed, eve)) { + const float dist = dist_squared_to_line_v2(eed->v1->xy, eed->v2->xy, eve->xy); + if (dist < SF_EPSILON_SQ) { + /* new edge */ + ed1 = BLI_scanfill_edge_add(sf_ctx, eed->v1, eve); + + /* printf("fill: vertex near edge %x\n", eve); */ + ed1->poly_nr = eed->poly_nr; + eed->v1 = eve; + eve->edge_tot = 3; + break; } } } @@ -875,41 +874,40 @@ unsigned int BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const if (UNLIKELY(eve == NULL)) { return 0; } + + float n[3]; + + if (nor_proj) { + copy_v3_v3(n, nor_proj); + } else { - float n[3]; + /* define projection: with 'best' normal */ + /* Newell's Method */ + /* Similar code used elsewhere, but this checks for double ups + * which historically this function supports so better not change */ - if (nor_proj) { - copy_v3_v3(n, nor_proj); - } - else { - /* define projection: with 'best' normal */ - /* Newell's Method */ - /* Similar code used elsewhere, but this checks for double ups - * which historically this function supports so better not change */ - - /* warning: this only gives stable direction with single polygons, - * ideally we'd calculate connectivity and each polys normal, see T41047 */ - const float *v_prev; - - zero_v3(n); - eve = sf_ctx->fillvertbase.last; - v_prev = eve->co; - - for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { - if (LIKELY(!compare_v3v3(v_prev, eve->co, SF_EPSILON))) { - add_newell_cross_v3_v3v3(n, v_prev, eve->co); - v_prev = eve->co; - } - } - } + /* warning: this only gives stable direction with single polygons, + * ideally we'd calculate connectivity and each polys normal, see T41047 */ + const float *v_prev; - if (UNLIKELY(normalize_v3(n) == 0.0f)) { - return 0; + zero_v3(n); + eve = sf_ctx->fillvertbase.last; + v_prev = eve->co; + + for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) { + if (LIKELY(!compare_v3v3(v_prev, eve->co, SF_EPSILON))) { + add_newell_cross_v3_v3v3(n, v_prev, eve->co); + v_prev = eve->co; + } } + } - axis_dominant_v3_to_m3_negate(mat_2d, n); + if (UNLIKELY(normalize_v3(n) == 0.0f)) { + return 0; } + axis_dominant_v3_to_m3_negate(mat_2d, n); + /* STEP 1: COUNT POLYS */ if (sf_ctx->poly_nr != SF_POLY_UNSET) { poly = (unsigned short)(sf_ctx->poly_nr + 1); diff --git a/source/blender/blenlib/intern/scanfill_utils.c b/source/blender/blenlib/intern/scanfill_utils.c index 31b2bf85142..660d3dca807 100644 --- a/source/blender/blenlib/intern/scanfill_utils.c +++ b/source/blender/blenlib/intern/scanfill_utils.c @@ -139,9 +139,8 @@ static int edge_isect_ls_sort_cb(void *thunk, const void *def_a_ptr, const void if (a > b) { return -1; } - else { - return (a < b); - } + + return (a < b); } static ScanFillEdge *edge_step(PolyInfo *poly_info, diff --git a/source/blender/blenlib/intern/smallhash.c b/source/blender/blenlib/intern/smallhash.c index 6d1ce3c84cd..ab2b0fd2928 100644 --- a/source/blender/blenlib/intern/smallhash.c +++ b/source/blender/blenlib/intern/smallhash.c @@ -253,10 +253,9 @@ bool BLI_smallhash_reinsert(SmallHash *sh, uintptr_t key, void *item) e->val = item; return false; } - else { - BLI_smallhash_insert(sh, key, item); - return true; - } + + BLI_smallhash_insert(sh, key, item); + return true; } #ifdef USE_REMOVE diff --git a/source/blender/blenlib/intern/sort_utils.c b/source/blender/blenlib/intern/sort_utils.c index 09babd3d424..e02d77de0c7 100644 --- a/source/blender/blenlib/intern/sort_utils.c +++ b/source/blender/blenlib/intern/sort_utils.c @@ -44,12 +44,11 @@ int BLI_sortutil_cmp_float(const void *a_, const void *b_) if (a->sort_value > b->sort_value) { return 1; } - else if (a->sort_value < b->sort_value) { + if (a->sort_value < b->sort_value) { return -1; } - else { - return 0; - } + + return 0; } int BLI_sortutil_cmp_float_reverse(const void *a_, const void *b_) @@ -59,12 +58,11 @@ int BLI_sortutil_cmp_float_reverse(const void *a_, const void *b_) if (a->sort_value < b->sort_value) { return 1; } - else if (a->sort_value > b->sort_value) { + if (a->sort_value > b->sort_value) { return -1; } - else { - return 0; - } + + return 0; } int BLI_sortutil_cmp_int(const void *a_, const void *b_) @@ -74,12 +72,11 @@ int BLI_sortutil_cmp_int(const void *a_, const void *b_) if (a->sort_value > b->sort_value) { return 1; } - else if (a->sort_value < b->sort_value) { + if (a->sort_value < b->sort_value) { return -1; } - else { - return 0; - } + + return 0; } int BLI_sortutil_cmp_int_reverse(const void *a_, const void *b_) @@ -89,12 +86,11 @@ int BLI_sortutil_cmp_int_reverse(const void *a_, const void *b_) if (a->sort_value < b->sort_value) { return 1; } - else if (a->sort_value > b->sort_value) { + if (a->sort_value > b->sort_value) { return -1; } - else { - return 0; - } + + return 0; } int BLI_sortutil_cmp_ptr(const void *a_, const void *b_) @@ -104,12 +100,11 @@ int BLI_sortutil_cmp_ptr(const void *a_, const void *b_) if (a->sort_value > b->sort_value) { return 1; } - else if (a->sort_value < b->sort_value) { + if (a->sort_value < b->sort_value) { return -1; } - else { - return 0; - } + + return 0; } int BLI_sortutil_cmp_ptr_reverse(const void *a_, const void *b_) @@ -119,10 +114,9 @@ int BLI_sortutil_cmp_ptr_reverse(const void *a_, const void *b_) if (a->sort_value < b->sort_value) { return 1; } - else if (a->sort_value > b->sort_value) { + if (a->sort_value > b->sort_value) { return -1; } - else { - return 0; - } + + return 0; } diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index d3191148c90..fbd9e562b6a 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -96,9 +96,7 @@ char *BLI_current_working_dir(char *dir, const size_t maxncpy) memcpy(dir, pwd, srclen + 1); return dir; } - else { - return NULL; - } + return NULL; } return getcwd(dir, maxncpy); #endif diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index abdae06acd5..8b4720ca1e1 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -394,9 +394,7 @@ char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict if (LIKELY(*(endMatch - 1) != '\\')) { break; } - else { - endMatch++; - } + endMatch++; } if (endMatch) { @@ -470,11 +468,9 @@ char *BLI_str_replaceN(const char *__restrict str, return str_new; } - else { - /* Just create a new copy of the entire string - we avoid going through the assembly buffer - * for what should be a bit more efficiency. */ - return BLI_strdup(str); - } + /* Just create a new copy of the entire string - we avoid going through the assembly buffer + * for what should be a bit more efficiency. */ + return BLI_strdup(str); } /** @@ -574,10 +570,10 @@ int BLI_strcasecmp(const char *s1, const char *s2) if (c1 < c2) { return -1; } - else if (c1 > c2) { + if (c1 > c2) { return 1; } - else if (c1 == 0) { + if (c1 == 0) { break; } } @@ -597,10 +593,10 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len) if (c1 < c2) { return -1; } - else if (c1 > c2) { + if (c1 > c2) { return 1; } - else if (c1 == 0) { + if (c1 == 0) { break; } } @@ -627,15 +623,13 @@ static int left_number_strcmp(const char *s1, const char *s2, int *tiebreaker) if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) { continue; } - else if (isdigit(*(p1 + numdigit))) { + if (isdigit(*(p1 + numdigit))) { return 1; /* s2 is bigger */ } - else if (isdigit(*(p2 + numdigit))) { + if (isdigit(*(p2 + numdigit))) { return -1; /* s1 is bigger */ } - else { - break; - } + break; } /* same number of digits, compare size of number */ @@ -759,14 +753,14 @@ int BLI_strcmp_ignore_pad(const char *str1, const char *str2, const char pad) if (str1_len == str2_len) { return strncmp(str1, str2, str2_len); } - else if (str1_len > str2_len) { + if (str1_len > str2_len) { int ret = strncmp(str1, str2, str2_len); if (ret == 0) { ret = 1; } return ret; } - else { + { int ret = strncmp(str1, str2, str1_len); if (ret == 0) { ret = -1; diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index e9fdce83710..0a723a623f0 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -215,11 +215,9 @@ int BLI_utf8_invalid_strip(char *str, size_t length) tot++; break; } - else { - /* strip, keep looking */ - memmove(str, str + 1, length + 1); /* +1 for NULL char! */ - tot++; - } + /* strip, keep looking */ + memmove(str, str + 1, length + 1); /* +1 for NULL char! */ + tot++; } return tot; diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c index fb9530b5cb5..dbeb75570fb 100644 --- a/source/blender/blenlib/intern/string_utils.c +++ b/source/blender/blenlib/intern/string_utils.c @@ -72,7 +72,7 @@ size_t BLI_split_name_num(char *left, int *nr, const char *name, const char deli } return a; } - else if (isdigit(name[a]) == 0) { + if (isdigit(name[a]) == 0) { /* non-numeric suffix - give up */ break; } diff --git a/source/blender/blenlib/intern/threads.cc b/source/blender/blenlib/intern/threads.cc index a8333d0c696..002b78bec39 100644 --- a/source/blender/blenlib/intern/threads.cc +++ b/source/blender/blenlib/intern/threads.cc @@ -309,7 +309,7 @@ int BLI_system_thread_count(void) if (num_threads_override != 0) { return num_threads_override; } - else if (LIKELY(t != -1)) { + if (LIKELY(t != -1)) { return t; } @@ -751,7 +751,7 @@ void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms) if (pthread_cond_timedwait(&queue->push_cond, &queue->mutex, &timeout) == ETIMEDOUT) { break; } - else if (PIL_check_seconds_timer() - t >= ms * 0.001) { + if (PIL_check_seconds_timer() - t >= ms * 0.001) { break; } } diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 517e791e8fa..8d6d2e3e31d 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -345,7 +345,8 @@ static bool object_modifier_remove( object_remove_particle_system(bmain, scene, ob); return true; } - else if (md->type == eModifierType_Softbody) { + + if (md->type == eModifierType_Softbody) { if (ob->soft) { sbFree(ob); ob->softflag = 0; /* TODO(Sybren): this should probably be moved into sbFree() */ @@ -888,12 +889,11 @@ int ED_object_modifier_copy( BLI_insertlinkafter(&ob->modifiers, md, nmd); return true; } - else { - nmd = BKE_modifier_new(md->type); - BKE_modifier_copydata(md, nmd); - BLI_insertlinkafter(&ob->modifiers, md, nmd); - BKE_modifier_unique_name(&ob->modifiers, nmd); - } + + nmd = BKE_modifier_new(md->type); + BKE_modifier_copydata(md, nmd); + BLI_insertlinkafter(&ob->modifiers, md, nmd); + BKE_modifier_unique_name(&ob->modifiers, nmd); return 1; } @@ -1458,9 +1458,7 @@ static int modifier_apply_as_shapekey_invoke(bContext *C, wmOperator *op, const if (edit_modifier_invoke_properties(C, op, event, &retval)) { return modifier_apply_as_shapekey_exec(C, op); } - else { - return retval; - } + return retval; } static char *modifier_apply_as_shapekey_get_description(struct bContext *UNUSED(C), diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c index 9520b03f3a6..f4de8f712c8 100644 --- a/source/blender/editors/object/object_relations.c +++ b/source/blender/editors/object/object_relations.c @@ -2283,7 +2283,8 @@ static int make_override_library_invoke(bContext *C, wmOperator *op, const wmEve /* This invoke just calls another instance of this operator... */ return OPERATOR_INTERFACE; } - else if (ID_IS_LINKED(obact)) { + + if (ID_IS_LINKED(obact)) { /* Show menu with list of directly linked collections containing the active object. */ WM_enum_search_invoke(C, op, event); return OPERATOR_CANCELLED; diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 89fc0ac1a58..d0b834a3dc0 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -581,7 +581,8 @@ static bool sculpt_check_unique_face_set_for_edge_in_base_mesh(SculptSession *ss p1 = vert_map->indices[i]; break; } - else if (p2 == -1) { + + if (p2 == -1) { p2 = vert_map->indices[i]; break; } diff --git a/source/blender/editors/uvedit/uvedit_rip.c b/source/blender/editors/uvedit/uvedit_rip.c index 07bec2da1ae..421e58b1cb5 100644 --- a/source/blender/editors/uvedit/uvedit_rip.c +++ b/source/blender/editors/uvedit/uvedit_rip.c @@ -538,23 +538,22 @@ static bool uv_rip_pairs_loop_change_sides_test(BMLoop *l_switch, if (count_a + count_b == 4) { return count_a > count_b; } - else { - const float angle_a_before = uv_rip_pairs_calc_uv_angle( - l_switch, side_a, aspect_y, cd_loop_uv_offset); - const float angle_b_before = uv_rip_pairs_calc_uv_angle( - l_target, side_b, aspect_y, cd_loop_uv_offset); - UL(l_switch)->side = side_b; + const float angle_a_before = uv_rip_pairs_calc_uv_angle( + l_switch, side_a, aspect_y, cd_loop_uv_offset); + const float angle_b_before = uv_rip_pairs_calc_uv_angle( + l_target, side_b, aspect_y, cd_loop_uv_offset); - const float angle_a_after = uv_rip_pairs_calc_uv_angle( - l_switch, side_a, aspect_y, cd_loop_uv_offset); - const float angle_b_after = uv_rip_pairs_calc_uv_angle( - l_target, side_b, aspect_y, cd_loop_uv_offset); + UL(l_switch)->side = side_b; - UL(l_switch)->side = side_a; + const float angle_a_after = uv_rip_pairs_calc_uv_angle( + l_switch, side_a, aspect_y, cd_loop_uv_offset); + const float angle_b_after = uv_rip_pairs_calc_uv_angle( + l_target, side_b, aspect_y, cd_loop_uv_offset); - return fabsf(angle_a_before - angle_b_before) > fabsf(angle_a_after - angle_b_after); - } + UL(l_switch)->side = side_a; + + return fabsf(angle_a_before - angle_b_before) > fabsf(angle_a_after - angle_b_after); } /** diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c index 2f30ef1caa6..9f77bf31481 100644 --- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c +++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c @@ -1885,12 +1885,10 @@ static int smart_uv_project_thickface_area_cmp_fn(const void *tf_a_p, const void if (tf_a->area < tf_b->area) { return 1; } - else if (tf_a->area > tf_b->area) { + if (tf_a->area > tf_b->area) { return -1; } - else { - return 0; - } + return 0; } static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_faces, diff --git a/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c b/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c index 315f1b9e19b..389f3ca1bd2 100644 --- a/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c +++ b/source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c @@ -169,7 +169,7 @@ static int remapTime(struct GpencilModifierData *md, const int delta = abs(sfra - nfra); return efra - delta + 1; } - else if (cfra + offset > efra) { + if (cfra + offset > efra) { return nfra - efra + sfra - 1; } } diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c index 90d9ba45637..87cb4d5f584 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo.c @@ -452,9 +452,7 @@ bool wm_gizmo_select_and_highlight(bContext *C, wmGizmoMap *gzmap, wmGizmo *gz) wm_gizmomap_highlight_set(gzmap, C, gz, gz->highlight_part); return true; } - else { - return false; - } + return false; } /** diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c index 67f30f0d7ee..b64d544962d 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_group.c @@ -166,12 +166,10 @@ int WM_gizmo_cmp_temp_fl(const void *gz_a_ptr, const void *gz_b_ptr) if (gz_a->temp.f < gz_b->temp.f) { return -1; } - else if (gz_a->temp.f > gz_b->temp.f) { + if (gz_a->temp.f > gz_b->temp.f) { return 1; } - else { - return 0; - } + return 0; } int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr) @@ -181,12 +179,10 @@ int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr) if (gz_a->temp.f < gz_b->temp.f) { return 1; } - else if (gz_a->temp.f > gz_b->temp.f) { + if (gz_a->temp.f > gz_b->temp.f) { return -1; } - else { - return 0; - } + return 0; } static bool wm_gizmo_keymap_uses_event_modifier(wmWindowManager *wm, @@ -396,10 +392,9 @@ static int gizmo_select_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE return OPERATOR_FINISHED; } - else { - BLI_assert(0); - return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); - } + + BLI_assert(0); + return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); } void GIZMOGROUP_OT_gizmo_select(wmOperatorType *ot) @@ -476,9 +471,7 @@ static bool gizmo_tweak_start_and_finish( } return true; } - else { - return false; - } + return false; } static void gizmo_tweak_finish(bContext *C, wmOperator *op, const bool cancel, bool clear_modal) diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c index 2038a82c9fd..cecd324ff28 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c @@ -263,11 +263,10 @@ bool WM_gizmomap_minmax(const wmGizmoMap *gzmap, } return i != 0; } - else { - bool ok = false; - BLI_assert(!"TODO"); - return ok; - } + + bool ok = false; + BLI_assert(!"TODO"); + return ok; } /** @@ -647,10 +646,9 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos, } return hit_found; } - else { - const uint *hit_near = GPU_select_buffer_near(buffer, hits); - return hit_near ? hit_near[3] : -1; - } + + const uint *hit_near = GPU_select_buffer_near(buffer, hits); + return hit_near ? hit_near[3] : -1; } /** diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c index 2dc03d1419c..b056ed40943 100644 --- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c +++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_target_props.c @@ -70,9 +70,7 @@ wmGizmoProperty *WM_gizmo_target_property_find(wmGizmo *gz, const char *idname) if (index != -1) { return WM_gizmo_target_property_at_index(gz, index); } - else { - return NULL; - } + return NULL; } void WM_gizmo_target_property_def_rna_ptr(wmGizmo *gz, @@ -195,9 +193,7 @@ float WM_gizmo_target_property_float_get(const wmGizmo *gz, wmGizmoProperty *gz_ if (gz_prop->index == -1) { return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop); } - else { - return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index); - } + return RNA_property_float_get_index(&gz_prop->ptr, gz_prop->prop, gz_prop->index); } void WM_gizmo_target_property_float_set(bContext *C, @@ -255,9 +251,7 @@ bool WM_gizmo_target_property_float_range_get(const wmGizmo *gz, gz_prop->custom_func.range_get_fn(gz, gz_prop, range); return true; } - else { - return false; - } + return false; } float step, precision; diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c index 2af68956923..08d6df340d0 100644 --- a/source/blender/windowmanager/intern/wm_cursors.c +++ b/source/blender/windowmanager/intern/wm_cursors.c @@ -319,15 +319,15 @@ bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event) wm_cursor_warp_relative(win, 0, fac); return 1; } - else if (event->type == EVT_DOWNARROWKEY) { + if (event->type == EVT_DOWNARROWKEY) { wm_cursor_warp_relative(win, 0, -fac); return 1; } - else if (event->type == EVT_LEFTARROWKEY) { + if (event->type == EVT_LEFTARROWKEY) { wm_cursor_warp_relative(win, -fac, 0); return 1; } - else if (event->type == EVT_RIGHTARROWKEY) { + if (event->type == EVT_RIGHTARROWKEY) { wm_cursor_warp_relative(win, fac, 0); return 1; } diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c index 5f13adcb971..ec18a401fa4 100644 --- a/source/blender/windowmanager/intern/wm_dragdrop.c +++ b/source/blender/windowmanager/intern/wm_dragdrop.c @@ -296,7 +296,7 @@ void WM_drag_add_ID(wmDrag *drag, ID *id, ID *from_parent) } return; } - else if (GS(drag_id->id->name) != GS(id->name)) { + if (GS(drag_id->id->name) != GS(id->name)) { BLI_assert(!"All dragged IDs must have the same type"); return; } @@ -355,7 +355,7 @@ static const char *wm_drag_name(wmDrag *drag) if (single) { return id->name + 2; } - else if (id) { + if (id) { return BKE_idtype_idcode_to_name_plural(GS(id->name)); } break; diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c index 190db919b41..fe4c98394a3 100644 --- a/source/blender/windowmanager/intern/wm_draw.c +++ b/source/blender/windowmanager/intern/wm_draw.c @@ -207,7 +207,7 @@ static bool wm_draw_region_stereo_set(Main *bmain, if (region->regiontype == RGN_TYPE_PREVIEW) { return true; } - else if (region->regiontype == RGN_TYPE_WINDOW) { + if (region->regiontype == RGN_TYPE_WINDOW) { return (sseq->draw_flag & SEQ_DRAW_BACKDROP) != 0; } } @@ -520,9 +520,7 @@ GPUTexture *wm_draw_region_texture(ARegion *region, int view) if (viewport) { return GPU_viewport_color_texture(viewport, view); } - else { - return GPU_offscreen_color_texture(region->draw_buffer->offscreen); - } + return GPU_offscreen_color_texture(region->draw_buffer->offscreen); } void wm_draw_region_blend(ARegion *region, int view, bool blend) diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 05ef4bfac30..0941dd49d23 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -597,7 +597,7 @@ static int wm_handler_ui_call(bContext *C, if (is_wheel) { return WM_HANDLER_CONTINUE; } - else if (wm_event_always_pass(event) == 0) { + if (wm_event_always_pass(event) == 0) { do_wheel_ui = true; } } @@ -783,7 +783,7 @@ bool WM_operator_poll(bContext *C, wmOperatorType *ot) if (ot->pyop_poll) { return ot->pyop_poll(C, ot); } - else if (ot->poll) { + if (ot->poll) { return ot->poll(C); } @@ -1095,7 +1095,7 @@ bool WM_operator_repeat_check(const bContext *UNUSED(C), wmOperator *op) if (op->type->exec != NULL) { return true; } - else if (op->opm) { + if (op->opm) { /* for macros, check all have exec() we can call */ wmOperatorTypeMacro *otmacro; for (otmacro = op->opm->type->macro.first; otmacro; otmacro = otmacro->next) { @@ -1816,10 +1816,10 @@ static bool wm_eventmatch(const wmEvent *winevent, const wmKeyMapItem *kmi) /* tablet events can occur on hover + keypress */ return false; } - else if ((kmitype == TABLET_STYLUS) && (wmtab->active != EVT_TABLET_STYLUS)) { + if ((kmitype == TABLET_STYLUS) && (wmtab->active != EVT_TABLET_STYLUS)) { return false; } - else if ((kmitype == TABLET_ERASER) && (wmtab->active != EVT_TABLET_ERASER)) { + if ((kmitype == TABLET_ERASER) && (wmtab->active != EVT_TABLET_ERASER)) { return false; } } @@ -2434,13 +2434,11 @@ static int wm_handlers_do_keymap_with_keymap_handler( } break; } + if (action & WM_HANDLER_HANDLED) { + CLOG_INFO(WM_LOG_HANDLERS, 2, "handled - and pass on! '%s'", kmi->idname); + } else { - if (action & WM_HANDLER_HANDLED) { - CLOG_INFO(WM_LOG_HANDLERS, 2, "handled - and pass on! '%s'", kmi->idname); - } - else { - CLOG_INFO(WM_LOG_HANDLERS, 2, "un-handled '%s'", kmi->idname); - } + CLOG_INFO(WM_LOG_HANDLERS, 2, "un-handled '%s'", kmi->idname); } } } @@ -2492,16 +2490,14 @@ static int wm_handlers_do_keymap_with_gizmo_handler( } break; } - else { - if (action & WM_HANDLER_HANDLED) { - if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) { - printf("%s: handled - and pass on! '%s'\n", __func__, kmi->idname); - } - } - else { - PRINT("%s: un-handled '%s'\n", __func__, kmi->idname); + if (action & WM_HANDLER_HANDLED) { + if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) { + printf("%s: handled - and pass on! '%s'\n", __func__, kmi->idname); } } + else { + PRINT("%s: un-handled '%s'\n", __func__, kmi->idname); + } } } } @@ -3126,13 +3122,9 @@ static bool wm_event_pie_filter(wmWindow *win, const wmEvent *event) win->lock_pie_event = EVENT_NONE; return false; } - else { - return true; - } - } - else { - return false; + return true; } + return false; } /** @@ -3692,10 +3684,8 @@ wmKeyMap *WM_event_get_keymap_from_toolsystem_fallback(wmWindowManager *wm, handler->keymap_tool = area->runtime.tool; return km; } - else { - printf( - "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); - } + printf( + "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); } } return NULL; @@ -3716,10 +3706,8 @@ wmKeyMap *WM_event_get_keymap_from_toolsystem(wmWindowManager *wm, wmEventHandle handler->keymap_tool = area->runtime.tool; return km; } - else { - printf( - "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); - } + printf( + "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname); } } return NULL; @@ -3775,12 +3763,10 @@ static bool event_or_prev_in_rect(const wmEvent *event, const rcti *rect) if (BLI_rcti_isect_pt(rect, event->x, event->y)) { return true; } - else if (event->type == MOUSEMOVE && BLI_rcti_isect_pt(rect, event->prevx, event->prevy)) { + if (event->type == MOUSEMOVE && BLI_rcti_isect_pt(rect, event->prevx, event->prevy)) { return true; } - else { - return false; - } + return false; } static bool handler_region_v2d_mask_test(const ARegion *region, const wmEvent *event) @@ -3966,138 +3952,137 @@ static int convert_key(GHOST_TKey key) if (key >= GHOST_kKeyA && key <= GHOST_kKeyZ) { return (EVT_AKEY + ((int)key - GHOST_kKeyA)); } - else if (key >= GHOST_kKey0 && key <= GHOST_kKey9) { + if (key >= GHOST_kKey0 && key <= GHOST_kKey9) { return (EVT_ZEROKEY + ((int)key - GHOST_kKey0)); } - else if (key >= GHOST_kKeyNumpad0 && key <= GHOST_kKeyNumpad9) { + if (key >= GHOST_kKeyNumpad0 && key <= GHOST_kKeyNumpad9) { return (EVT_PAD0 + ((int)key - GHOST_kKeyNumpad0)); } - else if (key >= GHOST_kKeyF1 && key <= GHOST_kKeyF24) { + if (key >= GHOST_kKeyF1 && key <= GHOST_kKeyF24) { return (EVT_F1KEY + ((int)key - GHOST_kKeyF1)); } - else { - switch (key) { - case GHOST_kKeyBackSpace: - return EVT_BACKSPACEKEY; - case GHOST_kKeyTab: - return EVT_TABKEY; - case GHOST_kKeyLinefeed: - return EVT_LINEFEEDKEY; - case GHOST_kKeyClear: - return 0; - case GHOST_kKeyEnter: - return EVT_RETKEY; - - case GHOST_kKeyEsc: - return EVT_ESCKEY; - case GHOST_kKeySpace: - return EVT_SPACEKEY; - case GHOST_kKeyQuote: - return EVT_QUOTEKEY; - case GHOST_kKeyComma: - return EVT_COMMAKEY; - case GHOST_kKeyMinus: - return EVT_MINUSKEY; - case GHOST_kKeyPlus: - return EVT_PLUSKEY; - case GHOST_kKeyPeriod: - return EVT_PERIODKEY; - case GHOST_kKeySlash: - return EVT_SLASHKEY; - - case GHOST_kKeySemicolon: - return EVT_SEMICOLONKEY; - case GHOST_kKeyEqual: - return EVT_EQUALKEY; - - case GHOST_kKeyLeftBracket: - return EVT_LEFTBRACKETKEY; - case GHOST_kKeyRightBracket: - return EVT_RIGHTBRACKETKEY; - case GHOST_kKeyBackslash: - return EVT_BACKSLASHKEY; - case GHOST_kKeyAccentGrave: - return EVT_ACCENTGRAVEKEY; - - case GHOST_kKeyLeftShift: - return EVT_LEFTSHIFTKEY; - case GHOST_kKeyRightShift: - return EVT_RIGHTSHIFTKEY; - case GHOST_kKeyLeftControl: - return EVT_LEFTCTRLKEY; - case GHOST_kKeyRightControl: - return EVT_RIGHTCTRLKEY; - case GHOST_kKeyOS: - return EVT_OSKEY; - case GHOST_kKeyLeftAlt: - return EVT_LEFTALTKEY; - case GHOST_kKeyRightAlt: - return EVT_RIGHTALTKEY; - case GHOST_kKeyApp: - return EVT_APPKEY; - - case GHOST_kKeyCapsLock: - return EVT_CAPSLOCKKEY; - case GHOST_kKeyNumLock: - return 0; - case GHOST_kKeyScrollLock: - return 0; - - case GHOST_kKeyLeftArrow: - return EVT_LEFTARROWKEY; - case GHOST_kKeyRightArrow: - return EVT_RIGHTARROWKEY; - case GHOST_kKeyUpArrow: - return EVT_UPARROWKEY; - case GHOST_kKeyDownArrow: - return EVT_DOWNARROWKEY; - - case GHOST_kKeyPrintScreen: - return 0; - case GHOST_kKeyPause: - return EVT_PAUSEKEY; - - case GHOST_kKeyInsert: - return EVT_INSERTKEY; - case GHOST_kKeyDelete: - return EVT_DELKEY; - case GHOST_kKeyHome: - return EVT_HOMEKEY; - case GHOST_kKeyEnd: - return EVT_ENDKEY; - case GHOST_kKeyUpPage: - return EVT_PAGEUPKEY; - case GHOST_kKeyDownPage: - return EVT_PAGEDOWNKEY; - - case GHOST_kKeyNumpadPeriod: - return EVT_PADPERIOD; - case GHOST_kKeyNumpadEnter: - return EVT_PADENTER; - case GHOST_kKeyNumpadPlus: - return EVT_PADPLUSKEY; - case GHOST_kKeyNumpadMinus: - return EVT_PADMINUS; - case GHOST_kKeyNumpadAsterisk: - return EVT_PADASTERKEY; - case GHOST_kKeyNumpadSlash: - return EVT_PADSLASHKEY; - - case GHOST_kKeyGrLess: - return EVT_GRLESSKEY; - - case GHOST_kKeyMediaPlay: - return EVT_MEDIAPLAY; - case GHOST_kKeyMediaStop: - return EVT_MEDIASTOP; - case GHOST_kKeyMediaFirst: - return EVT_MEDIAFIRST; - case GHOST_kKeyMediaLast: - return EVT_MEDIALAST; - - default: - return EVT_UNKNOWNKEY; /* GHOST_kKeyUnknown */ - } + + switch (key) { + case GHOST_kKeyBackSpace: + return EVT_BACKSPACEKEY; + case GHOST_kKeyTab: + return EVT_TABKEY; + case GHOST_kKeyLinefeed: + return EVT_LINEFEEDKEY; + case GHOST_kKeyClear: + return 0; + case GHOST_kKeyEnter: + return EVT_RETKEY; + + case GHOST_kKeyEsc: + return EVT_ESCKEY; + case GHOST_kKeySpace: + return EVT_SPACEKEY; + case GHOST_kKeyQuote: + return EVT_QUOTEKEY; + case GHOST_kKeyComma: + return EVT_COMMAKEY; + case GHOST_kKeyMinus: + return EVT_MINUSKEY; + case GHOST_kKeyPlus: + return EVT_PLUSKEY; + case GHOST_kKeyPeriod: + return EVT_PERIODKEY; + case GHOST_kKeySlash: + return EVT_SLASHKEY; + + case GHOST_kKeySemicolon: + return EVT_SEMICOLONKEY; + case GHOST_kKeyEqual: + return EVT_EQUALKEY; + + case GHOST_kKeyLeftBracket: + return EVT_LEFTBRACKETKEY; + case GHOST_kKeyRightBracket: + return EVT_RIGHTBRACKETKEY; + case GHOST_kKeyBackslash: + return EVT_BACKSLASHKEY; + case GHOST_kKeyAccentGrave: + return EVT_ACCENTGRAVEKEY; + + case GHOST_kKeyLeftShift: + return EVT_LEFTSHIFTKEY; + case GHOST_kKeyRightShift: + return EVT_RIGHTSHIFTKEY; + case GHOST_kKeyLeftControl: + return EVT_LEFTCTRLKEY; + case GHOST_kKeyRightControl: + return EVT_RIGHTCTRLKEY; + case GHOST_kKeyOS: + return EVT_OSKEY; + case GHOST_kKeyLeftAlt: + return EVT_LEFTALTKEY; + case GHOST_kKeyRightAlt: + return EVT_RIGHTALTKEY; + case GHOST_kKeyApp: + return EVT_APPKEY; + + case GHOST_kKeyCapsLock: + return EVT_CAPSLOCKKEY; + case GHOST_kKeyNumLock: + return 0; + case GHOST_kKeyScrollLock: + return 0; + + case GHOST_kKeyLeftArrow: + return EVT_LEFTARROWKEY; + case GHOST_kKeyRightArrow: + return EVT_RIGHTARROWKEY; + case GHOST_kKeyUpArrow: + return EVT_UPARROWKEY; + case GHOST_kKeyDownArrow: + return EVT_DOWNARROWKEY; + + case GHOST_kKeyPrintScreen: + return 0; + case GHOST_kKeyPause: + return EVT_PAUSEKEY; + + case GHOST_kKeyInsert: + return EVT_INSERTKEY; + case GHOST_kKeyDelete: + return EVT_DELKEY; + case GHOST_kKeyHome: + return EVT_HOMEKEY; + case GHOST_kKeyEnd: + return EVT_ENDKEY; + case GHOST_kKeyUpPage: + return EVT_PAGEUPKEY; + case GHOST_kKeyDownPage: + return EVT_PAGEDOWNKEY; + + case GHOST_kKeyNumpadPeriod: + return EVT_PADPERIOD; + case GHOST_kKeyNumpadEnter: + return EVT_PADENTER; + case GHOST_kKeyNumpadPlus: + return EVT_PADPLUSKEY; + case GHOST_kKeyNumpadMinus: + return EVT_PADMINUS; + case GHOST_kKeyNumpadAsterisk: + return EVT_PADASTERKEY; + case GHOST_kKeyNumpadSlash: + return EVT_PADSLASHKEY; + + case GHOST_kKeyGrLess: + return EVT_GRLESSKEY; + + case GHOST_kKeyMediaPlay: + return EVT_MEDIAPLAY; + case GHOST_kKeyMediaStop: + return EVT_MEDIASTOP; + case GHOST_kKeyMediaFirst: + return EVT_MEDIAFIRST; + case GHOST_kKeyMediaLast: + return EVT_MEDIALAST; + + default: + return EVT_UNKNOWNKEY; /* GHOST_kKeyUnknown */ } } diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index f39fc0aecf2..ef4f2b4a62a 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -1404,10 +1404,8 @@ bool write_crash_blend(void) printf("written: %s\n", path); return 1; } - else { - printf("failed: %s\n", path); - return 0; - } + printf("failed: %s\n", path); + return 0; } /** @@ -2091,9 +2089,7 @@ static int wm_homefile_read_invoke(bContext *C, wmOperator *op, const wmEvent *U wm_close_file_dialog(C, callback); return OPERATOR_INTERFACE; } - else { - return wm_homefile_read_exec(C, op); - } + return wm_homefile_read_exec(C, op); } static void read_homefile_props(wmOperatorType *ot) @@ -2255,9 +2251,7 @@ static int wm_open_mainfile__discard_changes(bContext *C, wmOperator *op) wm_close_file_dialog(C, callback); return OPERATOR_INTERFACE; } - else { - return wm_open_mainfile_dispatch(C, op); - } + return wm_open_mainfile_dispatch(C, op); } static int wm_open_mainfile__select_file_path(bContext *C, wmOperator *op) @@ -2328,9 +2322,7 @@ static int wm_open_mainfile__open(bContext *C, wmOperator *op) ED_view3d_local_collections_reset(C, (G.fileflags & G_FILE_NO_UI) != 0); return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } static OperatorDispatchTarget wm_open_mainfile_dispatch_targets[] = { @@ -2475,9 +2467,7 @@ static int wm_revert_mainfile_exec(bContext *C, wmOperator *op) if (success) { return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } static bool wm_revert_mainfile_poll(bContext *UNUSED(C)) @@ -2572,9 +2562,7 @@ static int wm_recover_auto_save_exec(bContext *C, wmOperator *op) if (success) { return OPERATOR_FINISHED; } - else { - return OPERATOR_CANCELLED; - } + return OPERATOR_CANCELLED; } static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c index 31d36603505..6ccc5d79962 100644 --- a/source/blender/windowmanager/intern/wm_files_link.c +++ b/source/blender/windowmanager/intern/wm_files_link.c @@ -357,11 +357,11 @@ static int wm_link_append_exec(bContext *C, wmOperator *op) BKE_reportf(op->reports, RPT_ERROR, "'%s': not a library", path); return OPERATOR_CANCELLED; } - else if (!group) { + if (!group) { BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path); return OPERATOR_CANCELLED; } - else if (BLI_path_cmp(BKE_main_blendfile_path(bmain), libname) == 0) { + if (BLI_path_cmp(BKE_main_blendfile_path(bmain), libname) == 0) { BKE_reportf(op->reports, RPT_ERROR, "'%s': cannot use current file as library", path); return OPERATOR_CANCELLED; } @@ -755,7 +755,7 @@ static void lib_relocate_do_remap(Main *bmain, if (c == '.') { break; } - else if (c < '0' || c > '9') { + if (c < '0' || c > '9') { has_num = false; break; } diff --git a/source/blender/windowmanager/intern/wm_jobs.c b/source/blender/windowmanager/intern/wm_jobs.c index 87a19d832c9..c9b125901e7 100644 --- a/source/blender/windowmanager/intern/wm_jobs.c +++ b/source/blender/windowmanager/intern/wm_jobs.c @@ -344,9 +344,7 @@ void *WM_jobs_customdata_get(wmJob *wm_job) if (!wm_job->customdata) { return wm_job->run_customdata; } - else { - return wm_job->customdata; - } + return wm_job->customdata; } void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void (*free)(void *)) diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index f0ad5f1e9c6..d7ff2689a86 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -321,9 +321,7 @@ bool WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf) return true; } - else { - return false; - } + return false; } void WM_keyconfig_clear(wmKeyConfig *keyconf) @@ -448,9 +446,7 @@ bool WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap) return true; } - else { - return false; - } + return false; } bool WM_keymap_poll(bContext *C, wmKeyMap *keymap) @@ -551,9 +547,7 @@ bool WM_keymap_remove_item(wmKeyMap *keymap, wmKeyMapItem *kmi) WM_keyconfig_update_tag(keymap, NULL); return true; } - else { - return false; - } + return false; } /** \} */ @@ -1122,7 +1116,7 @@ const char *WM_key_event_string(const short type, const bool compact) if (platform == MACOS) { return key_event_glyph_or_text(font_id, IFACE_("Cmd"), "\xe2\x8c\x98"); } - else if (platform == MSWIN) { + if (platform == MSWIN) { return key_event_glyph_or_text(font_id, IFACE_("Win"), "\xe2\x9d\x96"); } return IFACE_("OS"); diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c index 650d5bbe015..457cd0f16be 100644 --- a/source/blender/windowmanager/intern/wm_operator_type.c +++ b/source/blender/windowmanager/intern/wm_operator_type.c @@ -606,9 +606,7 @@ char *WM_operatortype_description(struct bContext *C, if (description[0]) { return description; } - else { - MEM_freeN(description); - } + MEM_freeN(description); } } @@ -621,9 +619,7 @@ char *WM_operatortype_description(struct bContext *C, if (info && info[0]) { return BLI_strdup(info); } - else { - return NULL; - } + return NULL; } /** \} */ diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c index 72cc5a3d7dd..6a3f4f6a364 100644 --- a/source/blender/windowmanager/intern/wm_operators.c +++ b/source/blender/windowmanager/intern/wm_operators.c @@ -864,19 +864,17 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) } return ret_value | OPERATOR_PASS_THROUGH; } - else { - /* If we are in init phase, and cannot validate init of modal operations, - * just fall back to basic exec. - */ - RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false); + /* If we are in init phase, and cannot validate init of modal operations, + * just fall back to basic exec. + */ + RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false); - ret_value = op->type->exec(C, op); - OPERATOR_RETVAL_CHECK(ret_value); + ret_value = op->type->exec(C, op); + OPERATOR_RETVAL_CHECK(ret_value); - return ret_value | OPERATOR_PASS_THROUGH; - } + return ret_value | OPERATOR_PASS_THROUGH; } - else if (event->type == init_event_type && event->val == KM_RELEASE) { + if (event->type == init_event_type && event->val == KM_RELEASE) { RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false); ret_value = op->type->exec(C, op); @@ -884,7 +882,7 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) return ret_value | OPERATOR_PASS_THROUGH; } - else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { + if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { const int drag_delta[2] = { mval[0] - event->mval[0], mval[1] - event->mval[1], @@ -895,11 +893,9 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event) if (WM_event_drag_test_with_delta(event, drag_delta)) { return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; } - else { - /* Important not to return anything other than PASS_THROUGH here, - * otherwise it prevents underlying tweak detection code to work properly. */ - return OPERATOR_PASS_THROUGH; - } + /* Important not to return anything other than PASS_THROUGH here, + * otherwise it prevents underlying tweak detection code to work properly. */ + return OPERATOR_PASS_THROUGH; } return OPERATOR_RUNNING_MODAL | OPERATOR_PASS_THROUGH; @@ -1151,9 +1147,7 @@ int WM_operator_confirm_or_exec(bContext *C, wmOperator *op, const wmEvent *UNUS if (confirm) { return WM_operator_confirm_message(C, op, NULL); } - else { - return op->type->exec(C, op); - } + return op->type->exec(C, op); } /* op->invoke, opens fileselect if path property not set, otherwise executes */ @@ -1162,10 +1156,8 @@ int WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *UNUSED(event if (RNA_struct_property_is_set(op->ptr, "filepath")) { return WM_operator_call_notest(C, op); /* call exec direct */ } - else { - WM_event_add_fileselect(C, op); - return OPERATOR_RUNNING_MODAL; - } + WM_event_add_fileselect(C, op); + return OPERATOR_RUNNING_MODAL; } bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const struct ImageFormatData *im_format) @@ -2536,10 +2528,8 @@ static int radial_control_get_path(PointerRNA *ctx_ptr, if (flags & RC_PROP_ALLOW_MISSING) { return 1; } - else { - BKE_reportf(op->reports, RPT_ERROR, "Could not resolve path '%s'", name); - return 0; - } + BKE_reportf(op->reports, RPT_ERROR, "Could not resolve path '%s'", name); + return 0; } /* check property type */ @@ -2591,13 +2581,12 @@ static int radial_control_get_properties(bContext *C, wmOperator *op) (RC_PROP_ALLOW_MISSING | RC_PROP_REQUIRE_BOOL))) { return 0; } + + if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) { + data_path = "data_path_secondary"; + } else { - if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) { - data_path = "data_path_secondary"; - } - else { - data_path = "data_path_primary"; - } + data_path = "data_path_primary"; } if (!radial_control_get_path(&ctx_ptr, op, data_path, &rc->ptr, &rc->prop, 0, 0)) { @@ -2664,7 +2653,7 @@ static int radial_control_get_properties(bContext *C, wmOperator *op) if (!radial_control_get_path(&ctx_ptr, op, "image_id", &rc->image_id_ptr, NULL, 0, 0)) { return 0; } - else if (rc->image_id_ptr.data) { + if (rc->image_id_ptr.data) { /* extra check, pointer must be to an ID */ if (!RNA_struct_is_ID(rc->image_id_ptr.type)) { BKE_report(op->reports, RPT_ERROR, "Pointer from path image_id is not an ID"); @@ -2841,171 +2830,169 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even radial_control_update_header(op, C); return OPERATOR_RUNNING_MODAL; } - else { - handled = false; - switch (event->type) { - case EVT_ESCKEY: - case RIGHTMOUSE: - /* canceled; restore original value */ - radial_control_set_value(rc, rc->initial_value); - ret = OPERATOR_CANCELLED; - break; - - case LEFTMOUSE: - case EVT_PADENTER: - case EVT_RETKEY: - /* done; value already set */ - RNA_property_update(C, &rc->ptr, rc->prop); - ret = OPERATOR_FINISHED; - break; - - case MOUSEMOVE: - if (!has_numInput) { - if (rc->slow_mode) { - if (rc->subtype == PROP_ANGLE) { - float position[2] = {event->x, event->y}; - - /* calculate the initial angle here first */ - delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; - delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1]; - - /* precision angle gets calculated from dial and gets added later */ - angle_precision = -0.1f * BLI_dial_angle(rc->dial, position); - } - else { - delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; - delta[1] = 0.0f; - if (rc->zoom_prop) { - RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); - delta[0] /= zoom[0]; - } + handled = false; + switch (event->type) { + case EVT_ESCKEY: + case RIGHTMOUSE: + /* canceled; restore original value */ + radial_control_set_value(rc, rc->initial_value); + ret = OPERATOR_CANCELLED; + break; - dist = len_v2(delta); + case LEFTMOUSE: + case EVT_PADENTER: + case EVT_RETKEY: + /* done; value already set */ + RNA_property_update(C, &rc->ptr, rc->prop); + ret = OPERATOR_FINISHED; + break; - delta[0] = event->x - rc->slow_mouse[0]; + case MOUSEMOVE: + if (!has_numInput) { + if (rc->slow_mode) { + if (rc->subtype == PROP_ANGLE) { + float position[2] = {event->x, event->y}; - if (rc->zoom_prop) { - delta[0] /= zoom[0]; - } + /* calculate the initial angle here first */ + delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; + delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1]; - dist = dist + 0.1f * (delta[0]); - } + /* precision angle gets calculated from dial and gets added later */ + angle_precision = -0.1f * BLI_dial_angle(rc->dial, position); } else { - delta[0] = rc->initial_mouse[0] - event->x; - delta[1] = rc->initial_mouse[1] - event->y; + delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; + delta[1] = 0.0f; + if (rc->zoom_prop) { RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); delta[0] /= zoom[0]; - delta[1] /= zoom[1]; } - if (rc->subtype == PROP_ANGLE) { - dist = len_v2(delta); - } - else { - dist = clamp_f(-delta[0], 0.0f, FLT_MAX); + + dist = len_v2(delta); + + delta[0] = event->x - rc->slow_mouse[0]; + + if (rc->zoom_prop) { + delta[0] /= zoom[0]; } - } - /* calculate new value and apply snapping */ - switch (rc->subtype) { - case PROP_NONE: - case PROP_DISTANCE: - case PROP_PIXEL: - new_value = dist; - if (snap) { - new_value = ((int)new_value + 5) / 10 * 10; - } - break; - case PROP_PERCENTAGE: - new_value = ((dist - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE) / - WM_RADIAL_CONTROL_DISPLAY_WIDTH) * - 100.0f; - if (snap) { - new_value = ((int)(new_value + 2.5f)) / 5 * 5; - } - break; - case PROP_FACTOR: - new_value = (WM_RADIAL_CONTROL_DISPLAY_SIZE - dist) / - WM_RADIAL_CONTROL_DISPLAY_WIDTH; - if (snap) { - new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f; - } - /* Invert new value to increase the factor moving the mouse to the right */ - new_value = 1 - new_value; - break; - case PROP_ANGLE: - new_value = atan2f(delta[1], delta[0]) + (float)M_PI + angle_precision; - new_value = fmod(new_value, 2.0f * (float)M_PI); - if (new_value < 0.0f) { - new_value += 2.0f * (float)M_PI; - } - if (snap) { - new_value = DEG2RADF(((int)RAD2DEGF(new_value) + 5) / 10 * 10); - } - break; - default: - new_value = dist; /* dummy value, should this ever happen? - campbell */ - break; + dist = dist + 0.1f * (delta[0]); } - - /* clamp and update */ - CLAMP(new_value, rc->min_value, rc->max_value); - radial_control_set_value(rc, new_value); - rc->current_value = new_value; - handled = true; - break; } - break; - - case EVT_LEFTSHIFTKEY: - case EVT_RIGHTSHIFTKEY: { - if (event->val == KM_PRESS) { - rc->slow_mouse[0] = event->x; - rc->slow_mouse[1] = event->y; - rc->slow_mode = true; + else { + delta[0] = rc->initial_mouse[0] - event->x; + delta[1] = rc->initial_mouse[1] - event->y; + if (rc->zoom_prop) { + RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); + delta[0] /= zoom[0]; + delta[1] /= zoom[1]; + } if (rc->subtype == PROP_ANGLE) { - float initial_position[2] = {UNPACK2(rc->initial_mouse)}; - float current_position[2] = {UNPACK2(rc->slow_mouse)}; - rc->dial = BLI_dial_init(initial_position, 0.0f); - /* immediately set the position to get a an initial direction */ - BLI_dial_angle(rc->dial, current_position); + dist = len_v2(delta); } - handled = true; - } - if (event->val == KM_RELEASE) { - rc->slow_mode = false; - handled = true; - if (rc->dial) { - MEM_freeN(rc->dial); - rc->dial = NULL; + else { + dist = clamp_f(-delta[0], 0.0f, FLT_MAX); } } + + /* calculate new value and apply snapping */ + switch (rc->subtype) { + case PROP_NONE: + case PROP_DISTANCE: + case PROP_PIXEL: + new_value = dist; + if (snap) { + new_value = ((int)new_value + 5) / 10 * 10; + } + break; + case PROP_PERCENTAGE: + new_value = ((dist - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE) / + WM_RADIAL_CONTROL_DISPLAY_WIDTH) * + 100.0f; + if (snap) { + new_value = ((int)(new_value + 2.5f)) / 5 * 5; + } + break; + case PROP_FACTOR: + new_value = (WM_RADIAL_CONTROL_DISPLAY_SIZE - dist) / WM_RADIAL_CONTROL_DISPLAY_WIDTH; + if (snap) { + new_value = ((int)ceil(new_value * 10.f) * 10.0f) / 100.f; + } + /* Invert new value to increase the factor moving the mouse to the right */ + new_value = 1 - new_value; + break; + case PROP_ANGLE: + new_value = atan2f(delta[1], delta[0]) + (float)M_PI + angle_precision; + new_value = fmod(new_value, 2.0f * (float)M_PI); + if (new_value < 0.0f) { + new_value += 2.0f * (float)M_PI; + } + if (snap) { + new_value = DEG2RADF(((int)RAD2DEGF(new_value) + 5) / 10 * 10); + } + break; + default: + new_value = dist; /* dummy value, should this ever happen? - campbell */ + break; + } + + /* clamp and update */ + CLAMP(new_value, rc->min_value, rc->max_value); + radial_control_set_value(rc, new_value); + rc->current_value = new_value; + handled = true; break; } + break; + + case EVT_LEFTSHIFTKEY: + case EVT_RIGHTSHIFTKEY: { + if (event->val == KM_PRESS) { + rc->slow_mouse[0] = event->x; + rc->slow_mouse[1] = event->y; + rc->slow_mode = true; + if (rc->subtype == PROP_ANGLE) { + float initial_position[2] = {UNPACK2(rc->initial_mouse)}; + float current_position[2] = {UNPACK2(rc->slow_mouse)}; + rc->dial = BLI_dial_init(initial_position, 0.0f); + /* immediately set the position to get a an initial direction */ + BLI_dial_angle(rc->dial, current_position); + } + handled = true; + } + if (event->val == KM_RELEASE) { + rc->slow_mode = false; + handled = true; + if (rc->dial) { + MEM_freeN(rc->dial); + rc->dial = NULL; + } + } + break; } + } - /* Modal numinput inactive, try to handle numeric inputs last... */ - if (!handled && event->val == KM_PRESS && handleNumInput(C, &rc->num_input, event)) { - applyNumInput(&rc->num_input, &numValue); + /* Modal numinput inactive, try to handle numeric inputs last... */ + if (!handled && event->val == KM_PRESS && handleNumInput(C, &rc->num_input, event)) { + applyNumInput(&rc->num_input, &numValue); - if (rc->subtype == PROP_ANGLE) { - numValue = fmod(numValue, 2.0f * (float)M_PI); - if (numValue < 0.0f) { - numValue += 2.0f * (float)M_PI; - } + if (rc->subtype == PROP_ANGLE) { + numValue = fmod(numValue, 2.0f * (float)M_PI); + if (numValue < 0.0f) { + numValue += 2.0f * (float)M_PI; } + } - CLAMP(numValue, rc->min_value, rc->max_value); - new_value = numValue; + CLAMP(numValue, rc->min_value, rc->max_value); + new_value = numValue; - radial_control_set_value(rc, new_value); + radial_control_set_value(rc, new_value); - rc->current_value = new_value; - radial_control_update_header(op, C); - return OPERATOR_RUNNING_MODAL; - } + rc->current_value = new_value; + radial_control_update_header(op, C); + return OPERATOR_RUNNING_MODAL; } ED_region_tag_redraw(CTX_wm_region(C)); diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c index 245560d3795..9667ed5b631 100644 --- a/source/blender/windowmanager/intern/wm_stereo.c +++ b/source/blender/windowmanager/intern/wm_stereo.c @@ -353,12 +353,11 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_WINDOW, NULL); return OPERATOR_FINISHED; } - else { - /* without this, the popup won't be freed freed properly T44688 */ - CTX_wm_window_set(C, win_src); - win_src->stereo3d_format->display_mode = prev_display_mode; - return OPERATOR_CANCELLED; - } + + /* without this, the popup won't be freed freed properly T44688 */ + CTX_wm_window_set(C, win_src); + win_src->stereo3d_format->display_mode = prev_display_mode; + return OPERATOR_CANCELLED; } int wm_stereo3d_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) @@ -368,9 +367,7 @@ int wm_stereo3d_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(ev if (wm_stereo3d_set_properties(C, op)) { return wm_stereo3d_set_exec(C, op); } - else { - return WM_operator_props_dialog_popup(C, op, 250); - } + return WM_operator_props_dialog_popup(C, op, 250); } void wm_stereo3d_set_draw(bContext *UNUSED(C), wmOperator *op) diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index fc04323333b..e0dcd746aea 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -355,10 +355,8 @@ wmWindow *wm_window_copy_test(bContext *C, WM_event_add_notifier_ex(wm, CTX_wm_window(C), NC_WINDOW | NA_ADDED, NULL); return win_dst; } - else { - wm_window_close(C, wm, win_dst); - return NULL; - } + wm_window_close(C, wm, win_dst); + return NULL; } /** \} */ @@ -813,9 +811,7 @@ static bool wm_window_update_size_position(wmWindow *win) win->posy = posy; return true; } - else { - return false; - } + return false; } /** @@ -840,11 +836,10 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect) if (win->ghostwin) { return win; } - else { - wm_window_close(C, wm, win); - CTX_wm_window_set(C, win_prev); - return NULL; - } + + wm_window_close(C, wm, win); + CTX_wm_window_set(C, win_prev); + return NULL; } /** @@ -969,13 +964,12 @@ wmWindow *WM_window_open_temp(bContext *C, GHOST_SetTitle(win->ghostwin, title); return win; } - else { - /* very unlikely! but opening a new window can fail */ - wm_window_close(C, wm, win); - CTX_wm_window_set(C, win_prev); - return NULL; - } + /* very unlikely! but opening a new window can fail */ + wm_window_close(C, wm, win); + CTX_wm_window_set(C, win_prev); + + return NULL; } /* ****************** Operators ****************** */ @@ -1215,15 +1209,13 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr puts(" event has no window"); return 1; } - else if (!GHOST_ValidWindow(g_system, ghostwin)) { + if (!GHOST_ValidWindow(g_system, ghostwin)) { /* XXX - should be checked, why are we getting an event here, and */ /* what is it? */ puts(" event has invalid window"); return 1; } - else { - win = GHOST_GetWindowUserData(ghostwin); - } + win = GHOST_GetWindowUserData(ghostwin); switch (type) { case GHOST_kEventWindowDeactivate: diff --git a/source/blender/windowmanager/xr/intern/wm_xr_session.c b/source/blender/windowmanager/xr/intern/wm_xr_session.c index c564f74b771..b44f006cde8 100644 --- a/source/blender/windowmanager/xr/intern/wm_xr_session.c +++ b/source/blender/windowmanager/xr/intern/wm_xr_session.c @@ -183,16 +183,15 @@ static wmXrSessionStateEvent wm_xr_session_state_to_event(const wmXrSessionState if (!state->is_view_data_set) { return SESSION_STATE_EVENT_START; } - else if (wm_xr_session_draw_data_needs_reset_to_base_pose(state, settings)) { + if (wm_xr_session_draw_data_needs_reset_to_base_pose(state, settings)) { return SESSION_STATE_EVENT_RESET_TO_BASE_POSE; } - else { - const bool position_tracking_toggled = ((state->prev_settings_flag & - XR_SESSION_USE_POSITION_TRACKING) != - (settings->flag & XR_SESSION_USE_POSITION_TRACKING)); - if (position_tracking_toggled) { - return SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE; - } + + const bool position_tracking_toggled = ((state->prev_settings_flag & + XR_SESSION_USE_POSITION_TRACKING) != + (settings->flag & XR_SESSION_USE_POSITION_TRACKING)); + if (position_tracking_toggled) { + return SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE; } return SESSION_STATE_EVENT_NONE; -- cgit v1.2.3