From ef31552cf1414b37c175048cb30c5e05a2dff03a Mon Sep 17 00:00:00 2001 From: zfilip Date: Fri, 14 Oct 2022 23:46:12 -0700 Subject: [PATCH] Use distance instead of distance squared in calculating cost of ocean path --- modules/routes-generator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/routes-generator.js b/modules/routes-generator.js index 7d884cba..627a41ce 100644 --- a/modules/routes-generator.js +++ b/modules/routes-generator.js @@ -278,8 +278,8 @@ window.Routes = (function () { } if (cells.h[c] >= 20) continue; // ignore land cells if (temp[cells.g[c]] <= -5) continue; // ignore cells with term <= -5 - const dist2 = (cells.p[c][1] - cells.p[n][1]) ** 2 + (cells.p[c][0] - cells.p[n][0]) ** 2; - const totalCost = p + (cells.road[c] ? 1 + dist2 / 2 : dist2 + (cells.t[c] ? 1 : 100)); + const dist = Math.sqrt((cells.p[c][1] - cells.p[n][1]) ** 2 + (cells.p[c][0] - cells.p[n][0]) ** 2); + const totalCost = p + (cells.road[c] ? 1 + dist / 2 : dist + (cells.t[c] ? 1 : 100)); if (from[c] || totalCost >= cost[c]) continue; (from[c] = n), (cost[c] = totalCost);