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] 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];