From 7aeaeaf37805d7d906787e5ad5d0d76817dd0bc5 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 Aug 2012 11:27:46 +0000 Subject: 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. --- source/blender/python/mathutils/mathutils_geometry.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source') diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index 524515ac460..19f9aa2dc88 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -728,6 +728,7 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec 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 @@ static PyObject *M_Geometry_intersect_point_line(PyObject *UNUSED(self), PyObjec } /* 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; } -- cgit v1.2.3