Quadtree in javascript
I have been working in jQuery and I was given this code for a quadtree in javascript:
map = array(
array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4)),
array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4)),
array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4)),
array(array(1,2,3,4), array(1,2,3,4), array(1,2,3,4), array(1,2,3,4))
);
map[0][3][3] = "END OF ARRAY 1";
map[1][3][3] = "END OF ARRAY 2";
However this just looks like a 3d array to me, am I bein开发者_开发知识库g stupid? ^.^
Since all nodes have exactly four children it is a quadtree. It is also a 3D array, since it is three levels deep.
So technically this is a quadtree, but it's not what most people would expect if you said "here's some quadtree code".
Quadtree code would normally mean a class that handles building such a tree by inserting objects with 2D coordinates, then finding intersecting or nearby objects.
E.g. see http://www.mikechambers.com/blog/2011/03/21/javascript-quadtree-implementation/
精彩评论