Skip to content

Commit

Permalink
Merge pull request #170 from d3/two-large-circles-150
Browse files Browse the repository at this point in the history
rescale epsilon to the circles' magnitude
  • Loading branch information
Fil authored Aug 23, 2020
2 parents 3b614f2 + d368302 commit 48a5616
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pack/enclose.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function enclosesNot(a, b) {
}

function enclosesWeak(a, b) {
var dr = a.r - b.r + 1e-6, dx = b.x - a.x, dy = b.y - a.y;
var dr = a.r - b.r + Math.max(a.r, b.r, 1) * 1e-9, dx = b.x - a.x, dy = b.y - a.y;
return dr > 0 && dr * dr > dx * dx + dy * dy;
}

Expand Down
10 changes: 10 additions & 0 deletions test/pack/siblings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ tape("packSiblings(circles) can successfully pack a circle with a tiny radius",
test.end();
});

tape("packSiblings accepts large circles", function(test) {
test.deepEqual(d3.packSiblings([ {r: 1e+11}, {r: 1}, {r: 1} ]),
[{r: 1e+11, x: 0, y: 0}, {r: 1, x: 1e+11 + 1, y: 0}, {r: 1, x: 1e+11 + 1, y: 2}]
);
test.deepEqual(d3.packSiblings([ {r: 1e+16}, {r: 1}, {r: 1} ]),
[{r: 1e+16, x: 0, y: 0}, {r: 1, x: 1e+16 + 1, y: 0}, {r: 1, x: 1e+16 + 1, y: 2}]
);
test.end();
});

function swap(array, i, j) {
var t = array[i];
array[i] = array[j];
Expand Down

0 comments on commit 48a5616

Please sign in to comment.