diff options
Diffstat (limited to 'source/blender/blenlib/intern')
20 files changed, 1138 insertions, 1139 deletions
diff --git a/source/blender/blenlib/intern/BLI_args.c b/source/blender/blenlib/intern/BLI_args.c index ed3c6fad1a0..4e194b24c1e 100644 --- a/source/blender/blenlib/intern/BLI_args.c +++ b/source/blender/blenlib/intern/BLI_args.c @@ -49,7 +49,7 @@ typedef struct bArgDoc { const char *short_arg; const char *long_arg; const char *documentation; - int done; + int done; } bArgDoc; typedef struct bAKey { @@ -68,24 +68,24 @@ typedef struct bArgument { struct bArgs { ListBase docs; GHash *items; - int argc; + int argc; const char **argv; - int *passes; + int *passes; }; static unsigned int case_strhash(const void *ptr) { - const char *s= ptr; - unsigned int i= 0; + const char *s = ptr; + unsigned int i = 0; unsigned char c; - while ( (c= tolower(*s++)) ) - i= i*37 + c; + while ( (c = tolower(*s++)) ) + i = i * 37 + c; return i; } -static unsigned int keyhash(const void *ptr) +static unsigned int keyhash(const void *ptr) { const bAKey *k = ptr; return case_strhash(k->arg); // ^ BLI_ghashutil_inthash((void*)k->pass); @@ -102,7 +102,7 @@ static int keycmp(const void *a, const void *b) return strcmp(ka->arg, kb->arg); } else { - return BLI_ghashutil_intcmp((const void*)ka->pass, (const void*)kb->pass); + return BLI_ghashutil_intcmp((const void *)ka->pass, (const void *)kb->pass); } } @@ -182,8 +182,8 @@ static void internalAdd(struct bArgs *ba, const char *arg, int pass, int case_st if (a) { printf("WARNING: conflicting argument\n"); - printf("\ttrying to add '%s' on pass %i, %scase sensitive\n", arg, pass, case_str == 1? "not ": ""); - printf("\tconflict with '%s' on pass %i, %scase sensitive\n\n", a->key->arg, (int)a->key->pass, a->key->case_str == 1? "not ": ""); + printf("\ttrying to add '%s' on pass %i, %scase sensitive\n", arg, pass, case_str == 1 ? "not " : ""); + printf("\tconflict with '%s' on pass %i, %scase sensitive\n\n", a->key->arg, (int)a->key->pass, a->key->case_str == 1 ? "not " : ""); } a = MEM_callocN(sizeof(bArgument), "bArgument"); @@ -259,9 +259,9 @@ 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 */ + /* -1 signal what side of the comparison it is */ bArgument *a = lookUp(ba, ba->argv[i], pass, -1); BA_ArgCallback func = NULL; void *data = NULL; diff --git a/source/blender/blenlib/intern/BLI_dynstr.c b/source/blender/blenlib/intern/BLI_dynstr.c index 54d9bc5f16d..d1c30504153 100644 --- a/source/blender/blenlib/intern/BLI_dynstr.c +++ b/source/blender/blenlib/intern/BLI_dynstr.c @@ -46,9 +46,9 @@ #ifndef va_copy # ifdef __va_copy -# define va_copy(a,b) __va_copy(a,b) +# define va_copy(a, b) __va_copy(a, b) # else /* !__va_copy */ -# define va_copy(a,b) ((a)=(b)) +# define va_copy(a, b) ((a) = (b)) # endif /* __va_copy */ #endif /* va_copy */ @@ -70,65 +70,65 @@ struct DynStr { DynStr *BLI_dynstr_new(void) { - DynStr *ds= MEM_mallocN(sizeof(*ds), "DynStr"); - ds->elems= ds->last= NULL; - ds->curlen= 0; + DynStr *ds = MEM_mallocN(sizeof(*ds), "DynStr"); + ds->elems = ds->last = NULL; + ds->curlen = 0; return ds; } void BLI_dynstr_append(DynStr *ds, const char *cstr) { - DynStrElem *dse= malloc(sizeof(*dse)); - int cstrlen= strlen(cstr); + DynStrElem *dse = malloc(sizeof(*dse)); + int cstrlen = strlen(cstr); - dse->str= malloc(cstrlen+1); - memcpy(dse->str, cstr, cstrlen+1); - dse->next= NULL; + dse->str = malloc(cstrlen + 1); + memcpy(dse->str, cstr, cstrlen + 1); + dse->next = NULL; if (!ds->last) - ds->last= ds->elems= dse; + ds->last = ds->elems = dse; else - ds->last= ds->last->next= dse; + ds->last = ds->last->next = dse; - ds->curlen+= cstrlen; + ds->curlen += cstrlen; } void BLI_dynstr_nappend(DynStr *ds, const char *cstr, int len) { - DynStrElem *dse= malloc(sizeof(*dse)); - int cstrlen= BLI_strnlen(cstr, len); + DynStrElem *dse = malloc(sizeof(*dse)); + int cstrlen = BLI_strnlen(cstr, len); - dse->str= malloc(cstrlen+1); + dse->str = malloc(cstrlen + 1); memcpy(dse->str, cstr, cstrlen); dse->str[cstrlen] = '\0'; - dse->next= NULL; + dse->next = NULL; if (!ds->last) - ds->last= ds->elems= dse; + ds->last = ds->elems = dse; else - ds->last= ds->last->next= dse; + ds->last = ds->last->next = dse; - ds->curlen+= cstrlen; + ds->curlen += cstrlen; } void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) { char *message, fixedmessage[256]; - int len= sizeof(fixedmessage); - const int maxlen= 65536; + int len = sizeof(fixedmessage); + const int maxlen = 65536; int retval; while (1) { va_list args_cpy; if (len == sizeof(fixedmessage)) - message= fixedmessage; + message = fixedmessage; else - message= MEM_callocN(sizeof(char) * len, "BLI_dynstr_appendf"); + message = MEM_callocN(sizeof(char) * len, "BLI_dynstr_appendf"); /* cant reuse the same args, so work on a copy */ va_copy(args_cpy, args); - retval= vsnprintf(message, len, format, args_cpy); + retval = vsnprintf(message, len, format, args_cpy); va_end(args_cpy); if (retval == -1) { @@ -136,7 +136,7 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) * there is a formatting error, so we impose a maximum length */ if (message != fixedmessage) MEM_freeN(message); - message= NULL; + message = NULL; len *= 2; if (len > maxlen) { @@ -148,10 +148,10 @@ void BLI_dynstr_vappendf(DynStr *ds, const char *format, va_list args) /* in C99 the actual length required is returned */ if (message != fixedmessage) MEM_freeN(message); - message= NULL; + message = NULL; /* retval doesn't include \0 terminator */ - len= retval + 1; + len = retval + 1; } else break; @@ -169,8 +169,8 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) { va_list args; char *message, fixedmessage[256]; - int len= sizeof(fixedmessage); - const int maxlen= 65536; + int len = sizeof(fixedmessage); + const int maxlen = 65536; int retval; /* note that it's tempting to just call BLI_dynstr_vappendf here @@ -179,12 +179,12 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) while (1) { if (len == sizeof(fixedmessage)) - message= fixedmessage; + message = fixedmessage; else - message= MEM_callocN(sizeof(char)*(len), "BLI_dynstr_appendf"); + message = MEM_callocN(sizeof(char) * (len), "BLI_dynstr_appendf"); va_start(args, format); - retval= vsnprintf(message, len, format, args); + retval = vsnprintf(message, len, format, args); va_end(args); if (retval == -1) { @@ -192,7 +192,7 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) * there is a formatting error, so we impose a maximum length */ if (message != fixedmessage) MEM_freeN(message); - message= NULL; + message = NULL; len *= 2; if (len > maxlen) { @@ -204,10 +204,10 @@ void BLI_dynstr_appendf(DynStr *ds, const char *format, ...) /* in C99 the actual length required is returned */ if (message != fixedmessage) MEM_freeN(message); - message= NULL; + message = NULL; /* retval doesn't include \0 terminator */ - len= retval + 1; + len = retval + 1; } else break; @@ -231,19 +231,19 @@ void BLI_dynstr_get_cstring_ex(DynStr *ds, char *rets) char *s; DynStrElem *dse; - for (s= rets, dse= ds->elems; dse; dse= dse->next) { - int slen= strlen(dse->str); + for (s = rets, dse = ds->elems; dse; dse = dse->next) { + int slen = strlen(dse->str); memcpy(s, dse->str, slen); - s+= slen; + s += slen; } - rets[ds->curlen]= '\0'; + rets[ds->curlen] = '\0'; } char *BLI_dynstr_get_cstring(DynStr *ds) { - char *rets= MEM_mallocN(ds->curlen+1, "dynstr_cstring"); + char *rets = MEM_mallocN(ds->curlen + 1, "dynstr_cstring"); BLI_dynstr_get_cstring_ex(ds, rets); return rets; } @@ -252,13 +252,13 @@ void BLI_dynstr_free(DynStr *ds) { DynStrElem *dse; - for (dse= ds->elems; dse; ) { - DynStrElem *n= dse->next; + for (dse = ds->elems; dse; ) { + DynStrElem *n = dse->next; free(dse->str); free(dse); - dse= n; + dse = n; } MEM_freeN(ds); diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 65461b7258a..6ec3d033672 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -78,7 +78,7 @@ int BLI_ghash_size(GHash *gh) void BLI_ghash_insert(GHash *gh, void *key, void *val) { unsigned int hash = gh->hashfp(key) % gh->nbuckets; - Entry *e = (Entry*)BLI_mempool_alloc(gh->entrypool); + Entry *e = (Entry *)BLI_mempool_alloc(gh->entrypool); e->key = key; e->val = val; @@ -90,11 +90,11 @@ void BLI_ghash_insert(GHash *gh, void *key, void *val) int i, nold = gh->nbuckets; gh->nbuckets = hashsizes[++gh->cursize]; - gh->buckets = (Entry**)MEM_mallocN(gh->nbuckets * sizeof(*gh->buckets), "buckets"); + gh->buckets = (Entry **)MEM_mallocN(gh->nbuckets * sizeof(*gh->buckets), "buckets"); memset(gh->buckets, 0, gh->nbuckets * sizeof(*gh->buckets)); for (i = 0; i < nold; i++) { - for (e = old[i]; e;) { + for (e = old[i]; e; ) { Entry *n = e->next; hash = gh->hashfp(e->key) % gh->nbuckets; @@ -174,7 +174,7 @@ void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreef for (i = 0; i < gh->nbuckets; i++) { Entry *e; - for (e = gh->buckets[i]; e;) { + for (e = gh->buckets[i]; e; ) { Entry *n = e->next; if (keyfreefp) keyfreefp(e->key); @@ -333,6 +333,6 @@ int BLI_ghashutil_paircmp(const void *a, const void *b) void BLI_ghashutil_pairfree(void *ptr) { - MEM_freeN((void*)ptr); + MEM_freeN((void *)ptr); } diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index fa7b91b8539..4e135805efb 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -184,7 +184,7 @@ void *BLI_heap_popmin(Heap *heap) if (heap->size == 1) heap->size--; else { - HEAP_SWAP(heap, 0, heap->size-1); + HEAP_SWAP(heap, 0, heap->size - 1); heap->size--; BLI_heap_down(heap, 0); diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index 8662406b0e9..2b21758fdc1 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -50,59 +50,54 @@ #define MAX_TREETYPE 32 #define DEFAULT_FIND_NEAREST_HEAP_SIZE 1024 -typedef struct BVHNode -{ +typedef struct BVHNode { struct BVHNode **children; struct BVHNode *parent; // some user defined traversed need that struct BVHNode *skip[2]; - float *bv; // Bounding volume of all nodes, max 13 axis - int index; // face, edge, vertex index - char totnode; // how many nodes are used, used for speedup - char main_axis; // Axis used to split this node + float *bv; /* Bounding volume of all nodes, max 13 axis */ + int index; /* face, edge, vertex index */ + char totnode; /* how many nodes are used, used for speedup */ + char main_axis; /* Axis used to split this node */ } BVHNode; -struct BVHTree -{ +struct BVHTree { BVHNode **nodes; - BVHNode *nodearray; /* pre-alloc branch nodes */ - BVHNode **nodechild; // pre-alloc childs for nodes - float *nodebv; // pre-alloc bounding-volumes for nodes - float epsilon; /* epslion is used for inflation of the k-dop */ - int totleaf; // leafs - int totbranch; - char tree_type; // type of tree (4 => quadtree) - char axis; // kdop type (6 => OBB, 7 => AABB, ...) - char start_axis, stop_axis; // KDOP_AXES array indices according to axis + BVHNode *nodearray; /* pre-alloc branch nodes */ + BVHNode **nodechild; /* pre-alloc childs for nodes */ + float *nodebv; /* pre-alloc bounding-volumes for nodes */ + float epsilon; /* epslion is used for inflation of the k-dop */ + int totleaf; /* leafs */ + int totbranch; + char tree_type; /* type of tree (4 => quadtree) */ + char axis; /* kdop type (6 => OBB, 7 => AABB, ...) */ + char start_axis, stop_axis; /* KDOP_AXES array indices according to axis */ }; -typedef struct BVHOverlapData -{ +typedef struct BVHOverlapData { BVHTree *tree1, *tree2; BVHTreeOverlap *overlap; int i, max_overlap; /* i is number of overlaps */ int start_axis, stop_axis; } BVHOverlapData; -typedef struct BVHNearestData -{ +typedef struct BVHNearestData { BVHTree *tree; - const float *co; + const float *co; BVHTree_NearestPointCallback callback; - void *userdata; - float proj[13]; //coordinates projection over axis + void *userdata; + float proj[13]; /* coordinates projection over axis */ BVHTreeNearest nearest; } BVHNearestData; -typedef struct BVHRayCastData -{ +typedef struct BVHRayCastData { BVHTree *tree; BVHTree_RayCastCallback callback; - void *userdata; + void *userdata; - BVHTreeRay ray; + BVHTreeRay ray; float ray_dot_axis[13]; float idot_axis[13]; int index[6]; @@ -120,55 +115,55 @@ typedef struct BVHRayCastData // Notes: You can choose the tree type --> binary, quad, octree, choose below //////////////////////////////////////////////////////////////////////// -static float KDOP_AXES[13][3] = -{ {1.0, 0, 0}, {0, 1.0, 0}, {0, 0, 1.0}, {1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, -1.0}, -{1.0, -1.0, -1.0}, {1.0, 1.0, 0}, {1.0, 0, 1.0}, {0, 1.0, 1.0}, {1.0, -1.0, 0}, {1.0, 0, -1.0}, -{0, 1.0, -1.0} +static float KDOP_AXES[13][3] = { + {1.0, 0, 0}, {0, 1.0, 0}, {0, 0, 1.0}, {1.0, 1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, -1.0}, + {1.0, -1.0, -1.0}, {1.0, 1.0, 0}, {1.0, 0, 1.0}, {0, 1.0, 1.0}, {1.0, -1.0, 0}, {1.0, 0, -1.0}, + {0, 1.0, -1.0} }; /* * Generic push and pop heap */ -#define PUSH_HEAP_BODY(HEAP_TYPE, PRIORITY, heap, heap_size) \ -{ \ - HEAP_TYPE element = heap[heap_size-1]; \ - int child = heap_size-1; \ - while (child != 0) \ - { \ - int parent = (child-1) / 2; \ - if (PRIORITY(element, heap[parent])) \ - { \ - heap[child] = heap[parent]; \ - child = parent; \ - } \ - else break; \ - } \ - heap[child] = element; \ -} +#define PUSH_HEAP_BODY(HEAP_TYPE, PRIORITY, heap, heap_size) \ + { \ + HEAP_TYPE element = heap[heap_size - 1]; \ + int child = heap_size - 1; \ + while (child != 0) \ + { \ + int parent = (child - 1) / 2; \ + if (PRIORITY(element, heap[parent])) \ + { \ + heap[child] = heap[parent]; \ + child = parent; \ + } \ + else break; \ + } \ + heap[child] = element; \ + } -#define POP_HEAP_BODY(HEAP_TYPE, PRIORITY, heap, heap_size) \ -{ \ - HEAP_TYPE element = heap[heap_size-1]; \ - int parent = 0; \ - while (parent < (heap_size-1)/2 ) \ - { \ - int child2 = (parent+1)*2; \ - if (PRIORITY(heap[child2-1], heap[child2])) \ - --child2; \ - \ - if (PRIORITY(element, heap[child2])) \ - break; \ - \ - heap[parent] = heap[child2]; \ - parent = child2; \ - } \ - heap[parent] = element; \ -} +#define POP_HEAP_BODY(HEAP_TYPE, PRIORITY, heap, heap_size) \ + { \ + HEAP_TYPE element = heap[heap_size - 1]; \ + int parent = 0; \ + while (parent < (heap_size - 1) / 2) \ + { \ + int child2 = (parent + 1) * 2; \ + if (PRIORITY(heap[child2 - 1], heap[child2])) { \ + child2--; \ + } \ + if (PRIORITY(element, heap[child2])) { \ + break; \ + } \ + heap[parent] = heap[child2]; \ + parent = child2; \ + } \ + heap[parent] = element; \ + } #if 0 static int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, int *max_size, int size_per_item) { - int new_max_size = *max_size * 2; + int new_max_size = *max_size * 2; void *new_memblock = NULL; if (new_size <= *max_size) @@ -176,11 +171,11 @@ static int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, in if (*memblock == local_memblock) { - new_memblock = malloc( size_per_item * new_max_size ); + new_memblock = malloc(size_per_item * new_max_size); memcpy(new_memblock, *memblock, size_per_item * *max_size); } else - new_memblock = realloc(*memblock, size_per_item * new_max_size ); + new_memblock = realloc(*memblock, size_per_item * new_max_size); if (new_memblock) { @@ -206,7 +201,7 @@ static int ADJUST_MEMORY(void *local_memblock, void **memblock, int new_size, in #if 0 static int floor_lg(int a) { - return (int)(floor(log(a)/log(2))); + return (int)(floor(log(a) / log(2))); } #endif @@ -217,20 +212,20 @@ static void bvh_insertionsort(BVHNode **a, int lo, int hi, int axis) { int i, j; BVHNode *t; - for (i=lo; i < hi; i++) { - j=i; + for (i = lo; i < hi; i++) { + j = i; t = a[i]; - while ((j!=lo) && (t->bv[axis] < (a[j-1])->bv[axis])) { - a[j] = a[j-1]; + while ((j != lo) && (t->bv[axis] < (a[j - 1])->bv[axis])) { + a[j] = a[j - 1]; j--; } a[j] = t; } } -static int bvh_partition(BVHNode **a, int lo, int hi, BVHNode * x, int axis) +static int bvh_partition(BVHNode **a, int lo, int hi, BVHNode *x, int axis) { - int i=lo, j=hi; + int i = lo, j = hi; while (1) { while ((a[i])->bv[axis] < x->bv[axis]) i++; j--; @@ -248,33 +243,33 @@ static int bvh_partition(BVHNode **a, int lo, int hi, BVHNode * x, int axis) #if 0 static void bvh_downheap(BVHNode **a, int i, int n, int lo, int axis) { - BVHNode * d = a[lo+i-1]; + BVHNode *d = a[lo + i - 1]; int child; - while (i<=n/2) + while (i <= n / 2) { - child = 2*i; - if ((child < n) && ((a[lo+child-1])->bv[axis] < (a[lo+child])->bv[axis])) + child = 2 * i; + if ((child < n) && ((a[lo + child - 1])->bv[axis] < (a[lo + child])->bv[axis])) { child++; } - if (!(d->bv[axis] < (a[lo+child-1])->bv[axis])) break; - a[lo+i-1] = a[lo+child-1]; + if (!(d->bv[axis] < (a[lo + child - 1])->bv[axis])) break; + a[lo + i - 1] = a[lo + child - 1]; i = child; } - a[lo+i-1] = d; + a[lo + i - 1] = d; } static void bvh_heapsort(BVHNode **a, int lo, int hi, int axis) { - int n = hi-lo, i; - for (i=n/2; i>=1; i=i-1) + int n = hi - lo, i; + for (i = n / 2; i >= 1; i = i - 1) { bvh_downheap(a, i, n, lo, axis); } - for (i=n; i>1; i=i-1) + for (i = n; i > 1; i = i - 1) { - SWAP(BVHNode*, a[lo], a[lo+i-1]); - bvh_downheap(a, 1, i-1, lo, axis); + SWAP(BVHNode *, a[lo], a[lo + i - 1]); + bvh_downheap(a, 1, i - 1, lo, axis); } } #endif @@ -307,21 +302,21 @@ static BVHNode *bvh_medianof3(BVHNode **a, int lo, int mid, int hi, int axis) // /* * Quicksort algorithm modified for Introsort */ -static void bvh_introsort_loop (BVHNode **a, int lo, int hi, int depth_limit, int axis) +static void bvh_introsort_loop(BVHNode **a, int lo, int hi, int depth_limit, int axis) { int p; - while (hi-lo > size_threshold) + while (hi - lo > size_threshold) { if (depth_limit == 0) { bvh_heapsort(a, lo, hi, axis); return; } - depth_limit=depth_limit-1; - p=bvh_partition(a, lo, hi, bvh_medianof3(a, lo, lo+((hi-lo)/2)+1, hi-1, axis), axis); + depth_limit = depth_limit - 1; + p = bvh_partition(a, lo, hi, bvh_medianof3(a, lo, lo + ((hi - lo) / 2) + 1, hi - 1, axis), axis); bvh_introsort_loop(a, p, hi, depth_limit, axis); - hi=p; + hi = p; } } @@ -329,8 +324,8 @@ static void sort(BVHNode **a0, int begin, int end, int axis) { if (begin < end) { - BVHNode **a=a0; - bvh_introsort_loop(a, begin, end, 2*floor_lg(end-begin), axis); + BVHNode **a = a0; + bvh_introsort_loop(a, begin, end, 2 * floor_lg(end - begin), axis); bvh_insertionsort(a, begin, end, axis); } } @@ -347,8 +342,8 @@ 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) { - cut = bvh_partition(a, begin, end, bvh_medianof3(a, begin, (begin+end)/2, end-1, axis), axis ); + while (end - begin > 3) { + cut = bvh_partition(a, begin, end, bvh_medianof3(a, begin, (begin + end) / 2, end - 1, axis), axis); if (cut <= n) begin = cut; else @@ -368,7 +363,7 @@ static void build_skip_links(BVHTree *tree, BVHNode *node, BVHNode *left, BVHNod node->skip[1] = right; for (i = 0; i < node->totnode; i++) { - if (i+1 < node->totnode) + if (i + 1 < node->totnode) build_skip_links(tree, node->children[i], left, node->children[i + 1]); else build_skip_links(tree, node->children[i], left, right); @@ -415,8 +410,8 @@ static void refit_kdop_hull(BVHTree *tree, BVHNode *node, int start, int end) for (i = tree->start_axis; i < tree->stop_axis; i++) { - bv[2*i] = FLT_MAX; - bv[2*i + 1] = -FLT_MAX; + bv[2 * i] = FLT_MAX; + bv[2 * i + 1] = -FLT_MAX; } for (j = start; j < end; j++) { @@ -445,15 +440,15 @@ static char get_largest_axis(float *bv) middle_point[2] = (bv[5]) - (bv[4]); // z axis if (middle_point[0] > middle_point[1]) { if (middle_point[0] > middle_point[2]) - return 1; // max x axis + return 1; // max x axis else - return 5; // max z axis + return 5; // max z axis } else { if (middle_point[1] > middle_point[2]) - return 3; // max y axis + return 3; // max y axis else - return 5; // max z axis + return 5; // max z axis } } @@ -464,8 +459,8 @@ static void node_join(BVHTree *tree, BVHNode *node) int i, j; for (i = tree->start_axis; i < tree->stop_axis; i++) { - node->bv[2*i] = FLT_MAX; - node->bv[2*i + 1] = -FLT_MAX; + node->bv[2 * i] = FLT_MAX; + node->bv[2 * i + 1] = -FLT_MAX; } for (i = 0; i < tree->tree_type; i++) { @@ -492,15 +487,15 @@ static void node_join(BVHTree *tree, BVHNode *node) static void bvhtree_print_tree(BVHTree *tree, BVHNode *node, int depth) { int i; - for (i=0; i<depth; i++) printf(" "); + for (i = 0; i < depth; i++) printf(" "); printf(" - %d (%ld): ", node->index, 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; i<tree->tree_type; i++) + for (i = 0; i < tree->tree_type; i++) if (node->children[i]) - bvhtree_print_tree(tree, node->children[i], depth+1); + bvhtree_print_tree(tree, node->children[i], depth + 1); } static void bvhtree_info(BVHTree *tree) @@ -508,15 +503,14 @@ static void bvhtree_info(BVHTree *tree) printf("BVHTree info\n"); printf("tree_type = %d, axis = %d, epsilon = %f\n", tree->tree_type, tree->axis, tree->epsilon); printf("nodes = %d, branches = %d, leafs = %d\n", tree->totbranch + tree->totleaf, tree->totbranch, tree->totleaf); - printf("Memory per node = %ldbytes\n", sizeof(BVHNode) + sizeof(BVHNode*)*tree->tree_type + sizeof(float)*tree->axis); + printf("Memory per node = %ldbytes\n", sizeof(BVHNode) + sizeof(BVHNode *) * tree->tree_type + sizeof(float) * tree->axis); printf("BV memory = %dbytes\n", MEM_allocN_len(tree->nodebv)); - printf("Total memory = %ldbytes\n", sizeof(BVHTree) - + MEM_allocN_len(tree->nodes) - + MEM_allocN_len(tree->nodearray) - + MEM_allocN_len(tree->nodechild) - + MEM_allocN_len(tree->nodebv) - ); + printf("Total memory = %ldbytes\n", sizeof(BVHTree) + + MEM_allocN_len(tree->nodes) + + MEM_allocN_len(tree->nodearray) + + MEM_allocN_len(tree->nodechild) + + MEM_allocN_len(tree->nodebv)); // bvhtree_print_tree(tree, tree->nodes[tree->totleaf], 0); } @@ -532,10 +526,10 @@ static void verify_tree(BVHTree *tree) // check the pointer list 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 - { + } + else { for (j = 0; j < tree->tree_type; j++) { if (tree->nodes[i]->parent->children[j] == tree->nodes[i]) @@ -552,10 +546,10 @@ static void verify_tree(BVHTree *tree) // check the leaf list 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 - { + } + else { for (j = 0; j < tree->tree_type; j++) { if (tree->nodearray[i].parent->children[j] == &tree->nodearray[i]) @@ -575,15 +569,14 @@ static void verify_tree(BVHTree *tree) //Helper data and structures to build a min-leaf generalized implicit tree //This code can be easily reduced (basicly this is only method to calculate pow(k, n) in O(1).. and stuff like that) -typedef struct BVHBuildHelper -{ - int tree_type; /* */ - int totleafs; /* */ +typedef struct BVHBuildHelper { + int tree_type; /* */ + int totleafs; /* */ - int leafs_per_child[32]; /* Min number of leafs that are archievable from a node at depth N */ - int branches_on_level[32]; /* Number of nodes at depth N (tree_type^N) */ + int leafs_per_child[32]; /* Min number of leafs that are archievable from a node at depth N */ + int branches_on_level[32]; /* Number of nodes at depth N (tree_type^N) */ - int remain_leafs; /* Number of leafs that are placed on the level that is not 100% filled */ + int remain_leafs; /* Number of leafs that are placed on the level that is not 100% filled */ } BVHBuildHelper; @@ -594,7 +587,7 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) int nnodes; data->totleafs = tree->totleaf; - data->tree_type= tree->tree_type; + data->tree_type = tree->tree_type; //Calculate the smallest tree_type^n such that tree_type^n >= num_leafs for (data->leafs_per_child[0] = 1; @@ -608,8 +601,8 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) //We could stop the loop first (but I am lazy to find out when) 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; + 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; } remain = data->totleafs - data->leafs_per_child[1]; @@ -620,11 +613,11 @@ static void build_implicit_tree_helper(BVHTree *tree, BVHBuildHelper *data) // return the min index of all the leafs archivable with the given branch static int implicit_leafs_index(BVHBuildHelper *data, int depth, int child_index) { - int min_leaf_index = child_index * data->leafs_per_child[depth-1]; + int min_leaf_index = child_index * data->leafs_per_child[depth - 1]; if (min_leaf_index <= data->remain_leafs) return min_leaf_index; else if (data->leafs_per_child[depth]) - return data->totleafs - (data->branches_on_level[depth-1] - child_index) * 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; } @@ -660,7 +653,7 @@ static int implicit_leafs_index(BVHBuildHelper *data, int depth, int child_index // This functions returns the number of branches needed to have the requested number of leafs. static int implicit_needed_branches(int tree_type, int leafs) { - return MAX2(1, (leafs + tree_type - 3) / (tree_type-1) ); + return MAX2(1, (leafs + tree_type - 3) / (tree_type - 1) ); } /* @@ -678,11 +671,11 @@ static int implicit_needed_branches(int tree_type, int leafs) static void split_leafs(BVHNode **leafs_array, int *nth, int partitions, int split_axis) { int i; - for (i=0; i < partitions-1; i++) { + for (i = 0; i < partitions - 1; i++) { if (nth[i] >= nth[partitions]) break; - partition_nth_element(leafs_array, nth[i], nth[partitions], nth[i+1], split_axis); + partition_nth_element(leafs_array, nth[i], nth[partitions], nth[i + 1], split_axis); } } @@ -708,19 +701,19 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, const int tree_type = tree->tree_type; const int tree_offset = 2 - tree->tree_type; //this value is 0 (on binary trees) and negative on the others - const int num_branches= implicit_needed_branches(tree_type, num_leafs); + const int num_branches = implicit_needed_branches(tree_type, num_leafs); BVHBuildHelper data; int depth; // set parent from root node to NULL - BVHNode *tmp = branches_array+0; + BVHNode *tmp = branches_array + 0; tmp->parent = NULL; //Most of bvhtree code relies on 1-leaf trees having at least one branch //We handle that special case here if (num_leafs == 1) { - BVHNode *root = branches_array+0; + BVHNode *root = branches_array + 0; refit_kdop_hull(tree, root, 0, num_leafs); root->main_axis = get_largest_axis(root->bv) / 2; root->totnode = 1; @@ -729,27 +722,27 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, return; } - branches_array--; //Implicit trees use 1-based indexs + branches_array--; //Implicit trees use 1-based indexs 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++) { - 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 + for (i = 1, depth = 1; i <= num_branches; i = i * tree_type + tree_offset, depth++) { + const int first_of_next_level = i * tree_type + tree_offset; + const int end_j = MIN2(first_of_next_level, num_branches + 1); //index of last branch on this level int j; //Loop all branches on this level #pragma omp parallel for private(j) schedule(static) for (j = i; j < end_j; j++) { int k; - const int parent_level_index= j-i; - BVHNode* parent = branches_array + j; - int nth_positions[ MAX_TREETYPE + 1]; + const int parent_level_index = j - i; + BVHNode *parent = branches_array + j; + int nth_positions[MAX_TREETYPE + 1]; char split_axis; int parent_leafs_begin = implicit_leafs_index(&data, depth, parent_level_index); - int parent_leafs_end = implicit_leafs_index(&data, depth, parent_level_index+1); + int parent_leafs_end = implicit_leafs_index(&data, depth, parent_level_index + 1); //This calculates the bounding box of this branch //and chooses the largest axis as the axis to divide leafs @@ -763,12 +756,12 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, //Only to assure that the elements are partioned on a way that each child takes the elements //it would take in case the whole array was sorted. //Split_leafs takes care of that "sort" problem. - nth_positions[ 0] = parent_leafs_begin; + nth_positions[0] = parent_leafs_begin; nth_positions[tree_type] = parent_leafs_end; for (k = 1; k < tree_type; k++) { int child_index = j * tree_type + tree_offset + k; int child_level_index = child_index - first_of_next_level; //child level index - nth_positions[k] = implicit_leafs_index(&data, depth+1, child_level_index); + nth_positions[k] = implicit_leafs_index(&data, depth + 1, child_level_index); } split_leafs(leafs_array, nth_positions, tree_type, split_axis); @@ -780,22 +773,22 @@ static void non_recursive_bvh_div_nodes(BVHTree *tree, BVHNode *branches_array, int child_index = j * tree_type + tree_offset + k; int child_level_index = child_index - first_of_next_level; //child level index - int child_leafs_begin = implicit_leafs_index(&data, depth+1, child_level_index); - int child_leafs_end = implicit_leafs_index(&data, depth+1, child_level_index+1); + int child_leafs_begin = implicit_leafs_index(&data, depth + 1, child_level_index); + int child_leafs_end = implicit_leafs_index(&data, depth + 1, child_level_index + 1); if (child_leafs_end - child_leafs_begin > 1) { parent->children[k] = branches_array + child_index; parent->children[k]->parent = parent; } else if (child_leafs_end - child_leafs_begin == 1) { - parent->children[k] = leafs_array[ child_leafs_begin ]; + parent->children[k] = leafs_array[child_leafs_begin]; parent->children[k]->parent = parent; } else { break; } - parent->totnode = k+1; + parent->totnode = k + 1; } } } @@ -858,27 +851,27 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis) //Allocate arrays numnodes = maxsize + implicit_needed_branches(tree_type, maxsize) + tree_type; - tree->nodes = (BVHNode **)MEM_callocN(sizeof(BVHNode *)*numnodes, "BVHNodes"); + tree->nodes = (BVHNode **)MEM_callocN(sizeof(BVHNode *) * numnodes, "BVHNodes"); if (!tree->nodes) { MEM_freeN(tree); return NULL; } - tree->nodebv = (float*)MEM_callocN(sizeof(float)* axis * numnodes, "BVHNodeBV"); + tree->nodebv = (float *)MEM_callocN(sizeof(float) * axis * numnodes, "BVHNodeBV"); if (!tree->nodebv) { MEM_freeN(tree->nodes); MEM_freeN(tree); } - tree->nodechild = (BVHNode**)MEM_callocN(sizeof(BVHNode*) * tree_type * numnodes, "BVHNodeBV"); + tree->nodechild = (BVHNode **)MEM_callocN(sizeof(BVHNode *) * tree_type * numnodes, "BVHNodeBV"); if (!tree->nodechild) { MEM_freeN(tree->nodebv); MEM_freeN(tree->nodes); MEM_freeN(tree); } - tree->nodearray = (BVHNode *)MEM_callocN(sizeof(BVHNode)* numnodes, "BVHNodeArray"); + tree->nodearray = (BVHNode *)MEM_callocN(sizeof(BVHNode) * numnodes, "BVHNodeArray"); if (!tree->nodearray) { MEM_freeN(tree->nodechild); @@ -889,7 +882,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; } @@ -914,8 +907,8 @@ void BLI_bvhtree_balance(BVHTree *tree) { int i; - BVHNode* branches_array = tree->nodearray + tree->totleaf; - BVHNode** leafs_array = tree->nodes; + BVHNode *branches_array = tree->nodearray + tree->totleaf; + BVHNode **leafs_array = tree->nodes; //This function should only be called once (some big bug goes here if its being called more than once per tree) assert(tree->totbranch == 0); @@ -942,7 +935,7 @@ int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints) 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 @@ -951,7 +944,7 @@ int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints) tree->totleaf++; create_kdop_hull(tree, node, co, numpoints, 0); - node->index= index; + node->index = index; // inflate the bv with some epsilon for (i = tree->start_axis; i < tree->stop_axis; i++) { @@ -967,7 +960,7 @@ int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints) int BLI_bvhtree_update_node(BVHTree *tree, int index, const float *co, const float *co_moving, int numpoints) { int i; - BVHNode *node= NULL; + BVHNode *node = NULL; // check if index exists if (index > tree->totleaf) @@ -996,8 +989,8 @@ void BLI_bvhtree_update_tree(BVHTree *tree) //TRICKY: the way we build the tree all the childs have an index greater than the parent //This allows us todo a bottom up update by starting on the biger numbered branch - BVHNode** root = tree->nodes + tree->totleaf; - BVHNode** index = tree->nodes + tree->totleaf + tree->totbranch-1; + BVHNode **root = tree->nodes + tree->totleaf; + BVHNode **index = tree->nodes + tree->totleaf + tree->totbranch - 1; for (; index >= root; index--) node_join(tree, *index); @@ -1018,13 +1011,13 @@ static int tree_overlap(BVHNode *node1, BVHNode *node2, int start_axis, int stop float *bv1 = node1->bv; float *bv2 = node2->bv; - float *bv1_end = bv1 + (stop_axis<<1); + float *bv1_end = bv1 + (stop_axis << 1); - bv1 += start_axis<<1; - bv2 += start_axis<<1; + bv1 += start_axis << 1; + bv2 += start_axis << 1; // test all axis if min + max overlap - for (; bv1 != bv1_end; bv1+=2, bv2+=2) { + for (; bv1 != bv1_end; bv1 += 2, bv2 += 2) { if ((*(bv1) > *(bv2 + 1)) || (*(bv2) > *(bv1 + 1))) return 0; } @@ -1048,7 +1041,7 @@ static void traverse(BVHOverlapData *data, BVHNode *node1, BVHNode *node2) if (data->i >= data->max_overlap) { // try to make alloc'ed memory bigger - data->overlap = realloc(data->overlap, sizeof(BVHTreeOverlap)*data->max_overlap*2); + data->overlap = realloc(data->overlap, sizeof(BVHTreeOverlap) * data->max_overlap * 2); if (!data->overlap) { printf("Out of Memory in traverse\n"); @@ -1095,19 +1088,19 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int 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"); + data = MEM_callocN(sizeof(BVHOverlapData *) * tree1->tree_type, "BVHOverlapData_star"); for (j = 0; j < tree1->tree_type; j++) { data[j] = (BVHOverlapData *)MEM_callocN(sizeof(BVHOverlapData), "BVHOverlapData"); // init BVHOverlapData - data[j]->overlap = (BVHTreeOverlap *)malloc(sizeof(BVHTreeOverlap)*MAX2(tree1->totleaf, tree2->totleaf)); + data[j]->overlap = (BVHTreeOverlap *)malloc(sizeof(BVHTreeOverlap) * MAX2(tree1->totleaf, tree2->totleaf)); data[j]->tree1 = tree1; data[j]->tree2 = tree2; data[j]->max_overlap = MAX2(tree1->totleaf, tree2->totleaf); data[j]->i = 0; data[j]->start_axis = MIN2(tree1->start_axis, tree2->start_axis); - data[j]->stop_axis = MIN2(tree1->stop_axis, tree2->stop_axis ); + data[j]->stop_axis = MIN2(tree1->stop_axis, tree2->stop_axis); } #pragma omp parallel for private(j) schedule(static) @@ -1118,11 +1111,11 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int for (j = 0; j < tree1->tree_type; j++) total += data[j]->i; - to = overlap = (BVHTreeOverlap *)MEM_callocN(sizeof(BVHTreeOverlap)*total, "BVHTreeOverlap"); + to = overlap = (BVHTreeOverlap *)MEM_callocN(sizeof(BVHTreeOverlap) * total, "BVHTreeOverlap"); for (j = 0; j < tree1->tree_type; j++) { - memcpy(to, data[j]->overlap, data[j]->i*sizeof(BVHTreeOverlap)); - to+=data[j]->i; + memcpy(to, data[j]->overlap, data[j]->i * sizeof(BVHTreeOverlap)); + to += data[j]->i; } for (j = 0; j < tree1->tree_type; j++) { @@ -1142,7 +1135,7 @@ static float calc_nearest_point(const float proj[3], BVHNode *node, float *neare const float *bv = node->bv; //nearest on AABB hull - for (i=0; i != 3; i++, bv += 2) { + for (i = 0; i != 3; i++, bv += 2) { if (bv[0] > proj[i]) nearest[i] = bv[0]; else if (bv[1] < proj[i]) @@ -1154,9 +1147,9 @@ 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 proj = dot_v3v3(nearest, KDOP_AXES[i]); float dl = bv[0] - proj; float du = bv[1] - proj; @@ -1173,14 +1166,13 @@ static float calc_nearest_point(const float proj[3], BVHNode *node, float *neare } -typedef struct NodeDistance -{ +typedef struct NodeDistance { BVHNode *node; float dist; } NodeDistance; -#define NodeDistance_priority(a, b) ( (a).dist < (b).dist ) +#define NodeDistance_priority(a, b) ( (a).dist < (b).dist) // TODO: use a priority queue to reduce the number of nodes looked on static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) @@ -1189,8 +1181,8 @@ static void dfs_find_nearest_dfs(BVHNearestData *data, BVHNode *node) if (data->callback) data->callback(data->userdata, node->index, data->co, &data->nearest); else { - data->nearest.index = node->index; - data->nearest.dist = calc_nearest_point(data->proj, node, data->nearest.co); + data->nearest.index = node->index; + data->nearest.dist = calc_nearest_point(data->proj, node, data->nearest.co); } } else { @@ -1198,16 +1190,16 @@ 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++) { - if ( calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; + for (i = 0; i != node->totnode; i++) { + if (calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; dfs_find_nearest_dfs(data, node->children[i]); } } else { - for (i=node->totnode-1; i >= 0 ; i--) { - if ( calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; + for (i = node->totnode - 1; i >= 0; i--) { + if (calc_nearest_point(data->proj, node->children[i], nearest) >= data->nearest.dist) continue; dfs_find_nearest_dfs(data, node->children[i]); } } @@ -1242,8 +1234,8 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) { int i; NodeDistance default_heap[DEFAULT_FIND_NEAREST_HEAP_SIZE]; - NodeDistance *heap=default_heap, current; - int heap_size = 0, max_heap_size = sizeof(default_heap)/sizeof(default_heap[0]); + NodeDistance *heap = default_heap, current; + int heap_size = 0, max_heap_size = sizeof(default_heap) / sizeof(default_heap[0]); float nearest[3]; int callbacks = 0, push_heaps = 0; @@ -1260,7 +1252,7 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) 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) @@ -1268,11 +1260,10 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) callbacks++; dfs_find_nearest_dfs(data, child); } - else - { + else { //adjust heap size if ((heap_size >= max_heap_size) && - ADJUST_MEMORY(default_heap, (void**)&heap, heap_size+1, &max_heap_size, sizeof(heap[0])) == FALSE) + 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"); @@ -1289,7 +1280,7 @@ static void bfs_find_nearest(BVHNearestData *data, BVHNode *node) heap_size++; NodeDistance_push_heap(heap, heap_size); - // PUSH_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size); + // PUSH_HEAP_BODY(NodeDistance, NodeDistance_priority, heap, heap_size); push_heaps++; } } @@ -1315,7 +1306,7 @@ int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *n int i; BVHNearestData data; - BVHNode* root = tree->nodes[tree->totleaf]; + BVHNode *root = tree->nodes[tree->totleaf]; //init data to search data.tree = tree; @@ -1363,7 +1354,7 @@ 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) { //axis aligned ray if (data->ray.origin[i] < bv[0] - data->ray.radius || @@ -1377,11 +1368,11 @@ static float ray_nearest_hit(BVHRayCastData *data, float *bv) float lu = (bv[1] + data->ray.radius - data->ray.origin[i]) / data->ray_dot_axis[i]; if (data->ray_dot_axis[i] > 0.0f) { - if (ll > low) low = ll; + if (ll > low) low = ll; if (lu < upper) upper = lu; } else { - if (lu > low) low = lu; + if (lu > low) low = lu; if (ll < upper) upper = ll; } @@ -1433,20 +1424,20 @@ static void dfs_raycast(BVHRayCastData *data, BVHNode *node) data->callback(data->userdata, node->index, &data->ray, &data->hit); } else { - data->hit.index = node->index; + data->hit.index = node->index; data->hit.dist = dist; madd_v3_v3v3fl(data->hit.co, data->ray.origin, data->ray.direction, dist); } } else { //pick loop direction to dive into the tree (based on ray direction and split axis) - if (data->ray_dot_axis[ (int)node->main_axis ] > 0.0f) { - for (i=0; i != node->totnode; i++) { + if (data->ray_dot_axis[(int)node->main_axis] > 0.0f) { + for (i = 0; i != node->totnode; i++) { dfs_raycast(data, node->children[i]); } } else { - for (i=node->totnode-1; i >= 0; i--) { + for (i = node->totnode - 1; i >= 0; i--) { dfs_raycast(data, node->children[i]); } } @@ -1467,19 +1458,18 @@ static void iterative_raycast(BVHRayCastData *data, BVHNode *node) if (node->totnode == 0) { - if (data->callback) + if (data->callback) { data->callback(data->userdata, node->index, &data->ray, &data->hit); - else - { - data->hit.index = node->index; + } + else { + data->hit.index = node->index; data->hit.dist = dist; madd_v3_v3v3fl(data->hit.co, data->ray.origin, data->ray.direction, dist); } node = node->skip[1]; } - else - { + else { node = node->children[0]; } } @@ -1490,7 +1480,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f { int i; BVHRayCastData data; - BVHNode * root = tree->nodes[tree->totleaf]; + BVHNode *root = tree->nodes[tree->totleaf]; data.tree = tree; @@ -1503,17 +1493,17 @@ 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) { data.ray_dot_axis[i] = 0.0; } - data.index[2*i] = data.idot_axis[i] < 0.0f ? 1 : 0; - data.index[2*i+1] = 1 - data.index[2*i]; - data.index[2*i] += 2*i; - data.index[2*i+1] += 2*i; + data.index[2 * i] = data.idot_axis[i] < 0.0f ? 1 : 0; + data.index[2 * i + 1] = 1 - data.index[2 * i]; + data.index[2 * i] += 2 * i; + data.index[2 * i + 1] += 2 * i; } @@ -1527,7 +1517,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f if (root) { dfs_raycast(&data, root); // iterative_raycast(&data, root); - } + } if (hit) @@ -1572,11 +1562,10 @@ float BLI_bvhtree_bb_raycast(float *bv, const float light_start[3], const float * Allocs and fills an array with the indexs of node that are on the given spherical range (center, radius) * Returns the size of the array. */ -typedef struct RangeQueryData -{ +typedef struct RangeQueryData { BVHTree *tree; const float *center; - float radius; //squared radius + float radius; //squared radius int hits; @@ -1590,7 +1579,7 @@ typedef struct RangeQueryData static void dfs_range_query(RangeQueryData *data, BVHNode *node) { if (node->totnode == 0) { -#if 0 /*UNUSED*/ +#if 0 /*UNUSED*/ //Calculate the node min-coords (if the node was a point then this is the point coordinates) float co[3]; co[0] = node->bv[0]; @@ -1600,7 +1589,7 @@ 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) { @@ -1618,12 +1607,12 @@ static void dfs_range_query(RangeQueryData *data, BVHNode *node) int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, BVHTree_RangeQuery callback, void *userdata) { - BVHNode * root = tree->nodes[tree->totleaf]; + BVHNode *root = tree->nodes[tree->totleaf]; RangeQueryData data; data.tree = tree; data.center = co; - data.radius = radius*radius; + data.radius = radius * radius; data.hits = 0; data.callback = callback; diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c index a518d1445e3..4878c0f05a6 100644 --- a/source/blender/blenlib/intern/BLI_kdtree.c +++ b/source/blender/blenlib/intern/BLI_kdtree.c @@ -38,7 +38,7 @@ #include "BLI_kdtree.h" #ifndef SWAP -#define SWAP(type, a, b) { type sw_ap; sw_ap=(a); (a)=(b); (b)=sw_ap; } +# define SWAP(type, a, b) { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } #endif typedef struct KDTreeNode { @@ -58,9 +58,9 @@ KDTree *BLI_kdtree_new(int maxsize) { KDTree *tree; - tree= MEM_callocN(sizeof(KDTree), "KDTree"); - tree->nodes= MEM_callocN(sizeof(KDTreeNode)*maxsize, "KDTreeNode"); - tree->totnode= 0; + tree = MEM_callocN(sizeof(KDTree), "KDTree"); + tree->nodes = MEM_callocN(sizeof(KDTreeNode) * maxsize, "KDTreeNode"); + tree->totnode = 0; return tree; } @@ -75,9 +75,9 @@ void BLI_kdtree_free(KDTree *tree) void BLI_kdtree_insert(KDTree *tree, int index, float *co, float *nor) { - KDTreeNode *node= &tree->nodes[tree->totnode++]; + KDTreeNode *node = &tree->nodes[tree->totnode++]; - node->index= index; + node->index = index; copy_v3_v3(node->co, co); if (nor) copy_v3_v3(node->nor, nor); } @@ -94,18 +94,18 @@ static KDTreeNode *kdtree_balance(KDTreeNode *nodes, int totnode, int axis) return nodes; /* quicksort style sorting around median */ - left= 0; - right= totnode-1; - median= totnode/2; + left = 0; + right = totnode - 1; + median = totnode / 2; while (right > left) { - co= nodes[right].co[axis]; - i= left-1; - j= right; + 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 (nodes[++i].co[axis] < co) ; + while (nodes[--j].co[axis] > co && j > left) ; if (i >= j) break; SWAP(KDTreeNode, nodes[i], nodes[j]); @@ -113,32 +113,32 @@ static KDTreeNode *kdtree_balance(KDTreeNode *nodes, int totnode, int axis) SWAP(KDTreeNode, nodes[i], nodes[right]); if (i >= median) - right= i-1; + right = i - 1; if (i <= median) - left= i+1; + left = i + 1; } /* set node and sort subnodes */ - node= &nodes[median]; - node->d= axis; - node->left= kdtree_balance(nodes, median, (axis+1)%3); - node->right= kdtree_balance(nodes+median+1, (totnode-(median+1)), (axis+1)%3); + node = &nodes[median]; + node->d = axis; + node->left = kdtree_balance(nodes, median, (axis + 1) % 3); + node->right = kdtree_balance(nodes + median + 1, (totnode - (median + 1)), (axis + 1) % 3); return node; } void BLI_kdtree_balance(KDTree *tree) { - tree->root= kdtree_balance(tree->nodes, tree->totnode, 0); + tree->root = kdtree_balance(tree->nodes, tree->totnode, 0); } static float squared_distance(const float v2[3], const float v1[3], float *UNUSED(n1), float *n2) { float d[3], dist; - d[0]= v2[0]-v1[0]; - d[1]= v2[1]-v1[1]; - d[2]= v2[2]-v1[2]; + d[0] = v2[0] - v1[0]; + d[1] = v2[1] - v1[1]; + d[2] = v2[2] - v1[2]; dist = dot_v3v3(d, d); @@ -152,84 +152,84 @@ static float squared_distance(const float v2[3], const float v1[3], float *UNUSE return dist; } -int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest *nearest) +int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest *nearest) { KDTreeNode *root, *node, *min_node; KDTreeNode **stack, *defaultstack[100]; float min_dist, cur_dist; - int totstack, cur=0; + int totstack, cur = 0; if (!tree->root) return -1; - stack= defaultstack; - totstack= 100; + stack = defaultstack; + totstack = 100; - root= tree->root; - min_node= root; - min_dist= squared_distance(root->co, co, root->nor, nor); + root = tree->root; + min_node = root; + min_dist = squared_distance(root->co, co, root->nor, nor); if (co[root->d] < root->co[root->d]) { if (root->right) - stack[cur++]=root->right; + stack[cur++] = root->right; if (root->left) - stack[cur++]=root->left; + stack[cur++] = root->left; } else { if (root->left) - stack[cur++]=root->left; + stack[cur++] = root->left; if (root->right) - stack[cur++]=root->right; + stack[cur++] = root->right; } while (cur--) { - node=stack[cur]; + node = stack[cur]; cur_dist = node->co[node->d] - co[node->d]; - if (cur_dist<0.0f) { - cur_dist= -cur_dist*cur_dist; + if (cur_dist < 0.0f) { + cur_dist = -cur_dist * cur_dist; - if (-cur_dist<min_dist) { - cur_dist=squared_distance(node->co, co, node->nor, nor); - if (cur_dist<min_dist) { - min_dist=cur_dist; - min_node=node; + if (-cur_dist < min_dist) { + cur_dist = squared_distance(node->co, co, node->nor, nor); + if (cur_dist < min_dist) { + min_dist = cur_dist; + min_node = node; } if (node->left) - stack[cur++]=node->left; + stack[cur++] = node->left; } if (node->right) - stack[cur++]=node->right; + stack[cur++] = node->right; } else { - cur_dist= cur_dist*cur_dist; + cur_dist = cur_dist * cur_dist; - if (cur_dist<min_dist) { - cur_dist=squared_distance(node->co, co, node->nor, nor); - if (cur_dist<min_dist) { - min_dist=cur_dist; - min_node=node; + if (cur_dist < min_dist) { + cur_dist = squared_distance(node->co, co, node->nor, nor); + if (cur_dist < min_dist) { + min_dist = cur_dist; + min_node = node; } if (node->right) - stack[cur++]=node->right; + stack[cur++] = node->right; } if (node->left) - stack[cur++]=node->left; + stack[cur++] = node->left; } - if (cur+3 > totstack) { - KDTreeNode **temp=MEM_callocN((totstack+100)*sizeof(KDTreeNode*), "psys_treestack"); - memcpy(temp, stack, totstack*sizeof(KDTreeNode*)); + if (cur + 3 > totstack) { + KDTreeNode **temp = MEM_callocN((totstack + 100) * sizeof(KDTreeNode *), "psys_treestack"); + memcpy(temp, stack, totstack * sizeof(KDTreeNode *)); if (stack != defaultstack) MEM_freeN(stack); - stack=temp; - totstack+=100; + stack = temp; + totstack += 100; } } if (nearest) { - nearest->index= min_node->index; - nearest->dist= sqrt(min_dist); + nearest->index = min_node->index; + nearest->dist = sqrt(min_dist); copy_v3_v3(nearest->co, min_node->co); } @@ -243,98 +243,98 @@ static void add_nearest(KDTreeNearest *ptn, int *found, int n, int index, float { int i; - if (*found<n) (*found)++; + if (*found < n) (*found)++; - for (i=*found-1; i>0; 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]; + ptn[i] = ptn[i - 1]; } - ptn[i].index= index; - ptn[i].dist= dist; + ptn[i].index = index; + ptn[i].dist = dist; copy_v3_v3(ptn[i].co, co); } /* finds the nearest n entries in tree to specified coordinates */ -int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTreeNearest *nearest) +int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTreeNearest *nearest) { - KDTreeNode *root, *node= NULL; + KDTreeNode *root, *node = NULL; KDTreeNode **stack, *defaultstack[100]; float cur_dist; - int i, totstack, cur=0, found=0; + int i, totstack, cur = 0, found = 0; if (!tree->root) return 0; - stack= defaultstack; - totstack= 100; + stack = defaultstack; + totstack = 100; - root= tree->root; + root = tree->root; - cur_dist= squared_distance(root->co, co, root->nor, nor); + 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) - stack[cur++]=root->right; + stack[cur++] = root->right; if (root->left) - stack[cur++]=root->left; + stack[cur++] = root->left; } else { if (root->left) - stack[cur++]=root->left; + stack[cur++] = root->left; if (root->right) - stack[cur++]=root->right; + stack[cur++] = root->right; } while (cur--) { - node=stack[cur]; + node = stack[cur]; cur_dist = node->co[node->d] - co[node->d]; - if (cur_dist<0.0f) { - cur_dist= -cur_dist*cur_dist; + if (cur_dist < 0.0f) { + cur_dist = -cur_dist * cur_dist; - if (found<n || -cur_dist<nearest[found-1].dist) { - cur_dist=squared_distance(node->co, co, node->nor, nor); + if (found < n || -cur_dist < nearest[found - 1].dist) { + cur_dist = squared_distance(node->co, co, node->nor, nor); - if (found<n || cur_dist<nearest[found-1].dist) + if (found < n || cur_dist < nearest[found - 1].dist) add_nearest(nearest, &found, n, node->index, cur_dist, node->co); if (node->left) - stack[cur++]=node->left; + stack[cur++] = node->left; } if (node->right) - stack[cur++]=node->right; + stack[cur++] = node->right; } else { - cur_dist= cur_dist*cur_dist; + cur_dist = cur_dist * cur_dist; - if (found<n || cur_dist<nearest[found-1].dist) { - cur_dist=squared_distance(node->co, co, node->nor, nor); - if (found<n || cur_dist<nearest[found-1].dist) + if (found < n || cur_dist < nearest[found - 1].dist) { + cur_dist = squared_distance(node->co, co, node->nor, nor); + if (found < n || cur_dist < nearest[found - 1].dist) add_nearest(nearest, &found, n, node->index, cur_dist, node->co); if (node->right) - stack[cur++]=node->right; + stack[cur++] = node->right; } if (node->left) - stack[cur++]=node->left; + stack[cur++] = node->left; } - if (cur+3 > totstack) { - KDTreeNode **temp=MEM_callocN((totstack+100)*sizeof(KDTreeNode*), "psys_treestack"); - memcpy(temp, stack, totstack * sizeof(KDTreeNode*)); + if (cur + 3 > totstack) { + KDTreeNode **temp = MEM_callocN((totstack + 100) * sizeof(KDTreeNode *), "psys_treestack"); + memcpy(temp, stack, totstack * sizeof(KDTreeNode *)); if (stack != defaultstack) MEM_freeN(stack); - stack=temp; - totstack+=100; + stack = temp; + totstack += 100; } } - for (i=0; i<found; i++) - nearest[i].dist= sqrt(nearest[i].dist); + for (i = 0; i < found; i++) + nearest[i].dist = sqrt(nearest[i].dist); if (stack != defaultstack) MEM_freeN(stack); @@ -342,7 +342,7 @@ int BLI_kdtree_find_n_nearest(KDTree *tree, int n, float *co, float *nor, KDTree return found; } -static int range_compare(const void * a, const void * b) +static int range_compare(const void *a, const void *b) { const KDTreeNearest *kda = a; const KDTreeNearest *kdb = b; @@ -358,13 +358,13 @@ static void add_in_range(KDTreeNearest **ptn, int found, int *totfoundstack, int { KDTreeNearest *to; - if (found+1 > *totfoundstack) { - KDTreeNearest *temp=MEM_callocN((*totfoundstack+50)*sizeof(KDTreeNode), "psys_treefoundstack"); + if (found + 1 > *totfoundstack) { + KDTreeNearest *temp = MEM_callocN((*totfoundstack + 50) * sizeof(KDTreeNode), "psys_treefoundstack"); memcpy(temp, *ptn, *totfoundstack * sizeof(KDTreeNearest)); if (*ptn) MEM_freeN(*ptn); *ptn = temp; - *totfoundstack+=50; + *totfoundstack += 50; } to = (*ptn) + found; @@ -375,27 +375,27 @@ static void add_in_range(KDTreeNearest **ptn, int found, int *totfoundstack, int } int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KDTreeNearest **nearest) { - KDTreeNode *root, *node= NULL; + KDTreeNode *root, *node = NULL; KDTreeNode **stack, *defaultstack[100]; - KDTreeNearest *foundstack=NULL; - float range2 = range*range, dist2; - int totstack, cur=0, found=0, totfoundstack=0; + KDTreeNearest *foundstack = NULL; + float range2 = range * range, dist2; + int totstack, cur = 0, found = 0, totfoundstack = 0; if (!tree || !tree->root) return 0; - stack= defaultstack; - totstack= 100; + stack = defaultstack; + totstack = 100; - root= tree->root; + root = tree->root; if (co[root->d] + range < root->co[root->d]) { if (root->left) - stack[cur++]=root->left; + stack[cur++] = root->left; } else if (co[root->d] - range > root->co[root->d]) { if (root->right) - stack[cur++]=root->right; + stack[cur++] = root->right; } else { dist2 = squared_distance(root->co, co, root->nor, nor); @@ -403,21 +403,21 @@ int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KD add_in_range(&foundstack, found++, &totfoundstack, root->index, dist2, root->co); if (root->left) - stack[cur++]=root->left; + stack[cur++] = root->left; if (root->right) - stack[cur++]=root->right; + stack[cur++] = root->right; } while (cur--) { - node=stack[cur]; + node = stack[cur]; if (co[node->d] + range < node->co[node->d]) { if (node->left) - stack[cur++]=node->left; + stack[cur++] = node->left; } else if (co[node->d] - range > node->co[node->d]) { if (node->right) - stack[cur++]=node->right; + stack[cur++] = node->right; } else { dist2 = squared_distance(node->co, co, node->nor, nor); @@ -425,18 +425,18 @@ int BLI_kdtree_range_search(KDTree *tree, float range, float *co, float *nor, KD add_in_range(&foundstack, found++, &totfoundstack, node->index, dist2, node->co); if (node->left) - stack[cur++]=node->left; + stack[cur++] = node->left; if (node->right) - stack[cur++]=node->right; + stack[cur++] = node->right; } - if (cur+3 > totstack) { - KDTreeNode **temp=MEM_callocN((totstack+100)*sizeof(KDTreeNode*), "psys_treestack"); - memcpy(temp, stack, totstack*sizeof(KDTreeNode*)); + if (cur + 3 > totstack) { + KDTreeNode **temp = MEM_callocN((totstack + 100) * sizeof(KDTreeNode *), "psys_treestack"); + memcpy(temp, stack, totstack * sizeof(KDTreeNode *)); if (stack != defaultstack) MEM_freeN(stack); - stack=temp; - totstack+=100; + stack = temp; + totstack += 100; } } diff --git a/source/blender/blenlib/intern/BLI_linklist.c b/source/blender/blenlib/intern/BLI_linklist.c index 5c7d7089825..0e630efc349 100644 --- a/source/blender/blenlib/intern/BLI_linklist.c +++ b/source/blender/blenlib/intern/BLI_linklist.c @@ -38,12 +38,12 @@ int BLI_linklist_length(LinkNode *list) { if (0) { - return list?(1+BLI_linklist_length(list->next)):0; + return list ? (1 + BLI_linklist_length(list->next)) : 0; } else { int len; - for (len=0; list; list= list->next) + for (len = 0; list; list = list->next) len++; return len; @@ -54,7 +54,7 @@ int BLI_linklist_index(LinkNode *list, void *ptr) { int index; - for (index = 0; list; list= list->next, index++) + for (index = 0; list; list = list->next, index++) if (list->link == ptr) return index; @@ -65,7 +65,7 @@ LinkNode *BLI_linklist_find(LinkNode *list, int index) { int i; - for (i = 0; list; list= list->next, i++) + for (i = 0; list; list = list->next, i++) if (i == index) return list; @@ -74,32 +74,32 @@ LinkNode *BLI_linklist_find(LinkNode *list, int index) void BLI_linklist_reverse(LinkNode **listp) { - LinkNode *rhead= NULL, *cur= *listp; + LinkNode *rhead = NULL, *cur = *listp; while (cur) { - LinkNode *next= cur->next; + LinkNode *next = cur->next; - cur->next= rhead; - rhead= cur; + cur->next = rhead; + rhead = cur; - cur= next; + cur = next; } - *listp= rhead; + *listp = rhead; } void BLI_linklist_prepend(LinkNode **listp, void *ptr) { - LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); - nlink->link= ptr; + LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink"); + nlink->link = ptr; - nlink->next= *listp; - *listp= nlink; + nlink->next = *listp; + *listp = nlink; } void BLI_linklist_append(LinkNode **listp, void *ptr) { - LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); + LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink"); LinkNode *node = *listp; nlink->link = ptr; @@ -118,16 +118,16 @@ void BLI_linklist_append(LinkNode **listp, void *ptr) void BLI_linklist_prepend_arena(LinkNode **listp, void *ptr, MemArena *ma) { - LinkNode *nlink= BLI_memarena_alloc(ma, sizeof(*nlink)); - nlink->link= ptr; + LinkNode *nlink = BLI_memarena_alloc(ma, sizeof(*nlink)); + nlink->link = ptr; - nlink->next= *listp; - *listp= nlink; + nlink->next = *listp; + *listp = nlink; } void BLI_linklist_insert_after(LinkNode **listp, void *ptr) { - LinkNode *nlink= MEM_mallocN(sizeof(*nlink), "nlink"); + LinkNode *nlink = MEM_mallocN(sizeof(*nlink), "nlink"); LinkNode *node = *listp; nlink->link = ptr; @@ -145,18 +145,18 @@ void BLI_linklist_insert_after(LinkNode **listp, void *ptr) void BLI_linklist_free(LinkNode *list, LinkNodeFreeFP freefunc) { while (list) { - LinkNode *next= list->next; + LinkNode *next = list->next; if (freefunc) freefunc(list->link); MEM_freeN(list); - list= next; + list = next; } } void BLI_linklist_apply(LinkNode *list, LinkNodeApplyFP applyfunc, void *userdata) { - for (; list; list= list->next) + for (; list; list = list->next) applyfunc(list->link, userdata); } diff --git a/source/blender/blenlib/intern/BLI_memarena.c b/source/blender/blenlib/intern/BLI_memarena.c index 95a007db43e..8c9993afee8 100644 --- a/source/blender/blenlib/intern/BLI_memarena.c +++ b/source/blender/blenlib/intern/BLI_memarena.c @@ -74,12 +74,12 @@ void BLI_memarena_use_align(struct MemArena *ma, int align) void BLI_memarena_free(MemArena *ma) { - BLI_linklist_free(ma->bufs, (void(*)(void *))MEM_freeN); + BLI_linklist_free(ma->bufs, (void (*)(void *))MEM_freeN); MEM_freeN(ma); } /* amt must be power of two */ -#define PADUP(num, amt) ((num + (amt - 1)) &~ (amt-1)) +#define PADUP(num, amt) ((num + (amt - 1)) & ~(amt - 1)) void *BLI_memarena_alloc(MemArena *ma, int size) { @@ -93,7 +93,7 @@ void *BLI_memarena_alloc(MemArena *ma, int size) unsigned char *tmp; if (size > ma->bufsize - (ma->align - 1)) { - ma->cursize = PADUP(size+1, ma->align); + ma->cursize = PADUP(size + 1, ma->align); } else ma->cursize = ma->bufsize; @@ -106,7 +106,7 @@ void *BLI_memarena_alloc(MemArena *ma, int size) BLI_linklist_prepend(&ma->bufs, ma->curbuf); /* align alloc'ed memory (needed if align > 8) */ - tmp = (unsigned char*)PADUP( (intptr_t) ma->curbuf, ma->align); + tmp = (unsigned char *)PADUP( (intptr_t) ma->curbuf, ma->align); ma->cursize -= (tmp - ma->curbuf); ma->curbuf = tmp; } diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c index 6398bd863db..bed5750ad44 100644 --- a/source/blender/blenlib/intern/DLRB_tree.c +++ b/source/blender/blenlib/intern/DLRB_tree.c @@ -37,7 +37,7 @@ /* Tree API */ /* Create a new tree, and initialize as necessary */ -DLRBT_Tree *BLI_dlrbTree_new (void) +DLRBT_Tree *BLI_dlrbTree_new(void) { /* just allocate for now */ return MEM_callocN(sizeof(DLRBT_Tree), "DLRBT_Tree"); @@ -49,11 +49,11 @@ void BLI_dlrbTree_init(DLRBT_Tree *tree) if (tree == NULL) return; - tree->first= tree->last= tree->root= NULL; + tree->first = tree->last = tree->root = NULL; } /* Helper for traversing tree and freeing sub-nodes */ -static void recursive_tree_free_nodes (DLRBT_Node *node) +static void recursive_tree_free_nodes(DLRBT_Node *node) { /* sanity check */ if (node == NULL) @@ -86,13 +86,13 @@ void BLI_dlrbTree_free(DLRBT_Tree *tree) } /* clear pointers */ - tree->first= tree->last= tree->root= NULL; + tree->first = tree->last = tree->root = NULL; } /* ------- */ /* Helper function - used for traversing down the tree from the root to add nodes in order */ -static void linkedlist_sync_add_node (DLRBT_Tree *tree, DLRBT_Node *node) +static void linkedlist_sync_add_node(DLRBT_Tree *tree, DLRBT_Node *node) { /* sanity checks */ if ((tree == NULL) || (node == NULL)) @@ -105,7 +105,7 @@ static void linkedlist_sync_add_node (DLRBT_Tree *tree, DLRBT_Node *node) * - must remove detach from other links first * (for now, only clear own pointers) */ - node->prev= node->next= NULL; + node->prev = node->next = NULL; BLI_addtail((ListBase *)tree, (Link *)node); /* finally, add right node (and its subtree) */ @@ -120,7 +120,7 @@ void BLI_dlrbTree_linkedlist_sync(DLRBT_Tree *tree) return; /* clear list-base pointers so that the new list can be added properly */ - tree->first= tree->last= NULL; + tree->first = tree->last = NULL; /* start adding items from the root */ linkedlist_sync_add_node(tree, tree->root); @@ -130,10 +130,10 @@ void BLI_dlrbTree_linkedlist_sync(DLRBT_Tree *tree) /* Tree Search Utilities */ /* Find the node which matches or is the closest to the requested node */ -DLRBT_Node *BLI_dlrbTree_search (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) +DLRBT_Node *BLI_dlrbTree_search(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) { DLRBT_Node *node = (tree) ? tree->root : NULL; - short found= 0; + short found = 0; /* check that there is a comparator to use */ // TODO: if no comparator is supplied, try using the one supplied with the tree... @@ -146,22 +146,22 @@ DLRBT_Node *BLI_dlrbTree_search (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, v * NOTE: it is assumed that the values will be unit values only */ switch (cmp_cb(node, search_data)) { - case -1: /* data less than node */ + case -1: /* data less than node */ if (node->left) - node= node->left; + node = node->left; else - found= 1; + found = 1; break; - case 1: /* data greater than node */ + case 1: /* data greater than node */ if (node->right) - node= node->right; + node = node->right; else - found= 1; + found = 1; break; - default: /* data equals node */ - found= 1; + default: /* data equals node */ + found = 1; break; } } @@ -171,10 +171,10 @@ DLRBT_Node *BLI_dlrbTree_search (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, v } /* Find the node which exactly matches the required data */ -DLRBT_Node *BLI_dlrbTree_search_exact (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) +DLRBT_Node *BLI_dlrbTree_search_exact(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) { DLRBT_Node *node = (tree) ? tree->root : NULL; - short found= 0; + short found = 0; /* check that there is a comparator to use */ // TODO: if no comparator is supplied, try using the one supplied with the tree... @@ -182,27 +182,27 @@ DLRBT_Node *BLI_dlrbTree_search_exact (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp return NULL; /* iteratively perform this search */ - while (node && found==0) { + while (node && found == 0) { /* check if traverse further or not * NOTE: it is assumed that the values will be unit values only */ switch (cmp_cb(node, search_data)) { - case -1: /* data less than node */ + case -1: /* data less than node */ if (node->left) - node= node->left; + node = node->left; else - found= -1; + found = -1; break; - case 1: /* data greater than node */ + case 1: /* data greater than node */ if (node->right) - node= node->right; + node = node->right; else - found= -1; + found = -1; break; - default: /* data equals node */ - found= 1; + default: /* data equals node */ + found = 1; break; } } @@ -212,7 +212,7 @@ DLRBT_Node *BLI_dlrbTree_search_exact (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp } /* Find the node which occurs immediately before the best matching node */ -DLRBT_Node *BLI_dlrbTree_search_prev (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) +DLRBT_Node *BLI_dlrbTree_search_prev(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) { DLRBT_Node *node; @@ -222,7 +222,7 @@ DLRBT_Node *BLI_dlrbTree_search_prev (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_ return NULL; /* get the node which best matches this description */ - node= BLI_dlrbTree_search(tree, cmp_cb, search_data); + node = BLI_dlrbTree_search(tree, cmp_cb, search_data); if (node) { /* if the item we're searching for is greater than the node found, we've found the match */ @@ -239,7 +239,7 @@ DLRBT_Node *BLI_dlrbTree_search_prev (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_ } /* Find the node which occurs immediately after the best matching node */ -DLRBT_Node *BLI_dlrbTree_search_next (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) +DLRBT_Node *BLI_dlrbTree_search_next(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void *search_data) { DLRBT_Node *node; @@ -249,7 +249,7 @@ DLRBT_Node *BLI_dlrbTree_search_next (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_ return NULL; /* get the node which best matches this description */ - node= BLI_dlrbTree_search(tree, cmp_cb, search_data); + node = BLI_dlrbTree_search(tree, cmp_cb, search_data); if (node) { /* if the item we're searching for is less than the node found, we've found the match */ @@ -277,7 +277,7 @@ short BLI_dlrbTree_contains(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, void * /* Tree Relationships Utilities */ /* get the 'grandparent' - the parent of the parent - of the given node */ -static DLRBT_Node *get_grandparent (DLRBT_Node *node) +static DLRBT_Node *get_grandparent(DLRBT_Node *node) { if (node && node->parent) return node->parent->parent; @@ -300,7 +300,7 @@ static DLRBT_Node *get_sibling(DLRBT_Node *node) } /* get the 'uncle' - the sibling of the parent - of the given node */ -static DLRBT_Node *get_uncle (DLRBT_Node *node) +static DLRBT_Node *get_uncle(DLRBT_Node *node) { if (node) /* return the child of the grandparent which isn't the node's parent */ @@ -314,71 +314,71 @@ static DLRBT_Node *get_uncle (DLRBT_Node *node) /* Tree Rotation Utilities */ /* make right child of 'root' the new root */ -static void rotate_left (DLRBT_Tree *tree, DLRBT_Node *root) +static void rotate_left(DLRBT_Tree *tree, DLRBT_Node *root) { DLRBT_Node **root_slot, *pivot; /* pivot is simply the root's right child, to become the root's parent */ - pivot= root->right; + pivot = root->right; if (pivot == NULL) return; if (root->parent) { if (root == root->parent->left) - root_slot= &root->parent->left; + root_slot = &root->parent->left; else - root_slot= &root->parent->right; + root_slot = &root->parent->right; } else - root_slot= ((DLRBT_Node**)&tree->root);//&((DLRBT_Node*)tree->root); + root_slot = ((DLRBT_Node **)&tree->root); //&((DLRBT_Node*)tree->root); /* - pivot's left child becomes root's right child * - root now becomes pivot's left child */ - root->right= pivot->left; - if (pivot->left) pivot->left->parent= root; + root->right = pivot->left; + if (pivot->left) pivot->left->parent = root; - pivot->left= root; - pivot->parent= root->parent; - root->parent= pivot; + pivot->left = root; + pivot->parent = root->parent; + root->parent = pivot; /* make the pivot the new root */ if (root_slot) - *root_slot= pivot; + *root_slot = pivot; } /* make the left child of the 'root' the new root */ -static void rotate_right (DLRBT_Tree *tree, DLRBT_Node *root) +static void rotate_right(DLRBT_Tree *tree, DLRBT_Node *root) { DLRBT_Node **root_slot, *pivot; /* pivot is simply the root's left child, to become the root's parent */ - pivot= root->left; + pivot = root->left; if (pivot == NULL) return; if (root->parent) { if (root == root->parent->left) - root_slot= &root->parent->left; + root_slot = &root->parent->left; else - root_slot= &root->parent->right; + root_slot = &root->parent->right; } else - root_slot= ((DLRBT_Node**)&tree->root);//&((DLRBT_Node*)tree->root); + root_slot = ((DLRBT_Node **)&tree->root); //&((DLRBT_Node*)tree->root); /* - pivot's right child becomes root's left child * - root now becomes pivot's right child */ - root->left= pivot->right; - if (pivot->right) pivot->right->parent= root; + root->left = pivot->right; + if (pivot->right) pivot->right->parent = root; - pivot->right= root; - pivot->parent= root->parent; - root->parent= pivot; + pivot->right = root; + pivot->parent = root->parent; + root->parent = pivot; /* make the pivot the new root */ if (root_slot) - *root_slot= pivot; + *root_slot = pivot; } /* *********************************************** */ @@ -392,41 +392,41 @@ static void insert_check_3(DLRBT_Tree *tree, DLRBT_Node *node); /* ----- */ /* W. 1) Root must be black (so that the 2nd-generation can have a black parent) */ -static void insert_check_1 (DLRBT_Tree *tree, DLRBT_Node *node) +static void insert_check_1(DLRBT_Tree *tree, DLRBT_Node *node) { if (node) { /* if this is the root, just ensure that it is black */ if (node->parent == NULL) - node->tree_col= DLRBT_BLACK; + node->tree_col = DLRBT_BLACK; else insert_check_2(tree, node); } } /* W. 2+3) Parent of node must be black, otherwise recolor and flush */ -static void insert_check_2 (DLRBT_Tree *tree, DLRBT_Node *node) +static void insert_check_2(DLRBT_Tree *tree, DLRBT_Node *node) { /* if the parent is not black, we need to change that... */ if (node && node->parent && node->parent->tree_col) { - DLRBT_Node *unc= get_uncle(node); + DLRBT_Node *unc = get_uncle(node); /* if uncle and parent are both red, need to change them to black and make * the parent black in order to satisfy the criteria of each node having the * same number of black nodes to its leaves */ if (unc && unc->tree_col) { - DLRBT_Node *gp= get_grandparent(node); + DLRBT_Node *gp = get_grandparent(node); /* make the n-1 generation nodes black */ - node->parent->tree_col= unc->tree_col= DLRBT_BLACK; + node->parent->tree_col = unc->tree_col = DLRBT_BLACK; /* - make the grandparent red, so that we maintain alternating red/black property * (it must exist, so no need to check for NULL here), * - as the grandparent may now cause inconsistencies with the rest of the tree, * we must flush up the tree and perform checks/rebalancing/repainting, using the - * grandparent as the node of interest + * grandparent as the node of interest */ - gp->tree_col= DLRBT_RED; + gp->tree_col = DLRBT_RED; insert_check_1(tree, gp); } else { @@ -439,9 +439,9 @@ static void insert_check_2 (DLRBT_Tree *tree, DLRBT_Node *node) } /* W. 4+5) Perform rotation on sub-tree containing the 'new' node, then do any */ -static void insert_check_3 (DLRBT_Tree *tree, DLRBT_Node *node) +static void insert_check_3(DLRBT_Tree *tree, DLRBT_Node *node) { - DLRBT_Node *gp= get_grandparent(node); + DLRBT_Node *gp = get_grandparent(node); /* check that grandparent and node->parent exist (jut in case... really shouldn't happen on a good tree) */ if (node && node->parent && gp) { @@ -451,11 +451,11 @@ static void insert_check_3 (DLRBT_Tree *tree, DLRBT_Node *node) */ if ((node == node->parent->right) && (node->parent == gp->left)) { rotate_left(tree, node); - node= node->left; + node = node->left; } else if ((node == node->parent->left) && (node->parent == gp->right)) { rotate_right(tree, node); - node= node->right; + node = node->right; } /* fix old parent's color-tagging, and perform rotation on the old parent in the @@ -464,11 +464,11 @@ static void insert_check_3 (DLRBT_Tree *tree, DLRBT_Node *node) */ if (node) { /* get 'new' grandparent (i.e. grandparent for old-parent (node)) */ - gp= get_grandparent(node); + gp = get_grandparent(node); /* modify the coloring of the grandparent and parent so that they still satisfy the constraints */ - node->parent->tree_col= DLRBT_BLACK; - gp->tree_col= DLRBT_RED; + node->parent->tree_col = DLRBT_BLACK; + gp->tree_col = DLRBT_RED; /* if there are several nodes that all form a left chain, do a right rotation to correct this * (or a rotation in the opposite direction if they all form a right chain) @@ -493,7 +493,7 @@ void BLI_dlrbTree_insert(DLRBT_Tree *tree, DLRBT_Node *node) return; /* firstly, the node we just added should be red by default */ - node->tree_col= DLRBT_RED; + node->tree_col = DLRBT_RED; /* start from case 1, an trek through the tail-recursive insertion checks */ insert_check_1(tree, node); @@ -504,9 +504,9 @@ void BLI_dlrbTree_insert(DLRBT_Tree *tree, DLRBT_Node *node) /* Add the given data to the tree, and return the node added */ // NOTE: for duplicates, the update_cb is called (if available), and the existing node is returned DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, - DLRBT_NAlloc_FP new_cb, DLRBT_NUpdate_FP update_cb, void *data) + DLRBT_NAlloc_FP new_cb, DLRBT_NUpdate_FP update_cb, void *data) { - DLRBT_Node *parNode, *node=NULL; + DLRBT_Node *parNode, *node = NULL; short new_node = 0; /* sanity checks */ @@ -522,7 +522,7 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, // TODO: if no updater is supplied, try using the one supplied with the tree... /* try to find the nearest node to this one */ - parNode= BLI_dlrbTree_search(tree, cmp_cb, data); + parNode = BLI_dlrbTree_search(tree, cmp_cb, data); /* add new node to the BST in the 'standard way' as appropriate * NOTE: we do not support duplicates in our tree... @@ -532,49 +532,49 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb, * NOTE: it is assumed that the values will be unit values only */ switch (cmp_cb(parNode, data)) { - case -1: /* add new node as left child */ + case -1: /* add new node as left child */ { - node= new_cb(data); - new_node= 1; + node = new_cb(data); + new_node = 1; - parNode->left= node; - node->parent= parNode; + parNode->left = node; + node->parent = parNode; } - break; + break; - case 1: /* add new node as right child */ + case 1: /* add new node as right child */ { - node= new_cb(data); - new_node= 1; + node = new_cb(data); + new_node = 1; - parNode->right= node; - node->parent= parNode; + parNode->right = node; + node->parent = parNode; } - break; + break; - default: /* update the duplicate node as appropriate */ + default: /* update the duplicate node as appropriate */ { if (update_cb) update_cb(parNode, data); } - break; + break; } } else { /* no nodes in the tree yet... add a new node as the root */ - node= new_cb(data); - new_node= 1; + node = new_cb(data); + new_node = 1; - tree->root= node; + tree->root = node; } /* if a new node was added, it should be tagged as red, and then balanced as appropriate */ if (new_node) { /* tag this new node as being 'red' */ - node->tree_col= DLRBT_RED; + node->tree_col = DLRBT_RED; /* perform BST balancing steps: - * start from case 1, an trek through the tail-recursive insertion checks + * start from case 1, an trek through the tail-recursive insertion checks */ insert_check_1(tree, node); } diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 48912eb927a..1aba8bbeaf2 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -221,7 +221,7 @@ static int findFileRecursive(char *filename_new, return found; if (*filesize == -1) - *filesize = 0; /* dir opened fine */ + *filesize = 0; /* dir opened fine */ while ((de = readdir(dir)) != NULL) { @@ -231,7 +231,7 @@ static int findFileRecursive(char *filename_new, BLI_join_dirfile(path, sizeof(path), dirname, de->d_name); if (stat(path, &status) != 0) - continue; /* cant stat, don't bother with this file, could print debug info here */ + continue; /* cant stat, don't bother with this file, could print debug info here */ if (S_ISREG(status.st_mode)) { /* is file */ if (strncmp(filename, de->d_name, FILE_MAX) == 0) { /* name matches */ @@ -388,29 +388,29 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int } switch (GS(id->name)) { - case ID_IM: - ima= (Image *)id; - if (ima->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) { - if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { - rewrite_path_fixed(ima->name, visit_cb, absbase, bpath_user_data); + case ID_IM: + ima = (Image *)id; + if (ima->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) { + if (ELEM3(ima->source, IMA_SRC_FILE, IMA_SRC_MOVIE, IMA_SRC_SEQUENCE)) { + rewrite_path_fixed(ima->name, visit_cb, absbase, bpath_user_data); + } } - } - break; - case ID_BR: + break; + case ID_BR: { - Brush *brush= (Brush *)id; + Brush *brush = (Brush *)id; if (brush->icon_filepath[0]) { rewrite_path_fixed(brush->icon_filepath, visit_cb, absbase, bpath_user_data); } } break; - case ID_OB: + case ID_OB: #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, \ @@ -420,69 +420,69 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int } \ - { - Object *ob= (Object *)id; - ModifierData *md; - ParticleSystem *psys; + { + Object *ob = (Object *)id; + ModifierData *md; + ParticleSystem *psys; - /* do via modifiers instead */ + /* do via modifiers instead */ #if 0 - if (ob->fluidsimSettings) { - rewrite_path_fixed(ob->fluidsimSettings->surfdataPath, visit_cb, absbase, bpath_user_data); - } + if (ob->fluidsimSettings) { + rewrite_path_fixed(ob->fluidsimSettings->surfdataPath, visit_cb, absbase, bpath_user_data); + } #endif - for (md= ob->modifiers.first; md; md= md->next) { - if (md->type == eModifierType_Fluidsim) { - FluidsimModifierData *fluidmd= (FluidsimModifierData *)md; - if (fluidmd->fss) { - rewrite_path_fixed(fluidmd->fss->surfdataPath, visit_cb, absbase, bpath_user_data); + for (md = ob->modifiers.first; md; md = md->next) { + if (md->type == eModifierType_Fluidsim) { + FluidsimModifierData *fluidmd = (FluidsimModifierData *)md; + if (fluidmd->fss) { + rewrite_path_fixed(fluidmd->fss->surfdataPath, visit_cb, absbase, bpath_user_data); + } } - } - else if (md->type == eModifierType_Smoke) { - SmokeModifierData *smd= (SmokeModifierData *)md; - if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { - BPATH_TRAVERSE_POINTCACHE(smd->domain->ptcaches[0]); + else if (md->type == eModifierType_Smoke) { + SmokeModifierData *smd = (SmokeModifierData *)md; + if (smd->type & MOD_SMOKE_TYPE_DOMAIN) { + BPATH_TRAVERSE_POINTCACHE(smd->domain->ptcaches[0]); + } + } + else if (md->type == eModifierType_Cloth) { + ClothModifierData *clmd = (ClothModifierData *) md; + BPATH_TRAVERSE_POINTCACHE(clmd->ptcaches); + } + else if (md->type == eModifierType_Ocean) { + OceanModifierData *omd = (OceanModifierData *) md; + rewrite_path_fixed(omd->cachepath, visit_cb, absbase, bpath_user_data); } } - else if (md->type==eModifierType_Cloth) { - ClothModifierData *clmd= (ClothModifierData*) md; - BPATH_TRAVERSE_POINTCACHE(clmd->ptcaches); - } - else if (md->type==eModifierType_Ocean) { - OceanModifierData *omd= (OceanModifierData*) md; - rewrite_path_fixed(omd->cachepath, visit_cb, absbase, bpath_user_data); - } - } - if (ob->soft) { - BPATH_TRAVERSE_POINTCACHE(ob->soft->ptcaches); - } + if (ob->soft) { + BPATH_TRAVERSE_POINTCACHE(ob->soft->ptcaches); + } - for (psys= ob->particlesystem.first; psys; psys= psys->next) { - BPATH_TRAVERSE_POINTCACHE(psys->ptcaches); + for (psys = ob->particlesystem.first; psys; psys = psys->next) { + BPATH_TRAVERSE_POINTCACHE(psys->ptcaches); + } } - } #undef BPATH_TRAVERSE_POINTCACHE - break; - case ID_SO: + break; + case ID_SO: { - bSound *sound= (bSound *)id; + bSound *sound = (bSound *)id; if (sound->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) { rewrite_path_fixed(sound->name, visit_cb, absbase, bpath_user_data); } } break; - case ID_TXT: - if (((Text*)id)->name) { - rewrite_path_alloc(&((Text *)id)->name, visit_cb, absbase, bpath_user_data); - } - break; - case ID_VF: + case ID_TXT: + if (((Text *)id)->name) { + rewrite_path_alloc(&((Text *)id)->name, visit_cb, absbase, bpath_user_data); + } + break; + case ID_VF: { - VFont *vf= (VFont *)id; + VFont *vf = (VFont *)id; if (vf->packedfile == NULL || (flag & BLI_BPATH_TRAVERSE_SKIP_PACKED) == 0) { if (strcmp(vf->name, FO_BUILTIN_NAME) != 0) { rewrite_path_fixed(((VFont *)id)->name, visit_cb, absbase, bpath_user_data); @@ -490,7 +490,7 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int } } break; - case ID_TE: + case ID_TE: { Tex *tex = (Tex *)id; if (tex->plugin) { @@ -504,13 +504,13 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int } break; - case ID_SCE: + case ID_SCE: { - Scene *scene= (Scene *)id; + Scene *scene = (Scene *)id; if (scene->ed) { Sequence *seq; - SEQ_BEGIN (scene->ed, seq) + SEQ_BEGIN(scene->ed, seq) { if (SEQ_HAS_PATH(seq)) { if (ELEM(seq->type, SEQ_MOVIE, SEQ_SOUND)) { @@ -519,16 +519,16 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int } else if (seq->type == SEQ_IMAGE) { /* might want an option not to loop over all strips */ - StripElem *se= seq->strip->stripdata; - int len= MEM_allocN_len(se) / sizeof(*se); + StripElem *se = seq->strip->stripdata; + int len = MEM_allocN_len(se) / sizeof(*se); int i; if (flag & BLI_BPATH_TRAVERSE_SKIP_MULTIFILE) { /* only operate on one path */ - len= MIN2(1, len); + 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); } @@ -547,31 +547,31 @@ void BLI_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int } } break; - case ID_ME: + case ID_ME: { - Mesh *me= (Mesh *)id; + Mesh *me = (Mesh *)id; if (me->fdata.external) { rewrite_path_fixed(me->fdata.external->filename, visit_cb, absbase, bpath_user_data); } } break; - case ID_LI: + case ID_LI: { - Library *lib= (Library *)id; + Library *lib = (Library *)id; if (rewrite_path_fixed(lib->name, visit_cb, absbase, bpath_user_data)) { BKE_library_filepath_set(lib, lib->name); } } break; - case ID_MC: + case ID_MC: { - MovieClip *clip= (MovieClip *)id; + MovieClip *clip = (MovieClip *)id; rewrite_path_fixed(clip->name, visit_cb, absbase, bpath_user_data); } break; - default: - /* Nothing to do for other IDs that don't contain file paths. */ - break; + default: + /* Nothing to do for other IDs that don't contain file paths. */ + break; } } diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index 531a4de361e..cdaf270adcb 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -41,14 +41,14 @@ #include "BLI_mempool.h" /**************inlined code************/ -static unsigned int _ehash_hashsizes[]= { +static unsigned int _ehash_hashsizes[] = { 1, 3, 5, 11, 17, 37, 67, 131, 257, 521, 1031, 2053, 4099, 8209, 16411, 32771, 65537, 131101, 262147, 524309, 1048583, 2097169, 4194319, 8388617, 16777259, 33554467, 67108879, 134217757, 268435459 }; -#define EDGE_HASH(v0, v1) ((v0 * 39)^(v1 * 31)) +#define EDGE_HASH(v0, v1) ((v0 * 39) ^ (v1 * 31)) /* ensure v0 is smaller */ #define EDGE_ORD(v0, v1) \ @@ -105,9 +105,9 @@ void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *v e->v1 = v1; e->val = val; e->next = eh->buckets[hash]; - eh->buckets[hash]= e; + eh->buckets[hash] = e; - if (++eh->nentries>eh->nbuckets * 3) { + if (++eh->nentries > eh->nbuckets * 3) { EdgeEntry *e, **old = eh->buckets; int i, nold = eh->nbuckets; @@ -116,12 +116,12 @@ void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *v memset(eh->buckets, 0, eh->nbuckets * sizeof(*eh->buckets)); for (i = 0; i < nold; i++) { - for (e = old[i]; e;) { + for (e = old[i]; e; ) { EdgeEntry *n = e->next; hash = EDGE_HASH(e->v0, e->v1) % eh->nbuckets; e->next = eh->buckets[hash]; - eh->buckets[hash]= e; + eh->buckets[hash] = e; e = n; } @@ -150,7 +150,7 @@ void *BLI_edgehash_lookup(EdgeHash *eh, unsigned int v0, unsigned int v1) { void **value_p = BLI_edgehash_lookup_p(eh, v0, v1); - return value_p?*value_p:NULL; + return value_p ? *value_p : NULL; } int BLI_edgehash_haskey(EdgeHash *eh, unsigned int v0, unsigned int v1) @@ -167,7 +167,7 @@ void BLI_edgehash_clear(EdgeHash *eh, EdgeHashFreeFP valfreefp) { int i; - for (i = 0; i<eh->nbuckets; i++) { + for (i = 0; i < eh->nbuckets; i++) { EdgeEntry *e; for (e = eh->buckets[i]; e; ) { @@ -231,7 +231,7 @@ void BLI_edgehashIterator_getKey(EdgeHashIterator *ehi, unsigned int *v0_r, unsi } void *BLI_edgehashIterator_getValue(EdgeHashIterator *ehi) { - return ehi->curEntry?ehi->curEntry->val:NULL; + return ehi->curEntry ? ehi->curEntry->val : NULL; } void BLI_edgehashIterator_setValue(EdgeHashIterator *ehi, void *val) diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 0a5e4d9fd48..e6d06484e74 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -74,7 +74,7 @@ int BLI_file_gzip(const char *from, const char *to) char buffer[10240]; int file; int readsize = 0; - int rval= 0, err; + int rval = 0, err; gzFile gzfile; /* level 1 is very close to 3 (the default) in terms of file size, @@ -82,7 +82,7 @@ int BLI_file_gzip(const char *from, const char *to) gzfile = BLI_gzopen(to, "wb1"); if (gzfile == NULL) return -1; - file = BLI_open(from, O_BINARY|O_RDONLY, 0); + file = BLI_open(from, O_BINARY | O_RDONLY, 0); if (file < 0) return -2; @@ -90,15 +90,15 @@ int BLI_file_gzip(const char *from, const char *to) readsize = read(file, buffer, sizeof(buffer)); if (readsize < 0) { - rval= -2; /* error happened in reading */ + rval = -2; /* error happened in reading */ fprintf(stderr, "Error reading file %s: %s.\n", from, strerror(errno)); break; } else if (readsize == 0) - break; /* done reading */ + break; /* done reading */ if (gzwrite(gzfile, buffer, readsize) <= 0) { - rval= -1; /* error happened in writing */ + rval = -1; /* error happened in writing */ fprintf(stderr, "Error writing gz file %s: %s.\n", to, gzerror(gzfile, &err)); break; } @@ -116,38 +116,38 @@ int BLI_file_gzip(const char *from, const char *to) char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r) { gzFile gzfile; - int readsize, size, alloc_size=0; - char *mem= NULL; - const int chunk_size= 512*1024; + int readsize, size, alloc_size = 0; + char *mem = NULL; + const int chunk_size = 512 * 1024; - size= 0; + size = 0; - gzfile = BLI_gzopen( from_file, "rb" ); - for (;;) { - if (mem==NULL) { - mem= MEM_callocN(chunk_size, "BLI_ungzip_to_mem"); - alloc_size= chunk_size; + gzfile = BLI_gzopen(from_file, "rb"); + for (;; ) { + if (mem == NULL) { + mem = MEM_callocN(chunk_size, "BLI_ungzip_to_mem"); + alloc_size = chunk_size; } else { - mem= MEM_reallocN(mem, size+chunk_size); - alloc_size+= chunk_size; + mem = MEM_reallocN(mem, size + chunk_size); + alloc_size += chunk_size; } - readsize= gzread(gzfile, mem+size, chunk_size); - if (readsize>0) { - size+= readsize; + readsize = gzread(gzfile, mem + size, chunk_size); + if (readsize > 0) { + size += readsize; } else break; } - if (size==0) { + if (size == 0) { MEM_freeN(mem); - mem= NULL; + mem = NULL; } - else if (alloc_size!=size) - mem= MEM_reallocN(mem, size); + else if (alloc_size != size) + mem = MEM_reallocN(mem, size); - *size_r= size; + *size_r = size; return mem; } @@ -254,14 +254,14 @@ int BLI_delete(const char *file, int dir, int recursive) if (recursive) { callLocalErrorCallBack("Recursive delete is unsupported on Windows"); - err= 1; + err = 1; } else if (dir) { - err= !RemoveDirectoryW(file_16); - if (err) printf ("Unable to remove directory"); + err = !RemoveDirectoryW(file_16); + if (err) printf("Unable to remove directory"); } else { - err= !DeleteFileW(file_16); + err = !DeleteFileW(file_16); if (err) callLocalErrorCallBack("Unable to delete file"); } @@ -288,7 +288,7 @@ int BLI_move(const char *file, const char *to) UTF16_ENCODE(file); UTF16_ENCODE(str); - err= !MoveFileW(file_16, str_16); + err = !MoveFileW(file_16, str_16); UTF16_UN_ENCODE(str); UTF16_UN_ENCODE(file); @@ -350,7 +350,7 @@ void BLI_dir_create_recursive(const char *dirname) * blah1/blah2 (without slash) */ BLI_strncpy(tmp, dirname, sizeof(tmp)); - lslash= BLI_last_slash(tmp); + lslash = BLI_last_slash(tmp); if (lslash == tmp + strlen(tmp) - 1) { *lslash = 0; @@ -358,7 +358,7 @@ void BLI_dir_create_recursive(const char *dirname) if (BLI_exists(tmp)) return; - lslash= BLI_last_slash(tmp); + lslash = BLI_last_slash(tmp); if (lslash) { /* Split about the last slash and recurse */ *lslash = 0; @@ -366,7 +366,7 @@ void BLI_dir_create_recursive(const char *dirname) } if (dirname[0]) /* patch, this recursive loop tries to create a nameless directory */ - if (umkdir(dirname)==-1) + if (umkdir(dirname) == -1) printf("Unable to create directory %s\n", dirname); } @@ -394,7 +394,7 @@ enum { recursiveOp_Callback_Error = 2 } recuresiveOp_Callback_Result; -typedef int (*recursiveOp_Callback) (const char *from, const char *to); +typedef int (*recursiveOp_Callback)(const char *from, const char *to); /* appending of filename to dir (ensures for buffer size before appending) */ static void join_dirfile_alloc(char **dst, size_t *alloc_len, const char *dir, const char *file) @@ -680,11 +680,11 @@ static int copy_single_file(const char *from, const char *to) need_free = 0; } else { - link_buffer = MEM_callocN(st.st_size+2, "copy_single_file link_buffer"); + link_buffer = MEM_callocN(st.st_size + 2, "copy_single_file link_buffer"); need_free = 1; } - link_len = readlink(from, link_buffer, st.st_size+1); + link_len = readlink(from, link_buffer, st.st_size + 1); if (link_len < 0) { perror("readlink"); @@ -706,10 +706,10 @@ static int copy_single_file(const char *from, const char *to) return recursiveOp_Callback_OK; } - else if (S_ISCHR (st.st_mode) || - S_ISBLK (st.st_mode) || - S_ISFIFO (st.st_mode) || - S_ISSOCK (st.st_mode)) + 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)) { @@ -798,7 +798,7 @@ static char *check_destination(const char *file, const char *to) if (!filename) { MEM_freeN(str); - return (char*)to; + return (char *)to; } /* skip slash */ @@ -814,7 +814,7 @@ static char *check_destination(const char *file, const char *to) } } - return (char*)to; + return (char *)to; } int BLI_copy(const char *file, const char *to) @@ -824,7 +824,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; @@ -852,16 +852,16 @@ void BLI_dir_create_recursive(const char *dirname) tmp = static_buf; needs_free = 0; #else - size = strlen(dirname)+1; + size = strlen(dirname) + 1; tmp = MEM_callocN(size, "BLI_dir_create_recursive tmp"); needs_free = 1; #endif BLI_strncpy(tmp, dirname, size); - lslash= BLI_last_slash(tmp); + lslash = BLI_last_slash(tmp); if (lslash) { - /* Split about the last slash and recurse */ + /* Split about the last slash and recurse */ *lslash = 0; BLI_dir_create_recursive(tmp); } diff --git a/source/blender/blenlib/intern/jitter.c b/source/blender/blenlib/intern/jitter.c index afe31fb1377..6203a98828b 100644 --- a/source/blender/blenlib/intern/jitter.c +++ b/source/blender/blenlib/intern/jitter.c @@ -43,41 +43,41 @@ void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1) int i, j, k; float vecx, vecy, dvecx, dvecy, x, y, len; - for (i = 2*num-2; i>=0 ; i-=2) { + for (i = 2 * num - 2; i >= 0; i -= 2) { dvecx = dvecy = 0.0; x = jit1[i]; - y = jit1[i+1]; - for (j = 2*num-2; j>=0 ; j-=2) { + y = jit1[i + 1]; + for (j = 2 * num - 2; j >= 0; j -= 2) { if (i != j) { vecx = jit1[j] - x - 1.0f; - vecy = jit1[j+1] - y - 1.0f; - for (k = 3; k>0 ; k--) { - if ( fabsf(vecx)<rad1 && fabsf(vecy)<rad1) { - len= sqrt(vecx*vecx + vecy*vecy); - if (len>0 && len<rad1) { - len= len/rad1; - dvecx += vecx/len; - dvecy += vecy/len; + vecy = jit1[j + 1] - y - 1.0f; + for (k = 3; k > 0; k--) { + if (fabsf(vecx) < rad1 && fabsf(vecy) < rad1) { + len = sqrt(vecx * vecx + vecy * vecy); + if (len > 0 && len < rad1) { + len = len / rad1; + dvecx += vecx / len; + dvecy += vecy / len; } } vecx += 1.0f; - if ( fabsf(vecx)<rad1 && fabsf(vecy)<rad1) { - len= sqrt(vecx*vecx + vecy*vecy); - if (len>0 && len<rad1) { - len= len/rad1; - dvecx += vecx/len; - dvecy += vecy/len; + if (fabsf(vecx) < rad1 && fabsf(vecy) < rad1) { + len = sqrt(vecx * vecx + vecy * vecy); + if (len > 0 && len < rad1) { + len = len / rad1; + dvecx += vecx / len; + dvecy += vecy / len; } } vecx += 1.0f; - if ( fabsf(vecx)<rad1 && fabsf(vecy)<rad1) { - len= sqrt(vecx*vecx + vecy*vecy); - if (len>0 && len<rad1) { - len= len/rad1; - dvecx += vecx/len; - dvecy += vecy/len; + if (fabsf(vecx) < rad1 && fabsf(vecy) < rad1) { + len = sqrt(vecx * vecx + vecy * vecy); + if (len > 0 && len < rad1) { + len = len / rad1; + dvecx += vecx / len; + dvecy += vecy / len; } } vecx -= 2.0f; @@ -86,12 +86,12 @@ void BLI_jitterate1(float *jit1, float *jit2, int num, float rad1) } } - x -= dvecx/18.0f; - y -= dvecy/18.0f; + x -= dvecx / 18.0f; + y -= dvecy / 18.0f; x -= floorf(x); y -= floorf(y); jit2[i] = x; - jit2[i+1] = y; + jit2[i + 1] = y; } memcpy(jit1, jit2, 2 * num * sizeof(float)); } @@ -101,36 +101,36 @@ void BLI_jitterate2(float *jit1, float *jit2, int num, float rad2) int i, j; float vecx, vecy, dvecx, dvecy, x, y; - for (i=2*num -2; i>= 0 ; i-=2) { + for (i = 2 * num - 2; i >= 0; i -= 2) { dvecx = dvecy = 0.0; x = jit1[i]; - y = jit1[i+1]; - for (j =2*num -2; j>= 0 ; j-=2) { + y = jit1[i + 1]; + for (j = 2 * num - 2; j >= 0; j -= 2) { if (i != j) { vecx = jit1[j] - x - 1.0f; - vecy = jit1[j+1] - y - 1.0f; + vecy = jit1[j + 1] - y - 1.0f; - if ( fabsf(vecx)<rad2) dvecx+= vecx*rad2; + if (fabsf(vecx) < rad2) dvecx += vecx * rad2; vecx += 1.0f; - if ( fabsf(vecx)<rad2) dvecx+= vecx*rad2; + if (fabsf(vecx) < rad2) dvecx += vecx * rad2; vecx += 1.0f; - if ( fabsf(vecx)<rad2) dvecx+= vecx*rad2; + if (fabsf(vecx) < rad2) dvecx += vecx * rad2; - if ( fabsf(vecy)<rad2) dvecy+= vecy*rad2; + if (fabsf(vecy) < rad2) dvecy += vecy * rad2; vecy += 1.0f; - if ( fabsf(vecy)<rad2) dvecy+= vecy*rad2; + if (fabsf(vecy) < rad2) dvecy += vecy * rad2; vecy += 1.0f; - if ( fabsf(vecy)<rad2) dvecy+= vecy*rad2; + if (fabsf(vecy) < rad2) dvecy += vecy * rad2; } } - x -= dvecx/2.0f; - y -= dvecy/2.0f; + x -= dvecx / 2.0f; + y -= dvecy / 2.0f; x -= floorf(x); y -= floorf(y); jit2[i] = x; - jit2[i+1] = y; + jit2[i + 1] = y; } memcpy(jit1, jit2, 2 * num * sizeof(float)); } @@ -141,23 +141,23 @@ void BLI_jitter_init(float *jitarr, int num) float *jit2, x, rad1, rad2, rad3; int i; - if (num==0) return; + if (num == 0) return; - jit2= MEM_mallocN(12 + 2*sizeof(float)*num, "initjit"); - rad1= 1.0f/sqrtf((float)num); - rad2= 1.0f/((float)num); - rad3= sqrtf((float)num)/((float)num); + jit2 = MEM_mallocN(12 + 2 * sizeof(float) * num, "initjit"); + rad1 = 1.0f / sqrtf((float)num); + rad2 = 1.0f / ((float)num); + rad3 = sqrtf((float)num) / ((float)num); BLI_srand(31415926 + num); - x= 0; - for (i=0; i<2*num; i+=2) { - jitarr[i]= x+ rad1*(float)(0.5-BLI_drand()); - jitarr[i+1]= ((float)i/2)/num +rad1*(float)(0.5-BLI_drand()); - x+= rad3; + x = 0; + for (i = 0; i < 2 * num; i += 2) { + jitarr[i] = x + rad1 * (float)(0.5 - BLI_drand()); + jitarr[i + 1] = ((float)i / 2) / num + rad1 * (float)(0.5 - BLI_drand()); + x += rad3; x -= floorf(x); } - for (i=0 ; i<24 ; i++) { + for (i = 0; i < 24; i++) { BLI_jitterate1(jitarr, jit2, num, rad1); BLI_jitterate1(jitarr, jit2, num, rad1); BLI_jitterate2(jitarr, jit2, num, rad2); @@ -166,9 +166,9 @@ void BLI_jitter_init(float *jitarr, int num) MEM_freeN(jit2); /* finally, move jittertab to be centered around (0,0) */ - for (i=0; i<2*num; i+=2) { + for (i = 0; i < 2 * num; i += 2) { jitarr[i] -= 0.5f; - jitarr[i+1] -= 0.5f; + jitarr[i + 1] -= 0.5f; } } diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index a81656d7ded..5f5321162c9 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -429,23 +429,23 @@ int isect_line_sphere_v3(const float l1[3], const float l2[3], */ const float ldir[3] = { - l2[0] - l1[0], - l2[1] - l1[1], - l2[2] - l1[2] + l2[0] - l1[0], + l2[1] - l1[1], + l2[2] - l1[2] }; const float a = dot_v3v3(ldir, ldir); const float b = 2.0f * - (ldir[0] * (l1[0] - sp[0]) + - ldir[1] * (l1[1] - sp[1]) + - ldir[2] * (l1[2] - sp[2])); + (ldir[0] * (l1[0] - sp[0]) + + ldir[1] * (l1[1] - sp[1]) + + ldir[2] * (l1[2] - sp[2])); const float c = - dot_v3v3(sp, sp) + - dot_v3v3(l1, l1) - - (2.0f * dot_v3v3(sp, l1)) - - (r * r); + dot_v3v3(sp, sp) + + dot_v3v3(l1, l1) - + (2.0f * dot_v3v3(sp, l1)) - + (r * r); const float i = b * b - 4.0f * a * c; @@ -490,14 +490,14 @@ int isect_line_sphere_v2(const float l1[2], const float l2[2], const float a = dot_v2v2(ldir, ldir); const float b = 2.0f * - (ldir[0] * (l1[0] - sp[0]) + - ldir[1] * (l1[1] - sp[1])); + (ldir[0] * (l1[0] - sp[0]) + + ldir[1] * (l1[1] - sp[1])); const float c = - dot_v2v2(sp, sp) + - dot_v2v2(l1, l1) - - (2.0f * dot_v2v2(sp, l1)) - - (r * r); + dot_v2v2(sp, sp) + + dot_v2v2(l1, l1) - + (2.0f * dot_v2v2(sp, l1)) - + (r * r); const float i = b * b - 4.0f * a * c; @@ -1738,9 +1738,9 @@ void axis_dominant_v3(int *axis_a, int *axis_b, const float axis[3]) const float yn = fabsf(axis[1]); const float zn = fabsf(axis[2]); - if (zn >= xn && zn >= yn) { *axis_a= 0; *axis_b = 1; } - else if (yn >= xn && yn >= zn) { *axis_a= 0; *axis_b = 2; } - else { *axis_a= 1; *axis_b = 2; } + if (zn >= xn && zn >= yn) { *axis_a = 0; *axis_b = 1; } + else if (yn >= xn && yn >= zn) { *axis_a = 0; *axis_b = 2; } + else { *axis_a = 1; *axis_b = 2; } } static float tri_signed_area(const float v1[3], const float v2[3], const float v3[3], const int i, const int j) diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 37402f9391c..066c9e7cd15 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1691,12 +1691,13 @@ void quat_apply_track(float quat[4], short axis, short upflag) { /* rotations are hard coded to match vec_to_quat */ const float quat_track[][4] = { - {0.70710676908493, 0.0, -0.70710676908493, 0.0}, /* pos-y90 */ - {0.5, 0.5, 0.5, 0.5}, /* Quaternion((1,0,0), radians(90)) * Quaternion((0,1,0), radians(90)) */ - {0.70710676908493, 0.0, 0.0, 0.70710676908493}, /* pos-z90 */ - {0.70710676908493, 0.0, 0.70710676908493, 0.0}, /* neg-y90 */ - {0.5, -0.5, -0.5, 0.5}, /* Quaternion((1,0,0), radians(-90)) * Quaternion((0,1,0), radians(-90)) */ - {-3.0908619663705394e-08, 0.70710676908493, 0.70710676908493, 3.0908619663705394e-08}}; /* no rotation */ + {0.70710676908493, 0.0, -0.70710676908493, 0.0}, /* pos-y90 */ + {0.5, 0.5, 0.5, 0.5}, /* Quaternion((1,0,0), radians(90)) * Quaternion((0,1,0), radians(90)) */ + {0.70710676908493, 0.0, 0.0, 0.70710676908493}, /* pos-z90 */ + {0.70710676908493, 0.0, 0.70710676908493, 0.0}, /* neg-y90 */ + {0.5, -0.5, -0.5, 0.5}, /* Quaternion((1,0,0), radians(-90)) * Quaternion((0,1,0), radians(-90)) */ + {-3.0908619663705394e-08, 0.70710676908493, 0.70710676908493, 3.0908619663705394e-08} /* no rotation */ + }; assert(axis >= 0 && axis <= 5); assert(upflag >= 0 && upflag <= 2); diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c index d795f9bf332..f591dc17f5b 100644 --- a/source/blender/blenlib/intern/noise.c +++ b/source/blender/blenlib/intern/noise.c @@ -45,10 +45,10 @@ static float noise3_perlin(float vec[3]); //static float turbulence_perlin(float *point, float lofreq, float hifreq); //static float turbulencep(float noisesize, float x, float y, float z, int nr); -#define HASHVEC(x, y, z) hashvectf + 3 * hash[ (hash[ (hash[(z) & 255] + (y)) & 255] + (x)) & 255] +#define HASHVEC(x, y, z) hashvectf + 3 * hash[(hash[(hash[(z) & 255] + (y)) & 255] + (x)) & 255] /* needed for voronoi */ -#define HASHPNT(x, y, z) hashpntf + 3 * hash[ (hash[ (hash[(z) & 255] + (y)) & 255] + (x)) & 255] +#define HASHPNT(x, y, z) hashpntf + 3 * hash[(hash[(hash[(z) & 255] + (y)) & 255] + (x)) & 255] static float hashpntf[768] = { 0.536902, 0.020915, 0.501445, 0.216316, 0.517036, 0.822466, 0.965315, 0.377313, 0.678764, 0.744545, 0.097731, 0.396357, 0.247202, 0.520897, @@ -162,7 +162,7 @@ static float hashpntf[768] = { 0.114246, 0.905043, 0.713870, 0.555261, 0.951333 }; -unsigned char hash[512]= { +unsigned char hash[512] = { 0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE, 0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32, 0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7, 0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, @@ -193,7 +193,7 @@ unsigned char hash[512]= { }; -float hashvectf[768]= { +float hashvectf[768] = { 0.33783, 0.715698, -0.611206, -0.944031, -0.326599, -0.045624, -0.101074, -0.416443, -0.903503, 0.799286, 0.49411, -0.341949, -0.854645, 0.518036, 0.033936, 0.42514, -0.437866, -0.792114, -0.358948, 0.597046, 0.717377, -0.985413, 0.144714, 0.089294, -0.601776, -0.33728, -0.723907, -0.449921, 0.594513, 0.666382, 0.208313, -0.10791, 0.972076, @@ -263,7 +263,7 @@ float hashvectf[768]= { 0.196045, -0.982941, 0.164307, -0.082245, 0.233734, -0.97226, -0.005005, -0.747253, -0.611328, 0.260437, 0.645599, 0.592773, 0.481384, 0.117706, -0.949524, -0.29068, -0.535004, -0.791901, -0.294312, -0.627167, -0.214447, 0.748718, -0.047974, -0.813477, -0.57959, -0.175537, 0.477264, -0.860992, 0.738556, -0.414246, -0.53183, 0.562561, -0.704071, -0.433289, -0.754944, 0.64801, -0.100586, 0.114716, 0.044525, -0.992371, 0.966003, 0.244873, -0.082764, + 0.433289, -0.754944, 0.64801, -0.100586, 0.114716, 0.044525, -0.992371, 0.966003, 0.244873, -0.082764, }; /**************************/ @@ -272,28 +272,28 @@ float hashvectf[768]= { static float lerp(float t, float a, float b) { - return (a+t*(b-a)); + return (a + t * (b - a)); } static float npfade(float t) { - return (t*t*t*(t*(t*6.0f-15.0f)+10.0f)); + return (t * t * t * (t * (t * 6.0f - 15.0f) + 10.0f)); } static float grad(int hash, float x, float y, float z) { int h = hash & 15; // CONVERT LO 4 BITS OF HASH CODE - float u = h<8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. - v = h<4 ? y : h==12||h==14 ? x : z; - return ((h&1) == 0 ? u : -u) + ((h&2) == 0 ? v : -v); + float u = h < 8 ? x : y, // INTO 12 GRADIENT DIRECTIONS. + v = h < 4 ? y : h == 12 || h == 14 ? x : z; + return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v); } /* instead of adding another permutation array, just use hash table defined above */ static float newPerlin(float x, float y, float z) { int A, AA, AB, B, BA, BB; - float u=floor(x), v=floor(y), w=floor(z); - int X=((int)u) & 255, Y=((int)v) & 255, Z=((int)w) & 255; // FIND UNIT CUBE THAT CONTAINS POINT + float u = floor(x), v = floor(y), w = floor(z); + int X = ((int)u) & 255, Y = ((int)v) & 255, Z = ((int)w) & 255; // FIND UNIT CUBE THAT CONTAINS POINT x -= u; // FIND RELATIVE X,Y,Z y -= v; // OF POINT IN CUBE. z -= w; @@ -315,7 +315,7 @@ static float newPerlin(float x, float y, float z) /* for use with BLI_gNoise()/BLI_gTurbulence(), returns unsigned improved perlin noise */ static float newPerlinU(float x, float y, float z) { - return (0.5f+0.5f*newPerlin(x, y, z)); + return (0.5f + 0.5f * newPerlin(x, y, z)); } @@ -328,92 +328,92 @@ static float orgBlenderNoise(float x, float y, float z) { register float cn1, cn2, cn3, cn4, cn5, cn6, i, *h; float fx, fy, fz, ox, oy, oz, jx, jy, jz; - float n= 0.5; + float n = 0.5; int ix, iy, iz, b00, b01, b10, b11, b20, b21; - fx= floor(x); - fy= floor(y); - fz= floor(z); - - ox= x- fx; - oy= y- fy; - oz= z- fz; - - ix= (int)fx; - iy= (int)fy; - iz= (int)fz; - - jx= ox-1; - jy= oy-1; - jz= oz-1; - - cn1=ox*ox; cn2=oy*oy; cn3=oz*oz; - cn4=jx*jx; cn5=jy*jy; cn6=jz*jz; - - cn1= 1.0f-3.0f*cn1+2.0f*cn1*ox; - cn2= 1.0f-3.0f*cn2+2.0f*cn2*oy; - cn3= 1.0f-3.0f*cn3+2.0f*cn3*oz; - cn4= 1.0f-3.0f*cn4-2.0f*cn4*jx; - cn5= 1.0f-3.0f*cn5-2.0f*cn5*jy; - cn6= 1.0f-3.0f*cn6-2.0f*cn6*jz; - - b00= hash[ hash[ix & 255]+(iy & 255)]; - b10= hash[ hash[(ix+1) & 255]+(iy & 255)]; - b01= hash[ hash[ix & 255]+((iy+1) & 255)]; - b11= hash[ hash[(ix+1) & 255]+((iy+1) & 255)]; - - b20=iz & 255; b21= (iz+1) & 255; - - /* 0 */ - i= (cn1*cn2*cn3); - h=hashvectf+ 3*hash[b20+b00]; - n+= i*(h[0]*ox+h[1]*oy+h[2]*oz); - /* 1 */ - i= (cn1*cn2*cn6); - h=hashvectf+ 3*hash[b21+b00]; - n+= i*(h[0]*ox+h[1]*oy+h[2]*jz); - /* 2 */ - i= (cn1*cn5*cn3); - h=hashvectf+ 3*hash[b20+b01]; - n+= i*(h[0]*ox+h[1]*jy+h[2]*oz); - /* 3 */ - i= (cn1*cn5*cn6); - h=hashvectf+ 3*hash[b21+b01]; - n+= i*(h[0]*ox+h[1]*jy+h[2]*jz); - /* 4 */ - i= cn4*cn2*cn3; - h=hashvectf+ 3*hash[b20+b10]; - n+= i*(h[0]*jx+h[1]*oy+h[2]*oz); - /* 5 */ - i= cn4*cn2*cn6; - h=hashvectf+ 3*hash[b21+b10]; - n+= i*(h[0]*jx+h[1]*oy+h[2]*jz); - /* 6 */ - i= cn4*cn5*cn3; - h=hashvectf+ 3*hash[b20+b11]; - n+= i*(h[0]*jx+h[1]*jy+h[2]*oz); - /* 7 */ - i= (cn4*cn5*cn6); - h=hashvectf+ 3*hash[b21+b11]; - n+= i*(h[0]*jx+h[1]*jy+h[2]*jz); - - if (n<0.0f) n=0.0f; else if (n>1.0f) n=1.0f; + fx = floor(x); + fy = floor(y); + fz = floor(z); + + ox = x - fx; + oy = y - fy; + oz = z - fz; + + ix = (int)fx; + iy = (int)fy; + iz = (int)fz; + + jx = ox - 1; + jy = oy - 1; + jz = oz - 1; + + cn1 = ox * ox; cn2 = oy * oy; cn3 = oz * oz; + cn4 = jx * jx; cn5 = jy * jy; cn6 = jz * jz; + + cn1 = 1.0f - 3.0f * cn1 + 2.0f * cn1 * ox; + cn2 = 1.0f - 3.0f * cn2 + 2.0f * cn2 * oy; + cn3 = 1.0f - 3.0f * cn3 + 2.0f * cn3 * oz; + cn4 = 1.0f - 3.0f * cn4 - 2.0f * cn4 * jx; + cn5 = 1.0f - 3.0f * cn5 - 2.0f * cn5 * jy; + cn6 = 1.0f - 3.0f * cn6 - 2.0f * cn6 * jz; + + b00 = hash[hash[ix & 255] + (iy & 255)]; + b10 = hash[hash[(ix + 1) & 255] + (iy & 255)]; + b01 = hash[hash[ix & 255] + ((iy + 1) & 255)]; + b11 = hash[hash[(ix + 1) & 255] + ((iy + 1) & 255)]; + + b20 = iz & 255; b21 = (iz + 1) & 255; + + /* 0 */ + i = (cn1 * cn2 * cn3); + h = hashvectf + 3 * hash[b20 + b00]; + n += i * (h[0] * ox + h[1] * oy + h[2] * oz); + /* 1 */ + i = (cn1 * cn2 * cn6); + h = hashvectf + 3 * hash[b21 + b00]; + n += i * (h[0] * ox + h[1] * oy + h[2] * jz); + /* 2 */ + i = (cn1 * cn5 * cn3); + h = hashvectf + 3 * hash[b20 + b01]; + n += i * (h[0] * ox + h[1] * jy + h[2] * oz); + /* 3 */ + i = (cn1 * cn5 * cn6); + h = hashvectf + 3 * hash[b21 + b01]; + n += i * (h[0] * ox + h[1] * jy + h[2] * jz); + /* 4 */ + i = cn4 * cn2 * cn3; + h = hashvectf + 3 * hash[b20 + b10]; + n += i * (h[0] * jx + h[1] * oy + h[2] * oz); + /* 5 */ + i = cn4 * cn2 * cn6; + h = hashvectf + 3 * hash[b21 + b10]; + n += i * (h[0] * jx + h[1] * oy + h[2] * jz); + /* 6 */ + i = cn4 * cn5 * cn3; + h = hashvectf + 3 * hash[b20 + b11]; + n += i * (h[0] * jx + h[1] * jy + h[2] * oz); + /* 7 */ + i = (cn4 * cn5 * cn6); + h = hashvectf + 3 * hash[b21 + b11]; + n += i * (h[0] * jx + h[1] * jy + h[2] * jz); + + if (n < 0.0f) n = 0.0f; else if (n > 1.0f) n = 1.0f; return n; } /* as orgBlenderNoise(), returning signed noise */ static float orgBlenderNoiseS(float x, float y, float z) { - return (2.0f*orgBlenderNoise(x, y, z)-1.0f); + return (2.0f * orgBlenderNoise(x, y, z) - 1.0f); } /* separated from orgBlenderNoise above, with scaling */ float BLI_hnoise(float noisesize, float x, float y, float z) { - if (noisesize==0.0f) return 0.0f; - x= (1.0f+x)/noisesize; - y= (1.0f+y)/noisesize; - z= (1.0f+z)/noisesize; + if (noisesize == 0.0f) return 0.0f; + x = (1.0f + x) / noisesize; + y = (1.0f + y) / noisesize; + z = (1.0f + z) / noisesize; return orgBlenderNoise(x, y, z); } @@ -421,53 +421,54 @@ float BLI_hnoise(float noisesize, float x, float y, float z) /* original turbulence functions */ float BLI_turbulence(float noisesize, float x, float y, float z, int nr) { - float s, d= 0.5, div=1.0; + float s, d = 0.5, div = 1.0; - s= BLI_hnoise(noisesize, x, y, z); + s = BLI_hnoise(noisesize, x, y, z); - while (nr>0) { + while (nr > 0) { - s+= d*BLI_hnoise(noisesize*d, x, y, z); - div+= d; - d*= 0.5f; + s += d * BLI_hnoise(noisesize * d, x, y, z); + div += d; + d *= 0.5f; nr--; } - return s/div; + return s / div; } float BLI_turbulence1(float noisesize, float x, float y, float z, int nr) { - float s, d= 0.5, div=1.0; + float s, d = 0.5, div = 1.0; - s= fabsf((-1.0f + 2.0f * BLI_hnoise(noisesize, x, y, z))); + 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; - d*= 0.5f; + s += fabsf(d * (-1.0f + 2.0f * BLI_hnoise(noisesize * d, x, y, z))); + div += d; + d *= 0.5f; nr--; } - return s/div; + return s / div; } /* ********************* FROM PERLIN HIMSELF: ******************** */ -static char p[512+2]= { -0xA2,0xA0,0x19,0x3B,0xF8,0xEB,0xAA,0xEE,0xF3,0x1C,0x67,0x28,0x1D,0xED,0x0,0xDE,0x95,0x2E,0xDC,0x3F,0x3A,0x82,0x35,0x4D,0x6C,0xBA,0x36,0xD0,0xF6,0xC,0x79,0x32,0xD1,0x59,0xF4,0x8,0x8B,0x63,0x89,0x2F,0xB8,0xB4,0x97,0x83,0xF2,0x8F,0x18,0xC7,0x51,0x14,0x65,0x87,0x48,0x20,0x42,0xA8,0x80,0xB5,0x40,0x13,0xB2,0x22,0x7E,0x57, -0xBC,0x7F,0x6B,0x9D,0x86,0x4C,0xC8,0xDB,0x7C,0xD5,0x25,0x4E,0x5A,0x55,0x74,0x50,0xCD,0xB3,0x7A,0xBB,0xC3,0xCB,0xB6,0xE2,0xE4,0xEC,0xFD,0x98,0xB,0x96,0xD3,0x9E,0x5C,0xA1,0x64,0xF1,0x81,0x61,0xE1,0xC4,0x24,0x72,0x49,0x8C,0x90,0x4B,0x84,0x34,0x38,0xAB,0x78,0xCA,0x1F,0x1,0xD7,0x93,0x11,0xC1,0x58,0xA9,0x31,0xF9,0x44,0x6D, -0xBF,0x33,0x9C,0x5F,0x9,0x94,0xA3,0x85,0x6,0xC6,0x9A,0x1E,0x7B,0x46,0x15,0x30,0x27,0x2B,0x1B,0x71,0x3C,0x5B,0xD6,0x6F,0x62,0xAC,0x4F,0xC2,0xC0,0xE,0xB1,0x23,0xA7,0xDF,0x47,0xB0,0x77,0x69,0x5,0xE9,0xE6,0xE7,0x76,0x73,0xF,0xFE,0x6E,0x9B,0x56,0xEF,0x12,0xA5,0x37,0xFC,0xAE,0xD9,0x3,0x8E,0xDD,0x10,0xB9,0xCE,0xC9,0x8D, -0xDA,0x2A,0xBD,0x68,0x17,0x9F,0xBE,0xD4,0xA,0xCC,0xD2,0xE8,0x43,0x3D,0x70,0xB7,0x2,0x7D,0x99,0xD8,0xD,0x60,0x8A,0x4,0x2C,0x3E,0x92,0xE5,0xAF,0x53,0x7,0xE0,0x29,0xA6,0xC5,0xE3,0xF5,0xF7,0x4A,0x41,0x26,0x6A,0x16,0x5E,0x52,0x2D,0x21,0xAD,0xF0,0x91,0xFF,0xEA,0x54,0xFA,0x66,0x1A,0x45,0x39,0xCF,0x75,0xA4,0x88,0xFB,0x5D, -0xA2,0xA0,0x19,0x3B,0xF8,0xEB,0xAA,0xEE,0xF3,0x1C,0x67,0x28,0x1D,0xED,0x0,0xDE,0x95,0x2E,0xDC,0x3F,0x3A,0x82,0x35,0x4D,0x6C,0xBA,0x36,0xD0,0xF6,0xC,0x79,0x32,0xD1,0x59,0xF4,0x8,0x8B,0x63,0x89,0x2F,0xB8,0xB4,0x97,0x83,0xF2,0x8F,0x18,0xC7,0x51,0x14,0x65,0x87,0x48,0x20,0x42,0xA8,0x80,0xB5,0x40,0x13,0xB2,0x22,0x7E,0x57, -0xBC,0x7F,0x6B,0x9D,0x86,0x4C,0xC8,0xDB,0x7C,0xD5,0x25,0x4E,0x5A,0x55,0x74,0x50,0xCD,0xB3,0x7A,0xBB,0xC3,0xCB,0xB6,0xE2,0xE4,0xEC,0xFD,0x98,0xB,0x96,0xD3,0x9E,0x5C,0xA1,0x64,0xF1,0x81,0x61,0xE1,0xC4,0x24,0x72,0x49,0x8C,0x90,0x4B,0x84,0x34,0x38,0xAB,0x78,0xCA,0x1F,0x1,0xD7,0x93,0x11,0xC1,0x58,0xA9,0x31,0xF9,0x44,0x6D, -0xBF,0x33,0x9C,0x5F,0x9,0x94,0xA3,0x85,0x6,0xC6,0x9A,0x1E,0x7B,0x46,0x15,0x30,0x27,0x2B,0x1B,0x71,0x3C,0x5B,0xD6,0x6F,0x62,0xAC,0x4F,0xC2,0xC0,0xE,0xB1,0x23,0xA7,0xDF,0x47,0xB0,0x77,0x69,0x5,0xE9,0xE6,0xE7,0x76,0x73,0xF,0xFE,0x6E,0x9B,0x56,0xEF,0x12,0xA5,0x37,0xFC,0xAE,0xD9,0x3,0x8E,0xDD,0x10,0xB9,0xCE,0xC9,0x8D, -0xDA,0x2A,0xBD,0x68,0x17,0x9F,0xBE,0xD4,0xA,0xCC,0xD2,0xE8,0x43,0x3D,0x70,0xB7,0x2,0x7D,0x99,0xD8,0xD,0x60,0x8A,0x4,0x2C,0x3E,0x92,0xE5,0xAF,0x53,0x7,0xE0,0x29,0xA6,0xC5,0xE3,0xF5,0xF7,0x4A,0x41,0x26,0x6A,0x16,0x5E,0x52,0x2D,0x21,0xAD,0xF0,0x91,0xFF,0xEA,0x54,0xFA,0x66,0x1A,0x45,0x39,0xCF,0x75,0xA4,0x88,0xFB,0x5D, -0xA2,0xA0}; +static char p[512 + 2] = { + 0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE, 0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32, 0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7, 0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, 0xB5, 0x40, 0x13, 0xB2, 0x22, 0x7E, 0x57, + 0xBC, 0x7F, 0x6B, 0x9D, 0x86, 0x4C, 0xC8, 0xDB, 0x7C, 0xD5, 0x25, 0x4E, 0x5A, 0x55, 0x74, 0x50, 0xCD, 0xB3, 0x7A, 0xBB, 0xC3, 0xCB, 0xB6, 0xE2, 0xE4, 0xEC, 0xFD, 0x98, 0xB, 0x96, 0xD3, 0x9E, 0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4, 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34, 0x38, 0xAB, 0x78, 0xCA, 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D, + 0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E, 0x7B, 0x46, 0x15, 0x30, 0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD6, 0x6F, 0x62, 0xAC, 0x4F, 0xC2, 0xC0, 0xE, 0xB1, 0x23, 0xA7, 0xDF, 0x47, 0xB0, 0x77, 0x69, 0x5, 0xE9, 0xE6, 0xE7, 0x76, 0x73, 0xF, 0xFE, 0x6E, 0x9B, 0x56, 0xEF, 0x12, 0xA5, 0x37, 0xFC, 0xAE, 0xD9, 0x3, 0x8E, 0xDD, 0x10, 0xB9, 0xCE, 0xC9, 0x8D, + 0xDA, 0x2A, 0xBD, 0x68, 0x17, 0x9F, 0xBE, 0xD4, 0xA, 0xCC, 0xD2, 0xE8, 0x43, 0x3D, 0x70, 0xB7, 0x2, 0x7D, 0x99, 0xD8, 0xD, 0x60, 0x8A, 0x4, 0x2C, 0x3E, 0x92, 0xE5, 0xAF, 0x53, 0x7, 0xE0, 0x29, 0xA6, 0xC5, 0xE3, 0xF5, 0xF7, 0x4A, 0x41, 0x26, 0x6A, 0x16, 0x5E, 0x52, 0x2D, 0x21, 0xAD, 0xF0, 0x91, 0xFF, 0xEA, 0x54, 0xFA, 0x66, 0x1A, 0x45, 0x39, 0xCF, 0x75, 0xA4, 0x88, 0xFB, 0x5D, + 0xA2, 0xA0, 0x19, 0x3B, 0xF8, 0xEB, 0xAA, 0xEE, 0xF3, 0x1C, 0x67, 0x28, 0x1D, 0xED, 0x0, 0xDE, 0x95, 0x2E, 0xDC, 0x3F, 0x3A, 0x82, 0x35, 0x4D, 0x6C, 0xBA, 0x36, 0xD0, 0xF6, 0xC, 0x79, 0x32, 0xD1, 0x59, 0xF4, 0x8, 0x8B, 0x63, 0x89, 0x2F, 0xB8, 0xB4, 0x97, 0x83, 0xF2, 0x8F, 0x18, 0xC7, 0x51, 0x14, 0x65, 0x87, 0x48, 0x20, 0x42, 0xA8, 0x80, 0xB5, 0x40, 0x13, 0xB2, 0x22, 0x7E, 0x57, + 0xBC, 0x7F, 0x6B, 0x9D, 0x86, 0x4C, 0xC8, 0xDB, 0x7C, 0xD5, 0x25, 0x4E, 0x5A, 0x55, 0x74, 0x50, 0xCD, 0xB3, 0x7A, 0xBB, 0xC3, 0xCB, 0xB6, 0xE2, 0xE4, 0xEC, 0xFD, 0x98, 0xB, 0x96, 0xD3, 0x9E, 0x5C, 0xA1, 0x64, 0xF1, 0x81, 0x61, 0xE1, 0xC4, 0x24, 0x72, 0x49, 0x8C, 0x90, 0x4B, 0x84, 0x34, 0x38, 0xAB, 0x78, 0xCA, 0x1F, 0x1, 0xD7, 0x93, 0x11, 0xC1, 0x58, 0xA9, 0x31, 0xF9, 0x44, 0x6D, + 0xBF, 0x33, 0x9C, 0x5F, 0x9, 0x94, 0xA3, 0x85, 0x6, 0xC6, 0x9A, 0x1E, 0x7B, 0x46, 0x15, 0x30, 0x27, 0x2B, 0x1B, 0x71, 0x3C, 0x5B, 0xD6, 0x6F, 0x62, 0xAC, 0x4F, 0xC2, 0xC0, 0xE, 0xB1, 0x23, 0xA7, 0xDF, 0x47, 0xB0, 0x77, 0x69, 0x5, 0xE9, 0xE6, 0xE7, 0x76, 0x73, 0xF, 0xFE, 0x6E, 0x9B, 0x56, 0xEF, 0x12, 0xA5, 0x37, 0xFC, 0xAE, 0xD9, 0x3, 0x8E, 0xDD, 0x10, 0xB9, 0xCE, 0xC9, 0x8D, + 0xDA, 0x2A, 0xBD, 0x68, 0x17, 0x9F, 0xBE, 0xD4, 0xA, 0xCC, 0xD2, 0xE8, 0x43, 0x3D, 0x70, 0xB7, 0x2, 0x7D, 0x99, 0xD8, 0xD, 0x60, 0x8A, 0x4, 0x2C, 0x3E, 0x92, 0xE5, 0xAF, 0x53, 0x7, 0xE0, 0x29, 0xA6, 0xC5, 0xE3, 0xF5, 0xF7, 0x4A, 0x41, 0x26, 0x6A, 0x16, 0x5E, 0x52, 0x2D, 0x21, 0xAD, 0xF0, 0x91, 0xFF, 0xEA, 0x54, 0xFA, 0x66, 0x1A, 0x45, 0x39, 0xCF, 0x75, 0xA4, 0x88, 0xFB, 0x5D, + 0xA2, 0xA0 +}; -static float g[512+2][3]= { +static float g[512 + 2][3] = { {0.33783, 0.715698, -0.611206}, {-0.944031, -0.326599, -0.045624}, {-0.101074, -0.416443, -0.903503}, @@ -1005,15 +1006,15 @@ static float noise3_perlin(float vec[3]) SETUP(vec[1], by0, by1, ry0, ry1); SETUP(vec[2], bz0, bz1, rz0, rz1); - i = p[ bx0 ]; - j = p[ bx1 ]; + i = p[bx0]; + j = p[bx1]; - b00 = p[ i + by0 ]; - b10 = p[ j + by0 ]; - b01 = p[ i + by1 ]; - b11 = p[ j + by1 ]; + b00 = p[i + by0]; + b10 = p[j + by0]; + b01 = p[i + by1]; + b11 = p[j + by1]; -#define VALUE_AT(rx,ry,rz) (rx * q[0] + ry * q[1] + rz * q[2]) +#define VALUE_AT(rx, ry, rz) (rx * q[0] + ry * q[1] + rz * q[2]) #define SURVE(t) (t * t * (3.0f - 2.0f * t)) /* lerp moved to improved perlin above */ @@ -1023,30 +1024,30 @@ static float noise3_perlin(float vec[3]) sz = SURVE(rz0); - q = g[ b00 + bz0 ]; - u = VALUE_AT(rx0,ry0,rz0); - q = g[ b10 + bz0 ]; - v = VALUE_AT(rx1,ry0,rz0); + q = g[b00 + bz0]; + u = VALUE_AT(rx0, ry0, rz0); + q = g[b10 + bz0]; + v = VALUE_AT(rx1, ry0, rz0); a = lerp(sx, u, v); - q = g[ b01 + bz0 ]; - u = VALUE_AT(rx0,ry1,rz0); - q = g[ b11 + bz0 ]; - v = VALUE_AT(rx1,ry1,rz0); + q = g[b01 + bz0]; + u = VALUE_AT(rx0, ry1, rz0); + q = g[b11 + bz0]; + v = VALUE_AT(rx1, ry1, rz0); b = lerp(sx, u, v); c = lerp(sy, a, b); /* interpolate in y at lo x */ - q = g[ b00 + bz1 ]; - u = VALUE_AT(rx0,ry0,rz1); - q = g[ b10 + bz1 ]; - v = VALUE_AT(rx1,ry0,rz1); + q = g[b00 + bz1]; + u = VALUE_AT(rx0, ry0, rz1); + q = g[b10 + bz1]; + v = VALUE_AT(rx1, ry0, rz1); a = lerp(sx, u, v); - q = g[ b01 + bz1 ]; - u = VALUE_AT(rx0,ry1,rz1); - q = g[ b11 + bz1 ]; - v = VALUE_AT(rx1,ry1,rz1); + q = g[b01 + bz1]; + u = VALUE_AT(rx0, ry1, rz1); + q = g[b11 + bz1]; + v = VALUE_AT(rx1, ry1, rz1); b = lerp(sx, u, v); d = lerp(sy, a, b); /* interpolate in y at hi x */ @@ -1067,7 +1068,7 @@ static float turbulence_perlin(float *point, float lofreq, float hifreq) p[2] = point[2]; t = 0; - for (freq = lofreq ; freq < hifreq ; freq *= 2.0) { + for (freq = lofreq; freq < hifreq; freq *= 2.0) { t += fabsf(noise3_perlin(p)) / freq; p[0] *= 2.0f; p[1] *= 2.0f; @@ -1096,7 +1097,7 @@ static float orgPerlinNoiseU(float x, float y, float z) v[0] = x; v[1] = y; v[2] = z; - return (0.5f+0.5f*noise3_perlin(v)); + return (0.5f + 0.5f * noise3_perlin(v)); } /* *************** CALL AS: *************** */ @@ -1105,9 +1106,9 @@ float BLI_hnoisep(float noisesize, float x, float y, float z) { float vec[3]; - vec[0]= x/noisesize; - vec[1]= y/noisesize; - vec[2]= z/noisesize; + vec[0] = x / noisesize; + vec[1] = y / noisesize; + vec[2] = z / noisesize; return noise3_perlin(vec); } @@ -1117,11 +1118,11 @@ static float turbulencep(float noisesize, float x, float y, float z, int nr) { float vec[3]; - vec[0]= x/noisesize; - vec[1]= y/noisesize; - vec[2]= z/noisesize; + vec[0] = x / noisesize; + vec[1] = y / noisesize; + vec[2] = z / noisesize; nr++; - return turbulence_perlin(vec, 1.0, (float)(1<<nr)); + return turbulence_perlin(vec, 1.0, (float)(1 << nr)); } #endif @@ -1133,11 +1134,17 @@ static float turbulencep(float noisesize, float x, float y, float z, int nr) /* Camberra omitted, didn't seem useful */ /* distance squared */ -static float dist_Squared(float x, float y, float z, float e) { (void)e; return (x*x + y*y + z*z); } +static float dist_Squared(float x, float y, float z, float e) { + (void)e; return (x * x + y * y + z * z); +} /* real distance */ -static float dist_Real(float x, float y, float z, float e) { (void)e; return sqrtf(x*x + y*y + z*z); } +static float dist_Real(float x, float y, float z, float e) { + (void)e; return sqrtf(x * x + y * y + z * z); +} /* manhattan/taxicab/cityblock distance */ -static float dist_Manhattan(float x, float y, float z, float e) { (void)e; return (fabsf(x) + fabsf(y) + fabsf(z)); } +static float dist_Manhattan(float x, float y, float z, float e) { + (void)e; return (fabsf(x) + fabsf(y) + fabsf(z)); +} /* Chebychev */ static float dist_Chebychev(float x, float y, float z, float e) { @@ -1147,8 +1154,8 @@ static float dist_Chebychev(float x, float y, float z, float e) x = fabsf(x); y = fabsf(y); z = fabsf(z); - t = (x>y)?x:y; - return ((z>t)?z:t); + t = (x > y) ? x : y; + return ((z > t) ? z : t); } /* minkovsky preset exponent 0.5 */ @@ -1156,7 +1163,7 @@ static float dist_MinkovskyH(float x, float y, float z, float e) { float d = sqrtf(fabsf(x)) + sqrtf(fabsf(y)) + sqrtf(fabsf(z)); (void)e; - return (d*d); + return (d * d); } /* minkovsky preset exponent 4 */ @@ -1166,19 +1173,19 @@ static float dist_Minkovsky4(float x, float y, float z, float e) x *= x; y *= y; z *= z; - return sqrtf(sqrtf(x*x + y*y + z*z)); + return sqrtf(sqrtf(x * x + y * y + z * z)); } /* Minkovsky, general case, slow, maybe too slow to be useful */ static float dist_Minkovsky(float x, float y, float z, float e) { - return powf(powf(fabsf(x), e) + powf(fabsf(y), e) + powf(fabsf(z), e), 1.0f/e); + return powf(powf(fabsf(x), e) + powf(fabsf(y), e) + powf(fabsf(z), e), 1.0f / e); } /* Not 'pure' Worley, but the results are virtually the same. * Returns distances in da and point coords in pa */ -void voronoi(float x, float y, float z, float* da, float* pa, float me, int dtype) +void voronoi(float x, float y, float z, float *da, float *pa, float me, int dtype) { int xx, yy, zz, xi, yi, zi; float xd, yd, zd, d, *p; @@ -1212,35 +1219,35 @@ void voronoi(float x, float y, float z, float* da, float* pa, float me, int dtyp yi = (int)(floor(y)); zi = (int)(floor(z)); da[0] = da[1] = da[2] = da[3] = 1e10f; - for (xx=xi-1;xx<=xi+1;xx++) { - for (yy=yi-1;yy<=yi+1;yy++) { - for (zz=zi-1;zz<=zi+1;zz++) { + for (xx = xi - 1; xx <= xi + 1; xx++) { + for (yy = yi - 1; yy <= yi + 1; yy++) { + for (zz = zi - 1; zz <= zi + 1; zz++) { p = HASHPNT(xx, yy, zz); xd = x - (p[0] + xx); yd = y - (p[1] + yy); zd = z - (p[2] + zz); d = distfunc(xd, yd, zd, me); - if (d<da[0]) { - da[3]=da[2]; da[2]=da[1]; da[1]=da[0]; da[0]=d; - pa[9]=pa[6]; pa[10]=pa[7]; pa[11]=pa[8]; - pa[6]=pa[3]; pa[7]=pa[4]; pa[8]=pa[5]; - pa[3]=pa[0]; pa[4]=pa[1]; pa[5]=pa[2]; - pa[0]=p[0]+xx; pa[1]=p[1]+yy; pa[2]=p[2]+zz; + if (d < da[0]) { + da[3] = da[2]; da[2] = da[1]; da[1] = da[0]; da[0] = d; + pa[9] = pa[6]; pa[10] = pa[7]; pa[11] = pa[8]; + pa[6] = pa[3]; pa[7] = pa[4]; pa[8] = pa[5]; + pa[3] = pa[0]; pa[4] = pa[1]; pa[5] = pa[2]; + pa[0] = p[0] + xx; pa[1] = p[1] + yy; pa[2] = p[2] + zz; } - else if (d<da[1]) { - da[3]=da[2]; da[2]=da[1]; da[1]=d; - pa[9]=pa[6]; pa[10]=pa[7]; pa[11]=pa[8]; - pa[6]=pa[3]; pa[7]=pa[4]; pa[8]=pa[5]; - pa[3]=p[0]+xx; pa[4]=p[1]+yy; pa[5]=p[2]+zz; + else if (d < da[1]) { + da[3] = da[2]; da[2] = da[1]; da[1] = d; + pa[9] = pa[6]; pa[10] = pa[7]; pa[11] = pa[8]; + pa[6] = pa[3]; pa[7] = pa[4]; pa[8] = pa[5]; + pa[3] = p[0] + xx; pa[4] = p[1] + yy; pa[5] = p[2] + zz; } - else if (d<da[2]) { - da[3]=da[2]; da[2]=d; - pa[9]=pa[6]; pa[10]=pa[7]; pa[11]=pa[8]; - pa[6]=p[0]+xx; pa[7]=p[1]+yy; pa[8]=p[2]+zz; + else if (d < da[2]) { + da[3] = da[2]; da[2] = d; + pa[9] = pa[6]; pa[10] = pa[7]; pa[11] = pa[8]; + pa[6] = p[0] + xx; pa[7] = p[1] + yy; pa[8] = p[2] + zz; } - else if (d<da[3]) { - da[3]=d; - pa[9]=p[0]+xx; pa[10]=p[1]+yy; pa[11]=p[2]+zz; + else if (d < da[3]) { + da[3] = d; + pa[9] = p[0] + xx; pa[10] = p[1] + yy; pa[11] = p[2] + zz; } } } @@ -1280,14 +1287,14 @@ static float voronoi_F1F2(float x, float y, float z) { float da[4], pa[12]; voronoi(x, y, z, da, pa, 1, 0); - return (da[1]-da[0]); + return (da[1] - da[0]); } /* Crackle type pattern, just a scale/clamp of F2-F1 */ static float voronoi_Cr(float x, float y, float z) { - float t = 10*voronoi_F1F2(x, y, z); - if (t>1.f) return 1.f; + float t = 10 * voronoi_F1F2(x, y, z); + if (t > 1.f) return 1.f; return t; } @@ -1298,43 +1305,43 @@ static float voronoi_F1S(float x, float y, float z) { float da[4], pa[12]; voronoi(x, y, z, da, pa, 1, 0); - return (2.0f*da[0]-1.0f); + return (2.0f * da[0] - 1.0f); } static float voronoi_F2S(float x, float y, float z) { float da[4], pa[12]; voronoi(x, y, z, da, pa, 1, 0); - return (2.0f*da[1]-1.0f); + return (2.0f * da[1] - 1.0f); } static float voronoi_F3S(float x, float y, float z) { float da[4], pa[12]; voronoi(x, y, z, da, pa, 1, 0); - return (2.0f*da[2]-1.0f); + return (2.0f * da[2] - 1.0f); } static float voronoi_F4S(float x, float y, float z) { float da[4], pa[12]; voronoi(x, y, z, da, pa, 1, 0); - return (2.0f*da[3]-1.0f); + return (2.0f * da[3] - 1.0f); } static float voronoi_F1F2S(float x, float y, float z) { float da[4], pa[12]; voronoi(x, y, z, da, pa, 1, 0); - return (2.0f*(da[1]-da[0])-1.0f); + return (2.0f * (da[1] - da[0]) - 1.0f); } /* Crackle type pattern, just a scale/clamp of F2-F1 */ static float voronoi_CrS(float x, float y, float z) { - float t = 10*voronoi_F1F2(x, y, z); - if (t>1.f) return 1.f; - return (2.0f*t-1.0f); + float t = 10 * voronoi_F1F2(x, y, z); + if (t > 1.f) return 1.f; + return (2.0f * t - 1.0f); } @@ -1352,15 +1359,15 @@ static float cellNoiseU(float x, float y, float z) int xi = (int)(floor(x)); int yi = (int)(floor(y)); int zi = (int)(floor(z)); - unsigned int n = xi + yi*1301 + zi*314159; - n ^= (n<<13); - return ((float)(n*(n*n*15731 + 789221) + 1376312589) / 4294967296.0f); + unsigned int n = xi + yi * 1301 + zi * 314159; + n ^= (n << 13); + return ((float)(n * (n * n * 15731 + 789221) + 1376312589) / 4294967296.0f); } /* idem, signed */ float cellNoise(float x, float y, float z) { - return (2.0f*cellNoiseU(x, y, z)-1.0f); + return (2.0f * cellNoiseU(x, y, z) - 1.0f); } /* returns a vector/point/color in ca, using point hasharray directly */ @@ -1423,14 +1430,14 @@ float BLI_gNoise(float noisesize, float x, float y, float z, int hard, int noise } } - if (noisesize!=0.0f) { - noisesize = 1.0f/noisesize; + if (noisesize != 0.0f) { + noisesize = 1.0f / noisesize; x *= noisesize; y *= noisesize; z *= noisesize; } - if (hard) return fabsf(2.0f*noisefunc(x, y, z)-1.0f); + if (hard) return fabsf(2.0f * noisefunc(x, y, z) - 1.0f); return noisefunc(x, y, z); } @@ -1438,7 +1445,7 @@ float BLI_gNoise(float noisesize, float x, float y, float z, int hard, int noise float BLI_gTurbulence(float noisesize, float x, float y, float z, int oct, int hard, int noisebasis) { float (*noisefunc)(float, float, float); - float sum, t, amp=1, fscale=1; + float sum, t, amp = 1, fscale = 1; int i; switch (noisebasis) { @@ -1477,21 +1484,21 @@ float BLI_gTurbulence(float noisesize, float x, float y, float z, int oct, int h z += 1; } - if (noisesize!=0.0f) { - noisesize = 1.0f/noisesize; + if (noisesize != 0.0f) { + noisesize = 1.0f / noisesize; x *= noisesize; y *= noisesize; z *= noisesize; } sum = 0; - for (i=0;i<=oct;i++, amp*=0.5f, fscale*=2.0f) { - t = noisefunc(fscale*x, fscale*y, fscale*z); - if (hard) t = fabsf(2.0f*t-1.0f); + for (i = 0; i <= oct; i++, amp *= 0.5f, fscale *= 2.0f) { + t = noisefunc(fscale * x, fscale * y, fscale * z); + if (hard) t = fabsf(2.0f * t - 1.0f); sum += t * amp; } - sum *= ((float)(1<<oct)/(float)((1<<(oct+1))-1)); + sum *= ((float)(1 << oct) / (float)((1 << (oct + 1)) - 1)); return sum; @@ -1513,8 +1520,8 @@ float BLI_gTurbulence(float noisesize, float x, float y, float z, int oct, int h */ float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis) { - float rmd, value=0.0, pwr=1.0, pwHL=powf(lacunarity, -H); - int i; + float rmd, value = 0.0, pwr = 1.0, pwHL = powf(lacunarity, -H); + int i; float (*noisefunc)(float, float, float); switch (noisebasis) { @@ -1551,7 +1558,7 @@ float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves } } - for (i=0; i<(int)octaves; i++) { + for (i = 0; i < (int)octaves; i++) { value += noisefunc(x, y, z) * pwr; pwr *= pwHL; x *= lacunarity; @@ -1560,7 +1567,7 @@ float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves } rmd = octaves - floorf(octaves); - if (rmd!=0.f) value += rmd * noisefunc(x, y, z) * pwr; + if (rmd != 0.f) value += rmd * noisefunc(x, y, z) * pwr; return value; @@ -1583,7 +1590,7 @@ float mg_fBm(float x, float y, float z, float H, float lacunarity, float octaves * I modified it to something that made sense to me, so it might be wrong... */ float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, int noisebasis) { - float rmd, value=1.0, pwr=1.0, pwHL=powf(lacunarity, -H); + float rmd, value = 1.0, pwr = 1.0, pwHL = powf(lacunarity, -H); int i; float (*noisefunc)(float, float, float); @@ -1621,7 +1628,7 @@ float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, floa } } - for (i=0; i<(int)octaves; i++) { + for (i = 0; i < (int)octaves; i++) { value *= (pwr * noisefunc(x, y, z) + 1.0f); pwr *= pwHL; x *= lacunarity; @@ -1629,7 +1636,7 @@ float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, floa z *= lacunarity; } rmd = octaves - floorf(octaves); - if (rmd!=0.0f) value *= (rmd * noisefunc(x, y, z) * pwr + 1.0f); + if (rmd != 0.0f) value *= (rmd * noisefunc(x, y, z) * pwr + 1.0f); return value; @@ -1647,10 +1654,10 @@ float mg_MultiFractal(float x, float y, float z, float H, float lacunarity, floa */ float mg_HeteroTerrain(float x, float y, float z, float H, float lacunarity, float octaves, float offset, int noisebasis) { - float value, increment, rmd; + float value, increment, rmd; int i; float pwHL = powf(lacunarity, -H); - float pwr = pwHL; /* starts with i=1 instead of 0 */ + float pwr = pwHL; /* starts with i=1 instead of 0 */ float (*noisefunc)(float, float, float); switch (noisebasis) { @@ -1693,7 +1700,7 @@ float mg_HeteroTerrain(float x, float y, float z, float H, float lacunarity, flo y *= lacunarity; z *= lacunarity; - for (i=1; i<(int)octaves; i++) { + for (i = 1; i < (int)octaves; i++) { increment = (noisefunc(x, y, z) + offset) * pwr * value; value += increment; pwr *= pwHL; @@ -1703,7 +1710,7 @@ float mg_HeteroTerrain(float x, float y, float z, float H, float lacunarity, flo } rmd = octaves - floorf(octaves); - if (rmd!=0.0f) { + if (rmd != 0.0f) { increment = (noisefunc(x, y, z) + offset) * pwr * value; value += rmd * increment; } @@ -1723,7 +1730,7 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity float result, signal, weight, rmd; int i; float pwHL = powf(lacunarity, -H); - float pwr = pwHL; /* starts with i=1 instead of 0 */ + float pwr = pwHL; /* starts with i=1 instead of 0 */ float (*noisefunc)(float, float, float); switch (noisebasis) { @@ -1766,8 +1773,8 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity y *= lacunarity; z *= lacunarity; - for (i=1; (weight>0.001f) && (i<(int)octaves); i++) { - if (weight>1.0f) weight=1.0f; + for (i = 1; (weight > 0.001f) && (i < (int)octaves); i++) { + if (weight > 1.0f) weight = 1.0f; signal = (noisefunc(x, y, z) + offset) * pwr; pwr *= pwHL; result += weight * signal; @@ -1778,7 +1785,7 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity } rmd = octaves - floorf(octaves); - if (rmd!=0.f) result += rmd * ((noisefunc(x, y, z) + offset) * pwr); + if (rmd != 0.f) result += rmd * ((noisefunc(x, y, z) + offset) * pwr); return result; @@ -1796,9 +1803,9 @@ float mg_HybridMultiFractal(float x, float y, float z, float H, float lacunarity float mg_RidgedMultiFractal(float x, float y, float z, float H, float lacunarity, float octaves, float offset, float gain, int noisebasis) { float result, signal, weight; - int i; + int i; float pwHL = powf(lacunarity, -H); - float pwr = pwHL; /* starts with i=1 instead of 0 */ + float pwr = pwHL; /* starts with i=1 instead of 0 */ float (*noisefunc)(float, float, float); switch (noisebasis) { @@ -1840,12 +1847,12 @@ 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; weight = signal * gain; - if (weight>1.0f) weight=1.0f; else if (weight<0.0f) weight=0.0f; + if (weight > 1.0f) weight = 1.0f; else if (weight < 0.0f) weight = 0.0f; signal = offset - fabsf(noisefunc(x, y, z)); signal *= signal; signal *= weight; @@ -1934,10 +1941,10 @@ float mg_VLNoise(float x, float y, float z, float distortion, int nbas1, int nba } /* get a random vector and scale the randomization */ - rv[0] = noisefunc1(x+13.5f, y+13.5f, z+13.5f) * distortion; + rv[0] = noisefunc1(x + 13.5f, y + 13.5f, z + 13.5f) * distortion; rv[1] = noisefunc1(x, y, z) * distortion; - rv[2] = noisefunc1(x-13.5f, y-13.5f, z-13.5f) * distortion; - return noisefunc2(x+rv[0], y+rv[1], z+rv[2]); /* distorted-domain noise */ + rv[2] = noisefunc1(x - 13.5f, y - 13.5f, z - 13.5f) * distortion; + return noisefunc2(x + rv[0], y + rv[1], z + rv[2]); /* distorted-domain noise */ } /****************/ diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index b2e6cabec57..4435e9ce09c 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -41,22 +41,22 @@ #include "BLI_rand.h" #if defined(WIN32) && !defined(FREE_WINDOWS) -typedef unsigned __int64 r_uint64; +typedef unsigned __int64 r_uint64; -#define MULTIPLIER 0x5DEECE66Di64 -#define MASK 0x0000FFFFFFFFFFFFi64 +#define MULTIPLIER 0x5DEECE66Di64 +#define MASK 0x0000FFFFFFFFFFFFi64 #else -typedef unsigned long long r_uint64; +typedef unsigned long long r_uint64; -#define MULTIPLIER 0x5DEECE66Dll -#define MASK 0x0000FFFFFFFFFFFFll +#define MULTIPLIER 0x5DEECE66Dll +#define MASK 0x0000FFFFFFFFFFFFll #endif -#define ADDEND 0xB +#define ADDEND 0xB -#define LOWSEED 0x330E +#define LOWSEED 0x330E -extern unsigned char hash[]; // noise.c +extern unsigned char hash[]; // noise.c /***/ @@ -64,7 +64,7 @@ struct RNG { r_uint64 X; }; -RNG *rng_new(unsigned int seed) +RNG *rng_new(unsigned int seed) { RNG *rng = MEM_mallocN(sizeof(*rng), "rng"); @@ -73,39 +73,39 @@ RNG *rng_new(unsigned int seed) return rng; } -void rng_free(RNG* rng) +void rng_free(RNG *rng) { MEM_freeN(rng); } void rng_seed(RNG *rng, unsigned int seed) { - rng->X= (((r_uint64) seed)<<16) | LOWSEED; + rng->X = (((r_uint64) seed) << 16) | LOWSEED; } void rng_srandom(RNG *rng, unsigned int seed) { rng_seed(rng, seed + hash[seed & 255]); - seed= rng_getInt(rng); + seed = rng_getInt(rng); rng_seed(rng, seed + hash[seed & 255]); - seed= rng_getInt(rng); + seed = rng_getInt(rng); rng_seed(rng, seed + hash[seed & 255]); } int rng_getInt(RNG *rng) { - rng->X= (MULTIPLIER*rng->X + ADDEND)&MASK; - return (int) (rng->X>>17); + rng->X = (MULTIPLIER * rng->X + ADDEND) & MASK; + return (int) (rng->X >> 17); } double rng_getDouble(RNG *rng) { - return (double) rng_getInt(rng)/0x80000000; + return (double) rng_getInt(rng) / 0x80000000; } float rng_getFloat(RNG *rng) { - return (float) rng_getInt(rng)/0x80000000; + return (float) rng_getInt(rng) / 0x80000000; } void rng_shuffleArray(RNG *rng, void *data, int elemSize, int numElems) @@ -122,10 +122,10 @@ void rng_shuffleArray(RNG *rng, void *data, int elemSize, int numElems) /* XXX Shouldn't it rather be "while (i--) {" ? * Else we have no guaranty first (0) element has a chance to be shuffled... --mont29 */ while (--i) { - int j = rng_getInt(rng)%numElems; - if (i!=j) { - void *iElem = (unsigned char*)data + i*elemSize; - void *jElem = (unsigned char*)data + j*elemSize; + int j = rng_getInt(rng) % numElems; + if (i != j) { + void *iElem = (unsigned char *)data + i * elemSize; + void *jElem = (unsigned char *)data + j * elemSize; memcpy(temp, iElem, elemSize); memcpy(iElem, jElem, elemSize); memcpy(jElem, temp, elemSize); @@ -139,7 +139,7 @@ void rng_skip(RNG *rng, int n) { int i; - for (i=0; i<n; i++) + for (i = 0; i < n; i++) rng_getInt(rng); } @@ -177,10 +177,10 @@ float BLI_frand(void) void BLI_fillrand(void *addr, int len) { RNG rng; - unsigned char *p= addr; + unsigned char *p = addr; - rng_seed(&rng, (unsigned int) (PIL_check_seconds_timer()*0x7FFFFFFF)); - while (len--) *p++= rng_getInt(&rng)&0xFF; + rng_seed(&rng, (unsigned int) (PIL_check_seconds_timer() * 0x7FFFFFFF)); + while (len--) *p++ = rng_getInt(&rng) & 0xFF; } void BLI_array_randomize(void *data, int elemSize, int numElems, unsigned int seed) @@ -198,12 +198,12 @@ static RNG rng_tab[BLENDER_MAX_THREADS]; void BLI_thread_srandom(int thread, unsigned int seed) { if (thread >= BLENDER_MAX_THREADS) - thread= 0; + thread = 0; rng_seed(&rng_tab[thread], seed + hash[seed & 255]); - seed= rng_getInt(&rng_tab[thread]); + seed = rng_getInt(&rng_tab[thread]); rng_seed(&rng_tab[thread], seed + hash[seed & 255]); - seed= rng_getInt(&rng_tab[thread]); + seed = rng_getInt(&rng_tab[thread]); rng_seed(&rng_tab[thread], seed + hash[seed & 255]); } diff --git a/source/blender/blenlib/intern/smallhash.c b/source/blender/blenlib/intern/smallhash.c index fb03849bfb3..92125c6e988 100644 --- a/source/blender/blenlib/intern/smallhash.c +++ b/source/blender/blenlib/intern/smallhash.c @@ -40,8 +40,8 @@ * * note: these have the SMHASH suffix because we may want to make them public. */ -#define SMHASH_CELL_UNUSED ((void *)0x7FFFFFFF) -#define SMHASH_CELL_FREE ((void *)0x7FFFFFFD) +#define SMHASH_CELL_UNUSED ((void *)0x7FFFFFFF) +#define SMHASH_CELL_FREE ((void *)0x7FFFFFFD) #define SMHASH_NONZERO(n) ((n) + !(n)) #define SMHASH_NEXT(h, hoff) ABS(((h) + ((hoff = SMHASH_NONZERO(hoff * 2) + 1), hoff))) @@ -80,7 +80,7 @@ void BLI_smallhash_release(SmallHash *hash) void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item) { - int h, hoff=1; + int h, hoff = 1; if (hash->size < hash->used * 3) { int newsize = hashsizes[++hash->curhash]; @@ -103,7 +103,7 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item) hash->table[i].val = SMHASH_CELL_FREE; } - for (i = 0; i<hashsizes[hash->curhash - 1]; i++) { + for (i = 0; i < hashsizes[hash->curhash - 1]; i++) { if (ELEM(tmp[i].val, SMHASH_CELL_UNUSED, SMHASH_CELL_FREE)) { continue; } @@ -141,7 +141,7 @@ void BLI_smallhash_insert(SmallHash *hash, uintptr_t key, void *item) void BLI_smallhash_remove(SmallHash *hash, uintptr_t key) { - int h, hoff=1; + int h, hoff = 1; h = ABS((int)key); @@ -162,7 +162,7 @@ void BLI_smallhash_remove(SmallHash *hash, uintptr_t key) void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key) { - int h, hoff=1; + int h, hoff = 1; void *v; h = ABS((int)key); @@ -193,7 +193,7 @@ void *BLI_smallhash_lookup(SmallHash *hash, uintptr_t key) int BLI_smallhash_haskey(SmallHash *hash, uintptr_t key) { int h = ABS((int)key); - int hoff =1; + int hoff = 1; if (hash->table == NULL) { return 0; @@ -251,21 +251,21 @@ void *BLI_smallhash_iternew(SmallHash *hash, SmallHashIter *iter, uintptr_t *key #if 0 void BLI_smallhash_print(SmallHash *hash) { - int i, linecol=79, c=0; + int i, linecol = 79, c = 0; printf("{"); - for (i=0; i<hash->size; i++) { + for (i = 0; i < hash->size; i++) { if (hash->table[i].val == SMHASH_CELL_UNUSED) { printf("--u-"); } else if (hash->table[i].val == SMHASH_CELL_FREE) { printf("--f-"); } - else { + else { printf("%2x", (unsigned int)hash->table[i].key); } - if (i != hash->size-1) + if (i != hash->size - 1) printf(", "); c += 6; diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 047463f1e26..d4f251d4f5e 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -43,13 +43,13 @@ #include <time.h> #include <sys/stat.h> -#if defined (__sun__) || defined (__sun) || defined (__NetBSD__) +#if defined(__sun__) || defined(__sun) || defined(__NetBSD__) #include <sys/statvfs.h> /* Other modern unix os's should probably use this also */ #elif !defined(__FreeBSD__) && !defined(linux) && (defined(__sparc) || defined(__sparc__)) #include <sys/statfs.h> #endif -#if defined (__FreeBSD__) || defined (__OpenBSD__) +#if defined(__FreeBSD__) || defined(__OpenBSD__) #include <sys/param.h> #include <sys/mount.h> #endif @@ -66,7 +66,7 @@ #include <fcntl.h> -#include <string.h> /* strcpy etc.. */ +#include <string.h> /* strcpy etc.. */ #ifdef WIN32 # include <io.h> @@ -98,13 +98,13 @@ static int totnum, actnum; static struct direntry *files; -static struct ListBase dirbase_={NULL, NULL}; +static struct ListBase dirbase_ = {NULL, NULL}; static struct ListBase *dirbase = &dirbase_; /* can return NULL when the size is not big enough */ char *BLI_current_working_dir(char *dir, const int maxncpy) { - const char *pwd= getenv("PWD"); + const char *pwd = getenv("PWD"); if (pwd) { BLI_strncpy(dir, pwd, maxncpy); return dir; @@ -119,13 +119,13 @@ static int bli_compare(struct direntry *entry1, struct direntry *entry2) /* type is equal to stat.st_mode */ if (S_ISDIR(entry1->type)) { - if (S_ISDIR(entry2->type)==0) return (-1); + if (S_ISDIR(entry2->type) == 0) return (-1); } else { if (S_ISDIR(entry2->type)) return (1); } if (S_ISREG(entry1->type)) { - if (S_ISREG(entry2->type)==0) return (-1); + if (S_ISREG(entry2->type) == 0) return (-1); } else { if (S_ISREG(entry2->type)) return (1); @@ -134,10 +134,10 @@ static int bli_compare(struct direntry *entry1, struct direntry *entry2) 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)); } @@ -149,24 +149,24 @@ double BLI_dir_free_space(const char *dir) DWORD sectorspc, bytesps, freec, clusters; char tmp[4]; - tmp[0]='\\'; tmp[1]=0; /* Just a failsafe */ - if (dir[0]=='/' || dir[0]=='\\') { - tmp[0]='\\'; - tmp[1]=0; + tmp[0] = '\\'; tmp[1] = 0; /* Just a failsafe */ + if (dir[0] == '/' || dir[0] == '\\') { + tmp[0] = '\\'; + tmp[1] = 0; } - else if (dir[1]==':') { - tmp[0]=dir[0]; - tmp[1]=':'; - tmp[2]='\\'; - tmp[3]=0; + else if (dir[1] == ':') { + tmp[0] = dir[0]; + tmp[1] = ':'; + tmp[2] = '\\'; + tmp[3] = 0; } GetDiskFreeSpace(tmp, §orspc, &bytesps, &freec, &clusters); - return (double) (freec*bytesps*sectorspc); + return (double) (freec * bytesps * sectorspc); #else -#if defined (__sun__) || defined (__sun) || defined (__NetBSD__) +#if defined(__sun__) || defined(__sun) || defined(__NetBSD__) struct statvfs disk; #else struct statfs disk; @@ -185,11 +185,11 @@ double BLI_dir_free_space(const char *dir) } else strcpy(name, "/"); -#if defined (__FreeBSD__) || defined (linux) || defined (__OpenBSD__) || defined (__APPLE__) || defined(__GNU__) || defined(__GLIBC__) +#if defined(__FreeBSD__) || defined(linux) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__GNU__) || defined(__GLIBC__) if (statfs(name, &disk)) return(-1); #endif -#if defined (__sun__) || defined (__sun) || defined (__NetBSD__) +#if defined(__sun__) || defined(__sun) || defined(__NetBSD__) if (statvfs(name, &disk)) return(-1); #elif !defined(__FreeBSD__) && !defined(linux) && (defined(__sparc) || defined(__sparc__)) /* WARNING - This may not be supported by geeneric unix os's - Campbell */ @@ -209,10 +209,10 @@ static void bli_builddir(const char *dirname, const char *relname) DIR *dir; BLI_strncpy(buf, relname, sizeof(buf)); - rellen=strlen(relname); + rellen = strlen(relname); if (rellen) { - buf[rellen]='/'; + buf[rellen] = '/'; rellen++; } #ifndef WIN32 @@ -231,7 +231,7 @@ static void bli_builddir(const char *dirname, const char *relname) #endif if ((dir = (DIR *)opendir("."))) { - while ((fname = (struct dirent*) readdir(dir)) != NULL) { + while ((fname = (struct dirent *) readdir(dir)) != NULL) { dlink = (struct dirlink *)malloc(sizeof(struct dirlink)); if (dlink) { BLI_strncpy(buf + rellen, fname->d_name, sizeof(buf) - rellen); @@ -244,7 +244,7 @@ static void bli_builddir(const char *dirname, const char *relname) if (newnum) { if (files) { - void *tmp = realloc(files, (totnum+newnum) * sizeof(struct direntry)); + void *tmp = realloc(files, (totnum + newnum) * sizeof(struct direntry)); if (tmp) { files = (struct direntry *)tmp; } @@ -254,8 +254,8 @@ static void bli_builddir(const char *dirname, const char *relname) } } - if (files==NULL) - files=(struct direntry *)malloc(newnum * sizeof(struct direntry)); + if (files == NULL) + files = (struct direntry *)malloc(newnum * sizeof(struct direntry)); if (files) { dlink = (struct dirlink *) dirbase->first; @@ -266,18 +266,20 @@ static void bli_builddir(const char *dirname, const char *relname) // use 64 bit file size, only needed for WIN32 and WIN64. // Excluding other than current MSVC compiler until able to test #ifdef WIN32 - {wchar_t * name_16 = alloc_utf16_from_8(dlink->name, 0); -#if (defined(WIN32) || defined(WIN64)) && (_MSC_VER>=1500) - _wstat64(name_16, &files[actnum].s); + { + wchar_t *name_16 = alloc_utf16_from_8(dlink->name, 0); +#if (defined(WIN32) || defined(WIN64)) && (_MSC_VER >= 1500) + _wstat64(name_16, &files[actnum].s); #elif defined(__MINGW32__) - _stati64(dlink->name, &files[actnum].s); + _stati64(dlink->name, &files[actnum].s); #endif - free(name_16);}; + free(name_16); + } #else stat(dlink->name, &files[actnum].s); #endif - files[actnum].type=files[actnum].s.st_mode; + files[actnum].type = files[actnum].s.st_mode; files[actnum].flags = 0; totnum++; actnum++; @@ -290,7 +292,7 @@ static void bli_builddir(const char *dirname, const char *relname) } BLI_freelist(dirbase); - if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *, const void*))bli_compare); + if (files) qsort(files, actnum, sizeof(struct direntry), (int (*)(const void *, const void *))bli_compare); } else { printf("%s empty directory\n", dirname); @@ -308,7 +310,7 @@ static void bli_adddirstrings(void) char datum[100]; char buf[512]; char size[250]; - static const char * types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"}; + static const char *types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"}; int num, mode; #ifdef WIN32 __int64 st_size; @@ -316,11 +318,11 @@ static void bli_adddirstrings(void) off_t st_size; #endif - struct direntry * file; + struct direntry *file; struct tm *tm; - time_t zero= 0; + time_t zero = 0; - for (num=0, file= files; num<actnum; num++, file++) { + for (num = 0, file = files; num < actnum; num++, file++) { #ifdef WIN32 mode = 0; BLI_strncpy(file->mode1, types[0], sizeof(file->mode1)); @@ -333,13 +335,13 @@ static void bli_adddirstrings(void) BLI_strncpy(file->mode2, types[(mode & 0070) >> 3], sizeof(file->mode2)); BLI_strncpy(file->mode3, types[(mode & 0007)], sizeof(file->mode3)); - if (((mode & S_ISGID) == S_ISGID) && (file->mode2[2]=='-'))file->mode2[2]='l'; + if (((mode & S_ISGID) == S_ISGID) && (file->mode2[2] == '-')) file->mode2[2] = 'l'; if (mode & (S_ISUID | S_ISGID)) { - if (file->mode1[2]=='x') file->mode1[2]='s'; - else file->mode1[2]='S'; + if (file->mode1[2] == 'x') file->mode1[2] = 's'; + else file->mode1[2] = 'S'; - if (file->mode2[2]=='x')file->mode2[2]='s'; + if (file->mode2[2] == 'x') file->mode2[2] = 's'; } if (mode & S_ISVTX) { @@ -354,7 +356,7 @@ static void bli_adddirstrings(void) { struct passwd *pwuser; pwuser = getpwuid(file->s.st_uid); - if ( pwuser ) { + if (pwuser) { BLI_strncpy(file->owner, pwuser->pw_name, sizeof(file->owner)); } else { @@ -363,9 +365,9 @@ static void bli_adddirstrings(void) } #endif - tm= localtime(&file->s.st_mtime); + 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); @@ -374,16 +376,16 @@ static void bli_adddirstrings(void) * will buy us some time until files get bigger than 4GB or until * everyone starts using __USE_FILE_OFFSET64 or equivalent. */ - st_size= file->s.st_size; + st_size = file->s.st_size; - if (st_size > 1024*1024*1024) { - BLI_snprintf(file->size, sizeof(file->size), "%.2f GB", ((double)st_size)/(1024*1024*1024)); + if (st_size > 1024 * 1024 * 1024) { + BLI_snprintf(file->size, sizeof(file->size), "%.2f GB", ((double)st_size) / (1024 * 1024 * 1024)); } - else if (st_size > 1024*1024) { - BLI_snprintf(file->size, sizeof(file->size), "%.1f MB", ((double)st_size)/(1024*1024)); + else if (st_size > 1024 * 1024) { + BLI_snprintf(file->size, sizeof(file->size), "%.1f MB", ((double)st_size) / (1024 * 1024)); } else if (st_size > 1024) { - BLI_snprintf(file->size, sizeof(file->size), "%d KB", (int)(st_size/1024)); + BLI_snprintf(file->size, sizeof(file->size), "%d KB", (int)(st_size / 1024)); } else { BLI_snprintf(file->size, sizeof(file->size), "%d B", (int)st_size); @@ -401,7 +403,7 @@ static void bli_adddirstrings(void) } else if (st_size < 100 * 1000 * 1000) { BLI_snprintf(size, sizeof(size), "%2d %03d %03d", - (int) (st_size / (1000 * 1000)), (int) ((st_size / 1000) % 1000), (int) ( st_size % 1000)); + (int) (st_size / (1000 * 1000)), (int) ((st_size / 1000) % 1000), (int) (st_size % 1000)); } else { /* XXX, whats going on here?. 2x calls - campbell */ @@ -447,13 +449,13 @@ size_t BLI_file_descriptor_size(int file) struct stat buf; if (file <= 0) return (-1); - fstat(file, &buf);//CHANGE + fstat(file, &buf); /* CHANGE */ return (buf.st_size); } size_t BLI_file_size(const char *path) { - int size, file = BLI_open(path, O_BINARY|O_RDONLY, 0); + int size, file = BLI_open(path, O_BINARY | O_RDONLY, 0); if (file == -1) return -1; @@ -475,10 +477,10 @@ int BLI_exists(const char *name) /* in Windows stat doesn't recognize dir ending on a slash * To not break code where the ending slash is expected we * don't mess with the argument name directly here - elubie */ - wchar_t * tmp_16 = alloc_utf16_from_8(name, 0); + wchar_t *tmp_16 = alloc_utf16_from_8(name, 0); int len, res; len = wcslen(tmp_16); - if (len > 3 && ( tmp_16[len-1]==L'\\' || tmp_16[len-1]==L'/') ) tmp_16[len-1] = '\0'; + if (len > 3 && (tmp_16[len - 1] == L'\\' || tmp_16[len - 1] == L'/') ) tmp_16[len - 1] = '\0'; #ifndef __MINGW32__ res = _wstat(tmp_16, &st); #else @@ -499,7 +501,7 @@ int BLI_stat(const char *path, struct stat *buffer) { int r; UTF16_ENCODE(path); - r=_wstat(path_16,buffer); + r = _wstat(path_16, buffer); UTF16_UN_ENCODE(path); return r; } @@ -518,39 +520,39 @@ int BLI_is_dir(const char *file) int BLI_is_file(const char *path) { - int mode= BLI_exists(path); + int mode = BLI_exists(path); return (mode && !S_ISDIR(mode)); } LinkNode *BLI_file_read_as_lines(const char *name) { - FILE *fp= BLI_fopen(name, "r"); - LinkNode *lines= NULL; + FILE *fp = BLI_fopen(name, "r"); + LinkNode *lines = NULL; char *buf; size_t size; if (!fp) return NULL; fseek(fp, 0, SEEK_END); - size= (size_t)ftell(fp); + size = (size_t)ftell(fp); fseek(fp, 0, SEEK_SET); - buf= MEM_mallocN(size, "file_as_lines"); + buf = MEM_mallocN(size, "file_as_lines"); if (buf) { - size_t i, last= 0; + size_t i, last = 0; - /* - * size = because on win32 reading - * all the bytes in the file will return - * less bytes because of crnl changes. - */ - size= fread(buf, 1, size, fp); - for (i=0; i<=size; i++) { - if (i==size || buf[i]=='\n') { - char *line= BLI_strdupn(&buf[last], i-last); + /* + * size = because on win32 reading + * all the bytes in the file will return + * less bytes because of crnl changes. + */ + size = fread(buf, 1, size, fp); + for (i = 0; i <= size; i++) { + if (i == size || buf[i] == '\n') { + char *line = BLI_strdupn(&buf[last], i - last); BLI_linklist_prepend(&lines, line); - last= i+1; + last = i + 1; } } @@ -565,7 +567,7 @@ LinkNode *BLI_file_read_as_lines(const char *name) void BLI_file_free_lines(LinkNode *lines) { - BLI_linklist_free(lines, (void(*)(void*)) MEM_freeN); + BLI_linklist_free(lines, (void (*)(void *))MEM_freeN); } /** is file1 older then file2 */ diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c index 448f1c1b408..4f5ea0b23bd 100644 --- a/source/blender/blenlib/intern/threads.c +++ b/source/blender/blenlib/intern/threads.c @@ -114,7 +114,7 @@ static pthread_mutex_t _opengl_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _nodes_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_mutex_t _movieclip_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_t mainid; -static int thread_levels= 0; /* threads can be invoked inside threads */ +static int thread_levels = 0; /* threads can be invoked inside threads */ /* just a max for security reasons */ #define RE_MAX_THREAD BLENDER_MAX_THREADS @@ -151,16 +151,16 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) int a; if (threadbase != NULL && tot > 0) { - threadbase->first= threadbase->last= NULL; + 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; a<tot; a++) { - ThreadSlot *tslot= MEM_callocN(sizeof(ThreadSlot), "threadslot"); + for (a = 0; a < tot; a++) { + ThreadSlot *tslot = MEM_callocN(sizeof(ThreadSlot), "threadslot"); BLI_addtail(threadbase, tslot); - tslot->do_thread= do_thread; - tslot->avail= 1; + tslot->do_thread = do_thread; + tslot->avail = 1; } } @@ -182,9 +182,9 @@ void BLI_init_threads(ListBase *threadbase, void *(*do_thread)(void *), int tot) int BLI_available_threads(ListBase *threadbase) { ThreadSlot *tslot; - int counter=0; + int counter = 0; - for (tslot= threadbase->first; tslot; tslot= tslot->next) { + for (tslot = threadbase->first; tslot; tslot = tslot->next) { if (tslot->avail) counter++; } @@ -195,9 +195,9 @@ int BLI_available_threads(ListBase *threadbase) int BLI_available_thread_index(ListBase *threadbase) { ThreadSlot *tslot; - int counter=0; + int counter = 0; - for (tslot= threadbase->first; tslot; tslot= tslot->next, counter++) { + for (tslot = threadbase->first; tslot; tslot = tslot->next, counter++) { if (tslot->avail) return counter; } @@ -206,12 +206,12 @@ int BLI_available_thread_index(ListBase *threadbase) static void *tslot_thread_start(void *tslot_p) { - ThreadSlot *tslot= (ThreadSlot*)tslot_p; + ThreadSlot *tslot = (ThreadSlot *)tslot_p; #if defined(__APPLE__) && (PARALLEL == 1) && (__GNUC__ == 4) && (__GNUC_MINOR__ == 2) /* workaround for Apple gcc 4.2.1 omp vs background thread bug, * set gomp thread local storage pointer which was copied beforehand */ - pthread_setspecific (gomp_tls_key, thread_tls_data); + pthread_setspecific(gomp_tls_key, thread_tls_data); #endif return tslot->do_thread(tslot->callerdata); @@ -226,10 +226,10 @@ void BLI_insert_thread(ListBase *threadbase, void *callerdata) { ThreadSlot *tslot; - for (tslot= threadbase->first; tslot; tslot= tslot->next) { + for (tslot = threadbase->first; tslot; tslot = tslot->next) { if (tslot->avail) { - tslot->avail= 0; - tslot->callerdata= callerdata; + tslot->avail = 0; + tslot->callerdata = callerdata; pthread_create(&tslot->pthread, NULL, tslot_thread_start, tslot); return; } @@ -241,11 +241,11 @@ 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; + tslot->callerdata = NULL; + tslot->avail = 1; } } } @@ -253,7 +253,7 @@ void BLI_remove_thread(ListBase *threadbase, void *callerdata) void BLI_remove_thread_index(ListBase *threadbase, int index) { ThreadSlot *tslot; - int counter=0; + int counter = 0; for (tslot = threadbase->first; tslot; tslot = tslot->next, counter++) { if (counter == index && tslot->avail == 0) { @@ -286,8 +286,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); } } @@ -295,7 +295,7 @@ void BLI_end_threads(ListBase *threadbase) } thread_levels--; - if (thread_levels==0) + if (thread_levels == 0) MEM_set_lock_callback(NULL, NULL); } @@ -310,7 +310,7 @@ int BLI_system_thread_count(void) GetSystemInfo(&info); t = (int) info.dwNumberOfProcessors; #else -# ifdef __APPLE__ +# ifdef __APPLE__ int mib[2]; size_t len; @@ -318,14 +318,14 @@ int BLI_system_thread_count(void) mib[1] = HW_NCPU; len = sizeof(t); sysctl(mib, 2, &t, &len, NULL, 0); -# else +# else t = (int)sysconf(_SC_NPROCESSORS_ONLN); -# endif +# endif #endif - if (t>RE_MAX_THREAD) + if (t > RE_MAX_THREAD) return RE_MAX_THREAD; - if (t<1) + if (t < 1) return 1; return t; @@ -335,41 +335,41 @@ int BLI_system_thread_count(void) void BLI_lock_thread(int type) { - if (type==LOCK_IMAGE) + if (type == LOCK_IMAGE) pthread_mutex_lock(&_image_lock); - else if (type==LOCK_PREVIEW) + else if (type == LOCK_PREVIEW) pthread_mutex_lock(&_preview_lock); - else if (type==LOCK_VIEWER) + else if (type == LOCK_VIEWER) pthread_mutex_lock(&_viewer_lock); - else if (type==LOCK_CUSTOM1) + else if (type == LOCK_CUSTOM1) pthread_mutex_lock(&_custom1_lock); - else if (type==LOCK_RCACHE) + else if (type == LOCK_RCACHE) pthread_mutex_lock(&_rcache_lock); - else if (type==LOCK_OPENGL) + else if (type == LOCK_OPENGL) pthread_mutex_lock(&_opengl_lock); - else if (type==LOCK_NODES) + else if (type == LOCK_NODES) pthread_mutex_lock(&_nodes_lock); - else if (type==LOCK_MOVIECLIP) + else if (type == LOCK_MOVIECLIP) pthread_mutex_lock(&_movieclip_lock); } void BLI_unlock_thread(int type) { - if (type==LOCK_IMAGE) + if (type == LOCK_IMAGE) pthread_mutex_unlock(&_image_lock); - else if (type==LOCK_PREVIEW) + else if (type == LOCK_PREVIEW) pthread_mutex_unlock(&_preview_lock); - else if (type==LOCK_VIEWER) + 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); } @@ -425,20 +425,20 @@ void BLI_rw_mutex_end(ThreadRWMutex *mutex) typedef struct ThreadedWorker { ListBase threadbase; void *(*work_fnct)(void *); - char busy[RE_MAX_THREAD]; - int total; - int sleep_time; + char busy[RE_MAX_THREAD]; + int total; + int sleep_time; } ThreadedWorker; typedef struct WorkParam { ThreadedWorker *worker; void *param; - int index; + int index; } WorkParam; static void *exec_work_fnct(void *v_param) { - WorkParam *p = (WorkParam*)v_param; + WorkParam *p = (WorkParam *)v_param; void *value; value = p->worker->work_fnct(p->param); @@ -461,7 +461,7 @@ ThreadedWorker *BLI_create_worker(void *(*do_thread)(void *), int tot, int sleep tot = RE_MAX_THREAD; } else if (tot < 1) { - tot= 1; + tot = 1; } worker->total = tot; @@ -528,8 +528,8 @@ ThreadQueue *BLI_thread_queue_init(void) { ThreadQueue *queue; - queue= MEM_callocN(sizeof(ThreadQueue), "ThreadQueue"); - queue->queue= BLI_gsqueue_new(sizeof(void*)); + queue = MEM_callocN(sizeof(ThreadQueue), "ThreadQueue"); + queue->queue = BLI_gsqueue_new(sizeof(void *)); pthread_mutex_init(&queue->mutex, NULL); pthread_cond_init(&queue->cond, NULL); @@ -560,7 +560,7 @@ void BLI_thread_queue_push(ThreadQueue *queue, void *work) void *BLI_thread_queue_pop(ThreadQueue *queue) { - void *work= NULL; + void *work = NULL; /* wait until there is work */ pthread_mutex_lock(&queue->mutex); @@ -586,7 +586,7 @@ static void wait_timeout(struct timespec *timeout, int ms) struct _timeb now; _ftime(&now); sec = now.time; - usec = now.millitm*1000; /* microsecond precision would be better */ + usec = now.millitm * 1000; /* microsecond precision would be better */ } #else { @@ -601,23 +601,23 @@ static void wait_timeout(struct timespec *timeout, int ms) div_result = ldiv(ms, 1000); timeout->tv_sec = sec + div_result.quot; - x = usec + (div_result.rem*1000); + x = usec + (div_result.rem * 1000); if (x >= 1000000) { timeout->tv_sec++; x -= 1000000; } - timeout->tv_nsec = x*1000; + timeout->tv_nsec = x * 1000; } void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms) { double t; - void *work= NULL; + void *work = NULL; struct timespec timeout; - t= PIL_check_seconds_timer(); + t = PIL_check_seconds_timer(); wait_timeout(&timeout, ms); /* wait until there is work */ @@ -625,7 +625,7 @@ void *BLI_thread_queue_pop_timeout(ThreadQueue *queue, int ms) 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; } @@ -643,7 +643,7 @@ int BLI_thread_queue_size(ThreadQueue *queue) int size; pthread_mutex_lock(&queue->mutex); - size= BLI_gsqueue_size(queue->queue); + size = BLI_gsqueue_size(queue->queue); pthread_mutex_unlock(&queue->mutex); return size; @@ -653,7 +653,7 @@ void BLI_thread_queue_nowait(ThreadQueue *queue) { pthread_mutex_lock(&queue->mutex); - queue->nowait= 1; + queue->nowait = 1; /* signal threads waiting to pop */ pthread_cond_signal(&queue->cond); @@ -671,6 +671,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); } |