This is a simple conversion of BLI_kdtree to a version that supports any number of dimensions.
It currently only supports find_nearest (not range_search and other utility functions).
There are some open topics here, so this is a request-for-discussion on how best to resolve the issue.
- We could solve this by having a template function similar to source/blender/blenlib/intern/list_sort_impl.h to avoid duplicate code. (then define a float[3] and float[4] version).
- We could solve selecting co-planar faces differently (use a different data-structure for eg).
- Using a single distance for angle and distance isn't correct, It could pass in a distance callback which could treat components differently.
OTOH, in practice this patch work well as-is, making select co-planar usable again.