From 92f9b83f288e5a4cade07f69e265703ca29cc74d Mon Sep 17 00:00:00 2001 From: Pitchaya Boonsarngsuk <2285135b@student.gla.ac.uk> Date: Fri, 2 Feb 2018 13:26:20 +0000 Subject: [PATCH] InterpCommon Extract function --- src/interpolation/interpCommon.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) 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;