From 69e6894b15271884623ea6f56ead06db83acbe99 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 24 Mar 2012 06:18:31 +0000 Subject: style cleanup: follow style guide for formatting of if/for/while loops, and else if's --- source/blender/blenlib/intern/BLI_args.c | 8 +- source/blender/blenlib/intern/BLI_dynstr.c | 36 +-- source/blender/blenlib/intern/BLI_kdopbvh.c | 262 +++++++-------- source/blender/blenlib/intern/BLI_kdtree.c | 162 +++++----- source/blender/blenlib/intern/BLI_linklist.c | 5 +- source/blender/blenlib/intern/bpath.c | 10 +- source/blender/blenlib/intern/callbacks.c | 8 +- source/blender/blenlib/intern/dynlib.c | 10 +- source/blender/blenlib/intern/fileops.c | 168 +++++----- source/blender/blenlib/intern/freetypefont.c | 103 +++--- source/blender/blenlib/intern/graph.c | 36 +-- source/blender/blenlib/intern/gsqueue.c | 13 +- source/blender/blenlib/intern/jitter.c | 30 +- source/blender/blenlib/intern/listbase.c | 8 +- source/blender/blenlib/intern/math_base.c | 3 +- source/blender/blenlib/intern/math_base_inline.c | 30 +- source/blender/blenlib/intern/math_color.c | 34 +- source/blender/blenlib/intern/math_color_inline.c | 10 +- source/blender/blenlib/intern/math_geom.c | 315 +++++++++--------- source/blender/blenlib/intern/math_geom_inline.c | 6 +- source/blender/blenlib/intern/math_matrix.c | 164 +++++----- source/blender/blenlib/intern/math_rotation.c | 136 ++++---- source/blender/blenlib/intern/math_vector.c | 38 +-- source/blender/blenlib/intern/math_vector_inline.c | 26 +- source/blender/blenlib/intern/noise.c | 10 +- source/blender/blenlib/intern/path_util.c | 187 ++++++----- source/blender/blenlib/intern/pbvh.c | 352 ++++++++++----------- source/blender/blenlib/intern/rand.c | 6 +- source/blender/blenlib/intern/scanfill.c | 299 ++++++++--------- source/blender/blenlib/intern/storage.c | 59 ++-- source/blender/blenlib/intern/string.c | 48 +-- source/blender/blenlib/intern/string_utf8.c | 30 +- source/blender/blenlib/intern/threads.c | 70 ++-- source/blender/blenlib/intern/time.c | 6 +- source/blender/blenlib/intern/winstuff.c | 29 +- 35 files changed, 1414 insertions(+), 1303 deletions(-) (limited to 'source/blender/blenlib/intern') diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index 3d137641889..cd904030bb9 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -103,7 +103,8 @@ static int keycmp(const void *a, const void *b) return BLI_strcasecmp(ka->arg, kb->arg); else return strcmp(ka->arg, kb->arg); - } else { + } + else { return BLI_ghashutil_intcmp((const void*)ka->pass, (const void*)kb->pass); } } @@ -261,7 +262,7 @@ void BLI_argsParse(struct bArgs *ba, int pass, BA_ArgCallback default_cb, void * { int i = 0; - for( i = 1; i < ba->argc; i++) { /* skip argv[0] */ + for ( i = 1; i < ba->argc; i++) { /* skip argv[0] */ if (ba->passes[i] == 0) { /* -1 signal what side of the comparison it is */ bArgument *a = lookUp(ba, ba->argv[i], pass, -1); @@ -271,7 +272,8 @@ void BLI_argsParse(struct bArgs *ba, int pass, BA_ArgCallback default_cb, void * if (a) { func = a->func; data = a->data; - } else { + } + else { func = default_cb; data = default_data; } diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index ad52de180aa..ed049a573d9 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -119,9 +119,9 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) const int maxlen= 65536; int retval; - while(1) { + while (1) { va_list args_cpy; - if(len == sizeof(fixedmessage)) + if (len == sizeof(fixedmessage)) message= fixedmessage; else message= MEM_callocN(sizeof(char) * len, "BLI_dynstr_appendf"); @@ -131,22 +131,22 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) retval= vsnprintf(message, len, format, args_cpy); va_end(args_cpy); - if(retval == -1) { + if (retval == -1) { /* -1 means not enough space, but on windows it may also mean * there is a formatting error, so we impose a maximum length */ - if(message != fixedmessage) + if (message != fixedmessage) MEM_freeN(message); message= NULL; len *= 2; - if(len > maxlen) { + if (len > maxlen) { fprintf(stderr, "BLI_dynstr_append text too long or format error.\n"); break; } } - else if(retval >= len) { + else if (retval >= len) { /* in C99 the actual length required is returned */ - if(message != fixedmessage) + if (message != fixedmessage) MEM_freeN(message); message= NULL; @@ -157,10 +157,10 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) break; } - if(message) { + if (message) { BLI_dynstr_append(ds, message); - if(message != fixedmessage) + if (message != fixedmessage) MEM_freeN(message); } } @@ -177,8 +177,8 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) * and avoid code duplication, that crashes on some system because * va_start/va_end have to be called for each vsnprintf call */ - while(1) { - if(len == sizeof(fixedmessage)) + while (1) { + if (len == sizeof(fixedmessage)) message= fixedmessage; else message= MEM_callocN(sizeof(char)*(len), "BLI_dynstr_appendf"); @@ -187,22 +187,22 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) retval= vsnprintf(message, len, format, args); va_end(args); - if(retval == -1) { + if (retval == -1) { /* -1 means not enough space, but on windows it may also mean * there is a formatting error, so we impose a maximum length */ - if(message != fixedmessage) + if (message != fixedmessage) MEM_freeN(message); message= NULL; len *= 2; - if(len > maxlen) { + if (len > maxlen) { fprintf(stderr, "BLI_dynstr_append text too long or format error.\n"); break; } } - else if(retval >= len) { + else if (retval >= len) { /* in C99 the actual length required is returned */ - if(message != fixedmessage) + if (message != fixedmessage) MEM_freeN(message); message= NULL; @@ -213,10 +213,10 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) break; } - if(message) { + if (message) { BLI_dynstr_append(ds, message); - if(message != fixedmessage) + if (message != fixedmessage) MEM_freeN(message); } } diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 67e0ea6ebb9..cc05a8a2628 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -133,10 +133,10 @@ static float KDOP_AXES[13][3] = { \ HEAP_TYPE element = heap[heap_size-1]; \ int child = heap_size-1; \ - while(child != 0) \ + while (child != 0) \ { \ int parent = (child-1) / 2; \ - if(PRIORITY(element, heap[parent])) \ + if (PRIORITY(element, heap[parent])) \ { \ heap[child] = heap[parent]; \ child = parent; \ @@ -150,13 +150,13 @@ static float KDOP_AXES[13][3] = { \ HEAP_TYPE element = heap[heap_size-1]; \ int parent = 0; \ - while(parent < (heap_size-1)/2 ) \ + while (parent < (heap_size-1)/2 ) \ { \ int child2 = (parent+1)*2; \ - if(PRIORITY(heap[child2-1], heap[child2])) \ + if (PRIORITY(heap[child2-1], heap[child2])) \ --child2; \ \ - if(PRIORITY(element, heap[child2])) \ + if (PRIORITY(element, heap[child2])) \ break; \ \ heap[parent] = heap[child2]; \ @@ -171,10 +171,10 @@ static int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, in int new_max_size = *max_size * 2; void *new_memblock = NULL; - if(new_size <= *max_size) + if (new_size <= *max_size) return TRUE; - if(*memblock == local_memblock) + if (*memblock == local_memblock) { new_memblock = malloc( size_per_item * new_max_size ); memcpy( new_memblock, *memblock, size_per_item * *max_size ); @@ -182,7 +182,7 @@ static int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, in else new_memblock = realloc(*memblock, size_per_item * new_max_size ); - if(new_memblock) + if (new_memblock) { *memblock = new_memblock; *max_size = new_max_size; @@ -221,7 +221,7 @@ static void bvh_insertionsort(BVHNode **a, int lo, int hi, int axis) { 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--; @@ -238,7 +238,7 @@ static int bvh_partition(BVHNode **a, int lo, int hi, BVHNode * x, int axis) while ((a[i])->bv[axis] < x->bv[axis]) i++; j--; while (x->bv[axis] < (a[j])->bv[axis]) j--; - if(!(i < j)) + if (!(i < j)) return i; SWAP( BVHNode* , a[i], a[j]); i++; @@ -354,10 +354,10 @@ 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) + if (cut <= n) begin = cut; else end = cut; @@ -377,7 +377,7 @@ static void build_skip_links(BVHTree *tree, BVHNode *node, BVHNode *left, BVHNod for (i = 0; i < node->totnode; i++) { - if(i+1 < node->totnode) + if (i+1 < node->totnode) build_skip_links(tree, node->children[i], left, node->children[i+1] ); else build_skip_links(tree, node->children[i], left, right ); @@ -396,7 +396,7 @@ 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) + if (!moving) { for (i = tree->start_axis; i < tree->stop_axis; i++) { @@ -405,7 +405,7 @@ static void create_kdop_hull(BVHTree *tree, BVHNode *node, const float *co, int } } - for(k = 0; k < numpoints; k++) + for (k = 0; k < numpoints; k++) { // for all Axes. for (i = tree->start_axis; i < tree->stop_axis; i++) @@ -514,14 +514,14 @@ static void node_join(BVHTree *tree, BVHNode *node) static void bvhtree_print_tree(BVHTree *tree, BVHNode *node, int depth) { int i; - for(i=0; iindex, node - tree->nodearray); - for(i=2*tree->start_axis; i<2*tree->stop_axis; i++) + for (i=2*tree->start_axis; i<2*tree->stop_axis; i++) printf("%.3f ", node->bv[i]); printf("\n"); - for(i=0; itree_type; i++) - if(node->children[i]) + for (i=0; itree_type; i++) + if (node->children[i]) bvhtree_print_tree(tree, node->children[i], depth+1); } @@ -552,18 +552,18 @@ static void verify_tree(BVHTree *tree) int i, j, check = 0; // check the pointer list - for(i = 0; i < tree->totleaf; i++) + for (i = 0; i < tree->totleaf; i++) { - if(tree->nodes[i]->parent == NULL) + if (tree->nodes[i]->parent == NULL) printf("Leaf has no parent: %d\n", i); else { - for(j = 0; j < tree->tree_type; j++) + for (j = 0; j < tree->tree_type; j++) { - if(tree->nodes[i]->parent->children[j] == tree->nodes[i]) + if (tree->nodes[i]->parent->children[j] == tree->nodes[i]) check = 1; } - if(!check) + if (!check) { printf("Parent child relationship doesn't match: %d\n", i); } @@ -572,18 +572,18 @@ static void verify_tree(BVHTree *tree) } // check the leaf list - for(i = 0; i < tree->totleaf; i++) + for (i = 0; i < tree->totleaf; i++) { - if(tree->nodearray[i].parent == NULL) + if (tree->nodearray[i].parent == NULL) printf("Leaf has no parent: %d\n", i); else { - for(j = 0; j < tree->tree_type; j++) + for (j = 0; j < tree->tree_type; j++) { - if(tree->nodearray[i].parent->children[j] == &tree->nodearray[i]) + if (tree->nodearray[i].parent->children[j] == &tree->nodearray[i]) check = 1; } - if(!check) + if (!check) { printf("Parent child relationship doesn't match: %d\n", i); } @@ -619,7 +619,7 @@ 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( + for ( data->leafs_per_child[0] = 1; data->leafs_per_child[0] < data->totleafs; data->leafs_per_child[0] *= data->tree_type @@ -628,7 +628,7 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) 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; @@ -643,9 +643,9 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) static int implicit_leafs_index(BVHBuildHelper *data, int depth, int child_index) { int min_leaf_index = child_index * data->leafs_per_child[depth-1]; - if(min_leaf_index <= data->remain_leafs) + if (min_leaf_index <= data->remain_leafs) return min_leaf_index; - else if(data->leafs_per_child[depth]) + else if (data->leafs_per_child[depth]) return data->totleafs - (data->branches_on_level[depth-1] - child_index) * data->leafs_per_child[depth]; else return data->remain_leafs; @@ -700,9 +700,9 @@ 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]) + if (nth[i] >= nth[partitions]) break; partition_nth_element(leafs_array, nth[i], nth[partitions], nth[i+1], split_axis); @@ -742,7 +742,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); @@ -758,7 +758,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 @@ -766,7 +766,7 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, //Loop all branches on this level #pragma omp parallel for private(j) schedule(static) - for(j = i; j < end_j; j++) { + for (j = i; j < end_j; j++) { int k; const int parent_level_index= j-i; BVHNode* parent = branches_array + j; @@ -836,10 +836,10 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) int numnodes, i; // theres not support for trees below binary-trees :P - if(tree_type < 2) + if (tree_type < 2) return NULL; - if(tree_type > MAX_TREETYPE) + if (tree_type > MAX_TREETYPE) return NULL; tree = (BVHTree *)MEM_callocN(sizeof(BVHTree), "BVHTree"); @@ -849,7 +849,7 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) //this bug would show up when casting a ray aligned with a kdop-axis and with an edge of 2 faces epsilon = MAX2(FLT_EPSILON, epsilon); - if(tree) { + if (tree) { tree->epsilon = epsilon; tree->tree_type = tree_type; tree->axis = axis; @@ -885,21 +885,21 @@ 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); @@ -908,7 +908,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); @@ -918,7 +918,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,7 +931,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); @@ -957,7 +957,7 @@ void BLI_bvhtree_balance(BVHTree *tree) //current code expects the branches to be linked to the nodes array //we perform that linkage here tree->totbranch = implicit_needed_branches(tree->tree_type, tree->totleaf); - for(i = 0; i < tree->totbranch; i++) + for (i = 0; i < tree->totbranch; i++) tree->nodes[tree->totleaf + i] = branches_array + i; build_skip_links(tree, tree->nodes[tree->totleaf], NULL, NULL); @@ -970,10 +970,10 @@ int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints) BVHNode *node = NULL; // insert should only possible as long as tree->totbranch is 0 - if(tree->totbranch > 0) + if (tree->totbranch > 0) return 0; - if(tree->totleaf+1 >= MEM_allocN_len(tree->nodes)/sizeof(*(tree->nodes))) + if (tree->totleaf+1 >= MEM_allocN_len(tree->nodes)/sizeof(*(tree->nodes))) return 0; // TODO check if have enough nodes in array @@ -1002,14 +1002,14 @@ int BLI_bvhtree_update_node(BVHTree *tree, int index, const float *co, const flo BVHNode *node= NULL; // check if index exists - if(index > tree->totleaf) + if (index > tree->totleaf) return 0; node = tree->nodearray + index; create_kdop_hull(tree, node, co, numpoints, 0); - if(co_moving) + if (co_moving) create_kdop_hull(tree, node, co_moving, numpoints, 1); // inflate the bv with some epsilon @@ -1070,26 +1070,26 @@ 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; @@ -1105,9 +1105,9 @@ static void traverse(BVHOverlapData *data, BVHNode *node1, BVHNode *node2) } else { - for(j = 0; j < data->tree2->tree_type; j++) + for (j = 0; j < data->tree2->tree_type; j++) { - if(node2->children[j]) + if (node2->children[j]) traverse(data, node1, node2->children[j]); } } @@ -1115,9 +1115,9 @@ static void traverse(BVHOverlapData *data, BVHNode *node1, BVHNode *node2) else { - for(j = 0; j < data->tree2->tree_type; j++) + for (j = 0; j < data->tree2->tree_type; j++) { - if(node1->children[j]) + if (node1->children[j]) traverse(data, node1->children[j], node2); } } @@ -1133,16 +1133,16 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int BVHOverlapData **data; // check for compatibility of both trees (can't compare 14-DOP with 18-DOP) - if((tree1->axis != tree2->axis) && (tree1->axis == 14 || tree2->axis == 14) && (tree1->axis == 18 || tree2->axis == 18)) + if ((tree1->axis != tree2->axis) && (tree1->axis == 14 || tree2->axis == 14) && (tree1->axis == 18 || tree2->axis == 18)) return NULL; // fast check root nodes for collision before doing big splitting + traversal - if(!tree_overlap(tree1->nodes[tree1->totleaf], tree2->nodes[tree2->totleaf], MIN2(tree1->start_axis, tree2->start_axis), MIN2(tree1->stop_axis, tree2->stop_axis))) + if (!tree_overlap(tree1->nodes[tree1->totleaf], tree2->nodes[tree2->totleaf], MIN2(tree1->start_axis, tree2->start_axis), MIN2(tree1->stop_axis, tree2->stop_axis))) return NULL; 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"); @@ -1157,23 +1157,23 @@ 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]); } - for(j = 0; j < tree1->tree_type; j++) + for (j = 0; j < tree1->tree_type; j++) total += data[j]->i; 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,11 +1191,11 @@ 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]) + if (bv[0] > proj[i]) nearest[i] = bv[0]; - else if(bv[1] < proj[i]) + else if (bv[1] < proj[i]) nearest[i] = bv[1]; else nearest[i] = proj[i]; @@ -1204,16 +1204,16 @@ static float calc_nearest_point(const float proj[3], BVHNode *node, float *neare #if 0 //nearest on a general hull copy_v3_v3(nearest, data->co); - for(i = data->tree->start_axis; i != data->tree->stop_axis; i++, bv+=2) + for (i = data->tree->start_axis; i != data->tree->stop_axis; i++, bv+=2) { float proj = dot_v3v3( nearest, KDOP_AXES[i]); float dl = bv[0] - proj; float du = bv[1] - proj; - if(dl > 0) { + if (dl > 0) { madd_v3_v3fl(nearest, KDOP_AXES[i], dl); } - else if(du < 0) { + else if (du < 0) { madd_v3_v3fl(nearest, KDOP_AXES[i], du); } } @@ -1235,9 +1235,9 @@ 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) + if (data->callback) data->callback(data->userdata , node->index, data->co, &data->nearest); else { @@ -1251,20 +1251,20 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) 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; + 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--) + for (i=node->totnode-1; i >= 0 ; i--) { - if( calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; + if ( calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; dfs_find_nearest_dfs(data, node->children[i]); } } @@ -1275,7 +1275,7 @@ static void dfs_find_nearest_begin(BVHNearestData *data, BVHNode *node) { float nearest[3], sdist; sdist = calc_nearest_point(data->proj, node, nearest); - if(sdist >= data->nearest.dist) return; + if (sdist >= data->nearest.dist) return; dfs_find_nearest_dfs(data, node); } @@ -1305,7 +1305,7 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) int callbacks = 0, push_heaps = 0; - if(node->totnode == 0) + if (node->totnode == 0) { dfs_find_nearest_dfs(data, node); return; @@ -1314,13 +1314,13 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) current.node = node; current.dist = calc_nearest_point(data->proj, node, nearest); - while(current.dist < data->nearest.dist) + while (current.dist < data->nearest.dist) { // printf("%f : %f\n", current.dist, data->nearest.dist); - for(i=0; i< current.node->totnode; i++) + for (i=0; i< current.node->totnode; i++) { BVHNode *child = current.node->children[i]; - if(child->totnode == 0) + if (child->totnode == 0) { callbacks++; dfs_find_nearest_dfs(data, child); @@ -1328,12 +1328,12 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) else { //adjust heap size - if(heap_size >= max_heap_size + if (heap_size >= max_heap_size && ADJUST_MEMORY(default_heap, (void**)&heap, heap_size+1, &max_heap_size, sizeof(heap[0])) == FALSE) { printf("WARNING: bvh_find_nearest got out of memory\n"); - if(heap != default_heap) + if (heap != default_heap) free(heap); return; @@ -1342,7 +1342,7 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) heap[heap_size].node = current.node->children[i]; heap[heap_size].dist = calc_nearest_point(data->proj, current.node->children[i], nearest); - if(heap[heap_size].dist >= data->nearest.dist) continue; + if (heap[heap_size].dist >= data->nearest.dist) continue; heap_size++; NodeDistance_push_heap(heap, heap_size); @@ -1351,7 +1351,7 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) } } - if(heap_size == 0) break; + if (heap_size == 0) break; current = heap[0]; NodeDistance_pop_heap(heap, heap_size); @@ -1361,7 +1361,7 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) // printf("hsize=%d, callbacks=%d, pushs=%d\n", heap_size, callbacks, push_heaps); - if(heap != default_heap) + if (heap != default_heap) free(heap); } #endif @@ -1381,12 +1381,12 @@ 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) ); } @@ -1397,11 +1397,11 @@ int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *n } //dfs search - if(root) + if (root) dfs_find_nearest_begin(&data, root); //copy back results - if(nearest) + if (nearest) { memcpy(nearest, &data.nearest, sizeof(*nearest)); } @@ -1424,12 +1424,12 @@ static float ray_nearest_hit(BVHRayCastData *data, float *bv) float low = 0, upper = data->hit.dist; - for(i=0; i != 3; i++, bv += 2) + for (i=0; i != 3; i++, bv += 2) { - if(data->ray_dot_axis[i] == 0.0f) + if (data->ray_dot_axis[i] == 0.0f) { //axis aligned ray - if(data->ray.origin[i] < bv[0] - data->ray.radius + if (data->ray.origin[i] < bv[0] - data->ray.radius || data->ray.origin[i] > bv[1] + data->ray.radius) return FLT_MAX; } @@ -1438,18 +1438,18 @@ static float ray_nearest_hit(BVHRayCastData *data, float *bv) 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; + if (ll > low) low = ll; + if (lu < upper) upper = lu; } else { - if(lu > low) low = lu; - if(ll < upper) upper = ll; + if (lu > low) low = lu; + if (ll < upper) upper = ll; } - if(low > upper) return FLT_MAX; + if (low > upper) return FLT_MAX; } } return low; @@ -1472,9 +1472,9 @@ static float fast_ray_nearest_hit(const BVHRayCastData *data, const BVHNode *nod float t1z = (bv[data->index[4]] - data->ray.origin[2]) * data->idot_axis[2]; float t2z = (bv[data->index[5]] - data->ray.origin[2]) * data->idot_axis[2]; - if(t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return FLT_MAX; - if(t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return FLT_MAX; - if(t1x > data->hit.dist || t1y > data->hit.dist || t1z > data->hit.dist) return FLT_MAX; + if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return FLT_MAX; + if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return FLT_MAX; + if (t1x > data->hit.dist || t1y > data->hit.dist || t1z > data->hit.dist) return FLT_MAX; dist = t1x; if (t1y > dist) dist = t1y; @@ -1490,11 +1490,11 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) //before calling the ray-primitive functions /* XXX: temporary solution for particles until fast_ray_nearest_hit supports ray.radius */ 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 (dist >= data->hit.dist) return; - if(node->totnode == 0) + if (node->totnode == 0) { - if(data->callback) + if (data->callback) data->callback(data->userdata, node->index, &data->ray, &data->hit); else { @@ -1506,16 +1506,16 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) 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) + if (data->ray_dot_axis[ (int)node->main_axis ] > 0.0f) { - for(i=0; i != node->totnode; i++) + for (i=0; i != node->totnode; i++) { dfs_raycast(data, node->children[i]); } } else { - for(i=node->totnode-1; i >= 0; i--) + for (i=node->totnode-1; i >= 0; i--) { dfs_raycast(data, node->children[i]); } @@ -1526,18 +1526,18 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) #if 0 static void iterative_raycast(BVHRayCastData *data, BVHNode *node) { - while(node) + while (node) { float dist = fast_ray_nearest_hit(data, node); - if(dist >= data->hit.dist) + if (dist >= data->hit.dist) { node = node->skip[1]; continue; } - if(node->totnode == 0) + if (node->totnode == 0) { - if(data->callback) + if (data->callback) data->callback(data->userdata, node->index, &data->ray, &data->hit); else { @@ -1573,12 +1573,12 @@ 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; } @@ -1589,7 +1589,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f } - if(hit) + if (hit) memcpy( &data.hit, hit, sizeof(*hit) ); else { @@ -1597,14 +1597,14 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f data.hit.dist = FLT_MAX; } - if(root) + if (root) { dfs_raycast(&data, root); // iterative_raycast(&data, root); } - if(hit) + if (hit) memcpy( hit, &data.hit, sizeof(*hit) ); return data.hit.index; @@ -1633,7 +1633,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); } @@ -1664,7 +1664,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) @@ -1677,14 +1677,14 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node) 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); @@ -1709,14 +1709,14 @@ 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) + if (dist < data.radius) { //Its a leaf.. call the callback - if(root->totnode == 0) + if (root->totnode == 0) { data.hits++; data.callback(data.userdata, root->index, dist); diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c index 6db21ec14a6..388c61ec9dd 100644 --- a/source/blender/blenlib/intern/BLI_kdtree.c +++ b/source/blender/blenlib/intern/BLI_kdtree.c @@ -67,7 +67,7 @@ KDTree *BLI_kdtree_new(int maxsize) void BLI_kdtree_free(KDTree *tree) { - if(tree) { + if (tree) { MEM_freeN(tree->nodes); MEM_freeN(tree); } @@ -79,7 +79,7 @@ void BLI_kdtree_insert(KDTree *tree, int index, float *co, float *nor) node->index= index; copy_v3_v3(node->co, co); - if(nor) copy_v3_v3(node->nor, nor); + if (nor) copy_v3_v3(node->nor, nor); } static KDTreeNode *kdtree_balance(KDTreeNode *nodes, int totnode, int axis) @@ -88,9 +88,9 @@ static KDTreeNode *kdtree_balance(KDTreeNode *nodes, int totnode, int axis) float co; int left, right, median, i, j; - if(totnode <= 0) + if (totnode <= 0) return NULL; - else if(totnode == 1) + else if (totnode == 1) return nodes; /* quicksort style sorting around median */ @@ -98,23 +98,23 @@ static KDTreeNode *kdtree_balance(KDTreeNode *nodes, int totnode, int axis) right= totnode-1; median= totnode/2; - while(right > left) { + while (right > left) { co= nodes[right].co[axis]; i= left-1; j= right; - while(1) { - while(nodes[++i].co[axis] < co); - while(nodes[--j].co[axis] > co && j>left); + while (1) { + while (nodes[++i].co[axis] < co); + while (nodes[--j].co[axis] > co && j>left); - if(i >= j) break; + if (i >= j) break; SWAP(KDTreeNode, nodes[i], nodes[j]); } SWAP(KDTreeNode, nodes[i], nodes[right]); - if(i >= median) + if (i >= median) right= i-1; - if(i <= median) + if (i <= median) left= i+1; } @@ -145,7 +145,7 @@ static float squared_distance(const float v2[3], const float v1[3], float *UNUSE //if(n1 && n2 && (dot_v3v3(n1, n2) < 0.0f)) /* can someone explain why this is done?*/ - if(n2 && (dot_v3v3(d, n2) < 0.0f)) { + if (n2 && (dot_v3v3(d, n2) < 0.0f)) { dist *= 10.0f; } @@ -159,7 +159,7 @@ int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest * float min_dist, cur_dist; int totstack, cur=0; - if(!tree->root) + if (!tree->root) return -1; stack= defaultstack; @@ -169,71 +169,71 @@ int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest * min_node= root; min_dist= squared_distance(root->co,co,root->nor,nor); - if(co[root->d] < root->co[root->d]) { - if(root->right) + if (co[root->d] < root->co[root->d]) { + if (root->right) stack[cur++]=root->right; - if(root->left) + if (root->left) stack[cur++]=root->left; } else { - if(root->left) + if (root->left) stack[cur++]=root->left; - if(root->right) + if (root->right) stack[cur++]=root->right; } - while(cur--) { + while (cur--) { node=stack[cur]; cur_dist = node->co[node->d] - co[node->d]; - if(cur_dist<0.0f) { + if (cur_dist<0.0f) { cur_dist= -cur_dist*cur_dist; - if(-cur_distco,co,node->nor,nor); - if(cur_distleft) + if (node->left) stack[cur++]=node->left; } - if(node->right) + if (node->right) stack[cur++]=node->right; } - else{ + else { cur_dist= cur_dist*cur_dist; - if(cur_distco,co,node->nor,nor); - if(cur_distright) + if (node->right) stack[cur++]=node->right; } - if(node->left) + if (node->left) stack[cur++]=node->left; } - if(cur+3 > totstack) { + if (cur+3 > totstack) { KDTreeNode **temp=MEM_callocN((totstack+100)*sizeof(KDTreeNode*), "psys_treestack"); memcpy(temp,stack,totstack*sizeof(KDTreeNode*)); - if(stack != defaultstack) + if (stack != defaultstack) MEM_freeN(stack); stack=temp; totstack+=100; } } - if(nearest) { + if (nearest) { nearest->index= min_node->index; nearest->dist= sqrt(min_dist); copy_v3_v3(nearest->co, min_node->co); } - if(stack != defaultstack) + if (stack != defaultstack) MEM_freeN(stack); return min_node->index; @@ -243,10 +243,10 @@ static void add_nearest(KDTreeNearest *ptn, int *found, int n, int index, float { int i; - if(*found0; i--) { - if(dist >= ptn[i-1].dist) + for (i=*found-1; i>0; i--) { + if (dist >= ptn[i-1].dist) break; else ptn[i]= ptn[i-1]; @@ -265,7 +265,7 @@ int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTree float cur_dist; int i, totstack, cur=0, found=0; - if(!tree->root) + if (!tree->root) return 0; stack= defaultstack; @@ -276,67 +276,67 @@ int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTree cur_dist= squared_distance(root->co,co,root->nor,nor); add_nearest(nearest,&found,n,root->index,cur_dist,root->co); - if(co[root->d] < root->co[root->d]) { - if(root->right) + if (co[root->d] < root->co[root->d]) { + if (root->right) stack[cur++]=root->right; - if(root->left) + if (root->left) stack[cur++]=root->left; } else { - if(root->left) + if (root->left) stack[cur++]=root->left; - if(root->right) + if (root->right) stack[cur++]=root->right; } - while(cur--) { + while (cur--) { node=stack[cur]; cur_dist = node->co[node->d] - co[node->d]; - if(cur_dist<0.0f) { + if (cur_dist<0.0f) { cur_dist= -cur_dist*cur_dist; - if(foundco,co,node->nor,nor); - if(foundindex,cur_dist,node->co); - if(node->left) + if (node->left) stack[cur++]=node->left; } - if(node->right) + if (node->right) stack[cur++]=node->right; } - else{ + else { cur_dist= cur_dist*cur_dist; - if(foundco,co,node->nor,nor); - if(foundindex,cur_dist,node->co); - if(node->right) + if (node->right) stack[cur++]=node->right; } - if(node->left) + if (node->left) stack[cur++]=node->left; } - if(cur+3 > totstack) { + if (cur+3 > totstack) { KDTreeNode **temp=MEM_callocN((totstack+100)*sizeof(KDTreeNode*), "psys_treestack"); memcpy(temp,stack,totstack*sizeof(KDTreeNode*)); - if(stack != defaultstack) + if (stack != defaultstack) MEM_freeN(stack); stack=temp; totstack+=100; } } - for(i=0; idist < kdb->dist) + if (kda->dist < kdb->dist) return -1; - else if(kda->dist > kdb->dist) + else if (kda->dist > kdb->dist) return 1; else return 0; @@ -358,10 +358,10 @@ static void add_in_range(KDTreeNearest **ptn, int found, int *totfoundstack, int { KDTreeNearest *to; - if(found+1 > *totfoundstack) { + if (found+1 > *totfoundstack) { KDTreeNearest *temp=MEM_callocN((*totfoundstack+50)*sizeof(KDTreeNode), "psys_treefoundstack"); memcpy(temp, *ptn, *totfoundstack * sizeof(KDTreeNearest)); - if(*ptn) + if (*ptn) MEM_freeN(*ptn); *ptn = temp; *totfoundstack+=50; @@ -381,7 +381,7 @@ int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KD float range2 = range*range, dist2; int totstack, cur=0, found=0, totfoundstack=0; - if(!tree || !tree->root) + if (!tree || !tree->root) return 0; stack= defaultstack; @@ -389,61 +389,61 @@ int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KD root= tree->root; - if(co[root->d] + range < root->co[root->d]) { - if(root->left) + if (co[root->d] + range < root->co[root->d]) { + if (root->left) stack[cur++]=root->left; } - else if(co[root->d] - range > root->co[root->d]) { - if(root->right) + else if (co[root->d] - range > root->co[root->d]) { + if (root->right) stack[cur++]=root->right; } else { dist2 = squared_distance(root->co, co, root->nor, nor); - if(dist2 <= range2) + if (dist2 <= range2) add_in_range(&foundstack, found++, &totfoundstack, root->index, dist2, root->co); - if(root->left) + if (root->left) stack[cur++]=root->left; - if(root->right) + if (root->right) stack[cur++]=root->right; } - while(cur--) { + while (cur--) { node=stack[cur]; - if(co[node->d] + range < node->co[node->d]) { - if(node->left) + if (co[node->d] + range < node->co[node->d]) { + if (node->left) stack[cur++]=node->left; } - else if(co[node->d] - range > node->co[node->d]) { - if(node->right) + else if (co[node->d] - range > node->co[node->d]) { + if (node->right) stack[cur++]=node->right; } else { dist2 = squared_distance(node->co, co, node->nor, nor); - if(dist2 <= range2) + if (dist2 <= range2) add_in_range(&foundstack, found++, &totfoundstack, node->index, dist2, node->co); - if(node->left) + if (node->left) stack[cur++]=node->left; - if(node->right) + if (node->right) stack[cur++]=node->right; } - if(cur+3 > totstack) { + if (cur+3 > totstack) { KDTreeNode **temp=MEM_callocN((totstack+100)*sizeof(KDTreeNode*), "psys_treestack"); memcpy(temp,stack,totstack*sizeof(KDTreeNode*)); - if(stack != defaultstack) + if (stack != defaultstack) MEM_freeN(stack); stack=temp; totstack+=100; } } - if(stack != defaultstack) + if (stack != defaultstack) MEM_freeN(stack); - if(found) + if (found) qsort(foundstack, found, sizeof(KDTreeNearest), range_compare); *nearest = foundstack; diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index 7529904c1ea..5c7d7089825 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -39,7 +39,8 @@ int BLI_linklist_length(LinkNode *list) { if (0) { return list?(1+BLI_linklist_length(list->next)):0; - } else { + } + else { int len; for (len=0; list; list= list->next) @@ -131,7 +132,7 @@ void BLI_linklist_insert_after(LinkNode **listp, void *ptr) nlink->link = ptr; - if(node) { + if (node) { nlink->next = node->next; node->next = nlink; } diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index c4a1d4b2b8d..0504ac5be60 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -409,8 +409,8 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla #define BPATH_TRAVERSE_POINTCACHE(ptcaches) \ { \ PointCache *cache; \ - for(cache= (ptcaches).first; cache; cache= cache->next) { \ - if(cache->flag & PTCACHE_DISK_CACHE) { \ + for (cache= (ptcaches).first; cache; cache= cache->next) { \ + if (cache->flag & PTCACHE_DISK_CACHE) { \ rewrite_path_fixed(cache->path, \ visit_cb, \ absbase, \ @@ -441,7 +441,7 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla } else if (md->type == eModifierType_Smoke) { SmokeModifierData *smd= (SmokeModifierData *)md; - if(smd->type & MOD_SMOKE_TYPE_DOMAIN) { + if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { BPATH_TRAVERSE_POINTCACHE(smd->domain->ptcaches[0]); } } @@ -527,7 +527,7 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla len= MIN2(1, len); } - for(i= 0; i < len; i++, se++) { + for (i= 0; i < len; i++, se++) { rewrite_path_fixed_dirfile(seq->strip->dir, se->name, visit_cb, absbase, bpath_user_data); } @@ -557,7 +557,7 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla case ID_LI: { Library *lib= (Library *)id; - if(rewrite_path_fixed(lib->name, visit_cb, absbase, bpath_user_data)) { + if (rewrite_path_fixed(lib->name, visit_cb, absbase, bpath_user_data)) { BKE_library_filepath_set(lib, lib->name); } } diff --git a/source/blender/blenlib/intern/callbacks.c b/source/blender/blenlib/intern/callbacks.c index 7e063bc1a18..0cb986d9090 100644 --- a/source/blender/blenlib/intern/callbacks.c +++ b/source/blender/blenlib/intern/callbacks.c @@ -33,7 +33,7 @@ void BLI_exec_cb(struct Main *main, struct ID *self, eCbEvent evt) ListBase *lb= &callback_slots[evt]; bCallbackFuncStore *funcstore; - for(funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= (bCallbackFuncStore *)funcstore->next) { + for (funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= (bCallbackFuncStore *)funcstore->next) { funcstore->func(main, self, funcstore->arg); } } @@ -53,14 +53,14 @@ void BLI_cb_init(void) void BLI_cb_finalize(void) { eCbEvent evt; - for(evt= 0; evt < BLI_CB_EVT_TOT; evt++) { + for (evt= 0; evt < BLI_CB_EVT_TOT; evt++) { ListBase *lb= &callback_slots[evt]; bCallbackFuncStore *funcstore; bCallbackFuncStore *funcstore_next; - for(funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= funcstore_next) { + for (funcstore= (bCallbackFuncStore *)lb->first; funcstore; funcstore= funcstore_next) { funcstore_next= (bCallbackFuncStore *)funcstore->next; BLI_remlink(lb, funcstore); - if(funcstore->alloc) { + if (funcstore->alloc) { MEM_freeN(funcstore); } } diff --git a/source/blender/blenlib/intern/dynlib.c b/source/blender/blenlib/intern/dynlib.c index c23feb975df..e300d09ffbc 100644 --- a/source/blender/blenlib/intern/dynlib.c +++ b/source/blender/blenlib/intern/dynlib.c @@ -56,7 +56,7 @@ DynamicLibrary *BLI_dynlib_open(char *name) handle= LoadLibraryW(name_16); UTF16_UN_ENCODE(name); - if(!handle) + if (!handle) return NULL; lib= MEM_callocN(sizeof(*lib), "Dynamic Library"); @@ -76,13 +76,13 @@ char *BLI_dynlib_get_error_as_string(DynamicLibrary *lib) /* if lib is NULL reset the last error code */ err= GetLastError(); - if(!lib) + if (!lib) SetLastError(ERROR_SUCCESS); - if(err) { + if (err) { static char buf[1024]; - if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), buf, sizeof(buf), NULL)) return buf; @@ -106,7 +106,7 @@ DynamicLibrary *BLI_dynlib_open(char *name) DynamicLibrary *lib; void *handle= dlopen(name, RTLD_LAZY); - if(!handle) + if (!handle) return NULL; lib= MEM_callocN(sizeof(*lib), "Dynamic Library"); diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 9c53048dc5b..edb2daf2d62 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -80,24 +80,24 @@ int BLI_file_gzip(const char *from, const char *to) /* level 1 is very close to 3 (the default) in terms of file size, * but about twice as fast, best use for speedy saving - campbell */ gzfile = BLI_gzopen(to, "wb1"); - if(gzfile == NULL) + if (gzfile == NULL) return -1; file = BLI_open(from, O_BINARY|O_RDONLY,0); - if(file < 0) + if (file < 0) return -2; - while(1) { + while (1) { readsize = read(file, buffer, sizeof(buffer)); - if(readsize < 0) { + if (readsize < 0) { rval= -2; /* error happened in reading */ fprintf(stderr, "Error reading file %s: %s.\n", from, strerror(errno)); break; } - else if(readsize == 0) + else if (readsize == 0) break; /* done reading */ - if(gzwrite(gzfile, buffer, readsize) <= 0) { + if (gzwrite(gzfile, buffer, readsize) <= 0) { rval= -1; /* error happened in writing */ fprintf(stderr, "Error writing gz file %s: %s.\n", to, gzerror(gzfile, &err)); break; @@ -123,27 +123,28 @@ char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r) size= 0; gzfile = BLI_gzopen( from_file, "rb" ); - for(;;) { - if(mem==NULL) { + for (;;) { + if (mem==NULL) { mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem"); alloc_size= chunk_size; - } else { + } + else { mem= MEM_reallocN(mem, size+chunk_size); alloc_size+= chunk_size; } readsize= gzread(gzfile, mem+size, chunk_size); - if(readsize>0) { + if (readsize>0) { size+= readsize; } else break; } - if(size==0) { + if (size==0) { MEM_freeN(mem); mem= NULL; } - else if(alloc_size!=size) + else if (alloc_size!=size) mem= MEM_reallocN(mem, size); *size_r= size; @@ -165,7 +166,7 @@ int BLI_file_is_writable(const char *filename) * creating a file would be nice, but how? */ file = BLI_open(filename, O_BINARY | O_RDWR | O_CREAT, 0666); - if(file < 0) { + if (file < 0) { return 0; } else { @@ -188,7 +189,8 @@ int BLI_file_touch(const char *file) char c = getc(f); rewind(f); putc(c,f); - } else { + } + else { f = BLI_fopen(file,"wb"); } if (f) { @@ -212,7 +214,7 @@ gzFile BLI_gzopen(const char *filename, const char *mode) gzFile gzfile; int fi; - if(!filename || !mode) {return 0;} + if (!filename || !mode) {return 0;} else { @@ -224,7 +226,7 @@ gzFile BLI_gzopen(const char *filename, const char *mode) GetShortPathNameW(filename_16,short_name_16,256); - for(i=0;i<256;i++) {short_name[i]=short_name_16[i];}; + for (i=0;i<256;i++) {short_name[i]=short_name_16[i];}; gzfile = gzopen(short_name,mode); @@ -249,10 +251,12 @@ int BLI_delete(const char *file, int dir, int recursive) if (recursive) { callLocalErrorCallBack("Recursive delete is unsupported on Windows"); err= 1; - } else if (dir) { + } + else if (dir) { err= !RemoveDirectoryW(file_16); if (err) printf ("Unable to remove directory"); - } else { + } + else { err= !DeleteFileW(file_16); if (err) callLocalErrorCallBack("Unable to delete file"); } @@ -357,7 +361,7 @@ void BLI_dir_create_recursive(const char *dirname) BLI_dir_create_recursive(tmp); } - if(dirname[0]) /* patch, this recursive loop tries to create a nameless directory */ + if (dirname[0]) /* patch, this recursive loop tries to create a nameless directory */ if (umkdir(dirname)==-1) printf("Unable to create directory %s\n",dirname); } @@ -368,7 +372,7 @@ int BLI_rename(const char *from, const char *to) /* make sure the filenames are different (case insensitive) before removing */ if (BLI_exists(to) && BLI_strcasecmp(from, to)) - if(BLI_delete(to, 0, 0)) return 1; + if (BLI_delete(to, 0, 0)) return 1; return urename(from, to); } @@ -393,9 +397,9 @@ static void join_dirfile_alloc(char **dst, size_t *alloc_len, const char *dir, c { size_t len = strlen(dir) + strlen(file) + 1; - if(!*dst) + if (!*dst) *dst = MEM_callocN(len + 1, "join_dirfile_alloc path"); - else if(*alloc_len < len) + else if (*alloc_len < len) *dst = MEM_reallocN(*dst, len + 1); *alloc_len = len; @@ -423,27 +427,27 @@ static int recursive_operation(const char *startfrom, const char *startto, recur /* ensure there's no trailing slash in file path */ from = strip_last_slash(startfrom); - if(startto) + if (startto) to = strip_last_slash(startto); ret = lstat(from, &st); - if(ret < 0) { + if (ret < 0) { /* source wasn't found, nothing to operate with */ return ret; } - if(!S_ISDIR(st.st_mode)) { + if (!S_ISDIR(st.st_mode)) { /* source isn't a directory, can't do recursive walking for it, * so just call file callback and leave */ - if(callback_file) { + if (callback_file) { ret = callback_file(from, to); - if(ret != recursiveOp_Callback_OK) + if (ret != recursiveOp_Callback_OK) ret = -1; } MEM_freeN(from); - if(to) MEM_freeN(to); + if (to) MEM_freeN(to); return ret; } @@ -455,20 +459,20 @@ static int recursive_operation(const char *startfrom, const char *startto, recur perror("scandir"); MEM_freeN(from); - if(to) MEM_freeN(to); + if (to) MEM_freeN(to); return -1; } - if(callback_dir_pre) { + if (callback_dir_pre) { /* call pre-recursive walking directory callback */ ret = callback_dir_pre(from, to); - if(ret != recursiveOp_Callback_OK) { + if (ret != recursiveOp_Callback_OK) { MEM_freeN(from); - if(to) free(to); + if (to) free(to); - if(ret == recursiveOp_Callback_StopRecurs) { + if (ret == recursiveOp_Callback_StopRecurs) { /* callback requested not to perform recursive walking, not an error */ return 0; } @@ -480,28 +484,28 @@ static int recursive_operation(const char *startfrom, const char *startto, recur for (i = 0; i < n; i++) { struct dirent *dirent = dirlist[i]; - if(!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) { + if (!strcmp(dirent->d_name, ".") || !strcmp(dirent->d_name, "..")) { free(dirent); continue; } join_dirfile_alloc(&from_path, &from_alloc_len, from, dirent->d_name); - if(to) + if (to) join_dirfile_alloc(&to_path, &to_alloc_len, to, dirent->d_name); - if(dirent->d_type == DT_DIR) { + if (dirent->d_type == DT_DIR) { /* recursively dig into a folder */ ret = recursive_operation(from_path, to_path, callback_dir_pre, callback_file, callback_dir_post); } - else if(callback_file) { + else if (callback_file) { /* call file callback for current path */ ret = callback_file(from_path, to_path); - if(ret != recursiveOp_Callback_OK) + if (ret != recursiveOp_Callback_OK) ret = -1; } - if(ret != 0) { + if (ret != 0) { while (i < n) free(dirlist[i]); break; @@ -510,27 +514,27 @@ static int recursive_operation(const char *startfrom, const char *startto, recur free(dirlist); - if(ret == 0) { - if(callback_dir_post) { + if (ret == 0) { + if (callback_dir_post) { /* call post-recursive directory callback */ ret = callback_dir_post(from, to); - if(ret != recursiveOp_Callback_OK) + if (ret != recursiveOp_Callback_OK) ret = -1; } } - if(from_path) MEM_freeN(from_path); - if(to_path) MEM_freeN(to_path); + if (from_path) MEM_freeN(from_path); + if (to_path) MEM_freeN(to_path); MEM_freeN(from); - if(to) MEM_freeN(to); + if (to) MEM_freeN(to); return ret; } static int delete_callback_post(const char *from, const char *UNUSED(to)) { - if(rmdir(from)) { + if (rmdir(from)) { perror("rmdir"); return recursiveOp_Callback_Error; @@ -541,7 +545,7 @@ static int delete_callback_post(const char *from, const char *UNUSED(to)) static int delete_single_file(const char *from, const char *UNUSED(to)) { - if(unlink(from)) { + if (unlink(from)) { perror("unlink"); return recursiveOp_Callback_Error; @@ -567,7 +571,7 @@ int BLI_open(const char *filename, int oflag, int pmode) int BLI_delete(const char *file, int dir, int recursive) { - if(strchr(file, '"')) { + if (strchr(file, '"')) { printf("Error: not deleted file %s because of quote!\n", file); } else { @@ -588,10 +592,10 @@ static int check_the_same(const char *path_a, const char *path_b) { struct stat st_a, st_b; - if(lstat(path_a, &st_a)) + if (lstat(path_a, &st_a)) return 0; - if(lstat(path_b, &st_b)) + if (lstat(path_b, &st_b)) return 0; return st_a.st_dev == st_b.st_dev && st_a.st_ino == st_b.st_ino; @@ -599,12 +603,12 @@ static int check_the_same(const char *path_a, const char *path_b) static int set_permissions(const char *file, struct stat *st) { - if(chown(file, st->st_uid, st->st_gid)) { + if (chown(file, st->st_uid, st->st_gid)) { perror("chown"); return -1; } - if(chmod(file, st->st_mode)) { + if (chmod(file, st->st_mode)) { perror("chmod"); return -1; } @@ -618,24 +622,24 @@ static int copy_callback_pre(const char *from, const char *to) { struct stat st; - if(check_the_same(from, to)) { + if (check_the_same(from, to)) { fprintf(stderr, "%s: '%s' is the same as '%s'\n", __func__, from, to); return recursiveOp_Callback_Error; } - if(lstat(from, &st)) { + if (lstat(from, &st)) { perror("stat"); return recursiveOp_Callback_Error; } /* create a directory */ - if(mkdir(to, st.st_mode)) { + if (mkdir(to, st.st_mode)) { perror("mkdir"); return recursiveOp_Callback_Error; } /* set proper owner and group on new directory */ - if(chown(to, st.st_uid, st.st_gid)) { + if (chown(to, st.st_uid, st.st_gid)) { perror("chown"); return recursiveOp_Callback_Error; } @@ -650,24 +654,24 @@ static int copy_single_file(const char *from, const char *to) char buf[4096]; size_t len; - if(check_the_same(from, to)) { + if (check_the_same(from, to)) { fprintf(stderr, "%s: '%s' is the same as '%s'\n", __func__, from, to); return recursiveOp_Callback_Error; } - if(lstat(from, &st)) { + if (lstat(from, &st)) { perror("lstat"); return recursiveOp_Callback_Error; } - if(S_ISLNK(st.st_mode)) { + if (S_ISLNK(st.st_mode)) { /* symbolic links should be copied in special way */ char *link_buffer; int need_free; ssize_t link_len; /* get large enough buffer to read link content */ - if(st.st_size < sizeof(buf)) { + if (st.st_size < sizeof(buf)) { link_buffer = buf; need_free = 0; } @@ -677,69 +681,69 @@ static int copy_single_file(const char *from, const char *to) } link_len = readlink(from, link_buffer, st.st_size+1); - if(link_len < 0) { + if (link_len < 0) { perror("readlink"); - if(need_free) MEM_freeN(link_buffer); + if (need_free) MEM_freeN(link_buffer); return recursiveOp_Callback_Error; } link_buffer[link_len] = 0; - if(symlink(link_buffer, to)) { + if (symlink(link_buffer, to)) { perror("symlink"); - if(need_free) MEM_freeN(link_buffer); + if (need_free) MEM_freeN(link_buffer); return recursiveOp_Callback_Error; } - if(need_free) + if (need_free) MEM_freeN(link_buffer); return recursiveOp_Callback_OK; } - else if(S_ISCHR (st.st_mode) || + else if (S_ISCHR (st.st_mode) || S_ISBLK (st.st_mode) || S_ISFIFO (st.st_mode) || S_ISSOCK (st.st_mode)) { /* copy special type of file */ - if(mknod(to, st.st_mode, st.st_rdev)) { + if (mknod(to, st.st_mode, st.st_rdev)) { perror("mknod"); return recursiveOp_Callback_Error; } - if(set_permissions(to, &st)) + if (set_permissions(to, &st)) return recursiveOp_Callback_Error; return recursiveOp_Callback_OK; } - else if(!S_ISREG(st.st_mode)) { + else if (!S_ISREG(st.st_mode)) { fprintf(stderr, "Copying of this kind of files isn't supported yet\n"); return recursiveOp_Callback_Error; } from_stream = fopen(from, "rb"); - if(!from_stream) { + if (!from_stream) { perror("fopen"); return recursiveOp_Callback_Error; } to_stream = fopen(to, "wb"); - if(!to_stream) { + if (!to_stream) { perror("fopen"); fclose(from_stream); return recursiveOp_Callback_Error; } - while((len = fread(buf, 1, sizeof(buf), from_stream)) > 0) { + while ((len = fread(buf, 1, sizeof(buf), from_stream)) > 0) { fwrite(buf, 1, len, to_stream); } fclose(to_stream); fclose(from_stream); - if(set_permissions(to, &st)) + if (set_permissions(to, &st)) return recursiveOp_Callback_Error; return recursiveOp_Callback_OK; @@ -749,7 +753,7 @@ static int move_callback_pre(const char *from, const char *to) { int ret = rename(from, to); - if(ret) + if (ret) return copy_callback_pre(from, to); return recursiveOp_Callback_StopRecurs; @@ -759,7 +763,7 @@ static int move_single_file(const char *from, const char *to) { int ret = rename(from, to); - if(ret) + if (ret) return copy_single_file(from, to); return recursiveOp_Callback_OK; @@ -769,7 +773,7 @@ int BLI_move(const char *file, const char *to) { int ret = recursive_operation(file, to, move_callback_pre, move_single_file, NULL); - if(ret) { + if (ret) { return recursive_operation(file, NULL, NULL, delete_single_file, delete_callback_post); } @@ -780,15 +784,15 @@ static char *check_destination(const char *file, const char *to) { struct stat st; - if(!stat(to, &st)) { - if(S_ISDIR(st.st_mode)) { + if (!stat(to, &st)) { + if (S_ISDIR(st.st_mode)) { char *str, *filename, *path; size_t len = 0; str = strip_last_slash(file); filename = BLI_last_slash(str); - if(!filename) { + if (!filename) { MEM_freeN(str); return (char*)to; } @@ -816,7 +820,7 @@ int BLI_copy(const char *file, const char *to) ret = recursive_operation(file, actual_to, copy_callback_pre, copy_single_file, NULL); - if(actual_to!=to) + if (actual_to!=to) MEM_freeN(actual_to); return ret; @@ -858,7 +862,7 @@ void BLI_dir_create_recursive(const char *dirname) BLI_dir_create_recursive(tmp); } - if(needs_free) + if (needs_free) MEM_freeN(tmp); mkdir(dirname, 0777); @@ -869,7 +873,7 @@ int BLI_rename(const char *from, const char *to) if (!BLI_exists(from)) return 0; if (BLI_exists(to)) - if(BLI_delete(to, 0, 0)) return 1; + if (BLI_delete(to, 0, 0)) return 1; return rename(from, to); } diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index f55ebf915e2..019915b3128 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -86,7 +86,7 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf // adjust font size height= ((double) face->bbox.yMax - (double) face->bbox.yMin); - if(height != 0.0f) + if (height != 0.0f) scale = 1.0f / height; else scale = 1.0f / 1000.0f; @@ -99,7 +99,7 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf err= FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP); // If loading succeeded, convert the FT glyph to the internal format - if(!err) { + if (!err) { int *npoints; int *onpoints; @@ -120,29 +120,29 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf onpoints = (int *)MEM_callocN((ftoutline.n_contours) * sizeof(int),"onpoints"); // calculate total points of each contour - for(j = 0; j < ftoutline.n_contours; j++) { - if(j == 0) + for (j = 0; j < ftoutline.n_contours; j++) { + if (j == 0) npoints[j] = ftoutline.contours[j] + 1; else npoints[j] = ftoutline.contours[j] - ftoutline.contours[j - 1]; } // 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) + 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]++; - if(k < npoints[j] - 1 ) - if( ftoutline.tags[l] == FT_Curve_Tag_Conic && + if (k < npoints[j] - 1 ) + if ( ftoutline.tags[l] == FT_Curve_Tag_Conic && ftoutline.tags[l+1] == FT_Curve_Tag_Conic) onpoints[j]++; } } //contour loop, bezier & conic styles merged - for(j = 0; j < ftoutline.n_contours; j++) { + for (j = 0; j < ftoutline.n_contours; j++) { // add new curve nu = (Nurb *)MEM_callocN(sizeof(struct Nurb), "objfnt_nurb"); bezt = (BezTriple *)MEM_callocN((onpoints[j]) * sizeof(BezTriple), "objfnt_bezt"); @@ -156,9 +156,9 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf nu->bezt = bezt; //individual curve loop, start-end - for(k = 0; k < npoints[j]; k++) { - if(j > 0) l = k + ftoutline.contours[j - 1] + 1; else l = k; - if(k == 0) m = l; + for (k = 0; k < npoints[j]; k++) { + if (j > 0) l = k + ftoutline.contours[j - 1] + 1; else l = k; + if (k == 0) m = l; //virtual conic on-curve points if (k < npoints[j] - 1) { @@ -185,32 +185,37 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf } //on-curve points - if(ftoutline.tags[l] == FT_Curve_Tag_On) { + if (ftoutline.tags[l] == FT_Curve_Tag_On) { //left handle - if(k > 0) { - if(ftoutline.tags[l - 1] == FT_Curve_Tag_Cubic) { + if (k > 0) { + if (ftoutline.tags[l - 1] == FT_Curve_Tag_Cubic) { bezt->vec[0][0] = ftoutline.points[l-1].x* scale; bezt->vec[0][1] = ftoutline.points[l-1].y* scale; bezt->h1= HD_FREE; - } else if(ftoutline.tags[l - 1] == FT_Curve_Tag_Conic) { + } + else if (ftoutline.tags[l - 1] == FT_Curve_Tag_Conic) { bezt->vec[0][0] = (ftoutline.points[l].x + (2 * ftoutline.points[l - 1].x))* scale / 3.0f; bezt->vec[0][1] = (ftoutline.points[l].y + (2 * ftoutline.points[l - 1].y))* scale / 3.0f; bezt->h1= HD_FREE; - } else { + } + else { bezt->vec[0][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[l-1].x)* scale / 3.0f; bezt->vec[0][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[l-1].y)* scale / 3.0f; bezt->h1= HD_VECT; } - } else { //first point on curve - if(ftoutline.tags[ftoutline.contours[j]] == FT_Curve_Tag_Cubic) { + } + else { //first point on curve + if (ftoutline.tags[ftoutline.contours[j]] == FT_Curve_Tag_Cubic) { bezt->vec[0][0] = ftoutline.points[ftoutline.contours[j]].x * scale; bezt->vec[0][1] = ftoutline.points[ftoutline.contours[j]].y * scale; bezt->h1= HD_FREE; - } else if(ftoutline.tags[ftoutline.contours[j]] == FT_Curve_Tag_Conic) { + } + else if (ftoutline.tags[ftoutline.contours[j]] == FT_Curve_Tag_Conic) { bezt->vec[0][0] = (ftoutline.points[l].x + (2 * ftoutline.points[ftoutline.contours[j]].x))* scale / 3.0f; bezt->vec[0][1] = (ftoutline.points[l].y + (2 * ftoutline.points[ftoutline.contours[j]].y))* scale / 3.0f; bezt->h1= HD_FREE; - } else { + } + else { bezt->vec[0][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[ftoutline.contours[j]].x)* scale / 3.0f; bezt->vec[0][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[ftoutline.contours[j]].y)* scale / 3.0f; bezt->h1= HD_VECT; @@ -222,30 +227,35 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf bezt->vec[1][1] = ftoutline.points[l].y* scale; //right handle - if(k < (npoints[j] - 1)) { - if(ftoutline.tags[l+1] == FT_Curve_Tag_Cubic) { + if (k < (npoints[j] - 1)) { + if (ftoutline.tags[l+1] == FT_Curve_Tag_Cubic) { bezt->vec[2][0] = ftoutline.points[l+1].x* scale; bezt->vec[2][1] = ftoutline.points[l+1].y* scale; bezt->h2= HD_FREE; - } else if(ftoutline.tags[l+1] == FT_Curve_Tag_Conic) { + } + else if (ftoutline.tags[l+1] == FT_Curve_Tag_Conic) { bezt->vec[2][0] = (ftoutline.points[l].x + (2 * ftoutline.points[l+1].x))* scale / 3.0f; bezt->vec[2][1] = (ftoutline.points[l].y + (2 * ftoutline.points[l+1].y))* scale / 3.0f; bezt->h2= HD_FREE; - } else { + } + else { bezt->vec[2][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[l+1].x)* scale / 3.0f; bezt->vec[2][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[l+1].y)* scale / 3.0f; bezt->h2= HD_VECT; } - } else { //last point on curve - if(ftoutline.tags[m] == FT_Curve_Tag_Cubic) { + } + else { //last point on curve + if (ftoutline.tags[m] == FT_Curve_Tag_Cubic) { bezt->vec[2][0] = ftoutline.points[m].x* scale; bezt->vec[2][1] = ftoutline.points[m].y* scale; bezt->h2= HD_FREE; - } else if(ftoutline.tags[m] == FT_Curve_Tag_Conic) { + } + else if (ftoutline.tags[m] == FT_Curve_Tag_Conic) { bezt->vec[2][0] = (ftoutline.points[l].x + (2 * ftoutline.points[m].x))* scale / 3.0f; bezt->vec[2][1] = (ftoutline.points[l].y + (2 * ftoutline.points[m].y))* scale / 3.0f; bezt->h2= HD_FREE; - } else { + } + else { bezt->vec[2][0] = ftoutline.points[l].x* scale - (ftoutline.points[l].x - ftoutline.points[m].x)* scale / 3.0f; bezt->vec[2][1] = ftoutline.points[l].y* scale - (ftoutline.points[l].y - ftoutline.points[m].y)* scale / 3.0f; bezt->h2= HD_VECT; @@ -257,7 +267,7 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf // len_squared_v2v2, see if there's a distance between the three points // len_squared_v2v2 again, to check the angle between the handles // finally, check if one of them is a vector handle - if((dist_to_line_v2(bezt->vec[0],bezt->vec[1],bezt->vec[2]) < 0.001f) && + if ((dist_to_line_v2(bezt->vec[0],bezt->vec[1],bezt->vec[2]) < 0.001f) && (len_squared_v2v2(bezt->vec[0], bezt->vec[1]) > 0.0001f*0.0001f) && (len_squared_v2v2(bezt->vec[1], bezt->vec[2]) > 0.0001f*0.0001f) && (len_squared_v2v2(bezt->vec[0], bezt->vec[2]) > 0.0002f*0.0001f) && @@ -271,8 +281,8 @@ static void freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *vf } } } - if(npoints) MEM_freeN(npoints); - if(onpoints) MEM_freeN(onpoints); + if (npoints) MEM_freeN(npoints); + if (onpoints) MEM_freeN(onpoints); } } @@ -286,7 +296,7 @@ static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) tf= vfont_find_tmpfont(vfont); // What, no font found. Something strange here - if(!tf) return FALSE; + if (!tf) return FALSE; // Load the font to memory if (tf->pf) { @@ -334,7 +344,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) 0, &face ); - if(err) return NULL; + if (err) return NULL; #if 0 for ( n = 0; n < face->num_charmaps; n++ ) @@ -381,14 +391,14 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) err = FT_Set_Charmap( face, found ); - if( err ) + if ( err ) return NULL; lcode= charcode= FT_Get_First_Char(face, &glyph_index); } // Load characters - while(charcode < 256) + while (charcode < 256) { // Generate the font data freetypechar_to_vchar(face, charcode, vfd); @@ -397,7 +407,7 @@ static VFontData *objfnt_to_ftvfontdata(PackedFile * pf) charcode = FT_Get_Next_Char(face, charcode, &glyph_index); // Check that we won't start infinite loop - if(charcode <= lcode) + if (charcode <= lcode) break; lcode = charcode; } @@ -425,7 +435,7 @@ static int check_freetypefont(PackedFile * pf) pf->size, 0, &face ); - if(err) { + if (err) { success = 0; //XXX error("This is not a valid font"); } @@ -449,12 +459,13 @@ static int check_freetypefont(PackedFile * pf) glyph_index = FT_Get_Char_Index( face, 'A' ); err = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP); - if(err) success = 0; + if (err) success = 0; else { glyph = face->glyph; if (glyph->format == ft_glyph_format_outline ) { success = 1; - } else { + } + else { //XXX error("Selected Font has no outline data"); success = 0; } @@ -472,7 +483,7 @@ VFontData *BLI_vfontdata_from_freetypefont(PackedFile *pf) //init Freetype err = FT_Init_FreeType( &library); - if(err) { + if (err) { //XXX error("Failed to load the Freetype font library"); return NULL; } @@ -493,18 +504,18 @@ int BLI_vfontchar_from_freetypefont(VFont *vfont, unsigned long character) { int success = FALSE; - if(!vfont) return FALSE; + if (!vfont) return FALSE; // Init Freetype err = FT_Init_FreeType(&library); - if(err) { + if (err) { //XXX error("Failed to load the Freetype font library"); return 0; } // Load the character success = objchr_to_ftvfontdata(vfont, character); - if(success == FALSE) return FALSE; + if (success == FALSE) return FALSE; // Free Freetype FT_Done_FreeType(library); diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c index 967c4411903..75131f81ade 100644 --- a/source/blender/blenlib/intern/graph.c +++ b/source/blender/blenlib/intern/graph.c @@ -82,7 +82,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,7 +92,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,7 +109,7 @@ void BLI_buildAdjacencyList(BGraph *graph) BNode *node; BArc *arc; - for(node = graph->nodes.first; node; node = node->next) + for (node = graph->nodes.first; node; node = node->next) { if (node->arcs != NULL) { @@ -122,13 +122,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) + for (node = graph->nodes.first; node; node = node->next) { if (node->degree != node->flag) { @@ -151,7 +151,7 @@ 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) + for (arc = graph->arcs.first; arc; arc= arc->next) { if (arc->head == node) { @@ -173,7 +173,7 @@ void BLI_freeAdjacencyList(BGraph *graph) { BNode *node; - for(node = graph->nodes.first; node; node = node->next) + for (node = graph->nodes.first; node; node = node->next) { if (node->arcs != NULL) { @@ -187,7 +187,7 @@ int BLI_hasAdjacencyList(BGraph *graph) { BNode *node; - for(node = graph->nodes.first; node; node = node->next) + for (node = graph->nodes.first; node; node = node->next) { if (node->arcs == NULL) { @@ -267,9 +267,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_src = graph->nodes.first; node_src; node_src = node_src->next) { - for(node_replaced = graph->nodes.first; node_replaced; node_replaced = node_replaced->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) { @@ -285,7 +285,7 @@ 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)) @@ -308,7 +308,7 @@ static void flagSubgraph(BNode *node, int subgraph) 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); @@ -326,7 +326,7 @@ int BLI_FlagSubgraphs(BGraph *graph) 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; } @@ -369,7 +369,7 @@ static int detectCycle(BNode *node, BArc *src_arc) /* 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]; @@ -399,7 +399,7 @@ 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) @@ -415,7 +415,7 @@ BArc * BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v) { BArc *nextArc; - for(nextArc = graph->arcs.first; nextArc; nextArc = nextArc->next) + for (nextArc = graph->arcs.first; nextArc; nextArc = nextArc->next) { if (arc != nextArc && (nextArc->head == v || nextArc->tail == v)) { @@ -450,7 +450,7 @@ static int subtreeShape(BNode *node, BArc *rootArc, int include_root) { 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); @@ -480,7 +480,7 @@ 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); diff --git a/source/blender/blenlib/intern/gsqueue.c b/source/blender/blenlib/intern/gsqueue.c index c0fa81475c0..2aa51387c48 100644 --- a/source/blender/blenlib/intern/gsqueue.c +++ b/source/blender/blenlib/intern/gsqueue.c @@ -64,7 +64,7 @@ int BLI_gsqueue_size(GSQueue *gq) GSQueueElem *elem; int size= 0; - for(elem=gq->head; elem; elem=elem->next) + for (elem=gq->head; elem; elem=elem->next) size++; return size; @@ -79,7 +79,8 @@ void BLI_gsqueue_pop(GSQueue *gq, void *item_r) GSQueueElem *elem= gq->head; if (elem==gq->tail) { gq->head= gq->tail= NULL; - } else { + } + else { gq->head= gq->head->next; } @@ -92,7 +93,7 @@ void BLI_gsqueue_push(GSQueue *gq, void *item) /* compare: prevent events added double in row */ if (!BLI_gsqueue_is_empty(gq)) { - if(0==memcmp(item, &gq->head[1], gq->elem_size)) + if (0==memcmp(item, &gq->head[1], gq->elem_size)) return; } elem= MEM_mallocN(sizeof(*elem)+gq->elem_size, "gqueue_push"); @@ -101,7 +102,8 @@ void BLI_gsqueue_push(GSQueue *gq, void *item) if (BLI_gsqueue_is_empty(gq)) { gq->tail= gq->head= elem; - } else { + } + else { gq->tail= gq->tail->next= elem; } } @@ -113,7 +115,8 @@ void BLI_gsqueue_pushback(GSQueue *gq, void *item) if (BLI_gsqueue_is_empty(gq)) { gq->head= gq->tail= elem; - } else { + } + else { gq->head= elem; } } diff --git a/source/blender/blenlib/intern/jitter.c b/source/blender/blenlib/intern/jitter.c index 52733b092d3..fbdf698cc87 100644 --- a/source/blender/blenlib/intern/jitter.c +++ b/source/blender/blenlib/intern/jitter.c @@ -55,9 +55,9 @@ void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1) vecx = jit1[j] - x - 1.0f; vecy = jit1[j+1] - y - 1.0f; for (k = 3; k>0 ; k--) { - if( fabsf(vecx)0 && len0 && len0 && len0 && len0 && len0 && lenprev; } @@ -457,7 +457,7 @@ int BLI_findstringindex(const ListBase *listbase, const char *id, const int offs while (link) { id_iter= ((const char *)link) + offset; - if(id[0] == id_iter[0] && strcmp(id, id_iter)==0) + if (id[0] == id_iter[0] && strcmp(id, id_iter)==0) return i; i++; link= link->next; @@ -474,7 +474,7 @@ void BLI_duplicatelist(ListBase *dst, const ListBase *src) src_link= src->first; dst->first= dst->last= NULL; - while(src_link) { + while (src_link) { dst_link= MEM_dupallocN(src_link); BLI_addtail(dst, dst_link); diff --git a/source/blender/blenlib/intern/math_base.c b/source/blender/blenlib/intern/math_base.c index 67c2a989582..f2df36202fe 100644 --- a/source/blender/blenlib/intern/math_base.c +++ b/source/blender/blenlib/intern/math_base.c @@ -40,7 +40,8 @@ double copysign(double x, double y) /* use atan2 to distinguish -0. from 0. */ if (y > 0. || (y == 0. && atan2(y, -1.) > 0.)) { return fabs(x); - } else { + } + else { return -fabs(x); } } diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 74c7b67beed..d706f28e722 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -43,55 +43,55 @@ MINLINE float sqrt3f(float f) { - if(f==0.0f) return 0.0f; - if(f<0) return (float)(-exp(log(-f)/3)); + if (f==0.0f) return 0.0f; + if (f<0) return (float)(-exp(log(-f)/3)); else return (float)(exp(log(f)/3)); } MINLINE double sqrt3d(double d) { - if(d==0.0) return 0; - if(d<0) return -exp(log(-d)/3); + if (d==0.0) return 0; + if (d<0) return -exp(log(-d)/3); else return exp(log(d)/3); } MINLINE float saacos(float fac) { - if(fac<= -1.0f) return (float)M_PI; - else if(fac>=1.0f) return 0.0; + if (fac<= -1.0f) return (float)M_PI; + else if (fac>=1.0f) return 0.0; else return (float)acos(fac); } MINLINE float saasin(float fac) { - if(fac<= -1.0f) return (float)-M_PI/2.0f; - else if(fac>=1.0f) return (float)M_PI/2.0f; + if (fac<= -1.0f) return (float)-M_PI/2.0f; + else if (fac>=1.0f) return (float)M_PI/2.0f; else return (float)asin(fac); } MINLINE float sasqrt(float fac) { - if(fac<=0.0f) return 0.0f; + if (fac<=0.0f) return 0.0f; return (float)sqrt(fac); } MINLINE float saacosf(float fac) { - if(fac<= -1.0f) return (float)M_PI; - else if(fac>=1.0f) return 0.0f; + if (fac<= -1.0f) return (float)M_PI; + else if (fac>=1.0f) return 0.0f; else return (float)acosf(fac); } MINLINE float saasinf(float fac) { - if(fac<= -1.0f) return (float)-M_PI/2.0f; - else if(fac>=1.0f) return (float)M_PI/2.0f; + if (fac<= -1.0f) return (float)-M_PI/2.0f; + else if (fac>=1.0f) return (float)M_PI/2.0f; else return (float)asinf(fac); } MINLINE float sasqrtf(float fac) { - if(fac<=0.0f) return 0.0f; + if (fac<=0.0f) return 0.0f; return (float)sqrtf(fac); } @@ -125,7 +125,7 @@ MINLINE int power_of_2_max_i(int n) if (is_power_of_2_i(n)) return n; - while(!is_power_of_2_i(n)) + while (!is_power_of_2_i(n)) n = n & (n - 1); return n * 2; diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c index 96600b6665f..bef5b9e538b 100644 --- a/source/blender/blenlib/intern/math_color.c +++ b/source/blender/blenlib/intern/math_color.c @@ -41,7 +41,7 @@ void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b) int i; float f, p, q, t; - if(s==0.0f) { + if (s==0.0f) { *r = v; *g = v; *b = v; @@ -242,7 +242,7 @@ void rgb_to_hsv(float r, float g, float b, float *lh, float *ls, float *lv) *ls = s; *lh = h / 360.0f; - if(*lh < 0.0f) *lh= 0.0f; + if (*lh < 0.0f) *lh= 0.0f; *lv = v; } @@ -253,7 +253,7 @@ void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *l rgb_to_hsv(r, g, b, lh, ls, lv); - if(*lv <= 0.0f) { + if (*lv <= 0.0f) { *lh= orig_h; *ls= orig_s; } @@ -261,7 +261,7 @@ void rgb_to_hsv_compat(float r, float g, float b, float *lh, float *ls, float *l *lh= orig_h; } - if(*lh==0.0f && orig_h >= 1.0f) { + if (*lh==0.0f && orig_h >= 1.0f) { *lh= 1.0f; } } @@ -315,11 +315,11 @@ unsigned int rgb_to_cpack(float r, float g, float b) int ir, ig, ib; ir= (int)floor(255.0f*r); - if(ir<0) ir= 0; else if(ir>255) ir= 255; + if (ir<0) ir= 0; else if (ir>255) ir= 255; ig= (int)floor(255.0f*g); - if(ig<0) ig= 0; else if(ig>255) ig= 255; + if (ig<0) ig= 0; else if (ig>255) ig= 255; ib= (int)floor(255.0f*b); - if(ib<0) ib= 0; else if(ib>255) ib= 255; + if (ib<0) ib= 0; else if (ib>255) ib= 255; return (ir+ (ig*256) + (ib*256*256)); } @@ -404,12 +404,12 @@ float linearrgb_to_srgb(float c) void minmax_rgb(short c[]) { - if(c[0]>255) c[0]=255; - else if(c[0]<0) c[0]=0; - if(c[1]>255) c[1]=255; - else if(c[1]<0) c[1]=0; - if(c[2]>255) c[2]=255; - else if(c[2]<0) c[2]=0; + if (c[0]>255) c[0]=255; + else if (c[0]<0) c[0]=0; + if (c[1]>255) c[1]=255; + else if (c[1]<0) c[1]=0; + if (c[2]>255) c[2]=255; + else if (c[2]<0) c[2]=0; } /*If the requested RGB shade contains a negative weight for @@ -464,10 +464,10 @@ unsigned char rgb_to_luma_byte(const unsigned char rgb[3]) void lift_gamma_gain_to_asc_cdl(float *lift, float *gamma, float *gain, float *offset, float *slope, float *power) { int c; - for(c=0; c<3; c++) { + for (c=0; c<3; c++) { offset[c]= lift[c]*gain[c]; slope[c]= gain[c]*(1.0f-lift[c]); - if(gamma[c] == 0) + if (gamma[c] == 0) power[c]= FLT_MAX; else power[c]= 1.0f/gamma[c]; @@ -484,8 +484,8 @@ void rgb_float_set_hue_float_offset(float rgb[3], float hue_offset) rgb_to_hsv(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); hsv[0]+= hue_offset; - if(hsv[0] > 1.0f) hsv[0] -= 1.0f; - else if(hsv[0] < 0.0f) hsv[0] += 1.0f; + if (hsv[0] > 1.0f) hsv[0] -= 1.0f; + else if (hsv[0] < 0.0f) hsv[0] += 1.0f; hsv_to_rgb(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); } diff --git a/source/blender/blenlib/intern/math_color_inline.c b/source/blender/blenlib/intern/math_color_inline.c index 2f04bdc9b4b..4f7a197e79b 100644 --- a/source/blender/blenlib/intern/math_color_inline.c +++ b/source/blender/blenlib/intern/math_color_inline.c @@ -87,7 +87,7 @@ MINLINE void srgb_to_linearrgb_predivide_v4(float linear[4], const float srgb[4] { float alpha, inv_alpha; - if(srgb[3] == 1.0f || srgb[3] == 0.0f) { + if (srgb[3] == 1.0f || srgb[3] == 0.0f) { alpha = 1.0f; inv_alpha = 1.0f; } @@ -106,7 +106,7 @@ MINLINE void linearrgb_to_srgb_predivide_v4(float srgb[4], const float linear[4] { float alpha, inv_alpha; - if(linear[3] == 1.0f || linear[3] == 0.0f) { + if (linear[3] == 1.0f || linear[3] == 0.0f) { alpha = 1.0f; inv_alpha = 1.0f; } @@ -153,7 +153,7 @@ MINLINE void linearrgb_to_srgb_ushort4_predivide(unsigned short srgb[4], const f float alpha, inv_alpha, t; int i; - if(linear[3] == 1.0f || linear[3] == 0.0f) { + if (linear[3] == 1.0f || linear[3] == 0.0f) { linearrgb_to_srgb_ushort4(srgb, linear); return; } @@ -161,7 +161,7 @@ MINLINE void linearrgb_to_srgb_ushort4_predivide(unsigned short srgb[4], const f alpha = linear[3]; inv_alpha = 1.0f/alpha; - for(i=0; i<3; ++i) { + for (i=0; i<3; ++i) { t = linear[i] * inv_alpha; srgb[i] = (t < 1.0f)? (unsigned short)(to_srgb_table_lookup(t) * alpha) : FTOUSHORT(linearrgb_to_srgb(t) * alpha); } @@ -182,7 +182,7 @@ MINLINE void srgb_to_linearrgb_uchar4_predivide(float linear[4], const unsigned float fsrgb[4]; int i; - if(srgb[3] == 255 || srgb[3] == 0) { + if (srgb[3] == 255 || srgb[3] == 0) { srgb_to_linearrgb_uchar4(linear, srgb); return; } diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index e2850daa5b8..aa62df5ae3e 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -139,8 +139,8 @@ float area_poly_v3(int nr, float verts[][3], const float normal[3]) y= fabsf(normal[1]); z= fabsf(normal[2]); max = MAX3(x, y, z); - if(max==y) py=2; - else if(max==x) { + if (max==y) py=2; + else if (max==x) { px=1; py= 2; } @@ -149,7 +149,7 @@ float area_poly_v3(int nr, float verts[][3], const float normal[3]) prev= verts[nr-1]; cur= verts[0]; area= 0; - for(a=0; a= 1.0f) { + else if (labda >= 1.0f) { pt[0]= v3[0]; pt[1]= v3[1]; } @@ -215,9 +215,9 @@ void closest_to_line_segment_v2(float close_r[2], const float p[2], const float lambda= closest_to_line_v2(cp,p, l1, l2); - if(lambda <= 0.0f) + if (lambda <= 0.0f) copy_v2_v2(close_r, l1); - else if(lambda >= 1.0f) + else if (lambda >= 1.0f) copy_v2_v2(close_r, l2); else copy_v2_v2(close_r, cp); @@ -230,9 +230,9 @@ void closest_to_line_segment_v3(float close_r[3], const float v1[3], const float lambda= closest_to_line_v3(cp,v1, v2, v3); - if(lambda <= 0.0f) + if (lambda <= 0.0f) copy_v3_v3(close_r, v2); - else if(lambda >= 1.0f) + else if (lambda >= 1.0f) copy_v3_v3(close_r, v3); else copy_v3_v3(close_r, cp); @@ -298,14 +298,14 @@ int isect_line_line_v2_int(const int v1[2], const int v2[2], const int v3[2], co float div, labda, mu; div= (float)((v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0])); - if(div==0.0f) return ISECT_LINE_LINE_COLINEAR; + if (div==0.0f) return ISECT_LINE_LINE_COLINEAR; labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div; mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div; - if(labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) { - if(labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return ISECT_LINE_LINE_EXACT; + if (labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) { + if (labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return ISECT_LINE_LINE_EXACT; return ISECT_LINE_LINE_CROSS; } return ISECT_LINE_LINE_NONE; @@ -317,14 +317,14 @@ int isect_line_line_v2(const float v1[2], const float v2[2], const float v3[2], float div, labda, mu; div= (v2[0]-v1[0])*(v4[1]-v3[1])-(v2[1]-v1[1])*(v4[0]-v3[0]); - if(div==0.0f) return ISECT_LINE_LINE_COLINEAR; + if (div==0.0f) return ISECT_LINE_LINE_COLINEAR; labda= ((float)(v1[1]-v3[1])*(v4[0]-v3[0])-(v1[0]-v3[0])*(v4[1]-v3[1]))/div; mu= ((float)(v1[1]-v3[1])*(v2[0]-v1[0])-(v1[0]-v3[0])*(v2[1]-v1[1]))/div; - if(labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) { - if(labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return ISECT_LINE_LINE_EXACT; + if (labda>=0.0f && labda<=1.0f && mu>=0.0f && mu<=1.0f) { + if (labda==0.0f || labda==1.0f || mu==0.0f || mu==1.0f) return ISECT_LINE_LINE_EXACT; return ISECT_LINE_LINE_CROSS; } return ISECT_LINE_LINE_NONE; @@ -350,18 +350,19 @@ int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[ d= a1*b2-a2*b1; - if(d==0) { - if(a1*c2-a2*c1==0.0f && b1*c2-b2*c1==0.0f) { /* equal lines */ + if (d==0) { + if (a1*c2-a2*c1==0.0f && b1*c2-b2*c1==0.0f) { /* equal lines */ float a[2], b[2], c[2]; float u2; - if(len_v2v2(v1, v2)==0.0f) { - if(len_v2v2(v3, v4)>eps) { + if (len_v2v2(v1, v2)==0.0f) { + if (len_v2v2(v3, v4)>eps) { /* use non-point segment as basis */ SWAP(const float *, v1, v3); SWAP(const float *, v2, v4); - } else { /* both of segments are points */ - if(equals_v2v2(v1, v3)) { /* points are equal */ + } + else { /* both of segments are points */ + if (equals_v2v2(v1, v3)) { /* points are equal */ copy_v2_v2(vi, v1); return 1; } @@ -379,10 +380,10 @@ int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[ sub_v2_v2v2(a, v4, v1); u2= dot_v2v2(a, b) / dot_v2v2(c, c); - if(u>u2) SWAP(float, u, u2); + if (u>u2) SWAP(float, u, u2); - if(u>1.0f+eps || u2<-eps) return -1; /* non-ovlerlapping segments */ - else if(maxf(0.0f, u) == minf(1.0f, u2)) { /* one common point: can return result */ + if (u>1.0f+eps || u2<-eps) return -1; /* non-ovlerlapping segments */ + else if (maxf(0.0f, u) == minf(1.0f, u2)) { /* one common point: can return result */ interp_v2_v2v2(vi, v1, v2, maxf(0, u)); return 1; } @@ -395,7 +396,7 @@ int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[ u= (c2*b1-b2*c1)/d; v= (c1*a2-a1*c2)/d; - if(u>=-eps && u<=1.0f+eps && v>=-eps && v<=1.0f+eps) { /* intersection */ + if (u>=-eps && u<=1.0f+eps && v>=-eps && v<=1.0f+eps) { /* intersection */ interp_v2_v2v2(vi, v1, v2, u); return 1; } @@ -594,7 +595,8 @@ int isect_point_tri_v2(const float pt[2], const float v1[2], const float v2[2], return 1; } } - } else { + } + else { if (! (line_point_side_v2(v2,v3,pt)>=0.0f)) { if (! (line_point_side_v2(v3,v1,pt)>=0.0f)) { return -1; @@ -615,7 +617,8 @@ int isect_point_quad_v2(const float pt[2], const float v1[2], const float v2[2], } } } - } else { + } + else { if (! (line_point_side_v2(v2,v3,pt)>=0.0f)) { if (! (line_point_side_v2(v3,v4,pt)>=0.0f)) { if (! (line_point_side_v2(v4,v1,pt)>=0.0f)) { @@ -662,7 +665,7 @@ int isect_line_tri_v3(const float p1[3], const float p2[3], *r_lambda = f * dot_v3v3(e2, q); if ((*r_lambda < 0.0f)||(*r_lambda > 1.0f)) return 0; - if(r_uv) { + if (r_uv) { r_uv[0]= u; r_uv[1]= v; } @@ -703,7 +706,7 @@ int isect_ray_tri_v3(const float p1[3], const float d[3], *r_lambda = f * dot_v3v3(e2, q); if ((*r_lambda < 0.0f)) return 0; - if(r_uv) { + if (r_uv) { r_uv[0]= u; r_uv[1]= v; } @@ -771,7 +774,7 @@ int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], *r_lambda = f * dot_v3v3(e2, q); if ((*r_lambda < 0.0f)) return 0; - if(uv) { + if (uv) { uv[0]= u; uv[1]= v; } @@ -821,7 +824,7 @@ int isect_ray_tri_threshold_v3(const float p1[3], const float d[3], return 0; } - if(r_uv) { + if (r_uv) { r_uv[0]= u; r_uv[1]= v; } @@ -841,7 +844,7 @@ int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], cons normalize_v3_v3(p_no, plane_no); dot= dot_v3v3(l_vec, p_no); - if(dot == 0.0f) { + if (dot == 0.0f) { return 0; } else { @@ -850,7 +853,7 @@ int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], cons /* for predictable flipping since the plane is only used to * define a direction, ignore its flipping and aligned with 'l_vec' */ - if(dot < 0.0f) { + if (dot < 0.0f) { dot= -dot; negate_v3(p_no); } @@ -860,7 +863,7 @@ int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], cons dist = line_point_factor_v3(plane_co, l1, l1_plane); /* treat line like a ray, when 'no_flip' is set */ - if(no_flip && dist < 0.0f) { + if (no_flip && dist < 0.0f) { dist= -dist; } @@ -941,13 +944,13 @@ int isect_sweeping_sphere_tri_v3( normalize_v3(nor); /* flip normal */ - if(dot_v3v3(nor,vel)>0.0f) negate_v3(nor); + if (dot_v3v3(nor,vel)>0.0f) negate_v3(nor); a=dot_v3v3(p1,nor)-dot_v3v3(v0,nor); nordotv=dot_v3v3(nor,vel); if (fabsf(nordotv) < 0.000001f) { - if(fabsf(a) >= radius) { + if (fabsf(a) >= radius) { return 0; } } @@ -955,10 +958,10 @@ int isect_sweeping_sphere_tri_v3( float t0=(-a+radius)/nordotv; float t1=(-a-radius)/nordotv; - if(t0>t1) + if (t0>t1) SWAP(float, t0, t1); - if(t0>1.0f || t1<0.0f) return 0; + if (t0>1.0f || t1<0.0f) return 0; /* clamp to [0,1] */ CLAMP(t0, 0.0f, 1.0f); @@ -1005,7 +1008,7 @@ int isect_sweeping_sphere_tri_v3( b=2.0f*dot_v3v3(vel,temp); c=dot_v3v3(temp,temp)-radius2; - if(getLowestRoot(a, b, c, *r_lambda, r_lambda)) { + if (getLowestRoot(a, b, c, *r_lambda, r_lambda)) { copy_v3_v3(ipoint,v0); found_by_sweep=1; } @@ -1025,7 +1028,7 @@ int isect_sweeping_sphere_tri_v3( b=2.0f*dot_v3v3(vel,temp); c=dot_v3v3(temp,temp)-radius2; - if(getLowestRoot(a, b, c, *r_lambda, r_lambda)) { + if (getLowestRoot(a, b, c, *r_lambda, r_lambda)) { copy_v3_v3(ipoint,v2); found_by_sweep=1; } @@ -1137,9 +1140,9 @@ int isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3] if ((v < 0.0f)||(v > 1.0f)) return 0; f= e1[a1]; - if((f > -0.000001f) && (f < 0.000001f)) { + if ((f > -0.000001f) && (f < 0.000001f)) { f= e1[a2]; - if((f > -0.000001f) && (f < 0.000001f)) return 0; + if ((f > -0.000001f) && (f < 0.000001f)) return 0; u= (-p[a2]-v*e2[a2])/f; } else @@ -1366,7 +1369,8 @@ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2 /*w1 = w1/wtot;*/ /*w2 = w2/wtot;*/ r_uv[0] = w1/wtot; - } else { + } + else { /* lines are parallel, lambda_cp_line_ex is 3d grrr */ /*printf("\tparallel1\n");*/ pt3d[0] = pt[0]; @@ -1406,7 +1410,8 @@ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2 w2 = len_v2(v2d); wtot = w1+w2; r_uv[1] = w1/wtot; - } else { + } + else { /* lines are parallel, lambda_cp_line_ex is 3d grrr */ /*printf("\tparallel2\n");*/ pt3d[0] = pt[0]; @@ -1474,8 +1479,8 @@ int isect_point_tri_v2(float pt[2], float v1[2], float v2[2], float v3[2]) inp2= (v3[0]-v2[0])*(v2[1]-pt[1]) + (v2[1]-v3[1])*(v2[0]-pt[0]); inp3= (v1[0]-v3[0])*(v3[1]-pt[1]) + (v3[1]-v1[1])*(v3[0]-pt[0]); - if(inp1<=0.0f && inp2<=0.0f && inp3<=0.0f) return 1; - if(inp1>=0.0f && inp2>=0.0f && inp3>=0.0f) return 1; + if (inp1<=0.0f && inp2<=0.0f && inp3<=0.0f) return 1; + if (inp1>=0.0f && inp2>=0.0f && inp3>=0.0f) return 1; return 0; } @@ -1587,9 +1592,9 @@ static int point_in_slice_m(float p[3],float origin[3],float normal[3],float lns int isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3]) { - if(!point_in_slice(p,v1,v2,v3)) return 0; - if(!point_in_slice(p,v2,v3,v1)) return 0; - if(!point_in_slice(p,v3,v1,v2)) return 0; + if (!point_in_slice(p,v1,v2,v3)) return 0; + if (!point_in_slice(p,v2,v3,v1)) return 0; + if (!point_in_slice(p,v3,v1,v2)) return 0; return 1; } @@ -1601,21 +1606,21 @@ int clip_line_plane(float p1[3], float p2[3], const float plane[4]) sub_v3_v3v3(dp, p2, p1); div= dot_v3v3(dp, n); - if(div == 0.0f) /* parallel */ + if (div == 0.0f) /* parallel */ return 1; t= -(dot_v3v3(p1, n) + plane[3])/div; - if(div > 0.0f) { + if (div > 0.0f) { /* behind plane, completely clipped */ - if(t >= 1.0f) { + if (t >= 1.0f) { zero_v3(p1); zero_v3(p2); return 0; } /* intersect plane */ - if(t > 0.0f) { + if (t > 0.0f) { madd_v3_v3v3fl(pc, p1, dp, t); copy_v3_v3(p1, pc); return 1; @@ -1625,14 +1630,14 @@ int clip_line_plane(float p1[3], float p2[3], const float plane[4]) } else { /* behind plane, completely clipped */ - if(t <= 0.0f) { + if (t <= 0.0f) { zero_v3(p1); zero_v3(p2); return 0; } /* intersect plane */ - if(t < 1.0f) { + if (t < 1.0f) { madd_v3_v3v3fl(pc, p1, dp, t); copy_v3_v3(p2, pc); return 1; @@ -1657,7 +1662,7 @@ void plot_line_v2v2i(const int p1[2], const int p2[2], int (*callback)(int, int, int delta_x = (x2 > x1?(ix = 1, x2 - x1):(ix = -1, x1 - x2)) << 1; int delta_y = (y2 > y1?(iy = 1, y2 - y1):(iy = -1, y1 - y2)) << 1; - if(callback(x1, y1, userData) == 0) { + if (callback(x1, y1, userData) == 0) { return; } @@ -1700,7 +1705,7 @@ void plot_line_v2v2i(const int p1[2], const int p2[2], int (*callback)(int, int, y1 += iy; error += delta_x; - if(callback(x1, y1, userData) == 0) { + if (callback(x1, y1, userData) == 0) { return; } } @@ -1758,13 +1763,13 @@ void interp_weights_face_v3(float w[4], const float v1[3], const float v2[3], co w[0]= w[1]= w[2]= w[3]= 0.0f; /* first check for exact match */ - if(equals_v3v3(co, v1)) + if (equals_v3v3(co, v1)) w[0]= 1.0f; - else if(equals_v3v3(co, v2)) + else if (equals_v3v3(co, v2)) w[1]= 1.0f; - else if(equals_v3v3(co, v3)) + else if (equals_v3v3(co, v3)) w[2]= 1.0f; - else if(v4 && equals_v3v3(co, v4)) + else if (v4 && equals_v3v3(co, v4)) w[3]= 1.0f; else { /* otherwise compute barycentric interpolation weights */ @@ -1785,12 +1790,12 @@ void interp_weights_face_v3(float w[4], const float v1[3], const float v2[3], co degenerate= barycentric_weights(v1, v2, v4, co, n, w); SWAP(float, w[2], w[3]); - if(degenerate || (w[0] < 0.0f)) { + if (degenerate || (w[0] < 0.0f)) { /* if w[1] is negative, co is on the other side of the v1-v3 edge, * so we interpolate using the other triangle */ degenerate= barycentric_weights(v2, v3, v4, co, n, w2); - if(!degenerate) { + if (!degenerate) { w[0]= 0.0f; w[1]= w2[0]; w[2]= w2[1]; @@ -1879,13 +1884,13 @@ int interp_sparse_array(float *array, int const list_size, const float skipval) int i; for (i=0; i < list_size; i++) { - if(array[i] == skipval) + if (array[i] == skipval) found_invalid= 1; else found_valid= 1; } - if(found_valid==0) { + if (found_valid==0) { return -1; } else if (found_invalid==0) { @@ -1903,7 +1908,7 @@ int interp_sparse_array(float *array, int const list_size, const float skipval) int *ofs_tot_down= MEM_callocN(sizeof(int) * list_size, "interp_sparse_array tdown"); for (i=0; i < list_size; i++) { - if(array[i] == skipval) { + if (array[i] == skipval) { array_up[i]= valid_last; ofs_tot_up[i]= ++valid_ofs; } @@ -1917,7 +1922,7 @@ int interp_sparse_array(float *array, int const list_size, const float skipval) valid_ofs= 0; for (i=list_size-1; i >= 0; i--) { - if(array[i] == skipval) { + if (array[i] == skipval) { array_down[i]= valid_last; ofs_tot_down[i]= ++valid_ofs; } @@ -1929,12 +1934,14 @@ int interp_sparse_array(float *array, int const list_size, const float skipval) /* now blend */ for (i=0; i < list_size; i++) { - if(array[i] == skipval) { - if(array_up[i] != skipval && array_down[i] != skipval) { + if (array[i] == skipval) { + if (array_up[i] != skipval && array_down[i] != skipval) { array[i]= ((array_up[i] * ofs_tot_down[i]) + (array_down[i] * ofs_tot_up[i])) / (float)(ofs_tot_down[i] + ofs_tot_up[i]); - } else if (array_up[i] != skipval) { + } + else if (array_up[i] != skipval) { array[i]= array_up[i]; - } else if (array_down[i] != skipval) { + } + else if (array_down[i] != skipval) { array[i]= array_down[i]; } } @@ -1964,7 +1971,7 @@ static float mean_value_half_tan(const float v1[3], const float v2[3], const flo dot= dot_v3v3(d2, d3); len= len_v3(d2)*len_v3(d3); - if(area == 0.0f) + if (area == 0.0f) return 0.0f; else return (len - dot)/area; @@ -1977,7 +1984,7 @@ void interp_weights_poly_v3(float *w, float v[][3], const int n, const float co[ totweight= 0.0f; - for(i=0; i0 ? (-1.0) : 1.0; @@ -2082,12 +2091,12 @@ void resolve_quad_uv(float r_uv[2], const float st[2], const float st0[2], const const double denom_t= (1-r_uv[0])*(st0[1]-st3[1]) + r_uv[0]*(st1[1]-st2[1]); int i= 0; double denom= denom_s; - if(fabs(denom_s) bounds[1]*vec[3]) fl |= 1; - if(vec[0]< bounds[0]*vec[3]) fl |= 2; - if(vec[1] > bounds[3]*vec[3]) fl |= 4; - if(vec[1]< bounds[2]*vec[3]) fl |= 8; + if (bounds) { + if (vec[0] > bounds[1]*vec[3]) fl |= 1; + if (vec[0]< bounds[0]*vec[3]) fl |= 2; + if (vec[1] > bounds[3]*vec[3]) fl |= 4; + if (vec[1]< bounds[2]*vec[3]) fl |= 8; } else { - if(vec[0] < -vec[3]) fl |= 1; - if(vec[0] > vec[3]) fl |= 2; - if(vec[1] < -vec[3]) fl |= 4; - if(vec[1] > vec[3]) fl |= 8; + if (vec[0] < -vec[3]) fl |= 1; + if (vec[0] > vec[3]) fl |= 2; + if (vec[1] < -vec[3]) fl |= 4; + if (vec[1] > vec[3]) fl |= 8; } - if(vec[2] < -vec[3]) fl |= 16; - if(vec[2] > vec[3]) fl |= 32; + if (vec[2] < -vec[3]) fl |= 16; + if (vec[2] > vec[3]) fl |= 32; flag &= fl; - if(flag==0) return 0; + if (flag==0) return 0; } return flag; @@ -2289,7 +2300,7 @@ void box_minmax_bounds_m4(float min[3], float max[3], float boundbox[2][3], floa copy_v3_v3(mn, min); copy_v3_v3(mx, max); - for(a=0; a<8; a++) { + for (a=0; a<8; a++) { vec[0]= (a & 1)? boundbox[0][0]: boundbox[1][0]; vec[1]= (a & 2)? boundbox[0][1]: boundbox[1][1]; vec[2]= (a & 4)? boundbox[0][2]: boundbox[1][2]; @@ -2311,7 +2322,7 @@ void map_to_tube(float *r_u, float *r_v, const float x, const float y, const flo *r_v = (z + 1.0f) / 2.0f; len = sqrtf(x * x + y * y); - if(len > 0.0f) { + if (len > 0.0f) { *r_u = (float)((1.0 - (atan2(x/len,y/len) / M_PI)) / 2.0); } else { @@ -2324,8 +2335,8 @@ void map_to_sphere(float *r_u, float *r_v, const float x, const float y, const f float len; len = sqrtf(x * x + y * y + z * z); - if(len > 0.0f) { - if(x==0.0f && y==0.0f) *r_u= 0.0f; /* othwise domain error */ + if (len > 0.0f) { + if (x==0.0f && y==0.0f) *r_u= 0.0f; /* othwise domain error */ else *r_u = (1.0f - atan2f(x,y) / (float)M_PI) / 2.0f; *r_v = 1.0f - (float)saacos(z/len)/(float)M_PI; @@ -2348,7 +2359,7 @@ void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3], sub_v3_v3v3(vdiffs[0], co2, co1); sub_v3_v3v3(vdiffs[1], co3, co2); - if(nverts==3) { + if (nverts==3) { sub_v3_v3v3(vdiffs[2], co1, co3); } else { @@ -2367,7 +2378,7 @@ void accumulate_vertex_normals(float n1[3], float n2[3], float n3[3], const float *prev_edge = vdiffs[nverts-1]; int i; - for(i=0; inext) { - if(fabsf(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabsf(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) { + for (vt= *vtang; vt; vt=vt->next) { + if (fabsf(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabsf(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) { add_v3_v3(vt->tang, tang); return; } @@ -2439,7 +2450,7 @@ void sum_or_add_vertex_tangent(void *arena, VertexTangent **vtang, const float t vt->uv[0]= uv[0]; vt->uv[1]= uv[1]; - if(*vtang) + if (*vtang) vt->next= *vtang; *vtang= vt; } @@ -2449,8 +2460,8 @@ float *find_vertex_tangent(VertexTangent *vtang, const float uv[2]) VertexTangent *vt; static float nulltang[3] = {0.0f, 0.0f, 0.0f}; - for(vt= vtang; vt; vt=vt->next) - if(fabsf(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabsf(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) + for (vt= vtang; vt; vt=vt->next) + if (fabsf(uv[0]-vt->uv[0]) < STD_UV_CONNECT_LIMIT && fabsf(uv[1]-vt->uv[1]) < STD_UV_CONNECT_LIMIT) return vt->tang; return nulltang; /* shouldn't happen, except for nan or so */ @@ -2464,7 +2475,7 @@ void tangent_from_uv(float uv1[2], float uv2[2], float uv3[3], float co1[3], flo float t2= uv3[1] - uv1[1]; float det= (s1 * t2 - s2 * t1); - if(det != 0.0f) { /* otherwise 'tang' becomes nan */ + if (det != 0.0f) { /* otherwise 'tang' becomes nan */ float tangv[3], ct[3], e1[3], e2[3]; det= 1.0f/det; @@ -2543,7 +2554,7 @@ void vcloud_estimate_transform(int list_size, float (*pos)[3], float *weight,flo /* do com for both clouds */ if (pos && rpos && (list_size > 0)) { /* paranoya check */ /* do com for both clouds */ - for(a=0; amass); mass needs renormalzation here ?? */ sub_v3_v3v3(vb,pos[a],accu_com); @@ -2623,7 +2634,7 @@ void vcloud_estimate_transform(int list_size, float (*pos)[3], float *weight,flo /* without the far case ... but seems to work here pretty neat */ odet = 0.f; ndet = _det_m3(q); - while((odet-ndet)*(odet-ndet) > eps && i eps && i 0) { - if(sd[1] > 0) { - if(sd[2] > 0) { + if (sd[0] > 0) { + if (sd[1] > 0) { + if (sd[2] > 0) { // +++ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // ++- copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -2697,15 +2708,15 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] copy_v3_v3(q3, q2); } } - else if(sd[1] < 0) { - if(sd[2] > 0) { + else if (sd[1] < 0) { + if (sd[2] > 0) { // +-+ copy_v3_v3(q0, v0); vec_add_dir(q1, v0, v1, (sd[0]/(sd[0]-sd[1]))); vec_add_dir(q2, v1, v2, (sd[1]/(sd[1]-sd[2]))); copy_v3_v3(q3, v2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // +-- copy_v3_v3(q0, v0); vec_add_dir(q1, v0, v1, (sd[0]/(sd[0]-sd[1]))); @@ -2721,14 +2732,14 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] } } else { - if(sd[2] > 0) { + if (sd[2] > 0) { // +0+ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // +0- copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -2744,16 +2755,16 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] } } } - else if(sd[0] < 0) { - if(sd[1] > 0) { - if(sd[2] > 0) { + else if (sd[0] < 0) { + if (sd[1] > 0) { + if (sd[2] > 0) { // -++ vec_add_dir(q0, v0, v1, (sd[0]/(sd[0]-sd[1]))); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); vec_add_dir(q3, v0, v2, (sd[0]/(sd[0]-sd[2]))); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // -+- vec_add_dir(q0, v0, v1, (sd[0]/(sd[0]-sd[1]))); copy_v3_v3(q1, v1); @@ -2768,15 +2779,15 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] copy_v3_v3(q3, q2); } } - else if(sd[1] < 0) { - if(sd[2] > 0) { + else if (sd[1] < 0) { + if (sd[2] > 0) { // --+ vec_add_dir(q0, v0, v2, (sd[0]/(sd[0]-sd[2]))); vec_add_dir(q1, v1, v2, (sd[1]/(sd[1]-sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // --- return 0; } @@ -2786,14 +2797,14 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] } } else { - if(sd[2] > 0) { + if (sd[2] > 0) { // -0+ vec_add_dir(q0, v0, v2, (sd[0]/(sd[0]-sd[2]))); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // -0- return 0; } @@ -2804,15 +2815,15 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] } } else { - if(sd[1] > 0) { - if(sd[2] > 0) { + if (sd[1] > 0) { + if (sd[2] > 0) { // 0++ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // 0+- copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); @@ -2827,15 +2838,15 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] copy_v3_v3(q3, q2); } } - else if(sd[1] < 0) { - if(sd[2] > 0) { + else if (sd[1] < 0) { + if (sd[2] > 0) { // 0-+ copy_v3_v3(q0, v0); vec_add_dir(q1, v1, v2, (sd[1]/(sd[1]-sd[2]))); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // 0-- return 0; } @@ -2845,14 +2856,14 @@ static int ff_visible_quad(const float p[3], const float n[3], const float v0[3] } } else { - if(sd[2] > 0) { + if (sd[2] > 0) { // 00+ copy_v3_v3(q0, v0); copy_v3_v3(q1, v1); copy_v3_v3(q2, v2); copy_v3_v3(q3, q2); } - else if(sd[2] < 0) { + else if (sd[2] < 0) { // 00- return 0; } @@ -3007,7 +3018,7 @@ static void ff_normalize(float n[3]) d= dot_v3v3(n, n); - if(d > 1.0e-35F) { + if (d > 1.0e-35F) { d= 1.0f/sqrtf(d); n[0] *= d; @@ -3058,10 +3069,10 @@ float form_factor_hemi_poly(float p[3], float n[3], float v1[3], float v2[3], fl * covered by a quad or triangle, cosine weighted */ float q0[3], q1[3], q2[3], q3[3], contrib= 0.0f; - if(ff_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3)) + if (ff_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3)) contrib += ff_quad_form_factor(p, n, q0, q1, q2, q3); - if(v4 && ff_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3)) + if (v4 && ff_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3)) contrib += ff_quad_form_factor(p, n, q0, q1, q2, q3); return contrib; diff --git a/source/blender/blenlib/intern/math_geom_inline.c b/source/blender/blenlib/intern/math_geom_inline.c index 9031d52cf4c..634e68d0ccf 100644 --- a/source/blender/blenlib/intern/math_geom_inline.c +++ b/source/blender/blenlib/intern/math_geom_inline.c @@ -49,7 +49,7 @@ MINLINE void mul_sh_fl(float r[9], const float f) { int i; - for(i=0; i<9; i++) + for (i=0; i<9; i++) r[i] *= f; } @@ -57,7 +57,7 @@ MINLINE void add_sh_shsh(float r[9], const float a[9], const float b[9]) { int i; - for(i=0; i<9; i++) + for (i=0; i<9; i++) r[i]= a[i] + b[i]; } @@ -66,7 +66,7 @@ MINLINE float dot_shsh(float a[9], float b[9]) float r= 0.0f; int i; - for(i=0; i<9; i++) + for (i=0; i<9; i++) r += a[i]*b[i]; return r; diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index b777b394005..b32c5b833ae 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -117,7 +117,7 @@ void swap_m3m3(float m1[][3], float m2[][3]) float t; int i, j; - for(i = 0; i < 3; i++) { + for (i = 0; i < 3; i++) { for (j = 0; j < 3; j++) { t = m1[i][j]; m1[i][j] = m2[i][j]; @@ -131,7 +131,7 @@ void swap_m4m4(float m1[][4], float m2[][4]) float t; int i, j; - for(i = 0; i < 4; i++) { + for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { t = m1[i][j]; m1[i][j] = m2[i][j]; @@ -251,20 +251,20 @@ void mul_serie_m3(float answ[][3], { float temp[3][3]; - if(m1==NULL || m2==NULL) return; + if (m1==NULL || m2==NULL) return; mul_m3_m3m3(answ, m2, m1); - if(m3) { + if (m3) { mul_m3_m3m3(temp, m3, answ); - if(m4) { + if (m4) { mul_m3_m3m3(answ, m4, temp); - if(m5) { + if (m5) { mul_m3_m3m3(temp, m5, answ); - if(m6) { + if (m6) { mul_m3_m3m3(answ, m6, temp); - if(m7) { + if (m7) { mul_m3_m3m3(temp, m7, answ); - if(m8) { + if (m8) { mul_m3_m3m3(answ, m8, temp); } else copy_m3_m3(answ, temp); @@ -284,20 +284,20 @@ void mul_serie_m4(float answ[][4], float m1[][4], { float temp[4][4]; - if(m1==NULL || m2==NULL) return; + if (m1==NULL || m2==NULL) return; mult_m4_m4m4(answ, m1, m2); - if(m3) { + if (m3) { mult_m4_m4m4(temp, answ, m3); - if(m4) { + if (m4) { mult_m4_m4m4(answ, temp, m4); - if(m5) { + if (m5) { mult_m4_m4m4(temp, answ, m5); - if(m6) { + if (m6) { mult_m4_m4m4(answ, temp, m6); - if(m7) { + if (m7) { mult_m4_m4m4(temp, answ, m7); - if(m8) { + if (m8) { mult_m4_m4m4(answ, temp, m8); } else copy_m4_m4(answ, temp); @@ -422,8 +422,8 @@ void mul_m3_fl(float m[3][3], float f) { int i, j; - for(i=0;i<3;i++) - for(j=0;j<3;j++) + for (i=0;i<3;i++) + for (j=0;j<3;j++) m[i][j] *= f; } @@ -431,8 +431,8 @@ void mul_m4_fl(float m[4][4], float f) { int i, j; - for(i=0;i<4;i++) - for(j=0;j<4;j++) + for (i=0;i<4;i++) + for (j=0;j<4;j++) m[i][j] *= f; } @@ -440,8 +440,8 @@ void mul_mat3_m4_fl(float m[4][4], float f) { int i, j; - for(i=0; i<3; i++) - for(j=0; j<3; j++) + for (i=0; i<3; i++) + for (j=0; j<3; j++) m[i][j] *= f; } @@ -460,8 +460,8 @@ void add_m3_m3m3(float m1[][3], float m2[][3], float m3[][3]) { int i, j; - for(i=0;i<3;i++) - for(j=0;j<3;j++) + for (i=0;i<3;i++) + for (j=0;j<3;j++) m1[i][j]= m2[i][j] + m3[i][j]; } @@ -469,8 +469,8 @@ void add_m4_m4m4(float m1[][4], float m2[][4], float m3[][4]) { int i, j; - for(i=0;i<4;i++) - for(j=0;j<4;j++) + for (i=0;i<4;i++) + for (j=0;j<4;j++) m1[i][j]= m2[i][j] + m3[i][j]; } @@ -478,8 +478,8 @@ void sub_m3_m3m3(float m1[][3], float m2[][3], float m3[][3]) { int i, j; - for(i=0;i<3;i++) - for(j=0;j<3;j++) + for (i=0;i<3;i++) + for (j=0;j<3;j++) m1[i][j]= m2[i][j] - m3[i][j]; } @@ -487,8 +487,8 @@ void sub_m4_m4m4(float m1[][4], float m2[][4], float m3[][4]) { int i, j; - for(i=0;i<4;i++) - for(j=0;j<4;j++) + for (i=0;i<4;i++) + for (j=0;j<4;j++) m1[i][j]= m2[i][j] - m3[i][j]; } @@ -518,10 +518,10 @@ int invert_m3_m3(float m1[3][3], float m2[3][3]) success= (det != 0); - if(det==0) det=1; + if (det==0) det=1; det= 1/det; - for(a=0;a<3;a++) { - for(b=0;b<3;b++) { + for (a=0;a<3;a++) { + for (b=0;b<3;b++) { m1[a][b]*=det; } } @@ -565,23 +565,23 @@ int invert_m4_m4(float inverse[4][4], float mat[4][4]) inverse[i][i] = 1; /* Copy original matrix so we don't mess it up */ - for(i = 0; i < 4; i++) - for(j = 0; j <4; j++) + for (i = 0; i < 4; i++) + for (j = 0; j <4; j++) tempmat[i][j] = mat[i][j]; - for(i = 0; i < 4; i++) { + for (i = 0; i < 4; i++) { /* Look for row with max pivot */ max = fabs(tempmat[i][i]); maxj = i; - for(j = i + 1; j < 4; j++) { - if(fabsf(tempmat[j][i]) > max) { + for (j = i + 1; j < 4; j++) { + if (fabsf(tempmat[j][i]) > max) { max = fabs(tempmat[j][i]); maxj = j; } } /* Swap rows if necessary */ if (maxj != i) { - for(k = 0; k < 4; k++) { + for (k = 0; k < 4; k++) { SWAP(float, tempmat[i][k], tempmat[maxj][k]); SWAP(float, inverse[i][k], inverse[maxj][k]); } @@ -590,14 +590,14 @@ int invert_m4_m4(float inverse[4][4], float mat[4][4]) temp = tempmat[i][i]; if (temp == 0) return 0; /* No non-zero pivot */ - for(k = 0; k < 4; k++) { + for (k = 0; k < 4; k++) { tempmat[i][k] = (float)(tempmat[i][k]/temp); inverse[i][k] = (float)(inverse[i][k]/temp); } - for(j = 0; j < 4; j++) { - if(j != i) { + for (j = 0; j < 4; j++) { + if (j != i) { temp = tempmat[j][i]; - for(k = 0; k < 4; k++) { + for (k = 0; k < 4; k++) { tempmat[j][k] -= (float)(tempmat[i][k]*temp); inverse[j][k] -= (float)(inverse[i][k]*temp); } @@ -662,11 +662,13 @@ void orthogonalize_m3(float mat[][3], int axis) cross_v3_v3v3(mat[2], mat[0], mat[1]); normalize_v3(mat[2]); cross_v3_v3v3(mat[1], mat[2], mat[0]); - } else if (dot_v3v3(mat[0], mat[2]) < 1) { + } + else if (dot_v3v3(mat[0], mat[2]) < 1) { cross_v3_v3v3(mat[1], mat[2], mat[0]); normalize_v3(mat[1]); cross_v3_v3v3(mat[2], mat[0], mat[1]); - } else { + } + else { float vec[3]; vec[0]= mat[0][1]; @@ -682,11 +684,13 @@ void orthogonalize_m3(float mat[][3], int axis) cross_v3_v3v3(mat[2], mat[0], mat[1]); normalize_v3(mat[2]); cross_v3_v3v3(mat[0], mat[1], mat[2]); - } else if (dot_v3v3(mat[0], mat[2]) < 1) { + } + else if (dot_v3v3(mat[0], mat[2]) < 1) { cross_v3_v3v3(mat[0], mat[1], mat[2]); normalize_v3(mat[0]); cross_v3_v3v3(mat[2], mat[0], mat[1]); - } else { + } + else { float vec[3]; vec[0]= mat[1][1]; @@ -702,11 +706,13 @@ void orthogonalize_m3(float mat[][3], int axis) cross_v3_v3v3(mat[1], mat[2], mat[0]); normalize_v3(mat[1]); cross_v3_v3v3(mat[0], mat[1], mat[2]); - } else if (dot_v3v3(mat[2], mat[1]) < 1) { + } + else if (dot_v3v3(mat[2], mat[1]) < 1) { cross_v3_v3v3(mat[0], mat[1], mat[2]); normalize_v3(mat[0]); cross_v3_v3v3(mat[1], mat[2], mat[0]); - } else { + } + else { float vec[3]; vec[0]= mat[2][1]; @@ -735,11 +741,13 @@ void orthogonalize_m4(float mat[][4], int axis) cross_v3_v3v3(mat[2], mat[0], mat[1]); normalize_v3(mat[2]); cross_v3_v3v3(mat[1], mat[2], mat[0]); - } else if (dot_v3v3(mat[0], mat[2]) < 1) { + } + else if (dot_v3v3(mat[0], mat[2]) < 1) { cross_v3_v3v3(mat[1], mat[2], mat[0]); normalize_v3(mat[1]); cross_v3_v3v3(mat[2], mat[0], mat[1]); - } else { + } + else { float vec[3]; vec[0]= mat[0][1]; @@ -756,11 +764,13 @@ void orthogonalize_m4(float mat[][4], int axis) cross_v3_v3v3(mat[2], mat[0], mat[1]); normalize_v3(mat[2]); cross_v3_v3v3(mat[0], mat[1], mat[2]); - } else if (dot_v3v3(mat[0], mat[2]) < 1) { + } + else if (dot_v3v3(mat[0], mat[2]) < 1) { cross_v3_v3v3(mat[0], mat[1], mat[2]); normalize_v3(mat[0]); cross_v3_v3v3(mat[2], mat[0], mat[1]); - } else { + } + else { float vec[3]; vec[0]= mat[1][1]; @@ -776,11 +786,13 @@ void orthogonalize_m4(float mat[][4], int axis) cross_v3_v3v3(mat[1], mat[2], mat[0]); normalize_v3(mat[1]); cross_v3_v3v3(mat[0], mat[1], mat[2]); - } else if (dot_v3v3(mat[2], mat[1]) < 1) { + } + else if (dot_v3v3(mat[2], mat[1]) < 1) { cross_v3_v3v3(mat[0], mat[1], mat[2]); normalize_v3(mat[0]); cross_v3_v3v3(mat[1], mat[2], mat[0]); - } else { + } + else { float vec[3]; vec[0]= mat[2][1]; @@ -851,11 +863,11 @@ void normalize_m4(float mat[][4]) float len; len= normalize_v3(mat[0]); - if(len!=0.0f) mat[0][3]/= len; + if (len!=0.0f) mat[0][3]/= len; len= normalize_v3(mat[1]); - if(len!=0.0f) mat[1][3]/= len; + if (len!=0.0f) mat[1][3]/= len; len= normalize_v3(mat[2]); - if(len!=0.0f) mat[2][3]/= len; + if (len!=0.0f) mat[2][3]/= len; } void normalize_m4_m4(float rmat[][4], float mat[][4]) @@ -863,11 +875,11 @@ void normalize_m4_m4(float rmat[][4], float mat[][4]) float len; len= normalize_v3_v3(rmat[0], mat[0]); - if(len!=0.0f) rmat[0][3]= mat[0][3] / len; + if (len!=0.0f) rmat[0][3]= mat[0][3] / len; len= normalize_v3_v3(rmat[1], mat[1]); - if(len!=0.0f) rmat[1][3]= mat[1][3] / len; + if (len!=0.0f) rmat[1][3]= mat[1][3] / len; len= normalize_v3_v3(rmat[2], mat[2]); - if(len!=0.0f) rmat[2][3]= mat[2][3] / len; + if (len!=0.0f) rmat[2][3]= mat[2][3] / len; } void adjoint_m3_m3(float m1[][3], float m[][3]) @@ -1052,7 +1064,7 @@ void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]) /* so scale doesnt interfear with rotation [#24291] */ /* note: this is a workaround for negative matrix not working for rotation conversion, FIXME */ normalize_m3_m3(mat3_n, mat3); - if(is_negative_m3(mat3)) { + if (is_negative_m3(mat3)) { negate_v3(mat3_n[0]); negate_v3(mat3_n[1]); negate_v3(mat3_n[2]); @@ -1120,27 +1132,27 @@ void rotate_m4(float mat[][4], const char axis, const float angle) sine = (float)sin(angle); switch (axis) { case 'X': - for(col=0 ; col<4 ; col++) + for (col=0 ; col<4 ; col++) temp[col] = cosine*mat[1][col] + sine*mat[2][col]; - for(col=0 ; col<4 ; col++) { + for (col=0 ; col<4 ; col++) { mat[2][col] = - sine*mat[1][col] + cosine*mat[2][col]; mat[1][col] = temp[col]; } break; case 'Y': - for(col=0 ; col<4 ; col++) + for (col=0 ; col<4 ; col++) temp[col] = cosine*mat[0][col] - sine*mat[2][col]; - for(col=0 ; col<4 ; col++) { + for (col=0 ; col<4 ; col++) { mat[2][col] = sine*mat[0][col] + cosine*mat[2][col]; mat[0][col] = temp[col]; } break; case 'Z': - for(col=0 ; col<4 ; col++) + for (col=0 ; col<4 ; col++) temp[col] = cosine*mat[0][col] + sine*mat[1][col]; - for(col=0 ; col<4 ; col++) { + for (col=0 ; col<4 ; col++) { mat[1][col] = - sine*mat[0][col] + cosine*mat[1][col]; mat[0][col] = temp[col]; } @@ -1485,7 +1497,8 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) for (i = 0; i < k-1; i++) { U[i][k] = 0.0f; } - } else { + } + else { for (i = 0; i < m; i++) { U[i][k] = 0.0f; } @@ -1523,7 +1536,7 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) int kase=0; // Test for maximum iterations to avoid infinite loop - if(maxiter == 0) + if (maxiter == 0) break; maxiter--; @@ -1548,7 +1561,8 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) } if (k == p-2) { kase = 4; - } else { + } + else { int ks; for (ks = p-1; ks >= k; ks--) { float t; @@ -1564,9 +1578,11 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4]) } if (ks == k) { kase = 3; - } else if (ks == p-1) { + } + else if (ks == p-1) { kase = 1; - } else { + } + else { kase = 2; k = ks; } @@ -1753,7 +1769,7 @@ void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon) transpose_m4(V); zero_m4(Wm); - for(i=0; i<4; i++) + for (i=0; i<4; i++) Wm[i][i]= (W[i] < epsilon)? 0.0f: 1.0f/W[i]; transpose_m4(V); diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 4e85d033cf7..5ae226bf6d5 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -198,7 +198,7 @@ void quat_to_mat3(float m[][3], const float q[4]) { #ifdef DEBUG float f; - if(!((f=dot_qtqt(q, q))==0.0f || (fabsf(f-1.0f) < (float)QUAT_EPSILON))) { + if (!((f=dot_qtqt(q, q))==0.0f || (fabsf(f-1.0f) < (float)QUAT_EPSILON))) { fprintf(stderr, "Warning! quat_to_mat3() called with non-normalized: size %.8f *** report a bug ***\n", f); } #endif @@ -211,7 +211,7 @@ void quat_to_mat4(float m[][4], const float q[4]) double q0, q1, q2, q3, qda,qdb,qdc,qaa,qab,qac,qbb,qbc,qcc; #ifdef DEBUG - if(!((q0=dot_qtqt(q, q))==0.0f || (fabsf(q0-1.0) < QUAT_EPSILON))) { + if (!((q0=dot_qtqt(q, q))==0.0f || (fabsf(q0-1.0) < QUAT_EPSILON))) { fprintf(stderr, "Warning! quat_to_mat4() called with non-normalized: size %.8f *** report a bug ***\n", (float)q0); } #endif @@ -261,7 +261,7 @@ void mat3_to_quat(float *q, float wmat[][3]) tr= 0.25* (double)(1.0f+mat[0][0]+mat[1][1]+mat[2][2]); - if(tr>(double)FLT_EPSILON) { + if (tr>(double)FLT_EPSILON) { s= sqrt(tr); q[0]= (float)s; s= 1.0/(4.0*s); @@ -270,7 +270,7 @@ void mat3_to_quat(float *q, float wmat[][3]) q[3]= (float)((mat[0][1]-mat[1][0])*s); } else { - if(mat[0][0] > mat[1][1] && mat[0][0] > mat[2][2]) { + if (mat[0][0] > mat[1][1] && mat[0][0] > mat[2][2]) { s= 2.0f*sqrtf(1.0f + mat[0][0] - mat[1][1] - mat[2][2]); q[1]= (float)(0.25*s); @@ -279,7 +279,7 @@ void mat3_to_quat(float *q, float wmat[][3]) q[2]= (float)((double)(mat[1][0] + mat[0][1])*s); q[3]= (float)((double)(mat[2][0] + mat[0][2])*s); } - else if(mat[1][1] > mat[2][2]) { + else if (mat[1][1] > mat[2][2]) { s= 2.0f*sqrtf(1.0f + mat[1][1] - mat[0][0] - mat[2][2]); q[2]= (float)(0.25*s); @@ -359,7 +359,7 @@ float normalize_qt(float *q) float len; len= (float)sqrt(dot_qtqt(q, q)); - if(len!=0.0f) { + if (len!=0.0f) { mul_qt_fl(q, 1.0f/len); } else { @@ -399,7 +399,7 @@ void rotation_between_quats_to_quat(float *q, const float q1[4], const float q2[ conjugate_qt(tquat); dot = 1.0f / dot_qtqt(tquat, tquat); - for(x = 0; x < 4; x++) + for (x = 0; x < 4; x++) tquat[x] *= dot; mul_qt_qtqt(q, tquat, q2); @@ -414,7 +414,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) assert(upflag >= 0 && upflag <= 2); /* first rotate to axis */ - if(axis>2) { + if (axis>2) { x2= vec[0] ; y2= vec[1] ; z2= vec[2]; axis-= 3; } @@ -426,28 +426,28 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) q[1]=q[2]=q[3]= 0.0; len1= (float)sqrt(x2*x2+y2*y2+z2*z2); - if(len1 == 0.0f) return; + if (len1 == 0.0f) return; /* nasty! I need a good routine for this... * problem is a rotation of an Y axis to the negative Y-axis for example. */ - if(axis==0) { /* x-axis */ + if (axis==0) { /* x-axis */ nor[0]= 0.0; nor[1]= -z2; nor[2]= y2; - if(fabs(y2)+fabs(z2)<0.0001) + if (fabs(y2)+fabs(z2)<0.0001) nor[1]= 1.0; co= x2; } - else if(axis==1) { /* y-axis */ + else if (axis==1) { /* y-axis */ nor[0]= z2; nor[1]= 0.0; nor[2]= -x2; - if(fabs(x2)+fabs(z2)<0.0001) + if (fabs(x2)+fabs(z2)<0.0001) nor[2]= 1.0; co= y2; @@ -457,7 +457,7 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) nor[1]= x2; nor[2]= 0.0; - if(fabs(x2)+fabs(y2)<0.0001) + if (fabs(x2)+fabs(y2)<0.0001) nor[0]= 1.0; co= z2; @@ -473,20 +473,20 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) q[2]= nor[1]*si; q[3]= nor[2]*si; - if(axis!=upflag) { + if (axis!=upflag) { quat_to_mat3(mat,q); fp= mat[2]; - if(axis==0) { - if(upflag==1) angle= (float)(0.5*atan2(fp[2], fp[1])); + if (axis==0) { + if (upflag==1) angle= (float)(0.5*atan2(fp[2], fp[1])); else angle= (float)(-0.5*atan2(fp[1], fp[2])); } - else if(axis==1) { - if(upflag==0) angle= (float)(-0.5*atan2(fp[2], fp[0])); + else if (axis==1) { + if (upflag==0) angle= (float)(-0.5*atan2(fp[2], fp[0])); else angle= (float)(0.5*atan2(fp[0], fp[2])); } else { - if(upflag==0) angle= (float)(0.5*atan2(-fp[1], -fp[0])); + if (upflag==0) angle= (float)(0.5*atan2(-fp[1], -fp[0])); else angle= (float)(-0.5*atan2(-fp[0], -fp[1])); } @@ -570,7 +570,8 @@ void interp_qt_qtqt(float result[4], const float quat1[4], const float quat2[4], sinom = (float)sin(omega); sc1 = (float)sin((1 - t) * omega) / sinom; sc2 = (float)sin(t * omega) / sinom; - } else { + } + else { sc1= 1.0f - t; sc2= t; } @@ -602,7 +603,7 @@ void tri_to_quat(float quat[4], const float v1[3], const float v2[3], const floa n[2]= 0.0f; normalize_v3(n); - if(n[0]==0.0f && n[1]==0.0f) n[0]= 1.0f; + if (n[0]==0.0f && n[1]==0.0f) n[0]= 1.0f; angle= -0.5f*(float)saacos(vec[2]); co= (float)cos(angle); @@ -646,7 +647,7 @@ void axis_angle_to_quat(float q[4], const float axis[3], float angle) float nor[3]; float si; - if(normalize_v3_v3(nor, axis) == 0.0f) { + if (normalize_v3_v3(nor, axis) == 0.0f) { unit_qt(q); return; } @@ -665,7 +666,7 @@ void quat_to_axis_angle(float axis[3], float *angle, const float q[4]) float ha, si; #ifdef DEBUG - if(!((ha=dot_qtqt(q, q))==0.0f || (fabsf(ha-1.0f) < (float)QUAT_EPSILON))) { + if (!((ha=dot_qtqt(q, q))==0.0f || (fabsf(ha-1.0f) < (float)QUAT_EPSILON))) { fprintf(stderr, "Warning! quat_to_axis_angle() called with non-normalized: size %.8f *** report a bug ***\n", ha); } #endif @@ -712,7 +713,7 @@ void axis_angle_to_mat3(float mat[3][3], const float axis[3], const float angle) float nor[3], nsi[3], co, si, ico; /* normalize the axis first (to remove unwanted scaling) */ - if(normalize_v3_v3(nor, axis) == 0.0f) { + if (normalize_v3_v3(nor, axis) == 0.0f) { unit_m3(mat); return; } @@ -864,7 +865,7 @@ void vec_rot_to_quat(float *quat, const float vec[3], const float phi) quat[2]= vec[1]; quat[3]= vec[2]; - if(normalize_v3(quat+1) == 0.0f) { + if (normalize_v3(quat+1) == 0.0f) { unit_qt(quat); } else { @@ -960,7 +961,8 @@ static void mat3_to_eul2(float tmat[][3], float eul1[3], float eul2[3]) eul2[1] = (float)atan2(-mat[0][2], -cy); eul2[2] = (float)atan2(-mat[0][1], -mat[0][0]); - } else { + } + else { eul1[0] = (float)atan2(-mat[2][1], mat[1][1]); eul1[1] = (float)atan2(-mat[0][2], cy); eul1[2] = 0.0f; @@ -977,7 +979,7 @@ void mat3_to_eul(float *eul,float tmat[][3]) mat3_to_eul2(tmat, eul1, eul2); /* return best, which is just the one with lowest values it in */ - if(fabs(eul1[0])+fabs(eul1[1])+fabs(eul1[2]) > fabs(eul2[0])+fabs(eul2[1])+fabs(eul2[2])) { + if (fabs(eul1[0])+fabs(eul1[1])+fabs(eul1[2]) > fabs(eul2[0])+fabs(eul2[1])+fabs(eul2[2])) { copy_v3_v3(eul, eul2); } else { @@ -1028,8 +1030,8 @@ void rotate_eul(float *beul, const char axis, const float ang) assert(axis >= 'X' && axis <= 'Z'); eul[0]= eul[1]= eul[2]= 0.0f; - if(axis=='X') eul[0]= ang; - else if(axis=='Y') eul[1]= ang; + if (axis=='X') eul[0]= ang; + else if (axis=='Y') eul[1]= ang; else eul[2]= ang; eul_to_mat3(mat1,eul); @@ -1052,28 +1054,28 @@ void compatible_eul(float eul[3], const float oldrot[3]) dy= eul[1] - oldrot[1]; dz= eul[2] - oldrot[2]; - while(fabs(dx) > 5.1) { - if(dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; + while (fabs(dx) > 5.1) { + if (dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; dx= eul[0] - oldrot[0]; } - while(fabs(dy) > 5.1) { - if(dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; + while (fabs(dy) > 5.1) { + if (dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; dy= eul[1] - oldrot[1]; } - while(fabs(dz) > 5.1) { - if(dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; + while (fabs(dz) > 5.1) { + if (dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; dz= eul[2] - oldrot[2]; } /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */ - if(fabs(dx) > 3.2 && fabs(dy)<1.6 && fabs(dz)<1.6) { - if(dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; + if (fabs(dx) > 3.2 && fabs(dy)<1.6 && fabs(dz)<1.6) { + if (dx > 0.0f) eul[0] -= 2.0f*(float)M_PI; else eul[0]+= 2.0f*(float)M_PI; } - if(fabs(dy) > 3.2 && fabs(dz)<1.6 && fabs(dx)<1.6) { - if(dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; + if (fabs(dy) > 3.2 && fabs(dz)<1.6 && fabs(dx)<1.6) { + if (dy > 0.0f) eul[1] -= 2.0f*(float)M_PI; else eul[1]+= 2.0f*(float)M_PI; } - if(fabs(dz) > 3.2 && fabs(dx)<1.6 && fabs(dy)<1.6) { - if(dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; + if (fabs(dz) > 3.2 && fabs(dx)<1.6 && fabs(dy)<1.6) { + if (dz > 0.0f) eul[2] -= 2.0f*(float)M_PI; else eul[2]+= 2.0f*(float)M_PI; } /* the method below was there from ancient days... but why! probably because the code sucks :) @@ -1086,21 +1088,21 @@ void compatible_eul(float eul[3], const float oldrot[3]) /* special case, tested for x-z */ - if((fabs(dx) > 3.1 && fabs(dz) > 1.5) || (fabs(dx) > 1.5 && fabs(dz) > 3.1)) { - if(dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; - if(eul[1] > 0.0) eul[1]= M_PI - eul[1]; else eul[1]= -M_PI - eul[1]; - if(dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; + if ((fabs(dx) > 3.1 && fabs(dz) > 1.5) || (fabs(dx) > 1.5 && fabs(dz) > 3.1)) { + if (dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; + if (eul[1] > 0.0) eul[1]= M_PI - eul[1]; else eul[1]= -M_PI - eul[1]; + if (dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; } - else if((fabs(dx) > 3.1 && fabs(dy) > 1.5) || (fabs(dx) > 1.5 && fabs(dy) > 3.1)) { - if(dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; - if(dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; - if(eul[2] > 0.0) eul[2]= M_PI - eul[2]; else eul[2]= -M_PI - eul[2]; + else if ((fabs(dx) > 3.1 && fabs(dy) > 1.5) || (fabs(dx) > 1.5 && fabs(dy) > 3.1)) { + if (dx > 0.0) eul[0] -= M_PI; else eul[0]+= M_PI; + if (dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; + if (eul[2] > 0.0) eul[2]= M_PI - eul[2]; else eul[2]= -M_PI - eul[2]; } - else if((fabs(dy) > 3.1 && fabs(dz) > 1.5) || (fabs(dy) > 1.5 && fabs(dz) > 3.1)) { - if(eul[0] > 0.0) eul[0]= M_PI - eul[0]; else eul[0]= -M_PI - eul[0]; - if(dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; - if(dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; + else if ((fabs(dy) > 3.1 && fabs(dz) > 1.5) || (fabs(dy) > 1.5 && fabs(dz) > 3.1)) { + if (eul[0] > 0.0) eul[0]= M_PI - eul[0]; else eul[0]= -M_PI - eul[0]; + if (dy > 0.0) eul[1] -= M_PI; else eul[1]+= M_PI; + if (dz > 0.0) eul[2] -= M_PI; else eul[2]+= M_PI; } #endif } @@ -1121,7 +1123,7 @@ void mat3_to_compatible_eul(float eul[3], const float oldrot[3], float mat[][3]) d2= (float)fabs(eul2[0]-oldrot[0]) + (float)fabs(eul2[1]-oldrot[1]) + (float)fabs(eul2[2]-oldrot[2]); /* return best, which is just the one with lowest difference */ - if(d1 > d2) { + if (d1 > d2) { copy_v3_v3(eul, eul2); } else { @@ -1292,7 +1294,7 @@ void mat3_to_eulO(float eul[3], const short order,float M[3][3]) mat3_to_eulo2(M, eul1, eul2, order); /* return best, which is just the one with lowest values it in */ - if(fabs(eul1[0])+fabs(eul1[1])+fabs(eul1[2]) > fabs(eul2[0])+fabs(eul2[1])+fabs(eul2[2])) { + if (fabs(eul1[0])+fabs(eul1[1])+fabs(eul1[2]) > fabs(eul2[0])+fabs(eul2[1])+fabs(eul2[2])) { copy_v3_v3(eul, eul2); } else { @@ -1439,7 +1441,7 @@ void mat4_to_dquat(DualQuat *dq,float basemat[][4], float mat[][4]) copy_v3_v3(dscale, scale); dscale[0] -= 1.0f; dscale[1] -= 1.0f; dscale[2] -= 1.0f; - if((determinant_m4(mat) < 0.0f) || len_v3(dscale) > 1e-4f) { + if ((determinant_m4(mat) < 0.0f) || len_v3(dscale) > 1e-4f) { /* extract R and S */ float tmp[4][4]; @@ -1488,7 +1490,7 @@ void dquat_to_mat4(float mat[][4], DualQuat *dq) /* normalize */ len= (float)sqrt(dot_qtqt(q0, q0)); - if(len != 0.0f) + if (len != 0.0f) mul_qt_fl(q0, 1.0f/len); /* rotation */ @@ -1528,7 +1530,7 @@ void add_weighted_dq_dq(DualQuat *dqsum, DualQuat *dq, float weight) if (dq->scale_weight) { float wmat[4][4]; - if(flipped) /* we don't want negative weights for scaling */ + if (flipped) /* we don't want negative weights for scaling */ weight= -weight; copy_m4_m4(wmat, dq->scale); @@ -1545,10 +1547,10 @@ void normalize_dq(DualQuat *dq, float totweight) mul_qt_fl(dq->quat, scale); mul_qt_fl(dq->trans, scale); - if(dq->scale_weight) { + if (dq->scale_weight) { float addweight= totweight - dq->scale_weight; - if(addweight) { + if (addweight) { dq->scale[0][0] += addweight; dq->scale[1][1] += addweight; dq->scale[2][2] += addweight; @@ -1580,7 +1582,7 @@ void mul_v3m3_dq(float *co, float mat[][3],DualQuat *dq) M[2][2]= w*w + z*z - x*x - y*y; len2= dot_qtqt(dq->quat, dq->quat); - if(len2 > 0.0f) + if (len2 > 0.0f) len2= 1.0f/len2; /* translation */ @@ -1589,7 +1591,7 @@ void mul_v3m3_dq(float *co, float mat[][3],DualQuat *dq) t[2]= 2*(-t0*z + x*t2 + w*t3 - t1*y); /* apply scaling */ - if(dq->scale_weight) + if (dq->scale_weight) mul_m4_v3(dq->scale, co); /* apply rotation and translation */ @@ -1599,8 +1601,8 @@ void mul_v3m3_dq(float *co, float mat[][3],DualQuat *dq) co[2]= (co[2] + t[2])*len2; /* compute crazyspace correction mat */ - if(mat) { - if(dq->scale_weight) { + if (mat) { + if (dq->scale_weight) { copy_m3_m4(scalemat, dq->scale); mul_m3_m3m3(mat, M, scalemat); } @@ -1631,13 +1633,13 @@ void quat_apply_track(float quat[4], short axis, short upflag) mul_qt_qtqt(quat, quat, quat_track[axis]); - if(axis>2) + if (axis>2) axis= axis-3; /* there are 2 possible up-axis for each axis used, the 'quat_track' applies so the first * up axis is used X->Y, Y->X, Z->X, if this first up axis isn used then rotate 90d * the strange bit shift below just find the low axis {X:Y, Y:X, Z:X} */ - if(upflag != (2-axis)>>1) { + if (upflag != (2-axis)>>1) { float q[4]= {0.70710676908493, 0.0, 0.0, 0.0}; /* assign 90d rotation axis */ q[axis+1] = ((axis==1)) ? 0.70710676908493 : -0.70710676908493; /* flip non Y axis */ mul_qt_qtqt(quat, quat, q); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 39e1a9b31f0..63094d9cfd0 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -390,13 +390,13 @@ void print_v4(const char *str, const float v[4]) void minmax_v3v3_v3(float min[3], float max[3], const float vec[3]) { - if(min[0]>vec[0]) min[0]= vec[0]; - if(min[1]>vec[1]) min[1]= vec[1]; - if(min[2]>vec[2]) min[2]= vec[2]; + if (min[0]>vec[0]) min[0]= vec[0]; + if (min[1]>vec[1]) min[1]= vec[1]; + if (min[2]>vec[2]) min[2]= vec[2]; - if(max[0] 1.0e-35f) { + if (d > 1.0e-35f) { d= sqrtf(d); mul_v2_v2fl(r, a, 1.0f/d); - } else { + } + else { zero_v2(r); d= 0.0f; } @@ -569,7 +570,7 @@ MINLINE float normalize_v3_v3(float r[3], const float a[3]) /* a larger value causes normalize errors in a * scaled down models with camera xtreme close */ - if(d > 1.0e-35f) { + if (d > 1.0e-35f) { d= sqrtf(d); mul_v3_v3fl(r, a, 1.0f/d); } @@ -587,7 +588,7 @@ MINLINE double normalize_v3_d(double n[3]) /* a larger value causes normalize errors in a * scaled down models with camera xtreme close */ - if(d > 1.0e-35) { + if (d > 1.0e-35) { double mul; d= sqrt(d); @@ -596,7 +597,8 @@ MINLINE double normalize_v3_d(double n[3]) n[0] *= mul; n[1] *= mul; n[2] *= mul; - } else { + } + else { n[0] = n[1] = n[2] = 0; d= 0.0; } @@ -663,9 +665,9 @@ MINLINE int equals_v4v4(const float v1[4], const float v2[4]) MINLINE int compare_v3v3(const float v1[3], const float v2[3], const float limit) { - if(fabsf(v1[0]-v2[0])1.0f) n=1.0f; + if (n<0.0f) n=0.0f; else if (n>1.0f) n=1.0f; return n; } @@ -345,7 +345,7 @@ static float orgBlenderNoiseS(float x, float y, float z) /* separated from orgBlenderNoise above, with scaling */ float BLI_hnoise(float noisesize, float x, float y, float z) { - if(noisesize==0.0f) return 0.0f; + if (noisesize==0.0f) return 0.0f; x= (1.0f+x)/noisesize; y= (1.0f+y)/noisesize; z= (1.0f+z)/noisesize; @@ -360,7 +360,7 @@ float BLI_turbulence(float noisesize, float x, float y, float z, int nr) s= BLI_hnoise(noisesize, x, y, z); - while(nr>0) { + while (nr>0) { s+= d*BLI_hnoise(noisesize*d, x, y, z); div+= d; @@ -377,7 +377,7 @@ float BLI_turbulence1(float noisesize, float x, float y, float z, int nr) s= fabsf( (-1.0f+2.0f*BLI_hnoise(noisesize, x, y, z))); - while(nr>0) { + while (nr>0) { s+= fabsf(d* (-1.0f+2.0f*BLI_hnoise(noisesize*d, x, y, z))); div+= d; @@ -1771,7 +1771,7 @@ float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity result = signal; - for( i=1; i<(int)octaves; i++ ) { + for ( i=1; i<(int)octaves; i++ ) { x *= lacunarity; y *= lacunarity; z *= lacunarity; diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index ccf85934788..2bbc4517da1 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -111,18 +111,18 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu short i, found = 0; char *lslash = BLI_last_slash(string); len2 = len = strlen(string); - if(lslash) + if (lslash) lenlslash= (int)(lslash - string); - while(len > lenlslash && string[--len] != '.') {}; - if(len == lenlslash && string[len] != '.') len = len2; + while (len > lenlslash && string[--len] != '.') {}; + if (len == lenlslash && string[len] != '.') len = len2; for (i = len - 1; i >= lenlslash; i--) { if (isdigit(string[i])) { if (found) { nums = i; } - else{ + else { nume = i; nums = i; found = 1; @@ -154,7 +154,7 @@ int BLI_stringdec(const char *string, char *head, char *tail, unsigned short *nu void BLI_stringenc(char *string, const char *head, const char *tail, unsigned short numlen, int pic) { char fmtstr[16]=""; - if(pic < 0) pic= 0; + if (pic < 0) pic= 0; sprintf(fmtstr, "%%s%%.%dd%%s", numlen); sprintf(string, fmtstr, head, pic, tail); } @@ -169,23 +169,23 @@ int BLI_split_name_num(char *left, int *nr, const char *name, const char delim) a= strlen(name); memcpy(left, name, (a + 1) * sizeof(char)); - if(a>1 && name[a-1]==delim) return a; + if (a>1 && name[a-1]==delim) return a; - while(a--) { - if( name[a]==delim ) { + while (a--) { + if ( name[a]==delim ) { left[a]= 0; *nr= atol(name+a+1); /* casting down to an int, can overflow for large numbers */ - if(*nr < 0) + if (*nr < 0) *nr= 0; return a; } - if( isdigit(name[a])==0 ) break; + if ( isdigit(name[a])==0 ) break; left[a]= 0; } - for(a= 0; name[a]; a++) + for (a= 0; name[a]; a++) left[a]= name[a]; return a; @@ -217,11 +217,11 @@ void BLI_newname(char *name, int add) int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, const char defname[], char delim, char *name, short name_len) { - if(name[0] == '\0') { + if (name[0] == '\0') { BLI_strncpy(name, defname, name_len); } - if(unique_check(arg, name)) { + if (unique_check(arg, name)) { char numstr[16]; char tempname[UNIQUE_NAME_MAX]; char left[UNIQUE_NAME_MAX]; @@ -242,7 +242,7 @@ int BLI_uniquename_cb(int (*unique_check)(void *, const char *), void *arg, cons tempname_buf = BLI_strncat_utf8(tempname, left, name_len - numlen); memcpy(tempname_buf, numstr, numlen + 1); } - } while(unique_check(arg, tempname)); + } while (unique_check(arg, tempname)); BLI_strncpy(name, tempname, name_len); @@ -322,7 +322,8 @@ void BLI_cleanup_path(const char *relabase, char *dir) char *start, *eind; if (relabase) { BLI_path_abs(dir, relabase); - } else { + } + else { if (dir[0]=='/' && dir[1]=='/') { if (dir[2]== '\0') { return; /* path is "//" - cant clean it */ @@ -343,7 +344,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) /* Note, this should really be moved to the file selector, * since this function is used in many areas */ - if(strcmp(dir, ".")==0) { /* happens for example in FILE_MAIN */ + if (strcmp(dir, ".")==0) { /* happens for example in FILE_MAIN */ get_default_root(dir); return; } @@ -357,7 +358,8 @@ void BLI_cleanup_path(const char *relabase, char *dir) } if (a<0) { break; - } else { + } + else { memmove(dir + a, eind, strlen(eind) + 1); } } @@ -372,7 +374,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) memmove(start, eind, strlen(eind) + 1); } #else - if(dir[0]=='.') { /* happens, for example in FILE_MAIN */ + if (dir[0]=='.') { /* happens, for example in FILE_MAIN */ dir[0]= '/'; dir[1]= 0; return; @@ -381,7 +383,7 @@ void BLI_cleanup_path(const char *relabase, char *dir) /* support for odd paths: eg /../home/me --> /home/me * this is a valid path in blender but we cant handle this the usual way below * simply strip this prefix then evaluate the path as usual. pythons os.path.normpath() does this */ - while((strncmp(dir, "/../", 4)==0)) { + while ((strncmp(dir, "/../", 4)==0)) { memmove(dir, dir + 4, strlen(dir + 4) + 1); } @@ -432,7 +434,7 @@ void BLI_path_rel(char *file, const char *relfile) char res[FILE_MAX]; /* if file is already relative, bail out */ - if(file[0]=='/' && file[1]=='/') return; + if (file[0]=='/' && file[1]=='/') return; /* also bail out if relative path is not set */ if (relfile[0] == 0) return; @@ -448,7 +450,8 @@ void BLI_path_rel(char *file, const char *relfile) ptemp++; } BLI_strncpy(ptemp, relfile, FILE_MAX-3); - } else { + } + else { BLI_strncpy(temp, relfile, FILE_MAX); } @@ -549,7 +552,8 @@ int BLI_parent_dir(char *path) if (!BLI_testextensie(tmp, parent_dir)) { BLI_strncpy(path, tmp, sizeof(tmp)); return 1; - } else { + } + else { return 0; } } @@ -562,7 +566,8 @@ static int stringframe_chars(char *path, int *char_start, int *char_end) for (i = 0; path[i] != '\0'; i++) { if (path[i] == '\\' || path[i] == '/') { ch_end = 0; /* this is a directory name, don't use any hashes we found */ - } else if (path[i] == '#') { + } + else if (path[i] == '#') { ch_sta = i; ch_end = ch_sta+1; while (path[ch_end] == '#') { @@ -574,7 +579,7 @@ static int stringframe_chars(char *path, int *char_start, int *char_end) } } - if(ch_end) { + if (ch_end) { *char_start= ch_sta; *char_end= ch_end; return 1; @@ -590,13 +595,13 @@ static void ensure_digits(char *path, int digits) { char *file= BLI_last_slash(path); - if(file==NULL) + if (file==NULL) file= path; - if(strrchr(file, '#') == NULL) { + if (strrchr(file, '#') == NULL) { int len= strlen(file); - while(digits--) { + while (digits--) { file[len++]= '#'; } file[len]= '\0'; @@ -607,7 +612,7 @@ int BLI_path_frame(char *path, int frame, int digits) { int ch_sta, ch_end; - if(digits) + if (digits) ensure_digits(path, digits); if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ @@ -623,7 +628,7 @@ int BLI_path_frame_range(char *path, int sta, int end, int digits) { int ch_sta, ch_end; - if(digits) + if (digits) ensure_digits(path, digits); if (stringframe_chars(path, &ch_sta, &ch_end)) { /* warning, ch_end is the last # +1 */ @@ -706,10 +711,12 @@ int BLI_path_abs(char *path, const char *basepath) memcpy(tmp, base, baselen); BLI_strncpy(tmp+baselen, path, sizeof(tmp)-baselen); BLI_strncpy(path, tmp, FILE_MAX); - } else { + } + else { BLI_strncpy(path, tmp+2, FILE_MAX); } - } else { + } + else { BLI_strncpy(path, tmp, FILE_MAX); } @@ -752,7 +759,8 @@ int BLI_path_cwd(char *path) if (cwd[0] == '\0') { printf( "Could not get the current working directory - $PWD for an unknown reason."); - } else { + } + else { /* uses the blend path relative to cwd important for loading relative linked files. * * cwd should contain c:\ etc on win32 so the relbase can be NULL @@ -779,7 +787,8 @@ void BLI_splitdirstring(char *di, char *fi) if (lslash) { BLI_strncpy(fi, lslash+1, FILE_MAXFILE); *(lslash+1)=0; - } else { + } + else { BLI_strncpy(fi, di, FILE_MAXFILE); di[0]= 0; } @@ -799,7 +808,8 @@ void BLI_getlastdir(const char* dir, char *last, const size_t maxlen) } if (prevslash) { BLI_strncpy(last, prevslash+1, maxlen); - } else { + } + else { BLI_strncpy(last, dir, maxlen); } } @@ -826,7 +836,7 @@ const char *BLI_getDefaultDocumentFolder(void) HRESULT hResult; /* Check for %HOME% env var */ - if(uput_getenv("HOME",documentfolder,MAXPATHLEN)) { + if (uput_getenv("HOME",documentfolder,MAXPATHLEN)) { if (BLI_is_dir(documentfolder)) return documentfolder; } @@ -862,11 +872,11 @@ static int test_path(char *targetpath, const char *path_base, const char *path_s { char tmppath[FILE_MAX]; - if(path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep); + if (path_sep) BLI_join_dirfile(tmppath, sizeof(tmppath), path_base, path_sep); else BLI_strncpy(tmppath, path_base, sizeof(tmppath)); /* rare cases folder_name is omitted (when looking for ~/.blender/2.xx dir only) */ - if(folder_name) + if (folder_name) BLI_make_file_string("/", targetpath, tmppath, folder_name); else BLI_strncpy(targetpath, tmppath, sizeof(tmppath)); @@ -894,7 +904,8 @@ static int test_env_path(char *path, const char *envvar) if (BLI_is_dir(env)) { BLI_strncpy(path, env, FILE_MAX); return 1; - } else { + } + else { path[0] = '\0'; return 0; } @@ -908,10 +919,11 @@ static int get_path_local(char *targetpath, const char *folder_name, const char printf("get_path_local...\n"); #endif - if(folder_name) { + if (folder_name) { if (subfolder_name) { BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name); - } else { + } + else { BLI_strncpy(relfolder, folder_name, sizeof(relfolder)); } } @@ -920,7 +932,7 @@ static int get_path_local(char *targetpath, const char *folder_name, const char } /* try EXECUTABLE_DIR/2.5x/folder_name - new default directory for local blender installed files */ - if(test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder)) + if (test_path(targetpath, bprogdir, blender_version_decimal(ver), relfolder)) return 1; return 0; @@ -949,7 +961,8 @@ static int get_path_user(char *targetpath, const char *folder_name, const char * if (test_env_path(user_path, envvar)) { if (subfolder_name) { return test_path(targetpath, user_path, NULL, subfolder_name); - } else { + } + else { BLI_strncpy(targetpath, user_path, FILE_MAX); return 1; } @@ -960,7 +973,7 @@ static int get_path_user(char *targetpath, const char *folder_name, const char * BLI_snprintf(user_path, FILE_MAX, BLENDER_USER_FORMAT, user_base_path, blender_version_decimal(ver)); } - if(!user_path[0]) + if (!user_path[0]) return 0; #ifdef PATH_DEBUG2 @@ -970,7 +983,8 @@ static int get_path_user(char *targetpath, const char *folder_name, const char * if (subfolder_name) { /* try $HOME/folder_name/subfolder_name */ return test_path(targetpath, user_path, folder_name, subfolder_name); - } else { + } + else { /* try $HOME/folder_name */ return test_path(targetpath, user_path, NULL, folder_name); } @@ -987,10 +1001,11 @@ static int get_path_system(char *targetpath, const char *folder_name, const char char cwd[FILE_MAX]; char relfolder[FILE_MAX]; - if(folder_name) { + if (folder_name) { if (subfolder_name) { BLI_join_dirfile(relfolder, sizeof(relfolder), folder_name, subfolder_name); - } else { + } + else { BLI_strncpy(relfolder, folder_name, sizeof(relfolder)); } } @@ -999,14 +1014,14 @@ static int get_path_system(char *targetpath, const char *folder_name, const char } /* try CWD/release/folder_name */ - if(BLI_current_working_dir(cwd, sizeof(cwd))) { - if(test_path(targetpath, cwd, "release", relfolder)) { + if (BLI_current_working_dir(cwd, sizeof(cwd))) { + if (test_path(targetpath, cwd, "release", relfolder)) { return 1; } } /* try EXECUTABLE_DIR/release/folder_name */ - if(test_path(targetpath, bprogdir, "release", relfolder)) + if (test_path(targetpath, bprogdir, "release", relfolder)) return 1; /* end developer overrides */ @@ -1017,7 +1032,8 @@ static int get_path_system(char *targetpath, const char *folder_name, const char if (test_env_path(system_path, envvar)) { if (subfolder_name) { return test_path(targetpath, system_path, NULL, subfolder_name); - } else { + } + else { BLI_strncpy(targetpath, system_path, FILE_MAX); return 1; } @@ -1028,7 +1044,7 @@ static int get_path_system(char *targetpath, const char *folder_name, const char BLI_snprintf(system_path, FILE_MAX, BLENDER_SYSTEM_FORMAT, system_base_path, blender_version_decimal(ver)); } - if(!system_path[0]) + if (!system_path[0]) return 0; #ifdef PATH_DEBUG2 @@ -1038,7 +1054,8 @@ static int get_path_system(char *targetpath, const char *folder_name, const char if (subfolder_name) { /* try $BLENDERPATH/folder_name/subfolder_name */ return test_path(targetpath, system_path, folder_name, subfolder_name); - } else { + } + else { /* try $BLENDERPATH/folder_name */ return test_path(targetpath, system_path, NULL, folder_name); } @@ -1156,7 +1173,7 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check) BLI_assert(!"incorrect ID"); } - if((ok == FALSE) && do_check) { + if ((ok == FALSE) && do_check) { return NULL; } @@ -1201,17 +1218,17 @@ void BLI_setenv(const char *env, const char*val) */ void BLI_setenv_if_new(const char *env, const char* val) { - if(getenv(env) == NULL) + if (getenv(env) == NULL) BLI_setenv(env, val); } void BLI_clean(char *path) { - if(path==NULL) return; + if (path==NULL) return; #ifdef WIN32 - if(path && BLI_strnlen(path, 3) > 2) { + if (path && BLI_strnlen(path, 3) > 2) { BLI_char_switch(path+2, '/', '\\'); } #else @@ -1221,7 +1238,7 @@ void BLI_clean(char *path) void BLI_char_switch(char *string, char from, char to) { - if(string==NULL) return; + if (string==NULL) return; while (*string != 0) { if (*string == from) *string = to; string++; @@ -1304,7 +1321,7 @@ void BLI_make_file_string(const char *relabase, char *string, const char *dir, strcpy(string, relabase); lslash= BLI_last_slash(string); - if(lslash) *(lslash+1)= 0; + if (lslash) *(lslash+1)= 0; dir+=2; /* Skip over the relative reference */ } @@ -1360,11 +1377,13 @@ int BLI_testextensie(const char *str, const char *ext) a= strlen(str); b= strlen(ext); - if(a==0 || b==0 || b>=a) { + if (a==0 || b==0 || b>=a) { retval = 0; - } else if (BLI_strcasecmp(ext, str + a - b)) { + } + else if (BLI_strcasecmp(ext, str + a - b)) { retval = 0; - } else { + } + else { retval = 1; } @@ -1374,8 +1393,8 @@ int BLI_testextensie(const char *str, const char *ext) int BLI_testextensie_array(const char *str, const char **ext_array) { int i=0; - while(ext_array[i]) { - if(BLI_testextensie(str, ext_array[i])) { + while (ext_array[i]) { + if (BLI_testextensie(str, ext_array[i])) { return 1; } @@ -1391,11 +1410,11 @@ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch) const char *ext_step= ext_fnmatch; char pattern[16]; - while(ext_step[0]) { + while (ext_step[0]) { char *ext_next; int len_ext; - if((ext_next=strchr(ext_step, ';'))) { + if ((ext_next=strchr(ext_step, ';'))) { len_ext= (int)(ext_next - ext_step) + 1; } else { @@ -1404,7 +1423,7 @@ int BLI_testextensie_glob(const char *str, const char *ext_fnmatch) BLI_strncpy(pattern, ext_step, len_ext); - if(fnmatch(pattern, str, FNM_CASEFOLD)==0) { + if (fnmatch(pattern, str, FNM_CASEFOLD)==0) { return 1; } ext_step += len_ext; @@ -1420,7 +1439,7 @@ int BLI_replace_extension(char *path, size_t maxlen, const char *ext) size_t ext_len= strlen(ext); ssize_t a; - for(a= path_len - 1; a >= 0; a--) { + for (a= path_len - 1; a >= 0; a--) { if (ELEM3(path[a], '.', '/', '\\')) { break; } @@ -1430,7 +1449,7 @@ int BLI_replace_extension(char *path, size_t maxlen, const char *ext) a= path_len; } - if(a + ext_len >= maxlen) + if (a + ext_len >= maxlen) return 0; memcpy(path+a, ext, ext_len + 1); @@ -1451,7 +1470,7 @@ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) return 1; } - for(a= path_len - 1; a >= 0; a--) { + for (a= path_len - 1; a >= 0; a--) { if (path[a] == '.') { path[a]= '\0'; } @@ -1461,7 +1480,7 @@ int BLI_ensure_extension(char *path, size_t maxlen, const char *ext) } a++; - if(a + ext_len >= maxlen) + if (a + ext_len >= maxlen) return 0; memcpy(path+a, ext, ext_len + 1); @@ -1509,7 +1528,7 @@ void BLI_join_dirfile(char *dst, const size_t maxlen, const char *dir, const cha size_t dirlen= BLI_strnlen(dir, maxlen); if (dst != dir) { - if(dirlen == maxlen) { + if (dirlen == maxlen) { memcpy(dst, dir, dirlen); dst[dirlen - 1]= '\0'; return; /* dir fills the path */ @@ -1693,7 +1712,8 @@ void BLI_del_slash(char *string) if (string[len-1] == SEP) { string[len-1] = '\0'; len--; - } else { + } + else { break; } } @@ -1720,7 +1740,8 @@ static int add_win32_extension(char *name) ext[temp - extensions] = 0; extensions = temp + 1; strcat(filename, ext); - } else { + } + else { strcat(filename, extensions); } @@ -1733,7 +1754,8 @@ static int add_win32_extension(char *name) } while (temp); } #endif - } else { + } + else { retval = 1; } @@ -1776,9 +1798,9 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name #ifdef _WIN32 wchar_t * fullname_16 = MEM_mallocN(maxlen*sizeof(wchar_t), "ProgramPath"); - if(GetModuleFileNameW(0, fullname_16, maxlen)) { + if (GetModuleFileNameW(0, fullname_16, maxlen)) { conv_utf_16_to_8(fullname_16,fullname, maxlen); - if(!BLI_exists(fullname)) { + if (!BLI_exists(fullname)) { printf("path can't be found: \"%.*s\"\n", maxlen, fullname); MessageBox(NULL, "path contains invalid characters or is too long (see console)", "Error", MB_OK); } @@ -1798,7 +1820,7 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name BLI_current_working_dir(wdir, sizeof(wdir)); /* backup cwd to restore after */ // not needed but avoids annoying /./ in name - if(name[1]==SEP) + if (name[1]==SEP) BLI_join_dirfile(fullname, maxlen, wdir, name+2); else BLI_join_dirfile(fullname, maxlen, wdir, name); @@ -1809,7 +1831,8 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name // full path BLI_strncpy(fullname, name, maxlen); add_win32_extension(fullname); - } else { + } + else { // search for binary in $PATH path = getenv("PATH"); if (path) { @@ -1819,7 +1842,8 @@ static void bli_where_am_i(char *fullname, const size_t maxlen, const char *name strncpy(filename, path, temp - path); filename[temp - path] = 0; path = temp + 1; - } else { + } + else { strncpy(filename, path, sizeof(filename)); } BLI_join_dirfile(fullname, maxlen, fullname, name); @@ -1899,11 +1923,12 @@ static void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir if (fullname[0] == '\0') { BLI_strncpy(fullname, "/tmp/", maxlen); - } else { + } + else { /* add a trailing slash if needed */ BLI_add_slash(fullname); #ifdef WIN32 - if(userdir && userdir != fullname) { + if (userdir && userdir != fullname) { BLI_strncpy(userdir, fullname, maxlen); /* also set user pref to show %TEMP%. /tmp/ is just plain confusing for Windows users. */ } #endif diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index 1987cbeedac..e1b7ff120f9 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -186,7 +186,7 @@ static void BB_reset(BB *bb) static void BB_expand(BB *bb, float co[3]) { int i; - for(i = 0; i < 3; ++i) { + for (i = 0; i < 3; ++i) { bb->bmin[i] = MIN2(bb->bmin[i], co[i]); bb->bmax[i] = MAX2(bb->bmax[i], co[i]); } @@ -196,7 +196,7 @@ static void BB_expand(BB *bb, float co[3]) static void BB_expand_with_bb(BB *bb, BB *bb2) { int i; - for(i = 0; i < 3; ++i) { + for (i = 0; i < 3; ++i) { bb->bmin[i] = MIN2(bb->bmin[i], bb2->bmin[i]); bb->bmax[i] = MAX2(bb->bmax[i], bb2->bmax[i]); } @@ -208,17 +208,17 @@ static int BB_widest_axis(BB *bb) float dim[3]; int i; - for(i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) dim[i] = bb->bmax[i] - bb->bmin[i]; - if(dim[0] > dim[1]) { - if(dim[0] > dim[2]) + if (dim[0] > dim[1]) { + if (dim[0] > dim[2]) return 0; else return 2; } else { - if(dim[1] > dim[2]) + if (dim[1] > dim[2]) return 1; else return 2; @@ -228,7 +228,7 @@ static int BB_widest_axis(BB *bb) static void BBC_update_centroid(BBC *bbc) { int i; - for(i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) bbc->bcentroid[i] = (bbc->bmin[i] + bbc->bmax[i]) * 0.5f; } @@ -239,7 +239,7 @@ static void update_node_vb(PBVH *bvh, PBVHNode *node) BB_reset(&vb); - if(node->flag & PBVH_Leaf) { + if (node->flag & PBVH_Leaf) { PBVHVertexIter vd; BLI_pbvh_vertex_iter_begin(bvh, node, vd, PBVH_ITER_ALL) { @@ -285,11 +285,11 @@ static int partition_indices(int *prim_indices, int lo, int hi, int axis, float mid, BBC *prim_bbc) { int i=lo, j=hi; - for(;;) { - for(; prim_bbc[prim_indices[i]].bcentroid[axis] < mid; i++); - for(; mid < prim_bbc[prim_indices[j]].bcentroid[axis]; j--); + for (;;) { + for (; prim_bbc[prim_indices[i]].bcentroid[axis] < mid; i++); + for (; mid < prim_bbc[prim_indices[j]].bcentroid[axis]; j--); - if(!(i < j)) + if (!(i < j)) return i; SWAP(int, prim_indices[i], prim_indices[j]); @@ -306,22 +306,22 @@ static int partition_indices_material(PBVH *bvh, int lo, int hi) const void *first; int i=lo, j=hi; - if(bvh->faces) + if (bvh->faces) first = &faces[bvh->prim_indices[lo]]; else first = &flagmats[bvh->prim_indices[lo]]; - for(;;) { - if(bvh->faces) { - for(; face_materials_match(first, &faces[indices[i]]); i++); - for(; !face_materials_match(first, &faces[indices[j]]); j--); + for (;;) { + if (bvh->faces) { + for (; face_materials_match(first, &faces[indices[i]]); i++); + for (; !face_materials_match(first, &faces[indices[j]]); j--); } else { - for(; grid_materials_match(first, &flagmats[indices[i]]); i++); - for(; !grid_materials_match(first, &flagmats[indices[j]]); j--); + for (; grid_materials_match(first, &flagmats[indices[i]]); i++); + for (; !grid_materials_match(first, &flagmats[indices[j]]); j--); } - if(!(i < j)) + if (!(i < j)) return i; SWAP(int, bvh->prim_indices[i], bvh->prim_indices[j]); @@ -331,10 +331,10 @@ static int partition_indices_material(PBVH *bvh, int lo, int hi) static void grow_nodes(PBVH *bvh, int totnode) { - if(totnode > bvh->node_mem_count) { + if (totnode > bvh->node_mem_count) { PBVHNode *prev = bvh->nodes; bvh->node_mem_count *= 1.33; - if(bvh->node_mem_count < totnode) + if (bvh->node_mem_count < totnode) bvh->node_mem_count = totnode; bvh->nodes = MEM_callocN(sizeof(PBVHNode) * bvh->node_mem_count, "bvh nodes"); @@ -353,8 +353,8 @@ static int map_insert_vert(PBVH *bvh, GHash *map, { void *value, *key = SET_INT_IN_POINTER(vertex); - if(!BLI_ghash_haskey(map, key)) { - if(BLI_BITMAP_GET(bvh->vert_bitmap, vertex)) { + if (!BLI_ghash_haskey(map, key)) { + if (BLI_BITMAP_GET(bvh->vert_bitmap, vertex)) { value = SET_INT_IN_POINTER(~(*face_verts)); ++(*face_verts); } @@ -386,11 +386,11 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) node->face_vert_indices = MEM_callocN(sizeof(int) * 4*totface, "bvh node face vert indices"); - for(i = 0; i < totface; ++i) { + for (i = 0; i < totface; ++i) { MFace *f = bvh->faces + node->prim_indices[i]; int sides = f->v4 ? 4 : 3; - for(j = 0; j < sides; ++j) { + for (j = 0; j < sides; ++j) { node->face_vert_indices[i][j]= map_insert_vert(bvh, map, &node->face_verts, &node->uniq_verts, (&f->v1)[j]); @@ -402,13 +402,13 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) "bvh node vert indices"); /* Build the vertex list, unique verts first */ - for(iter = BLI_ghashIterator_new(map), i = 0; + for (iter = BLI_ghashIterator_new(map), i = 0; !BLI_ghashIterator_isDone(iter); BLI_ghashIterator_step(iter), ++i) { void *value = BLI_ghashIterator_getValue(iter); int ndx = GET_INT_FROM_POINTER(value); - if(ndx < 0) + if (ndx < 0) ndx = -ndx + node->uniq_verts - 1; node->vert_indices[ndx] = @@ -417,19 +417,19 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) BLI_ghashIterator_free(iter); - for(i = 0; i < totface; ++i) { + for (i = 0; i < totface; ++i) { MFace *f = bvh->faces + node->prim_indices[i]; int sides = f->v4 ? 4 : 3; - for(j = 0; j < sides; ++j) { - if(node->face_vert_indices[i][j] < 0) + for (j = 0; j < sides; ++j) { + if (node->face_vert_indices[i][j] < 0) node->face_vert_indices[i][j]= -node->face_vert_indices[i][j] + node->uniq_verts - 1; } } - if(!G.background) { + if (!G.background) { node->draw_buffers = GPU_build_mesh_buffers(node->face_vert_indices, bvh->faces, bvh->verts, @@ -444,7 +444,7 @@ static void build_mesh_leaf_node(PBVH *bvh, PBVHNode *node) static void build_grids_leaf_node(PBVH *bvh, PBVHNode *node) { - if(!G.background) { + if (!G.background) { node->draw_buffers = GPU_build_grid_buffers(node->prim_indices, node->totprim, bvh->grid_hidden, bvh->gridsize); @@ -458,7 +458,7 @@ static void update_vb(PBVH *bvh, PBVHNode *node, BBC *prim_bbc, int i; BB_reset(&node->vb); - for(i = offset + count - 1; i >= offset; --i) { + for (i = offset + count - 1; i >= offset; --i) { BB_expand_with_bb(&node->vb, (BB*)(&prim_bbc[bvh->prim_indices[i]])); } node->orig_vb = node->vb; @@ -475,7 +475,7 @@ static void build_leaf(PBVH *bvh, int node_index, BBC *prim_bbc, /* Still need vb for searches */ update_vb(bvh, &bvh->nodes[node_index], prim_bbc, offset, count); - if(bvh->faces) + if (bvh->faces) build_mesh_leaf_node(bvh, bvh->nodes + node_index); else build_grids_leaf_node(bvh, bvh->nodes + node_index); @@ -487,24 +487,24 @@ int leaf_needs_material_split(PBVH *bvh, int offset, int count) { int i, prim; - if(count <= 1) + if (count <= 1) return 0; - if(bvh->faces) { + if (bvh->faces) { const MFace *first = &bvh->faces[bvh->prim_indices[offset]]; - for(i = offset + count - 1; i > offset; --i) { + for (i = offset + count - 1; i > offset; --i) { prim = bvh->prim_indices[i]; - if(!face_materials_match(first, &bvh->faces[prim])) + if (!face_materials_match(first, &bvh->faces[prim])) return 1; } } else { const DMFlagMat *first = &bvh->grid_flag_mats[bvh->prim_indices[offset]]; - for(i = offset + count - 1; i > offset; --i) { + for (i = offset + count - 1; i > offset; --i) { prim = bvh->prim_indices[i]; - if(!grid_materials_match(first, &bvh->grid_flag_mats[prim])) + if (!grid_materials_match(first, &bvh->grid_flag_mats[prim])) return 1; } } @@ -532,8 +532,8 @@ static void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc, /* Decide whether this is a leaf or not */ below_leaf_limit = count <= bvh->leaf_limit; - if(below_leaf_limit) { - if(!leaf_needs_material_split(bvh, offset, count)) { + if (below_leaf_limit) { + if (!leaf_needs_material_split(bvh, offset, count)) { build_leaf(bvh, node_index, prim_bbc, offset, count); return; } @@ -546,12 +546,12 @@ static void build_sub(PBVH *bvh, int node_index, BB *cb, BBC *prim_bbc, /* Update parent node bounding box */ update_vb(bvh, &bvh->nodes[node_index], prim_bbc, offset, count); - if(!below_leaf_limit) { + if (!below_leaf_limit) { /* Find axis with widest range of primitive centroids */ - if(!cb) { + if (!cb) { cb = &cb_backing; BB_reset(cb); - for(i = offset + count - 1; i >= offset; --i) + for (i = offset + count - 1; i >= offset; --i) BB_expand(cb, prim_bbc[bvh->prim_indices[i]].bcentroid); } axis = BB_widest_axis(cb); @@ -579,16 +579,16 @@ static void pbvh_build(PBVH *bvh, BB *cb, BBC *prim_bbc, int totprim) { int i; - if(totprim != bvh->totprim) { + if (totprim != bvh->totprim) { bvh->totprim = totprim; - if(bvh->nodes) MEM_freeN(bvh->nodes); - if(bvh->prim_indices) MEM_freeN(bvh->prim_indices); + if (bvh->nodes) MEM_freeN(bvh->nodes); + if (bvh->prim_indices) MEM_freeN(bvh->prim_indices); bvh->prim_indices = MEM_callocN(sizeof(int) * totprim, "bvh prim indices"); - for(i = 0; i < totprim; ++i) + for (i = 0; i < totprim; ++i) bvh->prim_indices[i] = i; bvh->totnode = 0; - if(bvh->node_mem_count < 100) { + if (bvh->node_mem_count < 100) { bvh->node_mem_count = 100; bvh->nodes = MEM_callocN(sizeof(PBVHNode) * bvh->node_mem_count, @@ -619,14 +619,14 @@ void BLI_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int /* For each face, store the AABB and the AABB centroid */ prim_bbc = MEM_mallocN(sizeof(BBC) * totface, "prim_bbc"); - for(i = 0; i < totface; ++i) { + for (i = 0; i < totface; ++i) { MFace *f = faces + i; const int sides = f->v4 ? 4 : 3; BBC *bbc = prim_bbc + i; BB_reset((BB*)bbc); - for(j = 0; j < sides; ++j) + for (j = 0; j < sides; ++j) BB_expand((BB*)bbc, verts[(&f->v1)[j]].co); BBC_update_centroid(bbc); @@ -634,7 +634,7 @@ void BLI_pbvh_build_mesh(PBVH *bvh, MFace *faces, MVert *verts, int totface, int BB_expand(&cb, bbc->bcentroid); } - if(totface) + if (totface) pbvh_build(bvh, &cb, prim_bbc, totface); MEM_freeN(prim_bbc); @@ -664,13 +664,13 @@ void BLI_pbvh_build_grids(PBVH *bvh, DMGridData **grids, DMGridAdjacency *gridad /* For each grid, store the AABB and the AABB centroid */ prim_bbc = MEM_mallocN(sizeof(BBC) * totgrid, "prim_bbc"); - for(i = 0; i < totgrid; ++i) { + for (i = 0; i < totgrid; ++i) { DMGridData *grid= grids[i]; BBC *bbc = prim_bbc + i; BB_reset((BB*)bbc); - for(j = 0; j < gridsize*gridsize; ++j) + for (j = 0; j < gridsize*gridsize; ++j) BB_expand((BB*)bbc, grid[j].co); BBC_update_centroid(bbc); @@ -678,7 +678,7 @@ void BLI_pbvh_build_grids(PBVH *bvh, DMGridData **grids, DMGridAdjacency *gridad BB_expand(&cb, bbc->bcentroid); } - if(totgrid) + if (totgrid) pbvh_build(bvh, &cb, prim_bbc, totgrid); MEM_freeN(prim_bbc); @@ -696,15 +696,15 @@ void BLI_pbvh_free(PBVH *bvh) PBVHNode *node; int i; - for(i = 0; i < bvh->totnode; ++i) { + for (i = 0; i < bvh->totnode; ++i) { node= &bvh->nodes[i]; - if(node->flag & PBVH_Leaf) { - if(node->draw_buffers) + if (node->flag & PBVH_Leaf) { + if (node->draw_buffers) GPU_free_buffers(node->draw_buffers); - if(node->vert_indices) + if (node->vert_indices) MEM_freeN(node->vert_indices); - if(node->face_vert_indices) + if (node->face_vert_indices) MEM_freeN(node->face_vert_indices); } } @@ -714,15 +714,15 @@ void BLI_pbvh_free(PBVH *bvh) /* if pbvh was deformed, new memory was allocated for verts/faces -- free it */ MEM_freeN(bvh->verts); - if(bvh->faces) + if (bvh->faces) MEM_freeN(bvh->faces); } } - if(bvh->nodes) + if (bvh->nodes) MEM_freeN(bvh->nodes); - if(bvh->prim_indices) + if (bvh->prim_indices) MEM_freeN(bvh->prim_indices); MEM_freeN(bvh); @@ -744,20 +744,20 @@ static void pbvh_iter_begin(PBVHIter *iter, PBVH *bvh, BLI_pbvh_SearchCallback s static void pbvh_iter_end(PBVHIter *iter) { - if(iter->stackspace > STACK_FIXED_DEPTH) + if (iter->stackspace > STACK_FIXED_DEPTH) MEM_freeN(iter->stack); } static void pbvh_stack_push(PBVHIter *iter, PBVHNode *node, int revisiting) { - if(iter->stacksize == iter->stackspace) { + if (iter->stacksize == iter->stackspace) { PBVHStack *newstack; iter->stackspace *= 2; newstack= MEM_callocN(sizeof(PBVHStack)*iter->stackspace, "PBVHStack"); memcpy(newstack, iter->stack, sizeof(PBVHStack)*iter->stacksize); - if(iter->stackspace > STACK_FIXED_DEPTH) + if (iter->stackspace > STACK_FIXED_DEPTH) MEM_freeN(iter->stack); iter->stack= newstack; } @@ -775,26 +775,26 @@ static PBVHNode *pbvh_iter_next(PBVHIter *iter) /* purpose here is to traverse tree, visiting child nodes before their * parents, this order is necessary for e.g. computing bounding boxes */ - while(iter->stacksize) { + while (iter->stacksize) { /* pop node */ iter->stacksize--; node= iter->stack[iter->stacksize].node; /* on a mesh with no faces this can happen * can remove this check if we know meshes have at least 1 face */ - if(node==NULL) + if (node==NULL) return NULL; revisiting= iter->stack[iter->stacksize].revisiting; /* revisiting node already checked */ - if(revisiting) + if (revisiting) return node; - if(iter->scb && !iter->scb(node, iter->search_data)) + if (iter->scb && !iter->scb(node, iter->search_data)) continue; /* don't traverse, outside of search zone */ - if(node->flag & PBVH_Leaf) { + if (node->flag & PBVH_Leaf) { /* immediately hit leaf node */ return node; } @@ -815,18 +815,18 @@ static PBVHNode *pbvh_iter_next_occluded(PBVHIter *iter) { PBVHNode *node; - while(iter->stacksize) { + while (iter->stacksize) { /* pop node */ iter->stacksize--; node= iter->stack[iter->stacksize].node; /* on a mesh with no faces this can happen * can remove this check if we know meshes have at least 1 face */ - if(node==NULL) return NULL; + if (node==NULL) return NULL; - if(iter->scb && !iter->scb(node, iter->search_data)) continue; /* don't traverse, outside of search zone */ + if (iter->scb && !iter->scb(node, iter->search_data)) continue; /* don't traverse, outside of search zone */ - if(node->flag & PBVH_Leaf) { + if (node->flag & PBVH_Leaf) { /* immediately hit leaf node */ return node; } @@ -849,14 +849,14 @@ void BLI_pbvh_search_gather(PBVH *bvh, pbvh_iter_begin(&iter, bvh, scb, search_data); - while((node=pbvh_iter_next(&iter))) { - if(node->flag & PBVH_Leaf) { - if(tot == space) { + while ((node=pbvh_iter_next(&iter))) { + if (node->flag & PBVH_Leaf) { + if (tot == space) { /* resize array if needed */ space= (tot == 0)? 32: space*2; newarray= MEM_callocN(sizeof(PBVHNode)*space, "PBVHNodeSearch"); - if(array) { + if (array) { memcpy(newarray, array, sizeof(PBVHNode)*tot); MEM_freeN(array); } @@ -871,7 +871,7 @@ void BLI_pbvh_search_gather(PBVH *bvh, pbvh_iter_end(&iter); - if(tot == 0 && array) { + if (tot == 0 && array) { MEM_freeN(array); array= NULL; } @@ -889,7 +889,7 @@ void BLI_pbvh_search_callback(PBVH *bvh, pbvh_iter_begin(&iter, bvh, scb, search_data); - while((node=pbvh_iter_next(&iter))) + while ((node=pbvh_iter_next(&iter))) if (node->flag & PBVH_Leaf) hcb(node, hit_data); @@ -962,8 +962,8 @@ static void BLI_pbvh_search_callback_occluded(PBVH *bvh, pbvh_iter_begin(&iter, bvh, scb, search_data); - while((node=pbvh_iter_next_occluded(&iter))) { - if(node->flag & PBVH_Leaf) { + while ((node=pbvh_iter_next_occluded(&iter))) { + if (node->flag & PBVH_Leaf) { node_tree* new_node = malloc(sizeof(node_tree)); new_node->data = node; @@ -993,7 +993,7 @@ static int update_search_cb(PBVHNode *node, void *data_v) { int flag= GET_INT_FROM_POINTER(data_v); - if(node->flag & PBVH_Leaf) + if (node->flag & PBVH_Leaf) return (node->flag & flag); return 1; @@ -1005,7 +1005,7 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes, float (*vnor)[3]; int n; - if(bvh->type != PBVH_FACES) + if (bvh->type != PBVH_FACES) return; /* could be per node to save some memory, but also means @@ -1023,32 +1023,32 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes, */ #pragma omp parallel for private(n) schedule(static) - for(n = 0; n < totnode; n++) { + for (n = 0; n < totnode; n++) { PBVHNode *node= nodes[n]; - if((node->flag & PBVH_UpdateNormals)) { + if ((node->flag & PBVH_UpdateNormals)) { int i, j, totface, *faces; faces= node->prim_indices; totface= node->totprim; - for(i = 0; i < totface; ++i) { + for (i = 0; i < totface; ++i) { MFace *f= bvh->faces + faces[i]; float fn[3]; unsigned int *fv = &f->v1; int sides= (f->v4)? 4: 3; - if(f->v4) + if (f->v4) normal_quad_v3(fn, bvh->verts[f->v1].co, bvh->verts[f->v2].co, bvh->verts[f->v3].co, bvh->verts[f->v4].co); else normal_tri_v3(fn, bvh->verts[f->v1].co, bvh->verts[f->v2].co, bvh->verts[f->v3].co); - for(j = 0; j < sides; ++j) { + for (j = 0; j < sides; ++j) { int v= fv[j]; - if(bvh->verts[v].flag & ME_VERT_PBVH_UPDATE) { + if (bvh->verts[v].flag & ME_VERT_PBVH_UPDATE) { /* this seems like it could be very slow but profile * does not show this, so just leave it for now? */ #pragma omp atomic @@ -1060,27 +1060,27 @@ static void pbvh_update_normals(PBVH *bvh, PBVHNode **nodes, } } - if(face_nors) + if (face_nors) copy_v3_v3(face_nors[faces[i]], fn); } } } #pragma omp parallel for private(n) schedule(static) - for(n = 0; n < totnode; n++) { + for (n = 0; n < totnode; n++) { PBVHNode *node= nodes[n]; - if(node->flag & PBVH_UpdateNormals) { + if (node->flag & PBVH_UpdateNormals) { int i, *verts, totvert; verts= node->vert_indices; totvert= node->uniq_verts; - for(i = 0; i < totvert; ++i) { + for (i = 0; i < totvert; ++i) { const int v = verts[i]; MVert *mvert= &bvh->verts[v]; - if(mvert->flag & ME_VERT_PBVH_UPDATE) { + if (mvert->flag & ME_VERT_PBVH_UPDATE) { float no[3]; copy_v3_v3(no, vnor[v]); @@ -1108,17 +1108,17 @@ static void pbvh_update_BB_redraw(PBVH *bvh, PBVHNode **nodes, /* update BB, redraw flag */ #pragma omp parallel for private(n) schedule(static) - for(n = 0; n < totnode; n++) { + for (n = 0; n < totnode; n++) { PBVHNode *node= nodes[n]; - if((flag & PBVH_UpdateBB) && (node->flag & PBVH_UpdateBB)) + if ((flag & PBVH_UpdateBB) && (node->flag & PBVH_UpdateBB)) /* don't clear flag yet, leave it for flushing later */ update_node_vb(bvh, node); - if((flag & PBVH_UpdateOriginalBB) && (node->flag & PBVH_UpdateOriginalBB)) + if ((flag & PBVH_UpdateOriginalBB) && (node->flag & PBVH_UpdateOriginalBB)) node->orig_vb= node->vb; - if((flag & PBVH_UpdateRedraw) && (node->flag & PBVH_UpdateRedraw)) + if ((flag & PBVH_UpdateRedraw) && (node->flag & PBVH_UpdateRedraw)) node->flag &= ~PBVH_UpdateRedraw; } } @@ -1129,12 +1129,12 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) int n; /* can't be done in parallel with OpenGL */ - for(n = 0; n < totnode; n++) { + for (n = 0; n < totnode; n++) { node= nodes[n]; - if(node->flag & PBVH_RebuildDrawBuffers) { + if (node->flag & PBVH_RebuildDrawBuffers) { GPU_free_buffers(node->draw_buffers); - if(bvh->grids) { + if (bvh->grids) { node->draw_buffers = GPU_build_grid_buffers(node->prim_indices, node->totprim, bvh->grid_hidden, bvh->gridsize); @@ -1150,7 +1150,7 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode) node->flag &= ~PBVH_RebuildDrawBuffers; } - if(node->flag & PBVH_UpdateDrawBuffers) { + if (node->flag & PBVH_UpdateDrawBuffers) { switch(bvh->type) { case PBVH_GRIDS: GPU_update_grid_buffers(node->draw_buffers, @@ -1179,13 +1179,13 @@ static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag) int update= 0; /* difficult to multithread well, we just do single threaded recursive */ - if(node->flag & PBVH_Leaf) { - if(flag & PBVH_UpdateBB) { + if (node->flag & PBVH_Leaf) { + if (flag & PBVH_UpdateBB) { update |= (node->flag & PBVH_UpdateBB); node->flag &= ~PBVH_UpdateBB; } - if(flag & PBVH_UpdateOriginalBB) { + if (flag & PBVH_UpdateOriginalBB) { update |= (node->flag & PBVH_UpdateOriginalBB); node->flag &= ~PBVH_UpdateOriginalBB; } @@ -1196,9 +1196,9 @@ static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag) update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset, flag); update |= pbvh_flush_bb(bvh, bvh->nodes + node->children_offset + 1, flag); - if(update & PBVH_UpdateBB) + if (update & PBVH_UpdateBB) update_node_vb(bvh, node); - if(update & PBVH_UpdateOriginalBB) + if (update & PBVH_UpdateOriginalBB) node->orig_vb= node->vb; } @@ -1210,22 +1210,22 @@ void BLI_pbvh_update(PBVH *bvh, int flag, float (*face_nors)[3]) PBVHNode **nodes; int totnode; - if(!bvh->nodes) + if (!bvh->nodes) return; BLI_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(flag), &nodes, &totnode); - if(flag & PBVH_UpdateNormals) + if (flag & PBVH_UpdateNormals) pbvh_update_normals(bvh, nodes, totnode, face_nors); - if(flag & (PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw)) + if (flag & (PBVH_UpdateBB|PBVH_UpdateOriginalBB|PBVH_UpdateRedraw)) pbvh_update_BB_redraw(bvh, nodes, totnode, flag); - if(flag & (PBVH_UpdateBB|PBVH_UpdateOriginalBB)) + if (flag & (PBVH_UpdateBB|PBVH_UpdateOriginalBB)) pbvh_flush_bb(bvh, bvh->nodes, flag); - if(nodes) MEM_freeN(nodes); + if (nodes) MEM_freeN(nodes); } void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]) @@ -1238,8 +1238,8 @@ void BLI_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]) pbvh_iter_begin(&iter, bvh, NULL, NULL); - while((node=pbvh_iter_next(&iter))) - if(node->flag & PBVH_UpdateRedraw) + while ((node=pbvh_iter_next(&iter))) + if (node->flag & PBVH_UpdateRedraw) BB_expand_with_bb(&bb, &node->vb); pbvh_iter_end(&iter); @@ -1262,15 +1262,15 @@ void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot pbvh_iter_begin(&iter, bvh, NULL, NULL); - while((node=pbvh_iter_next(&iter))) { - if(node->flag & PBVH_UpdateNormals) { - for(i = 0; i < node->totprim; ++i) { + while ((node=pbvh_iter_next(&iter))) { + if (node->flag & PBVH_UpdateNormals) { + for (i = 0; i < node->totprim; ++i) { face= bvh->gridfaces[node->prim_indices[i]]; - if(!BLI_ghash_lookup(map, face)) + if (!BLI_ghash_lookup(map, face)) BLI_ghash_insert(map, face, face); } - if(clear) + if (clear) node->flag &= ~PBVH_UpdateNormals; } } @@ -1278,7 +1278,7 @@ void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot pbvh_iter_end(&iter); tot= BLI_ghash_size(map); - if(tot == 0) { + if (tot == 0) { *totface= 0; *gridfaces= NULL; BLI_ghash_free(map, NULL, NULL); @@ -1287,7 +1287,7 @@ void BLI_pbvh_get_grid_updates(PBVH *bvh, int clear, void ***gridfaces, int *tot faces= MEM_callocN(sizeof(void*)*tot, "PBVH Grid Faces"); - for(hiter = BLI_ghashIterator_new(map), i = 0; + for (hiter = BLI_ghashIterator_new(map), i = 0; !BLI_ghashIterator_isDone(hiter); BLI_ghashIterator_step(hiter), ++i) faces[i]= BLI_ghashIterator_getKey(hiter); @@ -1329,7 +1329,7 @@ void BLI_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden) { BLI_assert(node->flag & PBVH_Leaf); - if(fully_hidden) + if (fully_hidden) node->flag |= PBVH_FullyHidden; else node->flag &= ~PBVH_FullyHidden; @@ -1337,8 +1337,8 @@ void BLI_pbvh_node_fully_hidden_set(PBVHNode *node, int fully_hidden) void BLI_pbvh_node_get_verts(PBVH *bvh, PBVHNode *node, int **vert_indices, MVert **verts) { - if(vert_indices) *vert_indices= node->vert_indices; - if(verts) *verts= bvh->verts; + if (vert_indices) *vert_indices= node->vert_indices; + if (verts) *verts= bvh->verts; } void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *totvert) @@ -1348,12 +1348,12 @@ void BLI_pbvh_node_num_verts(PBVH *bvh, PBVHNode *node, int *uniquevert, int *to switch(bvh->type) { case PBVH_GRIDS: tot= node->totprim*bvh->gridsize*bvh->gridsize; - if(totvert) *totvert= tot; - if(uniquevert) *uniquevert= tot; + if (totvert) *totvert= tot; + if (uniquevert) *uniquevert= tot; break; case PBVH_FACES: - if(totvert) *totvert= node->uniq_verts + node->face_verts; - if(uniquevert) *uniquevert= node->uniq_verts; + if (totvert) *totvert= node->uniq_verts + node->face_verts; + if (uniquevert) *uniquevert= node->uniq_verts; break; } } @@ -1362,20 +1362,20 @@ void BLI_pbvh_node_get_grids(PBVH *bvh, PBVHNode *node, int **grid_indices, int { switch(bvh->type) { case PBVH_GRIDS: - if(grid_indices) *grid_indices= node->prim_indices; - if(totgrid) *totgrid= node->totprim; - if(maxgrid) *maxgrid= bvh->totgrid; - if(gridsize) *gridsize= bvh->gridsize; - if(griddata) *griddata= bvh->grids; - if(gridadj) *gridadj= bvh->gridadj; + if (grid_indices) *grid_indices= node->prim_indices; + if (totgrid) *totgrid= node->totprim; + if (maxgrid) *maxgrid= bvh->totgrid; + if (gridsize) *gridsize= bvh->gridsize; + if (griddata) *griddata= bvh->grids; + if (gridadj) *gridadj= bvh->gridadj; break; case PBVH_FACES: - if(grid_indices) *grid_indices= NULL; - if(totgrid) *totgrid= 0; - if(maxgrid) *maxgrid= 0; - if(gridsize) *gridsize= 0; - if(griddata) *griddata= NULL; - if(gridadj) *gridadj= NULL; + if (grid_indices) *grid_indices= NULL; + if (totgrid) *totgrid= 0; + if (maxgrid) *maxgrid= 0; + if (gridsize) *gridsize= 0; + if (griddata) *griddata= NULL; + if (gridadj) *gridadj= NULL; break; } } @@ -1421,7 +1421,7 @@ static int ray_aabb_intersect(PBVHNode *node, void *data_v) float bbox[2][3]; float tmin, tmax, tymin, tymax, tzmin, tzmax; - if(ray->original) + if (ray->original) BLI_pbvh_node_get_original_BB(node, bbox[0], bbox[1]); else BLI_pbvh_node_get_BB(node, bbox[0], bbox[1]); @@ -1432,22 +1432,22 @@ static int ray_aabb_intersect(PBVHNode *node, void *data_v) tymin = (bbox[ray->sign[1]][1] - ray->start[1]) * ray->inv_dir[1]; tymax = (bbox[1-ray->sign[1]][1] - ray->start[1]) * ray->inv_dir[1]; - if((tmin > tymax) || (tymin > tmax)) + if ((tmin > tymax) || (tymin > tmax)) return 0; - if(tymin > tmin) + if (tymin > tmin) tmin = tymin; - if(tymax < tmax) + if (tymax < tmax) tmax = tymax; tzmin = (bbox[ray->sign[2]][2] - ray->start[2]) * ray->inv_dir[2]; tzmax = (bbox[1-ray->sign[2]][2] - ray->start[2]) * ray->inv_dir[2]; - if((tmin > tzmax) || (tzmin > tmax)) + if ((tmin > tzmax) || (tzmin > tmax)) return 0; - if(tzmin > tmin) + if (tzmin > tmin) tmin = tzmin; // XXX jwilkins: tmax does not need to be updated since we don't use it @@ -1501,7 +1501,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], int *faces, totface, gridsize, totgrid; int i, x, y, hit= 0; - if(node->flag & PBVH_FullyHidden) + if (node->flag & PBVH_FullyHidden) return 0; switch(bvh->type) { @@ -1510,14 +1510,14 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], faces= node->prim_indices; totface= node->totprim; - for(i = 0; i < totface; ++i) { + for (i = 0; i < totface; ++i) { const MFace *f = bvh->faces + faces[i]; int *face_verts = node->face_vert_indices[i]; - if(paint_is_face_hidden(f, vert)) + if (paint_is_face_hidden(f, vert)) continue; - if(origco) { + if (origco) { /* intersect with backuped original coordinates */ hit |= ray_face_intersection(ray_start, ray_normal, origco[face_verts[0]], @@ -1541,22 +1541,22 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], totgrid= node->totprim; gridsize= bvh->gridsize; - for(i = 0; i < totgrid; ++i) { + for (i = 0; i < totgrid; ++i) { DMGridData *grid= bvh->grids[node->prim_indices[i]]; if (!grid) continue; gh= bvh->grid_hidden[node->prim_indices[i]]; - for(y = 0; y < gridsize-1; ++y) { - for(x = 0; x < gridsize-1; ++x) { + for (y = 0; y < gridsize-1; ++y) { + for (x = 0; x < gridsize-1; ++x) { /* check if grid face is hidden */ - if(gh) { - if(paint_is_grid_face_hidden(gh, gridsize, x, y)) + if (gh) { + if (paint_is_grid_face_hidden(gh, gridsize, x, y)) continue; } - if(origco) { + if (origco) { hit |= ray_face_intersection(ray_start, ray_normal, origco[y*gridsize + x], origco[y*gridsize + x+1], @@ -1575,7 +1575,7 @@ int BLI_pbvh_node_raycast(PBVH *bvh, PBVHNode *node, float (*origco)[3], } } - if(origco) + if (origco) origco += gridsize*gridsize; } break; @@ -1592,12 +1592,12 @@ void BLI_pbvh_node_draw(PBVHNode *node, void *setMaterial) /* XXX: Just some quick code to show leaf nodes in different colors */ float col[3]; int i; - if(0) { //is_partial) { + if (0) { //is_partial) { col[0] = (rand() / (float)RAND_MAX); col[1] = col[2] = 0.6; } else { srand((long long)node); - for(i = 0; i < 3; ++i) + for (i = 0; i < 3; ++i) col[i] = (rand() / (float)RAND_MAX) * 0.3 + 0.7; } glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, col); @@ -1605,7 +1605,7 @@ void BLI_pbvh_node_draw(PBVHNode *node, void *setMaterial) glColor3f(1, 0, 0); #endif - if(!(node->flag & PBVH_FullyHidden)) + if (!(node->flag & PBVH_FullyHidden)) GPU_draw_buffers(node->draw_buffers, setMaterial); } @@ -1628,9 +1628,9 @@ static PlaneAABBIsect test_planes_aabb(const float bb_min[3], PlaneAABBIsect ret = ISECT_INSIDE; int i, axis; - for(i = 0; i < 4; ++i) { - for(axis = 0; axis < 3; ++axis) { - if(planes[i][axis] > 0) { + for (i = 0; i < 4; ++i) { + for (axis = 0; axis < 3; ++axis) { + if (planes[i][axis] > 0) { vmin[axis] = bb_min[axis]; vmax[axis] = bb_max[axis]; } @@ -1640,9 +1640,9 @@ static PlaneAABBIsect test_planes_aabb(const float bb_min[3], } } - if(dot_v3v3(planes[i], vmin) + planes[i][3] > 0) + if (dot_v3v3(planes[i], vmin) + planes[i][3] > 0) return ISECT_OUTSIDE; - else if(dot_v3v3(planes[i], vmax) + planes[i][3] >= 0) + else if (dot_v3v3(planes[i], vmax) + planes[i][3] >= 0) ret = ISECT_INTERSECT; } @@ -1677,9 +1677,9 @@ void BLI_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3], pbvh_update_normals(bvh, nodes, totnode, face_nors); pbvh_update_draw_buffers(bvh, nodes, totnode); - if(nodes) MEM_freeN(nodes); + if (nodes) MEM_freeN(nodes); - if(planes) { + if (planes) { BLI_pbvh_search_callback(bvh, BLI_pbvh_node_planes_contain_AABB, planes, BLI_pbvh_node_draw, setMaterial); } @@ -1812,8 +1812,8 @@ void BLI_pbvh_gather_proxies(PBVH* pbvh, PBVHNode*** r_array, int* r_tot) for (n= 0; n < pbvh->totnode; n++) { node = pbvh->nodes + n; - if(node->proxy_count > 0) { - if(tot == space) { + if (node->proxy_count > 0) { + if (tot == space) { /* resize array if needed */ space= (tot == 0)? 32: space*2; newarray= MEM_callocN(sizeof(PBVHNode)*space, "BLI_pbvh_gather_proxies"); @@ -1831,7 +1831,7 @@ void BLI_pbvh_gather_proxies(PBVH* pbvh, PBVHNode*** r_array, int* r_tot) } } - if(tot == 0 && array) { + if (tot == 0 && array) { MEM_freeN(array); array= NULL; } @@ -1862,7 +1862,7 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node, vi->totgrid= (grids)? totgrid: 1; vi->gridsize= gridsize; - if(mode == PBVH_ITER_ALL) + if (mode == PBVH_ITER_ALL) vi->totvert = totvert; else vi->totvert= uniq_verts; @@ -1870,6 +1870,6 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node, vi->mverts= verts; vi->gh= NULL; - if(vi->grids && mode == PBVH_ITER_UNIQUE) + if (vi->grids && mode == PBVH_ITER_UNIQUE) vi->grid_hidden= bvh->grid_hidden; } diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 6114ffdda80..20f0a11f75f 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -121,7 +121,7 @@ void rng_shuffleArray(RNG *rng, void *data, int elemSize, int numElems) while (--i) { int j = rng_getInt(rng)%numElems; - if(i!=j) { + if (i!=j) { void *iElem = (unsigned char*)data + i*elemSize; void *jElem = (unsigned char*)data + j*elemSize; memcpy(temp, iElem, elemSize); @@ -137,7 +137,7 @@ void rng_skip(RNG *rng, int n) { int i; - for(i=0; i= BLENDER_MAX_THREADS) + if (thread >= BLENDER_MAX_THREADS) thread= 0; rng_seed(&rng_tab[thread], seed + hash[seed & 255]); diff --git a/source/blender/blenlib/intern/scanfill.c b/source/blender/blenlib/intern/scanfill.c index 420481f165b..90031d961c3 100644 --- a/source/blender/blenlib/intern/scanfill.c +++ b/source/blender/blenlib/intern/scanfill.c @@ -72,7 +72,8 @@ static int callLocalInterruptCallBack(void) { if (BLI_localInterruptCallBack) { return BLI_localInterruptCallBack(); - } else { + } + else { return 0; } } @@ -110,10 +111,10 @@ static int vergscdata(const void *a1, const void *a2) { const ScanFillVertLink *x1=a1,*x2=a2; - if( x1->v1->co[coy] < x2->v1->co[coy] ) return 1; - else if( x1->v1->co[coy] > x2->v1->co[coy]) return -1; - else if( x1->v1->co[cox] > x2->v1->co[cox] ) return 1; - else if( x1->v1->co[cox] < x2->v1->co[cox]) return -1; + if ( x1->v1->co[coy] < x2->v1->co[coy] ) return 1; + else if ( x1->v1->co[coy] > x2->v1->co[coy]) return -1; + else if ( x1->v1->co[cox] > x2->v1->co[cox] ) return 1; + else if ( x1->v1->co[cox] < x2->v1->co[cox]) return -1; return 0; } @@ -122,10 +123,10 @@ static int vergpoly(const void *a1, const void *a2) { const PolyFill *x1=a1, *x2=a2; - if( x1->min[cox] > x2->min[cox] ) return 1; - else if( x1->min[cox] < x2->min[cox] ) return -1; - else if( x1->min[coy] > x2->min[coy] ) return 1; - else if( x1->min[coy] < x2->min[coy] ) return -1; + if ( x1->min[cox] > x2->min[cox] ) return 1; + else if ( x1->min[cox] < x2->min[cox] ) return -1; + else if ( x1->min[coy] > x2->min[coy] ) return 1; + else if ( x1->min[coy] < x2->min[coy] ) return -1; return 0; } @@ -153,7 +154,7 @@ static void *mem_element_new(int size) size = (size + 3 ) & ~3; /* allocate in units of 4 */ - if(melem__cur && (size + melem__offs < MEM_ELEM_BLOCKSIZE)) { + if (melem__cur && (size + melem__offs < MEM_ELEM_BLOCKSIZE)) { void *adr= (void *) (melem__cur->data+melem__offs); melem__offs+= size; return adr; @@ -171,13 +172,13 @@ static void mem_element_reset(int keep_first) { struct mem_elements *first; - if((first= melem__lb.first)) { /* can be false if first fill fails */ + if ((first= melem__lb.first)) { /* can be false if first fill fails */ if (keep_first) { BLI_remlink(&melem__lb, first); } melem__cur= melem__lb.first; - while(melem__cur) { + while (melem__cur) { MEM_freeN(melem__cur->data); melem__cur= melem__cur->next; } @@ -261,20 +262,20 @@ static int boundisect(PolyFill *pf2, PolyFill *pf1) /* has pf2 been touched (intersected) by pf1 ? with bounding box */ /* test first if polys exist */ - if(pf1->edges==0 || pf2->edges==0) return 0; + if (pf1->edges==0 || pf2->edges==0) return 0; - if(pf2->max[cox] < pf1->min[cox] ) return 0; - if(pf2->max[coy] < pf1->min[coy] ) return 0; + if (pf2->max[cox] < pf1->min[cox] ) return 0; + if (pf2->max[coy] < pf1->min[coy] ) return 0; - if(pf2->min[cox] > pf1->max[cox] ) return 0; - if(pf2->min[coy] > pf1->max[coy] ) return 0; + if (pf2->min[cox] > pf1->max[cox] ) return 0; + if (pf2->min[coy] > pf1->max[coy] ) return 0; /* join */ - if(pf2->max[cox]max[cox]) pf2->max[cox]= pf1->max[cox]; - if(pf2->max[coy]max[coy]) pf2->max[coy]= pf1->max[coy]; + if (pf2->max[cox]max[cox]) pf2->max[cox]= pf1->max[cox]; + if (pf2->max[coy]max[coy]) pf2->max[coy]= pf1->max[coy]; - if(pf2->min[cox]>pf1->min[cox]) pf2->min[cox]= pf1->min[cox]; - if(pf2->min[coy]>pf1->min[coy]) pf2->min[coy]= pf1->min[coy]; + if (pf2->min[cox]>pf1->min[cox]) pf2->min[cox]= pf1->min[cox]; + if (pf2->min[coy]>pf1->min[coy]) pf2->min[coy]= pf1->min[coy]; return 1; } @@ -287,12 +288,12 @@ static void mergepolysSimp(PolyFill *pf1, PolyFill *pf2) /* add pf2 to pf1 */ /* replace old poly numbers */ eve= fillvertbase.first; - while(eve) { - if(eve->poly_nr == pf2->nr) eve->poly_nr = pf1->nr; + while (eve) { + if (eve->poly_nr == pf2->nr) eve->poly_nr = pf1->nr; eve= eve->next; } eed= filledgebase.first; - while(eed) { + while (eed) { if (eed->poly_nr == pf2->nr) eed->poly_nr = pf1->nr; eed= eed->next; } @@ -311,10 +312,10 @@ static short testedgeside(const float v1[3], const float v2[3], const float v3[3 inp= (v2[cox]-v1[cox])*(v1[coy]-v3[coy]) +(v1[coy]-v2[coy])*(v1[cox]-v3[cox]); - if(inp < 0.0f) return 0; - else if(inp==0) { - if(v1[cox]==v3[cox] && v1[coy]==v3[coy]) return 0; - if(v2[cox]==v3[cox] && v2[coy]==v3[coy]) return 0; + if (inp < 0.0f) return 0; + else if (inp==0) { + if (v1[cox]==v3[cox] && v1[coy]==v3[coy]) return 0; + if (v2[cox]==v3[cox] && v2[coy]==v3[coy]) return 0; } return 1; } @@ -325,7 +326,7 @@ static short addedgetoscanvert(ScanFillVertLink *sc, ScanFillEdge *eed) ScanFillEdge *ed; float fac,fac1,x,y; - if(sc->first==0) { + if (sc->first==0) { sc->first= sc->last= eed; eed->prev= eed->next=0; return 1; @@ -335,28 +336,28 @@ static short addedgetoscanvert(ScanFillVertLink *sc, ScanFillEdge *eed) y= eed->v1->co[coy]; fac1= eed->v2->co[coy]-y; - if(fac1==0.0f) { + if (fac1==0.0f) { fac1= 1.0e10f*(eed->v2->co[cox]-x); } else fac1= (x-eed->v2->co[cox])/fac1; ed= sc->first; - while(ed) { + while (ed) { - if(ed->v2==eed->v2) return 0; + if (ed->v2==eed->v2) return 0; fac= ed->v2->co[coy]-y; - if(fac==0.0f) { + if (fac==0.0f) { fac= 1.0e10f*(ed->v2->co[cox]-x); } else fac= (x-ed->v2->co[cox])/fac; - if(fac>fac1) break; + if (fac>fac1) break; ed= ed->next; } - if(ed) BLI_insertlinkbefore((ListBase *)&(sc->first), ed, eed); + if (ed) BLI_insertlinkbefore((ListBase *)&(sc->first), ed, eed); else BLI_addtail((ListBase *)&(sc->first),eed); return 1; @@ -371,14 +372,14 @@ static ScanFillVertLink *addedgetoscanlist(ScanFillEdge *eed, int len) ScanFillVert *eve; /* which vert is left-top? */ - if(eed->v1->co[coy] == eed->v2->co[coy]) { - if(eed->v1->co[cox] > eed->v2->co[cox]) { + if (eed->v1->co[coy] == eed->v2->co[coy]) { + if (eed->v1->co[cox] > eed->v2->co[cox]) { eve= eed->v1; eed->v1= eed->v2; eed->v2= eve; } } - else if(eed->v1->co[coy] < eed->v2->co[coy]) { + else if (eed->v1->co[coy] < eed->v2->co[coy]) { eve= eed->v1; eed->v1= eed->v2; eed->v2= eve; @@ -388,8 +389,8 @@ static ScanFillVertLink *addedgetoscanlist(ScanFillEdge *eed, int len) sc= (ScanFillVertLink *)bsearch(&scsearch,scdata,len, sizeof(ScanFillVertLink), vergscdata); - if(sc==0) printf("Error in search edge: %p\n", (void *)eed); - else if(addedgetoscanvert(sc,eed)==0) return sc; + if (sc==0) printf("Error in search edge: %p\n", (void *)eed); + else if (addedgetoscanvert(sc,eed)==0) return sc; return 0; } @@ -399,22 +400,24 @@ static short boundinsideEV(ScanFillEdge *eed, ScanFillVert *eve) { float minx,maxx,miny,maxy; - if(eed->v1->co[cox]v2->co[cox]) { + if (eed->v1->co[cox]v2->co[cox]) { minx= eed->v1->co[cox]; maxx= eed->v2->co[cox]; - } else { + } + else { minx= eed->v2->co[cox]; maxx= eed->v1->co[cox]; } - if(eve->co[cox]>=minx && eve->co[cox]<=maxx) { - if(eed->v1->co[coy]v2->co[coy]) { + if (eve->co[cox]>=minx && eve->co[cox]<=maxx) { + if (eed->v1->co[coy]v2->co[coy]) { miny= eed->v1->co[coy]; maxy= eed->v2->co[coy]; - } else { + } + else { miny= eed->v2->co[coy]; maxy= eed->v1->co[coy]; } - if(eve->co[coy]>=miny && eve->co[coy]<=maxy) return 1; + if (eve->co[coy]>=miny && eve->co[coy]<=maxy) return 1; } return 0; } @@ -430,30 +433,30 @@ static void testvertexnearedge(void) float dist,vec1[2],vec2[2],vec3[2]; eve= fillvertbase.first; - while(eve) { - if(eve->h==1) { + while (eve) { + if (eve->h==1) { vec3[0]= eve->co[cox]; vec3[1]= eve->co[coy]; /* find the edge which has vertex eve */ ed1= filledgebase.first; - while(ed1) { - if(ed1->v1==eve || ed1->v2==eve) break; + while (ed1) { + if (ed1->v1==eve || ed1->v2==eve) break; ed1= ed1->next; } - if(ed1->v1==eve) { + if (ed1->v1==eve) { ed1->v1= ed1->v2; ed1->v2= eve; } eed= filledgebase.first; - while(eed) { + while (eed) { if (eve != eed->v1 && eve != eed->v2 && eve->poly_nr == eed->poly_nr) { - if(compare_v3v3(eve->co,eed->v1->co, COMPLIMIT)) { + if (compare_v3v3(eve->co,eed->v1->co, COMPLIMIT)) { ed1->v2= eed->v1; eed->v1->h++; eve->h= 0; break; } - else if(compare_v3v3(eve->co,eed->v2->co, COMPLIMIT)) { + else if (compare_v3v3(eve->co,eed->v2->co, COMPLIMIT)) { ed1->v2= eed->v2; eed->v2->h++; eve->h= 0; @@ -464,9 +467,9 @@ static void testvertexnearedge(void) vec1[1]= eed->v1->co[coy]; vec2[0]= eed->v2->co[cox]; vec2[1]= eed->v2->co[coy]; - if(boundinsideEV(eed,eve)) { + if (boundinsideEV(eed,eve)) { dist= dist_to_line_v2(vec1,vec2,vec3); - if(dist<(float)COMPLIMIT) { + if (dist<(float)COMPLIMIT) { /* new edge */ ed1= BLI_addfilledge(eed->v1, eve); @@ -497,7 +500,7 @@ static void splitlist(ListBase *tempve, ListBase *temped, short nr) BLI_movelisttolist(temped,&filledgebase); eve= tempve->first; - while(eve) { + while (eve) { nextve= eve->next; if (eve->poly_nr == nr) { BLI_remlink(tempve,eve); @@ -506,9 +509,9 @@ static void splitlist(ListBase *tempve, ListBase *temped, short nr) eve= nextve; } eed= temped->first; - while(eed) { + while (eed) { nexted= eed->next; - if(eed->poly_nr==nr) { + if (eed->poly_nr==nr) { BLI_remlink(temped,eed); BLI_addtail(&filledgebase,eed); } @@ -532,12 +535,12 @@ static int scanfill(PolyFill *pf) #if 0 verts= pf->verts; eve= fillvertbase.first; - while(eve) { + while (eve) { printf("vert: %x co: %f %f\n",eve,eve->co[cox],eve->co[coy]); eve= eve->next; } eed= filledgebase.first; - while(eed) { + while (eed) { printf("edge: %x verts: %x %x\n",eed,eed->v1,eed->v2); eed= eed->next; } @@ -545,18 +548,18 @@ static int scanfill(PolyFill *pf) /* STEP 0: remove zero sized edges */ eed= filledgebase.first; - while(eed) { - if(eed->v1->co[cox]==eed->v2->co[cox]) { - if(eed->v1->co[coy]==eed->v2->co[coy]) { - if(eed->v1->f==255 && eed->v2->f!=255) { + while (eed) { + if (eed->v1->co[cox]==eed->v2->co[cox]) { + if (eed->v1->co[coy]==eed->v2->co[coy]) { + if (eed->v1->f==255 && eed->v2->f!=255) { eed->v2->f= 255; eed->v2->tmp.v= eed->v1->tmp.v; } - else if(eed->v2->f==255 && eed->v1->f!=255) { + else if (eed->v2->f==255 && eed->v1->f!=255) { eed->v1->f= 255; eed->v1->tmp.v= eed->v2->tmp.v; } - else if(eed->v2->f==255 && eed->v1->f==255) { + else if (eed->v2->f==255 && eed->v1->f==255) { eed->v1->tmp.v= eed->v2->tmp.v; } else { @@ -574,7 +577,7 @@ static int scanfill(PolyFill *pf) sc= scdata= (ScanFillVertLink *)MEM_callocN(pf->verts*sizeof(ScanFillVertLink),"Scanfill1"); eve= fillvertbase.first; verts= 0; - while(eve) { + while (eve) { if (eve->poly_nr == nr) { if (eve->f != 255) { verts++; @@ -589,7 +592,7 @@ static int scanfill(PolyFill *pf) qsort(scdata, verts, sizeof(ScanFillVertLink), vergscdata); eed= filledgebase.first; - while(eed) { + while (eed) { nexted= eed->next; BLI_remlink(&filledgebase,eed); /* This code is for handling zero-length edges that get @@ -597,26 +600,26 @@ static int scanfill(PolyFill *pf) * fix trunk bug #4544, so if that comes back, this code * may need some work, or there will have to be a better * fix to #4544. */ - if(eed->v1->f==255) { + if (eed->v1->f==255) { v1= eed->v1; - while((eed->v1->f == 255) && (eed->v1->tmp.v != v1)) + while ((eed->v1->f == 255) && (eed->v1->tmp.v != v1)) eed->v1 = eed->v1->tmp.v; } - if(eed->v2->f==255) { + if (eed->v2->f==255) { v2= eed->v2; - while((eed->v2->f == 255) && (eed->v2->tmp.v != v2)) + while ((eed->v2->f == 255) && (eed->v2->tmp.v != v2)) eed->v2 = eed->v2->tmp.v; } - if(eed->v1!=eed->v2) addedgetoscanlist(eed,verts); + if (eed->v1!=eed->v2) addedgetoscanlist(eed,verts); eed= nexted; } #if 0 sc= scdata; - for(a=0;av1); eed= sc->first; - while(eed) { + while (eed) { printf(" ed %x %x %x\n",eed,eed->v1,eed->v2); eed= eed->next; } @@ -627,66 +630,67 @@ static int scanfill(PolyFill *pf) /* STEP 2: FILL LOOP */ - if(pf->f==0) twoconnected= 1; + if (pf->f==0) twoconnected= 1; /* (temporal) security: never much more faces than vertices */ totface= 0; maxface= 2*verts; /* 2*verts: based at a filled circle within a triangle */ sc= scdata; - for(a=0;av1); */ ed1= sc->first; - while(ed1) { /* set connectflags */ + while (ed1) { /* set connectflags */ nexted= ed1->next; - if(ed1->v1->h==1 || ed1->v2->h==1) { + if (ed1->v1->h==1 || ed1->v2->h==1) { BLI_remlink((ListBase *)&(sc->first),ed1); BLI_addtail(&filledgebase,ed1); - if(ed1->v1->h>1) ed1->v1->h--; - if(ed1->v2->h>1) ed1->v2->h--; + if (ed1->v1->h>1) ed1->v1->h--; + if (ed1->v2->h>1) ed1->v2->h--; } else ed1->v2->f= 1; ed1= nexted; } - while(sc->first) { /* for as long there are edges */ + while (sc->first) { /* for as long there are edges */ ed1= sc->first; ed2= ed1->next; /* commented out... the ESC here delivers corrupted memory (and doesnt work during grab) */ /* if(callLocalInterruptCallBack()) break; */ - if(totface>maxface) { + if (totface>maxface) { /* printf("Fill error: endless loop. Escaped at vert %d, tot: %d.\n", a, verts); */ a= verts; break; } - if(ed2==0) { + if (ed2==0) { sc->first=sc->last= 0; /* printf("just 1 edge to vert\n"); */ BLI_addtail(&filledgebase,ed1); ed1->v2->f= 0; ed1->v1->h--; ed1->v2->h--; - } else { + } + else { /* test rest of vertices */ v1= ed1->v2; v2= ed1->v1; v3= ed2->v2; /* this happens with a serial of overlapping edges */ - if(v1==v2 || v2==v3) break; + if (v1==v2 || v2==v3) break; /* printf("test verts %x %x %x\n",v1,v2,v3); */ miny = ( (v1->co[coy])<(v3->co[coy]) ? (v1->co[coy]) : (v3->co[coy]) ); /* miny= MIN2(v1->co[coy],v3->co[coy]); */ sc1= sc+1; test= 0; - for(b=a+1;bv1->f==0) { - if(sc1->v1->co[coy] <= miny) break; + for (b=a+1;bv1->f==0) { + if (sc1->v1->co[coy] <= miny) break; - if(testedgeside(v1->co,v2->co,sc1->v1->co)) - if(testedgeside(v2->co,v3->co,sc1->v1->co)) - if(testedgeside(v3->co,v1->co,sc1->v1->co)) { + if (testedgeside(v1->co,v2->co,sc1->v1->co)) + if (testedgeside(v2->co,v3->co,sc1->v1->co)) + if (testedgeside(v3->co,v1->co,sc1->v1->co)) { /* point in triangle */ test= 1; @@ -695,7 +699,7 @@ static int scanfill(PolyFill *pf) } sc1++; } - if(test) { + if (test) { /* make new edge, and start over */ /* printf("add new edge %x %x and start again\n",v2,sc1->v1); */ @@ -718,7 +722,7 @@ static int scanfill(PolyFill *pf) ed1->v1->h--; ed1->v2->h--; /* ed2 can be removed when it's a boundary edge */ - if((ed2->f == 0 && twoconnected) || (ed2->f == FILLBOUNDARY)) { + if ((ed2->f == 0 && twoconnected) || (ed2->f == FILLBOUNDARY)) { BLI_remlink((ListBase *)&(sc->first),ed2); BLI_addtail(&filledgebase,ed2); ed2->v2->f= 0; @@ -736,14 +740,14 @@ static int scanfill(PolyFill *pf) /* printf("add new edge %x %x\n",v1,v3); */ sc1= addedgetoscanlist(ed3, verts); - if(sc1) { /* ed3 already exists: remove if a boundary */ + if (sc1) { /* ed3 already exists: remove if a boundary */ /* printf("Edge exists\n"); */ ed3->v1->h--; ed3->v2->h--; ed3= sc1->first; - while(ed3) { - if( (ed3->v1==v1 && ed3->v2==v3) || (ed3->v1==v3 && ed3->v2==v1) ) { + while (ed3) { + if ( (ed3->v1==v1 && ed3->v2==v3) || (ed3->v1==v3 && ed3->v2==v1) ) { if (twoconnected || ed3->f==FILLBOUNDARY) { BLI_remlink((ListBase *)&(sc1->first),ed3); BLI_addtail(&filledgebase,ed3); @@ -760,13 +764,13 @@ static int scanfill(PolyFill *pf) } /* test for loose edges */ ed1= sc->first; - while(ed1) { + while (ed1) { nexted= ed1->next; - if(ed1->v1->h<2 || ed1->v2->h<2) { + if (ed1->v1->h<2 || ed1->v2->h<2) { BLI_remlink((ListBase *)&(sc->first),ed1); BLI_addtail(&filledgebase,ed1); - if(ed1->v1->h>1) ed1->v1->h--; - if(ed1->v2->h>1) ed1->v2->h--; + if (ed1->v1->h>1) ed1->v1->h--; + if (ed1->v2->h>1) ed1->v2->h--; } ed1= nexted; @@ -809,7 +813,7 @@ int BLI_edgefill(short mat_nr) /* reset variables */ eve= fillvertbase.first; a = 0; - while(eve) { + while (eve) { eve->f= 0; eve->poly_nr= 0; eve->h= 0; @@ -822,7 +826,8 @@ int BLI_edgefill(short mat_nr) addfillface(eve, eve->next, eve->next->next); return 1; - } else if (a == 4 && (mat_nr & 2)) { + } + else if (a == 4 && (mat_nr & 2)) { float vec1[3], vec2[3]; eve = fillvertbase.first; @@ -835,11 +840,13 @@ int BLI_edgefill(short mat_nr) if (dot_v3v3(vec1, vec1) < dot_v3v3(vec2, vec2)) { addfillface(eve, eve->next, eve->next->next); addfillface(eve->next->next, eve->next->next->next, eve); - } else{ + } + else { addfillface(eve->next, eve->next->next, eve->next->next->next); addfillface(eve->next->next->next, eve, eve->next); } - } else { + } + else { addfillface(eve, eve->next, eve->next->next); addfillface(eve->next->next, eve->next->next->next, eve); } @@ -849,7 +856,7 @@ int BLI_edgefill(short mat_nr) /* first test vertices if they are in edges */ /* including resetting of flags */ eed= filledgebase.first; - while(eed) { + while (eed) { eed->poly_nr= 0; eed->v1->f= 1; eed->v2->f= 1; @@ -858,15 +865,15 @@ int BLI_edgefill(short mat_nr) } eve= fillvertbase.first; - while(eve) { - if(eve->f & 1) { + while (eve) { + if (eve->f & 1) { ok=1; break; } eve= eve->next; } - if(ok==0) return 0; + if (ok==0) return 0; /* NEW NEW! define projection: with 'best' normal */ /* just use the first three different vertices */ @@ -880,31 +887,31 @@ int BLI_edgefill(short mat_nr) eve= fillvertbase.first; limit = 1e-8f; - while(eve) { - if(v2) { - if(!compare_v3v3(v2, eve->co, COMPLIMIT)) { + while (eve) { + if (v2) { + if (!compare_v3v3(v2, eve->co, COMPLIMIT)) { float inner = angle_v3v3v3(v1, v2, eve->co); inner = MIN2(fabsf(inner), fabsf(M_PI - inner)); - if(inner > limit) { + if (inner > limit) { limit = inner; len= normal_tri_v3(norm, v1, v2, eve->co); } } } - else if(!compare_v3v3(v1, eve->co, COMPLIMIT)) + else if (!compare_v3v3(v1, eve->co, COMPLIMIT)) v2= eve->co; eve= eve->next; } - if(len==0.0f) return 0; /* no fill possible */ + if (len==0.0f) return 0; /* no fill possible */ axis_dominant_v3(&cox, &coy, norm); /* STEP 1: COUNT POLYS */ eve= fillvertbase.first; - while(eve) { + while (eve) { /* get first vertex with no poly number */ if (eve->poly_nr==0) { poly++; @@ -912,14 +919,14 @@ int BLI_edgefill(short mat_nr) ok= 1; eve->poly_nr = poly; - while(ok) { + while (ok) { ok= 0; toggle++; - if(toggle & 1) eed= filledgebase.first; + if (toggle & 1) eed= filledgebase.first; else eed= filledgebase.last; - while(eed) { + while (eed) { if (eed->v1->poly_nr == 0 && eed->v2->poly_nr == poly) { eed->v1->poly_nr = poly; eed->poly_nr= poly; @@ -936,7 +943,7 @@ int BLI_edgefill(short mat_nr) ok= 1; } } - if(toggle & 1) eed= eed->next; + if (toggle & 1) eed= eed->next; else eed= eed->prev; } } @@ -947,12 +954,12 @@ int BLI_edgefill(short mat_nr) /* STEP 2: remove loose edges and strings of edges */ eed= filledgebase.first; - while(eed) { - if(eed->v1->h++ >250) break; - if(eed->v2->h++ >250) break; + while (eed) { + if (eed->v1->h++ >250) break; + if (eed->v2->h++ >250) break; eed= eed->next; } - if(eed) { + if (eed) { /* otherwise it's impossible to be sure you can clear vertices */ callLocalErrorCallBack("No vertices with 250 edges allowed!"); return 0; @@ -962,21 +969,21 @@ int BLI_edgefill(short mat_nr) testvertexnearedge(); ok= 1; - while(ok) { + while (ok) { ok= 0; toggle++; - if(toggle & 1) eed= filledgebase.first; + if (toggle & 1) eed= filledgebase.first; else eed= filledgebase.last; - while(eed) { - if(toggle & 1) nexted= eed->next; + while (eed) { + if (toggle & 1) nexted= eed->next; else nexted= eed->prev; - if(eed->v1->h==1) { + if (eed->v1->h==1) { eed->v2->h--; BLI_remlink(&fillvertbase,eed->v1); BLI_remlink(&filledgebase,eed); ok= 1; } - else if(eed->v2->h==1) { + else if (eed->v2->h==1) { eed->v1->h--; BLI_remlink(&fillvertbase,eed->v2); BLI_remlink(&filledgebase,eed); @@ -985,7 +992,7 @@ int BLI_edgefill(short mat_nr) eed= nexted; } } - if(filledgebase.first==0) { + if (filledgebase.first==0) { /* printf("All edges removed\n"); */ return 0; } @@ -1005,20 +1012,20 @@ int BLI_edgefill(short mat_nr) /* STEP 3: MAKE POLYFILL STRUCT */ pflist= (PolyFill *)MEM_callocN(poly*sizeof(PolyFill),"edgefill"); pf= pflist; - for(a=1;a<=poly;a++) { + for (a=1;a<=poly;a++) { pf->nr= a; pf->min[0]=pf->min[1]=pf->min[2]= 1.0e20; pf->max[0]=pf->max[1]=pf->max[2]= -1.0e20; pf++; } eed= filledgebase.first; - while(eed) { + while (eed) { pflist[eed->poly_nr-1].edges++; eed= eed->next; } eve= fillvertbase.first; - while(eve) { + while (eve) { pflist[eve->poly_nr-1].verts++; minp= pflist[eve->poly_nr-1].min; maxp= pflist[eve->poly_nr-1].max; @@ -1027,7 +1034,7 @@ int BLI_edgefill(short mat_nr) minp[coy]= (minp[coy])<(eve->co[coy]) ? (minp[coy]) : (eve->co[coy]); maxp[cox]= (maxp[cox])>(eve->co[cox]) ? (maxp[cox]) : (eve->co[cox]); maxp[coy]= (maxp[coy])>(eve->co[coy]) ? (maxp[coy]) : (eve->co[coy]); - if(eve->h > 2) pflist[eve->poly_nr-1].f = 1; + if (eve->h > 2) pflist[eve->poly_nr-1].f = 1; eve= eve->next; } @@ -1037,7 +1044,7 @@ int BLI_edgefill(short mat_nr) * the edgefill itself has good auto-hole detection) * WATCH IT: ONLY WORKS WITH SORTED POLYS!!! */ - if(poly>1) { + if (poly>1) { short *polycache, *pc; /* so, sort first */ @@ -1045,7 +1052,7 @@ int BLI_edgefill(short mat_nr) #if 0 pf= pflist; - for(a=1;a<=poly;a++) { + for (a=1;a<=poly;a++) { printf("poly:%d edges:%d verts:%d flag: %d\n",a,pf->edges,pf->verts,pf->f); PRINT2(f, f, pf->min[0], pf->min[1]); pf++; @@ -1054,21 +1061,21 @@ int BLI_edgefill(short mat_nr) polycache= pc= MEM_callocN(sizeof(short)*poly, "polycache"); pf= pflist; - for(a=0; amax[cox] < (pflist+c)->min[cox]) break; */ + /* else if (pf->max[cox] < (pflist+c)->min[cox]) break; */ } - while(pc!=polycache) { + while (pc!=polycache) { pc--; mergepolysSimp(pf, pflist+ *pc); } @@ -1079,7 +1086,7 @@ int BLI_edgefill(short mat_nr) #if 0 printf("after merge\n"); pf= pflist; - for(a=1;a<=poly;a++) { + for (a=1;a<=poly;a++) { printf("poly:%d edges:%d verts:%d flag: %d\n",a,pf->edges,pf->verts,pf->f); pf++; } @@ -1095,8 +1102,8 @@ int BLI_edgefill(short mat_nr) filledgebase.first=filledgebase.last= 0; pf= pflist; - for(a=0;aedges>1) { + for (a=0;aedges>1) { splitlist(&tempve,&temped,pf->nr); totfaces += scanfill(pf); } diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 363052c7255..cce1d2136e2 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -123,22 +123,24 @@ static int bli_compare(struct direntry *entry1, struct direntry *entry2) if (S_ISDIR(entry1->type)) { if (S_ISDIR(entry2->type)==0) return (-1); - } else{ + } + else { if (S_ISDIR(entry2->type)) return (1); } if (S_ISREG(entry1->type)) { if (S_ISREG(entry2->type)==0) return (-1); - } else{ + } + else { if (S_ISREG(entry2->type)) return (1); } if ((entry1->type & S_IFMT) < (entry2->type & S_IFMT)) return (-1); if ((entry1->type & S_IFMT) > (entry2->type & S_IFMT)) return (1); /* make sure "." and ".." are always first */ - if( strcmp(entry1->relname, ".")==0 ) return (-1); - if( strcmp(entry2->relname, ".")==0 ) return (1); - if( strcmp(entry1->relname, "..")==0 ) return (-1); - if( strcmp(entry2->relname, "..")==0 ) return (1); + if ( strcmp(entry1->relname, ".")==0 ) return (-1); + if ( strcmp(entry2->relname, ".")==0 ) return (1); + if ( strcmp(entry1->relname, "..")==0 ) return (-1); + if ( strcmp(entry2->relname, "..")==0 ) return (1); return (BLI_natstrcmp(entry1->relname,entry2->relname)); } @@ -154,7 +156,8 @@ double BLI_dir_free_space(const char *dir) if (dir[0]=='/' || dir[0]=='\\') { tmp[0]='\\'; tmp[1]=0; - } else if (dir[1]==':') { + } + else if (dir[1]==':') { tmp[0]=dir[0]; tmp[1]=':'; tmp[2]='\\'; @@ -179,10 +182,11 @@ double BLI_dir_free_space(const char *dir) strcpy(name,dir); - if(len) { + if (len) { slash = strrchr(name,'/'); if (slash) slash[1] = 0; - } else strcpy(name,"/"); + } + else strcpy(name,"/"); #if defined (__FreeBSD__) || defined (linux) || defined (__OpenBSD__) || defined (__APPLE__) || defined(__GNU__) || defined(__GLIBC__) if (statfs(name, &disk)) return(-1); @@ -221,7 +225,7 @@ static void bli_builddir(const char *dirname, const char *relname) } #else UTF16_ENCODE(dirname) - if(!SetCurrentDirectoryW(dirname_16)){ + if (!SetCurrentDirectoryW(dirname_16)) { perror(dirname); free(dirname_16); return; @@ -229,7 +233,7 @@ static void bli_builddir(const char *dirname, const char *relname) UTF16_UN_ENCODE(dirname) #endif - if ( (dir = (DIR *)opendir(".")) ){ + if ( (dir = (DIR *)opendir(".")) ) { while ((fname = (struct dirent*) readdir(dir)) != NULL) { dlink = (struct dirlink *)malloc(sizeof(struct dirlink)); if (dlink) { @@ -242,9 +246,9 @@ static void bli_builddir(const char *dirname, const char *relname) if (newnum) { - if(files) { + if (files) { void *tmp= realloc(files, (totnum+newnum) * sizeof(struct direntry)); - if(tmp) { + if (tmp) { files= (struct direntry *)tmp; } else { /* realloc fail */ @@ -253,7 +257,7 @@ static void bli_builddir(const char *dirname, const char *relname) } } - if(files==NULL) + if (files==NULL) files=(struct direntry *)malloc(newnum * sizeof(struct direntry)); if (files) { @@ -282,19 +286,22 @@ static void bli_builddir(const char *dirname, const char *relname) actnum++; dlink = dlink->next; } - } else{ + } + else { printf("Couldn't get memory for dir\n"); exit(1); } BLI_freelist(dirbase); if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *,const void*))bli_compare); - } else { + } + else { printf("%s empty directory\n",dirname); } closedir(dir); - } else { + } + else { printf("%s non-existant directory\n",dirname); } } @@ -316,7 +323,7 @@ static void bli_adddirstrings(void) struct tm *tm; time_t zero= 0; - for(num=0, file= files; nummode1, types[0], sizeof(file->mode1)); @@ -352,7 +359,8 @@ static void bli_adddirstrings(void) pwuser = getpwuid(file->s.st_uid); if ( pwuser ) { BLI_strncpy(file->owner, pwuser->pw_name, sizeof(file->owner)); - } else { + } + else { BLI_snprintf(file->owner, sizeof(file->owner), "%d", file->s.st_uid); } } @@ -360,7 +368,7 @@ static void bli_adddirstrings(void) tm= localtime(&file->s.st_mtime); // prevent impossible dates in windows - if(tm==NULL) tm= localtime(&zero); + if (tm==NULL) tm= localtime(&zero); strftime(file->time, sizeof(file->time), "%H:%M", tm); strftime(file->date, sizeof(file->date), "%d-%b-%y", tm); @@ -426,7 +434,8 @@ unsigned int BLI_dir_contents(const char *dirname, struct direntry **filelist) if (files) { *(filelist) = files; - } else { + } + else { // keep blender happy. Blender stores this in a variable // where 0 has special meaning..... *(filelist) = files = malloc(sizeof(struct direntry)); @@ -553,16 +562,16 @@ int BLI_file_older(const char *file1, const char *file2) UTF16_ENCODE(file1) UTF16_ENCODE(file2) - if(_wstat(file1_16, &st1)) return 0; - if(_wstat(file2_16, &st2)) return 0; + if (_wstat(file1_16, &st1)) return 0; + if (_wstat(file2_16, &st2)) return 0; UTF16_UN_ENCODE(file2) UTF16_UN_ENCODE(file1) #else struct stat st1, st2; - if(stat(file1, &st1)) return 0; - if(stat(file2, &st2)) return 0; + if (stat(file1, &st1)) return 0; + if (stat(file2, &st2)) return 0; #endif return (st1.st_mtime < st2.st_mtime); } diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 80f1606414c..4c92a872ed7 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -124,7 +124,7 @@ char *BLI_sprintfN(const char *format, ...) size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) { size_t len= 0; - while(len < maxlen) { + while (len < maxlen) { switch(*src) { case '\0': goto escape_finish; @@ -135,7 +135,7 @@ size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) case '\t': case '\n': case '\r': - if(len + 1 < maxlen) { + if (len + 1 < maxlen) { *dst++ = '\\'; len++; } @@ -292,9 +292,11 @@ int BLI_strcasecmp(const char *s1, const char *s2) if (c1c2) { + } + else if (c1>c2) { return 1; - } else if (c1==0) { + } + else if (c1==0) { break; } } @@ -312,9 +314,11 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len) if (c1c2) { + } + else if (c1>c2) { return 1; - } else if (c1==0) { + } + else if (c1==0) { break; } } @@ -331,11 +335,11 @@ int BLI_natstrcmp(const char *s1, const char *s2) * then increase string deltas as long they are * numeric, else do a tolower and char compare */ - while(1) { + while (1) { char c1 = tolower(s1[d1]); char c2 = tolower(s2[d2]); - if( isdigit(c1) && isdigit(c2) ) { + if ( isdigit(c1) && isdigit(c2) ) { int val1, val2; val1= (int)strtol(s1+d1, (char **)NULL, 10); @@ -343,14 +347,15 @@ int BLI_natstrcmp(const char *s1, const char *s2) if (val1val2) { + } + else if (val1>val2) { return 1; } d1++; - while( isdigit(s1[d1]) ) + while ( isdigit(s1[d1]) ) d1++; d2++; - while( isdigit(s2[d2]) ) + while ( isdigit(s2[d2]) ) d2++; c1 = tolower(s1[d1]); @@ -358,15 +363,17 @@ int BLI_natstrcmp(const char *s1, const char *s2) } /* first check for '.' so "foo.bar" comes before "foo 1.bar" */ - if(c1=='.' && c2!='.') + if (c1=='.' && c2!='.') return -1; - if(c1!='.' && c2=='.') + if (c1!='.' && c2=='.') return 1; else if (c1c2) { + } + else if (c1>c2) { return 1; - } else if (c1==0) { + } + else if (c1==0) { break; } d1++; @@ -385,7 +392,8 @@ void BLI_timestr(double _time, char *str) if (hr) { sprintf(str, "%.2d:%.2d:%.2d.%.2d",hr,min,sec,hun); - } else { + } + else { sprintf(str, "%.2d:%.2d.%.2d",min,sec,hun); } @@ -403,8 +411,8 @@ void BLI_ascii_strtolower(char *str, int len) { int i; - for(i=0; i= 'A' && str[i] <= 'Z') + for (i=0; i= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A'; } @@ -412,8 +420,8 @@ void BLI_ascii_strtoupper(char *str, int len) { int i; - for(i=0; i= 'a' && str[i] <= 'z') + for (i=0; i= 'a' && str[i] <= 'z') str[i] -= 'a' - 'A'; } diff --git a/source/blender/blenlib/intern/string_utf8.c b/source/blender/blenlib/intern/string_utf8.c index 55ad30ab5dd..6f181c1ee6e 100644 --- a/source/blender/blenlib/intern/string_utf8.c +++ b/source/blender/blenlib/intern/string_utf8.c @@ -126,11 +126,11 @@ int BLI_utf8_invalid_strip(char *str, int length) { int bad_char, tot= 0; - while((bad_char= BLI_utf8_invalid_byte(str, length)) != -1) { + while ((bad_char= BLI_utf8_invalid_byte(str, length)) != -1) { str += bad_char; length -= bad_char; - if(length == 0) { + if (length == 0) { /* last character bad, strip it */ *str= '\0'; tot++; @@ -166,7 +166,7 @@ static const size_t utf8_skip_data[256] = { #define BLI_STR_UTF8_CPY(dst, src, maxncpy) \ { \ size_t utf8_size; \ - while(*src != '\0' && (utf8_size= utf8_skip_data[*src]) < maxncpy) { \ + while (*src != '\0' && (utf8_size= utf8_skip_data[*src]) < maxncpy) { \ maxncpy -= utf8_size; \ switch(utf8_size) { \ case 6: *dst ++ = *src ++; \ @@ -210,7 +210,7 @@ char *BLI_strncat_utf8(char *dst, const char *src, size_t maxncpy) size_t BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxcpy) { size_t len = 0; - while(*src && len < maxcpy) { /* XXX can still run over the buffer because utf8 size isn't known :| */ + while (*src && len < maxcpy) { /* XXX can still run over the buffer because utf8 size isn't known :| */ len += BLI_str_utf8_from_unicode(*src++, dst+len); } @@ -224,7 +224,7 @@ size_t BLI_wstrlen_utf8(const wchar_t *src) { size_t len = 0; - while(*src) { + while (*src) { len += BLI_str_utf8_from_unicode(*src++, NULL); } @@ -236,15 +236,17 @@ size_t BLI_strlen_utf8(const char *strc) { int len=0; - while(*strc) { + while (*strc) { if ((*strc & 0xe0) == 0xc0) { - if((strc[1] & 0x80) && (strc[1] & 0x40) == 0x00) + if ((strc[1] & 0x80) && (strc[1] & 0x40) == 0x00) strc++; - } else if ((*strc & 0xf0) == 0xe0) { - if((strc[1] & strc[2] & 0x80) && ((strc[1] | strc[2]) & 0x40) == 0x00) + } + else if ((*strc & 0xf0) == 0xe0) { + if ((strc[1] & strc[2] & 0x80) && ((strc[1] | strc[2]) & 0x40) == 0x00) strc += 2; - } else if ((*strc & 0xf8) == 0xf0) { - if((strc[1] & strc[2] & strc[3] & 0x80) && ((strc[1] | strc[2] | strc[3]) & 0x40) == 0x00) + } + else if ((*strc & 0xf8) == 0xf0) { + if ((strc[1] & strc[2] & strc[3] & 0x80) && ((strc[1] | strc[2] | strc[3]) & 0x40) == 0x00) strc += 3; } @@ -259,9 +261,9 @@ size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst_w, const char *src_c, const size { int len=0; - if(dst_w==NULL || src_c==NULL) return(0); + if (dst_w==NULL || src_c==NULL) return(0); - while(*src_c && len < maxcpy) { + while (*src_c && len < maxcpy) { size_t step= 0; unsigned int unicode= BLI_str_utf8_as_unicode_and_size(src_c, &step); if (unicode != BLI_UTF8_ERR) { @@ -415,7 +417,7 @@ unsigned int BLI_str_utf8_as_unicode_step(const char *p, size_t *index) * this is added for text drawing because some filepaths can have latin1 * characters */ UTF8_GET (result, p, i, mask, len, BLI_UTF8_ERR); - if(result == BLI_UTF8_ERR) { + if (result == BLI_UTF8_ERR) { len= 1; result= *p; } diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 3894a6a0b8e..17edc18b7bb 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -78,7 +78,7 @@ static void *thread_tls_data; * * BLI_init_threads(&lb, do_something_func, maxthreads); * - * while(cont) { + * while (cont) { * if(BLI_available_threads(&lb) && !(escape loop event)) { * // get new job (data pointer) * // tag job 'processed @@ -153,13 +153,13 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) { int a; - if(threadbase != NULL && tot > 0) { + if (threadbase != NULL && tot > 0) { threadbase->first= threadbase->last= NULL; - if(tot>RE_MAX_THREAD) tot= RE_MAX_THREAD; - else if(tot<1) tot= 1; + if (tot>RE_MAX_THREAD) tot= RE_MAX_THREAD; + else if (tot<1) tot= 1; - for(a=0; ado_thread= do_thread; @@ -167,7 +167,7 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) } } - if(thread_levels == 0) { + if (thread_levels == 0) { MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread); #if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) @@ -187,8 +187,8 @@ int BLI_available_threads(ListBase *threadbase) ThreadSlot *tslot; int counter=0; - for(tslot= threadbase->first; tslot; tslot= tslot->next) { - if(tslot->avail) + for (tslot= threadbase->first; tslot; tslot= tslot->next) { + if (tslot->avail) counter++; } return counter; @@ -200,8 +200,8 @@ int BLI_available_thread_index(ListBase *threadbase) ThreadSlot *tslot; int counter=0; - for(tslot= threadbase->first; tslot; tslot= tslot->next, counter++) { - if(tslot->avail) + for (tslot= threadbase->first; tslot; tslot= tslot->next, counter++) { + if (tslot->avail) return counter; } return 0; @@ -229,8 +229,8 @@ void BLI_insert_thread(ListBase *threadbase, void *callerdata) { ThreadSlot *tslot; - for(tslot= threadbase->first; tslot; tslot= tslot->next) { - if(tslot->avail) { + for (tslot= threadbase->first; tslot; tslot= tslot->next) { + if (tslot->avail) { tslot->avail= 0; tslot->callerdata= callerdata; pthread_create(&tslot->pthread, NULL, tslot_thread_start, tslot); @@ -244,8 +244,8 @@ void BLI_remove_thread(ListBase *threadbase, void *callerdata) { ThreadSlot *tslot; - for(tslot= threadbase->first; tslot; tslot= tslot->next) { - if(tslot->callerdata==callerdata) { + for (tslot= threadbase->first; tslot; tslot= tslot->next) { + if (tslot->callerdata==callerdata) { pthread_join(tslot->pthread, NULL); tslot->callerdata= NULL; tslot->avail= 1; @@ -258,7 +258,7 @@ void BLI_remove_thread_index(ListBase *threadbase, int index) ThreadSlot *tslot; int counter=0; - for(tslot = threadbase->first; tslot; tslot = tslot->next, counter++) { + for (tslot = threadbase->first; tslot; tslot = tslot->next, counter++) { if (counter == index && tslot->avail == 0) { pthread_join(tslot->pthread, NULL); tslot->callerdata = NULL; @@ -272,7 +272,7 @@ void BLI_remove_threads(ListBase *threadbase) { ThreadSlot *tslot; - for(tslot = threadbase->first; tslot; tslot = tslot->next) { + for (tslot = threadbase->first; tslot; tslot = tslot->next) { if (tslot->avail == 0) { pthread_join(tslot->pthread, NULL); tslot->callerdata = NULL; @@ -289,8 +289,8 @@ void BLI_end_threads(ListBase *threadbase) * this way we don't end up decrementing thread_levels on an empty threadbase * */ if (threadbase && threadbase->first != NULL) { - for(tslot= threadbase->first; tslot; tslot= tslot->next) { - if(tslot->avail==0) { + for (tslot= threadbase->first; tslot; tslot= tslot->next) { + if (tslot->avail==0) { pthread_join(tslot->pthread, NULL); } } @@ -298,7 +298,7 @@ void BLI_end_threads(ListBase *threadbase) } thread_levels--; - if(thread_levels==0) + if (thread_levels==0) MEM_set_lock_callback(NULL, NULL); } @@ -366,17 +366,17 @@ void BLI_unlock_thread(int type) pthread_mutex_unlock(&_preview_lock); else if (type==LOCK_VIEWER) pthread_mutex_unlock(&_viewer_lock); - else if(type==LOCK_CUSTOM1) + else if (type==LOCK_CUSTOM1) pthread_mutex_unlock(&_custom1_lock); - else if(type==LOCK_RCACHE) + else if (type==LOCK_RCACHE) pthread_mutex_unlock(&_rcache_lock); - else if(type==LOCK_OPENGL) + else if (type==LOCK_OPENGL) pthread_mutex_unlock(&_opengl_lock); - else if(type==LOCK_NODES) + else if (type==LOCK_NODES) pthread_mutex_unlock(&_nodes_lock); - else if(type==LOCK_MOVIECLIP) + else if (type==LOCK_MOVIECLIP) pthread_mutex_unlock(&_movieclip_lock); - else if(type == LOCK_SCANFILL) + else if (type == LOCK_SCANFILL) pthread_mutex_unlock(&_scanfill_lock); } @@ -411,7 +411,7 @@ void BLI_rw_mutex_init(ThreadRWMutex *mutex) void BLI_rw_mutex_lock(ThreadRWMutex *mutex, int mode) { - if(mode == THREAD_LOCK_READ) + if (mode == THREAD_LOCK_READ) pthread_rwlock_rdlock(mutex); else pthread_rwlock_wrlock(mutex); @@ -498,7 +498,7 @@ void BLI_insert_work(ThreadedWorker *worker, void *param) if (BLI_available_threads(&worker->threadbase) == 0) { index = worker->total; - while(index == worker->total) { + while (index == worker->total) { PIL_sleep_ms(worker->sleep_time); for (index = 0; index < worker->total; index++) { @@ -571,11 +571,11 @@ void *BLI_thread_queue_pop(ThreadQueue *queue) /* wait until there is work */ pthread_mutex_lock(&queue->mutex); - while(BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) + while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) pthread_cond_wait(&queue->cond, &queue->mutex); /* if we have something, pop it */ - if(!BLI_gsqueue_is_empty(queue->queue)) + if (!BLI_gsqueue_is_empty(queue->queue)) BLI_gsqueue_pop(queue->queue, &work); pthread_mutex_unlock(&queue->mutex); @@ -629,15 +629,15 @@ void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms) /* wait until there is work */ pthread_mutex_lock(&queue->mutex); - while(BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) { - if(pthread_cond_timedwait(&queue->cond, &queue->mutex, &timeout) == ETIMEDOUT) + while (BLI_gsqueue_is_empty(queue->queue) && !queue->nowait) { + if (pthread_cond_timedwait(&queue->cond, &queue->mutex, &timeout) == ETIMEDOUT) break; - else if(PIL_check_seconds_timer() - t >= ms*0.001) + else if (PIL_check_seconds_timer() - t >= ms*0.001) break; } /* if we have something, pop it */ - if(!BLI_gsqueue_is_empty(queue->queue)) + if (!BLI_gsqueue_is_empty(queue->queue)) BLI_gsqueue_pop(queue->queue, &work); pthread_mutex_unlock(&queue->mutex); @@ -669,7 +669,7 @@ void BLI_thread_queue_nowait(ThreadQueue *queue) void BLI_begin_threaded_malloc(void) { - if(thread_levels == 0) { + if (thread_levels == 0) { MEM_set_lock_callback(BLI_lock_malloc_thread, BLI_unlock_malloc_thread); } thread_levels++; @@ -678,6 +678,6 @@ void BLI_begin_threaded_malloc(void) void BLI_end_threaded_malloc(void) { thread_levels--; - if(thread_levels==0) + if (thread_levels==0) MEM_set_lock_callback(NULL, NULL); } diff --git a/source/blender/blenlib/intern/time.c b/source/blender/blenlib/intern/time.c index d86d68f6195..2f53aa38e77 100644 --- a/source/blender/blenlib/intern/time.c +++ b/source/blender/blenlib/intern/time.c @@ -52,14 +52,16 @@ double PIL_check_seconds_timer(void) QueryPerformanceCounter((LARGE_INTEGER*) &count); return count/perffreq; - } else { + } + else { static double accum= 0.0; static int ltick= 0; int ntick= GetTickCount(); if (ntickdirentry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName, 0); return &dp->direntry; - } else if (FindNextFileW (dp->handle, &(dp->data))) { + } + else if (FindNextFileW (dp->handle, &(dp->data))) { dp->direntry.d_name= BLI_alloc_utf_8_from_16(dp->data.cFileName,0); return &dp->direntry; - } else { + } + else { return NULL; } } @@ -264,7 +267,8 @@ void get_default_root(char* root) root[1] = ':'; root[2] = '\\'; root[3] = '\0'; - } else { + } + else { /* if GetWindowsDirectory fails, something has probably gone wrong, * we are trying the blender install dir though */ if (GetModuleFileName(NULL,str,MAX_PATH+1)) { @@ -273,7 +277,8 @@ void get_default_root(char* root) root[1] = ':'; root[2] = '\\'; root[3] = '\0'; - } else { + } + else { DWORD tmp; int i; int rc = 0; @@ -333,15 +338,15 @@ int check_file_chars(char *filename) char* dirname(char *path) { char *p; - if( path == NULL || *path == '\0' ) + if ( path == NULL || *path == '\0' ) return "."; p = path + strlen(path) - 1; - while( *p == '/' ) { - if( p == path ) + while ( *p == '/' ) { + if ( p == path ) return path; *p-- = '\0'; } - while( p >= path && *p != '/' ) + while ( p >= path && *p != '/' ) p--; return p < path ? "." : -- cgit v1.2.3