Hybrid change API
This commit is contained in:
@@ -27,8 +27,7 @@ function startHybridSimulation() {
|
|||||||
let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull)
|
let hybridSimulation = d3.hybridSimulation(simulation, forceSample, forceFull)
|
||||||
.sampleIterations(ITERATIONS)
|
.sampleIterations(ITERATIONS)
|
||||||
.fullIterations(FULL_ITERATIONS)
|
.fullIterations(FULL_ITERATIONS)
|
||||||
.pivots(PIVOTS)
|
.numPivots(PIVOTS ? NUM_PIVOTS:-1)
|
||||||
.numPivots(NUM_PIVOTS)
|
|
||||||
.interpFindTuneIts(INTERP_ENDING_ITS)
|
.interpFindTuneIts(INTERP_ENDING_ITS)
|
||||||
.interpDistanceFn(distance)
|
.interpDistanceFn(distance)
|
||||||
.on("sampleTick", ticked)
|
.on("sampleTick", ticked)
|
||||||
@@ -36,7 +35,7 @@ function startHybridSimulation() {
|
|||||||
.on("startInterp", startedFull)
|
.on("startInterp", startedFull)
|
||||||
.on("end", ended);
|
.on("end", ended);
|
||||||
|
|
||||||
let sample = hybridSimulation.sample();
|
let sample = hybridSimulation.subSet();
|
||||||
addNodesToDOM(sample);
|
addNodesToDOM(sample);
|
||||||
|
|
||||||
hybridSimulation.restart();
|
hybridSimulation.restart();
|
||||||
|
|||||||
@@ -29,8 +29,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
SAMPLE_ITERATIONS = 300,
|
SAMPLE_ITERATIONS = 300,
|
||||||
FULL_ITERATIONS = 20,
|
FULL_ITERATIONS = 20,
|
||||||
interpDistanceFn,
|
interpDistanceFn,
|
||||||
PIVOTS = false,
|
NUM_PIVOTS = 0,
|
||||||
NUM_PIVOTS = 3,
|
|
||||||
INTERP_FINE_ITS = 20,
|
INTERP_FINE_ITS = 20,
|
||||||
sample = [],
|
sample = [],
|
||||||
remainder = [],
|
remainder = [],
|
||||||
@@ -105,7 +104,6 @@ export default function (sim, forceS, forceF) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function sampleEnded() {
|
function sampleEnded() {
|
||||||
event.call("startInterp");
|
|
||||||
simulation.stop();
|
simulation.stop();
|
||||||
simulation.force("Sample force", null);
|
simulation.force("Sample force", null);
|
||||||
// Reset velocity of all nodes
|
// Reset velocity of all nodes
|
||||||
@@ -114,8 +112,10 @@ export default function (sim, forceS, forceF) {
|
|||||||
sample[i].vy=0;
|
sample[i].vy=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
event.call("startInterp");
|
||||||
let p1 = performance.now();
|
let p1 = performance.now();
|
||||||
if (PIVOTS) {
|
if (NUM_PIVOTS>=1) {
|
||||||
interpolationPivots(sample, remainder, NUM_PIVOTS, interpDistanceFn, INTERP_FINE_ITS);
|
interpolationPivots(sample, remainder, NUM_PIVOTS, interpDistanceFn, INTERP_FINE_ITS);
|
||||||
} else {
|
} else {
|
||||||
interpBruteForce(sample, remainder, interpDistanceFn, INTERP_FINE_ITS);
|
interpBruteForce(sample, remainder, interpDistanceFn, INTERP_FINE_ITS);
|
||||||
@@ -130,7 +130,7 @@ export default function (sim, forceS, forceF) {
|
|||||||
.on("end", null) // The ending condition should be iterations count
|
.on("end", null) // The ending condition should be iterations count
|
||||||
.nodes(nodes);
|
.nodes(nodes);
|
||||||
|
|
||||||
if (FULL_ITERATIONS==0 || forceF === undefined || forceF === null) {
|
if (FULL_ITERATIONS<1 || forceF === undefined || forceF === null) {
|
||||||
event.call("end");
|
event.call("end");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -152,10 +152,6 @@ export default function (sim, forceS, forceF) {
|
|||||||
return hybrid;
|
return hybrid;
|
||||||
},
|
},
|
||||||
|
|
||||||
pivots: function (_) {
|
|
||||||
return arguments.length ? (PIVOTS = _, hybrid) : PIVOTS;
|
|
||||||
},
|
|
||||||
|
|
||||||
numPivots: function (_) {
|
numPivots: function (_) {
|
||||||
return arguments.length ? (NUM_PIVOTS = +_, hybrid) : NUM_PIVOTS;
|
return arguments.length ? (NUM_PIVOTS = +_, hybrid) : NUM_PIVOTS;
|
||||||
},
|
},
|
||||||
@@ -168,10 +164,6 @@ export default function (sim, forceS, forceF) {
|
|||||||
return arguments.length ? (FULL_ITERATIONS = +_, hybrid) : FULL_ITERATIONS;
|
return arguments.length ? (FULL_ITERATIONS = +_, hybrid) : FULL_ITERATIONS;
|
||||||
},
|
},
|
||||||
|
|
||||||
interpDistanceFn: function (_) {
|
|
||||||
return arguments.length ? (interpDistanceFn = +_, hybrid) : interpDistanceFn;
|
|
||||||
},
|
|
||||||
|
|
||||||
interpFindTuneIts: function (_) {
|
interpFindTuneIts: function (_) {
|
||||||
return arguments.length ? (INTERP_FINE_ITS = +_, hybrid) : INTERP_FINE_ITS;
|
return arguments.length ? (INTERP_FINE_ITS = +_, hybrid) : INTERP_FINE_ITS;
|
||||||
},
|
},
|
||||||
@@ -180,11 +172,11 @@ export default function (sim, forceS, forceF) {
|
|||||||
return arguments.length > 1 ? (event.on(name, _), hybrid) : event.on(name);
|
return arguments.length > 1 ? (event.on(name, _), hybrid) : event.on(name);
|
||||||
},
|
},
|
||||||
|
|
||||||
sample: function (_) {
|
subSet: function (_) {
|
||||||
return arguments.length ? (sample = _, hybrid) : sample;
|
return arguments.length ? (sample = _, hybrid) : sample;
|
||||||
},
|
},
|
||||||
|
|
||||||
remainder: function (_) {
|
nonSubSet: function (_) {
|
||||||
return arguments.length ? (remainder = _, hybrid) : remainder;
|
return arguments.length ? (remainder = _, hybrid) : remainder;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user