Commit: 1cb6a374d1379cb4dae0be83649d30c5df42452a
Author: Lukas Tönne
Date:   Thu Dec 18 11:42:20 2014 +0100
Branches: mathutils_bvhtree
https://developer.blender.org/rB1cb6a374d1379cb4dae0be83649d30c5df42452a

Use separate result tuple constructors for ray_cast and find_nearest.

These are technically the same, but the semantics are slightly different
(distance vs squared distance).

===================================================================

M       source/blender/python/mathutils/mathutils_bvhtree.c

===================================================================

diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c 
b/source/blender/python/mathutils/mathutils_bvhtree.c
index db05ce1..feb0e49 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -97,7 +97,7 @@ static int dm_tessface_to_poly_index_safe(DerivedMesh *dm, 
int tessface_index)
        return ORIGINDEX_NONE;
 }
 
-static PyObject *bvhtree_lookup_result_to_py(const float co[3], const float 
no[3], int index, float dist)
+static PyObject *bvhtree_ray_hit_to_py(const float co[3], const float no[3], 
int index, float dist)
 {
        PyObject *py_retval = PyTuple_New(4);
 
@@ -109,6 +109,18 @@ static PyObject *bvhtree_lookup_result_to_py(const float 
co[3], const float no[3
        return py_retval;
 }
 
+static PyObject *bvhtree_nearest_to_py(const float co[3], const float no[3], 
int index, float dist_sq)
+{
+       PyObject *py_retval = PyTuple_New(4);
+
+       PyTuple_SET_ITEM(py_retval, 0, Vector_CreatePyObject((float *)co, 3, 
Py_NEW, NULL));
+       PyTuple_SET_ITEM(py_retval, 1, Vector_CreatePyObject((float *)no, 3, 
Py_NEW, NULL));
+       PyTuple_SET_ITEM(py_retval, 2, PyLong_FromLong(index));
+       PyTuple_SET_ITEM(py_retval, 3, PyFloat_FromDouble(dist_sq));
+
+       return py_retval;
+}
+
 /* -------------------------------------------------------------------- */
 /* BVHTree */
 
@@ -333,12 +345,12 @@ static PyObject *py_BVHTree_ray_cast(PyBVHTree *self, 
PyObject *args, PyObject *
                {
                        if (hit.dist <= dist) {
                                int ret_index = use_poly_index ? 
dm_tessface_to_poly_index_safe(ob->derivedFinal, hit.index) : hit.index;
-                               return bvhtree_lookup_result_to_py(hit.co, 
hit.no, ret_index, hit.dist);
+                               return bvhtree_ray_hit_to_py(hit.co, hit.no, 
ret_index, hit.dist);
                        }
                }
        }
        
-       return bvhtree_lookup_result_to_py(ZERO, ZERO, -1, 0.0f);
+       return bvhtree_ray_hit_to_py(ZERO, ZERO, -1, 0.0f);
 }
 
 PyDoc_STRVAR(py_BVHTree_find_nearest_doc,
@@ -390,11 +402,11 @@ static PyObject *py_BVHTree_find_nearest(PyBVHTree *self, 
PyObject *args, PyObje
                                             meshdata->nearest_callback, 
meshdata) != -1)
                {
                        int ret_index = use_poly_index ? 
dm_tessface_to_poly_index_safe(ob->derivedFinal, nearest.index) : nearest.index;
-                       return bvhtree_lookup_result_to_py(nearest.co, 
nearest.no, ret_index, nearest.dist_sq);
+                       return bvhtree_nearest_to_py(nearest.co, nearest.no, 
ret_index, nearest.dist_sq);
                }
        }
        
-       return bvhtree_lookup_result_to_py(ZERO, ZERO, -1, 0.0f);
+       return bvhtree_ray_hit_to_py(ZERO, ZERO, -1, 0.0f);
 }

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to