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:
authorCampbell Barton <ideasman42@gmail.com>2007-04-28 00:48:23 +0400
committerCampbell Barton <ideasman42@gmail.com>2007-04-28 00:48:23 +0400
commita2000b53cd2a8c8b3945c8f457f1189f750c8c98 (patch)
tree424d18abf9eaf602ea5817bacfe6712def1a02ca /source/blender/python/api2_2x/Geometry.c
parentc84d18a67996832395b4d580a4e3db66e57b5778 (diff)
Adding Blender.Geometry function PointInTriangle2D
Diffstat (limited to 'source/blender/python/api2_2x/Geometry.c')
-rw-r--r--source/blender/python/api2_2x/Geometry.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/source/blender/python/api2_2x/Geometry.c b/source/blender/python/api2_2x/Geometry.c
index 4504c2d5d29..816fa03ac30 100644
--- a/source/blender/python/api2_2x/Geometry.c
+++ b/source/blender/python/api2_2x/Geometry.c
@@ -54,17 +54,20 @@
/*-- forward declarations -- */
static PyObject *M_Geometry_PolyFill( PyObject * self, PyObject * args );
static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args );
+static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args );
static PyObject *M_Geometry_BoxPack2D( PyObject * self, PyObject * args );
/*-------------------------DOC STRINGS ---------------------------*/
static char M_Geometry_doc[] = "The Blender Geometry module\n\n";
static char M_Geometry_PolyFill_doc[] = "(veclist_list) - takes a list of polylines (each point a vector) and returns the point indicies for a polyline filled with triangles";
static char M_Geometry_LineIntersect2D_doc[] = "(lineA_p1, lineA_p2, lineB_p1, lineB_p2) - takes 2 lines (as 4 vectors) and returns a vector for their point of intersection or None";
+static char M_Geometry_PointInTriangle2D_doc[] = "(pt, tri_p1, tri_p2, tri_p3) - takes 4 vectors, one is the point and the next 3 define the triabgle, only the x and y are used from the vectors";
static char M_Geometry_BoxPack2D_doc[] = "";
/*-----------------------METHOD DEFINITIONS ----------------------*/
struct PyMethodDef M_Geometry_methods[] = {
{"PolyFill", ( PyCFunction ) M_Geometry_PolyFill, METH_VARARGS, M_Geometry_PolyFill_doc},
{"LineIntersect2D", ( PyCFunction ) M_Geometry_LineIntersect2D, METH_VARARGS, M_Geometry_LineIntersect2D_doc},
+ {"PointInTriangle2D", ( PyCFunction ) M_Geometry_PointInTriangle2D, METH_VARARGS, M_Geometry_PointInTriangle2D_doc},
{"BoxPack2D", ( PyCFunction ) M_Geometry_BoxPack2D, METH_VARARGS, M_Geometry_BoxPack2D_doc},
{NULL, NULL, 0, NULL}
};
@@ -274,6 +277,28 @@ static PyObject *M_Geometry_LineIntersect2D( PyObject * self, PyObject * args )
Py_RETURN_NONE;
}
+#define SIDE_OF_LINE(pa,pb,pp) ((pa[0]-pp[0])*(pb[1]-pp[1]))-((pb[0]-pp[0])*(pa[1]-pp[1]))
+#define POINT_IN_TRI(p0,p1,p2,p3) ((SIDE_OF_LINE(p1,p2,p0)>=0) && (SIDE_OF_LINE(p2,p3,p0)>=0) && (SIDE_OF_LINE(p3,p1,p0)>=0))
+
+static PyObject *M_Geometry_PointInTriangle2D( PyObject * self, PyObject * args )
+{
+ VectorObject *pt_vec, *tri_p1, *tri_p2, *tri_p3;
+
+ if( !PyArg_ParseTuple ( args, "O!O!O!O!",
+ &vector_Type, &pt_vec,
+ &vector_Type, &tri_p1,
+ &vector_Type, &tri_p2,
+ &vector_Type, &tri_p3)
+ )
+ return ( EXPP_ReturnPyObjError
+ ( PyExc_TypeError, "expected 4 vector types\n" ) );
+
+ if POINT_IN_TRI(pt_vec->vec, tri_p1->vec, tri_p2->vec, tri_p3->vec)
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
+
int boxPack_FromPyObject(PyObject * value, boxPack **boxarray )
{
int len, i;