Cleanup: Python, Clang-Tidy else-after-return fixes
This addresses warnings from Clang-Tidy's `readability-else-after-return` rule in the `source/blender/python` module. No functional changes.
This commit is contained in:
@@ -249,42 +249,41 @@ int mathutils_array_parse_alloc(float **array,
|
||||
memcpy(*array, ((BaseMathObject *)value)->data, size * sizeof(float));
|
||||
return size;
|
||||
}
|
||||
else
|
||||
|
||||
#endif
|
||||
{
|
||||
PyObject *value_fast = NULL;
|
||||
// *array = NULL;
|
||||
int ret;
|
||||
|
||||
/* non list/tuple cases */
|
||||
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
|
||||
/* PySequence_Fast sets the error */
|
||||
return -1;
|
||||
}
|
||||
PyObject *value_fast = NULL;
|
||||
// *array = NULL;
|
||||
int ret;
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (size < array_min) {
|
||||
Py_DECREF(value_fast);
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected > %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*array = PyMem_Malloc(size * sizeof(float));
|
||||
|
||||
ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix);
|
||||
Py_DECREF(value_fast);
|
||||
|
||||
if (ret == -1) {
|
||||
PyMem_Free(*array);
|
||||
}
|
||||
|
||||
return ret;
|
||||
/* non list/tuple cases */
|
||||
if (!(value_fast = PySequence_Fast(value, error_prefix))) {
|
||||
/* PySequence_Fast sets the error */
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = PySequence_Fast_GET_SIZE(value_fast);
|
||||
|
||||
if (size < array_min) {
|
||||
Py_DECREF(value_fast);
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%.200s: sequence size is %d, expected > %d",
|
||||
error_prefix,
|
||||
size,
|
||||
array_min);
|
||||
return -1;
|
||||
}
|
||||
|
||||
*array = PyMem_Malloc(size * sizeof(float));
|
||||
|
||||
ret = mathutils_array_parse_fast(*array, size, value_fast, error_prefix);
|
||||
Py_DECREF(value_fast);
|
||||
|
||||
if (ret == -1) {
|
||||
PyMem_Free(*array);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* parse an array of vectors */
|
||||
@@ -482,45 +481,41 @@ int mathutils_any_to_rotmat(float rmat[3][3], PyObject *value, const char *error
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
eulO_to_mat3(rmat, ((EulerObject *)value)->eul, ((EulerObject *)value)->order);
|
||||
return 0;
|
||||
}
|
||||
|
||||
eulO_to_mat3(rmat, ((EulerObject *)value)->eul, ((EulerObject *)value)->order);
|
||||
return 0;
|
||||
}
|
||||
else if (QuaternionObject_Check(value)) {
|
||||
if (QuaternionObject_Check(value)) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
float tquat[4];
|
||||
normalize_qt_qt(tquat, ((QuaternionObject *)value)->quat);
|
||||
quat_to_mat3(rmat, tquat);
|
||||
return 0;
|
||||
}
|
||||
|
||||
float tquat[4];
|
||||
normalize_qt_qt(tquat, ((QuaternionObject *)value)->quat);
|
||||
quat_to_mat3(rmat, tquat);
|
||||
return 0;
|
||||
}
|
||||
else if (MatrixObject_Check(value)) {
|
||||
if (MatrixObject_Check(value)) {
|
||||
if (BaseMath_ReadCallback((BaseMathObject *)value) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) {
|
||||
if (((MatrixObject *)value)->num_row < 3 || ((MatrixObject *)value)->num_col < 3) {
|
||||
PyErr_Format(
|
||||
PyExc_ValueError, "%.200s: matrix must have minimum 3x3 dimensions", error_prefix);
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
matrix_as_3x3(rmat, (MatrixObject *)value);
|
||||
normalize_m3(rmat);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: expected a Euler, Quaternion or Matrix type, "
|
||||
"found %.200s",
|
||||
error_prefix,
|
||||
Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
|
||||
matrix_as_3x3(rmat, (MatrixObject *)value);
|
||||
normalize_m3(rmat);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"%.200s: expected a Euler, Quaternion or Matrix type, "
|
||||
"found %.200s",
|
||||
error_prefix,
|
||||
Py_TYPE(value)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ----------------------------------MATRIX FUNCTIONS-------------------- */
|
||||
|
||||
@@ -347,7 +347,7 @@ static PyObject *Color_subscript(ColorObject *self, PyObject *item)
|
||||
}
|
||||
return Color_item(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -357,19 +357,17 @@ static PyObject *Color_subscript(ColorObject *self, PyObject *item)
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return Color_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with color");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with color");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *value)
|
||||
@@ -384,7 +382,7 @@ static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *valu
|
||||
}
|
||||
return Color_ass_item(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, COLOR_SIZE, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -394,16 +392,14 @@ static int Color_ass_subscript(ColorObject *self, PyObject *item, PyObject *valu
|
||||
if (step == 1) {
|
||||
return Color_ass_slice(self, start, stop, value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with color");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with color");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "color indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -----------------PROTCOL DECLARATIONS-------------------------- */
|
||||
|
||||
@@ -558,7 +558,7 @@ static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
|
||||
}
|
||||
return Euler_item(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -568,19 +568,17 @@ static PyObject *Euler_subscript(EulerObject *self, PyObject *item)
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return Euler_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with eulers");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with eulers");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *value)
|
||||
@@ -595,7 +593,7 @@ static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *valu
|
||||
}
|
||||
return Euler_ass_item(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, EULER_SIZE, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -605,16 +603,14 @@ static int Euler_ass_subscript(EulerObject *self, PyObject *item, PyObject *valu
|
||||
if (step == 1) {
|
||||
return Euler_ass_slice(self, start, stop, value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with euler");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with euler");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "euler indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -----------------PROTCOL DECLARATIONS-------------------------- */
|
||||
|
||||
@@ -54,9 +54,8 @@ static int matrix_row_vector_check(MatrixObject *mat, VectorObject *vec, int row
|
||||
"owner matrix has been resized since this row vector was created");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col)
|
||||
@@ -67,9 +66,8 @@ static int matrix_col_vector_check(MatrixObject *mat, VectorObject *vec, int col
|
||||
"owner matrix has been resized since this column vector was created");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
@@ -380,9 +378,8 @@ static PyObject *Matrix_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
if (Matrix_ass_slice((MatrixObject *)matrix, 0, INT_MAX, arg) == 0) {
|
||||
return matrix;
|
||||
}
|
||||
else { /* matrix ok, slice assignment not */
|
||||
Py_DECREF(matrix);
|
||||
}
|
||||
/* matrix ok, slice assignment not */
|
||||
Py_DECREF(matrix);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -406,15 +403,13 @@ static PyObject *matrix__apply_to_copy(PyObject *(*matrix_func)(MatrixObject *),
|
||||
Py_DECREF(ret_dummy);
|
||||
return ret;
|
||||
}
|
||||
else { /* error */
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* copy may fail if the read callback errors out */
|
||||
/* error */
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* copy may fail if the read callback errors out */
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* when a matrix is 4x4 size but initialized as a 3x3, re-assign values for 4x4 */
|
||||
@@ -512,10 +507,9 @@ static PyObject *C_Matrix_Rotation(PyObject *cls, PyObject *args)
|
||||
"or a string in 'X', 'Y', 'Z'");
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
/* use the string */
|
||||
vec = NULL;
|
||||
}
|
||||
|
||||
/* use the string */
|
||||
vec = NULL;
|
||||
}
|
||||
|
||||
angle = angle_wrap_rad(angle);
|
||||
@@ -1023,7 +1017,7 @@ static float matrix_determinant_internal(const MatrixObject *self)
|
||||
MATRIX_ITEM(self, 1, 0),
|
||||
MATRIX_ITEM(self, 1, 1));
|
||||
}
|
||||
else if (self->num_col == 3) {
|
||||
if (self->num_col == 3) {
|
||||
return determinant_m3(MATRIX_ITEM(self, 0, 0),
|
||||
MATRIX_ITEM(self, 0, 1),
|
||||
MATRIX_ITEM(self, 0, 2),
|
||||
@@ -1034,9 +1028,8 @@ static float matrix_determinant_internal(const MatrixObject *self)
|
||||
MATRIX_ITEM(self, 2, 1),
|
||||
MATRIX_ITEM(self, 2, 2));
|
||||
}
|
||||
else {
|
||||
return determinant_m4((float(*)[4])self->matrix);
|
||||
}
|
||||
|
||||
return determinant_m4((float(*)[4])self->matrix);
|
||||
}
|
||||
|
||||
static void adjoint_matrix_n(float *mat_dst, const float *mat_src, const ushort dim)
|
||||
@@ -1094,9 +1087,8 @@ static bool matrix_invert_internal(const MatrixObject *self, float *r_mat)
|
||||
matrix_invert_with_det_n_internal(r_mat, self->matrix, det, self->num_col);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1475,9 +1467,8 @@ static bool matrix_invert_is_compat(const MatrixObject *self)
|
||||
"only square matrices are supported");
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool matrix_invert_args_check(const MatrixObject *self, PyObject *args, bool check_type)
|
||||
@@ -1605,10 +1596,9 @@ static PyObject *Matrix_inverted(MatrixObject *self, PyObject *args)
|
||||
Py_INCREF(fallback);
|
||||
return fallback;
|
||||
}
|
||||
else {
|
||||
matrix_invert_raise_degenerate();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
matrix_invert_raise_degenerate();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Matrix_copy_notest(self, mat);
|
||||
@@ -2386,48 +2376,47 @@ static int Matrix_ass_slice(MatrixObject *self, int begin, int end, PyObject *va
|
||||
/* PySequence_Fast sets the error */
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
|
||||
const int size = end - begin;
|
||||
int row, col;
|
||||
float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
|
||||
float vec[4];
|
||||
|
||||
if (PySequence_Fast_GET_SIZE(value_fast) != size) {
|
||||
PyObject **value_fast_items = PySequence_Fast_ITEMS(value_fast);
|
||||
const int size = end - begin;
|
||||
int row, col;
|
||||
float mat[MATRIX_MAX_DIM * MATRIX_MAX_DIM];
|
||||
float vec[4];
|
||||
|
||||
if (PySequence_Fast_GET_SIZE(value_fast) != size) {
|
||||
Py_DECREF(value_fast);
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"matrix[begin:end] = []: "
|
||||
"size mismatch in slice assignment");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(mat, self->matrix, self->num_col * self->num_row * sizeof(float));
|
||||
|
||||
/* parse sub items */
|
||||
for (row = begin; row < end; row++) {
|
||||
/* parse each sub sequence */
|
||||
PyObject *item = value_fast_items[row - begin];
|
||||
|
||||
if (mathutils_array_parse(
|
||||
vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") ==
|
||||
-1) {
|
||||
Py_DECREF(value_fast);
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"matrix[begin:end] = []: "
|
||||
"size mismatch in slice assignment");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(mat, self->matrix, self->num_col * self->num_row * sizeof(float));
|
||||
|
||||
/* parse sub items */
|
||||
for (row = begin; row < end; row++) {
|
||||
/* parse each sub sequence */
|
||||
PyObject *item = value_fast_items[row - begin];
|
||||
|
||||
if (mathutils_array_parse(
|
||||
vec, self->num_col, self->num_col, item, "matrix[begin:end] = value assignment") ==
|
||||
-1) {
|
||||
Py_DECREF(value_fast);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (col = 0; col < self->num_col; col++) {
|
||||
mat[col * self->num_row + row] = vec[col];
|
||||
}
|
||||
for (col = 0; col < self->num_col; col++) {
|
||||
mat[col * self->num_row + row] = vec[col];
|
||||
}
|
||||
|
||||
Py_DECREF(value_fast);
|
||||
|
||||
/*parsed well - now set in matrix*/
|
||||
memcpy(self->matrix, mat, self->num_col * self->num_row * sizeof(float));
|
||||
|
||||
(void)BaseMath_WriteCallback(self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Py_DECREF(value_fast);
|
||||
|
||||
/*parsed well - now set in matrix*/
|
||||
memcpy(self->matrix, mat, self->num_col * self->num_row * sizeof(float));
|
||||
|
||||
(void)BaseMath_WriteCallback(self);
|
||||
return 0;
|
||||
}
|
||||
/*------------------------NUMERIC PROTOCOLS----------------------
|
||||
*------------------------obj + obj------------------------------*/
|
||||
@@ -2540,7 +2529,7 @@ static PyObject *Matrix_mul(PyObject *m1, PyObject *m2)
|
||||
|
||||
return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1));
|
||||
}
|
||||
else if (mat2) {
|
||||
if (mat2) {
|
||||
/*FLOAT/INT * MATRIX */
|
||||
if (((scalar = PyFloat_AsDouble(m1)) == -1.0f && PyErr_Occurred()) == 0) {
|
||||
return matrix_mul_float(mat2, scalar);
|
||||
@@ -2655,7 +2644,7 @@ static PyObject *Matrix_matmul(PyObject *m1, PyObject *m2)
|
||||
|
||||
return Matrix_CreatePyObject(mat, mat2->num_col, mat1->num_row, Py_TYPE(mat1));
|
||||
}
|
||||
else if (mat1) {
|
||||
if (mat1) {
|
||||
/* MATRIX @ VECTOR */
|
||||
if (VectorObject_Check(m2)) {
|
||||
VectorObject *vec2 = (VectorObject *)m2;
|
||||
@@ -2772,7 +2761,7 @@ static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item)
|
||||
}
|
||||
return Matrix_item_row(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -2782,19 +2771,17 @@ static PyObject *Matrix_subscript(MatrixObject *self, PyObject *item)
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return Matrix_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *value)
|
||||
@@ -2809,7 +2796,7 @@ static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *va
|
||||
}
|
||||
return Matrix_ass_item_row(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->num_row, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -2819,16 +2806,14 @@ static int Matrix_ass_subscript(MatrixObject *self, PyObject *item, PyObject *va
|
||||
if (step == 1) {
|
||||
return Matrix_ass_slice(self, start, stop, value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrices");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PyMappingMethods Matrix_AsMapping = {
|
||||
@@ -2977,15 +2962,14 @@ static PyObject *Matrix_is_negative_get(MatrixObject *self, void *UNUSED(closure
|
||||
if (self->num_row == 4 && self->num_col == 4) {
|
||||
return PyBool_FromLong(is_negative_m4((float(*)[4])self->matrix));
|
||||
}
|
||||
else if (self->num_row == 3 && self->num_col == 3) {
|
||||
if (self->num_row == 3 && self->num_col == 3) {
|
||||
return PyBool_FromLong(is_negative_m3((float(*)[3])self->matrix));
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Matrix.is_negative: "
|
||||
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Matrix.is_negative: "
|
||||
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(Matrix_is_orthogonal_doc,
|
||||
@@ -3000,15 +2984,14 @@ static PyObject *Matrix_is_orthogonal_get(MatrixObject *self, void *UNUSED(closu
|
||||
if (self->num_row == 4 && self->num_col == 4) {
|
||||
return PyBool_FromLong(is_orthonormal_m4((float(*)[4])self->matrix));
|
||||
}
|
||||
else if (self->num_row == 3 && self->num_col == 3) {
|
||||
if (self->num_row == 3 && self->num_col == 3) {
|
||||
return PyBool_FromLong(is_orthonormal_m3((float(*)[3])self->matrix));
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Matrix.is_orthogonal: "
|
||||
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Matrix.is_orthogonal: "
|
||||
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(Matrix_is_orthogonal_axis_vectors_doc,
|
||||
@@ -3024,15 +3007,14 @@ static PyObject *Matrix_is_orthogonal_axis_vectors_get(MatrixObject *self, void
|
||||
if (self->num_row == 4 && self->num_col == 4) {
|
||||
return PyBool_FromLong(is_orthogonal_m4((float(*)[4])self->matrix));
|
||||
}
|
||||
else if (self->num_row == 3 && self->num_col == 3) {
|
||||
if (self->num_row == 3 && self->num_col == 3) {
|
||||
return PyBool_FromLong(is_orthogonal_m3((float(*)[3])self->matrix));
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Matrix.is_orthogonal_axis_vectors: "
|
||||
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_AttributeError,
|
||||
"Matrix.is_orthogonal_axis_vectors: "
|
||||
"inappropriate matrix size - expects 3x3 or 4x4 matrix");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
@@ -3478,14 +3460,13 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item
|
||||
}
|
||||
return Matrix_item_row(matrix_user, i);
|
||||
}
|
||||
else { /* MAT_ACCESS_ROW */
|
||||
if (i < 0) {
|
||||
i += matrix_user->num_col;
|
||||
}
|
||||
return Matrix_item_col(matrix_user, i);
|
||||
/* MAT_ACCESS_ROW */
|
||||
if (i < 0) {
|
||||
i += matrix_user->num_col;
|
||||
}
|
||||
return Matrix_item_col(matrix_user, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, MatrixAccess_len(self), &start, &stop, &step, &slicelength) <
|
||||
@@ -3496,19 +3477,17 @@ static PyObject *MatrixAccess_subscript(MatrixAccessObject *self, PyObject *item
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return MatrixAccess_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrix accessors");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with matrix accessors");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item, PyObject *value)
|
||||
@@ -3527,19 +3506,17 @@ static int MatrixAccess_ass_subscript(MatrixAccessObject *self, PyObject *item,
|
||||
}
|
||||
return Matrix_ass_item_row(matrix_user, i, value);
|
||||
}
|
||||
else { /* MAT_ACCESS_ROW */
|
||||
if (i < 0) {
|
||||
i += matrix_user->num_col;
|
||||
}
|
||||
return Matrix_ass_item_col(matrix_user, i, value);
|
||||
/* MAT_ACCESS_ROW */
|
||||
if (i < 0) {
|
||||
i += matrix_user->num_col;
|
||||
}
|
||||
return Matrix_ass_item_col(matrix_user, i, value);
|
||||
}
|
||||
/* TODO, slice */
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "matrix indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PyObject *MatrixAccess_iter(MatrixAccessObject *self)
|
||||
|
||||
@@ -815,7 +815,7 @@ static PyObject *Quaternion_subscript(QuaternionObject *self, PyObject *item)
|
||||
}
|
||||
return Quaternion_item(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -825,20 +825,17 @@ static PyObject *Quaternion_subscript(QuaternionObject *self, PyObject *item)
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return Quaternion_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternions");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"quaternion indices must be integers, not %.200s",
|
||||
Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternions");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "quaternion indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyObject *value)
|
||||
@@ -853,7 +850,7 @@ static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyOb
|
||||
}
|
||||
return Quaternion_ass_item(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, QUAT_SIZE, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -863,17 +860,14 @@ static int Quaternion_ass_subscript(QuaternionObject *self, PyObject *item, PyOb
|
||||
if (step == 1) {
|
||||
return Quaternion_ass_slice(self, start, stop, value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternion");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"quaternion indices must be integers, not %.200s",
|
||||
Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with quaternion");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "quaternion indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------NUMERIC PROTOCOLS---------------------- */
|
||||
@@ -967,7 +961,7 @@ static PyObject *Quaternion_mul(PyObject *q1, PyObject *q2)
|
||||
return Quaternion_CreatePyObject(quat, Py_TYPE(q1));
|
||||
}
|
||||
/* the only case this can happen (for a supported type is "FLOAT * QUAT") */
|
||||
else if (quat2) { /* FLOAT * QUAT */
|
||||
if (quat2) { /* FLOAT * QUAT */
|
||||
if (((scalar = PyFloat_AsDouble(q1)) == -1.0f && PyErr_Occurred()) == 0) {
|
||||
return quat_mul_float(quat2, scalar);
|
||||
}
|
||||
@@ -1049,7 +1043,7 @@ static PyObject *Quaternion_matmul(PyObject *q1, PyObject *q2)
|
||||
mul_qt_qtqt(quat, quat1->quat, quat2->quat);
|
||||
return Quaternion_CreatePyObject(quat, Py_TYPE(q1));
|
||||
}
|
||||
else if (quat1) {
|
||||
if (quat1) {
|
||||
/* QUAT @ VEC */
|
||||
if (VectorObject_Check(q2)) {
|
||||
VectorObject *vec2 = (VectorObject *)q2;
|
||||
@@ -1384,10 +1378,9 @@ static PyObject *quat__apply_to_copy(PyObject *(*quat_func)(QuaternionObject *),
|
||||
Py_DECREF(ret_dummy);
|
||||
return ret;
|
||||
}
|
||||
else { /* error */
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
/* error */
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* axis vector suffers from precision errors, use this function to ensure */
|
||||
|
||||
@@ -104,10 +104,9 @@ static PyObject *vec__apply_to_copy(PyObject *(*vec_func)(VectorObject *), Vecto
|
||||
Py_DECREF(ret_dummy);
|
||||
return (PyObject *)ret;
|
||||
}
|
||||
else { /* error */
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
/* error */
|
||||
Py_DECREF(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*-----------------------CLASS-METHODS----------------------------*/
|
||||
@@ -1004,12 +1003,11 @@ static PyObject *Vector_angle(VectorObject *self, PyObject *args)
|
||||
Py_INCREF(fallback);
|
||||
return fallback;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.angle(other): "
|
||||
"zero length vectors have no valid angle");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.angle(other): "
|
||||
"zero length vectors have no valid angle");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyFloat_FromDouble(saacos(dot / (sqrt(dot_self) * sqrt(dot_other))));
|
||||
@@ -1059,12 +1057,11 @@ static PyObject *Vector_angle_signed(VectorObject *self, PyObject *args)
|
||||
Py_INCREF(fallback);
|
||||
return fallback;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.angle_signed(other): "
|
||||
"zero length vectors have no valid angle");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.angle_signed(other): "
|
||||
"zero length vectors have no valid angle");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyFloat_FromDouble(angle_signed_v2v2(self->vec, tvec));
|
||||
@@ -1238,12 +1235,11 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args)
|
||||
Py_INCREF(fallback);
|
||||
return fallback;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.slerp(): "
|
||||
"zero length vectors unsupported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.slerp(): "
|
||||
"zero length vectors unsupported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* We have sane state, execute slerp */
|
||||
@@ -1256,12 +1252,11 @@ static PyObject *Vector_slerp(VectorObject *self, PyObject *args)
|
||||
Py_INCREF(fallback);
|
||||
return fallback;
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.slerp(): "
|
||||
"opposite vectors unsupported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"Vector.slerp(): "
|
||||
"opposite vectors unsupported");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
interp_dot_slerp(fac, cosom, w);
|
||||
@@ -1785,7 +1780,7 @@ static PyObject *Vector_mul(PyObject *v1, PyObject *v2)
|
||||
/* element-wise product */
|
||||
return vector_mul_vec(vec1, vec2);
|
||||
}
|
||||
else if (vec1) {
|
||||
if (vec1) {
|
||||
if (((scalar = PyFloat_AsDouble(v2)) == -1.0f && PyErr_Occurred()) == 0) { /* VEC * FLOAT */
|
||||
return vector_mul_float(vec1, scalar);
|
||||
}
|
||||
@@ -1890,7 +1885,7 @@ static PyObject *Vector_matmul(PyObject *v1, PyObject *v2)
|
||||
/*dot product*/
|
||||
return PyFloat_FromDouble(dot_vn_vn(vec1->vec, vec2->vec, vec1->size));
|
||||
}
|
||||
else if (vec1) {
|
||||
if (vec1) {
|
||||
if (MatrixObject_Check(v2)) {
|
||||
/* VEC @ MATRIX */
|
||||
float tvec[MAX_DIMENSIONS];
|
||||
@@ -2039,9 +2034,8 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
if (comparison_type == Py_NE) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else {
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
vecA = (VectorObject *)objectA;
|
||||
vecB = (VectorObject *)objectB;
|
||||
@@ -2054,9 +2048,8 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
if (comparison_type == Py_NE) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else {
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
switch (comparison_type) {
|
||||
@@ -2107,9 +2100,8 @@ static PyObject *Vector_richcmpr(PyObject *objectA, PyObject *objectB, int compa
|
||||
if (result == 1) {
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else {
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static Py_hash_t Vector_hash(VectorObject *self)
|
||||
@@ -2152,7 +2144,7 @@ static PyObject *Vector_subscript(VectorObject *self, PyObject *item)
|
||||
}
|
||||
return Vector_item(self, i);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -2162,19 +2154,17 @@ static PyObject *Vector_subscript(VectorObject *self, PyObject *item)
|
||||
if (slicelength <= 0) {
|
||||
return PyTuple_New(0);
|
||||
}
|
||||
else if (step == 1) {
|
||||
if (step == 1) {
|
||||
return Vector_slice(self, start, stop);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *value)
|
||||
@@ -2189,7 +2179,7 @@ static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *va
|
||||
}
|
||||
return Vector_ass_item(self, i, value);
|
||||
}
|
||||
else if (PySlice_Check(item)) {
|
||||
if (PySlice_Check(item)) {
|
||||
Py_ssize_t start, stop, step, slicelength;
|
||||
|
||||
if (PySlice_GetIndicesEx(item, self->size, &start, &stop, &step, &slicelength) < 0) {
|
||||
@@ -2199,16 +2189,14 @@ static int Vector_ass_subscript(VectorObject *self, PyObject *item, PyObject *va
|
||||
if (step == 1) {
|
||||
return Vector_ass_slice(self, start, stop, value);
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
|
||||
PyErr_SetString(PyExc_IndexError, "slice steps not supported with vectors");
|
||||
return -1;
|
||||
}
|
||||
|
||||
PyErr_Format(
|
||||
PyExc_TypeError, "vector indices must be integers, not %.200s", Py_TYPE(item)->tp_name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PyMappingMethods Vector_AsMapping = {
|
||||
@@ -2523,9 +2511,8 @@ static int Vector_swizzle_set(VectorObject *self, PyObject *value, void *closure
|
||||
if (BaseMath_WriteCallback(self) == -1) {
|
||||
return -1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define _SWIZZLE1(a) ((a) | SWIZZLE_VALID_AXIS)
|
||||
|
||||
@@ -914,16 +914,15 @@ static PyObject *C_BVHTree_FromPolygons(PyObject *UNUSED(cls), PyObject *args, P
|
||||
return bvhtree_CreatePyObject(
|
||||
tree, epsilon, coords, coords_len, tris, tris_len, orig_index, orig_normal);
|
||||
}
|
||||
else {
|
||||
if (coords) {
|
||||
MEM_freeN(coords);
|
||||
}
|
||||
if (tris) {
|
||||
MEM_freeN(tris);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
if (coords) {
|
||||
MEM_freeN(coords);
|
||||
}
|
||||
if (tris) {
|
||||
MEM_freeN(tris);
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#ifndef MATH_STANDALONE
|
||||
@@ -1053,55 +1052,48 @@ static Mesh *bvh_get_mesh(const char *funcname,
|
||||
funcname);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
*r_free_mesh = true;
|
||||
return mesh_create_eval_final_render(depsgraph, scene, ob, &data_masks);
|
||||
}
|
||||
|
||||
*r_free_mesh = true;
|
||||
return mesh_create_eval_final_render(depsgraph, scene, ob, &data_masks);
|
||||
}
|
||||
else if (ob_eval != NULL) {
|
||||
if (ob_eval != NULL) {
|
||||
if (use_cage) {
|
||||
return mesh_get_eval_deform(depsgraph, scene, ob_eval, &data_masks);
|
||||
}
|
||||
else {
|
||||
return mesh_get_eval_final(depsgraph, scene, ob_eval, &data_masks);
|
||||
}
|
||||
|
||||
return mesh_get_eval_final(depsgraph, scene, ob_eval, &data_masks);
|
||||
}
|
||||
else {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s(...): Cannot get evaluated data from given dependency graph / object pair",
|
||||
funcname);
|
||||
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s(...): Cannot get evaluated data from given dependency graph / object pair",
|
||||
funcname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* !use_deform */
|
||||
if (use_render) {
|
||||
if (use_cage) {
|
||||
PyErr_Format(
|
||||
PyExc_ValueError,
|
||||
"%s(...): cage arg is unsupported when dependency graph evaluation mode is RENDER",
|
||||
funcname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*r_free_mesh = true;
|
||||
return mesh_create_eval_no_deform_render(depsgraph, scene, ob, &data_masks);
|
||||
}
|
||||
else {
|
||||
/* !use_deform */
|
||||
if (use_render) {
|
||||
if (use_cage) {
|
||||
PyErr_Format(
|
||||
PyExc_ValueError,
|
||||
"%s(...): cage arg is unsupported when dependency graph evaluation mode is RENDER",
|
||||
funcname);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
*r_free_mesh = true;
|
||||
return mesh_create_eval_no_deform_render(depsgraph, scene, ob, &data_masks);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (use_cage) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s(...): cage arg is unsupported when deform=False and dependency graph "
|
||||
"evaluation mode is not RENDER",
|
||||
funcname);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
*r_free_mesh = true;
|
||||
return mesh_create_eval_no_deform(depsgraph, scene, ob, &data_masks);
|
||||
}
|
||||
}
|
||||
|
||||
if (use_cage) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"%s(...): cage arg is unsupported when deform=False and dependency graph "
|
||||
"evaluation mode is not RENDER",
|
||||
funcname);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
*r_free_mesh = true;
|
||||
return mesh_create_eval_no_deform(depsgraph, scene, ob, &data_masks);
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(C_BVHTree_FromObject_doc,
|
||||
|
||||
@@ -204,12 +204,11 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject
|
||||
/* collinear */
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
else {
|
||||
tuple = PyTuple_New(2);
|
||||
PyTuple_SET_ITEMS(
|
||||
tuple, Vector_CreatePyObject(i1, len, NULL), Vector_CreatePyObject(i2, len, NULL));
|
||||
return tuple;
|
||||
}
|
||||
|
||||
tuple = PyTuple_New(2);
|
||||
PyTuple_SET_ITEMS(
|
||||
tuple, Vector_CreatePyObject(i1, len, NULL), Vector_CreatePyObject(i2, len, NULL));
|
||||
return tuple;
|
||||
}
|
||||
|
||||
/* Line-Line intersection using algorithm from mathworld.wolfram.com */
|
||||
@@ -466,9 +465,8 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj
|
||||
if (isect_seg_seg_v2_point(UNPACK4(lines), vi) == 1) {
|
||||
return Vector_CreatePyObject(vi, 2, NULL);
|
||||
}
|
||||
else {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(
|
||||
@@ -519,9 +517,8 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec
|
||||
if (isect_line_plane_v3(isect, line_a, line_b, plane_co, plane_no) == 1) {
|
||||
return Vector_CreatePyObject(isect, 3, NULL);
|
||||
}
|
||||
else {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(
|
||||
@@ -637,43 +634,42 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje
|
||||
-1)) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
bool use_a = true;
|
||||
bool use_b = true;
|
||||
float lambda;
|
||||
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
bool use_a = true;
|
||||
bool use_b = true;
|
||||
float lambda;
|
||||
|
||||
switch (isect_line_sphere_v3(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) {
|
||||
case 1:
|
||||
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
use_b = false;
|
||||
break;
|
||||
case 2:
|
||||
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_b = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
|
||||
switch (isect_line_sphere_v3(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) {
|
||||
case 1:
|
||||
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
use_b = false;
|
||||
break;
|
||||
case 2:
|
||||
if (!(!clip || (((lambda = line_point_factor_v3(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
if (!(!clip || (((lambda = line_point_factor_v3(isect_b, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_b = false;
|
||||
break;
|
||||
}
|
||||
|
||||
PyTuple_SET_ITEMS(ret,
|
||||
use_a ? Vector_CreatePyObject(isect_a, 3, NULL) : Py_INCREF_RET(Py_None),
|
||||
use_b ? Vector_CreatePyObject(isect_b, 3, NULL) : Py_INCREF_RET(Py_None));
|
||||
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
use_a = false;
|
||||
use_b = false;
|
||||
break;
|
||||
}
|
||||
|
||||
PyTuple_SET_ITEMS(ret,
|
||||
use_a ? Vector_CreatePyObject(isect_a, 3, NULL) : Py_INCREF_RET(Py_None),
|
||||
use_b ? Vector_CreatePyObject(isect_b, 3, NULL) : Py_INCREF_RET(Py_None));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* keep in sync with M_Geometry_intersect_line_sphere */
|
||||
@@ -723,43 +719,42 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO
|
||||
-1)) == 0) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
bool use_a = true;
|
||||
bool use_b = true;
|
||||
float lambda;
|
||||
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
bool use_a = true;
|
||||
bool use_b = true;
|
||||
float lambda;
|
||||
|
||||
switch (isect_line_sphere_v2(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) {
|
||||
case 1:
|
||||
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
use_b = false;
|
||||
break;
|
||||
case 2:
|
||||
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_b = false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
|
||||
switch (isect_line_sphere_v2(line_a, line_b, sphere_co, sphere_radius, isect_a, isect_b)) {
|
||||
case 1:
|
||||
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
use_b = false;
|
||||
break;
|
||||
case 2:
|
||||
if (!(!clip || (((lambda = line_point_factor_v2(isect_a, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_a = false;
|
||||
}
|
||||
if (!(!clip || (((lambda = line_point_factor_v2(isect_b, line_a, line_b)) >= 0.0f) &&
|
||||
(lambda <= 1.0f)))) {
|
||||
use_b = false;
|
||||
break;
|
||||
}
|
||||
|
||||
PyTuple_SET_ITEMS(ret,
|
||||
use_a ? Vector_CreatePyObject(isect_a, 2, NULL) : Py_INCREF_RET(Py_None),
|
||||
use_b ? Vector_CreatePyObject(isect_b, 2, NULL) : Py_INCREF_RET(Py_None));
|
||||
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
use_a = false;
|
||||
use_b = false;
|
||||
break;
|
||||
}
|
||||
|
||||
PyTuple_SET_ITEMS(ret,
|
||||
use_a ? Vector_CreatePyObject(isect_a, 2, NULL) : Py_INCREF_RET(Py_None),
|
||||
use_b ? Vector_CreatePyObject(isect_b, 2, NULL) : Py_INCREF_RET(Py_None));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(
|
||||
@@ -849,9 +844,8 @@ static PyObject *M_Geometry_intersect_point_tri(PyObject *UNUSED(self), PyObject
|
||||
if (isect_point_tri_v3(pt, UNPACK3(tri), vi)) {
|
||||
return Vector_CreatePyObject(vi, 3, NULL);
|
||||
}
|
||||
else {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(M_Geometry_closest_point_on_tri_doc,
|
||||
@@ -1094,65 +1088,61 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a
|
||||
(float **)&planes, 4, py_planes, "points_in_planes")) == -1) {
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
/* note, this could be refactored into plain C easy - py bits are noted */
|
||||
const float eps = 0.0001f;
|
||||
const uint len = (uint)planes_len;
|
||||
uint i, j, k, l;
|
||||
|
||||
float n1n2[3], n2n3[3], n3n1[3];
|
||||
float potentialVertex[3];
|
||||
char *planes_used = PyMem_Malloc(sizeof(char) * len);
|
||||
/* note, this could be refactored into plain C easy - py bits are noted */
|
||||
const float eps = 0.0001f;
|
||||
const uint len = (uint)planes_len;
|
||||
uint i, j, k, l;
|
||||
|
||||
/* python */
|
||||
PyObject *py_verts = PyList_New(0);
|
||||
PyObject *py_plane_index = PyList_New(0);
|
||||
float n1n2[3], n2n3[3], n3n1[3];
|
||||
float potentialVertex[3];
|
||||
char *planes_used = PyMem_Malloc(sizeof(char) * len);
|
||||
|
||||
memset(planes_used, 0, sizeof(char) * len);
|
||||
/* python */
|
||||
PyObject *py_verts = PyList_New(0);
|
||||
PyObject *py_plane_index = PyList_New(0);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
const float *N1 = planes[i];
|
||||
for (j = i + 1; j < len; j++) {
|
||||
const float *N2 = planes[j];
|
||||
cross_v3_v3v3(n1n2, N1, N2);
|
||||
if (len_squared_v3(n1n2) > eps) {
|
||||
for (k = j + 1; k < len; k++) {
|
||||
const float *N3 = planes[k];
|
||||
cross_v3_v3v3(n2n3, N2, N3);
|
||||
if (len_squared_v3(n2n3) > eps) {
|
||||
cross_v3_v3v3(n3n1, N3, N1);
|
||||
if (len_squared_v3(n3n1) > eps) {
|
||||
const float quotient = dot_v3v3(N1, n2n3);
|
||||
if (fabsf(quotient) > eps) {
|
||||
/**
|
||||
* <pre>
|
||||
* potentialVertex = (
|
||||
* (n2n3 * N1[3] + n3n1 * N2[3] + n1n2 * N3[3]) *
|
||||
* (-1.0 / quotient));
|
||||
* </pre>
|
||||
*/
|
||||
const float quotient_ninv = -1.0f / quotient;
|
||||
potentialVertex[0] = ((n2n3[0] * N1[3]) + (n3n1[0] * N2[3]) +
|
||||
(n1n2[0] * N3[3])) *
|
||||
quotient_ninv;
|
||||
potentialVertex[1] = ((n2n3[1] * N1[3]) + (n3n1[1] * N2[3]) +
|
||||
(n1n2[1] * N3[3])) *
|
||||
quotient_ninv;
|
||||
potentialVertex[2] = ((n2n3[2] * N1[3]) + (n3n1[2] * N2[3]) +
|
||||
(n1n2[2] * N3[3])) *
|
||||
quotient_ninv;
|
||||
for (l = 0; l < len; l++) {
|
||||
const float *NP = planes[l];
|
||||
if ((dot_v3v3(NP, potentialVertex) + NP[3]) > 0.000001f) {
|
||||
break;
|
||||
}
|
||||
memset(planes_used, 0, sizeof(char) * len);
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
const float *N1 = planes[i];
|
||||
for (j = i + 1; j < len; j++) {
|
||||
const float *N2 = planes[j];
|
||||
cross_v3_v3v3(n1n2, N1, N2);
|
||||
if (len_squared_v3(n1n2) > eps) {
|
||||
for (k = j + 1; k < len; k++) {
|
||||
const float *N3 = planes[k];
|
||||
cross_v3_v3v3(n2n3, N2, N3);
|
||||
if (len_squared_v3(n2n3) > eps) {
|
||||
cross_v3_v3v3(n3n1, N3, N1);
|
||||
if (len_squared_v3(n3n1) > eps) {
|
||||
const float quotient = dot_v3v3(N1, n2n3);
|
||||
if (fabsf(quotient) > eps) {
|
||||
/**
|
||||
* <pre>
|
||||
* potentialVertex = (
|
||||
* (n2n3 * N1[3] + n3n1 * N2[3] + n1n2 * N3[3]) *
|
||||
* (-1.0 / quotient));
|
||||
* </pre>
|
||||
*/
|
||||
const float quotient_ninv = -1.0f / quotient;
|
||||
potentialVertex[0] = ((n2n3[0] * N1[3]) + (n3n1[0] * N2[3]) + (n1n2[0] * N3[3])) *
|
||||
quotient_ninv;
|
||||
potentialVertex[1] = ((n2n3[1] * N1[3]) + (n3n1[1] * N2[3]) + (n1n2[1] * N3[3])) *
|
||||
quotient_ninv;
|
||||
potentialVertex[2] = ((n2n3[2] * N1[3]) + (n3n1[2] * N2[3]) + (n1n2[2] * N3[3])) *
|
||||
quotient_ninv;
|
||||
for (l = 0; l < len; l++) {
|
||||
const float *NP = planes[l];
|
||||
if ((dot_v3v3(NP, potentialVertex) + NP[3]) > 0.000001f) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (l == len) { /* ok */
|
||||
/* python */
|
||||
PyList_APPEND(py_verts, Vector_CreatePyObject(potentialVertex, 3, NULL));
|
||||
planes_used[i] = planes_used[j] = planes_used[k] = true;
|
||||
}
|
||||
if (l == len) { /* ok */
|
||||
/* python */
|
||||
PyList_APPEND(py_verts, Vector_CreatePyObject(potentialVertex, 3, NULL));
|
||||
planes_used[i] = planes_used[j] = planes_used[k] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1160,22 +1150,22 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PyMem_Free(planes);
|
||||
PyMem_Free(planes);
|
||||
|
||||
/* now make a list of used planes */
|
||||
for (i = 0; i < len; i++) {
|
||||
if (planes_used[i]) {
|
||||
PyList_APPEND(py_plane_index, PyLong_FromLong(i));
|
||||
}
|
||||
/* now make a list of used planes */
|
||||
for (i = 0; i < len; i++) {
|
||||
if (planes_used[i]) {
|
||||
PyList_APPEND(py_plane_index, PyLong_FromLong(i));
|
||||
}
|
||||
PyMem_Free(planes_used);
|
||||
}
|
||||
PyMem_Free(planes_used);
|
||||
|
||||
{
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEMS(ret, py_verts, py_plane_index);
|
||||
return ret;
|
||||
}
|
||||
{
|
||||
PyObject *ret = PyTuple_New(2);
|
||||
PyTuple_SET_ITEMS(ret, py_verts, py_plane_index);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1321,7 +1311,7 @@ static PyObject *M_Geometry_tessellate_polygon(PyObject *UNUSED(self), PyObject
|
||||
BKE_displist_free(&dispbase); /* possible some dl was allocated */
|
||||
return NULL;
|
||||
}
|
||||
else if (totpoints) {
|
||||
if (totpoints) {
|
||||
/* now make the list to return */
|
||||
BKE_displist_fill(&dispbase, &dispbase, is_2d ? ((const float[3]){0, 0, -1}) : NULL, false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user