diff options
Diffstat (limited to 'source/blender/python/generic/mathutils_geometry.c')
-rw-r--r-- | source/blender/python/generic/mathutils_geometry.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/source/blender/python/generic/mathutils_geometry.c b/source/blender/python/generic/mathutils_geometry.c index 75f94752e6e..6031c716807 100644 --- a/source/blender/python/generic/mathutils_geometry.c +++ b/source/blender/python/generic/mathutils_geometry.c @@ -1,5 +1,5 @@ /* - * $Id: mathutils_geometry.c 34380 2011-01-18 01:58:19Z campbellbarton $ + * $Id$ * * ***** BEGIN GPL LICENSE BLOCK ***** * @@ -27,6 +27,13 @@ * ***** END GPL LICENSE BLOCK ***** */ +/** \file blender/python/generic/mathutils_geometry.c + * \ingroup pygen + */ + + +#include <Python.h> + #include "mathutils_geometry.h" /* Used for PolyFill */ @@ -41,7 +48,7 @@ #include "BKE_curve.h" -#define SWAP_FLOAT(a,b,tmp) tmp=a; a=b; b=tmp +#define SWAP_FLOAT(a, b, tmp) tmp=a; a=b; b=tmp #define eps 0.000001 @@ -65,7 +72,7 @@ static char M_Geometry_intersect_ray_tri_doc[] = " :type ray: :class:`mathutils.Vector`\n" " :arg orig: Origin\n" " :type orig: :class:`mathutils.Vector`\n" -" :arg clip: Clip by the ray length\n" +" :arg clip: When False, don't restrict the intersection to the area of the triangle, use the infinite plane defined by the triangle.\n" " :type clip: boolean\n" " :return: The point of intersection or None if no intersection is found\n" " :rtype: :class:`mathutils.Vector` or None\n" @@ -85,7 +92,7 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject* return NULL; } - if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2) || !BaseMath_ReadCallback(vec3) || !BaseMath_ReadCallback(ray) || !BaseMath_ReadCallback(ray_off)) + if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(ray) == -1 || BaseMath_ReadCallback(ray_off) == -1) return NULL; VECCOPY(v1, vec1->vec); @@ -107,7 +114,7 @@ static PyObject *M_Geometry_intersect_ray_tri(PyObject *UNUSED(self), PyObject* /* if determinant is near zero, ray lies in plane of triangle */ det= dot_v3v3(e1, pvec); - if (det > -0.000001 && det < 0.000001) { + if (det > -0.000001f && det < 0.000001f) { Py_RETURN_NONE; } @@ -172,7 +179,7 @@ static PyObject *M_Geometry_intersect_line_line(PyObject *UNUSED(self), PyObject return NULL; } - if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2) || !BaseMath_ReadCallback(vec3) || !BaseMath_ReadCallback(vec4)) + if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1) return NULL; if(vec1->size == 3 || vec1->size == 2) { @@ -258,7 +265,7 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args) return NULL; } - if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2) || !BaseMath_ReadCallback(vec3)) + if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1) return NULL; normal_tri_v3(n, vec1->vec, vec2->vec, vec3->vec); @@ -276,7 +283,7 @@ static PyObject *M_Geometry_normal(PyObject *UNUSED(self), PyObject* args) return NULL; } - if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2) || !BaseMath_ReadCallback(vec3) || !BaseMath_ReadCallback(vec4)) + if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1 || BaseMath_ReadCallback(vec4) == -1) return NULL; normal_quad_v3(n, vec1->vec, vec2->vec, vec3->vec, vec4->vec); @@ -313,7 +320,7 @@ static PyObject *M_Geometry_area_tri(PyObject *UNUSED(self), PyObject* args) return NULL; } - if(!BaseMath_ReadCallback(vec1) || !BaseMath_ReadCallback(vec2) || !BaseMath_ReadCallback(vec3)) + if(BaseMath_ReadCallback(vec1) == -1 || BaseMath_ReadCallback(vec2) == -1 || BaseMath_ReadCallback(vec3) == -1) return NULL; if (vec1->size == 3) { @@ -390,7 +397,7 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject * polyVec= PySequence_GetItem(polyLine, index); if(VectorObject_Check(polyVec)) { - if(!BaseMath_ReadCallback((VectorObject *)polyVec)) + if(BaseMath_ReadCallback((VectorObject *)polyVec) == -1) ls_error= 1; fp[0]= ((VectorObject *)polyVec)->vec[0]; @@ -439,7 +446,8 @@ static PyObject *M_Geometry_tesselate_polygon(PyObject *UNUSED(self), PyObject * index++; } freedisplist(&dispbase); - } else { + } + else { /* no points, do this so scripts dont barf */ freedisplist(&dispbase); /* possible some dl was allocated */ tri_list= PyList_New(0); @@ -477,12 +485,13 @@ static PyObject *M_Geometry_intersect_line_line_2d(PyObject *UNUSED(self), PyObj return NULL; } - if(!BaseMath_ReadCallback(line_a1) || !BaseMath_ReadCallback(line_a2) || !BaseMath_ReadCallback(line_b1) || !BaseMath_ReadCallback(line_b2)) + if(BaseMath_ReadCallback(line_a1) == -1 || BaseMath_ReadCallback(line_a2) == -1 || BaseMath_ReadCallback(line_b1) == -1 || BaseMath_ReadCallback(line_b2) == -1) return NULL; if(isect_seg_seg_v2_point(line_a1->vec, line_a2->vec, line_b1->vec, line_b2->vec, vi) == 1) { return newVectorObject(vi, 2, Py_NEW, NULL); - } else { + } + else { Py_RETURN_NONE; } } @@ -516,7 +525,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec return NULL; } - if(!BaseMath_ReadCallback(pt) || !BaseMath_ReadCallback(line_1) || !BaseMath_ReadCallback(line_2)) + if(BaseMath_ReadCallback(pt) == -1 || BaseMath_ReadCallback(line_1) == -1 || BaseMath_ReadCallback(line_2) == -1) return NULL; /* accept 2d verts */ @@ -530,7 +539,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec else { l2[2]=0.0; VECCOPY2D(l2, line_2->vec) } /* do the calculation */ - lambda= closest_to_line_v3(pt_out,pt_in, l1, l2); + lambda= closest_to_line_v3(pt_out, pt_in, l1, l2); ret= PyTuple_New(2); PyTuple_SET_ITEM(ret, 0, newVectorObject(pt_out, 3, Py_NEW, NULL)); @@ -566,7 +575,7 @@ static PyObject *M_Geometry_intersect_point_tri_2d(PyObject *UNUSED(self), PyObj return NULL; } - if(!BaseMath_ReadCallback(pt_vec) || !BaseMath_ReadCallback(tri_p1) || !BaseMath_ReadCallback(tri_p2) || !BaseMath_ReadCallback(tri_p3)) + if(BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(tri_p1) == -1 || BaseMath_ReadCallback(tri_p2) == -1 || BaseMath_ReadCallback(tri_p3) == -1) return NULL; return PyLong_FromLong(isect_point_tri_v2(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec)); @@ -603,7 +612,7 @@ static PyObject *M_Geometry_intersect_point_quad_2d(PyObject *UNUSED(self), PyOb return NULL; } - if(!BaseMath_ReadCallback(pt_vec) || !BaseMath_ReadCallback(quad_p1) || !BaseMath_ReadCallback(quad_p2) || !BaseMath_ReadCallback(quad_p3) || !BaseMath_ReadCallback(quad_p4)) + if(BaseMath_ReadCallback(pt_vec) == -1 || BaseMath_ReadCallback(quad_p1) == -1 || BaseMath_ReadCallback(quad_p2) == -1 || BaseMath_ReadCallback(quad_p3) == -1 || BaseMath_ReadCallback(quad_p4) == -1) return NULL; return PyLong_FromLong(isect_point_quad_v2(pt_vec->vec, quad_p1->vec, quad_p2->vec, quad_p3->vec, quad_p4->vec)); @@ -677,7 +686,7 @@ static char M_Geometry_box_pack_2d_doc[] = "\n" " Returns the normal of the 3D tri or quad.\n" "\n" -" :arg boxes: list of boxes, each box is a list where the first 4 items are [x,y, width, height, ...] other items are ignored.\n" +" :arg boxes: list of boxes, each box is a list where the first 4 items are [x, y, width, height, ...] other items are ignored.\n" " :type boxes: list\n" " :return: the width and height of the packed bounding box\n" " :rtype: tuple, pair of floats\n" @@ -690,7 +699,7 @@ static PyObject *M_Geometry_box_pack_2d(PyObject *UNUSED(self), PyObject *boxlis PyObject *ret; if(!PyList_Check(boxlist)) { - PyErr_SetString(PyExc_TypeError, "expected a list of boxes [[x,y,w,h], ... ]"); + PyErr_SetString(PyExc_TypeError, "expected a list of boxes [[x, y, w, h], ... ]"); return NULL; } @@ -760,7 +769,7 @@ static PyObject *M_Geometry_interpolate_bezier(PyObject *UNUSED(self), PyObject* return NULL; } - if(!BaseMath_ReadCallback(vec_k1) || !BaseMath_ReadCallback(vec_h1) || !BaseMath_ReadCallback(vec_k2) || !BaseMath_ReadCallback(vec_h2)) + if(BaseMath_ReadCallback(vec_k1) == -1 || BaseMath_ReadCallback(vec_h1) == -1 || BaseMath_ReadCallback(vec_k2) == -1 || BaseMath_ReadCallback(vec_h2) == -1) return NULL; dims= MAX4(vec_k1->size, vec_h1->size, vec_h2->size, vec_k2->size); @@ -832,10 +841,10 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje vec_t1_tar->size != 3 || vec_t2_tar->size != 3 || vec_t3_tar->size != 3) - { - PyErr_SetString(PyExc_ValueError, "One of more of the vector arguments wasnt a 3D vector"); - return NULL; - } + { + PyErr_SetString(PyExc_ValueError, "One of more of the vector arguments wasnt a 3D vector"); + return NULL; + } barycentric_transform(vec, vec_pt->vec, vec_t1_tar->vec, vec_t2_tar->vec, vec_t3_tar->vec, @@ -844,7 +853,7 @@ static PyObject *M_Geometry_barycentric_transform(PyObject *UNUSED(self), PyObje return newVectorObject(vec, 3, Py_NEW, NULL); } -struct PyMethodDef M_Geometry_methods[]= { +static PyMethodDef M_Geometry_methods[]= { {"intersect_ray_tri", (PyCFunction) M_Geometry_intersect_ray_tri, METH_VARARGS, M_Geometry_intersect_ray_tri_doc}, {"intersect_point_line", (PyCFunction) M_Geometry_intersect_point_line, METH_VARARGS, M_Geometry_intersect_point_line_doc}, {"intersect_point_tri_2d", (PyCFunction) M_Geometry_intersect_point_tri_2d, METH_VARARGS, M_Geometry_intersect_point_tri_2d_doc}, @@ -866,10 +875,10 @@ static struct PyModuleDef M_Geometry_module_def= { M_Geometry_doc, /* m_doc */ 0, /* m_size */ M_Geometry_methods, /* m_methods */ - 0, /* m_reload */ - 0, /* m_traverse */ - 0, /* m_clear */ - 0, /* m_free */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ }; /*----------------------------MODULE INIT-------------------------*/ |