Interpolation expose ending refinement interations to othre fn

This commit is contained in:
Pitchaya Boonsarngsuk
2018-01-31 16:04:19 +00:00
parent 7bb1cd755b
commit 0b0cd6d545
3 changed files with 11 additions and 9 deletions

View File

@@ -32,6 +32,7 @@ export default function(sampleSet, remainderSet, distanceFn) {
if (index !== -1) if (index !== -1)
sampleSubsetDistanceCache[index] = dist; sampleSubsetDistanceCache[index] = dist;
} }
placeNearToNearestNeighbour(node, nearestSample, minDist, sampleSubset, sampleSubsetDistanceCache);
placeNearToNearestNeighbour(node, nearestSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
} }
} }

View File

@@ -1,7 +1,7 @@
import {pointOnCircle, sumDistError} from "./helpers"; import {pointOnCircle, sumDistError} from "./helpers";
import jiggle from "../jiggle"; import jiggle from "../jiggle";
export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleSubset, realDistances) { export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleSubset, realDistances, endingIts) {
let let
dist0 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 0, radius), sampleSubset, realDistances), dist0 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 0, radius), sampleSubset, realDistances),
dist90 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 90, radius), sampleSubset, realDistances), dist90 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 90, radius), sampleSubset, realDistances),
@@ -47,12 +47,13 @@ export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleS
node.x = newPoint.x; node.x = newPoint.x;
node.y = newPoint.y; node.y = newPoint.y;
let sumForces; // Common temp variables, avoid GC let
for (let i = 0; i < 20; i++) { multiplier = 1/sampleSubset.length,
sumForces;
for (let i = 0; i < endingIts; i++) {
sumForces = sumForcesToSample(node, sampleSubset, realDistances); sumForces = sumForcesToSample(node, sampleSubset, realDistances);
//console.log(forces); node.x += sumForces.x*multiplier;
node.x += sumForces.x*0.5; node.y += sumForces.y*multiplier;
node.y += sumForces.y*0.5;
} }
} }

View File

@@ -22,7 +22,7 @@ import {placeNearToNearestNeighbour} from "./interpCommon";
* @param {number} endingIts - for phase 3, how many iterations to refine the * @param {number} endingIts - for phase 3, how many iterations to refine the
* placement of each interpolated point * placement of each interpolated point
*/ */
export default function(sampleSet, remainderSet, numPivots, distanceFn) { export default function(sampleSet, remainderSet, numPivots, distanceFn, endingIts) {
// Pivot based parent finding // Pivot based parent finding
let numBuckets = Math.floor(Math.sqrt(sampleSet.length)); let numBuckets = Math.floor(Math.sqrt(sampleSet.length));
let sets = takeSampleFrom(sampleSet, numPivots); let sets = takeSampleFrom(sampleSet, numPivots);
@@ -126,6 +126,6 @@ export default function(sampleSet, remainderSet, numPivots, distanceFn) {
if (sampleSubsetDistanceCache[k] === undefined) if (sampleSubsetDistanceCache[k] === undefined)
sampleSubsetDistanceCache[k] = distanceFn(node, sampleSubset[k]); sampleSubsetDistanceCache[k] = distanceFn(node, sampleSubset[k]);
} }
placeNearToNearestNeighbour(node, nearSample, minDist, sampleSubset, sampleSubsetDistanceCache); placeNearToNearestNeighbour(node, nearSample, minDist, sampleSubset, sampleSubsetDistanceCache, endingIts);
} }
} }