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.
This commit is contained in:
2020-08-07 11:23:02 +02:00
parent e0c51b466f
commit a29686eeb3
59 changed files with 1079 additions and 1350 deletions

View File

@@ -92,13 +92,9 @@ static bool keycmp(const void *a, const void *b)
if (ka->case_str == 1 || kb->case_str == 1) { if (ka->case_str == 1 || kb->case_str == 1) {
return (BLI_strcasecmp(ka->arg, kb->arg) != 0); return (BLI_strcasecmp(ka->arg, kb->arg) != 0);
} }
else { return (!STREQ(ka->arg, kb->arg));
return (!STREQ(ka->arg, kb->arg));
}
}
else {
return BLI_ghashutil_intcmp((const void *)ka->pass, (const void *)kb->pass);
} }
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) static bArgument *lookUp(struct bArgs *ba, const char *arg, int pass, int case_str)

View File

@@ -538,10 +538,8 @@ BLI_INLINE bool ghash_insert_safe(GHash *gh,
} }
return false; return false;
} }
else { ghash_insert_ex(gh, key, val, bucket_index);
ghash_insert_ex(gh, key, val, bucket_index); return true;
return true;
}
} }
BLI_INLINE bool ghash_insert_safe_keyonly(GHash *gh, BLI_INLINE bool ghash_insert_safe_keyonly(GHash *gh,
@@ -564,10 +562,8 @@ BLI_INLINE bool ghash_insert_safe_keyonly(GHash *gh,
} }
return false; return false;
} }
else { ghash_insert_ex_keyonly(gh, key, bucket_index);
ghash_insert_ex_keyonly(gh, key, bucket_index); return true;
return true;
}
} }
/** /**
@@ -792,9 +788,7 @@ void *BLI_ghash_replace_key(GHash *gh, void *key)
e->e.key = key; e->e.key = key;
return key_prev; return key_prev;
} }
else { return NULL;
return NULL;
}
} }
/** /**
@@ -915,9 +909,7 @@ bool BLI_ghash_remove(GHash *gh,
BLI_mempool_free(gh->entrypool, e); BLI_mempool_free(gh->entrypool, e);
return true; return true;
} }
else { return false;
return false;
}
} }
/* same as above but return the value, /* 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); BLI_mempool_free(gh->entrypool, e);
return val; 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); BLI_mempool_free(gh->entrypool, e);
return true; return true;
} }
else {
*r_key = *r_val = NULL; *r_key = *r_val = NULL;
return false; return false;
}
} }
/** /**
@@ -1246,10 +1235,9 @@ bool BLI_gset_pop(GSet *gs, GSetIterState *state, void **r_key)
BLI_mempool_free(((GHash *)gs)->entrypool, e); BLI_mempool_free(((GHash *)gs)->entrypool, e);
return true; return true;
} }
else {
*r_key = NULL; *r_key = NULL;
return false; return false;
}
} }
void BLI_gset_clear_ex(GSet *gs, GSetKeyFreeFP keyfreefp, const uint nentries_reserve) 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); BLI_mempool_free(((GHash *)gs)->entrypool, e);
return key_ret; return key_ret;
} }
else { return NULL;
return NULL;
}
} }
/** \} */ /** \} */

View File

@@ -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]) { if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) {
return a[mid]; return a[mid];
} }
else { if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) {
if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { return a[hi];
return a[hi];
}
else {
return a[lo];
}
} }
return a[lo];
} }
else {
if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) { if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) {
if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) { if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) {
return a[lo]; return a[lo];
}
else {
return a[hi];
}
}
else {
return a[mid];
} }
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]) { if (middle_point[0] > middle_point[2]) {
return 1; /* max x axis */ return 1; /* max x axis */
} }
else { return 5; /* max z axis */
return 5; /* max z axis */
}
} }
else { if (middle_point[1] > middle_point[2]) {
if (middle_point[1] > middle_point[2]) { return 3; /* max y axis */
return 3; /* max y axis */
}
else {
return 5; /* max z 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) { if (min_leaf_index <= data->remain_leafs) {
return min_leaf_index; return min_leaf_index;
} }
else if (data->leafs_per_child[depth]) { if (data->leafs_per_child[depth]) {
return data->totleafs - return data->totleafs -
(data->branches_on_level[depth - 1] - child_index) * data->leafs_per_child[depth]; (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); data->callback(data->userdata, node->index, data->co, &data->nearest);
return (data->nearest.dist_sq < dist_sq); return (data->nearest.dist_sq < dist_sq);
} }
else { data->nearest.index = node->index;
data->nearest.index = node->index; return true;
return true;
}
} }
} }
else { 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)) { (t1x > data->hit.dist || t1y > data->hit.dist || t1z > data->hit.dist)) {
return FLT_MAX; return FLT_MAX;
} }
else { return max_fff(t1x, t1y, t1z);
return max_fff(t1x, t1y, t1z);
}
} }
static void dfs_raycast(BVHRayCastData *data, BVHNode *node) 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( return walk_data->walk_leaf_cb(
(const BVHTreeAxisRange *)node->bv, node->index, walk_data->userdata); (const BVHTreeAxisRange *)node->bv, node->index, walk_data->userdata);
} }
else {
/* First pick the closest node to recurse into */ /* First pick the closest node to recurse into */
if (walk_data->walk_order_cb( if (walk_data->walk_order_cb(
(const BVHTreeAxisRange *)node->bv, node->main_axis, walk_data->userdata)) { (const BVHTreeAxisRange *)node->bv, node->main_axis, walk_data->userdata)) {
for (int i = 0; i != node->totnode; i++) { for (int i = 0; i != node->totnode; i++) {
if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv, if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv,
walk_data->userdata)) { walk_data->userdata)) {
if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) { if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) {
return false; return false;
}
} }
} }
} }
else { }
for (int i = node->totnode - 1; i >= 0; i--) { else {
if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv, for (int i = node->totnode - 1; i >= 0; i--) {
walk_data->userdata)) { if (walk_data->walk_parent_cb((const BVHTreeAxisRange *)node->children[i]->bv,
if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) { walk_data->userdata)) {
return false; if (!bvhtree_walk_dfs_recursive(walk_data, node->children[i])) {
} return false;
} }
} }
} }

View File

@@ -147,7 +147,7 @@ void BLI_linklist_move_item(LinkNode **listp, int curr_index, int new_index)
lnk_pdst = lnk; lnk_pdst = lnk;
break; break;
} }
else if (i == curr_index - 1) { if (i == curr_index - 1) {
lnk_psrc = lnk; lnk_psrc = lnk;
} }
} }

View File

@@ -269,9 +269,7 @@ void *BLI_memiter_elem_first(BLI_memiter *mi)
BLI_memiter_elem *elem = (BLI_memiter_elem *)chunk->data; BLI_memiter_elem *elem = (BLI_memiter_elem *)chunk->data;
return elem->data; return elem->data;
} }
else { return NULL;
return NULL;
}
} }
void *BLI_memiter_elem_first_size(BLI_memiter *mi, uint *r_size) 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; *r_size = (uint)elem->size;
return elem->data; 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)]; iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)];
return (void *)data; return (void *)data;
} }
else { return NULL;
return NULL;
}
} }
void *BLI_memiter_iter_step(BLI_memiter_handle *iter) 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)]; iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)];
return (void *)data; return (void *)data;
} }
else { return NULL;
return NULL;
}
} }
/** \} */ /** \} */

View File

@@ -299,9 +299,7 @@ static DLRBT_Node *get_grandparent(DLRBT_Node *node)
if (node && node->parent) { if (node && node->parent) {
return node->parent->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) */ /* 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) { if (node == node->parent->left) {
return node->parent->right; return node->parent->right;
} }
else { return node->parent->left;
return node->parent->left;
}
} }
/* sibling not found */ /* sibling not found */

View File

@@ -355,9 +355,7 @@ static bool bchunk_data_compare(const BChunk *chunk,
if (offset + (size_t)chunk->data_len <= data_base_len) { if (offset + (size_t)chunk->data_len <= data_base_len) {
return (memcmp(&data_base[offset], chunk->data, chunk->data_len) == 0); 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 # endif
return key; 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_array_from_cref(info, cref, info->accum_read_ahead_bytes, hash_store);
hash_accum_single(hash_store, hash_store_len, info->accum_steps); hash_accum_single(hash_store, hash_store_len, info->accum_steps);
hash_key key = hash_store[0]; hash_key key = hash_store[0];
# ifdef USE_HASH_TABLE_KEY_CACHE # ifdef USE_HASH_TABLE_KEY_CACHE
if (UNLIKELY(key == HASH_TABLE_KEY_UNSET)) { if (UNLIKELY(key == HASH_TABLE_KEY_UNSET)) {
key = HASH_TABLE_KEY_FALLBACK; key = HASH_TABLE_KEY_FALLBACK;
}
# endif
return key;
} }
# endif
return key;
} }
static const BChunkRef *table_lookup(const BArrayInfo *info, 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) { if (cref == cref_match_first) {
break; break;
} }
else { cref = cref->next;
cref = cref->next;
}
} }
/* happens when bytes are removed from the end of the array */ /* happens when bytes are removed from the end of the array */
if (chunk_size_step == data_len_original) { if (chunk_size_step == data_len_original) {

View File

@@ -208,7 +208,7 @@ bool _bli_array_iter_span(const void *arr,
if (arr_len == 0) { if (arr_len == 0) {
return false; 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; return false;
} }

View File

@@ -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]) { if (co_a[1] < co_b[1]) {
return -1; return -1;
} }
else if (co_a[1] > co_b[1]) { if (co_a[1] > co_b[1]) {
return 1; return 1;
} }
else if (co_a[0] < co_b[0]) { if (co_a[0] < co_b[0]) {
return -1; return -1;
} }
else if (co_a[0] > co_b[0]) { if (co_a[0] > co_b[0]) {
return 1; return 1;
} }
else { /* co_a & co_b are identical, use the line closest to the x-min */
/* co_a & co_b are identical, use the line closest to the x-min */ const int *co = co_a;
const int *co = co_a; co_a = verts[a[1]];
co_a = verts[a[1]]; co_b = verts[b[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])));
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) {
if (ord > 0) { return -1;
return -1; }
} if (ord < 0) {
if (ord < 0) { return 1;
return 1;
}
} }
return 0; return 0;
} }

View File

@@ -216,7 +216,7 @@ static int box_areasort(const void *p1, const void *p2)
if (a1 < a2) { if (a1 < a2) {
return 1; return 1;
} }
else if (a1 > a2) { if (a1 > a2) {
return -1; return -1;
} }
return 0; 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)) { if (UNLIKELY(v1->free == 0 && v2->free == 0)) {
return 0; return 0;
} }
else if (UNLIKELY(v1->free == 0)) { if (UNLIKELY(v1->free == 0)) {
return 1; return 1;
} }
else if (UNLIKELY(v2->free == 0)) { if (UNLIKELY(v2->free == 0)) {
return -1; return -1;
} }
#endif #endif
@@ -266,7 +266,7 @@ static int vertex_sort(const void *p1, const void *p2, void *vs_ctx_p)
if (a1 > a2) { if (a1 > a2) {
return 1; return 1;
} }
else if (a1 < a2) { if (a1 < a2) {
return -1; return -1;
} }
return 0; return 0;

View File

@@ -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) { if (is_left(points[r_points[top - 1]], points[r_points[top]], points[i]) > 0.0f) {
break; /* points[i] is a new hull vertex */ 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 */ 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) { if (is_left(points[r_points[top - 1]], points[r_points[top]], points[i]) > 0.0f) {
break; /* points[i] is a new hull vertex */ 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]) { 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]) { if (a->pt[1] > b->pt[1]) {
return 1; return 1;
} }
else if (a->pt[1] < b->pt[1]) { if (a->pt[1] < b->pt[1]) {
return -1; return -1;
} }
if (a->pt[0] > b->pt[0]) { if (a->pt[0] > b->pt[0]) {
return 1; return 1;
} }
else if (a->pt[0] < b->pt[0]) { if (a->pt[0] < b->pt[0]) {
return -1; return -1;
} }
return 0;
else {
return 0;
}
} }
/** /**

View File

@@ -600,19 +600,19 @@ static int site_lexicographic_cmp(const void *a, const void *b)
if (co1[0] < co2[0]) { if (co1[0] < co2[0]) {
return -1; return -1;
} }
else if (co1[0] > co2[0]) { if (co1[0] > co2[0]) {
return 1; return 1;
} }
else if (co1[1] < co2[1]) { if (co1[1] < co2[1]) {
return -1; return -1;
} }
else if (co1[1] > co2[1]) { if (co1[1] > co2[1]) {
return 1; return 1;
} }
else if (s1->orig_index < s2->orig_index) { if (s1->orig_index < s2->orig_index) {
return -1; return -1;
} }
else if (s1->orig_index > s2->orig_index) { if (s1->orig_index > s2->orig_index) {
return 1; return 1;
} }
return 0; return 0;
@@ -974,7 +974,7 @@ static void initial_triangulation(CDT_state *cdt)
if (jco[0] > xend) { if (jco[0] > xend) {
break; /* No more j's to process. */ 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. */ /* Get past any string of v's with the same x and too-big y. */
xcur = jco[0]; xcur = jco[0];
while (++j < n) { while (++j < n) {
@@ -1414,7 +1414,7 @@ static bool get_next_crossing_from_vert(CDT_state *cdt,
ok = true; ok = true;
break; break;
} }
else if (t->face != cdt->outer_face) { if (t->face != cdt->outer_face) {
orient2 = orient2d(vcur->co, vb->co, v2->co); orient2 = orient2d(vcur->co, vb->co, v2->co);
#ifdef DEBUG_CDT #ifdef DEBUG_CDT
if (dbg_level > 1) { 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)) { (cd_prev->lambda != 0.0 && cd_prev->in->vert != v && cd_prev->in->next->vert != v)) {
break; 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 #ifdef DEBUG_CDT
if (dbg_level > 0) { if (dbg_level > 0) {
fprintf(stderr, "deleted crossing %d\n", j); fprintf(stderr, "deleted crossing %d\n", j);
}
#endif
} }
#endif
} }
if (j < i - 1) { if (j < i - 1) {
/* Some crossings were deleted. Fix the in and out edges across gap. */ /* 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) { if (area->e_id < sb->e_id) {
return -1; return -1;
} }
else if (area->e_id > sb->e_id) { if (area->e_id > sb->e_id) {
return 1; return 1;
} }
else if (area->lambda < sb->lambda) { if (area->lambda < sb->lambda) {
return -1; return -1;
} }
else if (area->lambda > sb->lambda) { if (area->lambda > sb->lambda) {
return 1; return 1;
} }
else if (area->v_id < sb->v_id) { if (area->v_id < sb->v_id) {
return -1; return -1;
} }
else if (area->v_id > sb->v_id) { if (area->v_id > sb->v_id) {
return 1; return 1;
} }
return 0; return 0;
@@ -2386,9 +2384,7 @@ static const CDT_input *modify_input_for_near_edge_ends(const CDT_input *input,
if (new_input != NULL) { if (new_input != NULL) {
return (const CDT_input *)new_input; return (const CDT_input *)new_input;
} }
else { return input;
return input;
}
} }
static void free_modified_input(CDT_input *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) { if (e1->len_squared > e2->len_squared) {
return -1; return -1;
} }
else if (e1->len_squared < e2->len_squared) { if (e1->len_squared < e2->len_squared) {
return 1; return 1;
} }
return 0; return 0;
@@ -4570,17 +4566,13 @@ static double orient2d(const double *pa, const double *pb, const double *pc)
if (detright <= 0.0) { if (detright <= 0.0) {
return det; return det;
} }
else { detsum = detleft + detright;
detsum = detleft + detright;
}
} }
else if (detleft < 0.0) { else if (detleft < 0.0) {
if (detright >= 0.0) { if (detright >= 0.0) {
return det; return det;
} }
else { detsum = -detleft - detright;
detsum = -detleft - detright;
}
} }
else { else {
return det; return det;

View File

@@ -60,7 +60,7 @@ void Cluster::set_parent_cluster(Cluster *new_parent)
if (parent_ == new_parent) { if (parent_ == new_parent) {
return; return;
} }
else if (parent_ == nullptr) { if (parent_ == nullptr) {
graph_.top_level_clusters_.remove(this); graph_.top_level_clusters_.remove(this);
new_parent->children_.add_new(this); new_parent->children_.add_new(this);
} }
@@ -80,7 +80,7 @@ void Node::set_parent_cluster(Cluster *cluster)
if (cluster_ == cluster) { if (cluster_ == cluster) {
return; return;
} }
else if (cluster_ == nullptr) { if (cluster_ == nullptr) {
graph_.top_level_nodes_.remove(this); graph_.top_level_nodes_.remove(this);
cluster->nodes_.add_new(this); cluster->nodes_.add_new(this);
} }

View File

@@ -72,18 +72,16 @@ float BLI_easing_bounce_ease_out(float time, float begin, float change, float du
if (time < (1 / 2.75f)) { if (time < (1 / 2.75f)) {
return change * (7.5625f * time * time) + begin; return change * (7.5625f * time * time) + begin;
} }
else if (time < (2 / 2.75f)) { if (time < (2 / 2.75f)) {
time -= (1.5f / 2.75f); time -= (1.5f / 2.75f);
return change * ((7.5625f * time) * time + 0.75f) + begin; 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); time -= (2.25f / 2.75f);
return change * ((7.5625f * time) * time + 0.9375f) + begin; return change * ((7.5625f * time) * time + 0.9375f) + begin;
} }
else { time -= (2.625f / 2.75f);
time -= (2.625f / 2.75f); return change * ((7.5625f * time) * time + 0.984375f) + begin;
return change * ((7.5625f * time) * time + 0.984375f) + begin;
}
} }
float BLI_easing_bounce_ease_in(float time, float begin, float change, float duration) 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) { if (time < duration / 2) {
return BLI_easing_bounce_ease_in(time * 2, 0, change, duration) * 0.5f + begin; 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 +
return BLI_easing_bounce_ease_out(time * 2 - duration, 0, change, duration) * 0.5f + change * 0.5f + begin;
change * 0.5f + begin;
}
} }
float BLI_easing_circ_ease_in(float time, float begin, float change, float duration) 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))) + sinf((time * duration - s) * (2 * (float)M_PI) / period))) +
begin; begin;
} }
else {
time = -time; time = -time;
f *= 0.5f; f *= 0.5f;
return (f * (amplitude * powf(2, 10 * time) * return (f * (amplitude * powf(2, 10 * time) *
sinf((time * duration - s) * (2 * (float)M_PI) / period))) + sinf((time * duration - s) * (2 * (float)M_PI) / period))) +
change + begin; change + begin;
}
} }
static const float pow_min = 0.0009765625f; /* = 2^(-10) */ 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) { if (time <= duration_half) {
return BLI_easing_expo_ease_in(time, begin, change_half, duration_half); return BLI_easing_expo_ease_in(time, begin, change_half, duration_half);
} }
else { return BLI_easing_expo_ease_out(
return BLI_easing_expo_ease_out( time - duration_half, begin + change_half, change_half, duration_half);
time - duration_half, begin + change_half, change_half, duration_half);
}
} }
float BLI_easing_linear_ease(float time, float begin, float change, float duration) float BLI_easing_linear_ease(float time, float begin, float change, float duration)

View File

@@ -185,7 +185,7 @@ BLI_INLINE EdgeHashEntry *edgehash_insert(EdgeHash *eh, Edge edge, void *value)
if (index == SLOT_EMPTY) { if (index == SLOT_EMPTY) {
return edgehash_insert_at_slot(eh, slot, edge, value); return edgehash_insert_at_slot(eh, slot, edge, value);
} }
else if (index == SLOT_DUMMY) { if (index == SLOT_DUMMY) {
eh->dummy_count--; eh->dummy_count--;
return edgehash_insert_at_slot(eh, slot, edge, value); 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)) { if (EH_INDEX_HAS_EDGE(eh, index, edge)) {
return &eh->entries[index]; return &eh->entries[index];
} }
else if (index == SLOT_EMPTY) { if (index == SLOT_EMPTY) {
return NULL; return NULL;
} }
} }
@@ -294,7 +294,7 @@ bool BLI_edgehash_reinsert(EdgeHash *eh, uint v0, uint v1, void *value)
eh->entries[index].value = value; eh->entries[index].value = value;
return false; return false;
} }
else if (index == SLOT_EMPTY) { if (index == SLOT_EMPTY) {
if (edgehash_ensure_can_insert(eh)) { if (edgehash_ensure_can_insert(eh)) {
edgehash_insert(eh, edge, value); 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; *r_value = &eh->entries[index].value;
return true; return true;
} }
else if (index == SLOT_EMPTY) { if (index == SLOT_EMPTY) {
if (edgehash_ensure_can_insert(eh)) { if (edgehash_ensure_can_insert(eh)) {
*r_value = &edgehash_insert(eh, edge, NULL)->value; *r_value = &edgehash_insert(eh, edge, NULL)->value;
} }
@@ -413,7 +413,7 @@ void *BLI_edgehash_popkey(EdgeHash *eh, uint v0, uint v1)
} }
return value; return value;
} }
else if (index == SLOT_EMPTY) { if (index == SLOT_EMPTY) {
return NULL; return NULL;
} }
} }
@@ -583,7 +583,7 @@ bool BLI_edgeset_add(EdgeSet *es, uint v0, uint v1)
if (ES_INDEX_HAS_EDGE(es, index, edge)) { if (ES_INDEX_HAS_EDGE(es, index, edge)) {
return false; return false;
} }
else if (index == SLOT_EMPTY) { if (index == SLOT_EMPTY) {
edgeset_insert_at_slot(es, slot, edge); edgeset_insert_at_slot(es, slot, edge);
return true; return true;
} }
@@ -615,7 +615,7 @@ bool BLI_edgeset_haskey(EdgeSet *es, uint v0, uint v1)
if (ES_INDEX_HAS_EDGE(es, index, edge)) { if (ES_INDEX_HAS_EDGE(es, index, edge)) {
return true; return true;
} }
else if (index == SLOT_EMPTY) { if (index == SLOT_EMPTY) {
return false; return false;
} }
} }

View File

@@ -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."; "Blender may not support moving files or directories to trash on your system.";
return -1; return -1;
} }
else if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus)) { if (WIFEXITED(wstatus) && WEXITSTATUS(wstatus)) {
*error_message = process_failed; *error_message = process_failed;
return -1; return -1;
} }
@@ -1036,12 +1036,10 @@ int BLI_delete(const char *file, bool dir, bool recursive)
if (recursive) { if (recursive) {
return recursive_operation(file, NULL, NULL, delete_single_file, delete_callback_post); return recursive_operation(file, NULL, NULL, delete_single_file, delete_callback_post);
} }
else if (dir) { if (dir) {
return rmdir(file); 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; return RecursiveOp_Callback_OK;
} }
else if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || S_ISFIFO(st.st_mode) || if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode) || S_ISFIFO(st.st_mode) || S_ISSOCK(st.st_mode)) {
S_ISSOCK(st.st_mode)) {
/* copy special type of file */ /* copy special type of file */
if (mknod(to, st.st_mode, st.st_rdev)) { if (mknod(to, st.st_mode, st.st_rdev)) {
perror("mknod"); perror("mknod");
@@ -1198,7 +1195,7 @@ static int copy_single_file(const char *from, const char *to)
return RecursiveOp_Callback_OK; 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"); fprintf(stderr, "Copying of this kind of files isn't supported yet\n");
return RecursiveOp_Callback_Error; return RecursiveOp_Callback_Error;
} }
@@ -1337,7 +1334,7 @@ bool BLI_dir_create_recursive(const char *dirname)
if (BLI_is_dir(dirname)) { if (BLI_is_dir(dirname)) {
return true; return true;
} }
else if (BLI_exists(dirname)) { if (BLI_exists(dirname)) {
return false; return false;
} }

View File

@@ -60,10 +60,9 @@ bool BLI_lasso_is_point_inside(const int mcoords[][2],
if (sx == error_value || mcoords_len == 0) { if (sx == error_value || mcoords_len == 0) {
return false; return false;
} }
else {
int pt[2] = {sx, sy}; int pt[2] = {sx, sy};
return isect_point_poly_v2_int(pt, mcoords, mcoords_len, true); return isect_point_poly_v2_int(pt, mcoords, mcoords_len, true);
}
} }
/* edge version for lasso select. we assume boundbox check was done */ /* edge version for lasso select. we assume boundbox check was done */

View File

@@ -162,9 +162,8 @@ bool BLI_remlink_safe(ListBase *listbase, void *vlink)
BLI_remlink(listbase, vlink); BLI_remlink(listbase, vlink);
return true; return true;
} }
else {
return false; return false;
}
} }
/** /**

View File

@@ -439,9 +439,8 @@ float srgb_to_linearrgb(float c)
if (c < 0.04045f) { if (c < 0.04045f) {
return (c < 0.0f) ? 0.0f : c * (1.0f / 12.92f); 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) float linearrgb_to_srgb(float c)
@@ -449,9 +448,8 @@ float linearrgb_to_srgb(float c)
if (c < 0.0031308f) { if (c < 0.0031308f) {
return (c < 0.0f) ? 0.0f : c * 12.92f; 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]) void minmax_rgb(short c[3])

View File

@@ -231,9 +231,8 @@ float cotangent_tri_weight_v3(const float v1[3], const float v2[3], const float
if (c_len > FLT_EPSILON) { if (c_len > FLT_EPSILON) {
return dot_v3v3(a, b) / c_len; return dot_v3v3(a, b) / c_len;
} }
else {
return 0.0f; return 0.0f;
}
} }
/********************************* Planes **********************************/ /********************************* Planes **********************************/
@@ -589,9 +588,8 @@ float dist_signed_squared_to_corner_v3v3v3(const float p[3],
if (flip) { if (flip) {
return min_ff(dist_a, dist_b); 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; return ISECT_LINE_LINE_CROSS;
} }
else {
return ISECT_LINE_LINE_COLINEAR; return ISECT_LINE_LINE_COLINEAR;
}
} }
/* intersect Line-Line, floats */ /* intersect Line-Line, floats */
@@ -1304,55 +1301,54 @@ int isect_seg_seg_v2_point_ex(const float v0[2],
/* out of segment intersection */ /* out of segment intersection */
return -1; 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 ((cross_v2v2(s10, s30) == 0.0f) && (cross_v2v2(s32, s30) == 0.0f)) {
if (len_squared_v2v2(v2, v3) > square_f(eps)) { /* equal lines */
/* use non-point segment as basis */ float s20[2];
SWAP(const float *, v0, v2); float u_a, u_b;
SWAP(const float *, v1, v3);
sub_v2_v2v2(s10, v1, v0); if (equals_v2v2(v0, v1)) {
sub_v2_v2v2(s30, v3, v0); if (len_squared_v2v2(v2, v3) > square_f(eps)) {
} /* use non-point segment as basis */
else { /* both of segments are points */ SWAP(const float *, v0, v2);
if (equals_v2v2(v0, v2)) { /* points are equal */ SWAP(const float *, v1, v3);
copy_v2_v2(r_vi, v0);
return 1;
}
/* two different points */ sub_v2_v2v2(s10, v1, v0);
return -1; 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;
}
sub_v2_v2v2(s20, v2, v0); /* two different points */
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; 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 */ sub_v2_v2v2(s20, v2, v0);
return -1;
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( int isect_seg_seg_v2_point(
@@ -1472,13 +1468,13 @@ int isect_line_sphere_v3(const float l1[3],
/* no intersections */ /* no intersections */
return 0; return 0;
} }
else if (i == 0.0f) { if (i == 0.0f) {
/* one intersection */ /* one intersection */
mu = -b / (2.0f * a); mu = -b / (2.0f * a);
madd_v3_v3v3fl(r_p1, l1, ldir, mu); madd_v3_v3v3fl(r_p1, l1, ldir, mu);
return 1; return 1;
} }
else if (i > 0.0f) { if (i > 0.0f) {
const float i_sqrt = sqrtf(i); /* avoid calc twice */ const float i_sqrt = sqrtf(i); /* avoid calc twice */
/* first intersection */ /* first intersection */
@@ -1490,10 +1486,9 @@ int isect_line_sphere_v3(const float l1[3],
madd_v3_v3v3fl(r_p2, l1, ldir, mu); madd_v3_v3v3fl(r_p2, l1, ldir, mu);
return 2; return 2;
} }
else {
/* math domain error - nan */ /* math domain error - nan */
return -1; return -1;
}
} }
/* keep in sync with isect_line_sphere_v3 */ /* keep in sync with isect_line_sphere_v3 */
@@ -1520,13 +1515,13 @@ int isect_line_sphere_v2(const float l1[2],
/* no intersections */ /* no intersections */
return 0; return 0;
} }
else if (i == 0.0f) { if (i == 0.0f) {
/* one intersection */ /* one intersection */
mu = -b / (2.0f * a); mu = -b / (2.0f * a);
madd_v2_v2v2fl(r_p1, l1, ldir, mu); madd_v2_v2v2fl(r_p1, l1, ldir, mu);
return 1; return 1;
} }
else if (i > 0.0f) { if (i > 0.0f) {
const float i_sqrt = sqrtf(i); /* avoid calc twice */ const float i_sqrt = sqrtf(i); /* avoid calc twice */
/* first intersection */ /* first intersection */
@@ -1538,10 +1533,9 @@ int isect_line_sphere_v2(const float l1[2],
madd_v2_v2v2fl(r_p2, l1, ldir, mu); madd_v2_v2v2fl(r_p2, l1, ldir, mu);
return 2; return 2;
} }
else {
/* math domain error - nan */ /* math domain error - nan */
return -1; return -1;
}
} }
/* point in polygon (keep float and int versions in sync) */ /* 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))) { if (UNLIKELY(det == 0.0f || !isfinite(det))) {
return false; return false;
} }
else {
/* Calculate scaled z-coordinates of vertices and use them to calculate /* Calculate scaled z-coordinates of vertices and use them to calculate
* the hit distance. * the hit distance.
*/ */
const int sign_det = (float_as_int(det) & (int)0x80000000); 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 t = (u * a_kz + v * b_kz + w * c_kz) * sz;
const float sign_t = xor_fl(t, sign_det); const float sign_t = xor_fl(t, sign_det);
if ((sign_t < 0.0f) if ((sign_t < 0.0f)
/* Differ from Cycles, don't read r_lambda's original value /* Differ from Cycles, don't read r_lambda's original value
* otherwise we won't match any of the other intersect functions here... * otherwise we won't match any of the other intersect functions here...
* which would be confusing. */ * which would be confusing. */
#if 0 #if 0
|| (sign_T > *r_lambda * xor_signmask(det, sign_mask)) || (sign_T > *r_lambda * xor_signmask(det, sign_mask))
#endif #endif
) { ) {
return false; 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;
}
} }
/* 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], 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); madd_v3_v3v3fl(r_isect_co, l1, u, lambda);
return true; return true;
} }
else {
/* The segment is parallel to plane */ /* The segment is parallel to plane */
return false; return false;
}
} }
/** /**
@@ -2257,9 +2248,8 @@ bool isect_plane_plane_plane_v3(const float plane_a[4],
return true; return true;
} }
else {
return false; return false;
}
} }
/** /**
@@ -2303,9 +2293,8 @@ bool isect_plane_plane_v3(const float plane_a[4],
return true; 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) { if (line_point_side_v2(t_a0, t_b1, t_a1) <= 0.0f) {
return 1; 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_a0, t_b0, t_a2) >= 0.0f) {
if (line_point_side_v2(t_a1, t_a2, t_b0) >= 0.0f) { if (line_point_side_v2(t_a1, t_a2, t_b0) >= 0.0f) {
return 1; return 1;
}
else {
return 0;
}
}
else {
return 0;
} }
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_b2, t_b1, t_a2) <= 0.0f) {
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) {
return 1; return 1;
} }
else {
return 0;
}
}
else {
return 0; return 0;
} }
}
else {
return 0; 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_a1, t_a2, t_b2) >= 0.0f) {
if (line_point_side_v2(t_a0, t_b0, t_a2) >= 0.0f) { if (line_point_side_v2(t_a0, t_b0, t_a2) >= 0.0f) {
return 1; 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) { if (line_point_side_v2(t_b2, t_a2, t_b1) >= 0.0f) {
return 1; return 1;
} }
else {
return 0;
}
}
else {
return 0; return 0;
} }
}
else {
return 0; return 0;
} }
return 0;
} }
static bool isect_tri_tri_v2_impl_edge(const float t_a0[2], 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) { if (line_point_side_v2(t_a0, t_a1, t_b2) >= 0.0f) {
return 1; return 1;
} }
else {
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;
}
}
}
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;
}
}
}
else {
return 0;
}
}
else {
return 0; 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;
} }
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;
}
if (line_point_side_v2(t_a1, t_a2, t_b2) >= 0.0f) {
return 1;
}
return 0;
}
return 0;
}
return 0;
} }
static int isect_tri_tri_impl_ccw_v2(const float t_a0[2], 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) { if (line_point_side_v2(t_b2, t_b0, t_a0) >= 0.0f) {
return 1; 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) { 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_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);
}
} }
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_b1, t_b2, t_a0) >= 0.0f) {
if (line_point_side_v2(t_b2, t_b0, 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_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);
} }
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], 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) { 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); 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) { 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_b2, t_b1);
}
else {
return isect_tri_tri_impl_ccw_v2(t_a0, t_a1, t_a2, t_b0, t_b1, t_b2);
}
} }
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) { if (plane_point_side_v3(planes[i], bb_far) < 0.0f) {
return ISECT_AABB_PLANE_BEHIND_ANY; return ISECT_AABB_PLANE_BEHIND_ANY;
} }
else if ((ret != ISECT_AABB_PLANE_CROSS_ANY) && if ((ret != ISECT_AABB_PLANE_CROSS_ANY) && (plane_point_side_v3(planes[i], bb_near) < 0.0f)) {
(plane_point_side_v3(planes[i], bb_near) < 0.0f)) {
ret = ISECT_AABB_PLANE_CROSS_ANY; ret = ISECT_AABB_PLANE_CROSS_ANY;
} }
} }
@@ -2967,7 +2926,7 @@ int isect_line_line_epsilon_v3(const float v1[3],
return 0; return 0;
} }
/* test if the two lines are coplanar */ /* test if the two lines are coplanar */
else if (UNLIKELY(fabsf(d) <= epsilon)) { if (UNLIKELY(fabsf(d) <= epsilon)) {
cross_v3_v3v3(cb, c, b); cross_v3_v3v3(cb, c, b);
mul_v3_fl(a, dot_v3v3(cb, ab) / div); 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 */ return 1; /* one intersection only */
} }
/* if not */ /* 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 */ float n[3], t[3];
cross_v3_v3v3(n, a, b); float v3t[3], v4t[3];
project_v3_v3v3(t, t, n); sub_v3_v3v3(t, v1, v3);
/* for the first line, offset the second line until it is coplanar */ /* offset between both plane where the lines lies */
add_v3_v3v3(v3t, v3, t); cross_v3_v3v3(n, a, b);
add_v3_v3v3(v4t, v4, t); project_v3_v3v3(t, t, n);
sub_v3_v3v3(c, v3t, v1); /* for the first line, offset the second line until it is coplanar */
sub_v3_v3v3(a, v2, v1); add_v3_v3v3(v3t, v3, t);
sub_v3_v3v3(b, v4t, v3t); add_v3_v3v3(v4t, v4, t);
cross_v3_v3v3(ab, a, b); sub_v3_v3v3(c, v3t, v1);
cross_v3_v3v3(cb, c, b); sub_v3_v3v3(a, v2, v1);
sub_v3_v3v3(b, v4t, v3t);
mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab)); cross_v3_v3v3(ab, a, b);
add_v3_v3v3(r_i1, v1, a); cross_v3_v3v3(cb, c, b);
/* for the second line, just subtract the offset from the first intersection point */ mul_v3_fl(a, dot_v3v3(cb, ab) / dot_v3v3(ab, ab));
sub_v3_v3v3(r_i2, r_i1, t); 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], 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; return false;
} }
/* test if the two lines are coplanar */ /* test if the two lines are coplanar */
else if (UNLIKELY(fabsf(d) < epsilon)) { if (UNLIKELY(fabsf(d) < epsilon)) {
return false; return false;
} }
else {
float f1, f2;
cross_v3_v3v3(cb, c, b);
cross_v3_v3v3(ca, c, a);
f1 = dot_v3v3(cb, ab) / div; float f1, f2;
f2 = dot_v3v3(ca, ab) / div; cross_v3_v3v3(cb, c, b);
cross_v3_v3v3(ca, c, a);
if (f1 >= 0 && f1 <= 1 && f2 >= 0 && f2 <= 1) { f1 = dot_v3v3(cb, ab) / div;
mul_v3_fl(a, f1); f2 = dot_v3v3(ca, ab) / div;
add_v3_v3v3(vi, v1, a);
if (r_lambda) { if (f1 >= 0 && f1 <= 1 && f2 >= 0 && f2 <= 1) {
*r_lambda = f1; mul_v3_fl(a, f1);
} add_v3_v3v3(vi, v1, a);
return true; /* intersection found */ if (r_lambda) {
} *r_lambda = f1;
else {
return false;
} }
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])) { if ((hit_dist[1] < 0.0f || hit_dist[0] > hit_dist[1])) {
return false; return false;
} }
else {
if (tmin) { if (tmin) {
*tmin = hit_dist[0]; *tmin = hit_dist[0];
}
if (tmax) {
*tmax = hit_dist[1];
}
return true;
} }
if (tmax) {
*tmax = hit_dist[1];
}
return true;
} }
float closest_to_ray_v3(float r_close[3], float closest_to_ray_v3(float r_close[3],
@@ -3522,9 +3477,8 @@ bool isect_point_tri_v3(
return true; return true;
} }
else {
return false; return false;
}
} }
bool clip_segment_v3_plane( bool clip_segment_v3_plane(
@@ -3547,7 +3501,7 @@ bool clip_segment_v3_plane(
if (t >= div) { if (t >= div) {
return false; return false;
} }
else if (t > 0.0f) { if (t > 0.0f) {
const float p1_copy[3] = {UNPACK3(p1)}; const float p1_copy[3] = {UNPACK3(p1)};
copy_v3_v3(r_p2, p2); copy_v3_v3(r_p2, p2);
madd_v3_v3v3fl(r_p1, p1_copy, dp, t / div); madd_v3_v3v3fl(r_p1, p1_copy, dp, t / div);
@@ -3559,7 +3513,7 @@ bool clip_segment_v3_plane(
if (t >= 0.0f) { if (t >= 0.0f) {
return false; return false;
} }
else if (t > div) { if (t > div) {
const float p1_copy[3] = {UNPACK3(p1)}; const float p1_copy[3] = {UNPACK3(p1)};
copy_v3_v3(r_p1, p1); copy_v3_v3(r_p1, p1);
madd_v3_v3v3fl(r_p2, p1_copy, dp, t / div); 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) { if (t >= div) {
return false; return false;
} }
else if (t > 0.0f) { if (t > 0.0f) {
t /= div; t /= div;
if (t > p1_fac) { if (t > p1_fac) {
p1_fac = t; p1_fac = t;
@@ -3613,7 +3567,7 @@ bool clip_segment_v3_plane_n(const float p1[3],
if (t >= 0.0f) { if (t >= 0.0f) {
return false; return false;
} }
else if (t > div) { if (t > div) {
t /= div; t /= div;
if (t < p2_fac) { if (t < p2_fac) {
p2_fac = t; 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)) { 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; return 1;
} }
else if (IN_RANGE_INCL(w[0], 0.0f, 1.0f) && IN_RANGE_INCL(w[1], 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)) { IN_RANGE_INCL(w[2], 0.0f, 1.0f)) {
return 2; return 2;
} }
@@ -4095,69 +4049,68 @@ int interp_sparse_array(float *array, const int list_size, const float skipval)
if (found_valid == 0) { if (found_valid == 0) {
return -1; return -1;
} }
else if (found_invalid == 0) { if (found_invalid == 0) {
return 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"); /* found invalid depths, interpolate */
float *array_down = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up"); float valid_last = skipval;
int valid_ofs = 0;
int *ofs_tot_up = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tup"); float *array_up = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up");
int *ofs_tot_down = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tdown"); float *array_down = MEM_callocN(sizeof(float) * (size_t)list_size, "interp_sparse_array up");
for (i = 0; i < list_size; i++) { int *ofs_tot_up = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tup");
if (array[i] == skipval) { int *ofs_tot_down = MEM_callocN(sizeof(int) * (size_t)list_size, "interp_sparse_array tdown");
array_up[i] = valid_last;
ofs_tot_up[i] = ++valid_ofs; for (i = 0; i < list_size; i++) {
} if (array[i] == skipval) {
else { array_up[i] = valid_last;
valid_last = array[i]; ofs_tot_up[i] = ++valid_ofs;
valid_ofs = 0;
}
} }
else {
valid_last = skipval; valid_last = array[i];
valid_ofs = 0; 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];
}
}
}
MEM_freeN(array_up);
MEM_freeN(array_down);
MEM_freeN(ofs_tot_up);
MEM_freeN(ofs_tot_down);
} }
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;
}
}
/* 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(ofs_tot_up);
MEM_freeN(ofs_tot_down);
return 1; 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; ix_flag = IS_POINT_IX;
break; 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; ix_flag = IS_SEGMENT_IX;
break; 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; ix_flag = IS_POINT_IX;
break; 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; ix_flag = IS_SEGMENT_IX;
break; break;
} }
@@ -4647,17 +4600,15 @@ float resolve_quad_u_v2(const float st[2],
if (IS_ZERO(fDen) == 0) { if (IS_ZERO(fDen) == 0) {
return (float)(a / fDen); 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 #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) */ /* no angle difference (use fallback, length wont make any difference) */
return (1.0f / 3.0f) * 0.75f; return (1.0f / 3.0f) * 0.75f;
} }
else if (tan_dot < -1.0f + eps) { if (tan_dot < -1.0f + eps) {
/* parallele tangents (half-circle) */ /* parallele tangents (half-circle) */
return (1.0f / 2.0f); 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' */ /* non-aligned tangents, calculate handle length */
const float angle_sin = sinf(angle); const float angle = acosf(tan_dot) / 2.0f;
const float angle_cos = cosf(angle);
return ((1.0f - angle_cos) / (angle_sin * 2.0f)) / angle_sin; /* 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;
} }

View File

@@ -644,9 +644,8 @@ float angle_signed_normalized_qt(const float q[4])
if (q[0] >= 0.0f) { if (q[0] >= 0.0f) {
return 2.0f * saacos(q[0]); 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]) 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) { if (dot_qtqt(q1, q2) >= 0.0f) {
return angle_normalized_qtqt(q1, q2); return angle_normalized_qtqt(q1, q2);
} }
else {
float q2_copy[4]; float q2_copy[4];
negate_v4_v4(q2_copy, q2); negate_v4_v4(q2_copy, q2);
return -angle_normalized_qtqt(q1, q2_copy); return -angle_normalized_qtqt(q1, q2_copy);
}
} }
float angle_signed_qt(const float q[4]) 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) { if (dot_qtqt(q1, q2) >= 0.0f) {
return angle_qtqt(q1, q2); return angle_qtqt(q1, q2);
} }
else {
float q2_copy[4]; float q2_copy[4];
negate_v4_v4(q2_copy, q2); negate_v4_v4(q2_copy, q2);
return -angle_qtqt(q1, q2_copy); return -angle_qtqt(q1, q2_copy);
}
} }
/** \} */ /** \} */
@@ -1594,12 +1591,11 @@ static const RotOrderInfo *get_rotation_order_info(const short order)
if (order < 1) { if (order < 1) {
return &rotOrders[0]; return &rotOrders[0];
} }
else if (order < 6) { if (order < 6) {
return &rotOrders[order - 1]; return &rotOrders[order - 1];
} }
else {
return &rotOrders[5]; return &rotOrders[5];
}
} }
/* Construct quaternion from Euler angles (in radians). */ /* Construct quaternion from Euler angles (in radians). */

View File

@@ -506,11 +506,10 @@ float angle_normalized_v3v3(const float v1[3], const float v2[3])
if (dot_v3v3(v1, v2) >= 0.0f) { if (dot_v3v3(v1, v2) >= 0.0f) {
return 2.0f * saasin(len_v3v3(v1, v2) / 2.0f); return 2.0f * saasin(len_v3v3(v1, v2) / 2.0f);
} }
else {
float v2_n[3]; float v2_n[3];
negate_v3_v3(v2_n, v2); negate_v3_v3(v2_n, v2);
return (float)M_PI - 2.0f * saasin(len_v3v3(v1, v2_n) / 2.0f); 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]) 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) { if (dot_v2v2(v1, v2) >= 0.0f) {
return 2.0f * saasin(len_v2v2(v1, v2) / 2.0f); return 2.0f * saasin(len_v2v2(v1, v2) / 2.0f);
} }
else {
float v2_n[2]; float v2_n[2];
negate_v2_v2(v2_n, v2); negate_v2_v2(v2_n, v2);
return (float)M_PI - 2.0f * saasin(len_v2v2(v1, v2_n) / 2.0f); return (float)M_PI - 2.0f * saasin(len_v2v2(v1, v2_n) / 2.0f);
}
} }
/** /**

View File

@@ -427,9 +427,8 @@ static int BLI_path_unc_prefix_len(const char *path)
/* we assume long UNC path like \\?\server\share\folder etc... */ /* we assume long UNC path like \\?\server\share\folder etc... */
return 4; return 4;
} }
else {
return 2; return 2;
}
} }
return 0; return 0;
@@ -683,7 +682,7 @@ bool BLI_path_suffix(char *string, size_t maxlen, const char *suffix, const char
has_extension = true; has_extension = true;
break; break;
} }
else if (ELEM(string[a], '/', '\\')) { if (ELEM(string[a], '/', '\\')) {
break; break;
} }
} }
@@ -713,9 +712,8 @@ bool BLI_path_parent_dir(char *path)
strcpy(path, tmp); /* We assume pardir is always shorter... */ strcpy(path, tmp); /* We assume pardir is always shorter... */
return true; 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; *char_end = ch_end;
return true; return true;
} }
else {
*char_start = -1; *char_start = -1;
*char_end = -1; *char_end = -1;
return false; return false;
}
} }
/** /**
@@ -1731,9 +1728,8 @@ void BLI_join_dirfile(char *__restrict dst,
dst[dirlen - 1] = '\0'; dst[dirlen - 1] = '\0';
return; /* dir fills the path */ return; /* dir fills the path */
} }
else {
memcpy(dst, dir, dirlen + 1); memcpy(dst, dir, dirlen + 1);
}
if (dirlen + 1 >= maxlen) { if (dirlen + 1 >= maxlen) {
return; /* fills the path */ return; /* fills the path */
@@ -1891,32 +1887,31 @@ bool BLI_path_name_at_index(const char *__restrict path,
} }
return false; return false;
} }
else {
/* negative number, reverse where -1 is the last element */ /* negative number, reverse where -1 is the last element */
int index_step = -1; int index_step = -1;
int prev = strlen(path); int prev = strlen(path);
int i = prev - 1; int i = prev - 1;
while (true) { while (true) {
const char c = i >= 0 ? path[i] : '\0'; const char c = i >= 0 ? path[i] : '\0';
if (ELEM(c, SEP, ALTSEP, '\0')) { if (ELEM(c, SEP, ALTSEP, '\0')) {
if (prev - 1 != i) { if (prev - 1 != i) {
i += 1; i += 1;
if (index_step == index) { if (index_step == index) {
*r_offset = i; *r_offset = i;
*r_len = prev - i; *r_len = prev - i;
return true; return true;
}
index_step -= 1;
} }
if (c == '\0') { index_step -= 1;
break;
}
prev = i;
} }
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) { if (!ffslash) {
return fbslash; return fbslash;
} }
else if (!fbslash) { if (!fbslash) {
return ffslash; return ffslash;
} }
@@ -1948,7 +1943,7 @@ const char *BLI_path_slash_rfind(const char *string)
if (!lfslash) { if (!lfslash) {
return lbslash; return lbslash;
} }
else if (!lbslash) { if (!lbslash) {
return lfslash; return lfslash;
} }

View File

@@ -177,12 +177,11 @@ BLI_INLINE eSign signum_enum(float a)
if (UNLIKELY(a == 0.0f)) { if (UNLIKELY(a == 0.0f)) {
return 0; return 0;
} }
else if (a > 0.0f) { if (a > 0.0f) {
return 1; return 1;
} }
else {
return -1; return -1;
}
} }
/** /**
@@ -250,7 +249,7 @@ static uint kdtree2d_balance_recursive(
if (totnode <= 0) { if (totnode <= 0) {
return KDNODE_UNSET; return KDNODE_UNSET;
} }
else if (totnode == 1) { if (totnode == 1) {
return 0 + ofs; return 0 + ofs;
} }
@@ -330,9 +329,8 @@ static void kdtree2d_node_remove(struct KDTree2D *tree, uint index)
if (node_index == KDNODE_UNSET) { if (node_index == KDNODE_UNSET) {
return; return;
} }
else {
tree->nodes_map[index] = KDNODE_UNSET; tree->nodes_map[index] = KDNODE_UNSET;
}
node = &tree->nodes[node_index]; node = &tree->nodes[node_index];
tree->totnode -= 1; tree->totnode -= 1;

View File

@@ -64,14 +64,14 @@ static int oedge_cmp(const void *a1, const void *a2)
if (x1->verts[0] > x2->verts[0]) { if (x1->verts[0] > x2->verts[0]) {
return 1; return 1;
} }
else if (x1->verts[0] < x2->verts[0]) { if (x1->verts[0] < x2->verts[0]) {
return -1; return -1;
} }
if (x1->verts[1] > x2->verts[1]) { if (x1->verts[1] > x2->verts[1]) {
return 1; return 1;
} }
else if (x1->verts[1] < x2->verts[1]) { if (x1->verts[1] < x2->verts[1]) {
return -1; return -1;
} }
@@ -79,7 +79,7 @@ static int oedge_cmp(const void *a1, const void *a2)
if (x1->e_half > x2->e_half) { if (x1->e_half > x2->e_half) {
return 1; return 1;
} }
else if (x1->e_half < x2->e_half) { if (x1->e_half < x2->e_half) {
return -1; return -1;
} }
/* Should never get here, no two edges should be the same. */ /* 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)) { if ((area_2x_123 >= 0.0f) != (area_2x_134 >= 0.0f)) {
break; 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; break;
} }
@@ -150,11 +150,10 @@ float BLI_polyfill_beautify_quad_rotate_calc_ex(const float v1[2],
if (lock_degenerate) { if (lock_degenerate) {
break; 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 */ return -FLT_MAX; /* always rotate */
} }

View File

@@ -107,9 +107,8 @@ static bool quadric_to_tensor_m3_inverse(const Quadric *q, double m[3][3], doubl
return true; return true;
} }
else {
return false; return false;
}
} }
void BLI_quadric_to_vector_v3(const Quadric *q, double v[3]) 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); negate_v3_db(v);
return true; return true;
} }
else {
return false; return false;
}
} }

View File

@@ -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) { if (div == 0.0) {
return 1; /* co-linear */ return 1; /* co-linear */
} }
else {
const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) -
(v1[0] - v3[0]) * (v4[1] - v3[1])) / (v1[0] - v3[0]) * (v4[1] - v3[1])) /
div; div;
const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) -
(v1[0] - v3[0]) * (v2[1] - v1[1])) / (v1[0] - v3[0]) * (v2[1] - v1[1])) /
div; div;
return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0); return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0);
}
} }
static int isect_segments_fl(const float v1[2], static int isect_segments_fl(const float v1[2],
const float v2[2], const float v2[2],
@@ -258,15 +257,14 @@ static int isect_segments_fl(const float v1[2],
if (div == 0.0) { if (div == 0.0) {
return 1; /* co-linear */ return 1; /* co-linear */
} }
else {
const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - const double lambda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) -
(v1[0] - v3[0]) * (v4[1] - v3[1])) / (v1[0] - v3[0]) * (v4[1] - v3[1])) /
div; div;
const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) -
(v1[0] - v3[0]) * (v2[1] - v1[1])) / (v1[0] - v3[0]) * (v2[1] - v1[1])) /
div; div;
return (lambda >= 0.0 && lambda <= 1.0 && mu >= 0.0 && mu <= 1.0); 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]) 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)) { if (BLI_rcti_isect_pt_v(rect, s1) || BLI_rcti_isect_pt_v(rect, s2)) {
return true; 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: [\] */ /* both points are outside but may intersect the rect */
tvec1[0] = rect->xmin; int tvec1[2];
tvec1[1] = rect->ymax; int tvec2[2];
tvec2[0] = rect->xmax; /* diagonal: [/] */
tvec2[1] = rect->ymin; tvec1[0] = rect->xmin;
if (isect_segments_i(s1, s2, tvec1, tvec2)) { tvec1[1] = rect->ymin;
return true; tvec2[0] = rect->xmin;
} tvec2[1] = rect->ymax;
if (isect_segments_i(s1, s2, tvec1, tvec2)) {
/* no intersection */ return true;
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]) 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)) { if (BLI_rctf_isect_pt_v(rect, s1) || BLI_rctf_isect_pt_v(rect, s2)) {
return true; 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: [\] */ /* both points are outside but may intersect the rect */
tvec1[0] = rect->xmin; float tvec1[2];
tvec1[1] = rect->ymax; float tvec2[2];
tvec2[0] = rect->xmax; /* diagonal: [/] */
tvec2[1] = rect->ymin; tvec1[0] = rect->xmin;
if (isect_segments_fl(s1, s2, tvec1, tvec2)) { tvec1[1] = rect->ymin;
return true; tvec2[0] = rect->xmin;
} tvec2[1] = rect->ymax;
if (isect_segments_fl(s1, s2, tvec1, tvec2)) {
/* no intersection */ return true;
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) 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; return true;
} }
else {
if (dest) { if (dest) {
dest->xmin = 0; dest->xmin = 0;
dest->xmax = 0; dest->xmax = 0;
dest->ymin = 0; dest->ymin = 0;
dest->ymax = 0; dest->ymax = 0;
}
return false;
} }
return false;
} }
bool BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest) 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; return true;
} }
else {
if (dest) { if (dest) {
dest->xmin = 0; dest->xmin = 0;
dest->xmax = 0; dest->xmax = 0;
dest->ymin = 0; dest->ymin = 0;
dest->ymax = 0; dest->ymax = 0;
}
return false;
} }
return false;
} }
bool BLI_rctf_isect_rect_x(const rctf *src1, const rctf *src2, float range_x[2]) 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; return true;
} }
else {
if (range_x) { if (range_x) {
range_x[0] = 0; range_x[0] = 0;
range_x[1] = 0; range_x[1] = 0;
}
return false;
} }
return false;
} }
bool BLI_rctf_isect_rect_y(const rctf *src1, const rctf *src2, float range_y[2]) 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; return true;
} }
else {
if (range_y) { if (range_y) {
range_y[0] = 0; range_y[0] = 0;
range_y[1] = 0; range_y[1] = 0;
}
return false;
} }
return false;
} }
bool BLI_rcti_isect_rect_x(const rcti *src1, const rcti *src2, int range_x[2]) 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; return true;
} }
else {
if (range_x) { if (range_x) {
range_x[0] = 0; range_x[0] = 0;
range_x[1] = 0; range_x[1] = 0;
}
return false;
} }
return false;
} }
bool BLI_rcti_isect_rect_y(const rcti *src1, const rcti *src2, int range_y[2]) 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; return true;
} }
else {
if (range_y) { if (range_y) {
range_y[0] = 0; range_y[0] = 0;
range_y[1] = 0; range_y[1] = 0;
}
return false;
} }
return false;
} }
void BLI_rcti_rctf_copy(rcti *dst, const rctf *src) void BLI_rcti_rctf_copy(rcti *dst, const rctf *src)

View File

@@ -91,13 +91,13 @@ static int vergscdata(const void *a1, const void *a2)
if (x1->vert->xy[1] < x2->vert->xy[1]) { if (x1->vert->xy[1] < x2->vert->xy[1]) {
return 1; return 1;
} }
else if (x1->vert->xy[1] > x2->vert->xy[1]) { if (x1->vert->xy[1] > x2->vert->xy[1]) {
return -1; return -1;
} }
else if (x1->vert->xy[0] > x2->vert->xy[0]) { if (x1->vert->xy[0] > x2->vert->xy[0]) {
return 1; return 1;
} }
else if (x1->vert->xy[0] < x2->vert->xy[0]) { if (x1->vert->xy[0] < x2->vert->xy[0]) {
return -1; return -1;
} }
@@ -111,13 +111,13 @@ static int vergpoly(const void *a1, const void *a2)
if (x1->min_xy[0] > x2->min_xy[0]) { if (x1->min_xy[0] > x2->min_xy[0]) {
return 1; return 1;
} }
else if (x1->min_xy[0] < x2->min_xy[0]) { if (x1->min_xy[0] < x2->min_xy[0]) {
return -1; return -1;
} }
else if (x1->min_xy[1] > x2->min_xy[1]) { if (x1->min_xy[1] > x2->min_xy[1]) {
return 1; return 1;
} }
else if (x1->min_xy[1] < x2->min_xy[1]) { if (x1->min_xy[1] < x2->min_xy[1]) {
return -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) { if (inp < 0.0f) {
return false; return false;
} }
else if (inp == 0.0f) { if (inp == 0.0f) {
if (v1[0] == v3[0] && v1[1] == v3[1]) { if (v1[0] == v3[0] && v1[1] == v3[1]) {
return false; return false;
} }
@@ -417,25 +417,24 @@ static void testvertexnearedge(ScanFillContext *sf_ctx)
eve->edge_tot = 0; eve->edge_tot = 0;
break; 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; ed1->v2 = eed->v2;
eed->v2->edge_tot++; eed->v2->edge_tot++;
eve->edge_tot = 0; eve->edge_tot = 0;
break; 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); */ if (boundinsideEV(eed, eve)) {
ed1->poly_nr = eed->poly_nr; const float dist = dist_squared_to_line_v2(eed->v1->xy, eed->v2->xy, eve->xy);
eed->v1 = eve; if (dist < SF_EPSILON_SQ) {
eve->edge_tot = 3; /* new edge */
break; 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)) { if (UNLIKELY(eve == NULL)) {
return 0; return 0;
} }
float n[3];
if (nor_proj) {
copy_v3_v3(n, nor_proj);
}
else { 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) { /* warning: this only gives stable direction with single polygons,
copy_v3_v3(n, nor_proj); * ideally we'd calculate connectivity and each polys normal, see T41047 */
} const float *v_prev;
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, zero_v3(n);
* ideally we'd calculate connectivity and each polys normal, see T41047 */ eve = sf_ctx->fillvertbase.last;
const float *v_prev; v_prev = eve->co;
zero_v3(n); for (eve = sf_ctx->fillvertbase.first; eve; eve = eve->next) {
eve = sf_ctx->fillvertbase.last; if (LIKELY(!compare_v3v3(v_prev, eve->co, SF_EPSILON))) {
v_prev = eve->co; add_newell_cross_v3_v3v3(n, v_prev, eve->co);
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;
}
} }
} }
if (UNLIKELY(normalize_v3(n) == 0.0f)) {
return 0;
}
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 */ /* STEP 1: COUNT POLYS */
if (sf_ctx->poly_nr != SF_POLY_UNSET) { if (sf_ctx->poly_nr != SF_POLY_UNSET) {
poly = (unsigned short)(sf_ctx->poly_nr + 1); poly = (unsigned short)(sf_ctx->poly_nr + 1);

View File

@@ -139,9 +139,8 @@ static int edge_isect_ls_sort_cb(void *thunk, const void *def_a_ptr, const void
if (a > b) { if (a > b) {
return -1; return -1;
} }
else {
return (a < b); return (a < b);
}
} }
static ScanFillEdge *edge_step(PolyInfo *poly_info, static ScanFillEdge *edge_step(PolyInfo *poly_info,

View File

@@ -253,10 +253,9 @@ bool BLI_smallhash_reinsert(SmallHash *sh, uintptr_t key, void *item)
e->val = item; e->val = item;
return false; return false;
} }
else {
BLI_smallhash_insert(sh, key, item); BLI_smallhash_insert(sh, key, item);
return true; return true;
}
} }
#ifdef USE_REMOVE #ifdef USE_REMOVE

View File

@@ -44,12 +44,11 @@ int BLI_sortutil_cmp_float(const void *a_, const void *b_)
if (a->sort_value > b->sort_value) { if (a->sort_value > b->sort_value) {
return 1; return 1;
} }
else if (a->sort_value < b->sort_value) { if (a->sort_value < b->sort_value) {
return -1; return -1;
} }
else {
return 0; return 0;
}
} }
int BLI_sortutil_cmp_float_reverse(const void *a_, const void *b_) 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) { if (a->sort_value < b->sort_value) {
return 1; return 1;
} }
else if (a->sort_value > b->sort_value) { if (a->sort_value > b->sort_value) {
return -1; return -1;
} }
else {
return 0; return 0;
}
} }
int BLI_sortutil_cmp_int(const void *a_, const void *b_) 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) { if (a->sort_value > b->sort_value) {
return 1; return 1;
} }
else if (a->sort_value < b->sort_value) { if (a->sort_value < b->sort_value) {
return -1; return -1;
} }
else {
return 0; return 0;
}
} }
int BLI_sortutil_cmp_int_reverse(const void *a_, const void *b_) 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) { if (a->sort_value < b->sort_value) {
return 1; return 1;
} }
else if (a->sort_value > b->sort_value) { if (a->sort_value > b->sort_value) {
return -1; return -1;
} }
else {
return 0; return 0;
}
} }
int BLI_sortutil_cmp_ptr(const void *a_, const void *b_) 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) { if (a->sort_value > b->sort_value) {
return 1; return 1;
} }
else if (a->sort_value < b->sort_value) { if (a->sort_value < b->sort_value) {
return -1; return -1;
} }
else {
return 0; return 0;
}
} }
int BLI_sortutil_cmp_ptr_reverse(const void *a_, const void *b_) 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) { if (a->sort_value < b->sort_value) {
return 1; return 1;
} }
else if (a->sort_value > b->sort_value) { if (a->sort_value > b->sort_value) {
return -1; return -1;
} }
else {
return 0; return 0;
}
} }

View File

@@ -96,9 +96,7 @@ char *BLI_current_working_dir(char *dir, const size_t maxncpy)
memcpy(dir, pwd, srclen + 1); memcpy(dir, pwd, srclen + 1);
return dir; return dir;
} }
else { return NULL;
return NULL;
}
} }
return getcwd(dir, maxncpy); return getcwd(dir, maxncpy);
#endif #endif

View File

@@ -394,9 +394,7 @@ char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict
if (LIKELY(*(endMatch - 1) != '\\')) { if (LIKELY(*(endMatch - 1) != '\\')) {
break; break;
} }
else { endMatch++;
endMatch++;
}
} }
if (endMatch) { if (endMatch) {
@@ -470,11 +468,9 @@ char *BLI_str_replaceN(const char *__restrict str,
return str_new; return str_new;
} }
else { /* Just create a new copy of the entire string - we avoid going through the assembly buffer
/* Just create a new copy of the entire string - we avoid going through the assembly buffer * for what should be a bit more efficiency. */
* for what should be a bit more efficiency. */ return BLI_strdup(str);
return BLI_strdup(str);
}
} }
/** /**
@@ -574,10 +570,10 @@ int BLI_strcasecmp(const char *s1, const char *s2)
if (c1 < c2) { if (c1 < c2) {
return -1; return -1;
} }
else if (c1 > c2) { if (c1 > c2) {
return 1; return 1;
} }
else if (c1 == 0) { if (c1 == 0) {
break; break;
} }
} }
@@ -597,10 +593,10 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len)
if (c1 < c2) { if (c1 < c2) {
return -1; return -1;
} }
else if (c1 > c2) { if (c1 > c2) {
return 1; return 1;
} }
else if (c1 == 0) { if (c1 == 0) {
break; 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))) { if (isdigit(*(p1 + numdigit)) && isdigit(*(p2 + numdigit))) {
continue; continue;
} }
else if (isdigit(*(p1 + numdigit))) { if (isdigit(*(p1 + numdigit))) {
return 1; /* s2 is bigger */ return 1; /* s2 is bigger */
} }
else if (isdigit(*(p2 + numdigit))) { if (isdigit(*(p2 + numdigit))) {
return -1; /* s1 is bigger */ return -1; /* s1 is bigger */
} }
else { break;
break;
}
} }
/* same number of digits, compare size of number */ /* 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) { if (str1_len == str2_len) {
return strncmp(str1, str2, 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); int ret = strncmp(str1, str2, str2_len);
if (ret == 0) { if (ret == 0) {
ret = 1; ret = 1;
} }
return ret; return ret;
} }
else { {
int ret = strncmp(str1, str2, str1_len); int ret = strncmp(str1, str2, str1_len);
if (ret == 0) { if (ret == 0) {
ret = -1; ret = -1;

View File

@@ -215,11 +215,9 @@ int BLI_utf8_invalid_strip(char *str, size_t length)
tot++; tot++;
break; break;
} }
else { /* strip, keep looking */
/* strip, keep looking */ memmove(str, str + 1, length + 1); /* +1 for NULL char! */
memmove(str, str + 1, length + 1); /* +1 for NULL char! */ tot++;
tot++;
}
} }
return tot; return tot;

View File

@@ -72,7 +72,7 @@ size_t BLI_split_name_num(char *left, int *nr, const char *name, const char deli
} }
return a; return a;
} }
else if (isdigit(name[a]) == 0) { if (isdigit(name[a]) == 0) {
/* non-numeric suffix - give up */ /* non-numeric suffix - give up */
break; break;
} }

View File

@@ -309,7 +309,7 @@ int BLI_system_thread_count(void)
if (num_threads_override != 0) { if (num_threads_override != 0) {
return num_threads_override; return num_threads_override;
} }
else if (LIKELY(t != -1)) { if (LIKELY(t != -1)) {
return t; 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) { if (pthread_cond_timedwait(&queue->push_cond, &queue->mutex, &timeout) == ETIMEDOUT) {
break; break;
} }
else if (PIL_check_seconds_timer() - t >= ms * 0.001) { if (PIL_check_seconds_timer() - t >= ms * 0.001) {
break; break;
} }
} }

View File

@@ -345,7 +345,8 @@ static bool object_modifier_remove(
object_remove_particle_system(bmain, scene, ob); object_remove_particle_system(bmain, scene, ob);
return true; return true;
} }
else if (md->type == eModifierType_Softbody) {
if (md->type == eModifierType_Softbody) {
if (ob->soft) { if (ob->soft) {
sbFree(ob); sbFree(ob);
ob->softflag = 0; /* TODO(Sybren): this should probably be moved into sbFree() */ 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); BLI_insertlinkafter(&ob->modifiers, md, nmd);
return true; return true;
} }
else {
nmd = BKE_modifier_new(md->type); nmd = BKE_modifier_new(md->type);
BKE_modifier_copydata(md, nmd); BKE_modifier_copydata(md, nmd);
BLI_insertlinkafter(&ob->modifiers, md, nmd); BLI_insertlinkafter(&ob->modifiers, md, nmd);
BKE_modifier_unique_name(&ob->modifiers, nmd); BKE_modifier_unique_name(&ob->modifiers, nmd);
}
return 1; 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)) { if (edit_modifier_invoke_properties(C, op, event, &retval)) {
return modifier_apply_as_shapekey_exec(C, op); 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), static char *modifier_apply_as_shapekey_get_description(struct bContext *UNUSED(C),

View File

@@ -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... */ /* This invoke just calls another instance of this operator... */
return OPERATOR_INTERFACE; 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. */ /* Show menu with list of directly linked collections containing the active object. */
WM_enum_search_invoke(C, op, event); WM_enum_search_invoke(C, op, event);
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;

View File

@@ -581,7 +581,8 @@ static bool sculpt_check_unique_face_set_for_edge_in_base_mesh(SculptSession *ss
p1 = vert_map->indices[i]; p1 = vert_map->indices[i];
break; break;
} }
else if (p2 == -1) {
if (p2 == -1) {
p2 = vert_map->indices[i]; p2 = vert_map->indices[i];
break; break;
} }

View File

@@ -538,23 +538,22 @@ static bool uv_rip_pairs_loop_change_sides_test(BMLoop *l_switch,
if (count_a + count_b == 4) { if (count_a + count_b == 4) {
return count_a > count_b; 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( UL(l_switch)->side = side_b;
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_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);
} }
/** /**

View File

@@ -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) { if (tf_a->area < tf_b->area) {
return 1; return 1;
} }
else if (tf_a->area > tf_b->area) { if (tf_a->area > tf_b->area) {
return -1; return -1;
} }
else { return 0;
return 0;
}
} }
static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_faces, static uint smart_uv_project_calculate_project_normals(const ThickFace *thick_faces,

View File

@@ -169,7 +169,7 @@ static int remapTime(struct GpencilModifierData *md,
const int delta = abs(sfra - nfra); const int delta = abs(sfra - nfra);
return efra - delta + 1; return efra - delta + 1;
} }
else if (cfra + offset > efra) { if (cfra + offset > efra) {
return nfra - efra + sfra - 1; return nfra - efra + sfra - 1;
} }
} }

View File

@@ -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); wm_gizmomap_highlight_set(gzmap, C, gz, gz->highlight_part);
return true; return true;
} }
else { return false;
return false;
}
} }
/** /**

View File

@@ -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) { if (gz_a->temp.f < gz_b->temp.f) {
return -1; return -1;
} }
else if (gz_a->temp.f > gz_b->temp.f) { if (gz_a->temp.f > gz_b->temp.f) {
return 1; return 1;
} }
else { return 0;
return 0;
}
} }
int WM_gizmo_cmp_temp_fl_reverse(const void *gz_a_ptr, const void *gz_b_ptr) 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) { if (gz_a->temp.f < gz_b->temp.f) {
return 1; return 1;
} }
else if (gz_a->temp.f > gz_b->temp.f) { if (gz_a->temp.f > gz_b->temp.f) {
return -1; return -1;
} }
else { return 0;
return 0;
}
} }
static bool wm_gizmo_keymap_uses_event_modifier(wmWindowManager *wm, 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; return OPERATOR_FINISHED;
} }
else {
BLI_assert(0); BLI_assert(0);
return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH); return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
}
} }
void GIZMOGROUP_OT_gizmo_select(wmOperatorType *ot) void GIZMOGROUP_OT_gizmo_select(wmOperatorType *ot)
@@ -476,9 +471,7 @@ static bool gizmo_tweak_start_and_finish(
} }
return true; return true;
} }
else { return false;
return false;
}
} }
static void gizmo_tweak_finish(bContext *C, wmOperator *op, const bool cancel, bool clear_modal) static void gizmo_tweak_finish(bContext *C, wmOperator *op, const bool cancel, bool clear_modal)

View File

@@ -263,11 +263,10 @@ bool WM_gizmomap_minmax(const wmGizmoMap *gzmap,
} }
return i != 0; return i != 0;
} }
else {
bool ok = false; bool ok = false;
BLI_assert(!"TODO"); BLI_assert(!"TODO");
return ok; return ok;
}
} }
/** /**
@@ -647,10 +646,9 @@ static int gizmo_find_intersected_3d_intern(wmGizmo **visible_gizmos,
} }
return hit_found; return hit_found;
} }
else {
const uint *hit_near = GPU_select_buffer_near(buffer, hits); const uint *hit_near = GPU_select_buffer_near(buffer, hits);
return hit_near ? hit_near[3] : -1; return hit_near ? hit_near[3] : -1;
}
} }
/** /**

View File

@@ -70,9 +70,7 @@ wmGizmoProperty *WM_gizmo_target_property_find(wmGizmo *gz, const char *idname)
if (index != -1) { if (index != -1) {
return WM_gizmo_target_property_at_index(gz, index); return WM_gizmo_target_property_at_index(gz, index);
} }
else { return NULL;
return NULL;
}
} }
void WM_gizmo_target_property_def_rna_ptr(wmGizmo *gz, 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) { if (gz_prop->index == -1) {
return RNA_property_float_get(&gz_prop->ptr, gz_prop->prop); 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, 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); gz_prop->custom_func.range_get_fn(gz, gz_prop, range);
return true; return true;
} }
else { return false;
return false;
}
} }
float step, precision; float step, precision;

View File

@@ -319,15 +319,15 @@ bool wm_cursor_arrow_move(wmWindow *win, const wmEvent *event)
wm_cursor_warp_relative(win, 0, fac); wm_cursor_warp_relative(win, 0, fac);
return 1; return 1;
} }
else if (event->type == EVT_DOWNARROWKEY) { if (event->type == EVT_DOWNARROWKEY) {
wm_cursor_warp_relative(win, 0, -fac); wm_cursor_warp_relative(win, 0, -fac);
return 1; return 1;
} }
else if (event->type == EVT_LEFTARROWKEY) { if (event->type == EVT_LEFTARROWKEY) {
wm_cursor_warp_relative(win, -fac, 0); wm_cursor_warp_relative(win, -fac, 0);
return 1; return 1;
} }
else if (event->type == EVT_RIGHTARROWKEY) { if (event->type == EVT_RIGHTARROWKEY) {
wm_cursor_warp_relative(win, fac, 0); wm_cursor_warp_relative(win, fac, 0);
return 1; return 1;
} }

View File

@@ -296,7 +296,7 @@ void WM_drag_add_ID(wmDrag *drag, ID *id, ID *from_parent)
} }
return; 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"); BLI_assert(!"All dragged IDs must have the same type");
return; return;
} }
@@ -355,7 +355,7 @@ static const char *wm_drag_name(wmDrag *drag)
if (single) { if (single) {
return id->name + 2; return id->name + 2;
} }
else if (id) { if (id) {
return BKE_idtype_idcode_to_name_plural(GS(id->name)); return BKE_idtype_idcode_to_name_plural(GS(id->name));
} }
break; break;

View File

@@ -207,7 +207,7 @@ static bool wm_draw_region_stereo_set(Main *bmain,
if (region->regiontype == RGN_TYPE_PREVIEW) { if (region->regiontype == RGN_TYPE_PREVIEW) {
return true; return true;
} }
else if (region->regiontype == RGN_TYPE_WINDOW) { if (region->regiontype == RGN_TYPE_WINDOW) {
return (sseq->draw_flag & SEQ_DRAW_BACKDROP) != 0; return (sseq->draw_flag & SEQ_DRAW_BACKDROP) != 0;
} }
} }
@@ -520,9 +520,7 @@ GPUTexture *wm_draw_region_texture(ARegion *region, int view)
if (viewport) { if (viewport) {
return GPU_viewport_color_texture(viewport, view); 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) void wm_draw_region_blend(ARegion *region, int view, bool blend)

View File

@@ -597,7 +597,7 @@ static int wm_handler_ui_call(bContext *C,
if (is_wheel) { if (is_wheel) {
return WM_HANDLER_CONTINUE; return WM_HANDLER_CONTINUE;
} }
else if (wm_event_always_pass(event) == 0) { if (wm_event_always_pass(event) == 0) {
do_wheel_ui = true; do_wheel_ui = true;
} }
} }
@@ -783,7 +783,7 @@ bool WM_operator_poll(bContext *C, wmOperatorType *ot)
if (ot->pyop_poll) { if (ot->pyop_poll) {
return ot->pyop_poll(C, ot); return ot->pyop_poll(C, ot);
} }
else if (ot->poll) { if (ot->poll) {
return ot->poll(C); return ot->poll(C);
} }
@@ -1095,7 +1095,7 @@ bool WM_operator_repeat_check(const bContext *UNUSED(C), wmOperator *op)
if (op->type->exec != NULL) { if (op->type->exec != NULL) {
return true; return true;
} }
else if (op->opm) { if (op->opm) {
/* for macros, check all have exec() we can call */ /* for macros, check all have exec() we can call */
wmOperatorTypeMacro *otmacro; wmOperatorTypeMacro *otmacro;
for (otmacro = op->opm->type->macro.first; otmacro; otmacro = otmacro->next) { 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 */ /* tablet events can occur on hover + keypress */
return false; return false;
} }
else if ((kmitype == TABLET_STYLUS) && (wmtab->active != EVT_TABLET_STYLUS)) { if ((kmitype == TABLET_STYLUS) && (wmtab->active != EVT_TABLET_STYLUS)) {
return false; return false;
} }
else if ((kmitype == TABLET_ERASER) && (wmtab->active != EVT_TABLET_ERASER)) { if ((kmitype == TABLET_ERASER) && (wmtab->active != EVT_TABLET_ERASER)) {
return false; return false;
} }
} }
@@ -2434,13 +2434,11 @@ static int wm_handlers_do_keymap_with_keymap_handler(
} }
break; break;
} }
if (action & WM_HANDLER_HANDLED) {
CLOG_INFO(WM_LOG_HANDLERS, 2, "handled - and pass on! '%s'", kmi->idname);
}
else { else {
if (action & WM_HANDLER_HANDLED) { CLOG_INFO(WM_LOG_HANDLERS, 2, "un-handled '%s'", kmi->idname);
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);
}
} }
} }
} }
@@ -2492,15 +2490,13 @@ static int wm_handlers_do_keymap_with_gizmo_handler(
} }
break; break;
} }
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 { else {
if (action & WM_HANDLER_HANDLED) { PRINT("%s: un-handled '%s'\n", __func__, kmi->idname);
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; win->lock_pie_event = EVENT_NONE;
return false; return false;
} }
else { return true;
return true;
}
}
else {
return false;
} }
return false;
} }
/** /**
@@ -3692,10 +3684,8 @@ wmKeyMap *WM_event_get_keymap_from_toolsystem_fallback(wmWindowManager *wm,
handler->keymap_tool = area->runtime.tool; handler->keymap_tool = area->runtime.tool;
return km; return km;
} }
else { printf(
printf( "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname);
"Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname);
}
} }
} }
return NULL; return NULL;
@@ -3716,10 +3706,8 @@ wmKeyMap *WM_event_get_keymap_from_toolsystem(wmWindowManager *wm, wmEventHandle
handler->keymap_tool = area->runtime.tool; handler->keymap_tool = area->runtime.tool;
return km; return km;
} }
else { printf(
printf( "Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname);
"Keymap: '%s' not found for tool '%s'\n", tref_rt->keymap, area->runtime.tool->idname);
}
} }
} }
return NULL; 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)) { if (BLI_rcti_isect_pt(rect, event->x, event->y)) {
return true; 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; return true;
} }
else { return false;
return false;
}
} }
static bool handler_region_v2d_mask_test(const ARegion *region, const wmEvent *event) 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) { if (key >= GHOST_kKeyA && key <= GHOST_kKeyZ) {
return (EVT_AKEY + ((int)key - GHOST_kKeyA)); 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)); 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)); 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)); 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: switch (key) {
return EVT_ESCKEY; case GHOST_kKeyBackSpace:
case GHOST_kKeySpace: return EVT_BACKSPACEKEY;
return EVT_SPACEKEY; case GHOST_kKeyTab:
case GHOST_kKeyQuote: return EVT_TABKEY;
return EVT_QUOTEKEY; case GHOST_kKeyLinefeed:
case GHOST_kKeyComma: return EVT_LINEFEEDKEY;
return EVT_COMMAKEY; case GHOST_kKeyClear:
case GHOST_kKeyMinus: return 0;
return EVT_MINUSKEY; case GHOST_kKeyEnter:
case GHOST_kKeyPlus: return EVT_RETKEY;
return EVT_PLUSKEY;
case GHOST_kKeyPeriod:
return EVT_PERIODKEY;
case GHOST_kKeySlash:
return EVT_SLASHKEY;
case GHOST_kKeySemicolon: case GHOST_kKeyEsc:
return EVT_SEMICOLONKEY; return EVT_ESCKEY;
case GHOST_kKeyEqual: case GHOST_kKeySpace:
return EVT_EQUALKEY; 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_kKeyLeftBracket: case GHOST_kKeySemicolon:
return EVT_LEFTBRACKETKEY; return EVT_SEMICOLONKEY;
case GHOST_kKeyRightBracket: case GHOST_kKeyEqual:
return EVT_RIGHTBRACKETKEY; return EVT_EQUALKEY;
case GHOST_kKeyBackslash:
return EVT_BACKSLASHKEY;
case GHOST_kKeyAccentGrave:
return EVT_ACCENTGRAVEKEY;
case GHOST_kKeyLeftShift: case GHOST_kKeyLeftBracket:
return EVT_LEFTSHIFTKEY; return EVT_LEFTBRACKETKEY;
case GHOST_kKeyRightShift: case GHOST_kKeyRightBracket:
return EVT_RIGHTSHIFTKEY; return EVT_RIGHTBRACKETKEY;
case GHOST_kKeyLeftControl: case GHOST_kKeyBackslash:
return EVT_LEFTCTRLKEY; return EVT_BACKSLASHKEY;
case GHOST_kKeyRightControl: case GHOST_kKeyAccentGrave:
return EVT_RIGHTCTRLKEY; return EVT_ACCENTGRAVEKEY;
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: case GHOST_kKeyLeftShift:
return EVT_CAPSLOCKKEY; return EVT_LEFTSHIFTKEY;
case GHOST_kKeyNumLock: case GHOST_kKeyRightShift:
return 0; return EVT_RIGHTSHIFTKEY;
case GHOST_kKeyScrollLock: case GHOST_kKeyLeftControl:
return 0; 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_kKeyLeftArrow: case GHOST_kKeyCapsLock:
return EVT_LEFTARROWKEY; return EVT_CAPSLOCKKEY;
case GHOST_kKeyRightArrow: case GHOST_kKeyNumLock:
return EVT_RIGHTARROWKEY; return 0;
case GHOST_kKeyUpArrow: case GHOST_kKeyScrollLock:
return EVT_UPARROWKEY; return 0;
case GHOST_kKeyDownArrow:
return EVT_DOWNARROWKEY;
case GHOST_kKeyPrintScreen: case GHOST_kKeyLeftArrow:
return 0; return EVT_LEFTARROWKEY;
case GHOST_kKeyPause: case GHOST_kKeyRightArrow:
return EVT_PAUSEKEY; return EVT_RIGHTARROWKEY;
case GHOST_kKeyUpArrow:
return EVT_UPARROWKEY;
case GHOST_kKeyDownArrow:
return EVT_DOWNARROWKEY;
case GHOST_kKeyInsert: case GHOST_kKeyPrintScreen:
return EVT_INSERTKEY; return 0;
case GHOST_kKeyDelete: case GHOST_kKeyPause:
return EVT_DELKEY; return EVT_PAUSEKEY;
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: case GHOST_kKeyInsert:
return EVT_PADPERIOD; return EVT_INSERTKEY;
case GHOST_kKeyNumpadEnter: case GHOST_kKeyDelete:
return EVT_PADENTER; return EVT_DELKEY;
case GHOST_kKeyNumpadPlus: case GHOST_kKeyHome:
return EVT_PADPLUSKEY; return EVT_HOMEKEY;
case GHOST_kKeyNumpadMinus: case GHOST_kKeyEnd:
return EVT_PADMINUS; return EVT_ENDKEY;
case GHOST_kKeyNumpadAsterisk: case GHOST_kKeyUpPage:
return EVT_PADASTERKEY; return EVT_PAGEUPKEY;
case GHOST_kKeyNumpadSlash: case GHOST_kKeyDownPage:
return EVT_PADSLASHKEY; return EVT_PAGEDOWNKEY;
case GHOST_kKeyGrLess: case GHOST_kKeyNumpadPeriod:
return EVT_GRLESSKEY; 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_kKeyMediaPlay: case GHOST_kKeyGrLess:
return EVT_MEDIAPLAY; return EVT_GRLESSKEY;
case GHOST_kKeyMediaStop:
return EVT_MEDIASTOP;
case GHOST_kKeyMediaFirst:
return EVT_MEDIAFIRST;
case GHOST_kKeyMediaLast:
return EVT_MEDIALAST;
default: case GHOST_kKeyMediaPlay:
return EVT_UNKNOWNKEY; /* GHOST_kKeyUnknown */ 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 */
} }
} }

View File

@@ -1404,10 +1404,8 @@ bool write_crash_blend(void)
printf("written: %s\n", path); printf("written: %s\n", path);
return 1; return 1;
} }
else { printf("failed: %s\n", path);
printf("failed: %s\n", path); return 0;
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); wm_close_file_dialog(C, callback);
return OPERATOR_INTERFACE; 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) 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); wm_close_file_dialog(C, callback);
return OPERATOR_INTERFACE; 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) 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); ED_view3d_local_collections_reset(C, (G.fileflags & G_FILE_NO_UI) != 0);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
else { return OPERATOR_CANCELLED;
return OPERATOR_CANCELLED;
}
} }
static OperatorDispatchTarget wm_open_mainfile_dispatch_targets[] = { static OperatorDispatchTarget wm_open_mainfile_dispatch_targets[] = {
@@ -2475,9 +2467,7 @@ static int wm_revert_mainfile_exec(bContext *C, wmOperator *op)
if (success) { if (success) {
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
else { return OPERATOR_CANCELLED;
return OPERATOR_CANCELLED;
}
} }
static bool wm_revert_mainfile_poll(bContext *UNUSED(C)) 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) { if (success) {
return OPERATOR_FINISHED; 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)) static int wm_recover_auto_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))

View File

@@ -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); BKE_reportf(op->reports, RPT_ERROR, "'%s': not a library", path);
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
else if (!group) { if (!group) {
BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path); BKE_reportf(op->reports, RPT_ERROR, "'%s': nothing indicated", path);
return OPERATOR_CANCELLED; 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); BKE_reportf(op->reports, RPT_ERROR, "'%s': cannot use current file as library", path);
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
} }
@@ -755,7 +755,7 @@ static void lib_relocate_do_remap(Main *bmain,
if (c == '.') { if (c == '.') {
break; break;
} }
else if (c < '0' || c > '9') { if (c < '0' || c > '9') {
has_num = false; has_num = false;
break; break;
} }

View File

@@ -344,9 +344,7 @@ void *WM_jobs_customdata_get(wmJob *wm_job)
if (!wm_job->customdata) { if (!wm_job->customdata) {
return wm_job->run_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 *)) void WM_jobs_customdata_set(wmJob *wm_job, void *customdata, void (*free)(void *))

View File

@@ -321,9 +321,7 @@ bool WM_keyconfig_remove(wmWindowManager *wm, wmKeyConfig *keyconf)
return true; return true;
} }
else { return false;
return false;
}
} }
void WM_keyconfig_clear(wmKeyConfig *keyconf) void WM_keyconfig_clear(wmKeyConfig *keyconf)
@@ -448,9 +446,7 @@ bool WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
return true; return true;
} }
else { return false;
return false;
}
} }
bool WM_keymap_poll(bContext *C, wmKeyMap *keymap) 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); WM_keyconfig_update_tag(keymap, NULL);
return true; 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) { if (platform == MACOS) {
return key_event_glyph_or_text(font_id, IFACE_("Cmd"), "\xe2\x8c\x98"); 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 key_event_glyph_or_text(font_id, IFACE_("Win"), "\xe2\x9d\x96");
} }
return IFACE_("OS"); return IFACE_("OS");

View File

@@ -606,9 +606,7 @@ char *WM_operatortype_description(struct bContext *C,
if (description[0]) { if (description[0]) {
return description; return description;
} }
else { MEM_freeN(description);
MEM_freeN(description);
}
} }
} }
@@ -621,9 +619,7 @@ char *WM_operatortype_description(struct bContext *C,
if (info && info[0]) { if (info && info[0]) {
return BLI_strdup(info); return BLI_strdup(info);
} }
else { return NULL;
return NULL;
}
} }
/** \} */ /** \} */

View File

@@ -864,19 +864,9 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
} }
return ret_value | OPERATOR_PASS_THROUGH; return ret_value | OPERATOR_PASS_THROUGH;
} }
else { /* If we are in init phase, and cannot validate init of modal operations,
/* If we are in init phase, and cannot validate init of modal operations, * just fall back to basic exec.
* 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);
return ret_value | OPERATOR_PASS_THROUGH;
}
}
else if (event->type == init_event_type && event->val == KM_RELEASE) {
RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false); RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false);
ret_value = op->type->exec(C, op); ret_value = op->type->exec(C, op);
@@ -884,7 +874,15 @@ int WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
return ret_value | OPERATOR_PASS_THROUGH; return ret_value | OPERATOR_PASS_THROUGH;
} }
else if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) { 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);
OPERATOR_RETVAL_CHECK(ret_value);
return ret_value | OPERATOR_PASS_THROUGH;
}
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
const int drag_delta[2] = { const int drag_delta[2] = {
mval[0] - event->mval[0], mval[0] - event->mval[0],
mval[1] - event->mval[1], 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)) { if (WM_event_drag_test_with_delta(event, drag_delta)) {
return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH; return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
} }
else { /* Important not to return anything other than PASS_THROUGH here,
/* Important not to return anything other than PASS_THROUGH here, * otherwise it prevents underlying tweak detection code to work properly. */
* otherwise it prevents underlying tweak detection code to work properly. */ return OPERATOR_PASS_THROUGH;
return OPERATOR_PASS_THROUGH;
}
} }
return OPERATOR_RUNNING_MODAL | 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) { if (confirm) {
return WM_operator_confirm_message(C, op, NULL); 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 */ /* 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")) { if (RNA_struct_property_is_set(op->ptr, "filepath")) {
return WM_operator_call_notest(C, op); /* call exec direct */ return WM_operator_call_notest(C, op); /* call exec direct */
} }
else { WM_event_add_fileselect(C, op);
WM_event_add_fileselect(C, op); return OPERATOR_RUNNING_MODAL;
return OPERATOR_RUNNING_MODAL;
}
} }
bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const struct ImageFormatData *im_format) 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) { if (flags & RC_PROP_ALLOW_MISSING) {
return 1; return 1;
} }
else { BKE_reportf(op->reports, RPT_ERROR, "Could not resolve path '%s'", name);
BKE_reportf(op->reports, RPT_ERROR, "Could not resolve path '%s'", name); return 0;
return 0;
}
} }
/* check property type */ /* 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))) { (RC_PROP_ALLOW_MISSING | RC_PROP_REQUIRE_BOOL))) {
return 0; return 0;
} }
if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) {
data_path = "data_path_secondary";
}
else { else {
if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) { data_path = "data_path_primary";
data_path = "data_path_secondary";
}
else {
data_path = "data_path_primary";
}
} }
if (!radial_control_get_path(&ctx_ptr, op, data_path, &rc->ptr, &rc->prop, 0, 0)) { 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)) { if (!radial_control_get_path(&ctx_ptr, op, "image_id", &rc->image_id_ptr, NULL, 0, 0)) {
return 0; return 0;
} }
else if (rc->image_id_ptr.data) { if (rc->image_id_ptr.data) {
/* extra check, pointer must be to an ID */ /* extra check, pointer must be to an ID */
if (!RNA_struct_is_ID(rc->image_id_ptr.type)) { 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"); BKE_report(op->reports, RPT_ERROR, "Pointer from path image_id is not an ID");
@@ -2841,173 +2830,171 @@ static int radial_control_modal(bContext *C, wmOperator *op, const wmEvent *even
radial_control_update_header(op, C); radial_control_update_header(op, C);
return OPERATOR_RUNNING_MODAL; 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: handled = false;
case EVT_PADENTER: switch (event->type) {
case EVT_RETKEY: case EVT_ESCKEY:
/* done; value already set */ case RIGHTMOUSE:
RNA_property_update(C, &rc->ptr, rc->prop); /* canceled; restore original value */
ret = OPERATOR_FINISHED; radial_control_set_value(rc, rc->initial_value);
break; ret = OPERATOR_CANCELLED;
break;
case MOUSEMOVE: case LEFTMOUSE:
if (!has_numInput) { case EVT_PADENTER:
if (rc->slow_mode) { case EVT_RETKEY:
if (rc->subtype == PROP_ANGLE) { /* done; value already set */
float position[2] = {event->x, event->y}; RNA_property_update(C, &rc->ptr, rc->prop);
ret = OPERATOR_FINISHED;
break;
/* calculate the initial angle here first */ case MOUSEMOVE:
delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0]; if (!has_numInput) {
delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1]; if (rc->slow_mode) {
if (rc->subtype == PROP_ANGLE) {
float position[2] = {event->x, event->y};
/* precision angle gets calculated from dial and gets added later */ /* calculate the initial angle here first */
angle_precision = -0.1f * BLI_dial_angle(rc->dial, position); delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
} delta[1] = rc->initial_mouse[1] - rc->slow_mouse[1];
else {
delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
delta[1] = 0.0f;
if (rc->zoom_prop) { /* precision angle gets calculated from dial and gets added later */
RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); angle_precision = -0.1f * BLI_dial_angle(rc->dial, position);
delta[0] /= zoom[0];
}
dist = len_v2(delta);
delta[0] = event->x - rc->slow_mouse[0];
if (rc->zoom_prop) {
delta[0] /= zoom[0];
}
dist = dist + 0.1f * (delta[0]);
}
} }
else { else {
delta[0] = rc->initial_mouse[0] - event->x; delta[0] = rc->initial_mouse[0] - rc->slow_mouse[0];
delta[1] = rc->initial_mouse[1] - event->y; delta[1] = 0.0f;
if (rc->zoom_prop) { if (rc->zoom_prop) {
RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom); RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
delta[0] /= zoom[0]; 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);
}
}
/* calculate new value and apply snapping */ dist = len_v2(delta);
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 */ delta[0] = event->x - rc->slow_mouse[0];
CLAMP(new_value, rc->min_value, rc->max_value);
radial_control_set_value(rc, new_value); if (rc->zoom_prop) {
rc->current_value = new_value; delta[0] /= zoom[0];
handled = true; }
break;
dist = dist + 0.1f * (delta[0]);
}
} }
break; else {
delta[0] = rc->initial_mouse[0] - event->x;
case EVT_LEFTSHIFTKEY: delta[1] = rc->initial_mouse[1] - event->y;
case EVT_RIGHTSHIFTKEY: { if (rc->zoom_prop) {
if (event->val == KM_PRESS) { RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
rc->slow_mouse[0] = event->x; delta[0] /= zoom[0];
rc->slow_mouse[1] = event->y; delta[1] /= zoom[1];
rc->slow_mode = true; }
if (rc->subtype == PROP_ANGLE) { if (rc->subtype == PROP_ANGLE) {
float initial_position[2] = {UNPACK2(rc->initial_mouse)}; dist = len_v2(delta);
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; else {
} dist = clamp_f(-delta[0], 0.0f, FLT_MAX);
if (event->val == KM_RELEASE) {
rc->slow_mode = false;
handled = true;
if (rc->dial) {
MEM_freeN(rc->dial);
rc->dial = NULL;
} }
} }
/* 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;
} }
} break;
/* Modal numinput inactive, try to handle numeric inputs last... */ case EVT_LEFTSHIFTKEY:
if (!handled && event->val == KM_PRESS && handleNumInput(C, &rc->num_input, event)) { case EVT_RIGHTSHIFTKEY: {
applyNumInput(&rc->num_input, &numValue); if (event->val == KM_PRESS) {
rc->slow_mouse[0] = event->x;
if (rc->subtype == PROP_ANGLE) { rc->slow_mouse[1] = event->y;
numValue = fmod(numValue, 2.0f * (float)M_PI); rc->slow_mode = true;
if (numValue < 0.0f) { if (rc->subtype == PROP_ANGLE) {
numValue += 2.0f * (float)M_PI; 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;
CLAMP(numValue, rc->min_value, rc->max_value);
new_value = numValue;
radial_control_set_value(rc, new_value);
rc->current_value = new_value;
radial_control_update_header(op, C);
return OPERATOR_RUNNING_MODAL;
} }
} }
/* 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;
}
}
CLAMP(numValue, rc->min_value, rc->max_value);
new_value = numValue;
radial_control_set_value(rc, new_value);
rc->current_value = new_value;
radial_control_update_header(op, C);
return OPERATOR_RUNNING_MODAL;
}
ED_region_tag_redraw(CTX_wm_region(C)); ED_region_tag_redraw(CTX_wm_region(C));
radial_control_update_header(op, C); radial_control_update_header(op, C);

View File

@@ -353,12 +353,11 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_WINDOW, NULL); WM_event_add_notifier(C, NC_WINDOW, NULL);
return OPERATOR_FINISHED; return OPERATOR_FINISHED;
} }
else {
/* without this, the popup won't be freed freed properly T44688 */ /* without this, the popup won't be freed freed properly T44688 */
CTX_wm_window_set(C, win_src); CTX_wm_window_set(C, win_src);
win_src->stereo3d_format->display_mode = prev_display_mode; win_src->stereo3d_format->display_mode = prev_display_mode;
return OPERATOR_CANCELLED; return OPERATOR_CANCELLED;
}
} }
int wm_stereo3d_set_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event)) 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)) { if (wm_stereo3d_set_properties(C, op)) {
return wm_stereo3d_set_exec(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) void wm_stereo3d_set_draw(bContext *UNUSED(C), wmOperator *op)

View File

@@ -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); WM_event_add_notifier_ex(wm, CTX_wm_window(C), NC_WINDOW | NA_ADDED, NULL);
return win_dst; return win_dst;
} }
else { wm_window_close(C, wm, win_dst);
wm_window_close(C, wm, win_dst); return NULL;
return NULL;
}
} }
/** \} */ /** \} */
@@ -813,9 +811,7 @@ static bool wm_window_update_size_position(wmWindow *win)
win->posy = posy; win->posy = posy;
return true; return true;
} }
else { return false;
return false;
}
} }
/** /**
@@ -840,11 +836,10 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect)
if (win->ghostwin) { if (win->ghostwin) {
return win; return win;
} }
else {
wm_window_close(C, wm, win); wm_window_close(C, wm, win);
CTX_wm_window_set(C, win_prev); CTX_wm_window_set(C, win_prev);
return NULL; return NULL;
}
} }
/** /**
@@ -969,13 +964,12 @@ wmWindow *WM_window_open_temp(bContext *C,
GHOST_SetTitle(win->ghostwin, title); GHOST_SetTitle(win->ghostwin, title);
return win; 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 ****************** */ /* ****************** Operators ****************** */
@@ -1215,15 +1209,13 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
puts("<!> event has no window"); puts("<!> event has no window");
return 1; 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 */ /* XXX - should be checked, why are we getting an event here, and */
/* what is it? */ /* what is it? */
puts("<!> event has invalid window"); puts("<!> event has invalid window");
return 1; return 1;
} }
else { win = GHOST_GetWindowUserData(ghostwin);
win = GHOST_GetWindowUserData(ghostwin);
}
switch (type) { switch (type) {
case GHOST_kEventWindowDeactivate: case GHOST_kEventWindowDeactivate:

View File

@@ -183,16 +183,15 @@ static wmXrSessionStateEvent wm_xr_session_state_to_event(const wmXrSessionState
if (!state->is_view_data_set) { if (!state->is_view_data_set) {
return SESSION_STATE_EVENT_START; 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; return SESSION_STATE_EVENT_RESET_TO_BASE_POSE;
} }
else {
const bool position_tracking_toggled = ((state->prev_settings_flag & const bool position_tracking_toggled = ((state->prev_settings_flag &
XR_SESSION_USE_POSITION_TRACKING) != XR_SESSION_USE_POSITION_TRACKING) !=
(settings->flag & XR_SESSION_USE_POSITION_TRACKING)); (settings->flag & XR_SESSION_USE_POSITION_TRACKING));
if (position_tracking_toggled) { if (position_tracking_toggled) {
return SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE; return SESSION_STATE_EVENT_POSITON_TRACKING_TOGGLE;
}
} }
return SESSION_STATE_EVENT_NONE; return SESSION_STATE_EVENT_NONE;