From 8638142c3bf1d0701a08d3222366fcd92d3e7772 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 6 Mar 2015 18:48:26 +1100 Subject: Fix T43904: calc_vert_angle returns wrong value This was mis-named, rename to `calc_edge_angle` and allow a fallback value in the case when the vert doesn't have 2-edges. --- source/blender/python/bmesh/bmesh_py_types.c | 35 ++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c index 1da5599ea29..08a8a308138 100644 --- a/source/blender/python/bmesh/bmesh_py_types.c +++ b/source/blender/python/bmesh/bmesh_py_types.c @@ -1422,17 +1422,44 @@ static PyObject *bpy_bmvert_copy_from_face_interp(BPy_BMVert *self, PyObject *ar PyDoc_STRVAR(bpy_bmvert_calc_edge_angle_doc, -".. method:: calc_vert_angle()\n" +".. method:: calc_edge_angle(fallback=None)\n" "\n" " Return the angle between this vert's two connected edges.\n" "\n" +" :arg fallback: return this when the vert doesn't have 2 edges\n" +" (instead of raising a :exc:`ValueError`).\n" +" :type fallback: any\n" " :return: Angle between edges in radians.\n" " :rtype: float\n" ); -static PyObject *bpy_bmvert_calc_edge_angle(BPy_BMVert *self) +static PyObject *bpy_bmvert_calc_edge_angle(BPy_BMVert *self, PyObject *args) { + const float angle_invalid = -1.0f; + float angle; + PyObject *fallback = NULL; + BPY_BM_CHECK_OBJ(self); - return PyFloat_FromDouble(BM_vert_calc_edge_angle(self->v)); + + if (!PyArg_ParseTuple(args, "|O:calc_edge_angle", &fallback)) + return NULL; + + angle = BM_vert_calc_edge_angle_ex(self->v, angle_invalid); + + if (angle == angle_invalid) { + /* avoid exception */ + if (fallback) { + Py_INCREF(fallback); + return fallback; + } + else { + PyErr_SetString(PyExc_ValueError, + "BMVert.calc_edge_angle(): " + "vert doesn't use 2 edges"); + return NULL; + } + } + + return PyFloat_FromDouble(angle); } PyDoc_STRVAR(bpy_bmvert_calc_shell_factor_doc, @@ -2554,7 +2581,7 @@ static struct PyMethodDef bpy_bmvert_methods[] = { {"copy_from_face_interp", (PyCFunction)bpy_bmvert_copy_from_face_interp, METH_VARARGS, bpy_bmvert_copy_from_face_interp_doc}, {"copy_from_vert_interp", (PyCFunction)bpy_bmvert_copy_from_vert_interp, METH_VARARGS, bpy_bmvert_copy_from_vert_interp_doc}, - {"calc_vert_angle", (PyCFunction)bpy_bmvert_calc_edge_angle, METH_NOARGS, bpy_bmvert_calc_edge_angle_doc}, + {"calc_edge_angle", (PyCFunction)bpy_bmvert_calc_edge_angle, METH_VARARGS, bpy_bmvert_calc_edge_angle_doc}, {"calc_shell_factor", (PyCFunction)bpy_bmvert_calc_shell_factor, METH_NOARGS, bpy_bmvert_calc_shell_factor_doc}, {"normal_update", (PyCFunction)bpy_bmvert_normal_update, METH_NOARGS, bpy_bmvert_normal_update_doc}, -- cgit v1.2.3