diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 10:31:57 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-04-28 10:31:57 +0400 |
commit | b340f930ec5639f24e7e2d47fab221fb752b61dd (patch) | |
tree | 0e880a36bb528d133af6d10701fc090716b3b7f8 /source/blender/blenlib | |
parent | 09dc600839904a198ab4ba3fad62ce58c2d3aa07 (diff) |
style cleanup: changes to brace placement / newlines - for/while/if/switch
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/intern/BLI_kdopbvh.c | 283 | ||||
-rw-r--r-- | source/blender/blenlib/intern/DLRB_tree.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/dynlib.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/freetypefont.c | 19 | ||||
-rw-r--r-- | source/blender/blenlib/intern/graph.c | 399 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 10 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string_utf8.c | 2 |
11 files changed, 258 insertions, 472 deletions
diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 2cc67b3f0aa..3921c01d2cf 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -217,12 +217,10 @@ static void bvh_insertionsort(BVHNode **a, int lo, int hi, int axis) { int i,j; BVHNode *t; - for (i=lo; i < hi; i++) - { + for (i=lo; i < hi; i++) { j=i; t = a[i]; - while ((j!=lo) && (t->bv[axis] < (a[j-1])->bv[axis])) - { + while ((j!=lo) && (t->bv[axis] < (a[j-1])->bv[axis])) { a[j] = a[j-1]; j--; } @@ -233,8 +231,7 @@ static void bvh_insertionsort(BVHNode **a, int lo, int hi, int axis) static int bvh_partition(BVHNode **a, int lo, int hi, BVHNode * x, int axis) { int i=lo, j=hi; - while (1) - { + while (1) { while ((a[i])->bv[axis] < x->bv[axis]) i++; j--; while (x->bv[axis] < (a[j])->bv[axis]) j--; @@ -284,22 +281,18 @@ static void bvh_heapsort(BVHNode **a, int lo, int hi, int axis) static BVHNode *bvh_medianof3(BVHNode **a, int lo, int mid, int hi, int axis) // returns Sortable { - if ((a[mid])->bv[axis] < (a[lo])->bv[axis]) - { + if ((a[mid])->bv[axis] < (a[lo])->bv[axis]) { if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) return a[mid]; - else - { + else { if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) return a[hi]; else return a[lo]; } } - else - { - if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) - { + else { + if ((a[hi])->bv[axis] < (a[mid])->bv[axis]) { if ((a[hi])->bv[axis] < (a[lo])->bv[axis]) return a[lo]; else @@ -354,8 +347,7 @@ static void sort_along_axis(BVHTree *tree, int start, int end, int axis) static int partition_nth_element(BVHNode **a, int _begin, int _end, int n, int axis) { int begin = _begin, end = _end, cut; - while (end-begin > 3) - { + while (end-begin > 3) { cut = bvh_partition(a, begin, end, bvh_medianof3(a, begin, (begin+end)/2, end-1, axis), axis ); if (cut <= n) begin = cut; @@ -375,8 +367,7 @@ static void build_skip_links(BVHTree *tree, BVHNode *node, BVHNode *left, BVHNod node->skip[0] = left; node->skip[1] = right; - for (i = 0; i < node->totnode; i++) - { + for (i = 0; i < node->totnode; i++) { if (i+1 < node->totnode) build_skip_links(tree, node->children[i], left, node->children[i+1] ); else @@ -396,20 +387,16 @@ static void create_kdop_hull(BVHTree *tree, BVHNode *node, const float *co, int int i, k; // don't init boudings for the moving case - if (!moving) - { - for (i = tree->start_axis; i < tree->stop_axis; i++) - { - bv[2*i] = FLT_MAX; - bv[2*i + 1] = -FLT_MAX; + if (!moving) { + for (i = tree->start_axis; i < tree->stop_axis; i++) { + bv[2 * i] = FLT_MAX; + bv[2 * i + 1] = -FLT_MAX; } } - for (k = 0; k < numpoints; k++) - { - // for all Axes. - for (i = tree->start_axis; i < tree->stop_axis; i++) - { + for (k = 0; k < numpoints; k++) { + /* for all Axes. */ + for (i = tree->start_axis; i < tree->stop_axis; i++) { newminmax = dot_v3v3(&co[k * 3], KDOP_AXES[i]); if (newminmax < bv[2 * i]) bv[2 * i] = newminmax; @@ -427,17 +414,14 @@ static void refit_kdop_hull(BVHTree *tree, BVHNode *node, int start, int end) float *bv = node->bv; - for (i = tree->start_axis; i < tree->stop_axis; i++) - { + for (i = tree->start_axis; i < tree->stop_axis; i++) { bv[2*i] = FLT_MAX; bv[2*i + 1] = -FLT_MAX; } - for (j = start; j < end; j++) - { -// for all Axes. - for (i = tree->start_axis; i < tree->stop_axis; i++) - { + for (j = start; j < end; j++) { + /* for all Axes. */ + for (i = tree->start_axis; i < tree->stop_axis; i++) { newmin = tree->nodes[j]->bv[(2 * i)]; if ((newmin < bv[(2 * i)])) bv[(2 * i)] = newmin; @@ -459,15 +443,13 @@ static char get_largest_axis(float *bv) middle_point[0] = (bv[1]) - (bv[0]); // x axis middle_point[1] = (bv[3]) - (bv[2]); // y axis middle_point[2] = (bv[5]) - (bv[4]); // z axis - if (middle_point[0] > middle_point[1]) - { + if (middle_point[0] > middle_point[1]) { if (middle_point[0] > middle_point[2]) return 1; // max x axis else return 5; // max z axis } - else - { + else { if (middle_point[1] > middle_point[2]) return 3; // max y axis else @@ -481,18 +463,14 @@ static void node_join(BVHTree *tree, BVHNode *node) { int i, j; - for (i = tree->start_axis; i < tree->stop_axis; i++) - { + for (i = tree->start_axis; i < tree->stop_axis; i++) { node->bv[2*i] = FLT_MAX; node->bv[2*i + 1] = -FLT_MAX; } - for (i = 0; i < tree->tree_type; i++) - { - if (node->children[i]) - { - for (j = tree->start_axis; j < tree->stop_axis; j++) - { + for (i = 0; i < tree->tree_type; i++) { + if (node->children[i]) { + for (j = tree->start_axis; j < tree->stop_axis; j++) { // update minimum if (node->children[i]->bv[(2 * j)] < node->bv[(2 * j)]) node->bv[(2 * j)] = node->children[i]->bv[(2 * j)]; @@ -619,17 +597,17 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) data->tree_type= tree->tree_type; //Calculate the smallest tree_type^n such that tree_type^n >= num_leafs - for ( - data->leafs_per_child[0] = 1; - data->leafs_per_child[0] < data->totleafs; - data->leafs_per_child[0] *= data->tree_type - ); + for (data->leafs_per_child[0] = 1; + data->leafs_per_child[0] < data->totleafs; + data->leafs_per_child[0] *= data->tree_type) + { + /* pass */ + } data->branches_on_level[0] = 1; //We could stop the loop first (but I am lazy to find out when) - for (depth = 1; depth < 32; depth++) - { + for (depth = 1; depth < 32; depth++) { data->branches_on_level[depth] = data->branches_on_level[depth-1] * data->tree_type; data->leafs_per_child [depth] = data->leafs_per_child [depth-1] / data->tree_type; } @@ -700,8 +678,7 @@ static int implicit_needed_branches(int tree_type, int leafs) static void split_leafs(BVHNode **leafs_array, int *nth, int partitions, int split_axis) { int i; - for (i=0; i < partitions-1; i++) - { + for (i=0; i < partitions-1; i++) { if (nth[i] >= nth[partitions]) break; @@ -742,8 +719,7 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, //Most of bvhtree code relies on 1-leaf trees having at least one branch //We handle that special case here - if (num_leafs == 1) - { + if (num_leafs == 1) { BVHNode *root = branches_array+0; refit_kdop_hull(tree, root, 0, num_leafs); root->main_axis = get_largest_axis(root->bv) / 2; @@ -758,8 +734,7 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, build_implicit_tree_helper(tree, &data); //Loop tree levels (log N) loops - for (i=1, depth = 1; i <= num_branches; i = i*tree_type + tree_offset, depth++) - { + for (i=1, depth = 1; i <= num_branches; i = i*tree_type + tree_offset, depth++) { const int first_of_next_level = i*tree_type + tree_offset; const int end_j = MIN2(first_of_next_level, num_branches + 1); //index of last branch on this level int j; @@ -885,22 +860,19 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) tree->nodes = (BVHNode **)MEM_callocN(sizeof(BVHNode *)*numnodes, "BVHNodes"); - if (!tree->nodes) - { + if (!tree->nodes) { MEM_freeN(tree); return NULL; } tree->nodebv = (float*)MEM_callocN(sizeof(float)* axis * numnodes, "BVHNodeBV"); - if (!tree->nodebv) - { + if (!tree->nodebv) { MEM_freeN(tree->nodes); MEM_freeN(tree); } tree->nodechild = (BVHNode**)MEM_callocN(sizeof(BVHNode*) * tree_type * numnodes, "BVHNodeBV"); - if (!tree->nodechild) - { + if (!tree->nodechild) { MEM_freeN(tree->nodebv); MEM_freeN(tree->nodes); MEM_freeN(tree); @@ -908,8 +880,7 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) tree->nodearray = (BVHNode *)MEM_callocN(sizeof(BVHNode)* numnodes, "BVHNodeArray"); - if (!tree->nodearray) - { + if (!tree->nodearray) { MEM_freeN(tree->nodechild); MEM_freeN(tree->nodebv); MEM_freeN(tree->nodes); @@ -918,8 +889,7 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) } //link the dynamic bv and child links - for (i=0; i< numnodes; i++) - { + for (i=0; i< numnodes; i++) { tree->nodearray[i].bv = tree->nodebv + i * axis; tree->nodearray[i].children = tree->nodechild + i * tree_type; } @@ -931,8 +901,7 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) void BLI_bvhtree_free(BVHTree *tree) { - if (tree) - { + if (tree) { MEM_freeN(tree->nodes); MEM_freeN(tree->nodearray); MEM_freeN(tree->nodebv); @@ -985,8 +954,7 @@ int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints) node->index= index; // inflate the bv with some epsilon - for (i = tree->start_axis; i < tree->stop_axis; i++) - { + for (i = tree->start_axis; i < tree->stop_axis; i++) { node->bv[(2 * i)] -= tree->epsilon; // minimum node->bv[(2 * i) + 1] += tree->epsilon; // maximum } @@ -1013,8 +981,7 @@ int BLI_bvhtree_update_node(BVHTree *tree, int index, const float *co, const flo create_kdop_hull(tree, node, co_moving, numpoints, 1); // inflate the bv with some epsilon - for (i = tree->start_axis; i < tree->stop_axis; i++) - { + for (i = tree->start_axis; i < tree->stop_axis; i++) { node->bv[(2 * i)] -= tree->epsilon; // minimum node->bv[(2 * i) + 1] += tree->epsilon; // maximum } @@ -1057,8 +1024,7 @@ static int tree_overlap(BVHNode *node1, BVHNode *node2, int start_axis, int stop bv2 += start_axis<<1; // test all axis if min + max overlap - for (; bv1 != bv1_end; bv1+=2, bv2+=2) - { + for (; bv1 != bv1_end; bv1+=2, bv2+=2) { if ((*(bv1) > *(bv2 + 1)) || (*(bv2) > *(bv1 + 1))) return 0; } @@ -1070,27 +1036,21 @@ static void traverse(BVHOverlapData *data, BVHNode *node1, BVHNode *node2) { int j; - if (tree_overlap(node1, node2, data->start_axis, data->stop_axis)) - { + if (tree_overlap(node1, node2, data->start_axis, data->stop_axis)) { // check if node1 is a leaf - if (!node1->totnode) - { + if (!node1->totnode) { // check if node2 is a leaf - if (!node2->totnode) - { + if (!node2->totnode) { - if (node1 == node2) - { + if (node1 == node2) { return; } - if (data->i >= data->max_overlap) - { + if (data->i >= data->max_overlap) { // try to make alloc'ed memory bigger data->overlap = realloc(data->overlap, sizeof(BVHTreeOverlap)*data->max_overlap*2); - if (!data->overlap) - { + if (!data->overlap) { printf("Out of Memory in traverse\n"); return; } @@ -1103,20 +1063,15 @@ static void traverse(BVHOverlapData *data, BVHNode *node1, BVHNode *node2) data->i++; } - else - { - for (j = 0; j < data->tree2->tree_type; j++) - { + else { + for (j = 0; j < data->tree2->tree_type; j++) { if (node2->children[j]) traverse(data, node1, node2->children[j]); } } } - else - { - - for (j = 0; j < data->tree2->tree_type; j++) - { + else { + for (j = 0; j < data->tree2->tree_type; j++) { if (node1->children[j]) traverse(data, node1->children[j], node2); } @@ -1142,8 +1097,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int data = MEM_callocN(sizeof(BVHOverlapData *)* tree1->tree_type, "BVHOverlapData_star"); - for (j = 0; j < tree1->tree_type; j++) - { + for (j = 0; j < tree1->tree_type; j++) { data[j] = (BVHOverlapData *)MEM_callocN(sizeof(BVHOverlapData), "BVHOverlapData"); // init BVHOverlapData @@ -1157,8 +1111,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int } #pragma omp parallel for private(j) schedule(static) - for (j = 0; j < MIN2(tree1->tree_type, tree1->nodes[tree1->totleaf]->totnode); j++) - { + for (j = 0; j < MIN2(tree1->tree_type, tree1->nodes[tree1->totleaf]->totnode); j++) { traverse(data[j], tree1->nodes[tree1->totleaf]->children[j], tree2->nodes[tree2->totleaf]); } @@ -1167,14 +1120,12 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int to = overlap = (BVHTreeOverlap *)MEM_callocN(sizeof(BVHTreeOverlap)*total, "BVHTreeOverlap"); - for (j = 0; j < tree1->tree_type; j++) - { + for (j = 0; j < tree1->tree_type; j++) { memcpy(to, data[j]->overlap, data[j]->i*sizeof(BVHTreeOverlap)); to+=data[j]->i; } - for (j = 0; j < tree1->tree_type; j++) - { + for (j = 0; j < tree1->tree_type; j++) { free(data[j]->overlap); MEM_freeN(data[j]); } @@ -1191,8 +1142,7 @@ static float calc_nearest_point(const float proj[3], BVHNode *node, float *neare const float *bv = node->bv; //nearest on AABB hull - for (i=0; i != 3; i++, bv += 2) - { + for (i=0; i != 3; i++, bv += 2) { if (bv[0] > proj[i]) nearest[i] = bv[0]; else if (bv[1] < proj[i]) @@ -1235,35 +1185,28 @@ typedef struct NodeDistance // TODO: use a priority queue to reduce the number of nodes looked on static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) { - if (node->totnode == 0) - { + if (node->totnode == 0) { if (data->callback) data->callback(data->userdata , node->index, data->co, &data->nearest); - else - { + else { data->nearest.index = node->index; data->nearest.dist = calc_nearest_point(data->proj, node, data->nearest.co); } } - else - { + else { //Better heuristic to pick the closest node to dive on int i; float nearest[3]; - if (data->proj[ node->main_axis ] <= node->children[0]->bv[node->main_axis*2+1]) - { + if (data->proj[ node->main_axis ] <= node->children[0]->bv[node->main_axis*2+1]) { - for (i=0; i != node->totnode; i++) - { + for (i=0; i != node->totnode; i++) { if ( calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; dfs_find_nearest_dfs(data, node->children[i]); } } - else - { - for (i=node->totnode-1; i >= 0 ; i--) - { + else { + for (i=node->totnode-1; i >= 0 ; i--) { if ( calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; dfs_find_nearest_dfs(data, node->children[i]); } @@ -1381,17 +1324,14 @@ int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *n data.callback = callback; data.userdata = userdata; - for (i = data.tree->start_axis; i != data.tree->stop_axis; i++) - { + for (i = data.tree->start_axis; i != data.tree->stop_axis; i++) { data.proj[i] = dot_v3v3(data.co, KDOP_AXES[i]); } - if (nearest) - { + if (nearest) { memcpy( &data.nearest , nearest, sizeof(*nearest) ); } - else - { + else { data.nearest.index = -1; data.nearest.dist = FLT_MAX; } @@ -1401,8 +1341,7 @@ int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *n dfs_find_nearest_begin(&data, root); //copy back results - if (nearest) - { + if (nearest) { memcpy(nearest, &data.nearest, sizeof(*nearest)); } @@ -1424,10 +1363,8 @@ static float ray_nearest_hit(BVHRayCastData *data, float *bv) float low = 0, upper = data->hit.dist; - for (i=0; i != 3; i++, bv += 2) - { - if (data->ray_dot_axis[i] == 0.0f) - { + for (i=0; i != 3; i++, bv += 2) { + if (data->ray_dot_axis[i] == 0.0f) { //axis aligned ray if (data->ray.origin[i] < bv[0] - data->ray.radius || data->ray.origin[i] > bv[1] + data->ray.radius) @@ -1435,18 +1372,15 @@ static float ray_nearest_hit(BVHRayCastData *data, float *bv) return FLT_MAX; } } - else - { + else { float ll = (bv[0] - data->ray.radius - data->ray.origin[i]) / data->ray_dot_axis[i]; float lu = (bv[1] + data->ray.radius - data->ray.origin[i]) / data->ray_dot_axis[i]; - if (data->ray_dot_axis[i] > 0.0f) - { + if (data->ray_dot_axis[i] > 0.0f) { if (ll > low) low = ll; if (lu < upper) upper = lu; } - else - { + else { if (lu > low) low = lu; if (ll < upper) upper = ll; } @@ -1494,31 +1428,25 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) float dist = (data->ray.radius > 0.0f) ? ray_nearest_hit(data, node->bv) : fast_ray_nearest_hit(data, node); if (dist >= data->hit.dist) return; - if (node->totnode == 0) - { - if (data->callback) + if (node->totnode == 0) { + if (data->callback) { data->callback(data->userdata, node->index, &data->ray, &data->hit); - else - { + } + else { data->hit.index = node->index; data->hit.dist = dist; madd_v3_v3v3fl(data->hit.co, data->ray.origin, data->ray.direction, dist); } } - else - { + else { //pick loop direction to dive into the tree (based on ray direction and split axis) - if (data->ray_dot_axis[ (int)node->main_axis ] > 0.0f) - { - for (i=0; i != node->totnode; i++) - { + if (data->ray_dot_axis[ (int)node->main_axis ] > 0.0f) { + for (i=0; i != node->totnode; i++) { dfs_raycast(data, node->children[i]); } } - else - { - for (i=node->totnode-1; i >= 0; i--) - { + else { + for (i=node->totnode-1; i >= 0; i--) { dfs_raycast(data, node->children[i]); } } @@ -1575,13 +1503,11 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f normalize_v3(data.ray.direction); - for (i=0; i<3; i++) - { + for (i=0; i<3; i++) { data.ray_dot_axis[i] = dot_v3v3(data.ray.direction, KDOP_AXES[i]); data.idot_axis[i] = 1.0f / data.ray_dot_axis[i]; - if (fabsf(data.ray_dot_axis[i]) < FLT_EPSILON) - { + if (fabsf(data.ray_dot_axis[i]) < FLT_EPSILON) { data.ray_dot_axis[i] = 0.0; } data.index[2*i] = data.idot_axis[i] < 0.0f ? 1 : 0; @@ -1593,14 +1519,12 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f if (hit) memcpy( &data.hit, hit, sizeof(*hit) ); - else - { + else { data.hit.index = -1; data.hit.dist = FLT_MAX; } - if (root) - { + if (root) { dfs_raycast(&data, root); // iterative_raycast(&data, root); } @@ -1635,8 +1559,7 @@ float BLI_bvhtree_bb_raycast(float *bv, const float light_start[3], const float dist = ray_nearest_hit(&data, bv); - if (dist > 0.0f) - { + if (dist > 0.0f) { madd_v3_v3v3fl(pos, light_start, data.ray.direction, dist); } return dist; @@ -1666,8 +1589,7 @@ typedef struct RangeQueryData static void dfs_range_query(RangeQueryData *data, BVHNode *node) { - if (node->totnode == 0) - { + if (node->totnode == 0) { #if 0 /*UNUSED*/ //Calculate the node min-coords (if the node was a point then this is the point coordinates) float co[3]; @@ -1676,18 +1598,14 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node) co[2] = node->bv[4]; #endif } - else - { + else { int i; - for (i=0; i != node->totnode; i++) - { + for (i=0; i != node->totnode; i++) { float nearest[3]; float dist = calc_nearest_point(data->center, node->children[i], nearest); - if (dist < data->radius) - { + if (dist < data->radius) { //Its a leaf.. call the callback - if (node->children[i]->totnode == 0) - { + if (node->children[i]->totnode == 0) { data->hits++; data->callback(data->userdata, node->children[i]->index, dist); } @@ -1711,15 +1629,12 @@ int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, BVHT data.callback = callback; data.userdata = userdata; - if (root != NULL) - { + if (root != NULL) { float nearest[3]; float dist = calc_nearest_point(data.center, root, nearest); - if (dist < data.radius) - { - //Its a leaf.. call the callback - if (root->totnode == 0) - { + if (dist < data.radius) { + /* Its a leaf.. call the callback */ + if (root->totnode == 0) { data.hits++; data.callback(data.userdata, root->index, dist); } diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c index 0e90042a35f..7c5ee236a35 100644 --- a/source/blender/blenlib/intern/DLRB_tree.c +++ b/source/blender/blenlib/intern/DLRB_tree.c @@ -141,8 +141,7 @@ DLRBT_Node *BLI_dlrbTree_search (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, v return NULL; /* iteratively perform this search */ - while (node && found==0) - { + while (node && found == 0) { /* check if traverse further or not * NOTE: it is assumed that the values will be unit values only */ @@ -183,8 +182,7 @@ DLRBT_Node *BLI_dlrbTree_search_exact (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp return NULL; /* iteratively perform this search */ - while (node && found==0) - { + while (node && found==0) { /* check if traverse further or not * NOTE: it is assumed that the values will be unit values only */ diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 0504ac5be60..7c3ad2c62a2 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -387,7 +387,7 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla return; } - switch(GS(id->name)) { + switch (GS(id->name)) { case ID_IM: ima= (Image *)id; if (ima->packedfile == NULL || (flag & BPATH_TRAVERSE_SKIP_PACKED) == 0) { diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c index e300d09ffbc..c80f3e08e3b 100644 --- a/source/blender/blenlib/intern/dynlib.c +++ b/source/blender/blenlib/intern/dynlib.c @@ -85,7 +85,9 @@ char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib) if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) + { return buf; + } } return NULL; diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index a9a1f2bc57e..8f2a2e6f8b5 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -127,17 +127,21 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf npoints[j] = ftoutline.contours[j] - ftoutline.contours[j - 1]; } - // get number of on-curve points for beziertriples (including conic virtual on-points) + // get number of on-curve points for beziertriples (including conic virtual on-points) for (j = 0; j < ftoutline.n_contours; j++) { for (k = 0; k < npoints[j]; k++) { - if (j > 0) l = k + ftoutline.contours[j - 1] + 1; else l = k; - if (ftoutline.tags[l] == FT_Curve_Tag_On) - onpoints[j]++; + l = (j > 0) ? (k + ftoutline.contours[j - 1] + 1) : k; - if (k < npoints[j] - 1 ) + if (ftoutline.tags[l] == FT_Curve_Tag_On) + onpoints[j]++; + + if (k < npoints[j] - 1 ) { if ( ftoutline.tags[l] == FT_Curve_Tag_Conic && - ftoutline.tags[l+1] == FT_Curve_Tag_Conic) + ftoutline.tags[l+1] == FT_Curve_Tag_Conic) + { onpoints[j]++; + } + } } } @@ -398,8 +402,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) } // Load characters - while (charcode < 256) - { + while (charcode < 256) { // Generate the font data freetypechar_to_vchar(face, charcode, vfd); diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c index 75131f81ade..432a74a5890 100644 --- a/source/blender/blenlib/intern/graph.c +++ b/source/blender/blenlib/intern/graph.c @@ -46,13 +46,11 @@ static void flagAxialSymmetry(BNode *root_node, BNode *end_node, BArc *arc, int void BLI_freeNode(BGraph *graph, BNode *node) { - if (node->arcs) - { + if (node->arcs) { MEM_freeN(node->arcs); } - if (graph->free_node) - { + if (graph->free_node) { graph->free_node(node); } } @@ -70,8 +68,7 @@ BNode *BLI_otherNode(BArc *arc, BNode *node) void BLI_removeArc(BGraph *graph, BArc *arc) { - if (graph->free_arc) - { + if (graph->free_arc) { graph->free_arc(arc); } @@ -82,8 +79,7 @@ void BLI_flagNodes(BGraph *graph, int flag) { BNode *node; - for (node = graph->nodes.first; node; node = node->next) - { + for (node = graph->nodes.first; node; node = node->next) { node->flag = flag; } } @@ -92,8 +88,7 @@ void BLI_flagArcs(BGraph *graph, int flag) { BArc *arc; - for (arc = graph->arcs.first; arc; arc = arc->next) - { + for (arc = graph->arcs.first; arc; arc = arc->next) { arc->flag = flag; } } @@ -109,10 +104,8 @@ void BLI_buildAdjacencyList(BGraph *graph) BNode *node; BArc *arc; - for (node = graph->nodes.first; node; node = node->next) - { - if (node->arcs != NULL) - { + for (node = graph->nodes.first; node; node = node->next) { + if (node->arcs != NULL) { MEM_freeN(node->arcs); } @@ -122,16 +115,13 @@ void BLI_buildAdjacencyList(BGraph *graph) node->flag = 0; } - for (arc = graph->arcs.first; arc; arc= arc->next) - { + for (arc = graph->arcs.first; arc; arc= arc->next) { addArcToNodeAdjacencyList(arc->head, arc); addArcToNodeAdjacencyList(arc->tail, arc); } - for (node = graph->nodes.first; node; node = node->next) - { - if (node->degree != node->flag) - { + for (node = graph->nodes.first; node; node = node->next) { + if (node->degree != node->flag) { printf("error in node [%p]. Added only %i arcs out of %i\n", (void *)node, node->flag, node->degree); } } @@ -141,8 +131,7 @@ void BLI_rebuildAdjacencyListForNode(BGraph* graph, BNode *node) { BArc *arc; - if (node->arcs != NULL) - { + if (node->arcs != NULL) { MEM_freeN(node->arcs); } @@ -151,20 +140,16 @@ void BLI_rebuildAdjacencyListForNode(BGraph* graph, BNode *node) /* temporary use to indicate the first index available in the lists */ node->flag = 0; - for (arc = graph->arcs.first; arc; arc= arc->next) - { - if (arc->head == node) - { + for (arc = graph->arcs.first; arc; arc= arc->next) { + if (arc->head == node) { addArcToNodeAdjacencyList(arc->head, arc); } - else if (arc->tail == node) - { + else if (arc->tail == node) { addArcToNodeAdjacencyList(arc->tail, arc); } } - if (node->degree != node->flag) - { + if (node->degree != node->flag) { printf("error in node [%p]. Added only %i arcs out of %i\n", (void *)node, node->flag, node->degree); } } @@ -173,10 +158,8 @@ void BLI_freeAdjacencyList(BGraph *graph) { BNode *node; - for (node = graph->nodes.first; node; node = node->next) - { - if (node->arcs != NULL) - { + for (node = graph->nodes.first; node; node = node->next) { + if (node->arcs != NULL) { MEM_freeN(node->arcs); node->arcs = NULL; } @@ -187,10 +170,8 @@ int BLI_hasAdjacencyList(BGraph *graph) { BNode *node; - for (node = graph->nodes.first; node; node = node->next) - { - if (node->arcs == NULL) - { + for (node = graph->nodes.first; node; node = node->next) { + if (node->arcs == NULL) { return 0; } } @@ -200,28 +181,24 @@ int BLI_hasAdjacencyList(BGraph *graph) void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced) { - if (arc->head == node_replaced) - { + if (arc->head == node_replaced) { arc->head = node_src; node_src->degree++; } - if (arc->tail == node_replaced) - { + if (arc->tail == node_replaced) { arc->tail = node_src; node_src->degree++; } - if (arc->head == arc->tail) - { + if (arc->head == arc->tail) { node_src->degree -= 2; graph->free_arc(arc); BLI_freelinkN(&graph->arcs, arc); } - if (node_replaced->degree == 0) - { + if (node_replaced->degree == 0) { BLI_removeNode(graph, node_replaced); } } @@ -230,26 +207,22 @@ void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced) { BArc *arc, *next_arc; - for (arc = graph->arcs.first; arc; arc = next_arc) - { + for (arc = graph->arcs.first; arc; arc = next_arc) { next_arc = arc->next; - if (arc->head == node_replaced) - { + if (arc->head == node_replaced) { arc->head = node_src; node_replaced->degree--; node_src->degree++; } - if (arc->tail == node_replaced) - { + if (arc->tail == node_replaced) { arc->tail = node_src; node_replaced->degree--; node_src->degree++; } - if (arc->head == arc->tail) - { + if (arc->head == arc->tail) { node_src->degree -= 2; graph->free_arc(arc); @@ -257,8 +230,7 @@ void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced) } } - if (node_replaced->degree == 0) - { + if (node_replaced->degree == 0) { BLI_removeNode(graph, node_replaced); } } @@ -267,12 +239,9 @@ void BLI_removeDoubleNodes(BGraph *graph, float limit) { BNode *node_src, *node_replaced; - for (node_src = graph->nodes.first; node_src; node_src = node_src->next) - { - for (node_replaced = graph->nodes.first; node_replaced; node_replaced = node_replaced->next) - { - if (node_replaced != node_src && len_v3v3(node_replaced->p, node_src->p) <= limit) - { + for (node_src = graph->nodes.first; node_src; node_src = node_src->next) { + for (node_replaced = graph->nodes.first; node_replaced; node_replaced = node_replaced->next) { + if (node_replaced != node_src && len_v3v3(node_replaced->p, node_src->p) <= limit) { BLI_replaceNode(graph, node_src, node_replaced); } } @@ -285,11 +254,9 @@ BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit) BNode *closest_node = NULL, *node; float min_distance = 0.0f; - for (node = graph->nodes.first; node; node = node->next) - { + for (node = graph->nodes.first; node; node = node->next) { float distance = len_v3v3(p, node->p); - if (distance <= limit && (closest_node == NULL || distance < min_distance)) - { + if (distance <= limit && (closest_node == NULL || distance < min_distance)) { closest_node = node; min_distance = distance; } @@ -301,15 +268,13 @@ BNode * BLI_FindNodeByPosition(BGraph *graph, float *p, float limit) static void flagSubgraph(BNode *node, int subgraph) { - if (node->subgraph_index == 0) - { + if (node->subgraph_index == 0) { BArc *arc; int i; node->subgraph_index = subgraph; - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { arc = node->arcs[i]; flagSubgraph(BLI_otherNode(arc, node), subgraph); } @@ -321,20 +286,16 @@ int BLI_FlagSubgraphs(BGraph *graph) BNode *node; int subgraph = 0; - if (BLI_hasAdjacencyList(graph) == 0) - { + if (BLI_hasAdjacencyList(graph) == 0) { BLI_buildAdjacencyList(graph); } - for (node = graph->nodes.first; node; node = node->next) - { + for (node = graph->nodes.first; node; node = node->next) { node->subgraph_index = 0; } - for (node = graph->nodes.first; node; node = node->next) - { - if (node->subgraph_index == 0) - { + for (node = graph->nodes.first; node; node = node->next) { + if (node->subgraph_index == 0) { subgraph++; flagSubgraph(node, subgraph); } @@ -347,10 +308,8 @@ void BLI_ReflagSubgraph(BGraph *graph, int old_subgraph, int new_subgraph) { BNode *node; - for (node = graph->nodes.first; node; node = node->next) - { - if (node->flag == old_subgraph) - { + for (node = graph->nodes.first; node; node = node->next) { + if (node->flag == old_subgraph) { node->flag = new_subgraph; } } @@ -362,26 +321,22 @@ static int detectCycle(BNode *node, BArc *src_arc) { int value = 0; - if (node->flag == 0) - { + if (node->flag == 0) { int i; /* mark node as visited */ node->flag = 1; - for (i = 0; i < node->degree && value == 0; i++) - { + for (i = 0; i < node->degree && value == 0; i++) { BArc *arc = node->arcs[i]; /* don't go back on the source arc */ - if (arc != src_arc) - { + if (arc != src_arc) { value = detectCycle(BLI_otherNode(arc, node), arc); } } } - else - { + else { value = 1; } @@ -399,11 +354,9 @@ int BLI_isGraphCyclic(BGraph *graph) BLI_flagNodes(graph, 0); /* detectCycles in subgraphs */ - for (node = graph->nodes.first; node && value == 0; node = node->next) - { + for (node = graph->nodes.first; node && value == 0; node = node->next) { /* only for nodes in subgraphs that haven't been visited yet */ - if (node->flag == 0) - { + if (node->flag == 0) { value = value || detectCycle(node, NULL); } } @@ -415,10 +368,8 @@ BArc * BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v) { BArc *nextArc; - for (nextArc = graph->arcs.first; nextArc; nextArc = nextArc->next) - { - if (arc != nextArc && (nextArc->head == v || nextArc->tail == v)) - { + for (nextArc = graph->arcs.first; nextArc; nextArc = nextArc->next) { + if (arc != nextArc && (nextArc->head == v || nextArc->tail == v)) { break; } } @@ -434,30 +385,24 @@ static int subtreeShape(BNode *node, BArc *rootArc, int include_root) node->flag = 1; - if (include_root) - { + if (include_root) { BNode *newNode = BLI_otherNode(rootArc, node); return subtreeShape(newNode, rootArc, 0); } - else - { + else { /* Base case, no arcs leading away */ - if (node->arcs == NULL || *(node->arcs) == NULL) - { + if (node->arcs == NULL || *(node->arcs) == NULL) { return 0; } - else - { + else { int i; - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { BArc *arc = node->arcs[i]; BNode *newNode = BLI_otherNode(arc, node); /* stop immediate and cyclic backtracking */ - if (arc != rootArc && newNode->flag == 0) - { + if (arc != rootArc && newNode->flag == 0) { depth += subtreeShape(newNode, arc, 0); } } @@ -480,13 +425,11 @@ float BLI_subtreeLength(BNode *node) node->flag = 0; /* flag node as visited */ - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { BArc *arc = node->arcs[i]; BNode *other_node = BLI_otherNode(arc, node); - if (other_node->flag != 0) - { + if (other_node->flag != 0) { float subgraph_length = arc->length + BLI_subtreeLength(other_node); length = MAX2(length, subgraph_length); } @@ -503,15 +446,12 @@ void BLI_calcGraphLength(BGraph *graph) nb_subgraphs = BLI_FlagSubgraphs(graph); - for (i = 1; i <= nb_subgraphs; i++) - { + for (i = 1; i <= nb_subgraphs; i++) { BNode *node; - for (node = graph->nodes.first; node; node = node->next) - { + for (node = graph->nodes.first; node; node = node->next) { /* start on an external node of the subgraph */ - if (node->subgraph_index == i && node->degree == 1) - { + if (node->subgraph_index == i && node->degree == 1) { float subgraph_length = BLI_subtreeLength(node); length = MAX2(length, subgraph_length); break; @@ -542,32 +482,27 @@ static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, int i; /* sort ring by angle */ - for (i = 0; i < total - 1; i++) - { + for (i = 0; i < total - 1; i++) { float minAngle = FLT_MAX; int minIndex = -1; int j; - for (j = i + 1; j < total; j++) - { + for (j = i + 1; j < total; j++) { float angle = dot_v3v3(ring[i].n, ring[j].n); /* map negative values to 1..2 */ - if (angle < 0) - { + if (angle < 0) { angle = 1 - angle; } - if (angle < minAngle) - { + if (angle < minAngle) { minIndex = j; minAngle = angle; } } /* swap if needed */ - if (minIndex != i + 1) - { + if (minIndex != i + 1) { RadialArc tmp; tmp = ring[i + 1]; ring[i + 1] = ring[minIndex]; @@ -575,8 +510,7 @@ static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, } } - for (i = 0; i < total && symmetric; i++) - { + for (i = 0; i < total && symmetric; i++) { BNode *node1, *node2; float tangent[3]; float normal[3]; @@ -593,29 +527,25 @@ static void testRadialSymmetry(BGraph *graph, BNode* root_node, RadialArc* ring, BLI_mirrorAlongAxis(p, root_node->p, normal); /* check if it's within limit before continuing */ - if (len_v3v3(node1->p, p) > limit) - { + if (len_v3v3(node1->p, p) > limit) { symmetric = 0; } } - if (symmetric) - { + if (symmetric) { /* mark node as symmetric physically */ copy_v3_v3(root_node->symmetry_axis, axis); root_node->symmetry_flag |= SYM_PHYSICAL; root_node->symmetry_flag |= SYM_RADIAL; /* FLAG SYMMETRY GROUP */ - for (i = 0; i < total; i++) - { + for (i = 0; i < total; i++) { ring[i].arc->symmetry_group = group; ring[i].arc->symmetry_flag = SYM_SIDE_RADIAL + i; } - if (graph->radial_symmetry) - { + if (graph->radial_symmetry) { graph->radial_symmetry(root_node, ring, total); } } @@ -634,13 +564,11 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo root_node->symmetry_flag |= SYM_TOPOLOGICAL; /* total the number of arcs in the symmetry ring */ - for (i = 0; i < root_node->degree; i++) - { + for (i = 0; i < root_node->degree; i++) { BArc *connectedArc = root_node->arcs[i]; /* depth is store as a negative in flag. symmetry level is positive */ - if (connectedArc->symmetry_level == -depth) - { + if (connectedArc->symmetry_level == -depth) { total++; } } @@ -649,13 +577,11 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo unit = ring; /* fill in the ring */ - for (unit = ring, i = 0; i < root_node->degree; i++) - { + for (unit = ring, i = 0; i < root_node->degree; i++) { BArc *connectedArc = root_node->arcs[i]; /* depth is store as a negative in flag. symmetry level is positive */ - if (connectedArc->symmetry_level == -depth) - { + if (connectedArc->symmetry_level == -depth) { BNode *otherNode = BLI_otherNode(connectedArc, root_node); float vec[3]; @@ -676,19 +602,16 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo * using a rather bogus insertion sort * butrings will never get too big to matter * */ - for (i = 0; i < total; i++) - { + for (i = 0; i < total; i++) { int j; - for (j = i - 1; j >= 0; j--) - { + for (j = i - 1; j >= 0; j--) { BArc *arc1, *arc2; arc1 = ring[j].arc; arc2 = ring[j + 1].arc; - if (arc1->length > arc2->length) - { + if (arc1->length > arc2->length) { /* swap with smaller */ RadialArc tmp; @@ -696,8 +619,7 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo ring[j + 1] = ring[j]; ring[j] = tmp; } - else - { + else { break; } } @@ -707,38 +629,32 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo first = 0; group = 0; - for (i = 1; i < total; i++) - { + for (i = 1; i < total; i++) { int dispatch = 0; int last = i - 1; - if (fabsf(ring[first].arc->length - ring[i].arc->length) > limit) - { + if (fabsf(ring[first].arc->length - ring[i].arc->length) > limit) { dispatch = 1; } /* if not dispatching already and on last arc * Dispatch using current arc as last * */ - if (dispatch == 0 && i == total - 1) - { + if (dispatch == 0 && i == total - 1) { last = i; dispatch = 1; } - if (dispatch) - { + if (dispatch) { int sub_total = last - first + 1; group += 1; - if (sub_total == 1) - { + if (sub_total == 1) { group -= 1; /* not really a group so decrement */ /* NOTHING TO DO */ } - else if (sub_total == 2) - { + else if (sub_total == 2) { BArc *arc1, *arc2; BNode *node1, *node2; @@ -750,14 +666,12 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo testAxialSymmetry(graph, root_node, node1, node2, arc1, arc2, axis, limit, group); } - else if (sub_total != total) /* allocate a new sub ring if needed */ - { + else if (sub_total != total) /* allocate a new sub ring if needed */ { RadialArc *sub_ring = MEM_callocN(sizeof(RadialArc) * sub_total, "radial symmetry ring"); int sub_i; /* fill in the sub ring */ - for (sub_i = 0; sub_i < sub_total; sub_i++) - { + for (sub_i = 0; sub_i < sub_total; sub_i++) { sub_ring[sub_i] = ring[first + sub_i]; } @@ -765,8 +679,7 @@ static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, flo MEM_freeN(sub_ring); } - else if (sub_total == total) - { + else if (sub_total == total) { testRadialSymmetry(graph, root_node, ring, total, axis, limit, group); } @@ -786,12 +699,10 @@ static void flagAxialSymmetry(BNode *root_node, BNode *end_node, BArc *arc, int sub_v3_v3v3(vec, end_node->p, root_node->p); - if (dot_v3v3(vec, root_node->symmetry_axis) < 0) - { + if (dot_v3v3(vec, root_node->symmetry_axis) < 0) { arc->symmetry_flag |= SYM_SIDE_NEGATIVE; } - else - { + else { arc->symmetry_flag |= SYM_SIDE_POSITIVE; } } @@ -809,16 +720,13 @@ static void testAxialSymmetry(BGraph *graph, BNode* root_node, BNode* node1, BNo cross_v3_v3v3(nor, vec, axis); - if (abs(nor[0]) > abs(nor[1]) && abs(nor[0]) > abs(nor[2]) && nor[0] < 0) - { + if (abs(nor[0]) > abs(nor[1]) && abs(nor[0]) > abs(nor[2]) && nor[0] < 0) { negate_v3(nor); } - else if (abs(nor[1]) > abs(nor[0]) && abs(nor[1]) > abs(nor[2]) && nor[1] < 0) - { + else if (abs(nor[1]) > abs(nor[0]) && abs(nor[1]) > abs(nor[2]) && nor[1] < 0) { negate_v3(nor); } - else if (abs(nor[2]) > abs(nor[1]) && abs(nor[2]) > abs(nor[0]) && nor[2] < 0) - { + else if (abs(nor[2]) > abs(nor[1]) && abs(nor[2]) > abs(nor[0]) && nor[2] < 0) { negate_v3(nor); } @@ -827,8 +735,7 @@ static void testAxialSymmetry(BGraph *graph, BNode* root_node, BNode* node1, BNo BLI_mirrorAlongAxis(p, root_node->p, nor); /* check if it's within limit before continuing */ - if (len_v3v3(node1->p, p) <= limit) - { + if (len_v3v3(node1->p, p) <= limit) { /* mark node as symmetric physically */ copy_v3_v3(root_node->symmetry_axis, nor); root_node->symmetry_flag |= SYM_PHYSICAL; @@ -838,13 +745,11 @@ static void testAxialSymmetry(BGraph *graph, BNode* root_node, BNode* node1, BNo flagAxialSymmetry(root_node, node1, arc1, group); flagAxialSymmetry(root_node, node2, arc2, group); - if (graph->axial_symmetry) - { + if (graph->axial_symmetry) { graph->axial_symmetry(root_node, node1, node2, arc1, arc2); } } - else - { + else { /* NOT SYMMETRIC */ } } @@ -858,20 +763,16 @@ static void handleAxialSymmetry(BGraph *graph, BNode *root_node, int depth, floa /* mark topological symmetry */ root_node->symmetry_flag |= SYM_TOPOLOGICAL; - for (i = 0; i < root_node->degree; i++) - { + for (i = 0; i < root_node->degree; i++) { BArc *connectedArc = root_node->arcs[i]; /* depth is store as a negative in flag. symmetry level is positive */ - if (connectedArc->symmetry_level == -depth) - { - if (arc1 == NULL) - { + if (connectedArc->symmetry_level == -depth) { + if (arc1 == NULL) { arc1 = connectedArc; node1 = BLI_otherNode(arc1, root_node); } - else - { + else { arc2 = connectedArc; node2 = BLI_otherNode(arc2, root_node); break; /* Can stop now, the two arcs have been found */ @@ -880,8 +781,7 @@ static void handleAxialSymmetry(BGraph *graph, BNode *root_node, int depth, floa } /* shouldn't happen, but just to be sure */ - if (node1 == NULL || node2 == NULL) - { + if (node1 == NULL || node2 == NULL) { return; } @@ -897,18 +797,15 @@ static void markdownSecondarySymmetry(BGraph *graph, BNode *node, int depth, int /* count the number of branches in this symmetry group * and determinate the axis of symmetry * */ - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { BArc *connectedArc = node->arcs[i]; /* depth is store as a negative in flag. symmetry level is positive */ - if (connectedArc->symmetry_level == -depth) - { + if (connectedArc->symmetry_level == -depth) { count++; } /* If arc is on the axis */ - else if (connectedArc->symmetry_level == level) - { + else if (connectedArc->symmetry_level == level) { add_v3_v3(axis, connectedArc->head->p); sub_v3_v3v3(axis, axis, connectedArc->tail->p); } @@ -917,22 +814,18 @@ static void markdownSecondarySymmetry(BGraph *graph, BNode *node, int depth, int normalize_v3(axis); /* Split between axial and radial symmetry */ - if (count == 2) - { + if (count == 2) { handleAxialSymmetry(graph, node, depth, axis, limit); } - else - { + else { handleRadialSymmetry(graph, node, depth, axis, limit); } /* markdown secondary symetries */ - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { BArc *connectedArc = node->arcs[i]; - if (connectedArc->symmetry_level == -depth) - { + if (connectedArc->symmetry_level == -depth) { /* markdown symmetry for branches corresponding to the depth */ markdownSymmetryArc(graph, connectedArc, node, level + 1, limit); } @@ -944,19 +837,16 @@ static void markdownSymmetryArc(BGraph *graph, BArc *arc, BNode *node, int level int i; /* if arc is null, we start straight from a node */ - if (arc) - { + if (arc) { arc->symmetry_level = level; node = BLI_otherNode(arc, node); } - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { BArc *connectedArc = node->arcs[i]; - if (connectedArc != arc) - { + if (connectedArc != arc) { BNode *connectedNode = BLI_otherNode(connectedArc, node); /* symmetry level is positive value, negative values is subtree depth */ @@ -966,26 +856,22 @@ static void markdownSymmetryArc(BGraph *graph, BArc *arc, BNode *node, int level arc = NULL; - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { int issymmetryAxis = 0; BArc *connectedArc = node->arcs[i]; /* only arcs not already marked as symetric */ - if (connectedArc->symmetry_level < 0) - { + if (connectedArc->symmetry_level < 0) { int j; /* true by default */ issymmetryAxis = 1; - for (j = 0; j < node->degree; j++) - { + for (j = 0; j < node->degree; j++) { BArc *otherArc = node->arcs[j]; /* different arc, same depth */ - if (otherArc != connectedArc && otherArc->symmetry_level == connectedArc->symmetry_level) - { + if (otherArc != connectedArc && otherArc->symmetry_level == connectedArc->symmetry_level) { /* not on the symmetry axis */ issymmetryAxis = 0; break; @@ -994,15 +880,12 @@ static void markdownSymmetryArc(BGraph *graph, BArc *arc, BNode *node, int level } /* arc could be on the symmetry axis */ - if (issymmetryAxis == 1) - { + if (issymmetryAxis == 1) { /* no arc as been marked previously, keep this one */ - if (arc == NULL) - { + if (arc == NULL) { arc = connectedArc; } - else if (connectedArc->symmetry_level < arc->symmetry_level) - { + else if (connectedArc->symmetry_level < arc->symmetry_level) { /* go with more complex subtree as symmetry arc */ arc = connectedArc; } @@ -1010,20 +893,17 @@ static void markdownSymmetryArc(BGraph *graph, BArc *arc, BNode *node, int level } /* go down the arc continuing the symmetry axis */ - if (arc) - { + if (arc) { markdownSymmetryArc(graph, arc, node, level, limit); } /* secondary symmetry */ - for (i = 0; i < node->degree; i++) - { + for (i = 0; i < node->degree; i++) { BArc *connectedArc = node->arcs[i]; /* only arcs not already marked as symetric and is not the next arc on the symmetry axis */ - if (connectedArc->symmetry_level < 0) - { + if (connectedArc->symmetry_level < 0) { /* subtree depth is store as a negative value in the symmetry */ markdownSecondarySymmetry(graph, node, -connectedArc->symmetry_level, level, limit); } @@ -1035,13 +915,11 @@ void BLI_markdownSymmetry(BGraph *graph, BNode *root_node, float limit) BNode *node; BArc *arc; - if (root_node == NULL) - { + if (root_node == NULL) { return; } - if (BLI_isGraphCyclic(graph)) - { + if (BLI_isGraphCyclic(graph)) { return; } @@ -1054,37 +932,29 @@ void BLI_markdownSymmetry(BGraph *graph, BNode *root_node, float limit) node = root_node; /* sanity check REMOVE ME */ - if (node->degree > 0) - { + if (node->degree > 0) { arc = node->arcs[0]; - if (node->degree == 1) - { + if (node->degree == 1) { markdownSymmetryArc(graph, arc, node, 1, limit); } - else - { + else { markdownSymmetryArc(graph, NULL, node, 1, limit); } /* mark down non-symetric arcs */ - for (arc = graph->arcs.first; arc; arc = arc->next) - { - if (arc->symmetry_level < 0) - { + for (arc = graph->arcs.first; arc; arc = arc->next) { + if (arc->symmetry_level < 0) { arc->symmetry_level = 0; } - else - { + else { /* mark down nodes with the lowest level symmetry axis */ - if (arc->head->symmetry_level == 0 || arc->head->symmetry_level > arc->symmetry_level) - { + if (arc->head->symmetry_level == 0 || arc->head->symmetry_level > arc->symmetry_level) { arc->head->symmetry_level = arc->symmetry_level; } - if (arc->tail->symmetry_level == 0 || arc->tail->symmetry_level > arc->symmetry_level) - { + if (arc->tail->symmetry_level == 0 || arc->tail->symmetry_level > arc->symmetry_level) { arc->tail->symmetry_level = arc->symmetry_level; } } @@ -1108,16 +978,13 @@ void* IT_peek(void* arg, int n) { BArcIterator *iter = (BArcIterator*)arg; - if (iter->index + n < 0) - { + if (iter->index + n < 0) { return iter->head(iter); } - else if (iter->index + n >= iter->length) - { + else if (iter->index + n >= iter->length) { return iter->tail(iter); } - else - { + else { return iter->peek(iter, n); } } diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index b2b18286cfb..f7114822dfd 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -184,8 +184,7 @@ void BLI_sortlist(ListBase *listbase, int (*cmp)(void *, void *)) BLI_remlink(listbase, current); - while (previous && cmp(previous, current) == 1) - { + while (previous && cmp(previous, current) == 1) { previous = previous->prev; } diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 3c59ca8d52b..f52921cd19b 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1156,7 +1156,7 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check) { static char path[FILE_MAX] = ""; int ok; - switch(id) { + switch (id) { case BLENDER_RESOURCE_PATH_USER: ok= get_path_user(path, NULL, NULL, NULL, ver); break; diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 7a955cf6ed9..f4481c37f2d 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -1151,7 +1151,7 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) } if (node->flag & PBVH_UpdateDrawBuffers) { - switch(bvh->type) { + switch (bvh->type) { case PBVH_GRIDS: GPU_update_grid_buffers(node->draw_buffers, bvh->grids, @@ -1290,7 +1290,9 @@ void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot for (hiter = BLI_ghashIterator_new(map), i = 0; !BLI_ghashIterator_isDone(hiter); BLI_ghashIterator_step(hiter), ++i) + { faces[i]= BLI_ghashIterator_getKey(hiter); + } BLI_ghashIterator_free(hiter); @@ -1345,7 +1347,7 @@ void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *to { int tot; - switch(bvh->type) { + switch (bvh->type) { case PBVH_GRIDS: tot= node->totprim*bvh->gridsize*bvh->gridsize; if (totvert) *totvert= tot; @@ -1360,7 +1362,7 @@ void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *to void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int *totgrid, int *maxgrid, int *gridsize, DMGridData ***griddata, DMGridAdjacency **gridadj) { - switch(bvh->type) { + switch (bvh->type) { case PBVH_GRIDS: if (grid_indices) *grid_indices= node->prim_indices; if (totgrid) *totgrid= node->totprim; @@ -1504,7 +1506,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], if (node->flag & PBVH_FullyHidden) return 0; - switch(bvh->type) { + switch (bvh->type) { case PBVH_FACES: vert = bvh->verts; faces= node->prim_indices; diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 4c92a872ed7..b2245226a3c 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -125,7 +125,7 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) { size_t len= 0; while (len < maxlen) { - switch(*src) { + switch (*src) { case '\0': goto escape_finish; case '\\': diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index aede08be7f9..20c5c8082ce 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -168,7 +168,7 @@ static const size_t utf8_skip_data[256] = { size_t utf8_size; \ while (*src != '\0' && (utf8_size= utf8_skip_data[*src]) < maxncpy) { \ maxncpy -= utf8_size; \ - switch(utf8_size) { \ + switch (utf8_size) { \ case 6: *dst ++ = *src ++; \ case 5: *dst ++ = *src ++; \ case 4: *dst ++ = *src ++; \ |