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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSybren A. Stüvel <sybren@blender.org>2020-08-07 13:41:06 +0300
committerSybren A. Stüvel <sybren@blender.org>2020-08-07 14:38:07 +0300
commit3d48d99647b59a6f0461baa4456660917f1bbda6 (patch)
tree0183ca55640e5d8034ac59865ebc5a5071d29f1f /source/blender/python/mathutils/mathutils_geometry.c
parent44b7354742ef3728f212edac1277c0d25fa59934 (diff)
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.
Diffstat (limited to 'source/blender/python/mathutils/mathutils_geometry.c')
-rw-r--r--source/blender/python/mathutils/mathutils_geometry.c284
1 files changed, 137 insertions, 147 deletions
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c
index 93dbac32c19..37997e9f912 100644
--- a/source/blender/python/mathutils/mathutils_geometry.c
+++ b/source/blender/python/mathutils/mathutils_geometry.c
@@ -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;
- }
+ }
+ 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));
+ 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;
- }
+ 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;
- }
+ }
+ 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));
+ 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;
- }
+ 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,88 +1088,84 @@ 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);
-
- /* python */
- PyObject *py_verts = PyList_New(0);
- PyObject *py_plane_index = PyList_New(0);
-
- 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;
+ /* 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);
+
+ /* python */
+ PyObject *py_verts = PyList_New(0);
+ PyObject *py_plane_index = PyList_New(0);
+
+ 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;
+ }
}
}
}
}
}
}
+ }
- 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);