diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_listbase.h | 2 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_base.h | 24 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_math_rotation.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_pbvh.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_rect.h | 26 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_string.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_utildefines.h | 24 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_vfontdata.h | 12 | ||||
-rw-r--r-- | source/blender/blenlib/intern/freetypefont.c | 13 | ||||
-rw-r--r-- | source/blender/blenlib/intern/listbase.c | 38 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_rotation.c | 240 | ||||
-rw-r--r-- | source/blender/blenlib/intern/pbvh.c | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/rct.c | 40 | ||||
-rw-r--r-- | source/blender/blenlib/intern/string.c | 19 | ||||
-rw-r--r-- | source/blender/blenlib/intern/voronoi.c | 2 |
15 files changed, 264 insertions, 198 deletions
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h index abe7eacb1ac..1330a74bea3 100644 --- a/source/blender/blenlib/BLI_listbase.h +++ b/source/blender/blenlib/BLI_listbase.h @@ -48,11 +48,13 @@ int BLI_findstringindex(const struct ListBase *listbase, const char *id, const i void *BLI_findlink(const struct ListBase *listbase, int number); void *BLI_findstring(const struct ListBase *listbase, const char *id, const int offset); void *BLI_findstring_ptr(const struct ListBase *listbase, const char *id, const int offset); +void *BLI_findptr(const struct ListBase *listbase, const void *ptr, const int offset); /* find backwards */ void *BLI_rfindlink(const struct ListBase *listbase, int number); void *BLI_rfindstring(const struct ListBase *listbase, const char *id, const int offset); void *BLI_rfindstring_ptr(const struct ListBase *listbase, const char *id, const int offset); +void *BLI_rfindptr(const struct ListBase *listbase, const void *ptr, const int offset); void BLI_freelistN(struct ListBase *listbase); void BLI_addtail(struct ListBase *listbase, void *vlink); diff --git a/source/blender/blenlib/BLI_math_base.h b/source/blender/blenlib/BLI_math_base.h index b0e0d3cbf19..4a89776a52e 100644 --- a/source/blender/blenlib/BLI_math_base.h +++ b/source/blender/blenlib/BLI_math_base.h @@ -137,8 +137,30 @@ # endif #endif +/* Causes warning: + * incompatible types when assigning to type 'Foo' from type 'Bar' + * ... the compiler optimizes away the temp var */ +#ifndef CHECK_TYPE +#ifdef __GNUC__ +#define CHECK_TYPE(var, type) { \ + __typeof(var) *__tmp; \ + __tmp = (type *)NULL; \ + (void)__tmp; \ +} (void)0 +#else +#define CHECK_TYPE(var, type) +#endif +#endif + #ifndef SWAP -# define SWAP(type, a, b) { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } (void)0 +# define SWAP(type, a, b) { \ + type sw_ap; \ + CHECK_TYPE(a, type); \ + CHECK_TYPE(b, type); \ + sw_ap = (a); \ + (a) = (b); \ + (b) = sw_ap; \ +} (void)0 #endif #ifndef CLAMP diff --git a/source/blender/blenlib/BLI_math_rotation.h b/source/blender/blenlib/BLI_math_rotation.h index a40d4ca8463..8a439c7cf7a 100644 --- a/source/blender/blenlib/BLI_math_rotation.h +++ b/source/blender/blenlib/BLI_math_rotation.h @@ -60,6 +60,7 @@ void sub_qt_qtqt(float q[4], const float a[4], const float b[4]); void invert_qt(float q[4]); void invert_qt_qt(float q1[4], const float q2[4]); void conjugate_qt(float q[4]); +void conjugate_qt_qt(float q1[4], const float q2[4]); float dot_qtqt(const float a[4], const float b[4]); float normalize_qt(float q[4]); float normalize_qt_qt(float q1[4], const float q2[4]); @@ -151,10 +152,10 @@ void mat3_to_eulO(float eul[3], const short order, float mat[3][3]); void mat4_to_eulO(float eul[3], const short order, float mat[4][4]); void axis_angle_to_eulO(float eul[3], const short order, const float axis[3], const float angle); -void mat3_to_compatible_eulO(float eul[3], float old[3], short order, float mat[3][3]); -void mat4_to_compatible_eulO(float eul[3], float old[3], short order, float mat[4][4]); +void mat3_to_compatible_eulO(float eul[3], float old[3], const short order, float mat[3][3]); +void mat4_to_compatible_eulO(float eul[3], float old[3], const short order, float mat[4][4]); -void rotate_eulO(float eul[3], short order, char axis, float angle); +void rotate_eulO(float eul[3], const short order, char axis, float angle); /******************************* Dual Quaternions ****************************/ diff --git a/source/blender/blenlib/BLI_pbvh.h b/source/blender/blenlib/BLI_pbvh.h index 6c0d547fe6f..20d04f7881e 100644 --- a/source/blender/blenlib/BLI_pbvh.h +++ b/source/blender/blenlib/BLI_pbvh.h @@ -260,8 +260,8 @@ void BLI_pbvh_node_free_proxies(PBVHNode *node); PBVHProxyNode *BLI_pbvh_node_add_proxy(PBVH *bvh, PBVHNode *node); void BLI_pbvh_gather_proxies(PBVH *pbvh, PBVHNode ***nodes, int *totnode); -//void BLI_pbvh_node_BB_reset(PBVHNode* node); -//void BLI_pbvh_node_BB_expand(PBVHNode* node, float co[3]); +//void BLI_pbvh_node_BB_reset(PBVHNode *node); +//void BLI_pbvh_node_BB_expand(PBVHNode *node, float co[3]); #endif /* __BLI_PBVH_H__ */ diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index 55ab961cc53..eb9915d6c9b 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -57,25 +57,35 @@ void BLI_rctf_interp(struct rctf *rect, const struct rctf *rect_a, const struct //void BLI_rcti_interp(struct rctf *rect, struct rctf *rect_a, struct rctf *rect_b, float fac); int BLI_rctf_compare(const struct rctf *rect_a, const struct rctf *rect_b, const float limit); int BLI_rcti_compare(const struct rcti *rect_a, const struct rcti *rect_b); -int BLI_in_rcti(const struct rcti *rect, const int x, const int y); -int BLI_in_rcti_v(const struct rcti *rect, const int xy[2]); -int BLI_in_rctf(const struct rctf *rect, const float x, const float y); -int BLI_in_rctf_v(const struct rctf *rect, const float xy[2]); +int BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest); +int BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest); +int BLI_rcti_isect_pt(const struct rcti *rect, const int x, const int y); +int BLI_rcti_isect_pt_v(const struct rcti *rect, const int xy[2]); +int BLI_rctf_isect_pt(const struct rctf *rect, const float x, const float y); +int BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2]); int BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2]); #if 0 /* NOT NEEDED YET */ int BLI_rctf_isect_segment(struct rcti *rect, int s1[2], int s2[2]); #endif -int BLI_rctf_isect(const struct rctf *src1, const struct rctf *src2, struct rctf *dest); -int BLI_rcti_isect(const struct rcti *src1, const struct rcti *src2, struct rcti *dest); void BLI_rctf_union(struct rctf *rctf1, const struct rctf *rctf2); void BLI_rcti_union(struct rcti *rcti1, const struct rcti *rcti2); -void BLI_rcti_rctf_copy(struct rcti *tar, const struct rctf *src); +void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src); +void BLI_rctf_rcti_copy(struct rctf *dst, const struct rcti *src); void print_rctf(const char *str, const struct rctf *rect); void print_rcti(const char *str, const struct rcti *rect); +#define BLI_RCT_SIZE_X(rct) ((rct)->xmax - (rct)->xmin) +#define BLI_RCT_SIZE_Y(rct) ((rct)->ymax - (rct)->ymin) + +#define BLI_RCT_CENTER_X(rct) (((rct)->xmin + (rct)->xmax) / 2) +#define BLI_RCT_CENTER_Y(rct) (((rct)->ymin + (rct)->ymax) / 2) + +#define BLI_RCT_CENTER_X_FL(rct) ((float)((rct)->xmin + (rct)->xmax) / 2.0f) +#define BLI_RCT_CENTER_Y_FL(rct) ((float)((rct)->ymin + (rct)->ymax) / 2.0f) + #ifdef __cplusplus } #endif -#endif +#endif /* __BLI_RECT_H__ */ diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index a74629e589c..b3d0df04eb1 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -32,6 +32,8 @@ * \ingroup bli */ +#include <stdarg.h> + #ifdef __cplusplus extern "C" { #endif @@ -140,6 +142,11 @@ __attribute__((nonnull)) ; /* + * Replacement for vsnprintf + */ +size_t BLI_vsnprintf(char *buffer, size_t count, const char *format, va_list arg); + +/* * Print formatted string into a newly mallocN'd string * and return it. */ diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 78d54defafd..8a459b9b07c 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -113,8 +113,30 @@ /* some math and copy defines */ +/* Causes warning: + * incompatible types when assigning to type 'Foo' from type 'Bar' + * ... the compiler optimizes away the temp var */ +#ifndef CHECK_TYPE +#ifdef __GNUC__ +#define CHECK_TYPE(var, type) { \ + __typeof(var) *__tmp; \ + __tmp = (type *)NULL; \ + (void)__tmp; \ +} (void)0 +#else +#define CHECK_TYPE(var, type) +#endif +#endif + #ifndef SWAP -# define SWAP(type, a, b) { type sw_ap; sw_ap = (a); (a) = (b); (b) = sw_ap; } (void)0 +# define SWAP(type, a, b) { \ + type sw_ap; \ + CHECK_TYPE(a, type); \ + CHECK_TYPE(b, type); \ + sw_ap = (a); \ + (a) = (b); \ + (b) = sw_ap; \ +} (void)0 #endif #define ABS(a) ( (a) < 0 ? (-(a)) : (a) ) diff --git a/source/blender/blenlib/BLI_vfontdata.h b/source/blender/blenlib/BLI_vfontdata.h index a63ec8e9f61..ed7d10ab257 100644 --- a/source/blender/blenlib/BLI_vfontdata.h +++ b/source/blender/blenlib/BLI_vfontdata.h @@ -39,14 +39,8 @@ struct PackedFile; struct VFont; -#define MAX_VF_CHARS 256 - typedef struct VFontData { ListBase characters; - // ListBase nurbsbase[MAX_VF_CHARS]; - // float resol[MAX_VF_CHARS]; - // float width[MAX_VF_CHARS]; - // float *points[MAX_VF_CHARS]; char name[128]; } VFontData; @@ -59,12 +53,6 @@ typedef struct VChar { float *points; } VChar; -struct TmpFont { - struct TmpFont *next, *prev; - struct PackedFile *pf; - struct VFont *vfont; -}; - /** * Construct a new VFontData structure from * Freetype font data in a PackedFile. diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index 60999e76c47..597a645eb9c 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -293,19 +293,12 @@ static int objchr_to_ftvfontdata(VFont *vfont, FT_ULong charcode) { /* Freetype2 */ FT_Face face; - struct TmpFont *tf; - - /* Find the correct FreeType font */ - tf = BKE_vfont_tmpfont_find(vfont); - - /* What, no font found. Something strange here */ - if (!tf) return FALSE; /* Load the font to memory */ - if (tf->pf) { + if (vfont->temp_pf) { err = FT_New_Memory_Face(library, - tf->pf->data, - tf->pf->size, + vfont->temp_pf->data, + vfont->temp_pf->size, 0, &face); if (err) return FALSE; diff --git a/source/blender/blenlib/intern/listbase.c b/source/blender/blenlib/intern/listbase.c index 8fe9a94b466..ad718ed8e11 100644 --- a/source/blender/blenlib/intern/listbase.c +++ b/source/blender/blenlib/intern/listbase.c @@ -439,6 +439,44 @@ void *BLI_rfindstring_ptr(const ListBase *listbase, const char *id, const int of return NULL; } +void *BLI_findptr(const ListBase *listbase, const void *ptr, const int offset) +{ + Link *link = NULL; + const void *ptr_iter; + + if (listbase == NULL) return NULL; + + for (link = listbase->first; link; link = link->next) { + /* exact copy of BLI_findstring(), except for this line */ + ptr_iter = *((const char **)(((const char *)link) + offset)); + + if (ptr == ptr_iter) { + return link; + } + } + + return NULL; +} +/* same as above but find reverse */ +void *BLI_rfindptr(const ListBase *listbase, const void *ptr, const int offset) +{ + Link *link = NULL; + const void *ptr_iter; + + if (listbase == NULL) return NULL; + + for (link = listbase->last; link; link = link->prev) { + /* exact copy of BLI_rfindstring(), except for this line */ + ptr_iter = *((const char **)(((const char *)link) + offset)); + + if (ptr == ptr_iter) { + return link; + } + } + + return NULL; +} + int BLI_findstringindex(const ListBase *listbase, const char *id, const int offset) { Link *link = NULL; diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c index 1698733dda7..f0ed23aabc9 100644 --- a/source/blender/blenlib/intern/math_rotation.c +++ b/source/blender/blenlib/intern/math_rotation.c @@ -34,7 +34,7 @@ /******************************** Quaternions ********************************/ -/* used to test is a quat is not normalized */ +/* used to test is a quat is not normalized (only used for debug prints) */ #define QUAT_EPSILON 0.0001 /* convenience, avoids setting Y axis everywhere */ @@ -113,6 +113,14 @@ void mul_qt_v3(const float q[4], float v[3]) v[1] = t2; } +void conjugate_qt_qt(float q1[4], const float q2[4]) +{ + q1[0] = q2[0]; + q1[1] = -q2[1]; + q1[2] = -q2[2]; + q1[3] = -q2[3]; +} + void conjugate_qt(float q[4]) { q[1] = -q[1]; @@ -370,7 +378,7 @@ float normalize_qt(float q[4]) { float len; - len = (float)sqrt(dot_qtqt(q, q)); + len = sqrtf(dot_qtqt(q, q)); if (len != 0.0f) { mul_qt_fl(q, 1.0f / len); } @@ -404,80 +412,75 @@ void rotation_between_vecs_to_quat(float q[4], const float v1[3], const float v2 void rotation_between_quats_to_quat(float q[4], const float q1[4], const float q2[4]) { float tquat[4]; - double dot = 0.0f; - int x; - copy_qt_qt(tquat, q1); - conjugate_qt(tquat); - dot = 1.0f / dot_qtqt(tquat, tquat); + conjugate_qt_qt(tquat, q1); - for (x = 0; x < 4; x++) - tquat[x] *= dot; + mul_qt_fl(tquat, 1.0f / dot_qtqt(tquat, tquat)); mul_qt_qtqt(q, tquat, q2); } void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) { - float q2[4], nor[3], *fp, mat[3][3], angle, si, co, x2, y2, z2, len1; + float nor[3], tvec[3]; + float angle, si, co, len; assert(axis >= 0 && axis <= 5); assert(upflag >= 0 && upflag <= 2); - /* first rotate to axis */ + /* first set the quat to unit */ + unit_qt(q); + + len = len_v3(vec); + + if (UNLIKELY(len == 0.0f)) { + return; + } + + /* rotate to axis */ if (axis > 2) { - x2 = vec[0]; - y2 = vec[1]; - z2 = vec[2]; + copy_v3_v3(tvec, vec); axis -= 3; } else { - x2 = -vec[0]; - y2 = -vec[1]; - z2 = -vec[2]; + negate_v3_v3(tvec, vec); } - q[0] = 1.0; - q[1] = q[2] = q[3] = 0.0; - - len1 = (float)sqrt(x2 * x2 + y2 * y2 + z2 * z2); - if (len1 == 0.0f) return; - /* nasty! I need a good routine for this... * problem is a rotation of an Y axis to the negative Y-axis for example. */ if (axis == 0) { /* x-axis */ - nor[0] = 0.0; - nor[1] = -z2; - nor[2] = y2; + nor[0] = 0.0; + nor[1] = -tvec[2]; + nor[2] = tvec[1]; - if (fabsf(y2) + fabsf(z2) < 0.0001f) - nor[1] = 1.0; + if (fabsf(tvec[1]) + fabsf(tvec[2]) < 0.0001f) + nor[1] = 1.0f; - co = x2; + co = tvec[0]; } else if (axis == 1) { /* y-axis */ - nor[0] = z2; - nor[1] = 0.0; - nor[2] = -x2; + nor[0] = tvec[2]; + nor[1] = 0.0; + nor[2] = -tvec[0]; - if (fabsf(x2) + fabsf(z2) < 0.0001f) - nor[2] = 1.0; + if (fabsf(tvec[0]) + fabsf(tvec[2]) < 0.0001f) + nor[2] = 1.0f; - co = y2; + co = tvec[1]; } else { /* z-axis */ - nor[0] = -y2; - nor[1] = x2; - nor[2] = 0.0; + nor[0] = -tvec[1]; + nor[1] = tvec[0]; + nor[2] = 0.0; - if (fabsf(x2) + fabsf(y2) < 0.0001f) - nor[0] = 1.0; + if (fabsf(tvec[0]) + fabsf(tvec[1]) < 0.0001f) + nor[0] = 1.0f; - co = z2; + co = tvec[2]; } - co /= len1; + co /= len; normalize_v3(nor); @@ -489,28 +492,30 @@ void vec_to_quat(float q[4], const float vec[3], short axis, const short upflag) q[3] = nor[2] * si; if (axis != upflag) { + float mat[3][3]; + float q2[4]; + const float *fp = mat[2]; quat_to_mat3(mat, q); - fp = mat[2]; if (axis == 0) { - if (upflag == 1) angle = (float)(0.5 * atan2(fp[2], fp[1])); - else angle = (float)(-0.5 * atan2(fp[1], fp[2])); + if (upflag == 1) angle = 0.5f * atan2f(fp[2], fp[1]); + else angle = -0.5f * atan2f(fp[1], fp[2]); } else if (axis == 1) { - if (upflag == 0) angle = (float)(-0.5 * atan2(fp[2], fp[0])); - else angle = (float)(0.5 * atan2(fp[0], fp[2])); + if (upflag == 0) angle = -0.5f * atan2f(fp[2], fp[0]); + else angle = 0.5f * atan2f(fp[0], fp[2]); } else { - if (upflag == 0) angle = (float)(0.5 * atan2(-fp[1], -fp[0])); - else angle = (float)(-0.5 * atan2(-fp[0], -fp[1])); + if (upflag == 0) angle = 0.5f * atan2f(-fp[1], -fp[0]); + else angle = -0.5f * atan2f(-fp[0], -fp[1]); } co = cosf(angle); - si = sinf(angle) / len1; + si = sinf(angle) / len; q2[0] = co; - q2[1] = x2 * si; - q2[2] = y2 * si; - q2[3] = z2 * si; + q2[1] = tvec[0] * si; + q2[2] = tvec[1] * si; + q2[3] = tvec[2] * si; mul_qt_qtqt(q, q2, q); } @@ -1040,84 +1045,46 @@ void rotate_eul(float *beul, const char axis, const float ang) } -/* exported to transform.c */ - /* order independent! */ void compatible_eul(float eul[3], const float oldrot[3]) { - float dx, dy, dz; + /* we could use M_PI as pi_thresh: which is correct but 5.1 gives better results. + * Checked with baking actions to fcurves - campbell */ + const float pi_thresh = (5.1f); + const float pi_x2 = (2.0f * (float)M_PI); + + float deul[3]; + unsigned int i; /* correct differences of about 360 degrees first */ - dx = eul[0] - oldrot[0]; - dy = eul[1] - oldrot[1]; - dz = eul[2] - oldrot[2]; - - while (fabsf(dx) > 5.1f) { - if (dx > 0.0f) eul[0] -= 2.0f * (float)M_PI; - else eul[0] += 2.0f * (float)M_PI; - dx = eul[0] - oldrot[0]; - } - while (fabsf(dy) > 5.1f) { - if (dy > 0.0f) eul[1] -= 2.0f * (float)M_PI; - else eul[1] += 2.0f * (float)M_PI; - dy = eul[1] - oldrot[1]; - } - while (fabsf(dz) > 5.1f) { - if (dz > 0.0f) eul[2] -= 2.0f * (float)M_PI; - else eul[2] += 2.0f * (float)M_PI; - dz = eul[2] - oldrot[2]; + for (i = 0; i < 3; i++) { + deul[i] = eul[i] - oldrot[i]; + if (deul[i] > pi_thresh) { + eul[i] -= floorf(( deul[i] / pi_x2) + 0.5) * pi_x2; + deul[i] = eul[i] - oldrot[i]; + } + else if (deul[i] < -pi_thresh) { + eul[i] += floorf((-deul[i] / pi_x2) + 0.5) * pi_x2; + deul[i] = eul[i] - oldrot[i]; + } } /* is 1 of the axis rotations larger than 180 degrees and the other small? NO ELSE IF!! */ - if (fabsf(dx) > 3.2f && fabsf(dy) < 1.6f && fabsf(dz) < 1.6f) { - if (dx > 0.0f) eul[0] -= 2.0f * (float)M_PI; - else eul[0] += 2.0f * (float)M_PI; + if (fabsf(deul[0]) > 3.2f && fabsf(deul[1]) < 1.6f && fabsf(deul[2]) < 1.6f) { + if (deul[0] > 0.0f) eul[0] -= pi_x2; + else eul[0] += pi_x2; } - if (fabsf(dy) > 3.2f && fabsf(dz) < 1.6f && fabsf(dx) < 1.6f) { - if (dy > 0.0f) eul[1] -= 2.0f * (float)M_PI; - else eul[1] += 2.0f * (float)M_PI; + if (fabsf(deul[1]) > 3.2f && fabsf(deul[2]) < 1.6f && fabsf(deul[0]) < 1.6f) { + if (deul[1] > 0.0f) eul[1] -= pi_x2; + else eul[1] += pi_x2; } - if (fabsf(dz) > 3.2f && fabsf(dx) < 1.6f && fabsf(dy) < 1.6f) { - if (dz > 0.0f) eul[2] -= 2.0f * (float)M_PI; - else eul[2] += 2.0f * (float)M_PI; + if (fabsf(deul[2]) > 3.2f && fabsf(deul[0]) < 1.6f && fabsf(deul[1]) < 1.6f) { + if (deul[2] > 0.0f) eul[2] -= pi_x2; + else eul[2] += pi_x2; } - /* the method below was there from ancient days... but why! probably because the code sucks :) - */ -#if 0 - /* calc again */ - dx = eul[0] - oldrot[0]; - dy = eul[1] - oldrot[1]; - dz = eul[2] - oldrot[2]; - - /* special case, tested for x-z */ - - if ((fabsf(dx) > 3.1f && fabsf(dz) > 1.5f) || (fabsf(dx) > 1.5f && fabsf(dz) > 3.1f)) { - if (dx > 0.0f) eul[0] -= M_PI; - else eul[0] += M_PI; - if (eul[1] > 0.0) eul[1] = M_PI - eul[1]; - else eul[1] = -M_PI - eul[1]; - if (dz > 0.0f) eul[2] -= M_PI; - else eul[2] += M_PI; - - } - else if ((fabsf(dx) > 3.1f && fabsf(dy) > 1.5f) || (fabsf(dx) > 1.5f && fabsf(dy) > 3.1f)) { - if (dx > 0.0f) eul[0] -= M_PI; - else eul[0] += M_PI; - if (dy > 0.0f) eul[1] -= M_PI; - else eul[1] += M_PI; - if (eul[2] > 0.0f) eul[2] = M_PI - eul[2]; - else eul[2] = -M_PI - eul[2]; - } - else if ((fabsf(dy) > 3.1f && fabsf(dz) > 1.5f) || (fabsf(dy) > 1.5f && fabsf(dz) > 3.f1)) { - if (eul[0] > 0.0f) eul[0] = M_PI - eul[0]; - else eul[0] = -M_PI - eul[0]; - if (dy > 0.0f) eul[1] -= M_PI; - else eul[1] += M_PI; - if (dz > 0.0f) eul[2] -= M_PI; - else eul[2] += M_PI; - } -#endif +#undef PI_THRESH +#undef PI_2F } /* uses 2 methods to retrieve eulers, and picks the closest */ @@ -1166,7 +1133,7 @@ typedef struct RotOrderInfo { /* Array of info for Rotation Order calculations * WARNING: must be kept in same order as eEulerRotationOrders */ -static RotOrderInfo rotOrders[] = { +static const RotOrderInfo rotOrders[] = { /* i, j, k, n */ {{0, 1, 2}, 0}, /* XYZ */ {{0, 2, 1}, 1}, /* XZY */ @@ -1185,7 +1152,7 @@ static RotOrderInfo rotOrders[] = { /* Construct quaternion from Euler angles (in radians). */ void eulO_to_quat(float q[4], const float e[3], const short order) { - RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); + const RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); short i = R->axis[0], j = R->axis[1], k = R->axis[2]; double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; double a[3]; @@ -1230,7 +1197,7 @@ void quat_to_eulO(float e[3], short const order, const float q[4]) /* Construct 3x3 matrix from Euler angles (in radians). */ void eulO_to_mat3(float M[3][3], const float e[3], const short order) { - RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); + const RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); short i = R->axis[0], j = R->axis[1], k = R->axis[2]; double ti, tj, th, ci, cj, ch, si, sj, sh, cc, cs, sc, ss; @@ -1269,9 +1236,9 @@ void eulO_to_mat3(float M[3][3], const float e[3], const short order) } /* returns two euler calculation methods, so we can pick the best */ -static void mat3_to_eulo2(float M[3][3], float *e1, float *e2, short order) +static void mat3_to_eulo2(float M[3][3], float *e1, float *e2, const short order) { - RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); + const RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); short i = R->axis[0], j = R->axis[1], k = R->axis[2]; float m[3][3]; double cy; @@ -1349,7 +1316,7 @@ void mat4_to_eulO(float e[3], const short order, float M[4][4]) } /* uses 2 methods to retrieve eulers, and picks the closest */ -void mat3_to_compatible_eulO(float eul[3], float oldrot[3], short order, float mat[3][3]) +void mat3_to_compatible_eulO(float eul[3], float oldrot[3], const short order, float mat[3][3]) { float eul1[3], eul2[3]; float d1, d2; @@ -1369,7 +1336,7 @@ void mat3_to_compatible_eulO(float eul[3], float oldrot[3], short order, float m copy_v3_v3(eul, eul1); } -void mat4_to_compatible_eulO(float eul[3], float oldrot[3], short order, float M[4][4]) +void mat4_to_compatible_eulO(float eul[3], float oldrot[3], const short order, float M[4][4]) { float m[3][3]; @@ -1381,7 +1348,7 @@ void mat4_to_compatible_eulO(float eul[3], float oldrot[3], short order, float M /* rotate the given euler by the given angle on the specified axis */ // NOTE: is this safe to do with different axis orders? -void rotate_eulO(float beul[3], short order, char axis, float ang) +void rotate_eulO(float beul[3], const short order, char axis, float ang) { float eul[3], mat1[3][3], mat2[3][3], totmat[3][3]; @@ -1406,7 +1373,7 @@ void rotate_eulO(float beul[3], short order, char axis, float ang) /* the matrix is written to as 3 axis vectors */ void eulO_to_gimbal_axis(float gmat[][3], const float eul[3], const short order) { - RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); + const RotOrderInfo *R = GET_ROTATIONORDER_INFO(order); float mat[3][3]; float teul[3]; @@ -1474,10 +1441,9 @@ void mat4_to_dquat(DualQuat *dq, float basemat[][4], float mat[][4]) mult_m4_m4m4(baseRS, mat, basemat); mat4_to_size(scale, baseRS); - copy_v3_v3(dscale, scale); - dscale[0] -= 1.0f; - dscale[1] -= 1.0f; - dscale[2] -= 1.0f; + dscale[0] = scale[0] - 1.0f; + dscale[1] = scale[1] - 1.0f; + dscale[2] = scale[2] - 1.0f; if ((determinant_m4(mat) < 0.0f) || len_v3(dscale) > 1e-4f) { /* extract R and S */ @@ -1513,10 +1479,10 @@ void mat4_to_dquat(DualQuat *dq, float basemat[][4], float mat[][4]) /* dual part */ t = R[3]; q = dq->quat; - dq->trans[0] = -0.5f * (t[0] * q[1] + t[1] * q[2] + t[2] * q[3]); - dq->trans[1] = 0.5f * (t[0] * q[0] + t[1] * q[3] - t[2] * q[2]); - dq->trans[2] = 0.5f * (-t[0] * q[3] + t[1] * q[0] + t[2] * q[1]); - dq->trans[3] = 0.5f * (t[0] * q[2] - t[1] * q[1] + t[2] * q[0]); + dq->trans[0] = -0.5f * ( t[0] * q[1] + t[1] * q[2] + t[2] * q[3]); + dq->trans[1] = 0.5f * ( t[0] * q[0] + t[1] * q[3] - t[2] * q[2]); + dq->trans[2] = 0.5f * (-t[0] * q[3] + t[1] * q[0] + t[2] * q[1]); + dq->trans[3] = 0.5f * ( t[0] * q[2] - t[1] * q[1] + t[2] * q[0]); } void dquat_to_mat4(float mat[][4], DualQuat *dq) @@ -1527,7 +1493,7 @@ void dquat_to_mat4(float mat[][4], DualQuat *dq) copy_qt_qt(q0, dq->quat); /* normalize */ - len = (float)sqrt(dot_qtqt(q0, q0)); + len = sqrtf(dot_qtqt(q0, q0)); if (len != 0.0f) mul_qt_fl(q0, 1.0f / len); diff --git a/source/blender/blenlib/intern/pbvh.c b/source/blender/blenlib/intern/pbvh.c index b4b546d9167..22597c9f8e6 100644 --- a/source/blender/blenlib/intern/pbvh.c +++ b/source/blender/blenlib/intern/pbvh.c @@ -260,12 +260,12 @@ static void update_node_vb(PBVH *bvh, PBVHNode *node) node->vb = vb; } -//void BLI_pbvh_node_BB_reset(PBVHNode* node) +//void BLI_pbvh_node_BB_reset(PBVHNode *node) //{ // BB_reset(&node->vb); //} // -//void BLI_pbvh_node_BB_expand(PBVHNode* node, float co[3]) +//void BLI_pbvh_node_BB_expand(PBVHNode *node, float co[3]) //{ // BB_expand(&node->vb, co); //} diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index e22becddfd6..225ede8a8ef 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -58,7 +58,7 @@ int BLI_rctf_is_empty(const rctf *rect) return ((rect->xmax <= rect->xmin) || (rect->ymax <= rect->ymin)); } -int BLI_in_rcti(const rcti *rect, const int x, const int y) +int BLI_rcti_isect_pt(const rcti *rect, const int x, const int y) { if (x < rect->xmin) return 0; if (x > rect->xmax) return 0; @@ -74,7 +74,7 @@ int BLI_in_rcti(const rcti *rect, const int x, const int y) * * \return True if \a rect is empty. */ -int BLI_in_rcti_v(const rcti *rect, const int xy[2]) +int BLI_rcti_isect_pt_v(const rcti *rect, const int xy[2]) { if (xy[0] < rect->xmin) return 0; if (xy[0] > rect->xmax) return 0; @@ -83,7 +83,7 @@ int BLI_in_rcti_v(const rcti *rect, const int xy[2]) return 1; } -int BLI_in_rctf(const rctf *rect, const float x, const float y) +int BLI_rctf_isect_pt(const rctf *rect, const float x, const float y) { if (x < rect->xmin) return 0; if (x > rect->xmax) return 0; @@ -92,7 +92,7 @@ int BLI_in_rctf(const rctf *rect, const float x, const float y) return 1; } -int BLI_in_rctf_v(const rctf *rect, const float xy[2]) +int BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2]) { if (xy[0] < rect->xmin) return 0; if (xy[0] > rect->xmax) return 0; @@ -124,7 +124,7 @@ int BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2]) if (s1[1] > rect->ymax && s2[1] > rect->ymax) return 0; /* if either points intersect then we definetly intersect */ - if (BLI_in_rcti_v(rect, s1) || BLI_in_rcti_v(rect, s2)) { + if (BLI_rcti_isect_pt_v(rect, s1) || BLI_rcti_isect_pt_v(rect, s2)) { return 1; } else { @@ -252,8 +252,8 @@ void BLI_rctf_translate(rctf *rect, float x, float y) /* change width & height around the central location */ void BLI_rcti_resize(rcti *rect, int x, int y) { - rect->xmin = rect->xmax = (rect->xmax + rect->xmin) / 2; - rect->ymin = rect->ymax = (rect->ymax + rect->ymin) / 2; + rect->xmin = rect->xmax = BLI_RCT_CENTER_X(rect); + rect->ymin = rect->ymax = BLI_RCT_CENTER_Y(rect); rect->xmin -= x / 2; rect->ymin -= y / 2; rect->xmax = rect->xmin + x; @@ -262,8 +262,8 @@ void BLI_rcti_resize(rcti *rect, int x, int y) void BLI_rctf_resize(rctf *rect, float x, float y) { - rect->xmin = rect->xmax = (rect->xmax + rect->xmin) * 0.5f; - rect->ymin = rect->ymax = (rect->ymax + rect->ymin) * 0.5f; + rect->xmin = rect->xmax = BLI_RCT_CENTER_X(rect); + rect->ymin = rect->ymax = BLI_RCT_CENTER_Y(rect); rect->xmin -= x * 0.5f; rect->ymin -= y * 0.5f; rect->xmax = rect->xmin + x; @@ -363,22 +363,30 @@ int BLI_rcti_isect(const rcti *src1, const rcti *src2, rcti *dest) } } -void BLI_rcti_rctf_copy(rcti *tar, const rctf *src) +void BLI_rcti_rctf_copy(rcti *dst, const rctf *src) { - tar->xmin = floorf(src->xmin + 0.5f); - tar->xmax = floorf((src->xmax - src->xmin) + 0.5f); - tar->ymin = floorf(src->ymin + 0.5f); - tar->ymax = floorf((src->ymax - src->ymin) + 0.5f); + dst->xmin = floorf(src->xmin + 0.5f); + dst->xmax = dst->xmin + floorf(BLI_RCT_SIZE_X(src) + 0.5f); + dst->ymin = floorf(src->ymin + 0.5f); + dst->ymax = dst->ymin + floorf(BLI_RCT_SIZE_Y(src) + 0.5f); +} + +void BLI_rctf_rcti_copy(rctf *dst, const rcti *src) +{ + dst->xmin = src->xmin; + dst->xmax = src->xmax; + dst->ymin = src->ymin; + dst->ymax = src->ymax; } void print_rctf(const char *str, const rctf *rect) { printf("%s: xmin %.3f, xmax %.3f, ymin %.3f, ymax %.3f (%.3fx%.3f)\n", str, - rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin); + rect->xmin, rect->xmax, rect->ymin, rect->ymax, BLI_RCT_SIZE_X(rect), BLI_RCT_SIZE_Y(rect)); } void print_rcti(const char *str, const rcti *rect) { printf("%s: xmin %d, xmax %d, ymin %d, ymax %d (%dx%d)\n", str, - rect->xmin, rect->xmax, rect->ymin, rect->ymax, rect->xmax - rect->xmin, rect->ymax - rect->ymin); + rect->xmin, rect->xmax, rect->ymin, rect->ymax, BLI_RCT_SIZE_X(rect), BLI_RCT_SIZE_Y(rect)); } diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 7a750a74a33..8501db7c8b8 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -78,22 +78,31 @@ char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy) return dst; } -size_t BLI_snprintf(char *buffer, size_t count, const char *format, ...) +size_t BLI_vsnprintf(char *buffer, size_t count, const char *format, va_list arg) { size_t n; - va_list arg; - va_start(arg, format); n = vsnprintf(buffer, count, format, arg); - + if (n != -1 && n < count) { buffer[n] = '\0'; } else { buffer[count - 1] = '\0'; } - + + return n; +} + +size_t BLI_snprintf(char *buffer, size_t count, const char *format, ...) +{ + size_t n; + va_list arg; + + va_start(arg, format); + n = BLI_vsnprintf(buffer, count, format, arg); va_end(arg); + return n; } diff --git a/source/blender/blenlib/intern/voronoi.c b/source/blender/blenlib/intern/voronoi.c index f61df9c11f5..80a4da5cace 100644 --- a/source/blender/blenlib/intern/voronoi.c +++ b/source/blender/blenlib/intern/voronoi.c @@ -28,7 +28,7 @@ * http://blog.ivank.net/fortunes-algorithm-and-implementation.html */ -/** \file blender/blenkernel/intern/voronoi.c +/** \file blender/blenlib/intern/voronoi.c * \ingroup bli */ |