Neighbour change api
This commit is contained in:
@@ -16,6 +16,7 @@ function startHybridSimulation() {
|
|||||||
let forceSample = d3.forceNeighbourSampling()
|
let forceSample = d3.forceNeighbourSampling()
|
||||||
.neighbourSize(NEIGHBOUR_SIZE)
|
.neighbourSize(NEIGHBOUR_SIZE)
|
||||||
.sampleSize(SAMPLE_SIZE)
|
.sampleSize(SAMPLE_SIZE)
|
||||||
|
.stableVelocity(0)
|
||||||
.distance(distance)
|
.distance(distance)
|
||||||
|
|
||||||
let forceFull = d3.forceNeighbourSampling()
|
let forceFull = d3.forceNeighbourSampling()
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ function startNeighbourSamplingSimulation() {
|
|||||||
return distanceFunction(s, t, props, norm);
|
return distanceFunction(s, t, props, norm);
|
||||||
})
|
})
|
||||||
.stableVelocity(0.000001) //TODO
|
.stableVelocity(0.000001) //TODO
|
||||||
.stableVeloHandler(ended);
|
.onStableVelo(ended);
|
||||||
|
|
||||||
simulation
|
simulation
|
||||||
.alphaDecay(0)
|
.alphaDecay(0)
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {takeSampleFrom} from "./interpolation/helpers";
|
|||||||
* clean up the model.
|
* clean up the model.
|
||||||
* @param {object} sim - D3 Simulation object
|
* @param {object} sim - D3 Simulation object
|
||||||
* @param {object} forceS - Pre-configured D3 force object for the sample set.
|
* @param {object} forceS - Pre-configured D3 force object for the sample set.
|
||||||
The ending condition will be re-configured.
|
The ending handler will be re-configured.
|
||||||
Neighbour sampling force is expected, but other D3
|
Neighbour sampling force is expected, but other D3
|
||||||
forces may also work.
|
forces may also work.
|
||||||
* @param {object} forceF - Pre-configured D3 force object for the simultion ran
|
* @param {object} forceF - Pre-configured D3 force object for the simultion ran
|
||||||
@@ -60,10 +60,8 @@ export default function (sim, forceS, forceF) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function initForces(){
|
function initForces(){
|
||||||
if (forceSample.stableVelocity && forceSample.stableVeloHandler) {
|
if (forceSample.onStableVelo) {
|
||||||
forceSample
|
forceSample.onStableVelo(sampleEnded);
|
||||||
.stableVelocity(0) //TODO
|
|
||||||
.stableVeloHandler(sampleEnded);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set default value for interpDistanceFn if not been specified yet
|
// Set default value for interpDistanceFn if not been specified yet
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ export default function () {
|
|||||||
sampleSize = 10,
|
sampleSize = 10,
|
||||||
stableVelocity = 0,
|
stableVelocity = 0,
|
||||||
stableVeloHandler = null,
|
stableVeloHandler = null,
|
||||||
dataSizeFactor;
|
dataSizeFactor,
|
||||||
|
latestVelocityDiff = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply spring forces at each simulation iteration.
|
* Apply spring forces at each simulation iteration.
|
||||||
@@ -29,7 +30,7 @@ export default function () {
|
|||||||
function force(alpha) {
|
function force(alpha) {
|
||||||
let n = nodes.length;
|
let n = nodes.length;
|
||||||
// Cache old velocity for comparison later
|
// Cache old velocity for comparison later
|
||||||
if (stableVeloHandler!==null && stableVelocity!=0) {
|
if (stableVeloHandler!==null && stableVelocity>=0) {
|
||||||
for (let i = n-1, node; i>=0; i--) {
|
for (let i = n-1, node; i>=0; i--) {
|
||||||
node = nodes[i];
|
node = nodes[i];
|
||||||
node.oldvx = node.vx;
|
node.oldvx = node.vx;
|
||||||
@@ -53,13 +54,14 @@ export default function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Calculate velocity changes, aka force applied.
|
// Calculate velocity changes, aka force applied.
|
||||||
if (stableVeloHandler!==null && stableVelocity!=0) {
|
if (stableVeloHandler!==null && stableVelocity>=0) {
|
||||||
let velocityDiff = 0;
|
let velocityDiff = 0;
|
||||||
for (let i = n-1, node; i>=0; i--) {
|
for (let i = n-1, node; i>=0; i--) {
|
||||||
node = nodes[i];
|
node = nodes[i];
|
||||||
velocityDiff += Math.abs(Math.hypot(node.vx-node.oldvx, node.vy-node.oldvy));
|
velocityDiff += Math.abs(Math.hypot(node.vx-node.oldvx, node.vy-node.oldvy));
|
||||||
}
|
}
|
||||||
velocityDiff /= n*(neighbourSize+sampleSize);
|
velocityDiff /= n*(neighbourSize+sampleSize);
|
||||||
|
latestVelocityDiff = velocityDiff;
|
||||||
|
|
||||||
if(stableVeloHandler!==null && velocityDiff<stableVelocity){
|
if(stableVeloHandler!==null && velocityDiff<stableVelocity){
|
||||||
stableVeloHandler();
|
stableVeloHandler();
|
||||||
@@ -191,11 +193,11 @@ export default function () {
|
|||||||
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), force) : distance;
|
return arguments.length ? (distance = typeof _ === "function" ? _ : constant(+_), force) : distance;
|
||||||
};
|
};
|
||||||
|
|
||||||
force.velocity = function () {
|
force.latestAccel = function () {
|
||||||
return getAvgVelocity();
|
return latestVelocityDiff;
|
||||||
};
|
};
|
||||||
|
|
||||||
force.stableVeloHandler = function (_) {
|
force.onStableVelo = function (_) {
|
||||||
return arguments.length ? (stableVeloHandler = _, force) : stableVeloHandler;
|
return arguments.length ? (stableVeloHandler = _, force) : stableVeloHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user