diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-03-06 10:48:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-03-06 10:55:36 +0300 |
commit | 8638142c3bf1d0701a08d3222366fcd92d3e7772 (patch) | |
tree | f9395b2136e98c4cedd01233781f08a379e17883 /source/blender | |
parent | 7df60becb952be060bc3784f1b74dea7abcf1c59 (diff) |
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.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/python/bmesh/bmesh_py_types.c | 35 |
1 files 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}, |