[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [50256] trunk/blender/source/blender/ python/mathutils/mathutils_geometry.c: fix bug in mathutils.geometry. intersect_point_line() where 4D vectors were treated as 2D.

Campbell Barton ideasman42 at gmail.com
Tue Aug 28 13:27:47 CEST 2012


Revision: 50256
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=50256
Author:   campbellbarton
Date:     2012-08-28 11:27:46 +0000 (Tue, 28 Aug 2012)
Log Message:
-----------
fix bug in mathutils.geometry.intersect_point_line() where 4D vectors were treated as 2D.

also change behavior to return a 2d vector when all args are 2D.

Modified Paths:
--------------
    trunk/blender/source/blender/python/mathutils/mathutils_geometry.c

Modified: trunk/blender/source/blender/python/mathutils/mathutils_geometry.c
===================================================================
--- trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2012-08-28 10:41:37 UTC (rev 50255)
+++ trunk/blender/source/blender/python/mathutils/mathutils_geometry.c	2012-08-28 11:27:46 UTC (rev 50256)
@@ -728,6 +728,7 @@
 	float pt_in[3], pt_out[3], l1[3], l2[3];
 	float lambda;
 	PyObject *ret;
+	int size = 2;
 	
 	if (!PyArg_ParseTuple(args, "O!O!O!:intersect_point_line",
 	                      &vector_Type, &pt,
@@ -745,20 +746,20 @@
 	}
 
 	/* accept 2d verts */
-	if (pt->size == 3) {     copy_v3_v3(pt_in, pt->vec); }
-	else { pt_in[2] = 0.0f;  copy_v2_v2(pt_in, pt->vec); }
+	if (pt->size >= 3)     { copy_v3_v3(pt_in, pt->vec); size = 3; }
+	else                   { copy_v2_v2(pt_in, pt->vec); pt_in[2] = 0.0f; }
 	
-	if (line_1->size == 3) { copy_v3_v3(l1, line_1->vec); }
-	else { l1[2] = 0.0f;     copy_v2_v2(l1, line_1->vec); }
+	if (line_1->size >= 3) { copy_v3_v3(l1, line_1->vec); size = 3; }
+	else                   { copy_v2_v2(l1, line_1->vec); l1[2] = 0.0f; }
 	
-	if (line_2->size == 3) { copy_v3_v3(l2, line_2->vec); }
-	else { l2[2] = 0.0f;     copy_v2_v2(l2, line_2->vec); }
+	if (line_2->size >= 3) { copy_v3_v3(l2, line_2->vec); size = 3; }
+	else                   { copy_v2_v2(l2, line_2->vec); l2[2] = 0.0f; }
 	
 	/* do the calculation */
 	lambda = closest_to_line_v3(pt_out, pt_in, l1, l2);
 	
 	ret = PyTuple_New(2);
-	PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(pt_out, 3, Py_NEW, NULL));
+	PyTuple_SET_ITEM(ret, 0, Vector_CreatePyObject(pt_out, size, Py_NEW, NULL));
 	PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(lambda));
 	return ret;
 }




More information about the Bf-blender-cvs mailing list