diff options
author | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-10-20 20:48:48 +0400 |
---|---|---|
committer | Tamito Kajiyama <rd6t-kjym@asahi-net.or.jp> | 2012-10-20 20:48:48 +0400 |
commit | 55015daa43f0ab45341e316abcf11f23c87b5ebe (patch) | |
tree | 3156892b6d807d9ba513d444adb870b0ae358e7a /source/blender/blenlib | |
parent | 1fe70c07a008185c4e5925aff2c214c93ff396b7 (diff) | |
parent | a9e2e2279780ec2fb58e6820b9cad95ba03f4cad (diff) |
Merged changes in the trunk up to revision 51448.
Conflicts resolved:
source/blender/blenkernel/CMakeLists.txt
source/blender/blenloader/intern/readfile.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/makesrna/intern/rna_main_api.c
Diffstat (limited to 'source/blender/blenlib')
28 files changed, 410 insertions, 135 deletions
diff --git a/source/blender/blenlib/BLI_blenlib.h b/source/blender/blenlib/BLI_blenlib.h index 74b477bacaf..03b75975af4 100644 --- a/source/blender/blenlib/BLI_blenlib.h +++ b/source/blender/blenlib/BLI_blenlib.h @@ -78,8 +78,6 @@ extern "C" { #include "BLI_rect.h" -#include "BLI_noise.h" - #ifdef __cplusplus } #endif diff --git a/source/blender/blenlib/BLI_bpath.h b/source/blender/blenlib/BLI_bpath.h index 52b839d11a9..a86b362c271 100644 --- a/source/blender/blenlib/BLI_bpath.h +++ b/source/blender/blenlib/BLI_bpath.h @@ -64,4 +64,4 @@ void BLI_bpath_missing_files_find(struct Main *bmain, const char *searchpath, st void BLI_bpath_relative_convert(struct Main *bmain, const char *basedir, struct ReportList *reports); void BLI_bpath_absolute_convert(struct Main *bmain, const char *basedir, struct ReportList *reports); -#endif // __BLI_BPATH_H__ +#endif /* __BLI_BPATH_H__ */ diff --git a/source/blender/blenlib/BLI_dlrbTree.h b/source/blender/blenlib/BLI_dlrbTree.h index 92356b24403..d04e544376a 100644 --- a/source/blender/blenlib/BLI_dlrbTree.h +++ b/source/blender/blenlib/BLI_dlrbTree.h @@ -158,4 +158,4 @@ void BLI_dlrbTree_insert(DLRBT_Tree *tree, DLRBT_Node *node); /* ********************************************** */ -#endif // __BLI_DLRBTREE_H__ +#endif /* __BLI_DLRBTREE_H__ */ diff --git a/source/blender/blenlib/BLI_endian_switch_inline.h b/source/blender/blenlib/BLI_endian_switch_inline.h index b747da3b738..4bc6d3828b9 100644 --- a/source/blender/blenlib/BLI_endian_switch_inline.h +++ b/source/blender/blenlib/BLI_endian_switch_inline.h @@ -32,85 +32,63 @@ * \ingroup bli */ +/* note: using a temp char to switch endian is a lot slower, + * use bit shifting instead. */ +/* *** 16 *** */ BLI_INLINE void BLI_endian_switch_int16(short *val) { - char *p_i = (char *)val; - char s_i; + short tval = *val; + *val = (tval >> 8) | + (tval << 8); - s_i = p_i[0]; - p_i[0] = p_i[1]; - p_i[1] = s_i; } - BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val) { - char *p_i = (char *)val; - char s_i; - - s_i = p_i[0]; - p_i[0] = p_i[1]; - p_i[1] = s_i; + BLI_endian_switch_int16((short *)val); } + +/* *** 32 *** */ BLI_INLINE void BLI_endian_switch_int32(int *val) { - char *p_i = (char *)val; - char s_i; + int tval = *val; + *val = ((tval >> 24)) | + ((tval << 8) & 0x00ff0000) | + ((tval >> 8) & 0x0000ff00) | + ((tval << 24)); - s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; - s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; } - BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val) { - char *p_i = (char *)val; - char s_i; - - s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; - s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; + BLI_endian_switch_int32((int *)val); } - BLI_INLINE void BLI_endian_switch_float(float *val) { - char *p_i = (char *)val; - char s_i; - - s_i = p_i[0]; p_i[0] = p_i[3]; p_i[3] = s_i; - s_i = p_i[1]; p_i[1] = p_i[2]; p_i[2] = s_i; + BLI_endian_switch_int32((int *)val); } + +/* *** 64 *** */ BLI_INLINE void BLI_endian_switch_int64(int64_t *val) { - char *p_i = (char *)val; - char s_i; - - s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; - s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; - s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; + int64_t tval = *val; + *val = ((tval >> 56)) | + ((tval << 40) & 0x00ff000000000000ll) | + ((tval << 24) & 0x0000ff0000000000ll) | + ((tval << 8) & 0x000000ff00000000ll) | + ((tval >> 8) & 0x00000000ff000000ll) | + ((tval >> 24) & 0x0000000000ff0000ll) | + ((tval >> 40) & 0x000000000000ff00ll) | + ((tval << 56)); } - BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val) { - char *p_i = (char *)val; - char s_i; - - s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; - s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; - s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; + BLI_endian_switch_int64((int64_t *)val); } - BLI_INLINE void BLI_endian_switch_double(double *val) { - char *p_i = (char *)val; - char s_i; - - s_i = p_i[0]; p_i[0] = p_i[7]; p_i[7] = s_i; - s_i = p_i[1]; p_i[1] = p_i[6]; p_i[6] = s_i; - s_i = p_i[2]; p_i[2] = p_i[5]; p_i[5] = s_i; - s_i = p_i[3]; p_i[3] = p_i[4]; p_i[4] = s_i; + BLI_endian_switch_int64((int64_t *)val); } #endif /* __BLI_ENDIAN_SWITCH_INLINE_H__ */ diff --git a/source/blender/blenlib/BLI_heap.h b/source/blender/blenlib/BLI_heap.h index b378f2bb365..9d7e6107f19 100644 --- a/source/blender/blenlib/BLI_heap.h +++ b/source/blender/blenlib/BLI_heap.h @@ -42,6 +42,7 @@ typedef void (*HeapFreeFP)(void *ptr); /* Creates a new heap. BLI_memarena is used for allocating nodes. Removed nodes * are recycled, so memory usage will not shrink. */ +Heap *BLI_heap_new_ex(unsigned int tot_reserve); Heap *BLI_heap_new(void); void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp); diff --git a/source/blender/blenlib/BLI_kdopbvh.h b/source/blender/blenlib/BLI_kdopbvh.h index 985b5af3b94..8d0d4943ebe 100644 --- a/source/blender/blenlib/BLI_kdopbvh.h +++ b/source/blender/blenlib/BLI_kdopbvh.h @@ -75,7 +75,7 @@ typedef struct BVHTreeRayHit { } BVHTreeRayHit; /* callback must update nearest in case it finds a nearest result */ -typedef void (*BVHTree_NearestPointCallback)(void *userdata, int index, const float *co, BVHTreeNearest *nearest); +typedef void (*BVHTree_NearestPointCallback)(void *userdata, int index, const float co[3], BVHTreeNearest *nearest); /* callback must update hit in case it finds a nearest successful hit */ typedef void (*BVHTree_RayCastCallback)(void *userdata, int index, const BVHTreeRay *ray, BVHTreeRayHit *hit); @@ -87,11 +87,11 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis); void BLI_bvhtree_free(BVHTree *tree); /* construct: first insert points, then call balance */ -int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints); +int BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints); void BLI_bvhtree_balance(BVHTree *tree); /* update: first update points/nodes, then call update_tree to refit the bounding volumes */ -int BLI_bvhtree_update_node(BVHTree *tree, int index, const float *co, const float *co_moving, int numpoints); +int BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints); void BLI_bvhtree_update_tree(BVHTree *tree); /* collision/overlap: check two trees if they overlap, alloc's *overlap with length of the int return value */ @@ -99,19 +99,22 @@ BVHTreeOverlap *BLI_bvhtree_overlap(BVHTree *tree1, BVHTree *tree2, unsigned int float BLI_bvhtree_getepsilon(BVHTree *tree); -/* find nearest node to the given coordinates (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */ -int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest, BVHTree_NearestPointCallback callback, void *userdata); +/* find nearest node to the given coordinates + * (if nearest is given it will only search nodes where square distance is smaller than nearest->dist) */ +int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *nearest, + BVHTree_NearestPointCallback callback, void *userdata); -int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float *dir, float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata); +int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, + BVHTree_RayCastCallback callback, void *userdata); -float BLI_bvhtree_bb_raycast(const float *bv, const float light_start[3], const float light_end[3], float pos[3]); +float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], const float light_end[3], float pos[3]); /* range query */ -int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, BVHTree_RangeQuery callback, void *userdata); +int BLI_bvhtree_range_query(BVHTree *tree, const float co[3], float radius, + BVHTree_RangeQuery callback, void *userdata); #ifdef __cplusplus } #endif -#endif // __BLI_KDOPBVH_H__ - +#endif /* __BLI_KDOPBVH_H__ */ diff --git a/source/blender/blenlib/BLI_kdtree.h b/source/blender/blenlib/BLI_kdtree.h index e90566408d4..f9b52f34102 100644 --- a/source/blender/blenlib/BLI_kdtree.h +++ b/source/blender/blenlib/BLI_kdtree.h @@ -56,7 +56,7 @@ void BLI_kdtree_balance(KDTree *tree); /* Find nearest returns index, and -1 if no node is found. * Find n nearest returns number of points found, with results in nearest. * Normal is optional, but if given will limit results to points in normal direction from co. */ -int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest *nearest); +int BLI_kdtree_find_nearest(KDTree *tree, const float co[3], const float nor[3], KDTreeNearest *nearest); int BLI_kdtree_find_n_nearest(KDTree *tree, int n, const float co[3], const float nor[3], KDTreeNearest *nearest); /* Range search returns number of points found, with results in nearest */ diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index de1d423bfad..83b07bae53f 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -67,6 +67,7 @@ MINLINE void copy_v2_v2_short(short r[2], const short a[2]); MINLINE void copy_v3_v3_short(short r[3], const short a[3]); MINLINE void copy_v4_v4_short(short r[4], const short a[4]); /* int */ +MINLINE void zero_v3_int(int r[3]); MINLINE void copy_v2_v2_int(int r[2], const int a[2]); MINLINE void copy_v3_v3_int(int r[3], const int a[3]); MINLINE void copy_v4_v4_int(int r[4], const int a[4]); @@ -139,12 +140,16 @@ MINLINE void star_m3_v3(float rmat[3][3], float a[3]); MINLINE float len_squared_v2(const float v[2]); MINLINE float len_squared_v3(const float v[3]); +MINLINE float len_manhattan_v2(const float v[2]); +MINLINE float len_manhattan_v3(const float v[3]); MINLINE float len_v2(const float a[2]); MINLINE float len_v2v2(const float a[2], const float b[2]); MINLINE float len_squared_v2v2(const float a[2], const float b[2]); +MINLINE float len_squared_v3v3(const float a[3], const float b[3]); +MINLINE float len_manhattan_v2v2(const float a[2], const float b[2]); +MINLINE float len_manhattan_v3v3(const float a[3], const float b[3]); MINLINE float len_v3(const float a[3]); MINLINE float len_v3v3(const float a[3], const float b[3]); -MINLINE float len_squared_v3v3(const float a[3], const float b[3]); MINLINE float normalize_v2(float r[2]); MINLINE float normalize_v2_v2(float r[2], const float a[2]); diff --git a/source/blender/blenlib/BLI_quadric.h b/source/blender/blenlib/BLI_quadric.h new file mode 100644 index 00000000000..aec11ec2b44 --- /dev/null +++ b/source/blender/blenlib/BLI_quadric.h @@ -0,0 +1,56 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * Contributor(s): Laurence Bourn, Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_QUADRIC_H__ +#define __BLI_QUADRIC_H__ + +/** \file BLI_quadric.h + * \ingroup bli + */ + +typedef struct Quadric { + float a2, ab, ac, ad, + b2, bc, bd, + c2, cd, + d2; +} Quadric; + +/* conversion */ +void BLI_quadric_from_v3_dist(Quadric *q, const float v[3], const float offset); +void BLI_quadric_to_tensor_m3(const Quadric *q, float m[3][3]); +void BLI_quadric_to_vector_v3(const Quadric *q, float v[3]); + +void BLI_quadric_clear(Quadric *q); + +/* math */ +void BLI_quadric_add_qu_qu(Quadric *a, const Quadric *b); +void BLI_quadric_add_qu_ququ(Quadric *r, const Quadric *a, const Quadric *b); +void BLI_quadric_mul(Quadric *a, const float scalar); + +/* solve */ +float BLI_quadric_evaluate(const Quadric *q, const float v[3]); +int BLI_quadric_optimize(const Quadric *q, float v[3]); + +#endif /* __BLI_QUADRIC_H__ */ diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h index de4c2cf3a86..f84820e94f3 100644 --- a/source/blender/blenlib/BLI_rect.h +++ b/source/blender/blenlib/BLI_rect.h @@ -66,9 +66,7 @@ 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_segment(const struct rctf *rect, const float s1[2], const float s2[2]); 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 *dst, const struct rctf *src); diff --git a/source/blender/blenlib/BLI_string.h b/source/blender/blenlib/BLI_string.h index 666c74ca36f..943597b6688 100644 --- a/source/blender/blenlib/BLI_string.h +++ b/source/blender/blenlib/BLI_string.h @@ -74,7 +74,7 @@ __attribute__((nonnull)) * \param str2 second string for append * \retval Returns dst */ -char *BLI_strdupcat(const char *str1, const char *str2) +char *BLI_strdupcat(const char *__restrict str1, const char *__restrict str2) #ifdef __GNUC__ __attribute__((warn_unused_result)) __attribute__((nonnull)) @@ -91,7 +91,7 @@ __attribute__((nonnull)) * the size of dst) * \retval Returns dst */ -char *BLI_strncpy(char *dst, const char *src, const size_t maxncpy) +char *BLI_strncpy(char *__restrict dst, const char *__restrict src, const size_t maxncpy) #ifdef __GNUC__ __attribute__((nonnull)) #endif @@ -107,7 +107,7 @@ __attribute__((nonnull)) * Assume that the strings returned must be freed afterwards, and that the inputs will contain * data we want... */ -char *BLI_str_quoted_substrN(const char *str, const char *prefix) +char *BLI_str_quoted_substrN(const char *__restrict str, const char *__restrict prefix) #ifdef __GNUC__ __attribute__((warn_unused_result)) __attribute__((nonnull)) @@ -124,7 +124,7 @@ __attribute__((nonnull)) * \param newText The text in the string to find and replace * \retval Returns the duplicated string */ -char *BLI_replacestr(char *str, const char *oldText, const char *newText) +char *BLI_replacestr(char *__restrict str, const char *__restrict oldText, const char *__restrict newText) #ifdef __GNUC__ __attribute__((warn_unused_result)) __attribute__((nonnull)) @@ -134,7 +134,7 @@ __attribute__((nonnull)) /* * Replacement for snprintf */ -size_t BLI_snprintf(char *buffer, size_t len, const char *format, ...) +size_t BLI_snprintf(char *__restrict buffer, size_t len, const char *__restrict format, ...) #ifdef __GNUC__ __attribute__ ((format(printf, 3, 4))) __attribute__((nonnull)) @@ -144,7 +144,7 @@ __attribute__((nonnull)) /* * Replacement for vsnprintf */ -size_t BLI_vsnprintf(char *buffer, size_t count, const char *format, va_list arg) +size_t BLI_vsnprintf(char *__restrict buffer, size_t count, const char *__restrict format, va_list arg) #ifdef __GNUC__ __attribute__ ((format(printf, 3, 0))) #endif @@ -154,7 +154,7 @@ __attribute__ ((format(printf, 3, 0))) * Print formatted string into a newly mallocN'd string * and return it. */ -char *BLI_sprintfN(const char *format, ...) +char *BLI_sprintfN(const char *__restrict format, ...) #ifdef __GNUC__ __attribute__ ((format(printf, 1, 2))) __attribute__((warn_unused_result)) @@ -162,7 +162,7 @@ __attribute__((nonnull)) #endif ; -size_t BLI_strescape(char *dst, const char *src, const size_t maxlen) +size_t BLI_strescape(char *__restrict dst, const char *__restrict src, const size_t maxlen) #ifdef __GNUC__ __attribute__((nonnull)) #endif @@ -216,12 +216,12 @@ __attribute__((nonnull)) #endif ; /* time var is global */ -void BLI_ascii_strtolower(char *str, int len) +void BLI_ascii_strtolower(char *str, const size_t len) #ifdef __GNUC__ __attribute__((nonnull)) #endif ; -void BLI_ascii_strtoupper(char *str, int len) +void BLI_ascii_strtoupper(char *str, const size_t len) #ifdef __GNUC__ __attribute__((nonnull)) #endif diff --git a/source/blender/blenlib/BLI_string_utf8.h b/source/blender/blenlib/BLI_string_utf8.h index 56ed4beba53..47980d104fe 100644 --- a/source/blender/blenlib/BLI_string_utf8.h +++ b/source/blender/blenlib/BLI_string_utf8.h @@ -31,16 +31,16 @@ extern "C" { #endif -char *BLI_strncpy_utf8(char *dst, const char *src, size_t maxncpy); -char *BLI_strncat_utf8(char *dst, const char *src, size_t maxncpy); +char *BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy); +char *BLI_strncat_utf8(char *__restrict dst, const char *__restrict src, size_t maxncpy); int BLI_utf8_invalid_byte(const char *str, int length); int BLI_utf8_invalid_strip(char *str, int length); int BLI_str_utf8_size(const char *p); /* warning, can return -1 on bad chars */ /* copied from glib */ unsigned int BLI_str_utf8_as_unicode(const char *p); -unsigned int BLI_str_utf8_as_unicode_and_size(const char *p, size_t *index); -unsigned int BLI_str_utf8_as_unicode_step(const char *p, size_t *index); +unsigned int BLI_str_utf8_as_unicode_and_size(const char *__restrict p, size_t *__restrict index); +unsigned int BLI_str_utf8_as_unicode_step(const char *__restrict p, size_t *__restrict index); size_t BLI_str_utf8_from_unicode(unsigned int c, char *outbuf); char *BLI_str_find_prev_char_utf8(const char *str, const char *p); @@ -50,8 +50,8 @@ char *BLI_str_prev_char_utf8(const char *p); /* wchar_t functions, copied from blenders own font.c originally */ size_t BLI_wstrlen_utf8(const wchar_t *src); size_t BLI_strlen_utf8(const char *strc); -size_t BLI_strncpy_wchar_as_utf8(char *dst, const wchar_t *src, const size_t maxcpy); -size_t BLI_strncpy_wchar_from_utf8(wchar_t *dst, const char *src, const size_t maxcpy); +size_t BLI_strncpy_wchar_as_utf8(char *__restrict dst, const wchar_t *__restrict src, const size_t maxcpy); +size_t BLI_strncpy_wchar_from_utf8(wchar_t *__restrict dst, const char *__restrict src, const size_t maxcpy); #define BLI_UTF8_MAX 6 #define BLI_UTF8_ERR ((unsigned int)-1) diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h index 29097a4c6c3..47c2256c1e1 100644 --- a/source/blender/blenlib/BLI_utildefines.h +++ b/source/blender/blenlib/BLI_utildefines.h @@ -128,6 +128,10 @@ #endif #endif +/* can be used in simple macros */ +#define CHECK_TYPE_INLINE(val, type) \ + ((void)(((type *)0) != (val))) + #ifndef SWAP # define SWAP(type, a, b) { \ type sw_ap; \ @@ -189,6 +193,11 @@ *(v1 + 1) = *(v2 + 1) + *(v3 + 1) * (fac); \ *(v1 + 2) = *(v2 + 2) + *(v3 + 2) * (fac); \ } (void)0 +#define VECMADD(v1, v2, v3, v4) { \ + *(v1) = *(v2) + *(v3) * (*(v4)); \ + *(v1 + 1) = *(v2 + 1) + *(v3 + 1) * (*(v4 + 1)); \ + *(v1 + 2) = *(v2 + 2) + *(v3 + 2) * (*(v4 + 2)); \ +} (void)0 #define VECSUBFAC(v1, v2, v3, fac) { \ *(v1) = *(v2) - *(v3) * (fac); \ *(v1 + 1) = *(v2 + 1) - *(v3 + 1) * (fac); \ @@ -326,4 +335,4 @@ # define UNLIKELY(x) (x) #endif -#endif // __BLI_UTILDEFINES_H__ +#endif /* __BLI_UTILDEFINES_H__ */ diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index eef0a72d3b2..3aa0ffc3eaa 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -79,6 +79,7 @@ set(SRC intern/noise.c intern/path_util.c intern/pbvh.c + intern/quadric.c intern/rand.c intern/rct.c intern/scanfill.c @@ -91,8 +92,8 @@ set(SRC intern/threads.c intern/time.c intern/uvproject.c - intern/voxel.c intern/voronoi.c + intern/voxel.c intern/winstuff.c BLI_args.h @@ -136,6 +137,7 @@ set(SRC BLI_noise.h BLI_path_util.h BLI_pbvh.h + BLI_quadric.h BLI_rand.h BLI_rect.h BLI_scanfill.h diff --git a/source/blender/blenlib/PIL_time.h b/source/blender/blenlib/PIL_time.h index 288d2fe78e5..b8f895c5c82 100644 --- a/source/blender/blenlib/PIL_time.h +++ b/source/blender/blenlib/PIL_time.h @@ -30,7 +30,6 @@ * \brief Platform independent time functions. */ - #ifndef __PIL_TIME_H__ #define __PIL_TIME_H__ @@ -61,20 +60,24 @@ void PIL_sleep_ms(int ms); double _timeit_##var = PIL_check_seconds_timer(); \ printf("time start (" #var "): " AT "\n"); \ fflush(stdout); \ - { (void)0 \ - + { (void)0 #define TIMEIT_VALUE(var) (float)(PIL_check_seconds_timer() - _timeit_##var) +#define TIMEIT_VALUE_PRINT(var) \ + { \ + printf("time update(" #var "): %.6f" " " AT "\n", TIMEIT_VALUE(var));\ + fflush(stdout); \ + } (void)0 #define TIMEIT_END(var) \ } \ - printf("time end (" #var "): %.6f" " " AT "\n", TIMEIT_VALUE(var)); \ + printf("time end (" #var "): %.6f" " " AT "\n", TIMEIT_VALUE(var)); \ fflush(stdout); \ -} (void)0 \ +} (void)0 #ifdef __cplusplus } #endif -#endif /* !__PIL_TIME_H__ */ +#endif /* !__PIL_TIME_H__ */ diff --git a/source/blender/blenlib/intern/BLI_heap.c b/source/blender/blenlib/intern/BLI_heap.c index ee7d93ea1a9..5e0762a5d68 100644 --- a/source/blender/blenlib/intern/BLI_heap.c +++ b/source/blender/blenlib/intern/BLI_heap.c @@ -67,16 +67,22 @@ struct Heap { /***/ -Heap *BLI_heap_new(void) +/* use when the size of the heap is known in advance */ +Heap *BLI_heap_new_ex(unsigned int tot_reserve) { Heap *heap = (Heap *)MEM_callocN(sizeof(Heap), __func__); - heap->bufsize = 1; - heap->tree = (HeapNode **)MEM_mallocN(sizeof(HeapNode *), "BLIHeapTree"); + heap->bufsize = tot_reserve; + heap->tree = (HeapNode **)MEM_mallocN(tot_reserve * sizeof(HeapNode *), "BLIHeapTree"); heap->arena = BLI_memarena_new(1 << 16, "heap arena"); return heap; } +Heap *BLI_heap_new(void) +{ + return BLI_heap_new_ex(1); +} + void BLI_heap_free(Heap *heap, HeapFreeFP ptrfreefp) { int i; diff --git a/source/blender/blenlib/intern/BLI_kdopbvh.c b/source/blender/blenlib/intern/BLI_kdopbvh.c index a86783f3450..46b0cfeaaac 100644 --- a/source/blender/blenlib/intern/BLI_kdopbvh.c +++ b/source/blender/blenlib/intern/BLI_kdopbvh.c @@ -921,7 +921,7 @@ void BLI_bvhtree_balance(BVHTree *tree) /* bvhtree_info(tree); */ } -int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints) +int BLI_bvhtree_insert(BVHTree *tree, int index, const float co[3], int numpoints) { int i; BVHNode *node = NULL; @@ -952,7 +952,7 @@ int BLI_bvhtree_insert(BVHTree *tree, int index, const float *co, int numpoints) /* call before BLI_bvhtree_update_tree() */ -int BLI_bvhtree_update_node(BVHTree *tree, int index, const float *co, const float *co_moving, int numpoints) +int BLI_bvhtree_update_node(BVHTree *tree, int index, const float co[3], const float co_moving[3], int numpoints) { int i; BVHNode *node = NULL; @@ -1346,7 +1346,7 @@ int BLI_bvhtree_find_nearest(BVHTree *tree, const float co[3], BVHTreeNearest *n /* Determines the distance that the ray must travel to hit the bounding volume of the given node */ -static float ray_nearest_hit(BVHRayCastData *data, const float *bv) +static float ray_nearest_hit(BVHRayCastData *data, const float bv[6]) { int i; @@ -1524,7 +1524,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree, const float co[3], const float dir[3], f return data.hit.index; } -float BLI_bvhtree_bb_raycast(const float *bv, const float light_start[3], const float light_end[3], float pos[3]) +float BLI_bvhtree_bb_raycast(const float bv[6], const float light_start[3], const float light_end[3], float pos[3]) { BVHRayCastData data; float dist = 0.0; diff --git a/source/blender/blenlib/intern/BLI_kdtree.c b/source/blender/blenlib/intern/BLI_kdtree.c index 19985c56b84..900580317f2 100644 --- a/source/blender/blenlib/intern/BLI_kdtree.c +++ b/source/blender/blenlib/intern/BLI_kdtree.c @@ -132,7 +132,7 @@ void BLI_kdtree_balance(KDTree *tree) tree->root = kdtree_balance(tree->nodes, tree->totnode, 0); } -static float squared_distance(const float v2[3], const float v1[3], const float *UNUSED(n1), const float *n2) +static float squared_distance(const float v2[3], const float v1[3], const float UNUSED(n1[3]), const float n2[3]) { float d[3], dist; @@ -152,7 +152,7 @@ static float squared_distance(const float v2[3], const float v1[3], const float return dist; } -int BLI_kdtree_find_nearest(KDTree *tree, float *co, float *nor, KDTreeNearest *nearest) +int BLI_kdtree_find_nearest(KDTree *tree, const float co[3], const float nor[3], KDTreeNearest *nearest) { KDTreeNode *root, *node, *min_node; KDTreeNode **stack, *defaultstack[100]; diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c index d58ccbbd48e..4fb48d19239 100644 --- a/source/blender/blenlib/intern/edgehash.c +++ b/source/blender/blenlib/intern/edgehash.c @@ -108,7 +108,7 @@ void BLI_edgehash_insert(EdgeHash *eh, unsigned int v0, unsigned int v1, void *v eh->buckets[hash] = e; if (++eh->nentries > eh->nbuckets * 3) { - EdgeEntry *e, **old = eh->buckets; + EdgeEntry **old = eh->buckets; int i, nold = eh->nbuckets; eh->nbuckets = _ehash_hashsizes[++eh->cursize]; diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index 1df904f617a..883cdfde426 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -140,6 +140,8 @@ char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r) } else break; } + + gzclose(gzfile); if (size == 0) { MEM_freeN(mem); diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c index 85239270541..daedd39d693 100644 --- a/source/blender/blenlib/intern/freetypefont.c +++ b/source/blender/blenlib/intern/freetypefont.c @@ -33,8 +33,8 @@ */ -#ifdef WIN32 -#pragma warning (disable:4244) +#ifdef _MSC_VER +# pragma warning (disable:4244) #endif #include <ft2build.h> diff --git a/source/blender/blenlib/intern/math_base_inline.c b/source/blender/blenlib/intern/math_base_inline.c index 97fc431d8fa..21ecfccf9d9 100644 --- a/source/blender/blenlib/intern/math_base_inline.c +++ b/source/blender/blenlib/intern/math_base_inline.c @@ -59,34 +59,34 @@ MINLINE float saacos(float fac) { if (fac <= -1.0f) return (float)M_PI; else if (fac >= 1.0f) return 0.0; - else return (float)acos(fac); + else return acosf(fac); } MINLINE float saasin(float fac) { if (fac <= -1.0f) return (float)-M_PI / 2.0f; else if (fac >= 1.0f) return (float)M_PI / 2.0f; - else return (float)asin(fac); + else return asinf(fac); } MINLINE float sasqrt(float fac) { if (fac <= 0.0f) return 0.0f; - return (float)sqrt(fac); + return sqrtf(fac); } MINLINE float saacosf(float fac) { if (fac <= -1.0f) return (float)M_PI; else if (fac >= 1.0f) return 0.0f; - else return (float)acosf(fac); + else return acosf(fac); } MINLINE float saasinf(float fac) { if (fac <= -1.0f) return (float)-M_PI / 2.0f; else if (fac >= 1.0f) return (float)M_PI / 2.0f; - else return (float)asinf(fac); + else return asinf(fac); } MINLINE float sasqrtf(float fac) diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 2cfe999e032..191b0e16025 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -121,6 +121,13 @@ MINLINE void copy_v4_v4_char(char r[4], const char a[4]) } /* short */ +MINLINE void zero_v3_int(int r[3]) +{ + r[0] = 0; + r[1] = 0; + r[2] = 0; +} + MINLINE void copy_v2_v2_short(short r[2], const short a[2]) { r[0] = a[0]; @@ -561,6 +568,16 @@ MINLINE float len_squared_v3(const float v[3]) return v[0] * v[0] + v[1] * v[1] + v[2] * v[2]; } +MINLINE float len_manhattan_v2(const float v[2]) +{ + return fabsf(v[0]) + fabsf(v[1]); +} + +MINLINE float len_manhattan_v3(const float v[3]) +{ + return fabsf(v[0]) + fabsf(v[1]) + fabsf(v[2]); +} + MINLINE float len_v2(const float v[2]) { return sqrtf(v[0] * v[0] + v[1] * v[1]); @@ -588,20 +605,36 @@ MINLINE float len_squared_v2v2(const float a[2], const float b[2]) return dot_v2v2(d, d); } -MINLINE float len_v3v3(const float a[3], const float b[3]) +MINLINE float len_squared_v3v3(const float a[3], const float b[3]) { float d[3]; sub_v3_v3v3(d, b, a); - return len_v3(d); + return dot_v3v3(d, d); } -MINLINE float len_squared_v3v3(const float a[3], const float b[3]) +MINLINE float len_manhattan_v2v2(const float a[2], const float b[2]) +{ + float d[2]; + + sub_v2_v2v2(d, b, a); + return len_manhattan_v2(d); +} + +MINLINE float len_manhattan_v3v3(const float a[3], const float b[3]) { float d[3]; sub_v3_v3v3(d, b, a); - return dot_v3v3(d, d); + return len_manhattan_v3(d); +} + +MINLINE float len_v3v3(const float a[3], const float b[3]) +{ + float d[3]; + + sub_v3_v3v3(d, b, a); + return len_v3(d); } MINLINE float normalize_v2_v2(float r[2], const float a[2]) diff --git a/source/blender/blenlib/intern/noise.c b/source/blender/blenlib/intern/noise.c index 792bf929182..124624ca137 100644 --- a/source/blender/blenlib/intern/noise.c +++ b/source/blender/blenlib/intern/noise.c @@ -31,9 +31,9 @@ */ -#ifdef _WIN32 -#pragma warning (disable : 4244) // "conversion from double to float" -#pragma warning (disable : 4305) // "truncation from const double to float" +#ifdef _MSC_VER +# pragma warning (disable:4244) /* "conversion from double to float" */ +# pragma warning (disable:4305) /* "truncation from const double to float" */ #endif #include <math.h> diff --git a/source/blender/blenlib/intern/quadric.c b/source/blender/blenlib/intern/quadric.c new file mode 100644 index 00000000000..1c04beacbfb --- /dev/null +++ b/source/blender/blenlib/intern/quadric.c @@ -0,0 +1,131 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. + * All rights reserved. + * + * Contributor(s): Laurence Bourn, Campbell Barton + * + * ***** END GPL LICENSE BLOCK ***** + */ + +/** \file blender/blenlib/intern/quadric.c + * \ingroup bli + * + * \note This isn't fully complete, + * possible there are other useful functions to add here. + * + * \note try to follow BLI_math naming convention here. + */ + +//#include <string.h> + +#include "BLI_math.h" +#include "BLI_quadric.h" /* own include */ + + +#define QUADRIC_FLT_TOT (sizeof(Quadric) / sizeof(float)) + +void BLI_quadric_from_v3_dist(Quadric *q, const float v[3], const float offset) +{ + q->a2 = v[0] * v[0]; + q->b2 = v[1] * v[1]; + q->c2 = v[2] * v[2]; + + q->ab = v[0] * v[1]; + q->ac = v[0] * v[2]; + q->bc = v[1] * v[2]; + + q->ad = v[0] * offset; + q->bd = v[1] * offset; + q->cd = v[2] * offset; + + q->d2 = offset * offset; +} + +void BLI_quadric_to_tensor_m3(const Quadric *q, float m[3][3]) +{ + m[0][0] = q->a2; + m[0][1] = q->ab; + m[0][2] = q->ac; + + m[1][0] = q->ab; + m[1][1] = q->b2; + m[1][2] = q->bc; + + m[2][0] = q->ac; + m[2][1] = q->bc; + m[2][2] = q->c2; +} + +void BLI_quadric_to_vector_v3(const Quadric *q, float v[3]) +{ + v[0] = q->ad; + v[1] = q->bd; + v[2] = q->cd; +} + +void BLI_quadric_clear(Quadric *q) +{ + memset(q, 0, sizeof(*q)); +} + +void BLI_quadric_add_qu_qu(Quadric *a, const Quadric *b) +{ + add_vn_vn((float *)a, (float *)b, QUADRIC_FLT_TOT); +} + +void BLI_quadric_add_qu_ququ(Quadric *r, const Quadric *a, const Quadric *b) +{ + add_vn_vnvn((float *)r, (const float *)a, (const float *)b, QUADRIC_FLT_TOT); +} + +void BLI_quadric_mul(Quadric *a, const float scalar) +{ + mul_vn_fl((float *)a, QUADRIC_FLT_TOT, scalar); +} + +float BLI_quadric_evaluate(const Quadric *q, const float v[3]) +{ + return (v[0] * v[0] * q->a2 + 2.0f * v[0] * v[1] * q->ab + 2.0f * v[0] * v[2] * q->ac + 2.0f * v[0] * q->ad + + v[1] * v[1] * q->b2 + 2.0f * v[1] * v[2] * q->bc + 2.0f * v[1] * q->bd + + v[2] * v[2] * q->c2 + 2.0f * v[2] * q->cd + + q->d2); +} + +int BLI_quadric_optimize(const Quadric *q, float v[3]) +{ + float m[3][3]; + float det; + + BLI_quadric_to_tensor_m3(q, m); + det = determinant_m3(m[0][0], m[0][1], m[0][2], + m[1][0], m[1][1], m[1][2], + m[2][0], m[2][1], m[2][2]); + + if (det != 0.0f) { + invert_m3(m); + BLI_quadric_to_vector_v3(q, v); + mul_m3_v3(m, v); + negate_v3(v); + + return TRUE; + } + else { + return FALSE; + } +} diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c index 4435e9ce09c..3c22d73d113 100644 --- a/source/blender/blenlib/intern/rand.c +++ b/source/blender/blenlib/intern/rand.c @@ -40,7 +40,7 @@ #include "BLI_threads.h" #include "BLI_rand.h" -#if defined(WIN32) && !defined(FREE_WINDOWS) +#ifdef _MSC_VER typedef unsigned __int64 r_uint64; #define MULTIPLIER 0x5DEECE66Di64 diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c index cab383b60f3..2e2619df24e 100644 --- a/source/blender/blenlib/intern/rct.c +++ b/source/blender/blenlib/intern/rct.c @@ -102,7 +102,19 @@ int BLI_rctf_isect_pt_v(const rctf *rect, const float xy[2]) } /* based closely on 'isect_line_line_v2_int', but in modified so corner cases are treated as intersections */ -static int isect_segments(const int v1[2], const int v2[2], const int v3[2], const int v4[2]) +static int isect_segments_i(const int v1[2], const int v2[2], const int v3[2], const int v4[2]) +{ + const double div = (double)((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0])); + if (div == 0.0f) { + return 1; /* co-linear */ + } + else { + const double labda = (double)((v1[1] - v3[1]) * (v4[0] - v3[0]) - (v1[0] - v3[0]) * (v4[1] - v3[1])) / div; + const double mu = (double)((v1[1] - v3[1]) * (v2[0] - v1[0]) - (v1[0] - v3[0]) * (v2[1] - v1[1])) / div; + return (labda >= 0.0f && labda <= 1.0f && mu >= 0.0f && mu <= 1.0f); + } +} +static int isect_segments_fl(const float v1[2], const float v2[2], const float v3[2], const float v4[2]) { const double div = (double)((v2[0] - v1[0]) * (v4[1] - v3[1]) - (v2[1] - v1[1]) * (v4[0] - v3[0])); if (div == 0.0f) { @@ -134,14 +146,49 @@ int BLI_rcti_isect_segment(const rcti *rect, const int s1[2], const int s2[2]) /* diagonal: [/] */ tvec1[0] = rect->xmin; tvec1[1] = rect->ymin; tvec2[0] = rect->xmin; tvec2[1] = rect->ymax; - if (isect_segments(s1, s2, tvec1, tvec2)) { + if (isect_segments_i(s1, s2, tvec1, tvec2)) { + return 1; + } + + /* diagonal: [\] */ + tvec1[0] = rect->xmin; tvec1[1] = rect->ymax; + tvec2[0] = rect->xmax; tvec2[1] = rect->ymin; + if (isect_segments_i(s1, s2, tvec1, tvec2)) { + return 1; + } + + /* no intersection */ + return 0; + } +} + +int BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[2]) +{ + /* first do outside-bounds check for both points of the segment */ + if (s1[0] < rect->xmin && s2[0] < rect->xmin) return 0; + if (s1[0] > rect->xmax && s2[0] > rect->xmax) return 0; + if (s1[1] < rect->ymin && s2[1] < rect->ymin) return 0; + if (s1[1] > rect->ymax && s2[1] > rect->ymax) return 0; + + /* if either points intersect then we definetly intersect */ + if (BLI_rctf_isect_pt_v(rect, s1) || BLI_rctf_isect_pt_v(rect, s2)) { + return 1; + } + else { + /* both points are outside but may insersect the rect */ + float tvec1[2]; + float tvec2[2]; + /* diagonal: [/] */ + tvec1[0] = rect->xmin; tvec1[1] = rect->ymin; + tvec2[0] = rect->xmin; tvec2[1] = rect->ymax; + if (isect_segments_fl(s1, s2, tvec1, tvec2)) { return 1; } /* diagonal: [\] */ tvec1[0] = rect->xmin; tvec1[1] = rect->ymax; tvec2[0] = rect->xmax; tvec2[1] = rect->ymin; - if (isect_segments(s1, s2, tvec1, tvec2)) { + if (isect_segments_fl(s1, s2, tvec1, tvec2)) { return 1; } diff --git a/source/blender/blenlib/intern/string.c b/source/blender/blenlib/intern/string.c index 8501db7c8b8..4b64a650b52 100644 --- a/source/blender/blenlib/intern/string.c +++ b/source/blender/blenlib/intern/string.c @@ -296,11 +296,12 @@ char *BLI_strcasestr(const char *s, const char *find) int BLI_strcasecmp(const char *s1, const char *s2) { - int i; + register int i; + register char c1, c2; for (i = 0;; i++) { - char c1 = tolower(s1[i]); - char c2 = tolower(s2[i]); + c1 = tolower(s1[i]); + c2 = tolower(s2[i]); if (c1 < c2) { return -1; @@ -318,11 +319,12 @@ int BLI_strcasecmp(const char *s1, const char *s2) int BLI_strncasecmp(const char *s1, const char *s2, size_t len) { - int i; + register size_t i; + register char c1, c2; for (i = 0; i < len; i++) { - char c1 = tolower(s1[i]); - char c2 = tolower(s2[i]); + c1 = tolower(s1[i]); + c2 = tolower(s2[i]); if (c1 < c2) { return -1; @@ -341,15 +343,16 @@ int BLI_strncasecmp(const char *s1, const char *s2, size_t len) /* natural string compare, keeping numbers in order */ int BLI_natstrcmp(const char *s1, const char *s2) { - int d1 = 0, d2 = 0; + register int d1 = 0, d2 = 0; + register char c1, c2; /* if both chars are numeric, to a strtol(). * then increase string deltas as long they are * numeric, else do a tolower and char compare */ while (1) { - char c1 = tolower(s1[d1]); - char c2 = tolower(s2[d2]); + c1 = tolower(s1[d1]); + c2 = tolower(s2[d2]); if (isdigit(c1) && isdigit(c2) ) { int val1, val2; @@ -419,18 +422,18 @@ size_t BLI_strnlen(const char *str, size_t maxlen) return end ? (size_t) (end - str) : maxlen; } -void BLI_ascii_strtolower(char *str, int len) +void BLI_ascii_strtolower(char *str, const size_t len) { - int i; + size_t i; for (i = 0; i < len; i++) if (str[i] >= 'A' && str[i] <= 'Z') str[i] += 'a' - 'A'; } -void BLI_ascii_strtoupper(char *str, int len) +void BLI_ascii_strtoupper(char *str, const size_t len) { - int i; + size_t i; for (i = 0; i < len; i++) if (str[i] >= 'a' && str[i] <= 'z') |