QuadTree algorithm on JavaScript