Ahhh neat. Hmm... having had a quick look at your code earlier today, I'm feeling a little tempted to add some cache-behavior optimizations to my tree... oh wow... just realized it's been 3 years since I touched it.
Feel free to port it to Lua while you're at it... :-) Just kidding, but fyi I might sometime. The first time I tried to write a BerryBots gun and realized I didn't have a kd-tree to work with was sobering. :-)