Skip to content

Commit

Permalink
rescale epsilon to the circles' magnitude
Browse files Browse the repository at this point in the history
fixes #150
  • Loading branch information
Fil committed Aug 12, 2020
1 parent 7c04f65 commit 3d5510c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/pack/enclose.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ 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 scale = Math.max(a.r, b.r, 1) * 1e-9;
var dr = a.r - b.r + scale, dx = b.x - a.x, dy = b.y - a.y;
return dr > 0 && dr * dr > dx * dx + dy * dy;
}

Expand Down
7 changes: 7 additions & 0 deletions test/pack/siblings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ 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.end();
});

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

0 comments on commit 3d5510c

Please sign in to comment.