diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-01-04 09:03:54 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-01-04 09:43:57 +0300 |
commit | 8106a6b75d45cc7472fd92f3b045697e30be8c73 (patch) | |
tree | 3b81857d4df29ce8bcc8d0043045aa6c713e4a78 /source/blender/python/mathutils/mathutils_geometry.c | |
parent | c41431f1e9e75a424717b4080434b940c2685c20 (diff) |
mathutils: refactor instantiation
remove 'type' argument, very few mathutils objects are wrapped,
add new function for creating wrapped objects.
also fixes unlikely memory leak if the data-array can't be allocated.
Diffstat (limited to 'source/blender/python/mathutils/mathutils_geometry.c')
-rw-r--r-- | source/blender/python/mathutils/mathutils_geometry.c | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 67e48253726..2bf596bbfba 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -146,7 +146,7 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject * mul_v3_fl(dir, t); add_v3_v3v3(pvec, orig, dir); - return Vector_CreatePyObject(pvec, 3, Py_NEW, NULL); + return Vector_CreatePyObject(pvec, 3, NULL); } /* Line-Line intersection using algorithm from mathworld.wolfram.com */ @@ -207,8 +207,8 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject } else { tuple = PyTuple_New(2); - PyTuple_SET_ITEM(tuple, 0, Vector_CreatePyObject(i1, len, Py_NEW, NULL)); - PyTuple_SET_ITEM(tuple, 1, Vector_CreatePyObject(i2, len, Py_NEW, NULL)); + PyTuple_SET_ITEM(tuple, 0, Vector_CreatePyObject(i1, len, NULL)); + PyTuple_SET_ITEM(tuple, 1, Vector_CreatePyObject(i2, len, NULL)); return tuple; } } @@ -285,8 +285,8 @@ static PyObject *M_Geometry_intersect_sphere_sphere_2d(PyObject *UNUSED(self), P i2[0] = i_cent[0] - h * v_ab[1] / dist; i2[1] = i_cent[1] + h * v_ab[0] / dist; - PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(i1, 2, Py_NEW, NULL)); - PyTuple_SET_ITEM(ret, 1, Vector_CreatePyObject(i2, 2, Py_NEW, NULL)); + PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(i1, 2, NULL)); + PyTuple_SET_ITEM(ret, 1, Vector_CreatePyObject(i2, 2, NULL)); } return ret; @@ -324,7 +324,7 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject *args) } normal_poly_v3(n, (const float (*)[3])coords, coords_len); - ret = Vector_CreatePyObject(n, 3, Py_NEW, NULL); + ret = Vector_CreatePyObject(n, 3, NULL); finally: PyMem_Free(coords); @@ -446,7 +446,7 @@ 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, Py_NEW, NULL); + return Vector_CreatePyObject(vi, 2, NULL); } else { Py_RETURN_NONE; @@ -497,7 +497,7 @@ static PyObject *M_Geometry_intersect_line_plane(PyObject *UNUSED(self), PyObjec /* TODO: implements no_flip */ if (isect_line_plane_v3(isect, line_a, line_b, plane_co, plane_no) == 1) { - return Vector_CreatePyObject(isect, 3, Py_NEW, NULL); + return Vector_CreatePyObject(isect, 3, NULL); } else { Py_RETURN_NONE; @@ -551,8 +551,8 @@ static PyObject *M_Geometry_intersect_plane_plane(PyObject *UNUSED(self), PyObje { normalize_v3(isect_no); - ret_co = Vector_CreatePyObject(isect_co, 3, Py_NEW, NULL); - ret_no = Vector_CreatePyObject(isect_no, 3, Py_NEW, NULL); + ret_co = Vector_CreatePyObject(isect_co, 3, NULL); + ret_no = Vector_CreatePyObject(isect_no, 3, NULL); } else { ret_co = Py_None; @@ -631,10 +631,10 @@ static PyObject *M_Geometry_intersect_line_sphere(PyObject *UNUSED(self), PyObje break; } - if (use_a) { PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(isect_a, 3, Py_NEW, NULL)); } + if (use_a) { PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(isect_a, 3, NULL)); } else { PyTuple_SET_ITEM(ret, 0, Py_None); Py_INCREF(Py_None); } - if (use_b) { PyTuple_SET_ITEM(ret, 1, Vector_CreatePyObject(isect_b, 3, Py_NEW, NULL)); } + if (use_b) { PyTuple_SET_ITEM(ret, 1, Vector_CreatePyObject(isect_b, 3, NULL)); } else { PyTuple_SET_ITEM(ret, 1, Py_None); Py_INCREF(Py_None); } return ret; @@ -705,10 +705,10 @@ static PyObject *M_Geometry_intersect_line_sphere_2d(PyObject *UNUSED(self), PyO break; } - if (use_a) { PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(isect_a, 2, Py_NEW, NULL)); } + if (use_a) { PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(isect_a, 2, NULL)); } else { PyTuple_SET_ITEM(ret, 0, Py_None); Py_INCREF(Py_None); } - if (use_b) { PyTuple_SET_ITEM(ret, 1, Vector_CreatePyObject(isect_b, 2, Py_NEW, NULL)); } + if (use_b) { PyTuple_SET_ITEM(ret, 1, Vector_CreatePyObject(isect_b, 2, NULL)); } else { PyTuple_SET_ITEM(ret, 1, Py_None); Py_INCREF(Py_None); } return ret; @@ -756,7 +756,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_ITEM(ret, 0, Vector_CreatePyObject(pt_out, size, Py_NEW, NULL)); + PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(pt_out, size, NULL)); PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(lambda)); return ret; } @@ -802,7 +802,7 @@ 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, Py_NEW, NULL); + return Vector_CreatePyObject(vi, 3, NULL); } else { Py_RETURN_NONE; @@ -988,7 +988,7 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje UNPACK3(tri_dst), UNPACK3(tri_src)); - return Vector_CreatePyObject(pt_dst, 3, Py_NEW, NULL); + return Vector_CreatePyObject(pt_dst, 3, NULL); } PyDoc_STRVAR(M_Geometry_points_in_planes_doc, @@ -1062,7 +1062,7 @@ static PyObject *M_Geometry_points_in_planes(PyObject *UNUSED(self), PyObject *a if (l == len) { /* ok */ /* python */ - PyObject *item = Vector_CreatePyObject(potentialVertex, 3, Py_NEW, NULL); + PyObject *item = Vector_CreatePyObject(potentialVertex, 3, NULL); PyList_Append(py_verts, item); Py_DECREF(item); @@ -1157,7 +1157,7 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject list = PyList_New(resolu); fp = coord_array; for (i = 0; i < resolu; i++, fp = fp + dims) { - PyList_SET_ITEM(list, i, Vector_CreatePyObject(fp, dims, Py_NEW, NULL)); + PyList_SET_ITEM(list, i, Vector_CreatePyObject(fp, dims, NULL)); } MEM_freeN(coord_array); return list; |