fix added river basin selection

This commit is contained in:
Azgaar 2021-07-24 19:05:17 +03:00
parent dbcf46f83b
commit 424980f5be
3 changed files with 10 additions and 10 deletions

View file

@ -259,7 +259,7 @@
}; };
// add points at 1/3 and 2/3 of a line between adjacents river cells // add points at 1/3 and 2/3 of a line between adjacents river cells
const addMeandering = function (riverCells, meandering = 0.5, riverPoints = null) { const addMeandering = function (riverCells, riverPoints = null, meandering = 0.5) {
const {fl, conf, h} = pack.cells; const {fl, conf, h} = pack.cells;
const meandered = []; const meandered = [];
const lastStep = riverCells.length - 1; const lastStep = riverCells.length - 1;

View file

@ -1457,7 +1457,7 @@ function drawRivers() {
const {addMeandering, getRiverPath} = Rivers; const {addMeandering, getRiverPath} = Rivers;
lineGen.curve(d3.curveCatmullRom.alpha(0.1)); lineGen.curve(d3.curveCatmullRom.alpha(0.1));
const riverPaths = pack.rivers.map(river => { const riverPaths = pack.rivers.map(river => {
const riverMeandered = addMeandering(river.cells, 0.5, river.points); const riverMeandered = addMeandering(river.cells, river.points);
const widthFactor = river.widthFactor || 1; const widthFactor = river.widthFactor || 1;
const startingWidth = river.startingWidth || 0; const startingWidth = river.startingWidth || 0;
const path = getRiverPath(riverMeandered, widthFactor, startingWidth); const path = getRiverPath(riverMeandered, widthFactor, startingWidth);

View file

@ -540,8 +540,8 @@ function addRiverOnClick() {
const {alterHeights, resolveDepressions, addMeandering, getRiverPath, getBasin, getName, getType, getWidth, getOffset, getApproximateLength} = Rivers; const {alterHeights, resolveDepressions, addMeandering, getRiverPath, getBasin, getName, getType, getWidth, getOffset, getApproximateLength} = Rivers;
const riverCells = []; const riverCells = [];
let riverId = last(rivers).id + 1; let riverId = last(rivers).i + 1;
let parent = 0; let parent = riverId;
const initialFlux = grid.cells.prec[cells.g[i]]; const initialFlux = grid.cells.prec[cells.g[i]];
cells.fl[i] = initialFlux; cells.fl[i] = initialFlux;
@ -562,7 +562,7 @@ function addRiverOnClick() {
const feature = pack.features[cells.f[min]]; const feature = pack.features[cells.f[min]];
if (feature.type === "lake") { if (feature.type === "lake") {
parent = feature.outlet || 0; if (feature.outlet) parent = feature.outlet;
feature.inlets ? feature.inlets.push(riverId) : (feature.inlets = [riverId]); feature.inlets ? feature.inlets.push(riverId) : (feature.inlets = [riverId]);
} }
break; break;
@ -618,11 +618,11 @@ function addRiverOnClick() {
const source = riverCells[0]; const source = riverCells[0];
const mouth = riverCells[riverCells.length - 2]; const mouth = riverCells[riverCells.length - 2];
const widthFactor = river?.widthFactor || (!parent || parent === riverId ? 1.2 : 1); const widthFactor = river?.widthFactor || (!parent || parent === riverId ? 1.2 : 1);
const riverMeandered = addMeandering(riverCells); const meanderedPoints = addMeandering(riverCells);
const discharge = cells.fl[mouth]; // m3 in second const discharge = cells.fl[mouth]; // m3 in second
const length = getApproximateLength(riverMeandered); const length = getApproximateLength(meanderedPoints);
const width = getWidth(getOffset(discharge, riverMeandered.length, widthFactor)); const width = getWidth(getOffset(discharge, meanderedPoints.length, widthFactor));
if (river) { if (river) {
river.source = source; river.source = source;
@ -640,10 +640,10 @@ function addRiverOnClick() {
// render river // render river
lineGen.curve(d3.curveCatmullRom.alpha(0.1)); lineGen.curve(d3.curveCatmullRom.alpha(0.1));
const path = getRiverPath(riverMeandered, widthFactor); const path = getRiverPath(meanderedPoints, widthFactor);
const id = "river" + riverId; const id = "river" + riverId;
const riversG = viewbox.select("#rivers"); const riversG = viewbox.select("#rivers");
riversG.append("path").attr("d", path).attr("id", id); riversG.append("path").attr("id", id).attr("d", path);
if (d3.event.shiftKey === false) { if (d3.event.shiftKey === false) {
Lakes.cleanupLakeData(); Lakes.cleanupLakeData();