InterpCommon Extract function

This commit is contained in:
Pitchaya Boonsarngsuk
2018-02-02 13:26:20 +00:00
parent 636779322b
commit 92f9b83f28

View File

@@ -26,10 +26,13 @@ import jiggle from "../jiggle";
*/ */
export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleSubset, realDistances, endingIts) { export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleSubset, realDistances, endingIts) {
let let
dist0 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 0, radius), sampleSubset, realDistances), sumDistErrorByAngle = function(angle){
dist90 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 90, radius), sampleSubset, realDistances), return sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, angle, radius), sampleSubset, realDistances);
dist180 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 180, radius), sampleSubset, realDistances), })
dist270 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 270, radius), sampleSubset, realDistances), dist0 = sumDistErrorByAngle(0),
dist90 = sumDistErrorByAngle(90),
dist180 = sumDistErrorByAngle(180),
dist270 = sumDistErrorByAngle(270),
lowBound = 0.0, lowBound = 0.0,
highBound = 0.0; highBound = 0.0;
@@ -63,10 +66,7 @@ export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleS
} }
// Determine the angle // Determine the angle
let angle = binarySearchMin(lowBound, highBound, let angle = binarySearchMin(lowBound, highBound,sumDistErrorByAngle);
function(angle){
return sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, angle, radius), sampleSubset, realDistances);
});
let newPoint = pointOnCircle(nearNeighbour.x, nearNeighbour.y, angle, radius); let newPoint = pointOnCircle(nearNeighbour.x, nearNeighbour.y, angle, radius);
node.x = newPoint.x; node.x = newPoint.x;
node.y = newPoint.y; node.y = newPoint.y;