diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 47 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_mempool.h | 43 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_ghash.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/BLI_mempool.c | 212 | ||||
-rw-r--r-- | source/blender/blenlib/intern/DLRB_tree.c | 2 | ||||
-rw-r--r-- | source/blender/blenlib/intern/bpath.c | 10 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 183 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector_inline.c | 6 | ||||
-rw-r--r-- | source/blender/blenlib/intern/path_util.c | 6 |
10 files changed, 357 insertions, 158 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 99687ae8bb4..a2a4ffdc830 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -60,7 +60,8 @@ float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2]); float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2]); void closest_to_line_segment_v2(float closest[2], const float p[2], const float l1[2], const float l2[2]); -float dist_to_plane_v3(const float p[2], const float plane_co[3], const float plane_no[2]); +float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3]); +float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]); float dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]); float closest_to_line_v3(float r[3], const float p[3], const float l1[3], const float l2[3]); float closest_to_line_v2(float r[2], const float p[2], const float l1[2], const float l2[2]); @@ -92,14 +93,17 @@ int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[ * */ int isect_line_line_v3(const float v1[3], const float v2[3], - const float v3[3], const float v4[3], float i1[3], float i2[3]); + const float v3[3], const float v4[3], + float i1[3], float i2[3]); int isect_line_line_strict_v3(const float v1[3], const float v2[3], - const float v3[3], const float v4[3], float vi[3], float *lambda); + const float v3[3], const float v4[3], + float vi[3], float *r_lambda); /*if clip is nonzero, will only return true if lambda is >= 0.0 (i.e. intersection point is along positive d)*/ -int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], - float v1[3], float v2[3], float *lambda, int clip); +int isect_ray_plane_v3(const float p1[3], const float d[3], + const float v0[3], const float v1[3], const float v2[3], + float *r_lambda, const int clip); /** * Intersect line/plane, optionally treat line as directional (like a ray) with the no_flip argument. @@ -113,15 +117,30 @@ int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], const float plane_co[3], const float plane_no[3], const short no_flip); +/** + * Intersect two planes, return a point on the intersection and a vector + * that runs on the direction of the intersection. + * Return error code is the same as 'isect_line_line_v3'. + * @param r_isect_co The resulting intersection point. + * @param r_isect_no The resulting vector of the intersection. + * @param plane_a_co The point on the first plane. + * @param plane_a_no The normal of the first plane. + * @param plane_b_co The point on the second plane. + * @param plane_b_no The normal of the second plane. + */ +void isect_plane_plane_v3(float r_isect_co[3], float r_isect_no[3], + const float plane_a_co[3], const float plane_a_no[3], + const float plane_b_co[3], const float plane_b_no[3]); + /* line/ray triangle */ int isect_line_tri_v3(const float p1[3], const float p2[3], - const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2]); + const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2]); int isect_ray_tri_v3(const float p1[3], const float d[3], - const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2]); + const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2]); int isect_ray_tri_threshold_v3(const float p1[3], const float d[3], - const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2], const float threshold); + const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float threshold); int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], - const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2], const float epsilon); + const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float r_uv[2], const float epsilon); /* point in polygon */ int isect_point_quad_v2(const float p[2], const float a[2], const float b[2], const float c[2], const float d[2]); @@ -131,16 +150,16 @@ int isect_point_tri_v2_int(const int x1, const int y1, const int x2, const int y int isect_point_tri_prism_v3(const float p[3], const float v1[3], const float v2[3], const float v3[3]); void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], - const float pt[2], float *uv); + const float pt[2], float r_uv[2]); void isect_point_face_uv_v2(const int isquad, const float v0[2], const float v1[2], const float v2[2], - const float v3[2], const float pt[2], float *uv); + const float v3[2], const float pt[2], float r_uv[2]); /* other */ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const float radius, - const float v0[3], const float v1[3], const float v2[3], float *lambda, float ipoint[3]); + const float v0[3], const float v1[3], const float v2[3], float *r_lambda, float ipoint[3]); int isect_axial_line_tri_v3(const int axis, const float co1[3], const float co2[3], - const float v0[3], const float v1[3], const float v2[3], float *lambda); + const float v0[3], const float v1[3], const float v2[3], float *r_lambda); int isect_aabb_aabb_v3(const float min1[3], const float max1[3], const float min2[3], const float max2[3]); @@ -167,7 +186,7 @@ void barycentric_transform(float pt_tar[3], float const pt_src[3], void barycentric_weights_v2(const float v1[2], const float v2[2], const float v3[2], const float co[2], float w[3]); -void resolve_tri_uv(float uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2]); +void resolve_tri_uv(float r_uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2]); void resolve_quad_uv(float uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]); /***************************** View & Projection *****************************/ diff --git a/source/blender/blenlib/BLI_mempool.h b/source/blender/blenlib/BLI_mempool.h index 2a81966986f..f98919fadd3 100644 --- a/source/blender/blenlib/BLI_mempool.h +++ b/source/blender/blenlib/BLI_mempool.h @@ -34,12 +34,45 @@ * \brief Simple fast memory allocator. */ +#ifdef __cplusplus +extern "C" +{ +#endif + struct BLI_mempool; +struct BLI_mempool_chunk; + +typedef struct BLI_mempool BLI_mempool; + +/*allow_iter allows iteration on this mempool. note: this requires that the + first four bytes of the elements never contain the character string + 'free'. use with care.*/ -struct BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int use_sysmalloc); -void *BLI_mempool_alloc(struct BLI_mempool *pool); -void *BLI_mempool_calloc(struct BLI_mempool *pool); -void BLI_mempool_free(struct BLI_mempool *pool, void *addr); -void BLI_mempool_destroy(struct BLI_mempool *pool); +BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, + short use_sysmalloc, short allow_iter); +void *BLI_mempool_alloc(BLI_mempool *pool); +void *BLI_mempool_calloc(BLI_mempool *pool); +void BLI_mempool_free(BLI_mempool *pool, void *addr); +void BLI_mempool_destroy(BLI_mempool *pool); +int BLI_mempool_count(BLI_mempool *pool); + +/** iteration stuff. note: this may easy to produce bugs with **/ +/*private structure*/ +typedef struct BLI_mempool_iter { + BLI_mempool *pool; + struct BLI_mempool_chunk *curchunk; + int curindex; +} BLI_mempool_iter; + +/*allow iteration on this mempool. note: this requires that the + first four bytes of the elements never contain the character string + 'free'. use with care.*/ +void BLI_mempool_allow_iter(BLI_mempool *pool); +void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter); +void *BLI_mempool_iterstep(BLI_mempool_iter *iter); + +#ifdef __cplusplus +} +#endif #endif diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c index 080dc77fc06..c1894088300 100644 --- a/source/blender/blenlib/intern/BLI_ghash.c +++ b/source/blender/blenlib/intern/BLI_ghash.c @@ -60,7 +60,7 @@ GHash *BLI_ghash_new(GHashHashFP hashfp, GHashCmpFP cmpfp, const char *info) { GHash *gh= MEM_mallocN(sizeof(*gh), info); gh->hashfp= hashfp; gh->cmpfp= cmpfp; - gh->entrypool = BLI_mempool_create(sizeof(Entry), 64, 64, 0); + gh->entrypool = BLI_mempool_create(sizeof(Entry), 64, 64, FALSE, FALSE); gh->cursize= 0; gh->nentries= 0; diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c index b4dc5b73a65..19ae89da8ea 100644 --- a/source/blender/blenlib/intern/BLI_mempool.c +++ b/source/blender/blenlib/intern/BLI_mempool.c @@ -20,7 +20,7 @@ * * The Original Code is: all of this file. * - * Contributor(s): none yet. + * Contributor(s): Geoffery Bantle * * ***** END GPL LICENSE BLOCK ***** */ @@ -29,69 +29,112 @@ * \ingroup bli */ - /* - Simple, fast memory allocator for allocating many elements of the same size. -*/ + * Simple, fast memory allocator for allocating many elements of the same size. + */ + +#include "BLI_utildefines.h" +#include "BLI_listbase.h" + +#include "BLI_mempool.h" /* own include */ + +#include "DNA_listBase.h" #include "MEM_guardedalloc.h" -#include "BLI_blenlib.h" -#include "BLI_mempool.h" -#include <string.h> -typedef struct BLI_freenode{ +#include <string.h> +#include <stdlib.h> + +/* note: copied from BKE_utildefines.h, dont use here because we're in BLI */ +#ifdef __BIG_ENDIAN__ +/* Big Endian */ +# define MAKE_ID(a,b,c,d) ( (int)(a)<<24 | (int)(b)<<16 | (c)<<8 | (d) ) +#else +/* Little Endian */ +# define MAKE_ID(a,b,c,d) ( (int)(d)<<24 | (int)(c)<<16 | (b)<<8 | (a) ) +#endif + +#define FREEWORD MAKE_ID('f', 'r', 'e', 'e') + +typedef struct BLI_freenode { struct BLI_freenode *next; -}BLI_freenode; + int freeword; /* used to identify this as a freed node */ +} BLI_freenode; -typedef struct BLI_mempool_chunk{ +typedef struct BLI_mempool_chunk { struct BLI_mempool_chunk *next, *prev; void *data; -}BLI_mempool_chunk; +} BLI_mempool_chunk; -typedef struct BLI_mempool{ +struct BLI_mempool { struct ListBase chunks; - int esize, csize, pchunk; /*size of elements and chunks in bytes and number of elements per chunk*/ - struct BLI_freenode *free; /*free element list. Interleaved into chunk datas.*/ - int totalloc, totused; /*total number of elements allocated in total, and currently in use*/ - int use_sysmalloc; -}BLI_mempool; - -BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int use_sysmalloc) -{ BLI_mempool *pool = NULL; + int esize, csize, pchunk; /* size of elements and chunks in bytes + * and number of elements per chunk*/ + short use_sysmalloc, allow_iter; + /* keeps aligned to 16 bits */ + + BLI_freenode *free; /* free element list. Interleaved into chunk datas.*/ + int totalloc, totused; /* total number of elements allocated in total, + * and currently in use*/ +}; + +#define MEMPOOL_ELEM_SIZE_MIN (sizeof(void *) * 2) + +BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, + short use_sysmalloc, short allow_iter) +{ + BLI_mempool *pool = NULL; BLI_freenode *lasttail = NULL, *curnode = NULL; int i,j, maxchunks; char *addr; - - if (esize < sizeof(void*)) - esize = sizeof(void*); - + + if (esize < MEMPOOL_ELEM_SIZE_MIN) + esize = MEMPOOL_ELEM_SIZE_MIN; + /*allocate the pool structure*/ pool = use_sysmalloc ? malloc(sizeof(BLI_mempool)) : MEM_mallocN(sizeof(BLI_mempool), "memory pool"); - pool->esize = esize; + pool->esize = allow_iter ? MAX2(esize, sizeof(BLI_freenode)) : esize; pool->use_sysmalloc = use_sysmalloc; - pool->pchunk = pchunk; + pool->pchunk = pchunk; pool->csize = esize * pchunk; pool->chunks.first = pool->chunks.last = NULL; pool->totused= 0; + pool->allow_iter= allow_iter; maxchunks = tote / pchunk + 1; - + if (maxchunks==0) maxchunks = 1; + /*allocate the actual chunks*/ - for(i=0; i < maxchunks; i++){ + for (i=0; i < maxchunks; i++) { BLI_mempool_chunk *mpchunk = use_sysmalloc ? malloc(sizeof(BLI_mempool_chunk)) : MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk"); mpchunk->next = mpchunk->prev = NULL; mpchunk->data = use_sysmalloc ? malloc(pool->csize) : MEM_mallocN(pool->csize, "BLI Mempool Chunk Data"); BLI_addtail(&(pool->chunks), mpchunk); - if(i==0) pool->free = mpchunk->data; /*start of the list*/ + if (i==0) { + pool->free = mpchunk->data; /*start of the list*/ + if (pool->allow_iter) + pool->free->freeword = FREEWORD; + } + /*loop through the allocated data, building the pointer structures*/ - for(addr = mpchunk->data, j=0; j < pool->pchunk; j++){ + for (addr = mpchunk->data, j=0; j < pool->pchunk; j++) { curnode = ((BLI_freenode*)addr); addr += pool->esize; curnode->next = (BLI_freenode*)addr; + if (pool->allow_iter) { + if (j != pool->pchunk-1) + curnode->next->freeword = FREEWORD; + curnode->freeword = FREEWORD; + } } /*final pointer in the previously allocated chunk is wrong.*/ - if(lasttail) lasttail->next = mpchunk->data; + if (lasttail) { + lasttail->next = mpchunk->data; + if (pool->allow_iter) + lasttail->freeword = FREEWORD; + } + /*set the end of this chunks memoryy to the new tail for next iteration*/ lasttail = curnode; @@ -101,15 +144,18 @@ BLI_mempool *BLI_mempool_create(int esize, int tote, int pchunk, int use_sysmall curnode->next = NULL; return pool; } -void *BLI_mempool_alloc(BLI_mempool *pool){ + +void *BLI_mempool_alloc(BLI_mempool *pool) +{ void *retval=NULL; - BLI_freenode *curnode=NULL; - char *addr=NULL; - int j; pool->totused++; - if(!(pool->free)){ + if (!(pool->free)) { + BLI_freenode *curnode=NULL; + char *addr; + int j; + /*need to allocate a new chunk*/ BLI_mempool_chunk *mpchunk = pool->use_sysmalloc ? malloc(sizeof(BLI_mempool_chunk)) : MEM_mallocN(sizeof(BLI_mempool_chunk), "BLI_Mempool Chunk"); mpchunk->next = mpchunk->prev = NULL; @@ -117,10 +163,18 @@ void *BLI_mempool_alloc(BLI_mempool *pool){ BLI_addtail(&(pool->chunks), mpchunk); pool->free = mpchunk->data; /*start of the list*/ + if (pool->allow_iter) + pool->free->freeword = FREEWORD; for(addr = mpchunk->data, j=0; j < pool->pchunk; j++){ curnode = ((BLI_freenode*)addr); addr += pool->esize; curnode->next = (BLI_freenode*)addr; + + if (pool->allow_iter) { + curnode->freeword = FREEWORD; + if (j != pool->pchunk-1) + curnode->next->freeword = FREEWORD; + } } curnode->next = NULL; /*terminate the list*/ @@ -128,25 +182,28 @@ void *BLI_mempool_alloc(BLI_mempool *pool){ } retval = pool->free; + if (pool->allow_iter) + pool->free->freeword = 0x7FFFFFFF; + pool->free = pool->free->next; //memset(retval, 0, pool->esize); return retval; } -void *BLI_mempool_calloc(BLI_mempool *pool){ - void *retval=NULL; - retval = BLI_mempool_alloc(pool); +void *BLI_mempool_calloc(BLI_mempool *pool) +{ + void *retval= BLI_mempool_alloc(pool); memset(retval, 0, pool->esize); return retval; } - -void BLI_mempool_free(BLI_mempool *pool, void *addr){ //doesnt protect against double frees, dont be stupid! +/* doesnt protect against double frees, dont be stupid! */ +void BLI_mempool_free(BLI_mempool *pool, void *addr) +{ BLI_freenode *newhead = addr; - BLI_freenode *curnode=NULL; - char *tmpaddr=NULL; - int i; + if (pool->allow_iter) + newhead->freeword = FREEWORD; newhead->next = pool->free; pool->free = newhead; @@ -154,14 +211,18 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr){ //doesnt protect against d /*nothing is in use; free all the chunks except the first*/ if (pool->totused == 0) { - BLI_mempool_chunk *mpchunk=NULL, *first; + BLI_freenode *curnode=NULL; + char *tmpaddr=NULL; + int i; + + BLI_mempool_chunk *mpchunk=NULL; + BLI_mempool_chunk *first= pool->chunks.first; - first = pool->chunks.first; BLI_remlink(&pool->chunks, first); - for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) { - if(pool->use_sysmalloc) free(mpchunk->data); - else MEM_freeN(mpchunk->data); + for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) { + if (pool->use_sysmalloc) free(mpchunk->data); + else MEM_freeN(mpchunk->data); } pool->use_sysmalloc ? BLI_freelist(&(pool->chunks)) : BLI_freelistN(&(pool->chunks)); @@ -170,7 +231,7 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr){ //doesnt protect against d pool->totalloc = pool->pchunk; pool->free = first->data; /*start of the list*/ - for(tmpaddr = first->data, i=0; i < pool->pchunk; i++){ + for (tmpaddr = first->data, i=0; i < pool->pchunk; i++) { curnode = ((BLI_freenode*)tmpaddr); tmpaddr += pool->esize; curnode->next = (BLI_freenode*)tmpaddr; @@ -179,18 +240,63 @@ void BLI_mempool_free(BLI_mempool *pool, void *addr){ //doesnt protect against d } } +void BLI_mempool_iternew(BLI_mempool *pool, BLI_mempool_iter *iter) +{ + if (!pool->allow_iter) { + fprintf(stderr, "%s: Error! you can't iterate over this mempool!\n", __func__); + iter->curchunk = NULL; + iter->curindex = 0; + + return; + } + + iter->pool = pool; + iter->curchunk = pool->chunks.first; + iter->curindex = 0; +} + +static void *bli_mempool_iternext(BLI_mempool_iter *iter) +{ + void *ret = NULL; + + if (!iter->curchunk || !iter->pool->totused) return NULL; + + ret = ((char*)iter->curchunk->data) + iter->pool->esize*iter->curindex; + + iter->curindex++; + + if (iter->curindex >= iter->pool->pchunk) { + iter->curchunk = iter->curchunk->next; + iter->curindex = 0; + } + + return ret; +} + +void *BLI_mempool_iterstep(BLI_mempool_iter *iter) +{ + BLI_freenode *ret; + + do { + ret = bli_mempool_iternext(iter); + } while (ret && ret->freeword == FREEWORD); + + return ret; +} + void BLI_mempool_destroy(BLI_mempool *pool) { BLI_mempool_chunk *mpchunk=NULL; - if(pool->use_sysmalloc) { - for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) { + + if (pool->use_sysmalloc) { + for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) { free(mpchunk->data); } BLI_freelist(&(pool->chunks)); free(pool); } else { - for(mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) { + for (mpchunk = pool->chunks.first; mpchunk; mpchunk = mpchunk->next) { MEM_freeN(mpchunk->data); } BLI_freelistN(&(pool->chunks)); diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c index 72743e38d4c..4507d70e339 100644 --- a/source/blender/blenlib/intern/DLRB_tree.c +++ b/source/blender/blenlib/intern/DLRB_tree.c @@ -209,7 +209,7 @@ DLRBT_Node *BLI_dlrbTree_search_exact (DLRBT_Tree *tree, DLRBT_Comparator_FP cmp } } - /* return the nearest matching node */ + /* return the exactly matching node */ return (found == 1) ? (node) : (NULL); } diff --git a/source/blender/blenlib/intern/bpath.c b/source/blender/blenlib/intern/bpath.c index 2afa17cb4e1..80a5421aff3 100644 --- a/source/blender/blenlib/intern/bpath.c +++ b/source/blender/blenlib/intern/bpath.c @@ -132,7 +132,7 @@ static int makeFilesRelative_visit_cb(void *userdata, char *path_dst, const char void makeFilesRelative(Main *bmain, const char *basedir, ReportList *reports) { - BPathRemap_Data data= {0}; + BPathRemap_Data data= {NULL}; if(basedir[0] == '\0') { printf("%s: basedir='', this is a bug\n", __func__); @@ -175,7 +175,7 @@ static int makeFilesAbsolute_visit_cb(void *userdata, char *path_dst, const char /* similar to makeFilesRelative - keep in sync! */ void makeFilesAbsolute(Main *bmain, const char *basedir, ReportList *reports) { - BPathRemap_Data data= {0}; + BPathRemap_Data data= {NULL}; if(basedir[0] == '\0') { printf("%s: basedir='', this is a bug\n", __func__); @@ -281,7 +281,7 @@ static int findMissingFiles_visit_cb(void *userdata, char *path_dst, const char void findMissingFiles(Main *bmain, const char *searchpath, ReportList *reports) { - struct BPathFind_Data data= {0}; + struct BPathFind_Data data= {NULL}; data.reports= reports; BLI_split_dir_part(searchpath, data.searchdir, sizeof(data.searchdir)); @@ -432,6 +432,10 @@ void bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int fla 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) { diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index a135cb43882..9d42ee347d4 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -134,9 +134,9 @@ float area_poly_v3(int nr, float verts[][3], const float normal[3]) int a, px=0, py=1; /* first: find dominant axis: 0==X, 1==Y, 2==Z */ - x= (float)fabs(normal[0]); - y= (float)fabs(normal[1]); - z= (float)fabs(normal[2]); + x= fabsf(normal[0]); + y= fabsf(normal[1]); + z= fabsf(normal[2]); max = MAX3(x, y, z); if(max==y) py=2; else if(max==x) { @@ -238,7 +238,16 @@ void closest_to_line_segment_v3(float closest[3], const float v1[3], const float } /* signed distance from the point to the plane in 3D */ -float dist_to_plane_v3(const float p[2], const float plane_co[3], const float plane_no[2]) +float dist_to_plane_normalized_v3(const float p[3], const float plane_co[3], const float plane_no_unit[3]) +{ + float plane_co_other[3]; + + add_v3_v3v3(plane_co_other, plane_co, plane_no_unit); + + return line_point_factor_v3(p, plane_co, plane_co_other); +} + +float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]) { float plane_no_unit[3]; float plane_co_other[3]; @@ -246,7 +255,7 @@ float dist_to_plane_v3(const float p[2], const float plane_co[3], const float pl normalize_v3_v3(plane_no_unit, plane_no); add_v3_v3v3(plane_co_other, plane_co, plane_no_unit); - return -line_point_factor_v3(p, plane_co, plane_co_other); + return line_point_factor_v3(p, plane_co, plane_co_other); } /* distance v1 to line-piece v2-v3 in 3D */ @@ -601,7 +610,9 @@ int isect_point_quad_v2(const float pt[2], const float v1[2], const float v2[2], test if the line starting at p1 ending at p2 intersects the triangle v0..v2 return non zero if it does */ -int isect_line_tri_v3(const float p1[3], const float p2[3], const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2]) +int isect_line_tri_v3(const float p1[3], const float p2[3], + const float v0[3], const float v1[3], const float v2[3], + float *r_lambda, float r_uv[2]) { float p[3], s[3], d[3], e1[3], e2[3], q[3]; @@ -626,12 +637,12 @@ int isect_line_tri_v3(const float p1[3], const float p2[3], const float v0[3], c v = f * dot_v3v3(d, q); if ((v < 0.0f)||((u + v) > 1.0f)) return 0; - *lambda = f * dot_v3v3(e2, q); - if ((*lambda < 0.0f)||(*lambda > 1.0f)) return 0; + *r_lambda = f * dot_v3v3(e2, q); + if ((*r_lambda < 0.0f)||(*r_lambda > 1.0f)) return 0; - if(uv) { - uv[0]= u; - uv[1]= v; + if(r_uv) { + r_uv[0]= u; + r_uv[1]= v; } return 1; @@ -640,7 +651,9 @@ int isect_line_tri_v3(const float p1[3], const float p2[3], const float v0[3], c test if the ray starting at p1 going in d direction intersects the triangle v0..v2 return non zero if it does */ -int isect_ray_tri_v3(const float p1[3], const float d[3], const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2]) +int isect_ray_tri_v3(const float p1[3], const float d[3], + const float v0[3], const float v1[3], const float v2[3], + float *r_lambda, float r_uv[2]) { float p[3], s[3], e1[3], e2[3], q[3]; float a, f, u, v; @@ -665,18 +678,20 @@ int isect_ray_tri_v3(const float p1[3], const float d[3], const float v0[3], con v = f * dot_v3v3(d, q); if ((v < 0.0f)||((u + v) > 1.0f)) return 0; - *lambda = f * dot_v3v3(e2, q); - if ((*lambda < 0.0f)) return 0; + *r_lambda = f * dot_v3v3(e2, q); + if ((*r_lambda < 0.0f)) return 0; - if(uv) { - uv[0]= u; - uv[1]= v; + if(r_uv) { + r_uv[0]= u; + r_uv[1]= v; } return 1; } -int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], float v1[3], float v2[3], float *lambda, int clip) +int isect_ray_plane_v3(const float p1[3], const float d[3], + const float v0[3], const float v1[3], const float v2[3], + float *r_lambda, const int clip) { float p[3], s[3], e1[3], e2[3], q[3]; float a, f; @@ -700,13 +715,15 @@ int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], float v1[3], float /* v = f * dot_v3v3(d, q); */ /*UNUSED*/ - *lambda = f * dot_v3v3(e2, q); - if (clip && (*lambda < 0.0f)) return 0; + *r_lambda = f * dot_v3v3(e2, q); + if (clip && (*r_lambda < 0.0f)) return 0; return 1; } -int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2], const float epsilon) +int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], + const float v0[3], const float v1[3], const float v2[3], + float *r_lambda, float uv[2], const float epsilon) { float p[3], s[3], e1[3], e2[3], q[3]; float a, f, u, v; @@ -729,8 +746,8 @@ int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], const float v0 v = f * dot_v3v3(d, q); if ((v < -epsilon)||((u + v) > 1.0f+epsilon)) return 0; - *lambda = f * dot_v3v3(e2, q); - if ((*lambda < 0.0f)) return 0; + *r_lambda = f * dot_v3v3(e2, q); + if ((*r_lambda < 0.0f)) return 0; if(uv) { uv[0]= u; @@ -740,7 +757,9 @@ int isect_ray_tri_epsilon_v3(const float p1[3], const float d[3], const float v0 return 1; } -int isect_ray_tri_threshold_v3(const float p1[3], const float d[3], const float v0[3], const float v1[3], const float v2[3], float *lambda, float *uv, const float threshold) +int isect_ray_tri_threshold_v3(const float p1[3], const float d[3], + const float v0[3], const float v1[3], const float v2[3], + float *r_lambda, float r_uv[2], const float threshold) { float p[3], s[3], e1[3], e2[3], q[3]; float a, f, u, v; @@ -757,8 +776,8 @@ int isect_ray_tri_threshold_v3(const float p1[3], const float d[3], const float sub_v3_v3v3(s, p1, v0); cross_v3_v3v3(q, s, e1); - *lambda = f * dot_v3v3(e2, q); - if ((*lambda < 0.0f)) return 0; + *r_lambda = f * dot_v3v3(e2, q); + if ((*r_lambda < 0.0f)) return 0; u = f * dot_v3v3(s, p); v = f * dot_v3v3(d, q); @@ -782,9 +801,9 @@ int isect_ray_tri_threshold_v3(const float p1[3], const float d[3], const float return 0; } - if(uv) { - uv[0]= u; - uv[1]= v; + if(r_uv) { + r_uv[0]= u; + r_uv[1]= v; } return 1; @@ -833,6 +852,19 @@ int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], cons } } +/* note: return normal isnt unit length */ +void isect_plane_plane_v3(float r_isect_co[3], float r_isect_no[3], + const float plane_a_co[3], const float plane_a_no[3], + const float plane_b_co[3], const float plane_b_no[3]) +{ + float plane_a_co_other[3]; + cross_v3_v3v3(r_isect_no, plane_a_no, plane_b_no); /* direction is simply the cross product */ + cross_v3_v3v3(plane_a_co_other, plane_a_no, r_isect_no); + add_v3_v3(plane_a_co_other, plane_a_co); + isect_line_plane_v3(r_isect_co, plane_a_co, plane_a_co_other, plane_b_co, plane_b_no, FALSE); +} + + /* Adapted from the paper by Kasper Fauerby */ /* "Improved Collision detection and Response" */ static int getLowestRoot(const float a, const float b, const float c, const float maxR, float *root) @@ -872,7 +904,10 @@ static int getLowestRoot(const float a, const float b, const float c, const floa return 0; } -int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const float radius, const float v0[3], const float v1[3], const float v2[3], float *lambda, float ipoint[3]) +int isect_sweeping_sphere_tri_v3( + const float p1[3], const float p2[3], const float radius, + const float v0[3], const float v1[3], const float v2[3], + float *r_lambda, float ipoint[3]) { float e1[3], e2[3], e3[3], point[3], vel[3], /*dist[3],*/ nor[3], temp[3], bv[3]; float a, b, c, d, e, x, y, z, radius2=radius*radius; @@ -939,14 +974,14 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo if(z <= 0.0f && (x >= 0.0f && y >= 0.0f)) { //(((unsigned int)z)& ~(((unsigned int)x)|((unsigned int)y))) & 0x80000000){ - *lambda=t0; + *r_lambda=t0; copy_v3_v3(ipoint,point); return 1; } } - *lambda=1.0f; + *r_lambda=1.0f; /*---test points---*/ a=dot_v3v3(vel,vel); @@ -956,7 +991,7 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo b=2.0f*dot_v3v3(vel,temp); c=dot_v3v3(temp,temp)-radius2; - if(getLowestRoot(a, b, c, *lambda, lambda)) + if(getLowestRoot(a, b, c, *r_lambda, r_lambda)) { copy_v3_v3(ipoint,v0); found_by_sweep=1; @@ -967,7 +1002,7 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo b=2.0f*dot_v3v3(vel,temp); c=dot_v3v3(temp,temp)-radius2; - if(getLowestRoot(a, b, c, *lambda, lambda)) + if(getLowestRoot(a, b, c, *r_lambda, r_lambda)) { copy_v3_v3(ipoint,v1); found_by_sweep=1; @@ -978,7 +1013,7 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo b=2.0f*dot_v3v3(vel,temp); c=dot_v3v3(temp,temp)-radius2; - if(getLowestRoot(a, b, c, *lambda, lambda)) + if(getLowestRoot(a, b, c, *r_lambda, r_lambda)) { copy_v3_v3(ipoint,v2); found_by_sweep=1; @@ -999,13 +1034,13 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo b=2.0f*(elen2*dot_v3v3(vel,bv)-edotv*edotbv); c=elen2*(radius2-dot_v3v3(bv,bv))+edotbv*edotbv; - if(getLowestRoot(a, b, c, *lambda, &newLambda)) + if(getLowestRoot(a, b, c, *r_lambda, &newLambda)) { e=(edotv*newLambda-edotbv)/elen2; if(e >= 0.0f && e <= 1.0f) { - *lambda = newLambda; + *r_lambda = newLambda; copy_v3_v3(ipoint,e1); mul_v3_fl(ipoint,e); add_v3_v3(ipoint, v0); @@ -1023,13 +1058,13 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo b=2.0f*(elen2*dot_v3v3(vel,bv)-edotv*edotbv); c=elen2*(radius2-dot_v3v3(bv,bv))+edotbv*edotbv; - if(getLowestRoot(a, b, c, *lambda, &newLambda)) + if(getLowestRoot(a, b, c, *r_lambda, &newLambda)) { e=(edotv*newLambda-edotbv)/elen2; if(e >= 0.0f && e <= 1.0f) { - *lambda = newLambda; + *r_lambda = newLambda; copy_v3_v3(ipoint,e2); mul_v3_fl(ipoint,e); add_v3_v3(ipoint, v0); @@ -1052,13 +1087,13 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo b=2.0f*(elen2*dot_v3v3(vel,bv)-edotv*edotbv); c=elen2*(radius2-dot_v3v3(bv,bv))+edotbv*edotbv; - if(getLowestRoot(a, b, c, *lambda, &newLambda)) + if(getLowestRoot(a, b, c, *r_lambda, &newLambda)) { e=(edotv*newLambda-edotbv)/elen2; if(e >= 0.0f && e <= 1.0f) { - *lambda = newLambda; + *r_lambda = newLambda; copy_v3_v3(ipoint,e3); mul_v3_fl(ipoint,e); add_v3_v3(ipoint, v1); @@ -1069,7 +1104,8 @@ int isect_sweeping_sphere_tri_v3(const float p1[3], const float p2[3], const flo return found_by_sweep; } -int isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3], const float v0[3], const float v1[3], const float v2[3], float *lambda) +int isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3], + const float v0[3], const float v1[3], const float v2[3], float *r_lambda) { float p[3], e1[3], e2[3]; float u, v, f; @@ -1106,9 +1142,9 @@ int isect_axial_line_tri_v3(const int axis, const float p1[3], const float p2[3] if ((u < 0.0f) || ((u + v) > 1.0f)) return 0; - *lambda = (p[a0]+u*e1[a0]+v*e2[a0])/(p2[a0]-p1[a0]); + *r_lambda = (p[a0]+u*e1[a0]+v*e2[a0])/(p2[a0]-p1[a0]); - if ((*lambda < 0.0f) || (*lambda > 1.0f)) return 0; + if ((*r_lambda < 0.0f) || (*r_lambda > 1.0f)) return 0; return 1; } @@ -1182,7 +1218,7 @@ int isect_line_line_v3(const float v1[3], const float v2[3], const float v3[3], /* Intersection point strictly between the two lines * 0 when no intersection is found * */ -int isect_line_line_strict_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float vi[3], float *lambda) +int isect_line_line_strict_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3], float vi[3], float *r_lambda) { float a[3], b[3], c[3], ab[3], cb[3], ca[3], dir1[3], dir2[3]; float d; @@ -1216,12 +1252,9 @@ int isect_line_line_strict_v3(const float v1[3], const float v2[3], const float { mul_v3_fl(a, f1); add_v3_v3v3(vi, v1, a); - - if (lambda != NULL) - { - *lambda = f1; - } - + + if (r_lambda) *r_lambda = f1; + return 1; /* intersection found */ } else @@ -1285,7 +1318,7 @@ float line_point_factor_v2(const float p[2], const float l1[2], const float l2[2 } /* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */ -void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float *uv) +void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float r_uv[2]) { float x0,y0, x1,y1, wtot, v2d[2], w1, w2; @@ -1310,7 +1343,7 @@ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2 wtot = w1+w2; /*w1 = w1/wtot;*/ /*w2 = w2/wtot;*/ - uv[0] = w1/wtot; + r_uv[0] = w1/wtot; } else { /* lines are parallel, lambda_cp_line_ex is 3d grrr */ /*printf("\tparallel1\n");*/ @@ -1332,7 +1365,7 @@ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2 v2d[1] = pt[1]-pt_on_line[1]; w2 = len_v2(v2d); wtot = w1+w2; - uv[0] = w1/wtot; + r_uv[0] = w1/wtot; } /* Same as above to calc the uv[1] value, alternate calculation */ @@ -1350,7 +1383,7 @@ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2 v2d[1] = y1-v1[1]; w2 = len_v2(v2d); wtot = w1+w2; - uv[1] = w1/wtot; + r_uv[1] = w1/wtot; } else { /* lines are parallel, lambda_cp_line_ex is 3d grrr */ /*printf("\tparallel2\n");*/ @@ -1373,23 +1406,23 @@ void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2 v2d[1] = pt[1]-pt_on_line[1]; w2 = len_v2(v2d); wtot = w1+w2; - uv[1] = w1/wtot; + r_uv[1] = w1/wtot; } /* may need to flip UV's here */ } /* same as above but does tri's and quads, tri's are a bit of a hack */ -void isect_point_face_uv_v2(const int isquad, const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float *uv) +void isect_point_face_uv_v2(const int isquad, const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float r_uv[2]) { if (isquad) { - isect_point_quad_uv_v2(v0, v1, v2, v3, pt, uv); + isect_point_quad_uv_v2(v0, v1, v2, v3, pt, r_uv); } else { /* not for quads, use for our abuse of LineIntersectsTriangleUV */ float p1_3d[3], p2_3d[3], v0_3d[3], v1_3d[3], v2_3d[3], lambda; - p1_3d[0] = p2_3d[0] = uv[0]; - p1_3d[1] = p2_3d[1] = uv[1]; + p1_3d[0] = p2_3d[0] = r_uv[0]; + p1_3d[1] = p2_3d[1] = r_uv[1]; p1_3d[2] = 1.0f; p2_3d[2] = -1.0f; v0_3d[2] = v1_3d[2] = v2_3d[2] = 0.0; @@ -1406,7 +1439,7 @@ void isect_point_face_uv_v2(const int isquad, const float v0[2], const float v1[ copy_v2_v2(v2_3d, v2); /* Doing this in 3D is not nice */ - isect_line_tri_v3(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, uv); + isect_line_tri_v3(p1_3d, p2_3d, v0_3d, v1_3d, v2_3d, &lambda, r_uv); } } @@ -1668,9 +1701,9 @@ static int barycentric_weights(const float v1[3], const float v2[3], const float /* find best projection of face XY, XZ or YZ: barycentric weights of the 2d projected coords are the same and faster to compute */ - xn= (float)fabs(n[0]); - yn= (float)fabs(n[1]); - zn= (float)fabs(n[2]); + xn= fabsf(n[0]); + yn= fabsf(n[1]); + zn= fabsf(n[2]); if(zn>=xn && zn>=yn) {i= 0; j= 1;} else if(yn>=xn && yn>=zn) {i= 0; j= 2;} else {i= 1; j= 2;} @@ -1972,7 +2005,7 @@ void interp_cubic_v3(float x[3], float v[3], const float x1[3], const float v1[3 #define IS_ZERO(x) ((x>(-DBL_EPSILON) && x<DBL_EPSILON) ? 1 : 0) /* Barycentric reverse */ -void resolve_tri_uv(float uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2]) +void resolve_tri_uv(float r_uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2]) { /* find UV such that t= u*t0 + v*t1 + (1-u-v)*t2 @@ -1984,13 +2017,13 @@ void resolve_tri_uv(float uv[2], const float st[2], const float st0[2], const fl if(IS_ZERO(det)==0) { /* det should never be zero since the determinant is the signed ST area of the triangle. */ const double x[]= {st[0]-st2[0], st[1]-st2[1]}; - uv[0]= (float)((d*x[0] - b*x[1])/det); - uv[1]= (float)(((-c)*x[0] + a*x[1])/det); - } else zero_v2(uv); + r_uv[0]= (float)((d*x[0] - b*x[1])/det); + r_uv[1]= (float)(((-c)*x[0] + a*x[1])/det); + } else zero_v2(r_uv); } /* bilinear reverse */ -void resolve_quad_uv(float uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]) +void resolve_quad_uv(float r_uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]) { const double signed_area= (st0[0]*st1[1] - st0[1]*st1[0]) + (st1[0]*st2[1] - st1[1]*st2[0]) + (st2[0]*st3[1] - st2[1]*st3[0]) + (st3[0]*st0[1] - st3[1]*st0[0]); @@ -2008,25 +2041,25 @@ void resolve_quad_uv(float uv[2], const float st[2], const float st0[2], const f const double denom= a - 2*b + fC; // clear outputs - zero_v2(uv); + zero_v2(r_uv); if(IS_ZERO(denom)!=0) { const double fDen= a-fC; if(IS_ZERO(fDen)==0) - uv[0]= (float)(a / fDen); + r_uv[0]= (float)(a / fDen); } else { const double desc_sq= b*b - a*fC; const double desc= sqrt(desc_sq<0.0?0.0:desc_sq); const double s= signed_area>0 ? (-1.0) : 1.0; - uv[0]= (float)(( (a-b) + s * desc ) / denom); + r_uv[0]= (float)(( (a-b) + s * desc ) / denom); } /* find UV such that fST = (1-u)(1-v)*ST0 + u*(1-v)*ST1 + u*v*ST2 + (1-u)*v*ST3 */ { - const double denom_s= (1-uv[0])*(st0[0]-st3[0]) + uv[0]*(st1[0]-st2[0]); - const double denom_t= (1-uv[0])*(st0[1]-st3[1]) + uv[0]*(st1[1]-st2[1]); + const double denom_s= (1-r_uv[0])*(st0[0]-st3[0]) + r_uv[0]*(st1[0]-st2[0]); + const double denom_t= (1-r_uv[0])*(st0[1]-st3[1]) + r_uv[0]*(st1[1]-st2[1]); int i= 0; double denom= denom_s; if(fabs(denom_s)<fabs(denom_t)) { @@ -2035,7 +2068,7 @@ void resolve_quad_uv(float uv[2], const float st[2], const float st0[2], const f } if(IS_ZERO(denom)==0) - uv[1]= (float) (( (1.0f-uv[0])*(st0[i]-st[i]) + uv[0]*(st1[i]-st[i]) ) / denom); + r_uv[1]= (float) (( (1.0f-r_uv[0])*(st0[i]-st[i]) + r_uv[0]*(st1[i]-st[i]) ) / denom); } } diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 1637cd16161..e4664798f5d 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -1322,8 +1322,8 @@ void mat3_to_compatible_eulO(float eul[3], float oldrot[3], short order,float ma compatible_eul(eul1, oldrot); compatible_eul(eul2, oldrot); - d1= (float)fabs(eul1[0]-oldrot[0]) + (float)fabs(eul1[1]-oldrot[1]) + (float)fabs(eul1[2]-oldrot[2]); - d2= (float)fabs(eul2[0]-oldrot[0]) + (float)fabs(eul2[1]-oldrot[1]) + (float)fabs(eul2[2]-oldrot[2]); + d1= fabsf(eul1[0]-oldrot[0]) + fabsf(eul1[1]-oldrot[1]) + fabsf(eul1[2]-oldrot[2]); + d2= fabsf(eul2[0]-oldrot[0]) + fabsf(eul2[1]-oldrot[1]) + fabsf(eul2[2]-oldrot[2]); /* return best, which is just the one with lowest difference */ if (d1 > d2) diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 1c7d131c750..4570bd5e99e 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -181,19 +181,19 @@ MINLINE void add_v4_fl(float r[4], float f) r[3] += f; } -MINLINE void add_v2_v2(float *r, const float *a) +MINLINE void add_v2_v2(float r[2], const float a[2]) { r[0] += a[0]; r[1] += a[1]; } -MINLINE void add_v2_v2v2(float *r, const float *a, const float *b) +MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]) { r[0]= a[0] + b[0]; r[1]= a[1] + b[1]; } -MINLINE void add_v3_v3(float *r, const float *a) +MINLINE void add_v3_v3(float r[3], const float a[3]) { r[0] += a[0]; r[1] += a[1]; diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c index 7aa84523e9d..08d9dfaeb9e 100644 --- a/source/blender/blenlib/intern/path_util.c +++ b/source/blender/blenlib/intern/path_util.c @@ -1414,6 +1414,10 @@ int BLI_replace_extension(char *path, size_t maxlen, const char *ext) } } + if (path[a] != '.') { + a= path_len; + } + if(a + ext_len >= maxlen) return 0; @@ -1841,7 +1845,7 @@ const char *BLI_program_dir(void) * @param fullname The full path to the temp directory * @param userdir Directory specified in user preferences */ -void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir) +static void BLI_where_is_temp(char *fullname, const size_t maxlen, char *userdir) { fullname[0] = '\0'; |