From 8df1b9ee17cf433141fedd2956a4dbe152962211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Tue, 7 Jul 2020 16:32:07 +0200 Subject: [PATCH 1/2] aabb example to document visit --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index 05692ff..42b5a19 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,26 @@ Visits each [node](#nodes) in the quadtree in pre-order traversal, invoking the If the *callback* returns true for a given node, then the children of that node are not visited; otherwise, all child nodes are visited. This can be used to quickly visit only parts of the tree, for example when using the [Barnes–Hut approximation](https://en.wikipedia.org/wiki/Barnes–Hut_simulation). Note, however, that child quadrants are always visited in sibling order: top-left, top-right, bottom-left, bottom-right. In cases such as [search](#quadtree_find), visiting siblings in a specific order may be faster. +As an example, the following visits the quadtree an returns all the nodes within a rectangular extent [xmin, ymin, xmax, ymax], ignoring quads that cannot possibly contain any such node: + +```js +function search(quadtree, xmin, ymin, xmax, ymax) { + const results = []; + quadtree.visit(function(node, x1, y1, x2, y2) { + if (!node.length) { + do { + var d = node.data; + if (d[0] >= xmin && d[0] < xmax && d[1] >= ymin && d[1] < ymax) { + results.push(d); + } + } while (node = node.next); + } + return x1 >= xmax || y1 >= ymax || x2 < xmin || y2 < ymin; + }); + return results; +} +``` + # quadtree.visitAfter(callback) [<>](https://github.com/d3/d3-quadtree/blob/master/src/visitAfter.js "Source") From 6950ac85f5a52efda8f8aa96e04556843729f96a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Fri, 10 Jul 2020 21:30:23 +0200 Subject: [PATCH 2/2] typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42b5a19..334c9e6 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,7 @@ Visits each [node](#nodes) in the quadtree in pre-order traversal, invoking the If the *callback* returns true for a given node, then the children of that node are not visited; otherwise, all child nodes are visited. This can be used to quickly visit only parts of the tree, for example when using the [Barnes–Hut approximation](https://en.wikipedia.org/wiki/Barnes–Hut_simulation). Note, however, that child quadrants are always visited in sibling order: top-left, top-right, bottom-left, bottom-right. In cases such as [search](#quadtree_find), visiting siblings in a specific order may be faster. -As an example, the following visits the quadtree an returns all the nodes within a rectangular extent [xmin, ymin, xmax, ymax], ignoring quads that cannot possibly contain any such node: +As an example, the following visits the quadtree and returns all the nodes within a rectangular extent [xmin, ymin, xmax, ymax], ignoring quads that cannot possibly contain any such node: ```js function search(quadtree, xmin, ymin, xmax, ymax) {