ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211. For details on usage and instructions for migrating branches without conflicts, see: https://wiki.blender.org/wiki/Tools/ClangFormat
This commit is contained in:
@@ -16,48 +16,48 @@
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
set(INC
|
||||
.
|
||||
../../blenlib
|
||||
../../blenkernel
|
||||
../../bmesh
|
||||
../../depsgraph
|
||||
../../makesdna
|
||||
../../../../intern/guardedalloc
|
||||
.
|
||||
../../blenlib
|
||||
../../blenkernel
|
||||
../../bmesh
|
||||
../../depsgraph
|
||||
../../makesdna
|
||||
../../../../intern/guardedalloc
|
||||
)
|
||||
|
||||
set(INC_SYS
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
${PYTHON_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
set(SRC
|
||||
mathutils.c
|
||||
mathutils_Color.c
|
||||
mathutils_Euler.c
|
||||
mathutils_Matrix.c
|
||||
mathutils_Quaternion.c
|
||||
mathutils_Vector.c
|
||||
mathutils_bvhtree.c
|
||||
mathutils_geometry.c
|
||||
mathutils_interpolate.c
|
||||
mathutils_kdtree.c
|
||||
mathutils_noise.c
|
||||
mathutils.c
|
||||
mathutils_Color.c
|
||||
mathutils_Euler.c
|
||||
mathutils_Matrix.c
|
||||
mathutils_Quaternion.c
|
||||
mathutils_Vector.c
|
||||
mathutils_bvhtree.c
|
||||
mathutils_geometry.c
|
||||
mathutils_interpolate.c
|
||||
mathutils_kdtree.c
|
||||
mathutils_noise.c
|
||||
|
||||
mathutils.h
|
||||
mathutils_Color.h
|
||||
mathutils_Euler.h
|
||||
mathutils_Matrix.h
|
||||
mathutils_Quaternion.h
|
||||
mathutils_Vector.h
|
||||
mathutils_bvhtree.h
|
||||
mathutils_geometry.h
|
||||
mathutils_interpolate.h
|
||||
mathutils_kdtree.h
|
||||
mathutils_noise.h
|
||||
mathutils.h
|
||||
mathutils_Color.h
|
||||
mathutils_Euler.h
|
||||
mathutils_Matrix.h
|
||||
mathutils_Quaternion.h
|
||||
mathutils_Vector.h
|
||||
mathutils_bvhtree.h
|
||||
mathutils_geometry.h
|
||||
mathutils_interpolate.h
|
||||
mathutils_kdtree.h
|
||||
mathutils_noise.h
|
||||
)
|
||||
|
||||
set(LIB
|
||||
bf_blenlib
|
||||
bf_python_ext
|
||||
bf_blenlib
|
||||
bf_python_ext
|
||||
)
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -32,37 +32,39 @@ extern char BaseMathObject_is_frozen_doc[];
|
||||
extern char BaseMathObject_owner_doc[];
|
||||
|
||||
#define BASE_MATH_NEW(struct_name, root_type, base_type) \
|
||||
(struct_name *)((base_type ? (base_type)->tp_alloc(base_type, 0) : _PyObject_GC_New(&(root_type))));
|
||||
|
||||
(struct_name *)((base_type ? (base_type)->tp_alloc(base_type, 0) : \
|
||||
_PyObject_GC_New(&(root_type))));
|
||||
|
||||
/** BaseMathObject.flag */
|
||||
enum {
|
||||
/**
|
||||
* Do not own the memory used in this vector,
|
||||
* \note This is error prone if the memory may be freed while this vector is in use.
|
||||
* Prefer using callbacks where possible, see: #Mathutils_RegisterCallback
|
||||
*/
|
||||
BASE_MATH_FLAG_IS_WRAP = (1 << 0),
|
||||
/**
|
||||
* Prevent changes to the vector so it can be used as a set or dictionary key for example.
|
||||
* (typical use cases for tuple).
|
||||
*/
|
||||
BASE_MATH_FLAG_IS_FROZEN = (1 << 1),
|
||||
/**
|
||||
* Do not own the memory used in this vector,
|
||||
* \note This is error prone if the memory may be freed while this vector is in use.
|
||||
* Prefer using callbacks where possible, see: #Mathutils_RegisterCallback
|
||||
*/
|
||||
BASE_MATH_FLAG_IS_WRAP = (1 << 0),
|
||||
/**
|
||||
* Prevent changes to the vector so it can be used as a set or dictionary key for example.
|
||||
* (typical use cases for tuple).
|
||||
*/
|
||||
BASE_MATH_FLAG_IS_FROZEN = (1 << 1),
|
||||
};
|
||||
#define BASE_MATH_FLAG_DEFAULT 0
|
||||
|
||||
#define BASE_MATH_MEMBERS(_data) \
|
||||
PyObject_VAR_HEAD \
|
||||
float *_data; /* array of data (alias), wrapped status depends on wrapped status */ \
|
||||
PyObject *cb_user; /* if this vector references another object, otherwise NULL, \
|
||||
* *Note* this owns its reference */ \
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, etc */ \
|
||||
unsigned char cb_subtype; /* subtype: location, rotation... \
|
||||
* to avoid defining many new functions for every attribute of the same type */ \
|
||||
unsigned char flag /* wrapped data type? */ \
|
||||
#define BASE_MATH_MEMBERS(_data) \
|
||||
PyObject_VAR_HEAD float \
|
||||
*_data; /* array of data (alias), wrapped status depends on wrapped status */ \
|
||||
PyObject * \
|
||||
cb_user; /* if this vector references another object, otherwise NULL, \
|
||||
* *Note* this owns its reference */ \
|
||||
unsigned char cb_type; /* which user funcs do we adhere to, RNA, etc */ \
|
||||
unsigned char \
|
||||
cb_subtype; /* subtype: location, rotation... \
|
||||
* to avoid defining many new functions for every attribute of the same type */ \
|
||||
unsigned char flag /* wrapped data type? */
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(data);
|
||||
BASE_MATH_MEMBERS(data);
|
||||
} BaseMathObject;
|
||||
|
||||
/* types */
|
||||
@@ -73,8 +75,7 @@ typedef struct {
|
||||
#include "mathutils_Color.h"
|
||||
|
||||
/* avoid checking all types */
|
||||
#define BaseMathObject_CheckExact(v) \
|
||||
(Py_TYPE(v)->tp_dealloc == (destructor)BaseMathObject_dealloc)
|
||||
#define BaseMathObject_CheckExact(v) (Py_TYPE(v)->tp_dealloc == (destructor)BaseMathObject_dealloc)
|
||||
|
||||
PyObject *BaseMathObject_owner_get(BaseMathObject *self, void *);
|
||||
PyObject *BaseMathObject_is_wrapped_get(BaseMathObject *self, void *);
|
||||
@@ -94,18 +95,23 @@ int EXPP_VectorsAreEqual(const float *vecA, const float *vecB, int size, int flo
|
||||
|
||||
typedef struct Mathutils_Callback Mathutils_Callback;
|
||||
|
||||
typedef int (*BaseMathCheckFunc)(BaseMathObject *); /* checks the user is still valid */
|
||||
typedef int (*BaseMathGetFunc)(BaseMathObject *, int); /* gets the vector from the user */
|
||||
typedef int (*BaseMathSetFunc)(BaseMathObject *, int); /* sets the users vector values once its modified */
|
||||
typedef int (*BaseMathGetIndexFunc)(BaseMathObject *, int, int); /* same as above but only for an index */
|
||||
typedef int (*BaseMathSetIndexFunc)(BaseMathObject *, int, int); /* same as above but only for an index */
|
||||
typedef int (*BaseMathCheckFunc)(BaseMathObject *); /* checks the user is still valid */
|
||||
typedef int (*BaseMathGetFunc)(BaseMathObject *, int); /* gets the vector from the user */
|
||||
typedef int (*BaseMathSetFunc)(BaseMathObject *,
|
||||
int); /* sets the users vector values once its modified */
|
||||
typedef int (*BaseMathGetIndexFunc)(BaseMathObject *,
|
||||
int,
|
||||
int); /* same as above but only for an index */
|
||||
typedef int (*BaseMathSetIndexFunc)(BaseMathObject *,
|
||||
int,
|
||||
int); /* same as above but only for an index */
|
||||
|
||||
struct Mathutils_Callback {
|
||||
BaseMathCheckFunc check;
|
||||
BaseMathGetFunc get;
|
||||
BaseMathSetFunc set;
|
||||
BaseMathGetIndexFunc get_index;
|
||||
BaseMathSetIndexFunc set_index;
|
||||
BaseMathCheckFunc check;
|
||||
BaseMathGetFunc get;
|
||||
BaseMathSetFunc set;
|
||||
BaseMathGetIndexFunc get_index;
|
||||
BaseMathSetIndexFunc set_index;
|
||||
};
|
||||
|
||||
unsigned char Mathutils_RegisterCallback(Mathutils_Callback *cb);
|
||||
@@ -120,44 +126,55 @@ void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self);
|
||||
|
||||
/* since this is called so often avoid where possible */
|
||||
#define BaseMath_ReadCallback(_self) \
|
||||
(((_self)->cb_user ? _BaseMathObject_ReadCallback((BaseMathObject *)_self) : 0))
|
||||
(((_self)->cb_user ? _BaseMathObject_ReadCallback((BaseMathObject *)_self) : 0))
|
||||
#define BaseMath_WriteCallback(_self) \
|
||||
(((_self)->cb_user ?_BaseMathObject_WriteCallback((BaseMathObject *)_self) : 0))
|
||||
(((_self)->cb_user ? _BaseMathObject_WriteCallback((BaseMathObject *)_self) : 0))
|
||||
#define BaseMath_ReadIndexCallback(_self, _index) \
|
||||
(((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index) : 0))
|
||||
(((_self)->cb_user ? _BaseMathObject_ReadIndexCallback((BaseMathObject *)_self, _index) : 0))
|
||||
#define BaseMath_WriteIndexCallback(_self, _index) \
|
||||
(((_self)->cb_user ? _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index) : 0))
|
||||
(((_self)->cb_user ? _BaseMathObject_WriteIndexCallback((BaseMathObject *)_self, _index) : 0))
|
||||
|
||||
/* support BASE_MATH_FLAG_IS_FROZEN */
|
||||
#define BaseMath_ReadCallback_ForWrite(_self) \
|
||||
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
||||
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : (BaseMath_ReadCallback(_self)))
|
||||
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
||||
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \
|
||||
(BaseMath_ReadCallback(_self)))
|
||||
|
||||
#define BaseMath_ReadIndexCallback_ForWrite(_self, _index) \
|
||||
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
||||
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : (BaseMath_ReadIndexCallback(_self, _index)))
|
||||
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
||||
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \
|
||||
(BaseMath_ReadIndexCallback(_self, _index)))
|
||||
|
||||
#define BaseMath_Prepare_ForWrite(_self) \
|
||||
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
||||
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : 0)
|
||||
(UNLIKELY((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) ? \
|
||||
(_BaseMathObject_RaiseFrozenExc((BaseMathObject *)_self), -1) : \
|
||||
0)
|
||||
|
||||
#define BaseMathObject_Prepare_ForHash(_self) \
|
||||
(UNLIKELY(((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) == 0) ? \
|
||||
(_BaseMathObject_RaiseNotFrozenExc((BaseMathObject *)_self), -1) : 0)
|
||||
(UNLIKELY(((_self)->flag & BASE_MATH_FLAG_IS_FROZEN) == 0) ? \
|
||||
(_BaseMathObject_RaiseNotFrozenExc((BaseMathObject *)_self), -1) : \
|
||||
0)
|
||||
|
||||
/* utility func */
|
||||
int mathutils_array_parse(float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
|
||||
int mathutils_array_parse_alloc(float **array, int array_min, PyObject *value, const char *error_prefix);
|
||||
int mathutils_array_parse_alloc_v(float **array, int array_dim, PyObject *value, const char *error_prefix);
|
||||
int mathutils_array_parse(
|
||||
float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
|
||||
int mathutils_array_parse_alloc(float **array,
|
||||
int array_min,
|
||||
PyObject *value,
|
||||
const char *error_prefix);
|
||||
int mathutils_array_parse_alloc_v(float **array,
|
||||
int array_dim,
|
||||
PyObject *value,
|
||||
const char *error_prefix);
|
||||
int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error_prefix);
|
||||
|
||||
Py_hash_t mathutils_array_hash(const float *float_array, size_t array_len);
|
||||
|
||||
/* zero remaining unused elements of the array */
|
||||
#define MU_ARRAY_ZERO (1u << 30)
|
||||
#define MU_ARRAY_ZERO (1u << 30)
|
||||
/* ignore larger py sequences than requested (just use first elements),
|
||||
* handy when using 3d vectors as 2d */
|
||||
#define MU_ARRAY_SPILL (1u << 31)
|
||||
#define MU_ARRAY_SPILL (1u << 31)
|
||||
|
||||
#define MU_ARRAY_FLAGS (MU_ARRAY_ZERO | MU_ARRAY_SPILL)
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,6 @@
|
||||
* \ingroup pymathutils
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MATHUTILS_COLOR_H__
|
||||
#define __MATHUTILS_COLOR_H__
|
||||
|
||||
@@ -27,7 +26,7 @@ extern PyTypeObject color_Type;
|
||||
#define ColorObject_CheckExact(v) (Py_TYPE(v) == &color_Type)
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(col);
|
||||
BASE_MATH_MEMBERS(col);
|
||||
} ColorObject;
|
||||
|
||||
/* struct data contains a pointer to the actual data that the
|
||||
@@ -36,17 +35,12 @@ typedef struct {
|
||||
* blender (stored in blend_data). This is an either/or struct not both*/
|
||||
|
||||
/* prototypes */
|
||||
PyObject *Color_CreatePyObject(
|
||||
const float col[3],
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Color_CreatePyObject_wrap(
|
||||
float col[3],
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
||||
PyObject *Color_CreatePyObject_cb(
|
||||
PyObject *cb_user,
|
||||
unsigned char cb_type, unsigned char cb_subtype
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Color_CreatePyObject(const float col[3],
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Color_CreatePyObject_wrap(float col[3], PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
PyObject *Color_CreatePyObject_cb(PyObject *cb_user,
|
||||
unsigned char cb_type,
|
||||
unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
#endif /* __MATHUTILS_COLOR_H__ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,8 +26,8 @@ extern PyTypeObject euler_Type;
|
||||
#define EulerObject_CheckExact(v) (Py_TYPE(v) == &euler_Type)
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(eul);
|
||||
unsigned char order; /* rotation order */
|
||||
BASE_MATH_MEMBERS(eul);
|
||||
unsigned char order; /* rotation order */
|
||||
|
||||
} EulerObject;
|
||||
|
||||
@@ -37,20 +37,18 @@ typedef struct {
|
||||
* blender (stored in blend_data). This is an either/or struct not both */
|
||||
|
||||
/* prototypes */
|
||||
PyObject *Euler_CreatePyObject(
|
||||
const float eul[3], const short order,
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Euler_CreatePyObject_wrap(
|
||||
float eul[3], const short order,
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
||||
PyObject *Euler_CreatePyObject_cb(
|
||||
PyObject *cb_user, const short order,
|
||||
unsigned char cb_type, unsigned char cb_subtype
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Euler_CreatePyObject(const float eul[3],
|
||||
const short order,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Euler_CreatePyObject_wrap(float eul[3],
|
||||
const short order,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
PyObject *Euler_CreatePyObject_cb(PyObject *cb_user,
|
||||
const short order,
|
||||
unsigned char cb_type,
|
||||
unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
short euler_order_from_string(const char *str, const char *error_prefix);
|
||||
|
||||
|
||||
#endif /* __MATHUTILS_EULER_H__ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,6 @@
|
||||
* \ingroup pymathutils
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MATHUTILS_MATRIX_H__
|
||||
#define __MATHUTILS_MATRIX_H__
|
||||
|
||||
@@ -33,23 +32,25 @@ extern PyTypeObject matrix_access_Type;
|
||||
/* matrix[row][col] == MATRIX_ITEM_INDEX(matrix, row, col) */
|
||||
|
||||
#ifdef DEBUG
|
||||
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) (BLI_assert(_row < (_mat)->num_row && _col < (_mat)->num_col))
|
||||
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) \
|
||||
(BLI_assert(_row < (_mat)->num_row && _col < (_mat)->num_col))
|
||||
#else
|
||||
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) (void)0
|
||||
#endif
|
||||
|
||||
#define MATRIX_ITEM_INDEX_NUMROW(_totrow, _row, _col) (((_totrow) * (_col)) + (_row))
|
||||
#define MATRIX_ITEM_INDEX(_mat, _row, _col) (MATRIX_ITEM_ASSERT(_mat, _row, _col),(((_mat)->num_row * (_col)) + (_row)))
|
||||
#define MATRIX_ITEM_PTR( _mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col))
|
||||
#define MATRIX_ITEM( _mat, _row, _col) ((_mat)->matrix [MATRIX_ITEM_INDEX(_mat, _row, _col)])
|
||||
#define MATRIX_ITEM_INDEX(_mat, _row, _col) \
|
||||
(MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->num_row * (_col)) + (_row)))
|
||||
#define MATRIX_ITEM_PTR(_mat, _row, _col) ((_mat)->matrix + MATRIX_ITEM_INDEX(_mat, _row, _col))
|
||||
#define MATRIX_ITEM(_mat, _row, _col) ((_mat)->matrix[MATRIX_ITEM_INDEX(_mat, _row, _col)])
|
||||
|
||||
#define MATRIX_COL_INDEX(_mat, _col) (MATRIX_ITEM_INDEX(_mat, 0, _col))
|
||||
#define MATRIX_COL_PTR( _mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col))
|
||||
#define MATRIX_COL_PTR(_mat, _col) ((_mat)->matrix + MATRIX_COL_INDEX(_mat, _col))
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(matrix);
|
||||
unsigned short num_col;
|
||||
unsigned short num_row;
|
||||
BASE_MATH_MEMBERS(matrix);
|
||||
unsigned short num_col;
|
||||
unsigned short num_row;
|
||||
} MatrixObject;
|
||||
|
||||
/* struct data contains a pointer to the actual data that the
|
||||
@@ -58,21 +59,20 @@ typedef struct {
|
||||
* blender (stored in blend_data). This is an either/or struct not both */
|
||||
|
||||
/* prototypes */
|
||||
PyObject *Matrix_CreatePyObject(
|
||||
const float *mat,
|
||||
const unsigned short num_col, const unsigned short num_row,
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Matrix_CreatePyObject_wrap(
|
||||
float *mat,
|
||||
const unsigned short num_col, const unsigned short num_row,
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
||||
PyObject *Matrix_CreatePyObject_cb(
|
||||
PyObject *user,
|
||||
const unsigned short num_col, const unsigned short num_row,
|
||||
unsigned char cb_type, unsigned char cb_subtype
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Matrix_CreatePyObject(const float *mat,
|
||||
const unsigned short num_col,
|
||||
const unsigned short num_row,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Matrix_CreatePyObject_wrap(float *mat,
|
||||
const unsigned short num_col,
|
||||
const unsigned short num_row,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
PyObject *Matrix_CreatePyObject_cb(PyObject *user,
|
||||
const unsigned short num_col,
|
||||
const unsigned short num_row,
|
||||
unsigned char cb_type,
|
||||
unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/* PyArg_ParseTuple's "O&" formatting helpers. */
|
||||
int Matrix_ParseAny(PyObject *o, void *p);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -27,7 +27,7 @@ extern PyTypeObject quaternion_Type;
|
||||
#define QuaternionObject_CheckExact(v) (Py_TYPE(v) == &quaternion_Type)
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(quat);
|
||||
BASE_MATH_MEMBERS(quat);
|
||||
} QuaternionObject;
|
||||
|
||||
/* struct data contains a pointer to the actual data that the
|
||||
@@ -36,17 +36,13 @@ typedef struct {
|
||||
* blender (stored in blend_data). This is an either/or struct not both */
|
||||
|
||||
/* prototypes */
|
||||
PyObject *Quaternion_CreatePyObject(
|
||||
const float quat[4],
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Quaternion_CreatePyObject_wrap(
|
||||
float quat[4],
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
||||
PyObject *Quaternion_CreatePyObject_cb(
|
||||
PyObject *cb_user,
|
||||
unsigned char cb_type, unsigned char cb_subtype
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Quaternion_CreatePyObject(const float quat[4],
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Quaternion_CreatePyObject_wrap(float quat[4],
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
PyObject *Quaternion_CreatePyObject_cb(PyObject *cb_user,
|
||||
unsigned char cb_type,
|
||||
unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
#endif /* __MATHUTILS_QUATERNION_H__ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,6 @@
|
||||
* \ingroup pymathutils
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __MATHUTILS_VECTOR_H__
|
||||
#define __MATHUTILS_VECTOR_H__
|
||||
|
||||
@@ -28,27 +27,26 @@ extern PyTypeObject vector_Type;
|
||||
#define VectorObject_CheckExact(v) (Py_TYPE(v) == &vector_Type)
|
||||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(vec);
|
||||
BASE_MATH_MEMBERS(vec);
|
||||
|
||||
int size; /* vec size 2 or more */
|
||||
int size; /* vec size 2 or more */
|
||||
} VectorObject;
|
||||
|
||||
/*prototypes*/
|
||||
PyObject *Vector_CreatePyObject(
|
||||
const float *vec, const int size,
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Vector_CreatePyObject_wrap(
|
||||
float *vec, const int size,
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
||||
PyObject *Vector_CreatePyObject_cb(
|
||||
PyObject *user, int size,
|
||||
unsigned char cb_type, unsigned char subtype
|
||||
) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Vector_CreatePyObject_alloc(
|
||||
float *vec, const int size,
|
||||
PyTypeObject *base_type
|
||||
) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
|
||||
PyObject *Vector_CreatePyObject(const float *vec,
|
||||
const int size,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Vector_CreatePyObject_wrap(float *vec,
|
||||
const int size,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
PyObject *Vector_CreatePyObject_cb(PyObject *user,
|
||||
int size,
|
||||
unsigned char cb_type,
|
||||
unsigned char subtype) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Vector_CreatePyObject_alloc(float *vec,
|
||||
const int size,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
|
||||
#endif /* __MATHUTILS_VECTOR_H__ */
|
||||
#endif /* __MATHUTILS_VECTOR_H__ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -14,7 +14,6 @@
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
/** \file
|
||||
* \ingroup mathutils
|
||||
*/
|
||||
@@ -26,7 +25,7 @@ PyMODINIT_FUNC PyInit_mathutils_bvhtree(void);
|
||||
|
||||
extern PyTypeObject PyBVHTree_Type;
|
||||
|
||||
#define PyBVHTree_Check(v) PyObject_TypeCheck((v), &PyBVHTree_Type)
|
||||
#define PyBVHTree_CheckExact(v) (Py_TYPE(v) == &PyBVHTree_Type)
|
||||
#define PyBVHTree_Check(v) PyObject_TypeCheck((v), &PyBVHTree_Type)
|
||||
#define PyBVHTree_CheckExact(v) (Py_TYPE(v) == &PyBVHTree_Type)
|
||||
|
||||
#endif /* __MATHUTILS_BVHTREE_H__ */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,6 @@
|
||||
* \ingroup pymathutils
|
||||
*/
|
||||
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include "mathutils.h"
|
||||
@@ -32,105 +31,100 @@
|
||||
#endif
|
||||
|
||||
/*-------------------------DOC STRINGS ---------------------------*/
|
||||
PyDoc_STRVAR(M_Interpolate_doc,
|
||||
"The Blender interpolate module"
|
||||
);
|
||||
PyDoc_STRVAR(M_Interpolate_doc, "The Blender interpolate module");
|
||||
|
||||
/* ---------------------------------WEIGHT CALCULATION ----------------------- */
|
||||
|
||||
#ifndef MATH_STANDALONE
|
||||
|
||||
PyDoc_STRVAR(M_Interpolate_poly_3d_calc_doc,
|
||||
".. function:: poly_3d_calc(veclist, pt)\n"
|
||||
"\n"
|
||||
" Calculate barycentric weights for a point on a polygon.\n"
|
||||
"\n"
|
||||
" :arg veclist: list of vectors\n"
|
||||
" :arg pt: point"
|
||||
" :rtype: list of per-vector weights\n"
|
||||
);
|
||||
".. function:: poly_3d_calc(veclist, pt)\n"
|
||||
"\n"
|
||||
" Calculate barycentric weights for a point on a polygon.\n"
|
||||
"\n"
|
||||
" :arg veclist: list of vectors\n"
|
||||
" :arg pt: point"
|
||||
" :rtype: list of per-vector weights\n");
|
||||
static PyObject *M_Interpolate_poly_3d_calc(PyObject *UNUSED(self), PyObject *args)
|
||||
{
|
||||
float fp[3];
|
||||
float (*vecs)[3];
|
||||
Py_ssize_t len;
|
||||
float fp[3];
|
||||
float(*vecs)[3];
|
||||
Py_ssize_t len;
|
||||
|
||||
PyObject *point, *veclist, *ret;
|
||||
int i;
|
||||
PyObject *point, *veclist, *ret;
|
||||
int i;
|
||||
|
||||
if (!PyArg_ParseTuple(
|
||||
args, "OO!:poly_3d_calc",
|
||||
&veclist,
|
||||
&vector_Type, &point))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!PyArg_ParseTuple(args, "OO!:poly_3d_calc", &veclist, &vector_Type, &point)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (BaseMath_ReadCallback((VectorObject *)point) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (BaseMath_ReadCallback((VectorObject *)point) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fp[0] = ((VectorObject *)point)->vec[0];
|
||||
fp[1] = ((VectorObject *)point)->vec[1];
|
||||
if (((VectorObject *)point)->size > 2) {
|
||||
fp[2] = ((VectorObject *)point)->vec[2];
|
||||
}
|
||||
else {
|
||||
/* if its a 2d vector then set the z to be zero */
|
||||
fp[2] = 0.0f;
|
||||
}
|
||||
fp[0] = ((VectorObject *)point)->vec[0];
|
||||
fp[1] = ((VectorObject *)point)->vec[1];
|
||||
if (((VectorObject *)point)->size > 2) {
|
||||
fp[2] = ((VectorObject *)point)->vec[2];
|
||||
}
|
||||
else {
|
||||
/* if its a 2d vector then set the z to be zero */
|
||||
fp[2] = 0.0f;
|
||||
}
|
||||
|
||||
len = mathutils_array_parse_alloc_v(((float **)&vecs), 3, veclist, __func__);
|
||||
if (len == -1) {
|
||||
return NULL;
|
||||
}
|
||||
len = mathutils_array_parse_alloc_v(((float **)&vecs), 3, veclist, __func__);
|
||||
if (len == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (len) {
|
||||
float *weights = MEM_mallocN(sizeof(float) * len, __func__);
|
||||
if (len) {
|
||||
float *weights = MEM_mallocN(sizeof(float) * len, __func__);
|
||||
|
||||
interp_weights_poly_v3(weights, vecs, len, fp);
|
||||
interp_weights_poly_v3(weights, vecs, len, fp);
|
||||
|
||||
ret = PyList_New(len);
|
||||
for (i = 0; i < len; i++) {
|
||||
PyList_SET_ITEM(ret, i, PyFloat_FromDouble(weights[i]));
|
||||
}
|
||||
ret = PyList_New(len);
|
||||
for (i = 0; i < len; i++) {
|
||||
PyList_SET_ITEM(ret, i, PyFloat_FromDouble(weights[i]));
|
||||
}
|
||||
|
||||
MEM_freeN(weights);
|
||||
MEM_freeN(weights);
|
||||
|
||||
PyMem_Free(vecs);
|
||||
}
|
||||
else {
|
||||
ret = PyList_New(0);
|
||||
}
|
||||
PyMem_Free(vecs);
|
||||
}
|
||||
else {
|
||||
ret = PyList_New(0);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* MATH_STANDALONE */
|
||||
|
||||
|
||||
static PyMethodDef M_Interpolate_methods[] = {
|
||||
#ifndef MATH_STANDALONE
|
||||
{"poly_3d_calc", (PyCFunction) M_Interpolate_poly_3d_calc, METH_VARARGS, M_Interpolate_poly_3d_calc_doc},
|
||||
{"poly_3d_calc",
|
||||
(PyCFunction)M_Interpolate_poly_3d_calc,
|
||||
METH_VARARGS,
|
||||
M_Interpolate_poly_3d_calc_doc},
|
||||
#endif
|
||||
{NULL, NULL, 0, NULL},
|
||||
{NULL, NULL, 0, NULL},
|
||||
};
|
||||
|
||||
static struct PyModuleDef M_Interpolate_module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"mathutils.interpolate", /* m_name */
|
||||
M_Interpolate_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
M_Interpolate_methods, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
NULL, /* m_traverse */
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"mathutils.interpolate", /* m_name */
|
||||
M_Interpolate_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
M_Interpolate_methods, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
NULL, /* m_traverse */
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
};
|
||||
|
||||
/*----------------------------MODULE INIT-------------------------*/
|
||||
PyMODINIT_FUNC PyInit_mathutils_interpolate(void)
|
||||
{
|
||||
PyObject *submodule = PyModule_Create(&M_Interpolate_module_def);
|
||||
return submodule;
|
||||
PyObject *submodule = PyModule_Create(&M_Interpolate_module_def);
|
||||
return submodule;
|
||||
}
|
||||
|
||||
@@ -32,61 +32,58 @@
|
||||
#include "../generic/python_utildefines.h"
|
||||
|
||||
#include "mathutils.h"
|
||||
#include "mathutils_kdtree.h" /* own include */
|
||||
#include "mathutils_kdtree.h" /* own include */
|
||||
|
||||
#include "BLI_strict_flags.h"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
KDTree_3d *obj;
|
||||
unsigned int maxsize;
|
||||
unsigned int count;
|
||||
unsigned int count_balance; /* size when we last balanced */
|
||||
PyObject_HEAD KDTree_3d *obj;
|
||||
unsigned int maxsize;
|
||||
unsigned int count;
|
||||
unsigned int count_balance; /* size when we last balanced */
|
||||
} PyKDTree;
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Utility helper functions */
|
||||
|
||||
static void kdtree_nearest_to_py_tuple(const KDTreeNearest_3d *nearest, PyObject *py_retval)
|
||||
{
|
||||
BLI_assert(nearest->index >= 0);
|
||||
BLI_assert(PyTuple_GET_SIZE(py_retval) == 3);
|
||||
BLI_assert(nearest->index >= 0);
|
||||
BLI_assert(PyTuple_GET_SIZE(py_retval) == 3);
|
||||
|
||||
PyTuple_SET_ITEMS(py_retval,
|
||||
Vector_CreatePyObject((float *)nearest->co, 3, NULL),
|
||||
PyLong_FromLong(nearest->index),
|
||||
PyFloat_FromDouble(nearest->dist));
|
||||
PyTuple_SET_ITEMS(py_retval,
|
||||
Vector_CreatePyObject((float *)nearest->co, 3, NULL),
|
||||
PyLong_FromLong(nearest->index),
|
||||
PyFloat_FromDouble(nearest->dist));
|
||||
}
|
||||
|
||||
static PyObject *kdtree_nearest_to_py(const KDTreeNearest_3d *nearest)
|
||||
{
|
||||
PyObject *py_retval;
|
||||
PyObject *py_retval;
|
||||
|
||||
py_retval = PyTuple_New(3);
|
||||
py_retval = PyTuple_New(3);
|
||||
|
||||
kdtree_nearest_to_py_tuple(nearest, py_retval);
|
||||
kdtree_nearest_to_py_tuple(nearest, py_retval);
|
||||
|
||||
return py_retval;
|
||||
return py_retval;
|
||||
}
|
||||
|
||||
static PyObject *kdtree_nearest_to_py_and_check(const KDTreeNearest_3d *nearest)
|
||||
{
|
||||
PyObject *py_retval;
|
||||
PyObject *py_retval;
|
||||
|
||||
py_retval = PyTuple_New(3);
|
||||
py_retval = PyTuple_New(3);
|
||||
|
||||
if (nearest->index != -1) {
|
||||
kdtree_nearest_to_py_tuple(nearest, py_retval);
|
||||
}
|
||||
else {
|
||||
PyC_Tuple_Fill(py_retval, Py_None);
|
||||
}
|
||||
if (nearest->index != -1) {
|
||||
kdtree_nearest_to_py_tuple(nearest, py_retval);
|
||||
}
|
||||
else {
|
||||
PyC_Tuple_Fill(py_retval, Py_None);
|
||||
}
|
||||
|
||||
return py_retval;
|
||||
return py_retval;
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* KDTree */
|
||||
|
||||
@@ -95,395 +92,376 @@ static PyObject *kdtree_nearest_to_py_and_check(const KDTreeNearest_3d *nearest)
|
||||
|
||||
static int PyKDTree__tp_init(PyKDTree *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
unsigned int maxsize;
|
||||
const char *keywords[] = {"size", NULL};
|
||||
unsigned int maxsize;
|
||||
const char *keywords[] = {"size", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, "I:KDTree", (char **)keywords,
|
||||
&maxsize))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "I:KDTree", (char **)keywords, &maxsize)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (UINT_IS_NEG(maxsize)) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative 'size' given");
|
||||
return -1;
|
||||
}
|
||||
if (UINT_IS_NEG(maxsize)) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative 'size' given");
|
||||
return -1;
|
||||
}
|
||||
|
||||
self->obj = BLI_kdtree_3d_new(maxsize);
|
||||
self->maxsize = maxsize;
|
||||
self->count = 0;
|
||||
self->count_balance = 0;
|
||||
self->obj = BLI_kdtree_3d_new(maxsize);
|
||||
self->maxsize = maxsize;
|
||||
self->count = 0;
|
||||
self->count_balance = 0;
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void PyKDTree__tp_dealloc(PyKDTree *self)
|
||||
{
|
||||
BLI_kdtree_3d_free(self->obj);
|
||||
Py_TYPE(self)->tp_free((PyObject *)self);
|
||||
BLI_kdtree_3d_free(self->obj);
|
||||
Py_TYPE(self)->tp_free((PyObject *)self);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(py_kdtree_insert_doc,
|
||||
".. method:: insert(co, index)\n"
|
||||
"\n"
|
||||
" Insert a point into the KDTree.\n"
|
||||
"\n"
|
||||
" :arg co: Point 3d position.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg index: The index of the point.\n"
|
||||
" :type index: int\n"
|
||||
);
|
||||
".. method:: insert(co, index)\n"
|
||||
"\n"
|
||||
" Insert a point into the KDTree.\n"
|
||||
"\n"
|
||||
" :arg co: Point 3d position.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg index: The index of the point.\n"
|
||||
" :type index: int\n");
|
||||
static PyObject *py_kdtree_insert(PyKDTree *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyObject *py_co;
|
||||
float co[3];
|
||||
int index;
|
||||
const char *keywords[] = {"co", "index", NULL};
|
||||
PyObject *py_co;
|
||||
float co[3];
|
||||
int index;
|
||||
const char *keywords[] = {"co", "index", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *) "Oi:insert", (char **)keywords,
|
||||
&py_co, &index))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *)"Oi:insert", (char **)keywords, &py_co, &index)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "insert: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "insert: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (index < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative index given");
|
||||
return NULL;
|
||||
}
|
||||
if (index < 0) {
|
||||
PyErr_SetString(PyExc_ValueError, "negative index given");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->count >= self->maxsize) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Trying to insert more items than KDTree has room for");
|
||||
return NULL;
|
||||
}
|
||||
if (self->count >= self->maxsize) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "Trying to insert more items than KDTree has room for");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BLI_kdtree_3d_insert(self->obj, index, co);
|
||||
self->count++;
|
||||
BLI_kdtree_3d_insert(self->obj, index, co);
|
||||
self->count++;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(py_kdtree_balance_doc,
|
||||
".. method:: balance()\n"
|
||||
"\n"
|
||||
" Balance the tree.\n"
|
||||
"\n"
|
||||
".. note::\n"
|
||||
"\n"
|
||||
" This builds the entire tree, avoid calling after each insertion.\n"
|
||||
);
|
||||
".. method:: balance()\n"
|
||||
"\n"
|
||||
" Balance the tree.\n"
|
||||
"\n"
|
||||
".. note::\n"
|
||||
"\n"
|
||||
" This builds the entire tree, avoid calling after each insertion.\n");
|
||||
static PyObject *py_kdtree_balance(PyKDTree *self)
|
||||
{
|
||||
BLI_kdtree_3d_balance(self->obj);
|
||||
self->count_balance = self->count;
|
||||
Py_RETURN_NONE;
|
||||
BLI_kdtree_3d_balance(self->obj);
|
||||
self->count_balance = self->count;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
struct PyKDTree_NearestData {
|
||||
PyObject *py_filter;
|
||||
bool is_error;
|
||||
PyObject *py_filter;
|
||||
bool is_error;
|
||||
};
|
||||
|
||||
static int py_find_nearest_cb(void *user_data, int index, const float co[3], float dist_sq)
|
||||
{
|
||||
UNUSED_VARS(co, dist_sq);
|
||||
UNUSED_VARS(co, dist_sq);
|
||||
|
||||
struct PyKDTree_NearestData *data = user_data;
|
||||
struct PyKDTree_NearestData *data = user_data;
|
||||
|
||||
PyObject *py_args = PyTuple_New(1);
|
||||
PyTuple_SET_ITEM(py_args, 0, PyLong_FromLong(index));
|
||||
PyObject *result = PyObject_CallObject(data->py_filter, py_args);
|
||||
Py_DECREF(py_args);
|
||||
PyObject *py_args = PyTuple_New(1);
|
||||
PyTuple_SET_ITEM(py_args, 0, PyLong_FromLong(index));
|
||||
PyObject *result = PyObject_CallObject(data->py_filter, py_args);
|
||||
Py_DECREF(py_args);
|
||||
|
||||
if (result) {
|
||||
bool use_node;
|
||||
int ok = PyC_ParseBool(result, &use_node);
|
||||
Py_DECREF(result);
|
||||
if (ok) {
|
||||
return (int)use_node;
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
bool use_node;
|
||||
int ok = PyC_ParseBool(result, &use_node);
|
||||
Py_DECREF(result);
|
||||
if (ok) {
|
||||
return (int)use_node;
|
||||
}
|
||||
}
|
||||
|
||||
data->is_error = true;
|
||||
return -1;
|
||||
data->is_error = true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(py_kdtree_find_doc,
|
||||
".. method:: find(co, filter=None)\n"
|
||||
"\n"
|
||||
" Find nearest point to ``co``.\n"
|
||||
"\n"
|
||||
" :arg co: 3d coordinates.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg filter: function which takes an index and returns True for indices to include in the search.\n"
|
||||
" :type filter: callable\n"
|
||||
" :return: Returns (:class:`Vector`, index, distance).\n"
|
||||
" :rtype: :class:`tuple`\n"
|
||||
);
|
||||
".. method:: find(co, filter=None)\n"
|
||||
"\n"
|
||||
" Find nearest point to ``co``.\n"
|
||||
"\n"
|
||||
" :arg co: 3d coordinates.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg filter: function which takes an index and returns True for indices to "
|
||||
"include in the search.\n"
|
||||
" :type filter: callable\n"
|
||||
" :return: Returns (:class:`Vector`, index, distance).\n"
|
||||
" :rtype: :class:`tuple`\n");
|
||||
static PyObject *py_kdtree_find(PyKDTree *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyObject *py_co, *py_filter = NULL;
|
||||
float co[3];
|
||||
KDTreeNearest_3d nearest;
|
||||
const char *keywords[] = {"co", "filter", NULL};
|
||||
PyObject *py_co, *py_filter = NULL;
|
||||
float co[3];
|
||||
KDTreeNearest_3d nearest;
|
||||
const char *keywords[] = {"co", "filter", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *) "O|O:find", (char **)keywords,
|
||||
&py_co, &py_filter))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *)"O|O:find", (char **)keywords, &py_co, &py_filter)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "find: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "find: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->count != self->count_balance) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find()");
|
||||
return NULL;
|
||||
}
|
||||
if (self->count != self->count_balance) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nearest.index = -1;
|
||||
nearest.index = -1;
|
||||
|
||||
if (py_filter == NULL) {
|
||||
BLI_kdtree_3d_find_nearest(self->obj, co, &nearest);
|
||||
}
|
||||
else {
|
||||
struct PyKDTree_NearestData data = {0};
|
||||
if (py_filter == NULL) {
|
||||
BLI_kdtree_3d_find_nearest(self->obj, co, &nearest);
|
||||
}
|
||||
else {
|
||||
struct PyKDTree_NearestData data = {0};
|
||||
|
||||
data.py_filter = py_filter;
|
||||
data.is_error = false;
|
||||
data.py_filter = py_filter;
|
||||
data.is_error = false;
|
||||
|
||||
BLI_kdtree_3d_find_nearest_cb(
|
||||
self->obj, co,
|
||||
py_find_nearest_cb, &data,
|
||||
&nearest);
|
||||
BLI_kdtree_3d_find_nearest_cb(self->obj, co, py_find_nearest_cb, &data, &nearest);
|
||||
|
||||
if (data.is_error) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if (data.is_error) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
return kdtree_nearest_to_py_and_check(&nearest);
|
||||
return kdtree_nearest_to_py_and_check(&nearest);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(py_kdtree_find_n_doc,
|
||||
".. method:: find_n(co, n)\n"
|
||||
"\n"
|
||||
" Find nearest ``n`` points to ``co``.\n"
|
||||
"\n"
|
||||
" :arg co: 3d coordinates.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg n: Number of points to find.\n"
|
||||
" :type n: int\n"
|
||||
" :return: Returns a list of tuples (:class:`Vector`, index, distance).\n"
|
||||
" :rtype: :class:`list`\n"
|
||||
);
|
||||
".. method:: find_n(co, n)\n"
|
||||
"\n"
|
||||
" Find nearest ``n`` points to ``co``.\n"
|
||||
"\n"
|
||||
" :arg co: 3d coordinates.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg n: Number of points to find.\n"
|
||||
" :type n: int\n"
|
||||
" :return: Returns a list of tuples (:class:`Vector`, index, distance).\n"
|
||||
" :rtype: :class:`list`\n");
|
||||
static PyObject *py_kdtree_find_n(PyKDTree *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyObject *py_list;
|
||||
PyObject *py_co;
|
||||
float co[3];
|
||||
KDTreeNearest_3d *nearest;
|
||||
unsigned int n;
|
||||
int i, found;
|
||||
const char *keywords[] = {"co", "n", NULL};
|
||||
PyObject *py_list;
|
||||
PyObject *py_co;
|
||||
float co[3];
|
||||
KDTreeNearest_3d *nearest;
|
||||
unsigned int n;
|
||||
int i, found;
|
||||
const char *keywords[] = {"co", "n", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *) "OI:find_n", (char **)keywords,
|
||||
&py_co, &n))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *)"OI:find_n", (char **)keywords, &py_co, &n)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "find_n: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "find_n: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (UINT_IS_NEG(n)) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "negative 'n' given");
|
||||
return NULL;
|
||||
}
|
||||
if (UINT_IS_NEG(n)) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "negative 'n' given");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->count != self->count_balance) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find_n()");
|
||||
return NULL;
|
||||
}
|
||||
if (self->count != self->count_balance) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find_n()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nearest = MEM_mallocN(sizeof(KDTreeNearest_3d) * n, __func__);
|
||||
nearest = MEM_mallocN(sizeof(KDTreeNearest_3d) * n, __func__);
|
||||
|
||||
found = BLI_kdtree_3d_find_nearest_n(self->obj, co, nearest, n);
|
||||
found = BLI_kdtree_3d_find_nearest_n(self->obj, co, nearest, n);
|
||||
|
||||
py_list = PyList_New(found);
|
||||
py_list = PyList_New(found);
|
||||
|
||||
for (i = 0; i < found; i++) {
|
||||
PyList_SET_ITEM(py_list, i, kdtree_nearest_to_py(&nearest[i]));
|
||||
}
|
||||
for (i = 0; i < found; i++) {
|
||||
PyList_SET_ITEM(py_list, i, kdtree_nearest_to_py(&nearest[i]));
|
||||
}
|
||||
|
||||
MEM_freeN(nearest);
|
||||
MEM_freeN(nearest);
|
||||
|
||||
return py_list;
|
||||
return py_list;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(py_kdtree_find_range_doc,
|
||||
".. method:: find_range(co, radius)\n"
|
||||
"\n"
|
||||
" Find all points within ``radius`` of ``co``.\n"
|
||||
"\n"
|
||||
" :arg co: 3d coordinates.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg radius: Distance to search for points.\n"
|
||||
" :type radius: float\n"
|
||||
" :return: Returns a list of tuples (:class:`Vector`, index, distance).\n"
|
||||
" :rtype: :class:`list`\n"
|
||||
);
|
||||
".. method:: find_range(co, radius)\n"
|
||||
"\n"
|
||||
" Find all points within ``radius`` of ``co``.\n"
|
||||
"\n"
|
||||
" :arg co: 3d coordinates.\n"
|
||||
" :type co: float triplet\n"
|
||||
" :arg radius: Distance to search for points.\n"
|
||||
" :type radius: float\n"
|
||||
" :return: Returns a list of tuples (:class:`Vector`, index, distance).\n"
|
||||
" :rtype: :class:`list`\n");
|
||||
static PyObject *py_kdtree_find_range(PyKDTree *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
PyObject *py_list;
|
||||
PyObject *py_co;
|
||||
float co[3];
|
||||
KDTreeNearest_3d *nearest = NULL;
|
||||
float radius;
|
||||
int i, found;
|
||||
PyObject *py_list;
|
||||
PyObject *py_co;
|
||||
float co[3];
|
||||
KDTreeNearest_3d *nearest = NULL;
|
||||
float radius;
|
||||
int i, found;
|
||||
|
||||
const char *keywords[] = {"co", "radius", NULL};
|
||||
const char *keywords[] = {"co", "radius", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *) "Of:find_range", (char **)keywords,
|
||||
&py_co, &radius))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kwargs, (char *)"Of:find_range", (char **)keywords, &py_co, &radius)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "find_range: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (mathutils_array_parse(co, 3, 3, py_co, "find_range: invalid 'co' arg") == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (radius < 0.0f) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "negative radius given");
|
||||
return NULL;
|
||||
}
|
||||
if (radius < 0.0f) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "negative radius given");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->count != self->count_balance) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find_range()");
|
||||
return NULL;
|
||||
}
|
||||
if (self->count != self->count_balance) {
|
||||
PyErr_SetString(PyExc_RuntimeError, "KDTree must be balanced before calling find_range()");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
found = BLI_kdtree_3d_range_search(self->obj, co, &nearest, radius);
|
||||
found = BLI_kdtree_3d_range_search(self->obj, co, &nearest, radius);
|
||||
|
||||
py_list = PyList_New(found);
|
||||
py_list = PyList_New(found);
|
||||
|
||||
for (i = 0; i < found; i++) {
|
||||
PyList_SET_ITEM(py_list, i, kdtree_nearest_to_py(&nearest[i]));
|
||||
}
|
||||
for (i = 0; i < found; i++) {
|
||||
PyList_SET_ITEM(py_list, i, kdtree_nearest_to_py(&nearest[i]));
|
||||
}
|
||||
|
||||
if (nearest) {
|
||||
MEM_freeN(nearest);
|
||||
}
|
||||
if (nearest) {
|
||||
MEM_freeN(nearest);
|
||||
}
|
||||
|
||||
return py_list;
|
||||
return py_list;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PyKDTree_methods[] = {
|
||||
{"insert", (PyCFunction)py_kdtree_insert, METH_VARARGS | METH_KEYWORDS, py_kdtree_insert_doc},
|
||||
{"balance", (PyCFunction)py_kdtree_balance, METH_NOARGS, py_kdtree_balance_doc},
|
||||
{"find", (PyCFunction)py_kdtree_find, METH_VARARGS | METH_KEYWORDS, py_kdtree_find_doc},
|
||||
{"find_n", (PyCFunction)py_kdtree_find_n, METH_VARARGS | METH_KEYWORDS, py_kdtree_find_n_doc},
|
||||
{"find_range", (PyCFunction)py_kdtree_find_range, METH_VARARGS | METH_KEYWORDS, py_kdtree_find_range_doc},
|
||||
{NULL, NULL, 0, NULL},
|
||||
{"insert", (PyCFunction)py_kdtree_insert, METH_VARARGS | METH_KEYWORDS, py_kdtree_insert_doc},
|
||||
{"balance", (PyCFunction)py_kdtree_balance, METH_NOARGS, py_kdtree_balance_doc},
|
||||
{"find", (PyCFunction)py_kdtree_find, METH_VARARGS | METH_KEYWORDS, py_kdtree_find_doc},
|
||||
{"find_n", (PyCFunction)py_kdtree_find_n, METH_VARARGS | METH_KEYWORDS, py_kdtree_find_n_doc},
|
||||
{"find_range",
|
||||
(PyCFunction)py_kdtree_find_range,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
py_kdtree_find_range_doc},
|
||||
{NULL, NULL, 0, NULL},
|
||||
};
|
||||
|
||||
PyDoc_STRVAR(py_KDtree_doc,
|
||||
"KdTree(size) -> new kd-tree initialized to hold ``size`` items.\n"
|
||||
"\n"
|
||||
".. note::\n"
|
||||
"\n"
|
||||
" :class:`KDTree.balance` must have been called before using any of the ``find`` methods.\n"
|
||||
);
|
||||
"KdTree(size) -> new kd-tree initialized to hold ``size`` items.\n"
|
||||
"\n"
|
||||
".. note::\n"
|
||||
"\n"
|
||||
" :class:`KDTree.balance` must have been called before using any of the ``find`` "
|
||||
"methods.\n");
|
||||
PyTypeObject PyKDTree_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"KDTree", /* tp_name */
|
||||
sizeof(PyKDTree), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)PyKDTree__tp_dealloc, /* tp_dealloc */
|
||||
NULL, /* tp_print */
|
||||
NULL, /* tp_getattr */
|
||||
NULL, /* tp_setattr */
|
||||
NULL, /* tp_compare */
|
||||
NULL, /* tp_repr */
|
||||
NULL, /* tp_as_number */
|
||||
NULL, /* tp_as_sequence */
|
||||
NULL, /* tp_as_mapping */
|
||||
NULL, /* tp_hash */
|
||||
NULL, /* tp_call */
|
||||
NULL, /* tp_str */
|
||||
NULL, /* tp_getattro */
|
||||
NULL, /* tp_setattro */
|
||||
NULL, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
py_KDtree_doc, /* Documentation string */
|
||||
NULL, /* tp_traverse */
|
||||
NULL, /* tp_clear */
|
||||
NULL, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
NULL, /* tp_iter */
|
||||
NULL, /* tp_iternext */
|
||||
(struct PyMethodDef *)PyKDTree_methods, /* tp_methods */
|
||||
NULL, /* tp_members */
|
||||
NULL, /* tp_getset */
|
||||
NULL, /* tp_base */
|
||||
NULL, /* tp_dict */
|
||||
NULL, /* tp_descr_get */
|
||||
NULL, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PyKDTree__tp_init, /* tp_init */
|
||||
(allocfunc)PyType_GenericAlloc, /* tp_alloc */
|
||||
(newfunc)PyType_GenericNew, /* tp_new */
|
||||
(freefunc)0, /* tp_free */
|
||||
NULL, /* tp_is_gc */
|
||||
NULL, /* tp_bases */
|
||||
NULL, /* tp_mro */
|
||||
NULL, /* tp_cache */
|
||||
NULL, /* tp_subclasses */
|
||||
NULL, /* tp_weaklist */
|
||||
(destructor)NULL, /* tp_del */
|
||||
PyVarObject_HEAD_INIT(NULL, 0) "KDTree", /* tp_name */
|
||||
sizeof(PyKDTree), /* tp_basicsize */
|
||||
0, /* tp_itemsize */
|
||||
/* methods */
|
||||
(destructor)PyKDTree__tp_dealloc, /* tp_dealloc */
|
||||
NULL, /* tp_print */
|
||||
NULL, /* tp_getattr */
|
||||
NULL, /* tp_setattr */
|
||||
NULL, /* tp_compare */
|
||||
NULL, /* tp_repr */
|
||||
NULL, /* tp_as_number */
|
||||
NULL, /* tp_as_sequence */
|
||||
NULL, /* tp_as_mapping */
|
||||
NULL, /* tp_hash */
|
||||
NULL, /* tp_call */
|
||||
NULL, /* tp_str */
|
||||
NULL, /* tp_getattro */
|
||||
NULL, /* tp_setattro */
|
||||
NULL, /* tp_as_buffer */
|
||||
Py_TPFLAGS_DEFAULT, /* tp_flags */
|
||||
py_KDtree_doc, /* Documentation string */
|
||||
NULL, /* tp_traverse */
|
||||
NULL, /* tp_clear */
|
||||
NULL, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
NULL, /* tp_iter */
|
||||
NULL, /* tp_iternext */
|
||||
(struct PyMethodDef *)PyKDTree_methods, /* tp_methods */
|
||||
NULL, /* tp_members */
|
||||
NULL, /* tp_getset */
|
||||
NULL, /* tp_base */
|
||||
NULL, /* tp_dict */
|
||||
NULL, /* tp_descr_get */
|
||||
NULL, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PyKDTree__tp_init, /* tp_init */
|
||||
(allocfunc)PyType_GenericAlloc, /* tp_alloc */
|
||||
(newfunc)PyType_GenericNew, /* tp_new */
|
||||
(freefunc)0, /* tp_free */
|
||||
NULL, /* tp_is_gc */
|
||||
NULL, /* tp_bases */
|
||||
NULL, /* tp_mro */
|
||||
NULL, /* tp_cache */
|
||||
NULL, /* tp_subclasses */
|
||||
NULL, /* tp_weaklist */
|
||||
(destructor)NULL, /* tp_del */
|
||||
};
|
||||
|
||||
PyDoc_STRVAR(py_kdtree_doc,
|
||||
"Generic 3-dimentional kd-tree to perform spatial searches."
|
||||
);
|
||||
PyDoc_STRVAR(py_kdtree_doc, "Generic 3-dimentional kd-tree to perform spatial searches.");
|
||||
static struct PyModuleDef kdtree_moduledef = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"mathutils.kdtree", /* m_name */
|
||||
py_kdtree_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
NULL, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
NULL, /* m_traverse */
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"mathutils.kdtree", /* m_name */
|
||||
py_kdtree_doc, /* m_doc */
|
||||
0, /* m_size */
|
||||
NULL, /* m_methods */
|
||||
NULL, /* m_reload */
|
||||
NULL, /* m_traverse */
|
||||
NULL, /* m_clear */
|
||||
NULL, /* m_free */
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_mathutils_kdtree(void)
|
||||
{
|
||||
PyObject *m = PyModule_Create(&kdtree_moduledef);
|
||||
PyObject *m = PyModule_Create(&kdtree_moduledef);
|
||||
|
||||
if (m == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
if (m == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Register the 'KDTree' class */
|
||||
if (PyType_Ready(&PyKDTree_Type)) {
|
||||
return NULL;
|
||||
}
|
||||
PyModule_AddObject(m, "KDTree", (PyObject *) &PyKDTree_Type);
|
||||
/* Register the 'KDTree' class */
|
||||
if (PyType_Ready(&PyKDTree_Type)) {
|
||||
return NULL;
|
||||
}
|
||||
PyModule_AddObject(m, "KDTree", (PyObject *)&PyKDTree_Type);
|
||||
|
||||
return m;
|
||||
return m;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
/** \file
|
||||
* \ingroup mathutils
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user