Cleanup: use "num" as a suffix in: source/blender/python
See T85728
This commit is contained in:
parent
77155ae1c0
commit
83c274ccfc
|
@ -569,7 +569,7 @@ bool Vec3r_ptr_from_PyObject(PyObject *obj, Vec3r &vec)
|
|||
|
||||
bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f &vec)
|
||||
{
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 2) {
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->vec_num != 2) {
|
||||
return false;
|
||||
}
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) {
|
||||
|
@ -582,7 +582,7 @@ bool Vec2f_ptr_from_Vector(PyObject *obj, Vec2f &vec)
|
|||
|
||||
bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f &vec)
|
||||
{
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) {
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->vec_num != 3) {
|
||||
return false;
|
||||
}
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) {
|
||||
|
@ -596,7 +596,7 @@ bool Vec3f_ptr_from_Vector(PyObject *obj, Vec3f &vec)
|
|||
|
||||
bool Vec3r_ptr_from_Vector(PyObject *obj, Vec3r &vec)
|
||||
{
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->size != 3) {
|
||||
if (!VectorObject_Check(obj) || ((VectorObject *)obj)->vec_num != 3) {
|
||||
return false;
|
||||
}
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) {
|
||||
|
@ -758,7 +758,7 @@ bool Vec3r_ptr_from_PyTuple(PyObject *obj, Vec3r &vec)
|
|||
|
||||
bool float_array_from_PyObject(PyObject *obj, float *v, int n)
|
||||
{
|
||||
if (VectorObject_Check(obj) && ((VectorObject *)obj)->size == n) {
|
||||
if (VectorObject_Check(obj) && ((VectorObject *)obj)->vec_num == n) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)obj) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -233,8 +233,8 @@ static int bpy_slot_from_py(BMesh *bm,
|
|||
if (!Matrix_ParseAny(value, &pymat)) {
|
||||
return -1;
|
||||
}
|
||||
const ushort size = pymat->num_col;
|
||||
if ((size != pymat->num_row) || (!ELEM(size, 3, 4))) {
|
||||
const ushort size = pymat->col_num;
|
||||
if ((size != pymat->row_num) || (!ELEM(size, 3, 4))) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: keyword \"%.200s\" expected a 3x3 or 4x4 matrix",
|
||||
opname,
|
||||
|
|
|
@ -1309,7 +1309,7 @@ static PyObject *bpy_bmesh_transform(BPy_BMElem *self, PyObject *args, PyObject
|
|||
if (BaseMath_ReadCallback(mat) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if (mat->num_col != 4 || mat->num_row != 4) {
|
||||
if (mat->col_num != 4 || mat->row_num != 4) {
|
||||
PyErr_SetString(PyExc_ValueError, "expected a 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -381,11 +381,11 @@ static PyObject *pygpu_shader_uniform_float(BPyGPUShader *self, PyObject *args)
|
|||
if (BaseMath_ReadCallback(mat) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
if ((mat->num_row != mat->num_col) || !ELEM(mat->num_row, 3, 4)) {
|
||||
if ((mat->row_num != mat->col_num) || !ELEM(mat->row_num, 3, 4)) {
|
||||
PyErr_SetString(PyExc_ValueError, "Expected 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
length = mat->num_row * mat->num_col;
|
||||
length = mat->row_num * mat->col_num;
|
||||
memcpy(values, mat->matrix, sizeof(float) * length);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
void bpy_app_generic_callback(struct Main *main,
|
||||
struct PointerRNA **pointers,
|
||||
const int num_pointers,
|
||||
const int pointers_num,
|
||||
void *arg);
|
||||
|
||||
static PyTypeObject BlenderAppCbType;
|
||||
|
@ -305,7 +305,7 @@ static PyObject *choose_arguments(PyObject *func, PyObject *args_all, PyObject *
|
|||
/* the actual callback - not necessarily called from py */
|
||||
void bpy_app_generic_callback(struct Main *UNUSED(main),
|
||||
struct PointerRNA **pointers,
|
||||
const int num_pointers,
|
||||
const int pointers_num,
|
||||
void *arg)
|
||||
{
|
||||
PyObject *cb_list = py_cb_array[POINTER_AS_INT(arg)];
|
||||
|
@ -320,14 +320,14 @@ void bpy_app_generic_callback(struct Main *UNUSED(main),
|
|||
Py_ssize_t pos;
|
||||
|
||||
/* setup arguments */
|
||||
for (int i = 0; i < num_pointers; ++i) {
|
||||
for (int i = 0; i < pointers_num; ++i) {
|
||||
PyTuple_SET_ITEM(args_all, i, pyrna_struct_CreatePyObject(pointers[i]));
|
||||
}
|
||||
for (int i = num_pointers; i < num_arguments; ++i) {
|
||||
for (int i = pointers_num; i < num_arguments; ++i) {
|
||||
PyTuple_SET_ITEM(args_all, i, Py_INCREF_RET(Py_None));
|
||||
}
|
||||
|
||||
if (num_pointers == 0) {
|
||||
if (pointers_num == 0) {
|
||||
PyTuple_SET_ITEM(args_single, 0, Py_INCREF_RET(Py_None));
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -377,15 +377,15 @@ static int validate_array(PyObject *rvalue,
|
|||
totdim);
|
||||
return -1;
|
||||
}
|
||||
if (pymat->num_col != dimsize[0] || pymat->num_row != dimsize[1]) {
|
||||
if (pymat->col_num != dimsize[0] || pymat->row_num != dimsize[1]) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s %.200s.%.200s, matrix assign dimension size mismatch, "
|
||||
"is %dx%d, expected be %dx%d",
|
||||
error_prefix,
|
||||
RNA_struct_identifier(ptr->type),
|
||||
RNA_property_identifier(prop),
|
||||
pymat->num_col,
|
||||
pymat->num_row,
|
||||
pymat->col_num,
|
||||
pymat->row_num,
|
||||
dimsize[0],
|
||||
dimsize[1]);
|
||||
return -1;
|
||||
|
@ -473,7 +473,7 @@ static char *copy_values(PyObject *seq,
|
|||
if (dim == 0) {
|
||||
if (MatrixObject_Check(seq)) {
|
||||
MatrixObject *pymat = (MatrixObject *)seq;
|
||||
const size_t allocsize = pymat->num_col * pymat->num_row * sizeof(float);
|
||||
const size_t allocsize = pymat->col_num * pymat->row_num * sizeof(float);
|
||||
|
||||
/* read callback already done by validate */
|
||||
/* since this is the first iteration we can assume data is allocated */
|
||||
|
|
|
@ -92,47 +92,46 @@ Py_hash_t mathutils_array_hash(const float *array, size_t array_len)
|
|||
}
|
||||
|
||||
int mathutils_array_parse(
|
||||
float *array, int array_min, int array_max, PyObject *value, const char *error_prefix)
|
||||
float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix)
|
||||
{
|
||||
const uint flag = array_max;
|
||||
int size;
|
||||
const uint flag = array_num_max;
|
||||
int num;
|
||||
|
||||
array_max &= ~MU_ARRAY_FLAGS;
|
||||
array_num_max &= ~MU_ARRAY_FLAGS;
|
||||
|
||||
#if 1 /* approx 6x speedup for mathutils types */
|
||||
|
||||
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
||||
(size = EulerObject_Check(value) ? 3 : 0) ||
|
||||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(size = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if ((num = VectorObject_Check(value) ? ((VectorObject *)value)->vec_num : 0) ||
|
||||
(num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(num = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (flag & MU_ARRAY_SPILL) {
|
||||
CLAMP_MAX(size, array_max);
|
||||
CLAMP_MAX(num, array_num_max);
|
||||
}
|
||||
|
||||
if (size > array_max || size < array_min) {
|
||||
if (array_max == array_min) {
|
||||
if (num > array_num_max || num < array_num_min) {
|
||||
if (array_num_max == array_num_min) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected %d",
|
||||
"%.200s: sequence length is %d, expected %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_max);
|
||||
num,
|
||||
array_num_max);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected [%d - %d]",
|
||||
"%.200s: sequence length is %d, expected [%d - %d]",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min,
|
||||
array_max);
|
||||
num,
|
||||
array_num_min,
|
||||
array_num_max);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(array, ((const BaseMathObject *)value)->data, size * sizeof(float));
|
||||
memcpy(array, ((const BaseMathObject *)value)->data, num * sizeof(float));
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
@ -145,77 +144,76 @@ int mathutils_array_parse(
|
|||
return -1;
|
||||
}
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
num = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (flag & MU_ARRAY_SPILL) {
|
||||
CLAMP_MAX(size, array_max);
|
||||
CLAMP_MAX(num, array_num_max);
|
||||
}
|
||||
|
||||
if (size > array_max || size < array_min) {
|
||||
if (array_max == array_min) {
|
||||
if (num > array_num_max || num < array_num_min) {
|
||||
if (array_num_max == array_num_min) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected %d",
|
||||
"%.200s: sequence length is %d, expected %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_max);
|
||||
num,
|
||||
array_num_max);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected [%d - %d]",
|
||||
"%.200s: sequence length is %d, expected [%d - %d]",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min,
|
||||
array_max);
|
||||
num,
|
||||
array_num_min,
|
||||
array_num_max);
|
||||
}
|
||||
Py_DECREF(value_fast);
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = mathutils_array_parse_fast(array, size, value_fast, error_prefix);
|
||||
num = mathutils_array_parse_fast(array, num, value_fast, error_prefix);
|
||||
Py_DECREF(value_fast);
|
||||
}
|
||||
|
||||
if (size != -1) {
|
||||
if (num != -1) {
|
||||
if (flag & MU_ARRAY_ZERO) {
|
||||
const int size_left = array_max - size;
|
||||
if (size_left) {
|
||||
memset(&array[size], 0, sizeof(float) * size_left);
|
||||
const int array_num_left = array_num_max - num;
|
||||
if (array_num_left) {
|
||||
memset(&array[num], 0, sizeof(float) * array_num_left);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
return num;
|
||||
}
|
||||
|
||||
int mathutils_array_parse_alloc(float **array,
|
||||
int array_min,
|
||||
int array_num,
|
||||
PyObject *value,
|
||||
const char *error_prefix)
|
||||
{
|
||||
int size;
|
||||
int num;
|
||||
|
||||
#if 1 /* approx 6x speedup for mathutils types */
|
||||
|
||||
if ((size = VectorObject_Check(value) ? ((VectorObject *)value)->size : 0) ||
|
||||
(size = EulerObject_Check(value) ? 3 : 0) ||
|
||||
(size = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(size = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if ((num = VectorObject_Check(value) ? ((VectorObject *)value)->vec_num : 0) ||
|
||||
(num = EulerObject_Check(value) ? 3 : 0) || (num = QuaternionObject_Check(value) ? 4 : 0) ||
|
||||
(num = ColorObject_Check(value) ? 3 : 0)) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (size < array_min) {
|
||||
if (num < array_num) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected > %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min);
|
||||
num,
|
||||
array_num);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*array = PyMem_Malloc(size * sizeof(float));
|
||||
memcpy(*array, ((const BaseMathObject *)value)->data, size * sizeof(float));
|
||||
return size;
|
||||
*array = PyMem_Malloc(num * sizeof(float));
|
||||
memcpy(*array, ((const BaseMathObject *)value)->data, num * sizeof(float));
|
||||
return num;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -230,21 +228,21 @@ int mathutils_array_parse_alloc(float **array,
|
|||
return -1;
|
||||
}
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
num = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (size < array_min) {
|
||||
if (num < array_num) {
|
||||
Py_DECREF(value_fast);
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected > %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min);
|
||||
num,
|
||||
array_num);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*array = PyMem_Malloc(size * sizeof(float));
|
||||
*array = PyMem_Malloc(num * sizeof(float));
|
||||
|
||||
ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix);
|
||||
ret = mathutils_array_parse_fast(*array, num, value_fast, error_prefix);
|
||||
Py_DECREF(value_fast);
|
||||
|
||||
if (ret == -1) {
|
||||
|
@ -261,7 +259,7 @@ int mathutils_array_parse_alloc_v(float **array,
|
|||
{
|
||||
PyObject *value_fast;
|
||||
const int array_dim_flag = array_dim;
|
||||
int i, size;
|
||||
int i, num;
|
||||
|
||||
/* non list/tuple cases */
|
||||
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
|
||||
|
@ -269,30 +267,30 @@ int mathutils_array_parse_alloc_v(float **array,
|
|||
return -1;
|
||||
}
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
num = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (size != 0) {
|
||||
if (num != 0) {
|
||||
PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
|
||||
float *fp;
|
||||
|
||||
array_dim &= ~MU_ARRAY_FLAGS;
|
||||
|
||||
fp = *array = PyMem_Malloc(size * array_dim * sizeof(float));
|
||||
fp = *array = PyMem_Malloc(num * array_dim * sizeof(float));
|
||||
|
||||
for (i = 0; i < size; i++, fp += array_dim) {
|
||||
for (i = 0; i < num; i++, fp += array_dim) {
|
||||
PyObject *item = value_fast_items[i];
|
||||
|
||||
if (mathutils_array_parse(fp, array_dim, array_dim_flag, item, error_prefix) == -1) {
|
||||
PyMem_Free(*array);
|
||||
*array = NULL;
|
||||
size = -1;
|
||||
num = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Py_DECREF(value_fast);
|
||||
return size;
|
||||
return num;
|
||||
}
|
||||
|
||||
int mathutils_int_array_parse(int *array, int array_dim, PyObject *value, const char *error_prefix)
|
||||
|
@ -458,7 +456,7 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
|
|||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) {
|
||||
if (((MatrixObject *)value)->row_num < 3 || ((MatrixObject *)value)->col_num < 3) {
|
||||
PyErr_Format(
|
||||
PyExc_ValueError, "%.200s: matrix must have minimum 3x3 dimensions", error_prefix);
|
||||
return -1;
|
||||
|
|
|
@ -153,12 +153,12 @@ void _BaseMathObject_RaiseNotFrozenExc(const BaseMathObject *self);
|
|||
* \return length of `value`, -1 on error.
|
||||
*/
|
||||
int mathutils_array_parse(
|
||||
float *array, int array_min, int array_max, PyObject *value, const char *error_prefix);
|
||||
float *array, int array_num_min, int array_num_max, PyObject *value, const char *error_prefix);
|
||||
/**
|
||||
* \return -1 is returned on error and no allocation is made.
|
||||
*/
|
||||
int mathutils_array_parse_alloc(float **array,
|
||||
int array_min,
|
||||
int array_num_min,
|
||||
PyObject *value,
|
||||
const char *error_prefix);
|
||||
/**
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -20,14 +20,14 @@ typedef unsigned short ushort;
|
|||
|
||||
#ifdef DEBUG
|
||||
# define MATRIX_ITEM_ASSERT(_mat, _row, _col) \
|
||||
(BLI_assert(_row < (_mat)->num_row && _col < (_mat)->num_col))
|
||||
(BLI_assert(_row < (_mat)->row_num && _col < (_mat)->col_num))
|
||||
#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)))
|
||||
(MATRIX_ITEM_ASSERT(_mat, _row, _col), (((_mat)->row_num * (_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)])
|
||||
|
||||
|
@ -36,8 +36,8 @@ typedef unsigned short ushort;
|
|||
|
||||
typedef struct {
|
||||
BASE_MATH_MEMBERS(matrix);
|
||||
ushort num_col;
|
||||
ushort num_row;
|
||||
ushort col_num;
|
||||
ushort row_num;
|
||||
} MatrixObject;
|
||||
|
||||
/* struct data contains a pointer to the actual data that the
|
||||
|
@ -47,17 +47,17 @@ typedef struct {
|
|||
|
||||
/* prototypes */
|
||||
PyObject *Matrix_CreatePyObject(const float *mat,
|
||||
ushort num_col,
|
||||
ushort num_row,
|
||||
ushort col_num,
|
||||
ushort row_num,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
PyObject *Matrix_CreatePyObject_wrap(float *mat,
|
||||
ushort num_col,
|
||||
ushort num_row,
|
||||
ushort col_num,
|
||||
ushort row_num,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
PyObject *Matrix_CreatePyObject_cb(PyObject *user,
|
||||
unsigned short num_col,
|
||||
unsigned short num_row,
|
||||
unsigned short col_num,
|
||||
unsigned short row_num,
|
||||
unsigned char cb_type,
|
||||
unsigned char cb_subtype) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
|
@ -65,8 +65,8 @@ PyObject *Matrix_CreatePyObject_cb(PyObject *user,
|
|||
* \param mat: Initialized matrix value to use in-place, allocated with #PyMem_Malloc
|
||||
*/
|
||||
PyObject *Matrix_CreatePyObject_alloc(float *mat,
|
||||
ushort num_col,
|
||||
ushort num_row,
|
||||
ushort col_num,
|
||||
ushort row_num,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
|
||||
/* PyArg_ParseTuple's "O&" formatting helpers. */
|
||||
|
|
|
@ -1035,7 +1035,7 @@ static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2)
|
|||
VectorObject *vec2 = (VectorObject *)q2;
|
||||
float tvec[3];
|
||||
|
||||
if (vec2->size != 3) {
|
||||
if (vec2->vec_num != 3) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector multiplication: "
|
||||
"only 3D vector rotations (with quats) "
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -14,12 +14,13 @@ extern PyTypeObject vector_Type;
|
|||
typedef struct {
|
||||
BASE_MATH_MEMBERS(vec);
|
||||
|
||||
int size; /* vec size 2 or more */
|
||||
/** Number of items in this vector (2 or more). */
|
||||
int vec_num;
|
||||
} VectorObject;
|
||||
|
||||
/*prototypes*/
|
||||
PyObject *Vector_CreatePyObject(const float *vec,
|
||||
int size,
|
||||
int vec_num,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT;
|
||||
/**
|
||||
* Create a vector that wraps existing memory.
|
||||
|
@ -27,7 +28,7 @@ PyObject *Vector_CreatePyObject(const float *vec,
|
|||
* \param vec: Use this vector in-place.
|
||||
*/
|
||||
PyObject *Vector_CreatePyObject_wrap(float *vec,
|
||||
int size,
|
||||
int vec_num,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
/**
|
||||
|
@ -35,13 +36,13 @@ PyObject *Vector_CreatePyObject_wrap(float *vec,
|
|||
* see: #Mathutils_RegisterCallback
|
||||
*/
|
||||
PyObject *Vector_CreatePyObject_cb(PyObject *user,
|
||||
int size,
|
||||
int vec_num,
|
||||
unsigned char cb_type,
|
||||
unsigned char subtype) ATTR_WARN_UNUSED_RESULT;
|
||||
/**
|
||||
* \param vec: Initialized vector value to use in-place, allocated with #PyMem_Malloc
|
||||
*/
|
||||
PyObject *Vector_CreatePyObject_alloc(float *vec,
|
||||
int size,
|
||||
int vec_num,
|
||||
PyTypeObject *base_type) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL(1);
|
||||
|
|
|
@ -158,24 +158,30 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject
|
|||
PyObject *tuple;
|
||||
PyObject *py_lines[4];
|
||||
float lines[4][3], i1[3], i2[3];
|
||||
int len;
|
||||
int ix_vec_num;
|
||||
int result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOOO:intersect_line_line", UNPACK4_EX(&, py_lines, ))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((((len = mathutils_array_parse(
|
||||
if ((((ix_vec_num = mathutils_array_parse(
|
||||
lines[0], 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[0], error_prefix)) != -1) &&
|
||||
(mathutils_array_parse(
|
||||
lines[1], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[1], error_prefix) !=
|
||||
-1) &&
|
||||
(mathutils_array_parse(
|
||||
lines[2], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[2], error_prefix) !=
|
||||
-1) &&
|
||||
(mathutils_array_parse(
|
||||
lines[3], len, len | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_lines[3], error_prefix) !=
|
||||
-1)) == 0) {
|
||||
(mathutils_array_parse(lines[1],
|
||||
ix_vec_num,
|
||||
ix_vec_num | MU_ARRAY_SPILL | MU_ARRAY_ZERO,
|
||||
py_lines[1],
|
||||
error_prefix) != -1) &&
|
||||
(mathutils_array_parse(lines[2],
|
||||
ix_vec_num,
|
||||
ix_vec_num | MU_ARRAY_SPILL | MU_ARRAY_ZERO,
|
||||
py_lines[2],
|
||||
error_prefix) != -1) &&
|
||||
(mathutils_array_parse(lines[3],
|
||||
ix_vec_num,
|
||||
ix_vec_num | MU_ARRAY_SPILL | MU_ARRAY_ZERO,
|
||||
py_lines[3],
|
||||
error_prefix) != -1)) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -192,8 +198,9 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject
|
|||
}
|
||||
|
||||
tuple = PyTuple_New(2);
|
||||
PyTuple_SET_ITEMS(
|
||||
tuple, Vector_CreatePyObject(i1, len, NULL), Vector_CreatePyObject(i2, len, NULL));
|
||||
PyTuple_SET_ITEMS(tuple,
|
||||
Vector_CreatePyObject(i1, ix_vec_num, NULL),
|
||||
Vector_CreatePyObject(i2, ix_vec_num, NULL));
|
||||
return tuple;
|
||||
}
|
||||
|
||||
|
@ -764,14 +771,14 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec
|
|||
float pt[3], pt_out[3], line_a[3], line_b[3];
|
||||
float lambda;
|
||||
PyObject *ret;
|
||||
int size = 2;
|
||||
int pt_num = 2;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OOO:intersect_point_line", &py_pt, &py_line_a, &py_line_b)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* accept 2d verts */
|
||||
if ((((size = mathutils_array_parse(
|
||||
if ((((pt_num = mathutils_array_parse(
|
||||
pt, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_pt, error_prefix)) != -1) &&
|
||||
(mathutils_array_parse(
|
||||
line_a, 2, 3 | MU_ARRAY_SPILL | MU_ARRAY_ZERO, py_line_a, error_prefix) != -1) &&
|
||||
|
@ -784,7 +791,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec
|
|||
lambda = closest_to_line_v3(pt_out, pt, line_a, line_b);
|
||||
|
||||
ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEMS(ret, Vector_CreatePyObject(pt_out, size, NULL), PyFloat_FromDouble(lambda));
|
||||
PyTuple_SET_ITEMS(ret, Vector_CreatePyObject(pt_out, pt_num, NULL), PyFloat_FromDouble(lambda));
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -305,23 +305,24 @@ static PyObject *M_Noise_random_unit_vector(PyObject *UNUSED(self), PyObject *ar
|
|||
static const char *kwlist[] = {"size", NULL};
|
||||
float vec[4] = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
float norm = 2.0f;
|
||||
int size = 3;
|
||||
int vec_num = 3;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|$i:random_unit_vector", (char **)kwlist, &size)) {
|
||||
if (!PyArg_ParseTupleAndKeywords(
|
||||
args, kw, "|$i:random_unit_vector", (char **)kwlist, &vec_num)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size > 4 || size < 2) {
|
||||
if (vec_num > 4 || vec_num < 2) {
|
||||
PyErr_SetString(PyExc_ValueError, "Vector(): invalid size");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
while (norm == 0.0f || norm > 1.0f) {
|
||||
rand_vn(vec, size);
|
||||
norm = normalize_vn(vec, size);
|
||||
rand_vn(vec, vec_num);
|
||||
norm = normalize_vn(vec, vec_num);
|
||||
}
|
||||
|
||||
return Vector_CreatePyObject(vec, size, NULL);
|
||||
return Vector_CreatePyObject(vec, vec_num, NULL);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(M_Noise_random_vector_doc,
|
||||
|
@ -337,22 +338,22 @@ static PyObject *M_Noise_random_vector(PyObject *UNUSED(self), PyObject *args, P
|
|||
{
|
||||
static const char *kwlist[] = {"size", NULL};
|
||||
float *vec = NULL;
|
||||
int size = 3;
|
||||
int vec_num = 3;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|$i:random_vector", (char **)kwlist, &size)) {
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "|$i:random_vector", (char **)kwlist, &vec_num)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (size < 2) {
|
||||
if (vec_num < 2) {
|
||||
PyErr_SetString(PyExc_ValueError, "Vector(): invalid size");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
vec = PyMem_New(float, size);
|
||||
vec = PyMem_New(float, vec_num);
|
||||
|
||||
rand_vn(vec, size);
|
||||
rand_vn(vec, vec_num);
|
||||
|
||||
return Vector_CreatePyObject_alloc(vec, size, NULL);
|
||||
return Vector_CreatePyObject_alloc(vec, vec_num, NULL);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(M_Noise_seed_set_doc,
|
||||
|
|
Loading…
Reference in New Issue