quadtree-js retrieve nodes

Retrieve Nodes Example

To retrieve that match your query and contain objects you can overwrite the retrieve function like below or use the retrieve-nodes branch.

Github Issue: quadtree-js/issues/17

Quadtree.prototype.retrieve = function (pRect) {

    var indexes = this.getIndex(pRect),
        objects = this.objects;

    //modification: collect nodes
    var nodes = [];
    if (this.objects.length) nodes.push(this);


    //if we have subnodes, retrieve their objects
    if (this.nodes.length) {
        for (var i = 0; i < indexes.length; i++) {

            //modification: collect objects and nodes
            const retrieved = this.nodes[indexes[i]].retrieve(pRect);
            objects = objects.concat(retrieved.objects);
            nodes = nodes.concat(retrieved.nodes);
        }
    }

    //remove duplicate objects
    objects = objects.filter(function (item, index) {
        return objects.indexOf(item) >= index;
    });

    //modification: return objects and nodes
    return {
        objects: objects,
        nodes: nodes
    }
};