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_math_matrix.h5
-rw-r--r--source/blender/blenlib/BLI_math_vector.h6
-rw-r--r--source/blender/blenlib/BLI_rect.h2
-rw-r--r--source/blender/blenlib/BLI_sys_types.h2
-rw-r--r--source/blender/blenlib/BLI_task.h4
-rw-r--r--source/blender/blenlib/BLI_utildefines.h9
-rw-r--r--source/blender/blenlib/BLI_voronoi.h2
-rw-r--r--source/blender/blenlib/intern/BLI_ghash.c2
-rw-r--r--source/blender/blenlib/intern/BLI_mempool.c2
-rw-r--r--source/blender/blenlib/intern/convexhull2d.c4
-rw-r--r--source/blender/blenlib/intern/edgehash.c2
-rw-r--r--source/blender/blenlib/intern/math_matrix.c22
-rw-r--r--source/blender/blenlib/intern/math_rotation.c2
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c32
-rw-r--r--source/blender/blenlib/intern/rct.c26
-rw-r--r--source/blender/blenlib/intern/task.c2
-rw-r--r--source/blender/blenlib/intern/threads.c4
-rw-r--r--source/blender/blenlib/intern/voronoi.c10
18 files changed, 119 insertions, 19 deletions
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index b04af44156f..c83494790a8 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -60,6 +60,9 @@ void copy_m4_m4(float R[4][4], float A[4][4]);
void copy_m3_m4(float R[3][3], float A[4][4]);
void copy_m4_m3(float R[4][4], float A[3][3]);
+/* double->float */
+void copy_m3_m3d(float R[3][3], double A[3][3]);
+
void swap_m3m3(float A[3][3], float B[3][3]);
void swap_m4m4(float A[4][4], float B[4][4]);
@@ -160,6 +163,8 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A[4][4]);
void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon);
void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon);
+bool has_zero_axis_m4(float matrix[4][4]);
+
/****************************** Transformations ******************************/
void scale_m3_fl(float R[3][3], float scale);
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 675ba88fc72..3ff81e478c9 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -82,6 +82,9 @@ MINLINE void copy_v4fl_v4db(float r[4], const double a[4]);
MINLINE void copy_v2db_v2fl(double r[2], const float a[2]);
MINLINE void copy_v3db_v3fl(double r[3], const float a[3]);
MINLINE void copy_v4db_v4fl(double r[4], const float a[4]);
+/* float args -> vec */
+MINLINE void copy_v3_fl3(float v[3], float x, float y, float z);
+MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w);
/********************************* Arithmetic ********************************/
@@ -117,6 +120,9 @@ MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]) ATTR_WA
MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT;
MINLINE float dot_m3_v3_row_y(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT;
MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT;
+MINLINE float dot_m4_v3_row_x(float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT;
+MINLINE float dot_m4_v3_row_y(float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT;
+MINLINE float dot_m4_v3_row_z(float M[4][4], const float a[3]) ATTR_WARN_UNUSED_RESULT;
MINLINE void madd_v3_v3fl(float r[3], const float a[3], float f);
MINLINE void madd_v3_v3v3(float r[3], const float a[3], const float b[3]);
diff --git a/source/blender/blenlib/BLI_rect.h b/source/blender/blenlib/BLI_rect.h
index f8b9088fe3d..0fee9264191 100644
--- a/source/blender/blenlib/BLI_rect.h
+++ b/source/blender/blenlib/BLI_rect.h
@@ -74,6 +74,8 @@ bool BLI_rctf_isect_pt(const struct rctf *rect, const float x, const float y);
bool BLI_rctf_isect_pt_v(const struct rctf *rect, const float xy[2]);
bool BLI_rcti_isect_segment(const struct rcti *rect, const int s1[2], const int s2[2]);
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);
void BLI_rcti_union(struct rcti *rcti1, const struct rcti *rcti2);
diff --git a/source/blender/blenlib/BLI_sys_types.h b/source/blender/blenlib/BLI_sys_types.h
index e544006fd69..0b7f07e3d36 100644
--- a/source/blender/blenlib/BLI_sys_types.h
+++ b/source/blender/blenlib/BLI_sys_types.h
@@ -116,7 +116,7 @@ typedef uint64_t u_int64_t;
* use (bool, true / false) instead */
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
-#else
+#elif !defined(__bool_true_false_are_defined) && !defined(__BOOL_DEFINED)
# ifndef HAVE__BOOL
# ifdef __cplusplus
typedef bool _BLI_Bool;
diff --git a/source/blender/blenlib/BLI_task.h b/source/blender/blenlib/BLI_task.h
index f57d42858c7..c9cbaf997fb 100644
--- a/source/blender/blenlib/BLI_task.h
+++ b/source/blender/blenlib/BLI_task.h
@@ -88,8 +88,8 @@ void BLI_task_pool_cancel(TaskPool *pool);
/* stop all worker threads */
void BLI_task_pool_stop(TaskPool *pool);
-/* for worker threads, test if cancelled */
-bool BLI_task_pool_cancelled(TaskPool *pool);
+/* for worker threads, test if canceled */
+bool BLI_task_pool_canceled(TaskPool *pool);
/* optional userdata pointer to pass along to run function */
void *BLI_task_pool_userdata(TaskPool *pool);
diff --git a/source/blender/blenlib/BLI_utildefines.h b/source/blender/blenlib/BLI_utildefines.h
index c3a3c035ed3..9bf720c03ea 100644
--- a/source/blender/blenlib/BLI_utildefines.h
+++ b/source/blender/blenlib/BLI_utildefines.h
@@ -240,8 +240,13 @@
#define CLAMPIS(a, b, c) ((a) < (b) ? (b) : (a) > (c) ? (c) : (a))
-#define IS_EQ(a, b) ((fabs((double)(a) - (b)) >= (double) FLT_EPSILON) ? 0 : 1)
-#define IS_EQF(a, b) ((fabsf((float)(a) - (b)) >= (float) FLT_EPSILON) ? 0 : 1)
+#define IS_EQ(a, b) ( \
+ CHECK_TYPE_INLINE(a, double), CHECK_TYPE_INLINE(b, double), \
+ ((fabs((double)(a) - (b)) >= (double) FLT_EPSILON) ? false : true))
+
+#define IS_EQF(a, b) ( \
+ CHECK_TYPE_INLINE(a, float), CHECK_TYPE_INLINE(b, float), \
+ ((fabsf((float)(a) - (b)) >= (float) FLT_EPSILON) ? false : true))
#define IS_EQT(a, b, c) ((a > b) ? (((a - b) <= c) ? 1 : 0) : ((((b - a) <= c) ? 1 : 0)))
#define IN_RANGE(a, b, c) ((b < c) ? ((b < a && a < c) ? 1 : 0) : ((c < a && a < b) ? 1 : 0))
diff --git a/source/blender/blenlib/BLI_voronoi.h b/source/blender/blenlib/BLI_voronoi.h
index 68d7398d89b..9d32061bf97 100644
--- a/source/blender/blenlib/BLI_voronoi.h
+++ b/source/blender/blenlib/BLI_voronoi.h
@@ -52,7 +52,7 @@ typedef struct VoronoiEdge {
float f, g; /* directional coeffitients satisfying equation y = f * x + g (edge lies on this line) */
/* some edges consist of two parts, so we add the pointer to another part to connect them at the end of an algorithm */
- struct VoronoiEdge *neighbour;
+ struct VoronoiEdge *neighbor;
} VoronoiEdge;
typedef struct VoronoiTriangulationPoint {
diff --git a/source/blender/blenlib/intern/BLI_ghash.c b/source/blender/blenlib/intern/BLI_ghash.c
index fcca6cd59ba..f3ebddddc8c 100644
--- a/source/blender/blenlib/intern/BLI_ghash.c
+++ b/source/blender/blenlib/intern/BLI_ghash.c
@@ -136,7 +136,7 @@ BLI_INLINE void ghash_resize_buckets(GHash *gh, const unsigned int nbuckets)
}
/**
- * Increase initial bucket size to match a reserved ammount.
+ * Increase initial bucket size to match a reserved amount.
*/
BLI_INLINE void ghash_buckets_reserve(GHash *gh, const unsigned int nentries_reserve)
{
diff --git a/source/blender/blenlib/intern/BLI_mempool.c b/source/blender/blenlib/intern/BLI_mempool.c
index 261e53f0f55..28539d9ca34 100644
--- a/source/blender/blenlib/intern/BLI_mempool.c
+++ b/source/blender/blenlib/intern/BLI_mempool.c
@@ -584,7 +584,7 @@ void BLI_mempool_clear_ex(BLI_mempool *pool, const int totelem_reserve)
/* free all after pool->maxchunks */
- for (mpchunk = BLI_findlink(&pool->chunks, (int)maxchunks); mpchunk; mpchunk = mpchunk_next) {
+ for (mpchunk = BLI_findlink(&pool->chunks, (int)maxchunks); mpchunk; mpchunk = mpchunk_next) {
mpchunk_next = mpchunk->next;
BLI_remlink(&pool->chunks, mpchunk);
mempool_chunk_free(mpchunk, pool->flag);
diff --git a/source/blender/blenlib/intern/convexhull2d.c b/source/blender/blenlib/intern/convexhull2d.c
index 5669a302bd8..2c29ef042a1 100644
--- a/source/blender/blenlib/intern/convexhull2d.c
+++ b/source/blender/blenlib/intern/convexhull2d.c
@@ -191,6 +191,8 @@ static int pointref_cmp_y(const void *a_, const void *b_)
* \param points An array of 2D points.
* \param n The number of points in points.
* \param r_points An array of the convex hull vertex indices (max is n).
+ * _must_ be allocated as ``n * 2`` becauise of how its used internally,
+ * even though the final result will be no more then \a n in size.
* \returns the number of points in r_points.
*/
int BLI_convexhull_2d(const float (*points)[2], const int n, int r_points[])
@@ -310,7 +312,7 @@ float BLI_convexhull_aabb_fit_points_2d(const float (*points)[2], unsigned int n
float angle;
- index_map = MEM_mallocN(sizeof(*index_map) * n, __func__);
+ index_map = MEM_mallocN(sizeof(*index_map) * n * 2, __func__);
tot = BLI_convexhull_2d((const float (*)[2])points, (int)n, index_map);
diff --git a/source/blender/blenlib/intern/edgehash.c b/source/blender/blenlib/intern/edgehash.c
index b26e007b3e6..50dcd01207d 100644
--- a/source/blender/blenlib/intern/edgehash.c
+++ b/source/blender/blenlib/intern/edgehash.c
@@ -137,7 +137,7 @@ BLI_INLINE void edgehash_resize_buckets(EdgeHash *eh, const unsigned int nbucket
}
/**
- * Increase initial bucket size to match a reserved ammount.
+ * Increase initial bucket size to match a reserved amount.
*/
BLI_INLINE void edgehash_buckets_reserve(EdgeHash *eh, const unsigned int nentries_reserve)
{
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index d24200fc0b7..1f52caac8e9 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -112,6 +112,22 @@ void copy_m4_m3(float m1[4][4], float m2[3][3]) /* no clear */
}
+void copy_m3_m3d(float R[3][3], double A[3][3])
+{
+ /* Keep it stupid simple for better data flow in CPU. */
+ R[0][0] = A[0][0];
+ R[0][1] = A[0][1];
+ R[0][2] = A[0][2];
+
+ R[1][0] = A[1][0];
+ R[1][1] = A[1][1];
+ R[1][2] = A[1][2];
+
+ R[2][0] = A[2][0];
+ R[2][1] = A[2][1];
+ R[2][2] = A[2][2];
+}
+
void swap_m3m3(float m1[3][3], float m2[3][3])
{
float t;
@@ -2070,3 +2086,9 @@ void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon)
}
}
+bool has_zero_axis_m4(float matrix[4][4])
+{
+ return len_squared_v3(matrix[0]) < FLT_EPSILON ||
+ len_squared_v3(matrix[1]) < FLT_EPSILON ||
+ len_squared_v3(matrix[2]) < FLT_EPSILON;
+}
diff --git a/source/blender/blenlib/intern/math_rotation.c b/source/blender/blenlib/intern/math_rotation.c
index 2eebe10dd58..41535cf32b6 100644
--- a/source/blender/blenlib/intern/math_rotation.c
+++ b/source/blender/blenlib/intern/math_rotation.c
@@ -1712,7 +1712,7 @@ float fov_to_focallength(float hfov, float sensor)
return (sensor / 2.0f) / tanf(hfov * 0.5f);
}
-/* 'mod_inline(-3,4)= 1', 'fmod(-3,4)= -3' */
+/* 'mod_inline(-3, 4)= 1', 'fmod(-3, 4)= -3' */
static float mod_inline(float a, float b)
{
return a - (b * floorf(a / b));
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index ce5d9657c7f..ace8e6b48c1 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -235,6 +235,22 @@ MINLINE void swap_v4_v4(float a[4], float b[4])
SWAP(float, a[3], b[3]);
}
+/* float args -> vec */
+MINLINE void copy_v3_fl3(float v[3], float x, float y, float z)
+{
+ v[0] = x;
+ v[1] = y;
+ v[2] = z;
+}
+
+MINLINE void copy_v4_fl4(float v[4], float x, float y, float z, float w)
+{
+ v[0] = x;
+ v[1] = y;
+ v[2] = z;
+ v[3] = w;
+}
+
/********************************* Arithmetic ********************************/
MINLINE void add_v2_fl(float r[2], float f)
@@ -434,6 +450,22 @@ MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3])
return M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
}
+/**
+ * Almost like mul_m4_v3(), misses adding translation.
+ */
+MINLINE float dot_m4_v3_row_x(float M[4][4], const float a[3])
+{
+ return M[0][0] * a[0] + M[1][0] * a[1] + M[2][0] * a[2];
+}
+MINLINE float dot_m4_v3_row_y(float M[4][4], const float a[3])
+{
+ return M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
+}
+MINLINE float dot_m4_v3_row_z(float M[4][4], const float a[3])
+{
+ return M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
+}
+
MINLINE void madd_v2_v2fl(float r[2], const float a[2], float f)
{
r[0] += a[0] * f;
diff --git a/source/blender/blenlib/intern/rct.c b/source/blender/blenlib/intern/rct.c
index 02525e25dda..d36cd3cb394 100644
--- a/source/blender/blenlib/intern/rct.c
+++ b/source/blender/blenlib/intern/rct.c
@@ -216,6 +216,32 @@ bool BLI_rctf_isect_segment(const rctf *rect, const float s1[2], const float s2[
}
}
+bool BLI_rcti_isect_circle(const rcti *rect, const float xy[2], const float radius)
+{
+ float dx, dy;
+
+ if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) dx = 0;
+ else dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax);
+
+ if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) dy = 0;
+ else dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax);
+
+ return dx * dx + dy * dy <= radius * radius;
+}
+
+bool BLI_rctf_isect_circle(const rctf *rect, const float xy[2], const float radius)
+{
+ float dx, dy;
+
+ if (xy[0] >= rect->xmin && xy[0] <= rect->xmax) dx = 0;
+ else dx = (xy[0] < rect->xmin) ? (rect->xmin - xy[0]) : (xy[0] - rect->xmax);
+
+ if (xy[1] >= rect->ymin && xy[1] <= rect->ymax) dy = 0;
+ else dy = (xy[1] < rect->ymin) ? (rect->ymin - xy[1]) : (xy[1] - rect->ymax);
+
+ return dx * dx + dy * dy <= radius * radius;
+}
+
void BLI_rctf_union(rctf *rct1, const rctf *rct2)
{
if (rct1->xmin > rct2->xmin) rct1->xmin = rct2->xmin;
diff --git a/source/blender/blenlib/intern/task.c b/source/blender/blenlib/intern/task.c
index 7fa108b906f..4ae60abb2c8 100644
--- a/source/blender/blenlib/intern/task.c
+++ b/source/blender/blenlib/intern/task.c
@@ -402,7 +402,7 @@ void BLI_task_pool_stop(TaskPool *pool)
BLI_assert(pool->num == 0);
}
-bool BLI_task_pool_cancelled(TaskPool *pool)
+bool BLI_task_pool_canceled(TaskPool *pool)
{
return pool->do_cancel;
}
diff --git a/source/blender/blenlib/intern/threads.c b/source/blender/blenlib/intern/threads.c
index 64682965649..0b8f5dfdde5 100644
--- a/source/blender/blenlib/intern/threads.c
+++ b/source/blender/blenlib/intern/threads.c
@@ -166,7 +166,7 @@ TaskScheduler *BLI_task_scheduler_get(void)
if (task_scheduler == NULL) {
int tot_thread = BLI_system_thread_count();
- /* Do a lazy initialization, so it happes after
+ /* Do a lazy initialization, so it happens after
* command line arguments parsing
*/
task_scheduler = BLI_task_scheduler_create(tot_thread);
@@ -624,7 +624,7 @@ struct ThreadQueue {
pthread_cond_t push_cond;
pthread_cond_t finish_cond;
volatile int nowait;
- volatile int cancelled;
+ volatile int canceled;
};
ThreadQueue *BLI_thread_queue_init(void)
diff --git a/source/blender/blenlib/intern/voronoi.c b/source/blender/blenlib/intern/voronoi.c
index 3f6adff1eda..731536ff0df 100644
--- a/source/blender/blenlib/intern/voronoi.c
+++ b/source/blender/blenlib/intern/voronoi.c
@@ -99,7 +99,7 @@ static VoronoiEdge *voronoiEdge_new(float start[2], float left[2], float right[2
copy_v2_v2(edge->left, left);
copy_v2_v2(edge->right, right);
- edge->neighbour = NULL;
+ edge->neighbor = NULL;
edge->end[0] = 0;
edge->end[1] = 0;
@@ -395,7 +395,7 @@ static void voronoi_addParabola(VoronoiProcess *process, float site[2])
el = voronoiEdge_new(start, par->site, site);
er = voronoiEdge_new(start, site, par->site);
- el->neighbour = er;
+ el->neighbor = er;
BLI_addtail(&process->edges, el);
par->edge = er;
@@ -682,9 +682,9 @@ void BLI_voronoi_compute(const VoronoiSite *sites, int sites_total, int width, i
edge = process.edges.first;
while (edge) {
- if (edge->neighbour) {
- copy_v2_v2(edge->start, edge->neighbour->end);
- MEM_freeN(edge->neighbour);
+ if (edge->neighbor) {
+ copy_v2_v2(edge->start, edge->neighbor->end);
+ MEM_freeN(edge->neighbor);
}
edge = edge->next;