Fix exact coincidence with d3.forceCollide.

This commit is contained in:
Mike Bostock 2016-04-29 09:33:17 -07:00
parent 75284e0e28
commit cf287b8dba
5 changed files with 8 additions and 6 deletions

View File

@ -1,5 +1,6 @@
import constant from "./constant";
import {quadtree} from "d3-quadtree";
import {tau} from "./math";
function x(d) {
return d.x + d.vx;
@ -51,7 +52,7 @@ export default function(radius) {
l = x * x + y * y,
r = radii[i] + radii[quad.data.index];
if (l < r * r) {
l = (r - (l = Math.sqrt(l))) / l;
l = l ? (r - (l = Math.sqrt(l))) / l : (l = Math.random() * tau, x = Math.cos(l), y = Math.sin(l), r - 1);
vx += x * l, vy += y * l;
}
}

View File

@ -1,7 +1,6 @@
import {map} from "d3-collection";
import constant from "./constant";
var tau = 2 * Math.PI;
import {tau} from "./math";
function index(d, i) {
return i;

View File

@ -1,8 +1,7 @@
import constant from "./constant";
import {quadtree} from "d3-quadtree";
import {x, y} from "./simulation";
var tau = 2 * Math.PI;
import {tau} from "./math";
export default function() {
var nodes,

2
src/math.js Normal file
View File

@ -0,0 +1,2 @@
export var pi = Math.PI;
export var tau = 2 * pi;

View File

@ -1,6 +1,7 @@
import {dispatch} from "d3-dispatch";
import {map} from "d3-collection";
import {timer} from "d3-timer";
import {pi} from "./math";
export function x(d) {
return d.x;
@ -11,7 +12,7 @@ export function y(d) {
}
var initialRadius = 10,
initialAngle = Math.PI * (3 - Math.sqrt(5));
initialAngle = pi * (3 - Math.sqrt(5));
export default function(nodes) {
var simulation,