Skip to content

Commit eadf003

Browse files
committed
Clamp Math.sqrt to be on the safe side.
1 parent 9b3e780 commit eadf003

3 files changed

Lines changed: 8 additions & 8 deletions

File tree

d3.v2.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6286,8 +6286,8 @@ function d3_layout_packPlace(a, b, c) {
62866286
dc = dx * dx + dy * dy;
62876287
da *= da;
62886288
db *= db;
6289-
var x = (db + dc - da) / (2 * dc),
6290-
y = Math.sqrt(2 * da * (db + dc) - (db - dc) * (db - dc) - da * da) / (2 * dc);
6289+
var x = .5 + (db - da) / (2 * dc),
6290+
y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
62916291
c.x = a.x + x * dx + y * dy;
62926292
c.y = a.y + x * dy - y * dx;
62936293
} else {

0 commit comments

Comments
 (0)