Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r--source/blender/blenlib/BLI_bitmap.h3
-rw-r--r--source/blender/blenlib/BLI_math_geom.h5
-rw-r--r--source/blender/blenlib/BLI_path_util.h1
-rw-r--r--source/blender/blenlib/BLI_rect.h4
-rw-r--r--source/blender/blenlib/BLI_utildefines.h8
-rw-r--r--source/blender/blenlib/intern/BLI_ghash_utils.c2
-rw-r--r--source/blender/blenlib/intern/DLRB_tree.c2
-rw-r--r--source/blender/blenlib/intern/array_store.c4
-rw-r--r--source/blender/blenlib/intern/astar.c6
-rw-r--r--source/blender/blenlib/intern/freetypefont.c2
-rw-r--r--source/blender/blenlib/intern/math_geom.c73
-rw-r--r--source/blender/blenlib/intern/math_interp.c2
-rw-r--r--source/blender/blenlib/intern/path_util.c27
-rw-r--r--source/blender/blenlib/intern/rct.c4
-rw-r--r--source/blender/blenlib/intern/storage.c2
-rw-r--r--source/blender/blenlib/intern/string_utils.c8
-rw-r--r--source/blender/blenlib/intern/task.c2
17 files changed, 120 insertions, 35 deletions
diff --git a/source/blender/blenlib/BLI_bitmap.h b/source/blender/blenlib/BLI_bitmap.h
index 82704e95fdd..e8c92d9baff 100644
--- a/source/blender/blenlib/BLI_bitmap.h
+++ b/source/blender/blenlib/BLI_bitmap.h
@@ -49,8 +49,7 @@ typedef unsigned int BLI_bitmap;
#define BLI_BITMAP_SIZE(_tot) \
((size_t)(_BITMAP_NUM_BLOCKS(_tot)) * sizeof(BLI_bitmap))
-/* allocate memory for a bitmap with '_tot' bits; free
- * with MEM_freeN() */
+/* allocate memory for a bitmap with '_tot' bits; free with MEM_freeN() */
#define BLI_BITMAP_NEW(_tot, _alloc_string) \
((BLI_bitmap *)MEM_callocN(BLI_BITMAP_SIZE(_tot), \
_alloc_string))
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h
index b3a95d65752..e4cf4839b45 100644
--- a/source/blender/blenlib/BLI_math_geom.h
+++ b/source/blender/blenlib/BLI_math_geom.h
@@ -186,6 +186,11 @@ void limit_dist_v3(float v1[3], float v2[3], const float dist);
#define ISECT_LINE_LINE_CROSS 2
int isect_seg_seg_v2(const float a1[2], const float a2[2], const float b1[2], const float b2[2]);
+void isect_seg_seg_v3(
+ const float a0[3], const float a1[3],
+ const float b0[3], const float b1[3],
+ float r_a[3], float r_b[3]);
+
int isect_seg_seg_v2_int(const int a1[2], const int a2[2], const int b1[2], const int b2[2]);
int isect_seg_seg_v2_point_ex(
const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float endpoint_bias,
diff --git a/source/blender/blenlib/BLI_path_util.h b/source/blender/blenlib/BLI_path_util.h
index b4329bf81ac..e434e83416b 100644
--- a/source/blender/blenlib/BLI_path_util.h
+++ b/source/blender/blenlib/BLI_path_util.h
@@ -41,6 +41,7 @@ struct ListBase;
void BLI_setenv(const char *env, const char *val) ATTR_NONNULL(1);
void BLI_setenv_if_new(const char *env, const char *val) ATTR_NONNULL(1);
+const char *BLI_getenv(const char *env) ATTR_NONNULL(1);
void BLI_make_file_string(const char *relabase, char *string, const char *dir, const char *file);
void BLI_make_exist(char *dir);
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index 471d875c9af..a6670266643 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -92,8 +92,8 @@ bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int
bool BLI_rctf_isect_segment(const struct rctf *rect, const float s1[2], const float s2[2]);
bool BLI_rcti_isect_circle(const struct rcti *rect, const float xy[2], const float radius);
bool BLI_rctf_isect_circle(const struct rctf *rect, const float xy[2], const float radius);
-bool BLI_rcti_inside_rcti(rcti *rct_a, const rcti *rct_b);
-bool BLI_rctf_inside_rctf(rctf *rct_a, const rctf *rct_b);
+bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b);
+bool BLI_rctf_inside_rctf(const rctf *rct_a, const rctf *rct_b);
void BLI_rcti_union(struct rcti *rcti1, const struct rcti *rcti2);
void BLI_rctf_union(struct rctf *rctf1, const struct rctf *rctf2);
void BLI_rcti_rctf_copy(struct rcti *dst, const struct rctf *src);
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index 3d4b227ffa7..98c27bd053b 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -508,11 +508,11 @@ extern bool BLI_memory_is_zero(const void *arr, const size_t arr_size);
/* Warning-free macros for storing ints in pointers. Use these _only_
* for storing an int in a pointer, not a pointer in an int (64bit)! */
-#define SET_INT_IN_POINTER(i) ((void *)(intptr_t)(i))
-#define GET_INT_FROM_POINTER(i) ((void)0, ((int)(intptr_t)(i)))
+#define POINTER_FROM_INT(i) ((void *)(intptr_t)(i))
+#define POINTER_AS_INT(i) ((void)0, ((int)(intptr_t)(i)))
-#define SET_UINT_IN_POINTER(i) ((void *)(uintptr_t)(i))
-#define GET_UINT_FROM_POINTER(i) ((void)0, ((unsigned int)(uintptr_t)(i)))
+#define POINTER_FROM_UINT(i) ((void *)(uintptr_t)(i))
+#define POINTER_AS_UINT(i) ((void)0, ((unsigned int)(uintptr_t)(i)))
/* Set flag from a single test */
#define SET_FLAG_FROM_TEST(value, test, flag) \
diff --git a/source/blender/blenlib/intern/BLI_ghash_utils.c b/source/blender/blenlib/intern/BLI_ghash_utils.c
index 6554ee7c92f..953ceb3442b 100644
--- a/source/blender/blenlib/intern/BLI_ghash_utils.c
+++ b/source/blender/blenlib/intern/BLI_ghash_utils.c
@@ -126,7 +126,7 @@ uint BLI_ghashutil_inthash_p_murmur(const void *ptr)
uint BLI_ghashutil_inthash_p_simple(const void *ptr)
{
- return GET_UINT_FROM_POINTER(ptr);
+ return POINTER_AS_UINT(ptr);
}
bool BLI_ghashutil_intcmp(const void *a, const void *b)
diff --git a/source/blender/blenlib/intern/DLRB_tree.c b/source/blender/blenlib/intern/DLRB_tree.c
index 6ef77890e95..eb3a79502ae 100644
--- a/source/blender/blenlib/intern/DLRB_tree.c
+++ b/source/blender/blenlib/intern/DLRB_tree.c
@@ -572,7 +572,7 @@ DLRBT_Node *BLI_dlrbTree_add(DLRBT_Tree *tree, DLRBT_Comparator_FP cmp_cb,
node->tree_col = DLRBT_RED;
/* perform BST balancing steps:
- * start from case 1, an trek through the tail-recursive insertion checks
+ * start from case 1, an trek through the tail-recursive insertion checks
*/
insert_check_1(tree, node);
}
diff --git a/source/blender/blenlib/intern/array_store.c b/source/blender/blenlib/intern/array_store.c
index df93dad4c32..153ba3ea0d0 100644
--- a/source/blender/blenlib/intern/array_store.c
+++ b/source/blender/blenlib/intern/array_store.c
@@ -1760,7 +1760,7 @@ bool BLI_array_store_is_valid(
}
GHASH_ITER (gh_iter, chunk_list_map) {
const struct BChunkList *chunk_list = BLI_ghashIterator_getKey(&gh_iter);
- const int users = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter));
+ const int users = POINTER_AS_INT(BLI_ghashIterator_getValue(&gh_iter));
if (!(chunk_list->users == users)) {
ok = false;
goto user_finally;
@@ -1790,7 +1790,7 @@ bool BLI_array_store_is_valid(
GHASH_ITER (gh_iter, chunk_map) {
const struct BChunk *chunk = BLI_ghashIterator_getKey(&gh_iter);
- const int users = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter));
+ const int users = POINTER_AS_INT(BLI_ghashIterator_getValue(&gh_iter));
if (!(chunk->users == users)) {
ok = false;
goto user_finally;
diff --git a/source/blender/blenlib/intern/astar.c b/source/blender/blenlib/intern/astar.c
index 1b57dc5a683..86c1faad096 100644
--- a/source/blender/blenlib/intern/astar.c
+++ b/source/blender/blenlib/intern/astar.c
@@ -228,10 +228,10 @@ bool BLI_astar_graph_solve(
todo_nodes = BLI_heap_new();
BLI_heap_insert(todo_nodes,
f_cost_cb(as_graph, r_solution, NULL, -1, node_index_src, node_index_dst),
- SET_INT_IN_POINTER(node_index_src));
+ POINTER_FROM_INT(node_index_src));
while (!BLI_heap_is_empty(todo_nodes)) {
- const int node_curr_idx = GET_INT_FROM_POINTER(BLI_heap_pop_min(todo_nodes));
+ const int node_curr_idx = POINTER_AS_INT(BLI_heap_pop_min(todo_nodes));
BLI_AStarGNode *node_curr = &as_graph->nodes[node_curr_idx];
LinkData *ld;
@@ -271,7 +271,7 @@ bool BLI_astar_graph_solve(
* no problem. */
BLI_heap_insert(todo_nodes,
f_cost_cb(as_graph, r_solution, link, node_curr_idx, node_next_idx, node_index_dst),
- SET_INT_IN_POINTER(node_next_idx));
+ POINTER_FROM_INT(node_next_idx));
}
}
}
diff --git a/source/blender/blenlib/intern/freetypefont.c b/source/blender/blenlib/intern/freetypefont.c
index c7604b3cd6d..b493b97863c 100644
--- a/source/blender/blenlib/intern/freetypefont.c
+++ b/source/blender/blenlib/intern/freetypefont.c
@@ -99,7 +99,7 @@ static VChar *freetypechar_to_vchar(FT_Face face, FT_ULong charcode, VFontData *
che->index = charcode;
che->width = glyph->advance.x * scale;
- BLI_ghash_insert(vfd->characters, SET_UINT_IN_POINTER(che->index), che);
+ BLI_ghash_insert(vfd->characters, POINTER_FROM_UINT(che->index), che);
/* Start converting the FT data */
onpoints = (int *)MEM_callocN((ftoutline.n_contours) * sizeof(int), "onpoints");
diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c
index 356740b138f..dca9d4204c3 100644
--- a/source/blender/blenlib/intern/math_geom.c
+++ b/source/blender/blenlib/intern/math_geom.c
@@ -911,6 +911,70 @@ int isect_seg_seg_v2(const float v1[2], const float v2[2], const float v3[2], co
return ISECT_LINE_LINE_NONE;
}
+/* Returns a point on each segment that is closest to the other. */
+void isect_seg_seg_v3(
+ const float a0[3], const float a1[3],
+ const float b0[3], const float b1[3],
+ float r_a[3], float r_b[3])
+{
+ float fac_a, fac_b;
+ float a_dir[3], b_dir[3], a0b0[3], crs_ab[3];
+ sub_v3_v3v3(a_dir, a1, a0);
+ sub_v3_v3v3(b_dir, b1, b0);
+ sub_v3_v3v3(a0b0, b0, a0);
+ cross_v3_v3v3(crs_ab, b_dir, a_dir);
+ const float nlen = len_squared_v3(crs_ab);
+
+ if (nlen == 0.0f) {
+ /* Parallel Lines */
+ /* In this case return any point that
+ * is between the closest segments. */
+ float a0b1[3], a1b0[3], len_a, len_b, fac1, fac2;
+ sub_v3_v3v3(a0b1, b1, a0);
+ sub_v3_v3v3(a1b0, b0, a1);
+ len_a = len_squared_v3(a_dir);
+ len_b = len_squared_v3(b_dir);
+
+ if (len_a) {
+ fac1 = dot_v3v3(a0b0, a_dir);
+ fac2 = dot_v3v3(a0b1, a_dir);
+ CLAMP(fac1, 0.0f, len_a);
+ CLAMP(fac2, 0.0f, len_a);
+ fac_a = (fac1 + fac2) / (2 * len_a);
+ }
+ else {
+ fac_a = 0.0f;
+ }
+
+ if (len_b) {
+ fac1 = -dot_v3v3(a0b0, b_dir);
+ fac2 = -dot_v3v3(a1b0, b_dir);
+ CLAMP(fac1, 0.0f, len_b);
+ CLAMP(fac2, 0.0f, len_b);
+ fac_b = (fac1 + fac2) / (2 * len_b);
+ }
+ else {
+ fac_b = 0.0f;
+ }
+ }
+ else {
+ float c[3], cray[3];
+ sub_v3_v3v3(c, crs_ab, a0b0);
+
+ cross_v3_v3v3(cray, c, b_dir);
+ fac_a = dot_v3v3(cray, crs_ab) / nlen;
+
+ cross_v3_v3v3(cray, c, a_dir);
+ fac_b = dot_v3v3(cray, crs_ab) / nlen;
+
+ CLAMP(fac_a, 0.0f, 1.0f);
+ CLAMP(fac_b, 0.0f, 1.0f);
+ }
+
+ madd_v3_v3v3fl(r_a, a0, a_dir, fac_a);
+ madd_v3_v3v3fl(r_b, b0, b_dir, fac_b);
+}
+
/**
* Get intersection point of two 2D segments.
*
@@ -2618,8 +2682,9 @@ float line_plane_factor_v3(const float plane_co[3], const float plane_no[3],
return (dot != 0.0f) ? -dot_v3v3(plane_no, h) / dot : 0.0f;
}
-/** Ensure the distance between these points is no greater than 'dist'.
- * If it is, scale then both into the center.
+/**
+ * Ensure the distance between these points is no greater than 'dist'.
+ * If it is, scale then both into the center.
*/
void limit_dist_v3(float v1[3], float v2[3], const float dist)
{
@@ -3180,8 +3245,8 @@ void transform_point_by_tri_v3(
{
/* this works by moving the source triangle so its normal is pointing on the Z
* axis where its barycentric weights can be calculated in 2D and its Z offset can
- * be re-applied. The weights are applied directly to the targets 3D points and the
- * z-depth is used to scale the targets normal as an offset.
+ * be re-applied. The weights are applied directly to the targets 3D points and the
+ * z-depth is used to scale the targets normal as an offset.
* This saves transforming the target into its Z-Up orientation and back (which could also work) */
float no_tar[3], no_src[3];
float mat_src[3][3];
diff --git a/source/blender/blenlib/intern/math_interp.c b/source/blender/blenlib/intern/math_interp.c
index 8c361673715..b93a7f55821 100644
--- a/source/blender/blenlib/intern/math_interp.c
+++ b/source/blender/blenlib/intern/math_interp.c
@@ -44,7 +44,7 @@
***************************************************************************/
/* BICUBIC Interpolation functions
- * More info: http://wiki.blender.org/index.php/User:Damiles#Bicubic_pixel_interpolation
+ * More info: http://wiki.blender.org/index.php/User:Damiles#Bicubic_pixel_interpolation
* function assumes out to be zero'ed, only does RGBA */
static float P(float k)
diff --git a/source/blender/blenlib/intern/path_util.c b/source/blender/blenlib/intern/path_util.c
index 6272f2109d2..84c932db1c7 100644
--- a/source/blender/blenlib/intern/path_util.c
+++ b/source/blender/blenlib/intern/path_util.c
@@ -1095,7 +1095,7 @@ bool BLI_path_program_extensions_add_win32(char *name, const size_t maxlen)
if ((type == 0) || S_ISDIR(type)) {
/* typically 3-5, ".EXE", ".BAT"... etc */
const int ext_max = 12;
- const char *ext = getenv("PATHEXT");
+ const char *ext = BLI_getenv("PATHEXT");
if (ext) {
const int name_len = strlen(name);
char *filename = alloca(name_len + ext_max);
@@ -1152,7 +1152,7 @@ bool BLI_path_program_search(
const char separator = ':';
#endif
- path = getenv("PATH");
+ path = BLI_getenv("PATH");
if (path) {
char filename[FILE_MAX];
const char *temp;
@@ -1160,12 +1160,12 @@ bool BLI_path_program_search(
do {
temp = strchr(path, separator);
if (temp) {
- strncpy(filename, path, temp - path);
+ memcpy(filename, path, temp - path);
filename[temp - path] = 0;
path = temp + 1;
}
else {
- strncpy(filename, path, sizeof(filename));
+ BLI_strncpy(filename, path, sizeof(filename));
}
BLI_path_append(filename, maxlen, name);
@@ -1220,11 +1220,28 @@ void BLI_setenv(const char *env, const char *val)
*/
void BLI_setenv_if_new(const char *env, const char *val)
{
- if (getenv(env) == NULL)
+ if (BLI_getenv(env) == NULL)
BLI_setenv(env, val);
}
/**
+* get an env var, result has to be used immediately
+*/
+const char *BLI_getenv(const char *env)
+{
+#ifdef _MSC_VER
+ static char buffer[32767]; /* 32767 is the total size of the environment block on windows*/
+ if (GetEnvironmentVariableA(env, buffer, sizeof(buffer)))
+ return buffer;
+ else
+ return NULL;
+#else
+ return getenv(env);
+#endif
+}
+
+
+/**
* Strips off nonexistent (or non-accessible) subdirectories from the end of *dir, leaving the path of
* the lowest-level directory that does exist and we can read.
*/
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index 764b12431d0..e0d92e8a19f 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -161,14 +161,14 @@ float BLI_rctf_length_y(const rctf *rect, const float y)
/**
* is \a rct_b inside \a rct_a
*/
-bool BLI_rctf_inside_rctf(rctf *rct_a, const rctf *rct_b)
+bool BLI_rctf_inside_rctf(const rctf *rct_a, const rctf *rct_b)
{
return ((rct_a->xmin <= rct_b->xmin) &&
(rct_a->xmax >= rct_b->xmax) &&
(rct_a->ymin <= rct_b->ymin) &&
(rct_a->ymax >= rct_b->ymax));
}
-bool BLI_rcti_inside_rcti(rcti *rct_a, const rcti *rct_b)
+bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b)
{
return ((rct_a->xmin <= rct_b->xmin) &&
(rct_a->xmax >= rct_b->xmax) &&
diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c
index f69b35ce5a9..cfcc2bc4390 100644
--- a/source/blender/blenlib/intern/storage.c
+++ b/source/blender/blenlib/intern/storage.c
@@ -85,7 +85,7 @@
*/
char *BLI_current_working_dir(char *dir, const size_t maxncpy)
{
- const char *pwd = getenv("PWD");
+ const char *pwd = BLI_getenv("PWD");
if (pwd) {
size_t srclen = BLI_strnlen(pwd, maxncpy);
if (srclen != maxncpy) {
diff --git a/source/blender/blenlib/intern/string_utils.c b/source/blender/blenlib/intern/string_utils.c
index de24fc4d1f5..296086ed652 100644
--- a/source/blender/blenlib/intern/string_utils.c
+++ b/source/blender/blenlib/intern/string_utils.c
@@ -326,15 +326,13 @@ bool BLI_uniquename_cb(
# define GIVE_STRADDR(data, offset) ( ((char *)data) + offset)
#endif
-/* Generic function to set a unique name. It is only designed to be used in situations
+/**
+ * Generic function to set a unique name. It is only designed to be used in situations
* where the name is part of the struct.
*
* For places where this is used, see constraint.c for example...
*
- * name_offs: should be calculated using offsetof(structname, membername) macro from stddef.h
- * len: maximum length of string (to prevent overflows, etc.)
- * defname: the name that should be used by default if none is specified already
- * delim: the character which acts as a delimiter between parts of the name
+ * \param name_offs: should be calculated using offsetof(structname, membername) macro from stddef.h
*/
static bool uniquename_find_dupe(ListBase *list, void *vlink, const char *name, int name_offs)
{
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index 5d3c6b35ac1..2bb5d5397a9 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -116,7 +116,7 @@ typedef struct Task {
* At this moment task queue owns the memory.
*
* - When task is done and task_free() is called the memory will be put to the
- * pool which corresponds to a thread which handled the task.
+ * pool which corresponds to a thread which handled the task.
*/
typedef struct TaskMemPool {
/* Number of pre-allocated tasks in the pool. */