Index: /trunk/psLib/src/types/psTree.c
===================================================================
--- /trunk/psLib/src/types/psTree.c	(revision 18343)
+++ /trunk/psLib/src/types/psTree.c	(revision 18344)
@@ -368,11 +368,29 @@
     PS_ASSERT_TREE_NON_NULL(tree, NULL);
     PS_ASSERT_VECTOR_NON_NULL(coords, NULL);
-    PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, NULL);
     PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, NULL);
 #endif
 
+#define TREE_LEAF_CASE(TYPE) \
+  case PS_TYPE_##TYPE: \
+      for (; node->left; node = (coords->data.TYPE[node->divideDim] < tree->division[node->index]) ? \
+               node->left : node->right); \
+      break;
+
     psTreeNode *node = tree->root;      // Node of interest
-    for (; node->left; node = coords->data.F64[node->divideDim] < tree->division[node->index] ?
-             node->left : node->right);
+    switch (coords->type.type) {
+        TREE_LEAF_CASE(U8);
+        TREE_LEAF_CASE(U16);
+        TREE_LEAF_CASE(U32);
+        TREE_LEAF_CASE(U64);
+        TREE_LEAF_CASE(S8);
+        TREE_LEAF_CASE(S16);
+        TREE_LEAF_CASE(S32);
+        TREE_LEAF_CASE(S64);
+        TREE_LEAF_CASE(F32);
+        TREE_LEAF_CASE(F64);
+      default:
+        psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Unsupported type: %x", coords->type.type);
+        return NULL;
+    }
     return node;
 }
@@ -464,5 +482,5 @@
 // This is the engine for psTreeNearest() and psTreeNearestWithin()
 static inline long treeNearestWithin(const psTree *tree, // Tree
-                                     const psVector *coords, // Coordinates of interest
+                                     const psVector *coordinates, // Coordinates of interest
                                      double bestDistance // Distance (radius-squared) to best point
     )
@@ -470,8 +488,10 @@
 #if 1 // Might be in a tight loop
     PS_ASSERT_TREE_NON_NULL(tree, -1);
-    PS_ASSERT_VECTOR_NON_NULL(coords, -1);
-    PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, -1);
-    PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, -1);
+    PS_ASSERT_VECTOR_NON_NULL(coordinates, -1);
+    PS_ASSERT_VECTOR_SIZE(coordinates, (long)tree->dim, -1);
 #endif
+
+    psVector *coords = (coordinates->type.type == PS_TYPE_F64 ? psMemIncrRefCounter((psVector*)coordinates) :
+                        psVectorCopy(NULL, coordinates, PS_TYPE_F64)); // F64 version of coordinates
 
     // Find the closest point in the leaf that contains the point of interest
@@ -513,4 +533,5 @@
     }
     psFree(work);
+    psFree(coords);
 
     return bestIndex;
@@ -549,12 +570,14 @@
 
 // Given an arbitrary point and a matching radius, return the number of points within that radius
-long psTreeWithin(const psTree *tree, const psVector *coords, double radius)
+long psTreeWithin(const psTree *tree, const psVector *coordinates, double radius)
 {
 #if 1 // Might be in a tight loop
     PS_ASSERT_TREE_NON_NULL(tree, -1);
-    PS_ASSERT_VECTOR_NON_NULL(coords, -1);
-    PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, -1);
-    PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, -1);
+    PS_ASSERT_VECTOR_NON_NULL(coordinates, -1);
+    PS_ASSERT_VECTOR_SIZE(coordinates, (long)tree->dim, -1);
 #endif
+
+    psVector *coords = (coordinates->type.type == PS_TYPE_F64 ? psMemIncrRefCounter((psVector*)coordinates) :
+                        psVectorCopy(NULL, coordinates, PS_TYPE_F64)); // F64 version of coordinates
 
     radius *= radius;                   // We work with the radius-squared
@@ -590,4 +613,5 @@
     }
     psFree(work);
+    psFree(coords);
 
     return num;
@@ -612,12 +636,14 @@
 
 // Given an arbitrary point and a matching radius, return whether there are any points within that radius
-bool psTreeWithinAny(const psTree *tree, const psVector *coords, double radius)
+bool psTreeWithinAny(const psTree *tree, const psVector *coordinates, double radius)
 {
 #if 1 // Might be in a tight loop
     PS_ASSERT_TREE_NON_NULL(tree, false);
-    PS_ASSERT_VECTOR_NON_NULL(coords, false);
-    PS_ASSERT_VECTOR_TYPE(coords, PS_TYPE_F64, false);
-    PS_ASSERT_VECTOR_SIZE(coords, (long)tree->dim, false);
+    PS_ASSERT_VECTOR_NON_NULL(coordinates, false);
+    PS_ASSERT_VECTOR_SIZE(coordinates, (long)tree->dim, false);
 #endif
+
+    psVector *coords = (coordinates->type.type == PS_TYPE_F64 ? psMemIncrRefCounter((psVector*)coordinates) :
+                        psVectorCopy(NULL, coordinates, PS_TYPE_F64)); // F64 version of coordinates
 
     radius *= radius;                   // We work with the radius-squared
@@ -628,4 +654,5 @@
     psTreeNode *leaf = psTreeLeaf(tree, coords); // Leaf containing the point of interest
     if (treeLeafSearchWithinAny(radius, tree, leaf, coords)) {
+        psFree(coords);
         return true;
     }
@@ -650,4 +677,5 @@
                 memset(work->data, 0, (workIndex + 1) * sizeof(void));
                 psFree(work);
+                psFree(coords);
                 return true;
             }
@@ -659,4 +687,5 @@
     }
     psFree(work);
+    psFree(coords);
 
     return false;
