Page MenuHome

Inconsistent python api and documentation in mathutils.
Closed, ResolvedPublic


Blender Version
Broken: rBa6ca8a1b736e

Short description of error
While the api docs show mathutils.bvhtree.BVHTree.find_nearest() this does not exist in the python api.

Exact steps for others to reproduce the error

In blender's pythjon console we get the following -

>>> bvhtree.BVHTree.FromObject(C.object, C.scene).find()
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
TypeError: find_nearest() takes at least 1 argument (0 given)

>>> bvhtree.BVHTree.FromObject(C.object, C.scene).find_nearest()
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
AttributeError: 'BVHTree' object has no attribute 'find_nearest'

I expect that the method name find_nearest would be correct as it is the most used within the code and better describes the function. This mismatch stems from the api definition in mathutils_bvhtree.c with a fix being -

diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c
index 20baf6c..08b1f53 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -1132,7 +1132,7 @@ static PyObject *C_BVHTree_FromObject(PyObject *UNUSED(cls), PyObject *args, PyO
 static PyMethodDef py_bvhtree_methods[] = {
        {"ray_cast", (PyCFunction)py_bvhtree_ray_cast, METH_VARARGS, py_bvhtree_ray_cast_doc},
-       {"find", (PyCFunction)py_bvhtree_find_nearest, METH_VARARGS, py_bvhtree_find_nearest_doc},
+       {"find_nearest", (PyCFunction)py_bvhtree_find_nearest, METH_VARARGS, py_bvhtree_find_nearest_doc},
        {"overlap", (PyCFunction)py_bvhtree_overlap, METH_O, py_bvhtree_overlap_doc},
        /* class methods */

There is a possibility that BVHTree.find() is already in wide use and adjusting the documentation to match the use of BVHTree.find() will be less disruptive.