diff --git a/src/interpolation/interpCommon.js b/src/interpolation/interpCommon.js index 2beb10b..b4bfbbb 100644 --- a/src/interpolation/interpCommon.js +++ b/src/interpolation/interpCommon.js @@ -26,10 +26,13 @@ import jiggle from "../jiggle"; */ export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleSubset, realDistances, endingIts) { let - dist0 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 0, radius), sampleSubset, realDistances), - dist90 = sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, 90, 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), + sumDistErrorByAngle = function(angle){ + return sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, angle, radius), sampleSubset, realDistances); + }) + dist0 = sumDistErrorByAngle(0), + dist90 = sumDistErrorByAngle(90), + dist180 = sumDistErrorByAngle(180), + dist270 = sumDistErrorByAngle(270), lowBound = 0.0, highBound = 0.0; @@ -63,10 +66,7 @@ export function placeNearToNearestNeighbour(node, nearNeighbour, radius, sampleS } // Determine the angle - let angle = binarySearchMin(lowBound, highBound, - function(angle){ - return sumDistError(pointOnCircle(nearNeighbour.x, nearNeighbour.y, angle, radius), sampleSubset, realDistances); - }); + let angle = binarySearchMin(lowBound, highBound,sumDistErrorByAngle); let newPoint = pointOnCircle(nearNeighbour.x, nearNeighbour.y, angle, radius); node.x = newPoint.x; node.y = newPoint.y;