Skip to content

Commit

Permalink
Merge branch 'pack-opt' of git://github.com/jasondavies/d3 into 2.9.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Jul 31, 2012
2 parents fb86373 + eadf003 commit 313c5b3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
10 changes: 5 additions & 5 deletions d3.v2.js
Original file line number Diff line number Diff line change
Expand Up @@ -6283,11 +6283,11 @@ function d3_layout_packPlace(a, b, c) {
dy = b.y - a.y;
if (db && (dx || dy)) {
var da = b.r + c.r,
dc = Math.sqrt(dx * dx + dy * dy),
cos = Math.max(-1, Math.min(1, (db * db + dc * dc - da * da) / (2 * db * dc))),
theta = Math.acos(cos),
x = cos * (db /= dc),
y = Math.sin(theta) * db;
dc = dx * dx + dy * dy;
da *= da;
db *= db;
var x = .5 + (db - da) / (2 * dc),
y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
c.x = a.x + x * dx + y * dy;
c.y = a.y + x * dy - y * dx;
} else {
Expand Down
8 changes: 4 additions & 4 deletions d3.v2.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/layout/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ function d3_layout_packPlace(a, b, c) {
dy = b.y - a.y;
if (db && (dx || dy)) {
var da = b.r + c.r,
dc = Math.sqrt(dx * dx + dy * dy),
cos = Math.max(-1, Math.min(1, (db * db + dc * dc - da * da) / (2 * db * dc))),
theta = Math.acos(cos),
x = cos * (db /= dc),
y = Math.sin(theta) * db;
dc = dx * dx + dy * dy;
da *= da;
db *= db;
var x = .5 + (db - da) / (2 * dc),
y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
c.x = a.x + x * dx + y * dy;
c.y = a.y + x * dy - y * dx;
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/layout/pack-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ suite.addBatch({
{y: 0.5084543199854831, x: 0.4682608366855136, value: 0.01, r: 0.016411496513964046, depth: 1},
{y: 0.5084543199854831, x: 0.7167659426883449, value: 2, r: 0.23209360948886723, depth: 1},
{y: 0.34256315498862167, x: 0.2832340573116551, value: 2, r: 0.23209360948886723, depth: 1},
{y: 0.7254154893606051, x: 0.3852405506102519, value: 1, r: 0.16411496513964044, depth: 1}
{y: 0.7254154893606051, x: 0.38524055061025186, value: 1, r: 0.16411496513964044, depth: 1}
]);
assert.deepEqual(d3.layout.pack().sort(null).nodes({children: [
{value: 2},
Expand All @@ -45,7 +45,7 @@ suite.addBatch({
{y: 0.6274712284943809, x: 0.26624891409386664, value: 2, r: 0.23375108590613333, depth: 1},
{y: 0.6274712284943809, x: 0.7337510859061334, value: 2, r: 0.23375108590613333, depth: 1},
{y: 0.30406466355343187, x: 0.5, value: 1, r: 0.1652869779539461, depth: 1},
{y: 0.3878967195987758, x: 0.3386645534068855, value: 0.01, r: 0.01652869779539461, depth: 1}
{y: 0.3878967195987758, x: 0.3386645534068854, value: 0.01, r: 0.01652869779539461, depth: 1}
]);
},
"can handle residual floating point error": function(pack) {
Expand Down

0 comments on commit 313c5b3

Please sign in to comment.