Skip to content

Commit c4caa95

Browse files
committed
Only cache points if there are no bounds.
1 parent 1ce0475 commit c4caa95

3 files changed

Lines changed: 60 additions & 46 deletions

File tree

d3.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4478,26 +4478,28 @@ d3 = function() {
44784478
return quadtree(points);
44794479
}
44804480
function quadtree(data) {
4481-
var d, fx = d3_functor(x), fy = d3_functor(y), xs = [], ys = [], i, n = data.length, x1_, y1_, x2_, y2_;
4482-
if (compat) for (i = 0; i < n; ++i) {
4483-
d = data[i];
4484-
xs.push(d.x);
4485-
ys.push(d.y);
4486-
} else for (i = 0; i < n; ++i) {
4487-
xs.push(+fx(d = data[i], i));
4488-
ys.push(+fy(d, i));
4489-
}
4481+
var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
44904482
if (x1 != null) {
44914483
x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
44924484
} else {
44934485
x2_ = y2_ = -(x1_ = y1_ = Infinity);
4494-
for (i = 0; i < n; ++i) {
4495-
d = xs[i];
4496-
if (d < x1_) x1_ = d;
4497-
if (d > x2_) x2_ = d;
4498-
d = ys[i];
4499-
if (d < y1_) y1_ = d;
4500-
if (d > y2_) y2_ = d;
4486+
n = data.length;
4487+
if (compat) for (i = 0; i < n; ++i) {
4488+
d = data[i];
4489+
if (d.x < x1_) x1_ = d.x;
4490+
if (d.y < y1_) y1_ = d.y;
4491+
if (d.x > x2_) x2_ = d.x;
4492+
if (d.y > y2_) y2_ = d.y;
4493+
xs.push(d.x);
4494+
ys.push(d.y);
4495+
} else for (i = 0; i < n; ++i) {
4496+
var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
4497+
if (x_ < x1_) x1_ = x_;
4498+
if (y_ < y1_) y1_ = y_;
4499+
if (x_ > x2_) x2_ = x_;
4500+
if (y_ > y2_) y2_ = y_;
4501+
xs.push(x_);
4502+
ys.push(y_);
45014503
}
45024504
}
45034505
var dx = x2_ - x1_, dy = y2_ - y1_;
@@ -4537,10 +4539,14 @@ d3 = function() {
45374539
root.visit = function(f) {
45384540
d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
45394541
};
4540-
for (i = 0; i < n; ++i) {
4541-
insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
4542-
}
4543-
--i;
4542+
i = -1;
4543+
if (x1 == null) {
4544+
while (++i < n) {
4545+
insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
4546+
}
4547+
--i;
4548+
} else data.forEach(root.add);
4549+
xs = ys = data = d = null;
45444550
return root;
45454551
}
45464552
quadtree.x = function(_) {

0 commit comments

Comments
 (0)