From a1109c43f63237a5cc46df7982746f648d4532d2 Mon Sep 17 00:00:00 2001 From: mattnotmax <39072319+mattnotmax@users.noreply.github.com> Date: Tue, 8 Dec 2020 21:17:43 +1100 Subject: [PATCH 1/2] Fix for haversine distance bug --- src/core/operations/HaversineDistance.mjs | 4 ++-- tests/operations/tests/HaversineDistance.mjs | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/core/operations/HaversineDistance.mjs b/src/core/operations/HaversineDistance.mjs index 1d0d25e0..680bff4d 100644 --- a/src/core/operations/HaversineDistance.mjs +++ b/src/core/operations/HaversineDistance.mjs @@ -41,8 +41,8 @@ class HaversineDistance extends Operation { const lat1 = parseFloat(values[1]); const lng1 = parseFloat(values[3]); - const lat2 = parseFloat(values[6]); - const lng2 = parseFloat(values[8]); + const lat2 = parseFloat(values[5]); + const lng2 = parseFloat(values[7]); const TO_RAD = Math.PI / 180; const dLat = (lat2-lat1) * TO_RAD; diff --git a/tests/operations/tests/HaversineDistance.mjs b/tests/operations/tests/HaversineDistance.mjs index 94fc7289..54033512 100644 --- a/tests/operations/tests/HaversineDistance.mjs +++ b/tests/operations/tests/HaversineDistance.mjs @@ -11,7 +11,18 @@ TestRegister.addTests([ { name: "Haversine distance", input: "51.487263,-0.124323, 38.9517,-77.1467", - expectedOutput: "5619355.701829259", + expectedOutput: "5902.542836307819", + recipeConfig: [ + { + "op": "Haversine distance", + "args": [] + } + ], + }, + { + name: "Haversine distance, zero distance", + input: "51.487263,-0.124323, 51.487263,-0.124323", + expectedOutput: "0", recipeConfig: [ { "op": "Haversine distance", From 39b7e4ff9e883489c68838103b2f29032766868e Mon Sep 17 00:00:00 2001 From: mattnotmax <39072319+mattnotmax@users.noreply.github.com> Date: Wed, 9 Dec 2020 21:12:26 +1100 Subject: [PATCH 2/2] Correct Haversine test output --- tests/operations/tests/HaversineDistance.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/operations/tests/HaversineDistance.mjs b/tests/operations/tests/HaversineDistance.mjs index 54033512..81bbf56e 100644 --- a/tests/operations/tests/HaversineDistance.mjs +++ b/tests/operations/tests/HaversineDistance.mjs @@ -11,7 +11,7 @@ TestRegister.addTests([ { name: "Haversine distance", input: "51.487263,-0.124323, 38.9517,-77.1467", - expectedOutput: "5902.542836307819", + expectedOutput: "5902542.836307819", recipeConfig: [ { "op": "Haversine distance",