BLI_kdtree: add 2D kdtree support
authorCampbell Barton <ideasman42@gmail.com>
Tue, 19 Mar 2019 13:57:52 +0000 (00:57 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 19 Mar 2019 14:07:07 +0000 (01:07 +1100)
Some users of the 3D versions were storing 2D data in it.

Using a 3D tree for 2D data adds a spatially redundant branch
every 3rd level, as well as some extra memory use, best avoid this.

source/blender/blenlib/BLI_kdtree.h
source/blender/blenlib/CMakeLists.txt
source/blender/blenlib/intern/kdtree_2d.c [new file with mode: 0644]

index af10a44..18f3236 100644 (file)
  * \brief A kd-tree for nearest neighbor search.
  */
 
+/* 2D version */
+#define KD_DIMS 2
+#define KDTREE_PREFIX_ID BLI_kdtree_2d
+#define KDTree KDTree_2d
+#define KDTreeNearest KDTreeNearest_2d
+#include "BLI_kdtree_impl.h"
+#undef KD_DIMS
+#undef KDTree
+#undef KDTreeNearest
+#undef KDTREE_PREFIX_ID
+
 /* 3D version */
 #define KD_DIMS 3
 #define KDTREE_PREFIX_ID BLI_kdtree_3d
index d740fa0..fef24c0 100644 (file)
@@ -75,6 +75,7 @@ set(SRC
        intern/hash_mm2a.c
        intern/hash_mm3.c
        intern/jitter_2d.c
+       intern/kdtree_2d.c
        intern/kdtree_3d.c
        intern/kdtree_4d.c
        intern/lasso_2d.c
diff --git a/source/blender/blenlib/intern/kdtree_2d.c b/source/blender/blenlib/intern/kdtree_2d.c
new file mode 100644 (file)
index 0000000..8ad55e2
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bli
+ */
+
+#define KD_DIMS 2
+#define KDTREE_PREFIX_ID BLI_kdtree_2d
+#define KDTree KDTree_2d
+#define KDTreeNearest KDTreeNearest_2d
+#  include "kdtree_impl.h"