Skip to content

Commit

Permalink
Fix #74, again.
Browse files Browse the repository at this point in the history
Tested by generating millions of synthetic datasets!
  • Loading branch information
mbostock committed Jan 29, 2017
1 parent 73c4aad commit 2c75ec1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pack/siblings.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,22 +82,22 @@ export function packEnclose(circles) {
// Find the closest intersecting circle on the front-chain, if any.
// “Closeness” is determined by linear distance along the front-chain.
// “Ahead” or “behind” is likewise determined by linear distance.
j = b.next, k = a.previous, sj = b._.r + j._.r, sk = a._.r + k._.r;
j = b.next, k = a.previous, sj = b._.r, sk = a._.r;
do {
if (sj <= sk) {
if (intersects(j._, c._)) {
if (sj + a._.r + b._.r > distance1(j, b)) a = j; else b = j;
a.next = b, b.previous = a, --i;
continue pack;
}
sj += j._.r + (j = j.next)._.r;
sj += j._.r, j = j.next;
} else {
if (intersects(k._, c._)) {
if (distance1(a, k) > sk + a._.r + b._.r) a = k; else b = k;
a.next = b, b.previous = a, --i;
continue pack;
}
sk += k._.r + (k = k.previous)._.r;
sk += k._.r, k = k.previous;
}
} while (j !== k.next);

Expand Down
1 change: 1 addition & 0 deletions test/pack/siblings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tape("packSiblings(circles) produces a non-overlapping layout of circles", funct
permute([100, 200, 500, 70, 3].map(circleValue), p => intersectsAny(d3.packSiblings(p)) && test.fail(p.map(c => c.r)));
permute([3, 30, 50, 400, 600].map(circleValue), p => intersectsAny(d3.packSiblings(p)) && test.fail(p.map(c => c.r)));
permute([1, 1, 3, 30, 50, 400, 600].map(circleValue), p => intersectsAny(d3.packSiblings(p)) && test.fail(p.map(c => c.r)));
test.equal(intersectsAny(d3.packSiblings([0.24155803737254639, 0.06349736576607135, 0.4721808601742349, 0.7469141449305542, 1.6399276349079663].map(circleRadius))), false);
test.equal(intersectsAny(d3.packSiblings([2, 9071, 79, 51, 325, 867, 546, 19773, 371, 16, 165781, 10474, 6928, 40201, 31062, 14213, 8626, 12, 299, 1075, 98918, 4738, 664, 2694, 2619, 51237, 21431, 99, 5920, 1117, 321, 519162, 33559, 234, 4207].map(circleValue))), false);
test.equal(intersectsAny(d3.packSiblings([0.3371386860049076, 58.65337373332081, 2.118883785686244, 1.7024669121097333, 5.834919697833051, 8.949453403094978, 6.792586534702093, 105.30490014617664, 6.058936212213754, 0.9535722042975694, 313.7636051642043].map(circleRadius))), false);
test.equal(intersectsAny(d3.packSiblings([6.26551789195159, 1.707773433636342, 9.43220282933871, 9.298909705475646, 5.753163715613753, 8.882383159012575, 0.5819319661882536, 2.0234859171687747, 2.096171518434433, 9.762727931304937].map(circleRadius))), false);
Expand Down

0 comments on commit 2c75ec1

Please sign in to comment.