From 3d5510ce43c050ead94548462f580718b2463d73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Wed, 12 Aug 2020 11:33:39 +0200 Subject: [PATCH 1/3] rescale epsilon to the circles' magnitude fixes #150 --- src/pack/enclose.js | 3 ++- test/pack/siblings-test.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pack/enclose.js b/src/pack/enclose.js index 8b1d4d88..faf101f0 100644 --- a/src/pack/enclose.js +++ b/src/pack/enclose.js @@ -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; } diff --git a/test/pack/siblings-test.js b/test/pack/siblings-test.js index 004ab52b..c2c712df 100644 --- a/test/pack/siblings-test.js +++ b/test/pack/siblings-test.js @@ -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]; From 599d988456456a72cd938c4cdd1557052d909fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Mon, 17 Aug 2020 12:03:34 +0200 Subject: [PATCH 2/3] one more test --- test/pack/siblings-test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/pack/siblings-test.js b/test/pack/siblings-test.js index c2c712df..244084b1 100644 --- a/test/pack/siblings-test.js +++ b/test/pack/siblings-test.js @@ -37,6 +37,9 @@ 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(); }); From d368302608e1664d4d57df0c9af4fdf978692122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Sun, 23 Aug 2020 20:28:57 +0200 Subject: [PATCH 3/3] Update src/pack/enclose.js Co-authored-by: Mike Bostock --- src/pack/enclose.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pack/enclose.js b/src/pack/enclose.js index faf101f0..86231caa 100644 --- a/src/pack/enclose.js +++ b/src/pack/enclose.js @@ -47,8 +47,7 @@ function enclosesNot(a, b) { } function enclosesWeak(a, b) { - 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; + 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; }