From f7d1706b81d0dccc0cf73ea2ee530cbbd3192aab Mon Sep 17 00:00:00 2001 From: Azgaar Date: Tue, 24 Aug 2021 20:11:09 +0300 Subject: [PATCH] river create fix --- index.html | 4 ++-- modules/river-generator.js | 9 ++++++--- modules/ui/rivers-creator.js | 9 +++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/index.html b/index.html index 80a3ba8f..828c28f2 100644 --- a/index.html +++ b/index.html @@ -1652,9 +1652,9 @@ -
+
Source width:
- +
diff --git a/modules/river-generator.js b/modules/river-generator.js index a17cff87..43c67eb1 100644 --- a/modules/river-generator.js +++ b/modules/river-generator.js @@ -38,7 +38,7 @@ window.Rivers = (function () { const lakeOutCells = Lakes.setClimateData(h); land.forEach(function (i) { - cells.fl[i] += prec[cells.g[i]] * area[i] / 100; // add flux from precipitation + cells.fl[i] += (prec[cells.g[i]] * area[i]) / 100; // add flux from precipitation // create lake outlet if lake is not in deep depression and flux > evaporation const lakes = lakeOutCells[i] ? features.filter(feature => i === feature.outCell && feature.flux > feature.evaporation) : []; @@ -169,7 +169,7 @@ window.Rivers = (function () { const widthFactor = !parent || parent === riverId ? 1.2 : 1; const meanderedPoints = addMeandering(riverCells); const discharge = cells.fl[mouth]; // m3 in second - const length = rn(getApproximateLength(meanderedPoints), 2); + const length = getApproximateLength(meanderedPoints); const width = getWidth(getOffset(discharge, meanderedPoints.length, widthFactor, 0)); pack.rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth: 0, parent, cells: riverCells}); @@ -414,7 +414,10 @@ window.Rivers = (function () { return rw(riverTypes[isFork ? "fork" : "main"][isSmall ? "small" : "big"]); }; - const getApproximateLength = points => points.reduce((s, v, i, p) => s + (i ? Math.hypot(v[0] - p[i - 1][0], v[1] - p[i - 1][1]) : 0), 0); + const getApproximateLength = points => { + const length = points.reduce((s, v, i, p) => s + (i ? Math.hypot(v[0] - p[i - 1][0], v[1] - p[i - 1][1]) : 0), 0); + return rn(length, 2); + }; // Real mouth width examples: Amazon 6000m, Volga 6000m, Dniepr 3000m, Mississippi 1300m, Themes 900m, // Danube 800m, Daugava 600m, Neva 500m, Nile 450m, Don 400m, Wisla 300m, Pripyat 150m, Bug 140m, Muchavets 40m diff --git a/modules/ui/rivers-creator.js b/modules/ui/rivers-creator.js index 0a2d62c6..df6cd3e9 100644 --- a/modules/ui/rivers-creator.js +++ b/modules/ui/rivers-creator.js @@ -100,16 +100,13 @@ function createRiver() { const basin = getBasin(parent); rivers.push({i: riverId, source, mouth, discharge, length, width, widthFactor, sourceWidth, parent, cells: riverCells, basin, name, type: "River"}); + const id = "river" + riverId; // render river lineGen.curve(d3.curveCatmullRom.alpha(0.1)); - viewbox - .select("#rivers") - .append("path") - .attr("id", "river" + riverId) - .attr("d", getRiverPath(meanderedPoints, widthFactor, sourceWidth)); + viewbox.select("#rivers").append("path").attr("id", id).attr("d", getRiverPath(meanderedPoints, widthFactor, sourceWidth)); - editRiver(riverId); + editRiver(id); } function closeRiverCreator() {